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

#include <CSBMLunit.h>

Inheritance diagram for CSBMLunit:
Inheritance graph
[legend]
Collaboration diagram for CSBMLunit:
Collaboration graph
[legend]

Classes

class  SymbolicExponent
 this class uniquely (in a given context) identifies a symbol More...
 

Public Member Functions

void applyExponent (double exp)
 apply numeric exponent to the unit. More...
 
void applyExponent (const std::string &id, size_t frame)
 apply symbolic exponent to the unit More...
 
void applyInverseExponent (const std::string &id, size_t frame)
 apply inverse of symbolic exponent to the unit More...
 
 CSBMLunit (unsigned int sbmlLevel, unsigned int sbmlVersion)
 Default constructor. More...
 
 CSBMLunit (const CSBMLunit &src)
 Copy constructor. More...
 
 CSBMLunit (const UnitDefinition *ud)
 Constructor from libsbml units. More...
 
virtual std::string getDisplayString () const
 
UnitDefinition & getSBMLUnitDefinition ()
 
const UnitDefinition & getSBMLUnitDefinition () const
 
int getSymbolicExpExp () const
 
const std::string & getSymbolicExponent () const
 
void invert ()
 
bool isDimensionless () const
 
bool multiply (const CSBMLunit &unit)
 
virtual ~CSBMLunit ()
 

Static Public Member Functions

static bool isEqual (const CSBMLunit &unit1, const CSBMLunit &unit2)
 

Private Attributes

SymbolicExponent mSymExp
 
int mSymExpExp
 
UnitDefinition mUD
 

Detailed Description

The current implementation of the units is just a wrapper for the libsbml UnitDefinition class.

Definition at line 21 of file CSBMLunit.h.

Constructor & Destructor Documentation

CSBMLunit::CSBMLunit ( unsigned int  sbmlLevel,
unsigned int  sbmlVersion 
)

Default constructor.

Definition at line 12 of file CSBMLunit.cpp.

References mUD.

13  : mUD(UnitDefinition(sbmlLevel, sbmlVersion)),
14  mSymExp(),
15  mSymExpExp(0)
16 {
17  Unit *tmp = mUD.createUnit();
18  tmp->setKind(UNIT_KIND_DIMENSIONLESS);
19 
20 #if LIBSBML_VERSION > 40100
21  tmp->initDefaults();
22 #endif
23 }
UnitDefinition mUD
Definition: CSBMLunit.h:73
int mSymExpExp
Definition: CSBMLunit.h:91
SymbolicExponent mSymExp
Definition: CSBMLunit.h:90
CSBMLunit::CSBMLunit ( const CSBMLunit src)

Copy constructor.

Definition at line 25 of file CSBMLunit.cpp.

26  : mUD(src.mUD),
27  mSymExp(src.mSymExp),
29 {
30  //TODO verify that this does indeed do a deep copy
31 }
UnitDefinition mUD
Definition: CSBMLunit.h:73
int mSymExpExp
Definition: CSBMLunit.h:91
SymbolicExponent mSymExp
Definition: CSBMLunit.h:90
CSBMLunit::CSBMLunit ( const UnitDefinition *  ud)

Constructor from libsbml units.

Definition at line 33 of file CSBMLunit.cpp.

34  : mUD(*ud),
35  mSymExp(),
36  mSymExpExp(0)
37 {
38 }
UnitDefinition mUD
Definition: CSBMLunit.h:73
int mSymExpExp
Definition: CSBMLunit.h:91
SymbolicExponent mSymExp
Definition: CSBMLunit.h:90
CSBMLunit::~CSBMLunit ( )
virtual

Definition at line 40 of file CSBMLunit.cpp.

41 {
42 }

Member Function Documentation

void CSBMLunit::applyExponent ( double  exp)

apply numeric exponent to the unit.

The current implementation only supports integer exponents.

Definition at line 104 of file CSBMLunit.cpp.

References isDimensionless(), mSymExpExp, and mUD.

Referenced by CSBMLunitInterface::recursionPower().

105 {
106  if (isDimensionless())
107  return;
108 
109  if (mSymExpExp != 0)
110  {
111  // could not apply numeric exponent because of symbolic exponent !!!
112  }
113 
114  unsigned int i, imax = mUD.getNumUnits();
115 
116  for (i = 0; i < imax; ++i)
117  {
118  mUD.getUnit(i)->setExponent(floor(0.5 + exp*(double)mUD.getUnit(i)->getExponent()));
119  }
120 }
bool isDimensionless() const
Definition: CSBMLunit.cpp:175
UnitDefinition mUD
Definition: CSBMLunit.h:73
int mSymExpExp
Definition: CSBMLunit.h:91
void CSBMLunit::applyExponent ( const std::string &  id,
size_t  frame 
)

