COPASI API  4.16.103
Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
CDimension Class Reference

#include <CDimension.h>

Public Member Functions

 CDimension ()
 
CDimension compare (const CDimension &rhs) const
 
void fixDimensionless (bool d1, bool d2, bool d3, bool d4, bool d5)
 
std::string getDebugString () const
 
std::string getDisplayString (const CModel *pModel) const
 
bool isContradiction () const
 
bool isUnknown () const
 
CDimension operator* (const C_FLOAT64 &rhs) const
 
CDimension operator+ (const CDimension &rhs) const
 
CDimension operator- (const CDimension &rhs) const
 
bool operator== (const CDimension &rhs) const
 
std::string print (const CModel *pModel) const
 
void setContradiction ()
 
void setDimension (const C_FLOAT64 &d1, const C_FLOAT64 &d2, const C_FLOAT64 &d3, const C_FLOAT64 &d4, const C_FLOAT64 &d5)
 
void setUnknown ()
 

Static Private Member Functions

static std::string constructDisplayElement (const std::string &base, C_FLOAT64 exponent)
 

Private Attributes

bool mContradiction
 
C_FLOAT64 mD1
 exponent of quantity base unit More...
 
C_FLOAT64 mD2
 exponent of volume base unit More...
 
C_FLOAT64 mD3
 exponent of time base unit More...
 
C_FLOAT64 mD4
 exponent of area base unit More...
 
C_FLOAT64 mD5
 exponent of length base unit More...
 
bool mUnknown
 

Detailed Description

CDimension class. The class describes the dimension of a value, usually a CFunctionParameter.

The dimension is given as a quintuple of real numbers: (amount of substance, volume, time, area, length). It can also be "unknown" or "contradiction". The actual unit can be constructed from the dimension and the 5 basic units from the CModel class (which is done in the getDisplayString() method).

Definition at line 33 of file CDimension.h.

Constructor & Destructor Documentation

CDimension::CDimension ( )

Definition at line 22 of file CDimension.cpp.

23  : mD1(0), mD2(0), mD3(0), mD4(0), mD5(0),
24  mUnknown(true),
25  mContradiction(false)
26 {}
C_FLOAT64 mD3
exponent of time base unit
Definition: CDimension.h:78
bool mContradiction
Definition: CDimension.h:85
bool mUnknown
Definition: CDimension.h:84
C_FLOAT64 mD5
exponent of length base unit
Definition: CDimension.h:82
C_FLOAT64 mD4
exponent of area base unit
Definition: CDimension.h:80
C_FLOAT64 mD2
exponent of volume base unit
Definition: CDimension.h:76
C_FLOAT64 mD1
exponent of quantity base unit
Definition: CDimension.h:74

Member Function Documentation

CDimension CDimension::compare ( const CDimension rhs) const

Definition at line 219 of file CDimension.cpp.

References isContradiction(), isUnknown(), and setContradiction().

Referenced by CFindDimensions::findDimension().

220 {
221  CDimension result;
222 
223  if (this->isContradiction() || rhs.isContradiction())
224  result.setContradiction();
225  else if (*this == rhs)
226  result = *this;
227  else if (this->isUnknown())
228  result = rhs;
229  else if (rhs.isUnknown())
230  result = *this;
231  else
232  result.setContradiction();
233 
234  return result;
235 }
void setContradiction()
Definition: CDimension.cpp:38
bool isUnknown() const
Definition: CDimension.cpp:33
bool isContradiction() const
Definition: CDimension.cpp:43
std::string CDimension::constructDisplayElement ( const std::string &  base,
C_FLOAT64  exponent 
)
staticprivate

Definition at line 61 of file CDimension.cpp.

Referenced by getDisplayString().

62 {
63  if (exponent <= 0) return "";
64 
65  if (exponent == 1.0) return base;
66 
67  std::ostringstream ss;
68  ss << base << "^" << exponent;
69  return ss.str();
70 }
void CDimension::fixDimensionless ( bool  d1,
bool  d2,
bool  d3,
bool  d4,
bool  d5 
)

