COPASI API  4.16.103
CDimension.h
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2006 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 #ifndef COPASI_DIMENSION
16 #define COPASI_DIMENSION
17 
18 #include <string>
19 #include <vector>
20 #include "copasi/copasi.h"
21 
22 class CModel;
23 
24 /**
25  * CDimension class.
26  * The class describes the dimension of a value, usually a CFunctionParameter.
27  *
28  * The dimension is given as a quintuple of real numbers: (amount of substance, volume, time, area, length).
29  * It can also be "unknown" or "contradiction". The actual unit can be constructed from the
30  * dimension and the 5 basic units from the CModel class (which is done in the
31  * getDisplayString() method).
32  */
34 {
35 public:
36 
37  CDimension();
38 
39  void setUnknown();
40  bool isUnknown() const;
41 
42  void setContradiction();
43  bool isContradiction() const;
44 
45  void setDimension(const C_FLOAT64 & d1, const C_FLOAT64 & d2, const C_FLOAT64 & d3,
46  const C_FLOAT64 & d4, const C_FLOAT64 & d5);
47 
48  std::string getDisplayString(const CModel* pModel) const;
49  std::string getDebugString() const;
50 
51  bool operator==(const CDimension & rhs) const;
52  CDimension operator+(const CDimension & rhs) const;
53  CDimension operator-(const CDimension & rhs) const;
54  CDimension operator*(const C_FLOAT64 & rhs) const;
55 
56  CDimension compare(const CDimension & rhs) const;
57 
58  /**
59  * If one of the base units is dimensionless, the corresponding exponent is
60  * adjusted to be 0.0.
61  * d1,d2,d3, d4, d5 indicate whether the base units are dimensionless
62  */
63  void fixDimensionless(bool d1, bool d2, bool d3, bool d4, bool d5);
64 
65  /**
66  * insert operator
67  */
68  //friend std::ostream & operator<<(std::ostream &os, const CDimension & d);
69  std::string print(const CModel* pModel) const;
70 
71 private:
72 
73  ///exponent of quantity base unit
75  ///exponent of volume base unit
77  ///exponent of time base unit
79  ///exponent of area base unit
81  ///exponent of length base unit
83 
84  bool mUnknown;
86 
87  static std::string constructDisplayElement(const std::string & base, C_FLOAT64 exponent);
88 };
89 
90 //******************************************************************+
91 
92 class CFunction;
93 class CReaction;
94 class CEvaluationNode;
95 class CChemEq;
96 
97 /**
98  * CFindDimensions class.
99  * The class tries to find the dimensions of the "PARAMETER" variable nodes
100  * in a function tree.
101  *
102  * The function is specified in the constructor. After that the dimension of the root node
103  * has to be specified. This can be done with either of the two public findDimensions()
104  * methods.
105  * The result can be retrieved using the getDimensions() method.
106  */
108 {
109 private:
110  CFindDimensions();
111 
112 public:
113 
114  /**
115  * construct the class for a given function.
116  * d1,d2,d3, d4, d5 indicate if the base unit (for quantity, volume, time, area, length) is dimensionless
117  */
118  CFindDimensions(const CFunction* function, bool d1, bool d2, bool d3, bool d4, bool d5);
119 
120  /**
121  * initialize the known dimensions (from the parameter roles) and
122  * set the others to "unknown". This is called by the constructor.
123  */
124  void setupDimensions();
125 
126  /**
127  * find the dimensions from explicitly given root node dimension
128  */
129  void findDimensions(CDimension rootDim);
130 
131  /**
132  * find the dimensions for a function that is used in a reaction
133  * the dimension of the root node depends on the number of compartments
134  * that are involved in the reaction
135  */
136  void findDimensions(bool isMulticompartment);
137 
138  /**
139  * find the dimensions for both a one-compartment and a multi-compartment reaction
140  */
141  std::vector<std::string> findDimensionsBoth(const CModel* pModel);
142 
143  const std::vector<CDimension> & getDimensions() const;
144 
145  //print the content of mDimensions to cout
146 #ifdef COPASI_DEBUG
147  void printDebugOutput(const CModel* pModel) const;
148 #endif // COPASI_DEBUG
149 
150  void setUseHeuristics(bool flag);
151 
152  /**
153  * tell about chemical equation. This is needed only for mass action kinetics.
154  * It is ignored otherwise.
155  */
156  void setChemicalEquation(const CChemEq* eq);
157 
158  void setMolecularitiesForMassAction(const size_t & m1,
159  const size_t & m2);
160 
161 private:
162 
164  std::vector<CDimension> mDimensions;
167  //const CChemEq* mpChemEq;
170 
171  bool mD1;
172  bool mD2;
173  bool mD3;
174  bool mD4;
175  bool mD5;
176 
177  ///find dim for all parameters
178  void findDimensions();
179 
180  ///determine dimensions for mass action kinetics
181  ///chemical equation needs to be known
183 
184  ///find dim for one parameter
185  void findDimension(size_t index);
186 
188  const CEvaluationNode * requestingNode = NULL);
189 };
190 
191 #endif
C_FLOAT64 mD3
exponent of time base unit
Definition: CDimension.h:78
bool mContradiction
Definition: CDimension.h:85
CDimension compare(const CDimension &rhs) const
Definition: CDimension.cpp:219
CDimension mRootDimension
Definition: CDimension.h:165
void fixDimensionless(bool d1, bool d2, bool d3, bool d4, bool d5)
Definition: CDimension.cpp:263
bool mUnknown
Definition: CDimension.h:84
std::string getDebugString() const
static std::string constructDisplayElement(const std::string &base, C_FLOAT64 exponent)
Definition: CDimension.cpp:61
const std::vector< CDimension > & getDimensions() const
Definition: CDimension.cpp:335
std::string getDisplayString(const CModel *pModel) const
Definition: CDimension.cpp:72
void setUseHeuristics(bool flag)
Definition: CDimension.cpp:330
C_FLOAT64 mD5
exponent of length base unit
Definition: CDimension.h:82
C_FLOAT64 mM2
Definition: CDimension.h:169
CDimension operator-(const CDimension &rhs) const
Definition: CDimension.cpp:191
void setContradiction()
Definition: CDimension.cpp:38
void setChemicalEquation(const CChemEq *eq)
Definition: CDimension.cpp:410
void findDimension(size_t index)
find dim for one parameter
Definition: CDimension.cpp:453
std::string print(const CModel *pModel) const
Definition: CDimension.cpp:250
std::vector< CDimension > mDimensions
Definition: CDimension.h:164
C_FLOAT64 mD4
exponent of area base unit
Definition: CDimension.h:80
const CFunction * mpFunction
Definition: CDimension.h:163
long int flag
Definition: f2c.h:52
bool operator==(const CDimension &rhs) const
Definition: CDimension.cpp:166
void setUnknown()
Definition: CDimension.cpp:28
C_FLOAT64 mD2
exponent of volume base unit
Definition: CDimension.h:76
#define C_FLOAT64
Definition: copasi.h:92
void setupDimensions()
Definition: CDimension.cpp:295
void findDimensions()
find dim for all parameters
Definition: CDimension.cpp:383
void setDimension(const C_FLOAT64 &d1, const C_FLOAT64 &d2, const C_FLOAT64 &d3, const C_FLOAT64 &d4, const C_FLOAT64 &d5)
Definition: CDimension.cpp:48
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
C_FLOAT64 mD1
exponent of quantity base unit
Definition: CDimension.h:74
void findDimensionsMassAction()
Definition: CDimension.cpp:430
CDimension operator+(const CDimension &rhs) const
Definition: CDimension.cpp:177
Definition: CModel.h:50
bool isUnknown() const
Definition: CDimension.cpp:33
bool isContradiction() const
Definition: CDimension.cpp:43
std::vector< std::string > findDimensionsBoth(const CModel *pModel)
Definition: CDimension.cpp:358
void setMolecularitiesForMassAction(const size_t &m1, const size_t &m2)
Definition: CDimension.cpp:423
CDimension operator*(const C_FLOAT64 &rhs) const
Definition: CDimension.cpp:205
C_FLOAT64 mM1
Definition: CDimension.h:168