cta_treevector.h

Go to the documentation of this file.
00001 /*
00002 COSTA: Problem solving environment for data assimilation
00003 Copyright (C) 2005  Nils van Velzen
00004 
00005 This library is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU Lesser General Public
00007 License as published by the Free Software Foundation; either
00008 version 2.1 of the License, or (at your option) any later version.
00009 
00010 This library is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 Lesser General Public License for more details.
00014 
00015 You should have received a copy of the GNU Lesser General Public
00016 License along with this library; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 #ifndef CTA_TREEVECTOR_H
00020 #define CTA_TREEVECTOR_H
00021 #include "cta_system.h"
00022 #include "cta_datatypes.h"
00023 #include "cta_handles.h"
00024 #include "cta_vector.h"
00025 #include "cta_matrix.h"
00026 #include "cta_metainfo.h"
00027 
00028 /**
00029 \file  cta_treevector.h
00030 \brief Interface description of the COSTA default tree-vector component.
00031 
00032 The tree-vector is an extension of a vector component. A tree-vector
00033 either contains a single vector or is a concatenation of a number of
00034 tree-vectors, called sub-tree-vectors in this context. The usage of
00035 sub-tree-vectors makes is possible to concatenate models or extend models
00036 as is done when a deterministic model is extended into a stochastic model.
00037 The sub-tree-vectors are also very useful inside the model source code where the
00038 whole state of the model is not represented by a single vector. 
00039 The default tree-vector component uses COSTA vector-components for storing the values.
00040 
00041 Each (sub-)tree-vector has a tag. Tree-vectors having the same tag are considered
00042 to be the same, meaning they have the same buildup in sub-tree-vectors, length and
00043 datatypes.
00044 */
00045 
00046 
00047 /**
00048   Type definition of a handle to a COSTA tree-vector instance
00049 */
00050 typedef CTA_Handle CTA_TreeVector;
00051 
00052 #ifdef __cplusplus
00053 extern "C" {
00054 #endif
00055 
00056 /** \brief Create a tree-vector.
00057  *
00058  * \param name    I  name of the tree-vector, this is a human readable
00059  *                   string used for (debug) output and not by the algorithms
00060  *                   itself
00061  * \param tag     I  tag of this tree-vector
00062  * \param treevec  O new tree-vector
00063  *
00064  * \return error status: CTA_OK if successful
00065  */
00066 CTAEXPORT int CTA_TreeVector_Create(const char *name, const char *tag, CTA_TreeVector *treevec);
00067 
00068 /** \brief Duplicate a tree-vector.
00069  *
00070  * \note Duplication means that a new tree-vector is created that is identical to
00071  * the originating tree-vector. All data in the original tree-vector is also copied.
00072  *
00073  * \param treevec1  I  handle of treevector to be duplicated
00074  * \param treevec2  O  receives handle to duplicate
00075  *
00076  * \return error status: CTA_OK if successful
00077  */
00078 CTAEXPORT int CTA_TreeVector_Duplicate(CTA_TreeVector treevec1, CTA_TreeVector *treevec2 );
00079 
00080 
00081 /** \brief Define a tree-vector to be a concatination of other tree-vectors.
00082  *
00083  * \note The concatenation is done by reference (handle). The sub-tree-vectors that
00084  *       are concatenated are not copied.
00085  *
00086  * \param treevec1  I  tree-vector that will be concatenation of the sub-tree-vectors provided in parameter treevecs
00087  * \param treevecs  I  array of the sub-tree-vectors
00088  * \param ntreevecs I  number of sub-tree-vectors in treevecs
00089  *
00090  * \return error status: CTA_OK if successful
00091  */
00092 CTAEXPORT int CTA_TreeVector_Conc(CTA_TreeVector treevec1, CTA_TreeVector *treevecs, int ntreevecs);
00093 
00094 /** \brief Get the handle of a sub-tree-vectors using its tag.
00095  *
00096  * \note This is done by reference (handle). The handle of the
00097  *       returned sub-tree-vector is not a copy
00098  *
00099  * \param treevec   I  Tree-vector
00100  * \param tag       I  tag of the requested sub-tree-vector
00101  * \param subtreevec O  receives handle of the requested sub-tree-vectors, this is by reference, not a copy
00102  *
00103  * \return error status: CTA_OK if successful
00104  */
00105 CTAEXPORT int CTA_TreeVector_GetSubTreeVec(CTA_TreeVector treevec, const char *tag, CTA_TreeVector *subtreevec);
00106 
00107 /** \brief Get the handle of a first-layer sub-tree-vector using its index.
00108  *
00109  * \note The concatination is done by reference (handle). The handle of the
00110  *       returned sub-tree-vector is not a copy
00111  *
00112  * \param treevec   I  Tree-vector
00113  * \param index     I  index of requested sub-tree-vector. Note that the first sub-tree-vector has index 1.
00114  * \param subtreevec O  receives handle of the requested sub-tree-vector, this is by reference, not a copy
00115  *
00116  * \return error status: CTA_OK if successful
00117  */
00118 CTAEXPORT int CTA_TreeVector_GetSubTreeVecIndex(CTA_TreeVector treevec, int index,
00119                                 CTA_TreeVector *subtreevec);
00120 
00121 /** \brief Get number of sub-treevectors
00122  *
00123  * \note In case of a leaf 0 is returned
00124  *
00125  * \param treevec   I  Tree-vector
00126  * \param nsubvecs  O  Number of sub-treevectors
00127  *
00128  * \return error status: CTA_OK if successful
00129  */
00130 CTAEXPORT int CTA_TreeVector_GetNumSubTree(CTA_TreeVector treevec, int* numSubTrees);
00131 
00132 
00133 /** \brief Get the tag of the tree-vector.
00134  *
00135  * Note tag should be large enough to hold the result
00136  *      length of CTA_STRLEN_TAG is always save (no internal protection)
00137  *
00138  * \param treevec   I  Tree-vector
00139  * \param tag       O  receives the tag of the requested sub-tree-vector (see note)
00140  *
00141  * \return error status: CTA_OK if successful
00142  */
00143 CTAEXPORT int CTA_TreeVector_GetTag(CTA_TreeVector treevec, char *tag);
00144 
00145 
00146 /** \brief Set the values of the tree-vector
00147  *
00148  * \note This operation is only possible when all data elements in the tree-vector
00149  *       are of the same type and the size of the tree-vector corresponds to the
00150  *       size of the input vector.
00151  *
00152  * \param treevec   IO TreeVector
00153  * \param hvec      I  handle of the vector containing new values (see note)
00154  *
00155  * \return error status: CTA_OK if successful
00156  */
00157 CTAEXPORT int CTA_TreeVector_SetVec(CTA_TreeVector treevec, CTA_Vector hvec);
00158 
00159 /** \brief Get the values of the tree-vector.
00160  *
00161  * \note This operation is only possible when all data elements in the tree-vector
00162  *       are of the same type and the size of the tree-vector corresponds to the
00163  *       vector size.
00164  *
00165  * \param treevec   I  Tree-vector
00166  * \param hvec      O  Vector that is receiving the values; must exist before calling
00167  *
00168  * \return error status: CTA_OK if successful
00169  */
00170 CTAEXPORT int CTA_TreeVector_GetVec(CTA_TreeVector treevec, CTA_Vector hvec);
00171 
00172 /** \brief Axpy operation between two tree-vectors.
00173  *
00174  * \note  Axpy: y=alpha*x+y. Add alpha times tree-vector x to
00175  *              this tree-vector (y).
00176  *
00177  * \param y         IO Tree-vector (y)
00178  * \param alpha     I  scalar
00179  * \param x         I  Tree-vector (x)
00180  *
00181  * \return error status: CTA_OK if successful
00182  */
00183 CTAEXPORT int CTA_TreeVector_Axpy(CTA_TreeVector y, double alpha, CTA_TreeVector x);
00184 
00185 /** \brief Compute dot product of two tree-vectors.
00186  *
00187  * \note  dotprod = sum[all i]  (treevec1_i * treevec2_i)                           
00188  *
00189  * \param treevec1  I  first tree-vector
00190  * \param treevec2  I  second tree-vector
00191  * \param dotprod   O  receives the dot product
00192  *
00193  * \return error status: CTA_OK if successful
00194  */
00195 CTAEXPORT int CTA_TreeVector_Dot(CTA_TreeVector treevec1, CTA_TreeVector treevec2, double *dotprod);
00196 
00197 /** \brief Compute the 2-norm of a tree-vector.
00198  *
00199  * \param treevec1  I  Tree-vector
00200  * \param nrm2      O  receives the 2-norm
00201  *
00202  * \return error status: CTA_OK if successful
00203  */
00204 CTAEXPORT int CTA_TreeVector_Nrm2(CTA_TreeVector treevec1, double *nrm2);
00205 
00206 
00207 /** \brief Copy a tree-vector
00208  *
00209  * \note  The two tree-vectors must be compatible: same structure and datatypes.
00210  *
00211  * \param treevec1   I  sending tree-vector
00212  * \param treevec2   O  receiving tree-vector
00213  *
00214  * \return error status: CTA_OK if successful
00215  */
00216 CTAEXPORT int CTA_TreeVector_Copy(CTA_TreeVector treevec1, CTA_TreeVector treevec2);
00217 
00218 /** \brief Set whole tree-vector equal to a constant value.
00219  *
00220  * \note  This method can only be used if all elements of the tree-vector 
00221  *        have the same data type.
00222  *
00223  * \param treevec  IO TreeVector
00224  * \param val      I  value to set
00225  * \param datatype I  data type of val, must be same as data type of tree-vector
00226  *
00227  * \return error status: CTA_OK if successful
00228  */
00229 CTAEXPORT int CTA_TreeVector_SetConstant(CTA_TreeVector treevec, void *val,CTA_Datatype datatype);
00230 
00231 /** \brief Scale tree-vector.
00232  *
00233  * \param treevec   IO handle of tree-vector
00234  * \param alpha    I  scalar
00235  *
00236  * \return error status: CTA_OK if successful
00237  */
00238 CTAEXPORT int CTA_TreeVector_Scal(CTA_TreeVector treevec, double alpha);
00239 
00240 /** \brief Set all values of the tree-vector.
00241  *
00242  * \note  This method can only be used if all elements of the tree-vector 
00243  *        are of the same data type.
00244  *
00245  * \param treevec  IO Tree-vector
00246  * \param val      I  values to be set
00247  * \param nval     I  number of elements in val
00248  * \param datatype I  data type of *val, must be the same as data type of elements in tree-vector
00249  *
00250  * \return error status: CTA_OK if successful
00251  */
00252 CTAEXPORT int CTA_TreeVector_SetVals(CTA_TreeVector treevec, void *val,int nval, CTA_Datatype datatype);
00253 
00254 
00255 /** \brief Get all values of the tree-vector.
00256  *
00257  * \note  This method can only be used if all elements of the tree-vector
00258  *        are of the same data type.
00259  *
00260  * \param treevec  I  Tree-vector
00261  * \param val      O  receives the values
00262  * \param nval     I  number of elements in val
00263  * \param datatype I  data type of *val, must be the same as data type of elements in tree-vector
00264  *
00265  * \return error status: CTA_OK if successful
00266  */
00267 CTAEXPORT int CTA_TreeVector_GetVals(CTA_TreeVector treevec, void *val,int nval,CTA_Datatype datatype);
00268 
00269 /** \brief Set single value of the tree-vector.
00270  *
00271  * \param treevec  IO Tree-Vector
00272  * \param i        I  index of value in tree-vector
00273  * \param val      I  value to be set
00274  * \param datatype I  data type of *val, must be the same as data type of element in tree-vector
00275  *
00276  * \return error status: CTA_OK if successful
00277  */
00278 CTAEXPORT int CTA_TreeVector_SetVal(CTA_TreeVector treevec, int i, void *val, CTA_Datatype datatype);
00279 
00280 
00281 /** \brief Get single value of the tree-vector.
00282  *
00283  * \param treevec  I  Tree-vector
00284  * \param i        I  index in value in tree-vector
00285  * \param val      O  returned value
00286  * \param datatype I  data type of *val, must be the same as data type of element in tree-vector
00287  *
00288  * \return error status: CTA_OK if successful
00289  */
00290 CTAEXPORT int CTA_TreeVector_GetVal(CTA_TreeVector treevec, int i, void *val,CTA_Datatype datatype);
00291 
00292 /** \brief Get size of tree-vector.
00293  *
00294  * \param treevec  I  Tree-vector
00295  * \param n        O  receives size of tree-vector
00296  *
00297  * \return error status: CTA_OK if successful
00298  */
00299 CTAEXPORT int CTA_TreeVector_GetSize(CTA_TreeVector treevec, int *n);
00300 
00301 /** \brief Export tree-vector.
00302  *
00303  * Can export tree-vector to file or pack object.\n
00304  * usrdata must contain a handle of the file or pack object to be used.\n
00305  * Dependency: CTA_Vector_Export()
00306  *
00307  *
00308  * \param treevec  I  Tree-vector
00309  * \param usrdata  I  export properties
00310  *
00311  * \return error status: CTA_OK if successful
00312  */
00313 CTAEXPORT int CTA_TreeVector_Export(CTA_TreeVector treevec, CTA_Handle usrdata);
00314 
00315 /** \brief Import Tree-vector.
00316  *
00317  * Can import tree-vector from file or pack object.\n
00318  * usrdata must contain a handle of the file or pack object to be used.\n
00319  * Dependency: CTA_Vector_Import()
00320  *
00321  *
00322  * \param treevec  I  Tree-vector
00323  * \param usrdata  I  import properties
00324  *
00325  * \return error status: CTA_OK if successful
00326  */
00327 CTAEXPORT int CTA_TreeVector_Import(CTA_TreeVector treevec1, CTA_Handle usrdata);
00328 
00329 /** \brief Free Tree-vector.
00330  *
00331  * \param treevec     I  handle of tree-vector
00332  * \param recursive  I  also free all sub-tree-vectors, yes: CTA_TRUE or no: CTA_FALSE
00333  *
00334  * \return error status: CTA_OK if successful
00335  */
00336 CTAEXPORT int CTA_TreeVector_Free(CTA_TreeVector *treevec, int recursive);
00337 
00338 /** \brief Print tree-vector information.
00339  *
00340  * Gives following information:\n\n
00341  *  Tree-vector information:\n
00342  *  tag: [tag]\n
00343  *  nsubtreevecs: [number of sub-tree-vectors]\n
00344  *
00345  * If nsubtreevecs > 0: recursively prints all sub-tree-vectors
00346  * Else prints:\n
00347  * leaf: yes\n
00348  * tree-vector size (leaf)
00349  *
00350  * \param treevec     I  tree-vector
00351  *
00352  * \return error status: CTA_OK if successful
00353  */
00354 CTAEXPORT int CTA_TreeVector_Info(CTA_TreeVector treevec);
00355 
00356 /** \brief Perform the matrix multiplication C:=alpha*op(A)*op(B)+beta*C
00357     where op(X)=X, X^T. However C and A are matrices of wich the columns are 
00358     tree-vectors
00359  *
00360  *  \param sC     IO array of tree-vector (matrix C)
00361  *  \param nc     I  number of columns of C (dimension of sC)
00362  *  \param transa I  transpose flag CTA_TRUE/CTA_FALSE for matrix A (not supported)
00363  *  \param transb I  transpose flag CTA_TRUE/CTA_FALSE for matrix B
00364  *  \param alpha  I  scalar
00365  *  \param sA     I  handle of matrix A
00366  *  \param na     I  number of columns of A (dimension of sA)
00367  *  \param mB     I  handle of matrix B
00368  *  \param beta   I  scalar
00369  * \return error status: CTA_OK if successful
00370  */
00371 CTAEXPORT int CTA_TreeVector_Gemm(CTA_TreeVector *sC, int nc, int transa, int transb, double alpha, CTA_TreeVector *sA, int na,
00372                    CTA_Matrix mB, double beta);
00373 
00374 
00375 /** \brief Generate XML from one COSTA tree-vector
00376 *
00377 *  \param treevec   I  handle of a COSTA tree-vector
00378 *  \param writer I  the XML text writer
00379 */
00380 CTAEXPORT void CTAI_XML_WriteTreeVec(CTA_TreeVector treevec, xmlTextWriter *writer);
00381 
00382 /** \brief Create a COSTA tree-vector from XML. 
00383 *
00384 *  \param cur_node  I  Current XML node 
00385 *  \return             Handle to create or CTA_NULL in case of an error.
00386 */
00387 CTAEXPORT CTA_TreeVector CTAI_XML_CreateTreeVec(xmlNode *cur_node);
00388 
00389 
00390 /** \brief Perform given operation on all leafs of the treevector
00391 *
00392 *  \param treevec1 I  handle of first COSTA tree-vector
00393 *  \param treevec2 I  handle of second COSTA tree-vector
00394 *  \param treevec I  handle of a COSTA tree-vector
00395 *  \param op      I  operation to perform on the leafs
00396 *  \param arg     I  additional argument of operation
00397 *  \return            
00398 */
00399 CTAEXPORT int CTA_TreeVector_OpOnLeafs(CTA_TreeVector treevec1, CTA_TreeVector treevec2, CTA_Func op, CTA_Handle arg);
00400 
00401 /** \brief Elementwise division of two vectors
00402 *  \note y:=y./x
00403 *
00404 *  \param y       I  handle of a COSTA tree-vector (y)
00405 *  \param x       I  handle of a COSTA tree-vector (y)
00406 *  \return            
00407 */
00408 CTAEXPORT int CTA_TreeVector_ElmDiv(CTA_TreeVector y, CTA_TreeVector x);
00409 
00410 /** \brief Elementwise multiplication of two vectors
00411 *  \note y:=y.*x
00412 *
00413 *  \param y       I  handle of a COSTA tree-vector (y)
00414 *  \param x       I  handle of a COSTA tree-vector (y)
00415 *  \return            
00416 */
00417 CTAEXPORT int CTA_TreeVector_ElmProd(CTA_TreeVector y, CTA_TreeVector x);
00418 
00419 /** \brief Elementwise sqare root 
00420 *  \note y:=sqrt(y)
00421 *
00422 *  \param y       I  handle of a COSTA tree-vector (y)
00423 *  \return            
00424 */
00425 CTAEXPORT int CTA_TreeVector_ElmSqrt(CTA_TreeVector y);
00426 
00427 
00428 /** \brief Set nocompute flag of a sub-tree vector 
00429 *
00430 *  When this flag is set, the values of the sub-treevector will
00431 *  be ignored in all basic vector operations (including asking the 
00432 *  total length of the tree-vector). This propertie is used for
00433 *  additionally adding some meta information
00434 *
00435 * \note the nocompute flag is set at the level of the parent!
00436 * so the "isolated" sub-treevector can be used in basic vector
00437 * operations.
00438 *
00439 *  \param y       I  handle of a COSTA tree-vector (y)
00440 *  \return            
00441 */
00442 CTAEXPORT int CTA_TreeVector_SetSubTreeNocompute(CTA_TreeVector x, const char *tag);
00443 
00444 
00445 
00446 CTAEXPORT int CTA_TreeVector_SetMetainfo(CTA_TreeVector treevec, CTA_Metainfo minfo);
00447 CTAEXPORT int CTA_TreeVector_GetMetainfo(CTA_TreeVector treevec, CTA_Metainfo minfo);
00448 
00449 
00450 CTAEXPORT int CTAI_TreeVec_GetVecNumHandles(CTA_TreeVector treevec);
00451 
00452 CTAEXPORT int CTAI_TreeVec_List(CTA_TreeVector treevec, CTA_Vector taglist, int *indx);
00453 
00454 CTAEXPORT int CTA_TreeVector_List(CTA_TreeVector treevec, CTA_Vector taglist );
00455 
00456 CTAEXPORT int CTA_TreeVector_GetVecNumHandles(CTA_TreeVector treevec);
00457 
00458 CTAEXPORT void CTAI_Treevector_Operation_ScaledRMS(char *tag, CTA_Vector v1, 
00459                              CTA_Vector vscal, CTA_Handle hdum, int *retval);
00460 
00461 CTAEXPORT void CTAI_Treevector_Operation_Amax(char *tag, CTA_Vector v1, 
00462                              CTA_Vector * v2, CTA_Handle hdum, int *retval);
00463 
00464 CTAEXPORT void CTAI_Treevector_Operation_PrintEntry(char *tag, CTA_Vector v1, 
00465                              CTA_Vector v2, CTA_Handle hdum, int *retval);
00466 
00467 CTAEXPORT void CTAI_Treevector_Operation_ScaledSSQ(char *tag, CTA_Vector v1, 
00468                              CTA_Vector vscal, CTA_Handle hdum, int *retval);
00469 
00470 CTAEXPORT void CTAI_Treevector_Operation_MaxAbs(char *tag, CTA_Vector v1, 
00471                              CTA_Vector , CTA_Handle hdum, int *retval);
00472 
00473 #ifdef __cplusplus
00474 }
00475 #endif
00476 #endif
00477 

Generated on Mon Apr 6 14:05:58 2009 for COSTA by  doxygen 1.5.2