If one of the base units is dimensionless, the corresponding exponent is adjusted to be 0.0. d1,d2,d3, d4, d5 indicate whether the base units are dimensionless

Definition at line 263 of file CDimension.cpp.

References mD1, mD2, mD3, mD4, and mD5.

Referenced by CFindDimensions::findDimensions(), and CFindDimensions::findDimensionsMassAction().

264 {
265  if (d1)
266  mD1 = 0;
267 
268  if (d2)
269  mD2 = 0;
270 
271  if (d3)
272  mD3 = 0;
273 
274  if (d4)
275  mD4 = 0;
276 
277  if (d5)
278  mD5 = 0;
279 }
C_FLOAT64 mD3
exponent of time base unit
Definition: CDimension.h:78
C_FLOAT64 mD5
exponent of length base unit
Definition: CDimension.h:82
C_FLOAT64 mD4
exponent of area base unit
Definition: CDimension.h:80
C_FLOAT64 mD2
exponent of volume base unit
Definition: CDimension.h:76
C_FLOAT64 mD1
exponent of quantity base unit
Definition: CDimension.h:74
std::string CDimension::getDebugString ( ) const
std::string CDimension::getDisplayString ( const CModel pModel) const

Definition at line 72 of file CDimension.cpp.

References constructDisplayElement(), CModel::getAreaUnitName(), CModel::getLengthUnitName(), CModel::getQuantityUnitName(), CModel::getTimeUnitName(), CModel::getVolumeUnitName(), isContradiction(), isUnknown(), mD1, mD2, mD3, mD4, and mD5.

Referenced by print().

73 {
74  if (isUnknown())
75  return "?";
76 
77  if (isContradiction())
78  return "EEE";
79 
80  assert(pModel != NULL);
81 
82  std::string vol = pModel->getVolumeUnitName();
83  std::string time = pModel->getTimeUnitName();
84  std::string quan = pModel->getQuantityUnitName();
85  std::string area = pModel->getAreaUnitName();
86  std::string len = pModel->getLengthUnitName();
87 
88  std::string tmp;
89 
90  //positive exponents
91  std::string s1;
92  s1 = constructDisplayElement(quan, mD1);
93 
94  tmp = constructDisplayElement(vol, mD2);
95 
96  if ((s1 != "") && (tmp != "")) s1 += "*";
97 
98  s1 += tmp;
99 
100  tmp = constructDisplayElement(time, mD3);
101 
102  if ((s1 != "") && (tmp != "")) s1 += "*";
103 
104  s1 += tmp;
105 
106  tmp = constructDisplayElement(area, mD4);
107 
108  if ((s1 != "") && (tmp != "")) s1 += "*";
109 
110  s1 += tmp;
111 
112  tmp = constructDisplayElement(len, mD5);
113 
114  if ((s1 != "") && (tmp != "")) s1 += "*";
115 
116  s1 += tmp;
117 
118  //negative exponents
119  std::string s2;
120  bool parflag = false;
121  s2 = constructDisplayElement(quan, -mD1);
122 
123  tmp = constructDisplayElement(vol, -mD2);
124 
125  if ((s2 != "") && (tmp != ""))
126  {s2 += "*"; parflag = true;}
127 
128  s2 += tmp;
129 
130  tmp = constructDisplayElement(time, -mD3);
131 
132  if ((s2 != "") && (tmp != ""))
133  {s2 += "*"; parflag = true;}
134 
135  s2 += tmp;
136 
137  tmp = constructDisplayElement(area, -mD4);
138 
139  if ((s2 != "") && (tmp != ""))
140  {s2 += "*"; parflag = true;}
141 
142  s2 += tmp;
143 
144  tmp = constructDisplayElement(len, -mD5);
145 
146  if ((s2 != "") && (tmp != ""))
147  {s2 += "*"; parflag = true;}
148 
149  s2 += tmp;
150 
151  if (parflag) s2 = "(" + s2 + ")";
152 
153  //put it together..
154  if ((s1 == "") && (s2 == ""))
155  return "1";
156 
157  if (s1 == "")
158  return "1/" + s2;
159 
160  if (s2 == "")
161  return s1;
162 
163  return s1 + "/" + s2;
164 }
C_FLOAT64 mD3
exponent of time base unit
Definition: CDimension.h:78
std::string getTimeUnitName() const
Definition: CModel.cpp:2238
static std::string constructDisplayElement(const std::string &base, C_FLOAT64 exponent)
Definition: CDimension.cpp:61
C_FLOAT64 mD5
exponent of length base unit
Definition: CDimension.h:82
std::string getLengthUnitName() const
Definition: CModel.cpp:2215
C_FLOAT64 mD4
exponent of area base unit
Definition: CDimension.h:80
std::string getAreaUnitName() const
Definition: CModel.cpp:2193
std::string getQuantityUnitName() const
Definition: CModel.cpp:2321
C_FLOAT64 mD2
exponent of volume base unit
Definition: CDimension.h:76
C_FLOAT64 mD1
exponent of quantity base unit
Definition: CDimension.h:74
std::string getVolumeUnitName() const
Definition: CModel.cpp:2170
bool isUnknown() const
Definition: CDimension.cpp:33
bool isContradiction() const
Definition: CDimension.cpp:43
bool CDimension::isContradiction ( ) const