apply symbolic exponent to the unit

This method applies a symbol as an exponent to the unit. The result is not really a valid unit itself, but the exponent can cancel out later during the calculations (via applyInverseExponent() ). In the current implementation, a string and an integer (sbml id + frame stack index) are sufficient to uniquely identify a symbol within one expression. In other words: Once we know the frame index the ID is unique.

Definition at line 122 of file CSBMLunit.cpp.

References isDimensionless(), CSBMLunit::SymbolicExponent::isEqual(), mSymExp, and mSymExpExp.

123 {
124  if (isDimensionless())
125  return;
126 
127  if ((mSymExpExp == 0) || mSymExp.isEqual(SymbolicExponent(id, frame)))
128  {
129  // applied symbolic exponent
130  ++mSymExpExp;
131  mSymExp = SymbolicExponent(id, frame);
132  }
133  else
134  {
135  // could not apply symbolic exponent !!!
136  assert(false);
137  }
138 }
bool isDimensionless() const
Definition: CSBMLunit.cpp:175
int mSymExpExp
Definition: CSBMLunit.h:91
SymbolicExponent mSymExp
Definition: CSBMLunit.h:90
bool isEqual(const SymbolicExponent &se) const
Definition: CSBMLunit.h:86
void CSBMLunit::applyInverseExponent ( const std::string &  id,
size_t  frame 
)

apply inverse of symbolic exponent to the unit

This method applies a symbol as a reverse exponent to the unit. The result is not really a valid unit itself, but the exponent can cancel out later. See applyExponent(std::string id, int frame)

Definition at line 140 of file CSBMLunit.cpp.

References isDimensionless(), CSBMLunit::SymbolicExponent::isEqual(), mSymExp, and mSymExpExp.

Referenced by CSBMLunitInterface::recursionPower().

141 {
142  if (isDimensionless())
143  return;
144 
145  if ((mSymExpExp == 0) || mSymExp.isEqual(SymbolicExponent(id, frame)))
146  {
147  // applied inverse symbolic exponent
148  --mSymExpExp;
149  mSymExp = SymbolicExponent(id, frame);
150  }
151  else
152  {
153  // could not apply inverse symbolic exponent !!!
154  assert(false);
155  }
156 }
bool isDimensionless() const
Definition: CSBMLunit.cpp:175
int mSymExpExp
Definition: CSBMLunit.h:91
SymbolicExponent mSymExp
Definition: CSBMLunit.h:90
bool isEqual(const SymbolicExponent &se) const
Definition: CSBMLunit.h:86
std::string CSBMLunit::getDisplayString ( ) const
virtual

Reimplemented in CSBMLunitInformation.

Definition at line 44 of file CSBMLunit.cpp.

References CSBMLunit::SymbolicExponent::mID, mSymExp, mSymExpExp, and mUD.

Referenced by CSBMLunitInformation::getDisplayString().

45 {
46  if (mSymExpExp == 0)
47  {
48  return UnitDefinition::printUnits(&mUD, true);
49  }
50  else if (mSymExpExp == 1)
51  {
52  return "(" + UnitDefinition::printUnits(&mUD, true) + ")^" + mSymExp.mID;
53  }
54  else
55  {
56  return "(" + UnitDefinition::printUnits(&mUD, true) + ")^" + mSymExp.mID + "^someExponent";
57  }
58 }
UnitDefinition mUD
Definition: CSBMLunit.h:73
int mSymExpExp
Definition: CSBMLunit.h:91
SymbolicExponent mSymExp
Definition: CSBMLunit.h:90
UnitDefinition& CSBMLunit::getSBMLUnitDefinition ( )
inline

Definition at line 69 of file CSBMLunit.h.

References mUD.

Referenced by Expression2PresentationMMLUnits::getMathML(), and CSBMLunitInterface::writeBackToModel().

69 {return mUD;};
UnitDefinition mUD
Definition: CSBMLunit.h:73
const UnitDefinition& CSBMLunit::getSBMLUnitDefinition ( ) const
inline

Definition at line 70 of file CSBMLunit.h.

References mUD.

70 {return mUD;};
UnitDefinition mUD
Definition: CSBMLunit.h:73
int CSBMLunit::getSymbolicExpExp ( ) const
inline

Definition at line 72 of file CSBMLunit.h.

References mSymExpExp.

Referenced by Expression2PresentationMMLUnits::getMathML(), and CSBMLunitInterface::writeBackToModel().

72 {return mSymExpExp;};
int mSymExpExp
Definition: CSBMLunit.h:91
const std::string& CSBMLunit::getSymbolicExponent ( ) const
inline

Definition at line 73 of file CSBMLunit.h.

Referenced by Expression2PresentationMMLUnits::getMathML().