Definition at line 43 of file CDimension.cpp.

References mContradiction.

Referenced by compare(), getDisplayString(), operator*(), operator+(), and operator-().

44 {
45  return mContradiction;
46 }
bool mContradiction
Definition: CDimension.h:85
bool CDimension::isUnknown ( ) const

Definition at line 33 of file CDimension.cpp.

References mUnknown.

Referenced by compare(), getDisplayString(), operator*(), operator+(), and operator-().

34 {
35  return mUnknown;
36 }
bool mUnknown
Definition: CDimension.h:84
CDimension CDimension::operator* ( const C_FLOAT64 rhs) const

Definition at line 205 of file CDimension.cpp.

References isContradiction(), isUnknown(), mD1, mD2, mD3, mD4, mD5, setContradiction(), setDimension(), and setUnknown().

206 {
207  CDimension result;
208 
209  if (isContradiction())
210  result.setContradiction();
211  else if (isUnknown())
212  result.setUnknown();
213  else
214  result.setDimension(mD1 * rhs, mD2 * rhs, mD3 * rhs, mD4 * rhs, mD5 * rhs);
215 
216  return result;
217 }
C_FLOAT64 mD3
exponent of time base unit
Definition: CDimension.h:78
C_FLOAT64 mD5
exponent of length base unit
Definition: CDimension.h:82
void setContradiction()
Definition: CDimension.cpp:38
C_FLOAT64 mD4
exponent of area base unit
Definition: CDimension.h:80
void setUnknown()
Definition: CDimension.cpp:28
C_FLOAT64 mD2
exponent of volume base unit
Definition: CDimension.h:76
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
C_FLOAT64 mD1
exponent of quantity base unit
Definition: CDimension.h:74
bool isUnknown() const
Definition: CDimension.cpp:33
bool isContradiction() const
Definition: CDimension.cpp:43
CDimension CDimension::operator+ ( const CDimension rhs) const

Definition at line 177 of file CDimension.cpp.

References isContradiction(), isUnknown(), mD1, mD2, mD3, mD4, mD5, setContradiction(), setDimension(), and setUnknown().

178 {
179  CDimension result;
180 
181  if (isContradiction() || rhs.isContradiction())
182  result.setContradiction();
183  else if (isUnknown() || rhs.isUnknown())
184  result.setUnknown();
185  else
186  result.setDimension(mD1 + rhs.mD1, mD2 + rhs.mD2, mD3 + rhs.mD3, mD4 + rhs.mD4, mD5 + rhs.mD5);
187 
188  return result;
189 }
C_FLOAT64 mD3
exponent of time base unit
Definition: CDimension.h:78
C_FLOAT64 mD5
exponent of length base unit
Definition: CDimension.h:82
void setContradiction()
Definition: CDimension.cpp:38
C_FLOAT64 mD4
exponent of area base unit
Definition: CDimension.h:80
void setUnknown()
Definition: CDimension.cpp:28
C_FLOAT64 mD2
exponent of volume base unit
Definition: CDimension.h:76
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
C_FLOAT64 mD1
exponent of quantity base unit
Definition: CDimension.h:74
bool isUnknown() const
Definition: CDimension.cpp:33
bool isContradiction() const
Definition: CDimension.cpp:43
CDimension CDimension::operator- ( const CDimension rhs) const

Definition at line 191 of file CDimension.cpp.

References isContradiction(), isUnknown(), mD1, mD2, mD3, mD4, mD5, setContradiction(), setDimension(), and setUnknown().

192 {
193  CDimension result;
194 
195  if (isContradiction() || rhs.isContradiction())
196  result.setContradiction();
197  else if (isUnknown() || rhs.isUnknown())
198  result.setUnknown();
199  else
200  result.setDimension(mD1 - rhs.mD1, mD2 - rhs.mD2, mD3 - rhs.mD3, mD4 - rhs.mD4, mD5 - rhs.mD5);
201 
202  return result;
203 }
C_FLOAT64 mD3
exponent of time base unit
Definition: CDimension.h:78
C_FLOAT64 mD5
exponent of length base unit
Definition: CDimension.h:82
void setContradiction()
Definition: CDimension.cpp:38
C_FLOAT64 mD4
exponent of area base unit
Definition: CDimension.h:80
void setUnknown()
Definition: CDimension.cpp:28
C_FLOAT64 mD2
exponent of volume base unit
Definition: CDimension.h:76
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
C_FLOAT64 mD1
exponent of quantity base unit
Definition: CDimension.h:74
bool isUnknown() const
Definition: CDimension.cpp:33
bool isContradiction() const
Definition: CDimension.cpp:43
bool CDimension::operator== ( const CDimension rhs) const

Definition at line 166 of file CDimension.cpp.

References mContradiction, mD1, mD2, mD3, mD4, mD5, and mUnknown.

167 {
168  return (mUnknown == rhs.mUnknown)
169  && (mContradiction == rhs.mContradiction)
170  && (mD1 == rhs.mD1)
171  && (mD2 == rhs.mD2)
172  && (mD3 == rhs.mD3)
173  && (mD4 == rhs.mD4)
174  && (mD5 == rhs.mD5);
175 }
C_FLOAT64 mD3
exponent of time base unit
Definition: CDimension.h:78
bool mContradiction
Definition: CDimension.h:85
bool mUnknown
Definition: CDimension.h:84
C_FLOAT64 mD5
exponent of length base unit
Definition: CDimension.h:82
C_FLOAT64 mD4
exponent of area base unit
Definition: CDimension.h:80
C_FLOAT64 mD2
exponent of volume base unit
Definition: CDimension.h:76
C_FLOAT64 mD1
exponent of quantity base unit
Definition: CDimension.h:74
std::string CDimension::print ( const CModel pModel) const

insert operator

Disabled becuase the in order to generate output, the dimensions instance needs the datamodel. std::ostream & operator<<(std::ostream &os, const CDimension & d) { if (d.mUnknown) os << "Dim: unknown"; else if (d.mContradiction) os << "Dim: conctradiction"; else os << "Dim: (" << d.mD1 << ", " << d.mD2 << ", " << d.mD3 << ") " << d.getDisplayString();

return os; }

Definition at line 250 of file CDimension.cpp.

References getDisplayString(), mContradiction, mD1, mD2, mD3, mD4, mD5, and mUnknown.

251 {
252  std::ostringstream os;
253 
254  if (this->mUnknown) os << "Dim: unknown";
255  else if (this->mContradiction) os << "Dim: contradiction";
256  else os << "Dim: (" << this->mD1 << ", " << this->mD2 << ", " << this->mD3
257  << ", " << this->mD4 << ", " << this->mD5 << ") "
258  << this->getDisplayString(pModel);
259 
260  return os.str();
261 }
C_FLOAT64 mD3
exponent of time base unit
Definition: CDimension.h:78
bool mContradiction
Definition: CDimension.h:85
bool mUnknown
Definition: CDimension.h:84
std::string getDisplayString(const CModel *pModel) const
Definition: CDimension.cpp:72
C_FLOAT64 mD5
exponent of length base unit
Definition: CDimension.h:82
C_FLOAT64 mD4
exponent of area base unit
Definition: CDimension.h:80
C_FLOAT64 mD2
exponent of volume base unit
Definition: CDimension.h:76
C_FLOAT64 mD1
exponent of quantity base unit
Definition: CDimension.h:74
void CDimension::setContradiction ( )