73 {return mSymExp.mID;};
SymbolicExponent mSymExp
Definition: CSBMLunit.h:90
void CSBMLunit::invert ( )

Definition at line 88 of file CSBMLunit.cpp.

References isDimensionless(), mSymExpExp, and mUD.

Referenced by CSBMLunitInterface::handleOneExpression(), CSBMLunitInterface::initializeFromSBMLModel(), CSBMLunitInterface::recursionDivide(), and CSBMLunitInterface::recursionTimes().

89 {
90  if (isDimensionless())
91  return;
92 
93  if (mSymExpExp != 0)
94  {
95  // could not invert units because of symbolic exponent !!!
96  }
97 
98  unsigned int i, imax = mUD.getNumUnits();
99 
100  for (i = 0; i < imax; ++i)
101  mUD.getUnit(i)->setExponent(-mUD.getUnit(i)->getExponent());
102 }
bool isDimensionless() const
Definition: CSBMLunit.cpp:175
UnitDefinition mUD
Definition: CSBMLunit.h:73
int mSymExpExp
Definition: CSBMLunit.h:91
bool CSBMLunit::isDimensionless ( ) const

Definition at line 175 of file CSBMLunit.cpp.

References mUD.

Referenced by applyExponent(), applyInverseExponent(), invert(), isEqual(), and multiply().

176 {
177  return mUD.isVariantOfDimensionless();
178 }
UnitDefinition mUD
Definition: CSBMLunit.h:73
bool CSBMLunit::isEqual ( const CSBMLunit unit1,
const CSBMLunit unit2 
)
static

Definition at line 159 of file CSBMLunit.cpp.

References isDimensionless(), CSBMLunit::SymbolicExponent::isEqual(), mSymExp, mSymExpExp, and mUD.

Referenced by CSBMLunitInterface::handleTerminalNode(), and CSBMLunitInformation::isEqual().

160 {
161  if (unit1.isDimensionless() && unit2.isDimensionless())
162  return true;
163 
164  if (((unit1.mSymExpExp == 0) && (unit2.mSymExpExp == 0))
165  || (unit1.mSymExp.isEqual(unit2.mSymExp) && (unit1.mSymExpExp == unit2.mSymExpExp)))
166  {
167  return UnitDefinition::areEquivalent(&unit1.mUD, &unit2.mUD);
168  }
169  else
170  {
171  return false;
172  }
173 }
bool isDimensionless() const
Definition: CSBMLunit.cpp:175
UnitDefinition mUD
Definition: CSBMLunit.h:73
int mSymExpExp
Definition: CSBMLunit.h:91
SymbolicExponent mSymExp
Definition: CSBMLunit.h:90
bool isEqual(const SymbolicExponent &se) const
Definition: CSBMLunit.h:86
bool CSBMLunit::multiply ( const CSBMLunit unit)

Definition at line 60 of file CSBMLunit.cpp.

References isDimensionless(), CSBMLunit::SymbolicExponent::isEqual(), mSymExp, mSymExpExp, and mUD.

Referenced by CSBMLunitInterface::handleOneExpression(), CSBMLunitInterface::initializeFromSBMLModel(), CSBMLunitInterface::recursionDivide(), and CSBMLunitInterface::recursionTimes().

61 {
62  if (unit.isDimensionless())
63  return true;
64 
65  if (isDimensionless())
66  {
67  mUD = unit.mUD;
68  mSymExp = unit.mSymExp;
69  mSymExpExp = unit.mSymExpExp;
70  return true;
71  }
72 
73  if ((mSymExpExp == 0 && unit.mSymExpExp == 0)
74  || ((mSymExpExp == unit.mSymExpExp) && (mSymExp.isEqual(unit.mSymExp))))
75  {
76  UnitDefinition tmp = unit.mUD;
77  UnitDefinition * tmpPointerUD = UnitDefinition::combine(&this->mUD, &tmp);
78  mUD = *tmpPointerUD;
79  delete tmpPointerUD;
80  return true;
81  }
82 
83  // could not multiply units because of symbolic exponent !!!
84 
85  return false;
86 }
bool isDimensionless() const
Definition: CSBMLunit.cpp:175
UnitDefinition mUD
Definition: CSBMLunit.h:73
int mSymExpExp
Definition: CSBMLunit.h:91
SymbolicExponent mSymExp
Definition: CSBMLunit.h:90
bool isEqual(const SymbolicExponent &se) const
Definition: CSBMLunit.h:86

Member Data Documentation

SymbolicExponent CSBMLunit::mSymExp
private

Definition at line 90 of file CSBMLunit.h.

Referenced by applyExponent(), applyInverseExponent(), getDisplayString(), isEqual(), and multiply().

int CSBMLunit::mSymExpExp
private
UnitDefinition CSBMLunit::mUD
private

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