Definition at line 38 of file CDimension.cpp.

References mContradiction, and mUnknown.

Referenced by compare(), operator*(), operator+(), and operator-().

39 {
40  mUnknown = false;
41  mContradiction = true;
42 }
bool mContradiction
Definition: CDimension.h:85
bool mUnknown
Definition: CDimension.h:84
void CDimension::setDimension ( const C_FLOAT64 d1,
const C_FLOAT64 d2,
const C_FLOAT64 d3,
const C_FLOAT64 d4,
const C_FLOAT64 d5 
)

Definition at line 48 of file CDimension.cpp.

References mContradiction, mD1, mD2, mD3, mD4, mD5, and mUnknown.

Referenced by CFindDimensions::findDimension(), CFindDimensions::findDimensions(), CFindDimensions::findDimensionsMassAction(), operator*(), operator+(), and operator-().

50 {
51  mUnknown = false;
52  mContradiction = false;
53  mD1 = d1;
54  mD2 = d2;
55  mD3 = d3;
56  mD4 = d4;
57  mD5 = d5;
58 }
C_FLOAT64 mD3
exponent of time base unit
Definition: CDimension.h:78
bool mContradiction
Definition: CDimension.h:85
bool mUnknown
Definition: CDimension.h:84
C_FLOAT64 mD5
exponent of length base unit
Definition: CDimension.h:82
C_FLOAT64 mD4
exponent of area base unit
Definition: CDimension.h:80
C_FLOAT64 mD2
exponent of volume base unit
Definition: CDimension.h:76
C_FLOAT64 mD1
exponent of quantity base unit
Definition: CDimension.h:74
void CDimension::setUnknown ( )

Definition at line 28 of file CDimension.cpp.

References mContradiction, and mUnknown.

Referenced by CFindDimensions::findDimension(), operator*(), operator+(), and operator-().

29 {
30  mUnknown = true;
31  mContradiction = false;
32 }
bool mContradiction
Definition: CDimension.h:85
bool mUnknown
Definition: CDimension.h:84

Member Data Documentation

bool CDimension::mContradiction
private
C_FLOAT64 CDimension::mD1
private

exponent of quantity base unit

Definition at line 74 of file CDimension.h.

Referenced by fixDimensionless(), getDisplayString(), operator*(), operator+(), operator-(), operator==(), print(), and setDimension().

C_FLOAT64 CDimension::mD2
private

exponent of volume base unit

Definition at line 76 of file CDimension.h.

Referenced by fixDimensionless(), getDisplayString(), operator*(), operator+(), operator-(), operator==(), print(), and setDimension().

C_FLOAT64 CDimension::mD3
private

exponent of time base unit

Definition at line 78 of file CDimension.h.

Referenced by fixDimensionless(), getDisplayString(), operator*(), operator+(), operator-(), operator==(), print(), and setDimension().

C_FLOAT64 CDimension::mD4
private

exponent of area base unit

Definition at line 80 of file CDimension.h.

Referenced by fixDimensionless(), getDisplayString(), operator*(), operator+(), operator-(), operator==(), print(), and setDimension().

C_FLOAT64 CDimension::mD5
private

exponent of length base unit

Definition at line 82 of file CDimension.h.

Referenced by fixDimensionless(), getDisplayString(), operator*(), operator+(), operator-(), operator==(), print(), and setDimension().

bool CDimension::mUnknown
private

Definition at line 84 of file CDimension.h.

Referenced by isUnknown(), operator==(), print(), setContradiction(), setDimension(), and setUnknown().


The documentation for this class was generated from the following files: