COPASI API  4.16.103
CMathContainer.h
Go to the documentation of this file.
1 // Copyright (C) 2011 - 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 #ifndef COPASI_CMathContainer
7 #define COPASI_CMathContainer
8 
9 #include <map>
10 
12 
14 #include "copasi/math/CMathEvent.h"
17 
19 
21 
22 class CModelEntity;
23 class CReaction;
24 class CMoiety;
25 
26 template < class CType > class CCopasiVector;
27 
29 {
30 private:
31 
33  {
34  public:
37  };
38 
39  /**
40  * Default Constructor
41  */
43 
44 public:
45 
46  /**
47  * Specific Constructor
48  * @param CModel & model
49  */
50  CMathContainer(CModel & model);
51 
52  /**
53  * Copy constructor
54  * @param const CMathContainer & src
55  */
56  CMathContainer(const CMathContainer & src);
57 
58  /**
59  * Destructor
60  */
61  virtual ~CMathContainer();
62 
63  /**
64  * Retrieve the values of all mathematical objects
65  * @return const CVectorCore< C_FLOAT64 > & values
66  */
67  const CVectorCore< C_FLOAT64 > & getValues() const;
68 
69  /**
70  * Retrieve the values of all mathematical objects
71  * @return CVectorCore< C_FLOAT64 > & values
72  */
74 
75  /**
76  * Set the values of all mathematical objects
77  * @param const CVectorCore< C_FLOAT64 > & values
78  */
79  void setValues(const CVectorCore< C_FLOAT64 > & values);
80 
81  /**
82  * Retrieves the initial state values, i.e., all initial values of objects of
83  * simulation type Fixed, Time, ODE, Dependent, and Independent. It includes only
84  * extensive values for species.
85  * @return const CVectorCore< C_FLOAT64 > & initialState
86  */
88 
89  /**
90  * Retrieves the initial state values, i.e., all initial values of objects of
91  * simulation type Fixed, Time, ODE, Dependent, and Independent. It includes only
92  * extensive values for species.
93  * @return CVectorCore< C_FLOAT64 > & initialState
94  */
96 
97  /**
98  * Set the initial state values, i.e., all initial values of objects of
99  * simulation type Fixed, Time, ODE, Dependent, and Independent. It includes only
100  * extensive values for species.
101  * @param const CVectorCore< C_FLOAT64 > & initialState
102  */
103  void setInitialState(const CVectorCore< C_FLOAT64 > & initialState);
104 
105  /**
106  * Retrieves the state values, i.e., all initial values of objects of
107  * simulation type Time, ODE, Dependent, and Independent. It includes only
108  * extensive values for species.
109  * @return const CVectorCore< C_FLOAT64 > & state
110  */
111  const CVectorCore< C_FLOAT64 > & getState() const;
112 
113  /**
114  * Retrieves the state values, i.e., all initial values of objects of
115  * simulation type Time, ODE, Dependent, and Independent. It includes only
116  * extensive values for species.
117  * @return const CVectorCore< C_FLOAT64 > & state
118  */
120 
121  /**
122  * Set the state values, i.e., all initial values of objects of
123  * simulation type Time, ODE, Dependent, and Independent. It includes only
124  * extensive values for species.
125  * @param const CVectorCore< C_FLOAT64 > & state
126  */
127  void setState(const CVectorCore< C_FLOAT64 > & state);
128 
129  /**
130  * Retrieves the state values, i.e., all initial values of objects of
131  * simulation type Time, ODE, and Dependent. It includes only
132  * extensive values for species.
133  * @return const CVectorCore< C_FLOAT64 > & stateReduced
134  */
136 
137  /**
138  * Retrieves the reduced state values, i.e., all initial values of objects of
139  * simulation type Time, ODE, and Dependent. It includes only
140  * extensive values for species.
141  * @return const CVectorCore< C_FLOAT64 > & stateReduced
142  */
144 
145  /**
146  * Set the reduced state values, i.e., all initial values of objects of
147  * simulation type Time, ODE, Dependent, and Independent. It includes only
148  * extensive values for species.
149  * @param const CVectorCore< C_FLOAT64 > & stateReduced
150  */
151  void setStateReduced(const CVectorCore< C_FLOAT64 > & stateReduced);
152 
153  /**
154  * Calculate all dependent initial values based on initial extensive
155  * or intensive values
156  * @param const CModelParameter::Framework & framework
157  */
158  void updateInitialValues(const CModelParameter::Framework & framework);
159 
160  /**
161  * Set the transient values to the initial values and calculate all
162  * dependent values. Please call updateInitialValues before calling this
163  * method to assure that all values are up to date.
164  */
165  void applyInitialValues();
166 
167  /**
168  * Calculate all values required for simulation based on the current state
169  * @param const bool & useMoieties
170  */
171  void updateSimulatedValues(const bool & useMoieties);
172 
173  /**
174  * Apply the given update sequence to the mathematical objects in the container
175  * @param const CObjectInterface::UpdateSequence & updateSequence
176  */
177  void applyUpdateSequence(const CObjectInterface::UpdateSequence & updateSequence);
178 
179  /**
180  * Fetch the initial state from the associated model
181  */
182  void fetchInitialState();
183 
184  /**
185  * Push the initial state to the associated model
186  */
187  void pushInitialState();
188 
189  /**
190  * Fetch the state from the associated model
191  */
192  void fetchState();
193 
194  /**
195  * Push the state to the associated model
196  */
197  void pushState();
198 
199  /**
200  * Retrieve the CN of the math container
201  * The math container provides values for the numerical values of model objects.
202  * For the CN mechanism to work properly it has to pretend to be the model.
203  * @return CCopasiObjectName
204  */
205  virtual CCopasiObjectName getCN() const;
206 
207  /**
208  * Retrieve a descendant object by its CN.
209  */
210  virtual const CObjectInterface * getObject(const CCopasiObjectName & cn) const;
211 
212  /**
213  * Retrieve a pointer to corresponding the mathematical object
214  * for the given abject if it exists otherwise NULL
215  * @param const CObjectInterface * pObject
216  * @return CMathObject * pMathObject
217  */
218  CMathObject * getMathObject(const CObjectInterface * pObject) const;
219 
220  /**
221  * Retrieve a pointer to the mathematical object for data value pointer
222  * @param const C_FLOAT64 * pDataValue
223  * @return CMathObject * pMathObject
224  */
225  CMathObject * getMathObject(const C_FLOAT64 * pDataValue) const;
226 
227  /**
228  * Retrieve a pointer to the mathematical object for the given CN
229  * @param const CCopasiObjectName & cn
230  * @return CMathObject * pMathObject
231  */
232  CMathObject * getMathObject(const CCopasiObjectName & cn) const;
233 
234  /**
235  * Retrieve the model for the container
236  * @return const CModel & model
237  */
238  const CModel & getModel() const;
239 
240  /**
241  * Copy a node and all its children. Nodes are converted to suite the math container,
242  * i.e., objects nodes point to math object or numbers, function calls are expanded
243  * and discrete nodes are replaced by object node pointing to newly created math objects,
244  * which are and targets of automatically generated events.
245  * @param const CEvaluationNode * pSrc
246  * @param const bool & replaceDiscontinuousNodes
247  * @return CEvaluationNode * pCopy
248  */
250  const bool & replaceDiscontinuousNodes);
251 
252  /**
253  * Copy a node and all its children. Nodes are converted to suite the math container,
254  * i.e., objects nodes point to math object or numbers, function calls are expanded
255  * and discrete nodes are replaced by object node pointing to newly created math objects,
256  * which are and targets of automatically generated events.
257  * @param const CEvaluationNode * pSrc
258  * @param const CMath::Variables & variables
259  * @param const bool & replaceDiscontinuousNodes
260  * @return CEvaluationNode * pCopy
261  */
263  const CMath::Variables< CEvaluationNode * > & variables,
264  const bool & replaceDiscontinuousNodes);
265 
266  /**
267  * Replace a discontinuous node by an object node pointing to newly created math objects,
268  * which are targets of automatically generated events.
269  * @param const CEvaluationNode * pSrc
270  * @param const std::vector< CEvaluationNode * > & children
271  * @return CEvaluationNode * pCopy
272  */
274  const std::vector< CEvaluationNode * > & children);
275 
276  /**
277  * Retrieve the pointer to the corresponding initial value
278  * @param const C_FLOAT64 * pValue
279  * @return C_FLOAT64 * pInitialvalue
280  */
281  C_FLOAT64 * getInitialValuePointer(const C_FLOAT64 * pValue) const;
282 
283 private:
284  /**
285  * Initialize the mathematical model
286  */
287  void init();
288 
289  /**
290  * Allocate the memory for objects and values
291  */
292  void allocate();
293 
294  /**
295  * Initialize the pointers
296  * @param sPointers & pointers
297  */
298  void initializePointers(CMath::sPointers & pointers);
299 
300 #ifdef COPASI_DEBUG
301  /**
302  * Print pointer state
303  * @param sPointers & pointers
304  */
305  void printPointers(CMath::sPointers & pointers);
306 #endif // COAPSI_DEBUG
307 
308  /**
309  * Initialize the pointers used for the conversion of
310  * discontinuous nodes.
311  */
313 
314  /**
315  * Initialize the objects
316  * @param sPointers & pointers
317  */
318  void initializeObjects(CMath::sPointers & pointers);
319 
320  /**
321  * Initialize the events
322  * @param sPointers & pointers
323  */
324  void initializeEvents(CMath::sPointers & pointers);
325 
326  /**
327  * Compile the objects
328  */
329  bool compileObjects();
330 
331  /**
332  * Compile the events
333  */
334  bool compileEvents();
335 
336  /**
337  * Convert nodes which generate discrete changes into events
338  * and compiles them.
339  */
340  bool compileDiscreteChanges();
341 
342  /**
343  * Create a node based on the given pointer to the math object
344  * @param const CObjectInterface * pMathObject
345  * @return CEvaluationNode * pNode
346  */
348 
349  /**
350  * Create a node based on the given pointer to a data value
351  * @param const C_FLOAT64 * pDataValue
352  * @return CEvaluationNode * pNode
353  */
354  CEvaluationNode * createNodeFromValue(const C_FLOAT64 * pDataValue);
355 
356  /**
357  * Create Dependency Graphs
358  */
359  void createDependencyGraphs();
360 
361  /**
362  * Create the update sequences needed to synchronize the initial values
363  */
365 
366  /**
367  * Create the update sequence used when applying the initial state
368  */
370 
371  /**
372  * Create the update sequences used to calculate all values required for simulation
373  */
375 
376  /**
377  * Determine the entity type of an entity
378  * @param const CModelEntity * pEntity
379  * @return CMath::EntityType entityType
380  */
381  static CMath::EntityType getEntityType(const CModelEntity * pEntity);
382 
383  /**
384  * Initialize several mathematical objects of a common simulation type and
385  * advance relevant pointers
386  * @param const std::vector<const CModelEntity*> & entities
387  * @param const CMath::SimulationType & simulationType
388  * @param sPointers & pointers
389  */
390  void initializeMathObjects(const std::vector<const CModelEntity*> & entities,
391  const CMath::SimulationType & simulationType,
392  CMath::sPointers & pointers);
393 
394  /**
395  * Initialize several mathematical objects for local reaction parameters and
396  * advance relevant pointers
397  * @param const std::vector<const CCopasiObject *> & parameters
398  * @param CMathContainer::sPointers & p
399  */
400  void initializeMathObjects(const std::vector<const CCopasiObject *> & parameters,
401  CMath::sPointers & p);
402 
403  /**
404  * Initialize several mathematical objects for local reaction parameters and
405  * advance relevant pointers
406  * @param const CCopasiVector< CReaction > & reactions
407  * @param CMathContainer::sPointers & p
408  */
409  void initializeMathObjects(const CCopasiVector< CReaction > & reactions,
410  CMath::sPointers & p);
411 
412  /**
413  * Initialize several mathematical objects for local reaction parameters and
414  * advance relevant pointers
415  * @param const CCopasiVector< CMoiety > & moieties
416  * @param CMathContainer::sPointers & p
417  */
418  void initializeMathObjects(const CCopasiVector< CMoiety > & moieties,
419  CMath::sPointers & p);
420 
421  /**
422  * Determine whether on object has calculation dependencies.
423  */
424  static bool hasDependencies(const CCopasiObject * pObject);
425 
426  /**
427  * Map the data object to the math object
428  * @param CCopasiObject * pDataObject
429  * @param CMathObject * pMathObject
430  */
431  void map(CCopasiObject * pDataObject, CMathObject * pMathObject);
432 
433  /**
434  * Create an event of type CEvent::Discontinuity for each discontinuity in the model
435  */
437 
438  /**
439  * Create an event of type CEvent::Discontinuity for each discontinuity the tree with root pNode
440  * @param const CEvaluationTree * pTree
441  */
442  void createDiscontinuityEvents(const CEvaluationTree * pTree);
443 
444  /**
445  * Create an event of type CEvent::Discontinuity for the given node
446  * @param const CEvaluationNode * pNode
447  */
448  void createDiscontinuityDataEvent(const CEvaluationNode * pNode);
449 
450  /**
451  * Create the infix for trigger of the event which tracks changes in a discontinuity
452  * represented by the node.
453  * @param const CEvaluationNode * pNode
454  */
455  std::string createDiscontinuityTriggerInfix(const CEvaluationNode * pNode);
456 
457  // Attributes
458 
459  /**
460  * A pointer to the data model which mathematics are contained
461  */
465 
467 
476 
485 
494 
495  size_t mFixedCount;
497  size_t mODECount;
501 
502  /**
503  * The initial state contains also all fixed values
504  */
506 
507  /**
508  * The state contains values of type Time, ODE, Independent, and Dependent
509  */
511 
512  /**
513  * The state contains values of type Time, ODE, Independent
514  */
516 
517  /**
518  * Dependency graph for initial value calculations
519  */
521 
522  /**
523  * Dependency graph for transient value calculations
524  */
526 
527  /**
528  * The sequence of updates needed to synchronize the initial values based
529  * on extensive values, i.e., species amounts
530  */
532 
533  /**
534  * The sequence of updates needed to synchronize the initial values based
535  * on intensive values, i.e., species concentrations.
536  */
538 
539  /**
540  * The sequence of updates needed to apply the initial values
541  */
543 
544  /**
545  * The sequence of updates needed to calculate all simulation required values based
546  * on the assumption that all state values may have changed
547  */
549 
550  /**
551  * The sequence of updates needed to calculate all simulation required values based
552  * on the assumption that all state values may have changed
553  */
555 
556  /**
557  * The set of objects which determine the initial state of the model based on extensive
558  * values
559  */
561 
562  /**
563  * The set of objects which determine the initial state of the model based on intensive
564  * values
565  */
567 
568  /**
569  * The set of objects which determine the transient state of the model
570  */
572 
573  /**
574  * The set of objects which determine the transient state of the reduced model
575  */
577 
578  /**
579  * The objects which are required to be up to date for simulation of the full model,
580  * i.e., the right hand side of ODEs, rates of species determined by reaction,
581  * and event roots.
582  */
584 
585  /**
586  * The objects which are required to be up to date for simulation of the reduced model,
587  * i.e., the right hand side of ODEs, rates of independent species determined by reaction,
588  * and event roots.
589  */
590  // CObjectInterface::ObjectSet mSimulationRequiredValuesReduced;
591 
592  /**
593  * A vector containing all math objects.
594  */
596 
597  /**
598  * A vector containing all math events.
599  */
601 
602  /**
603  * A vector containing all math reactions.
604  */
606 
607  /**
608  * Structure of pointers used for creating discontinuities.
609  */
611 
612  /**
613  * A map from data objects to math objects
614  */
615  std::map< CCopasiObject *, CMathObject * > mDataObject2MathObject;
616 
617  /**
618  * A map from data objects values to math objects
619  */
620  std::map< C_FLOAT64 *, CMathObject * > mDataValue2MathObject;
621 
622  /**
623  * A vector of data events for discontinuities
624  */
626 
627  /**
628  * A map from the infix of the expression of a discontinuity to the object
629  * representing it.
630  */
631  std::map< std::string, CMathObject * > mDiscontinuityInfix2Object;
632 
633  /**
634  * A map from the discontinuity trigger infix of to event
635  * representing it.
636  */
637  std::map< std::string, CMathEventN * > mTriggerInfix2Event;
638 };
639 
640 #endif // COPASI_CMathContainer
CVector< CMathObject > mObjects
CVectorCore< C_FLOAT64 > mEventAssignments
std::map< CCopasiObject *, CMathObject * > mDataObject2MathObject
void setStateReduced(const CVectorCore< C_FLOAT64 > &stateReduced)
CVectorCore< C_FLOAT64 > mParticleFluxes
CVector< C_FLOAT64 > mValues
std::string createDiscontinuityTriggerInfix(const CEvaluationNode *pNode)
CObjectInterface::ObjectSet mInitialStateValueExtensive
CMathObject * getMathObject(const CObjectInterface *pObject) const
SimulationType
Definition: CMathEnum.h:182
sDiscontinuous mCreateDiscontinuousPointer
const CObjectInterface * mpQuantity2NumberFactor
void updateSimulatedValues(const bool &useMoieties)
CObjectInterface::UpdateSequence mSimulationValuesSequence
CVectorCore< C_FLOAT64 > mExtensiveValues
void initializePointers(CMath::sPointers &pointers)
std::map< C_FLOAT64 *, CMathObject * > mDataValue2MathObject
CVectorCore< C_FLOAT64 > mInitialIntensiveValues
void setInitialState(const CVectorCore< C_FLOAT64 > &initialState)
CEvaluationNode * copyBranch(const CEvaluationNode *pSrc, const bool &replaceDiscontinuousNodes)
CVectorCore< C_FLOAT64 > mTotalMasses
C_FLOAT64 * getInitialValuePointer(const C_FLOAT64 *pValue) const
void updateInitialValues(const CModelParameter::Framework &framework)
size_t mDependentCount
bool compileDiscreteChanges()
CObjectInterface::ObjectSet mInitialStateValueIntensive
CMathDependencyGraph mTransientDependencies
CVectorCore< C_FLOAT64 > mPropensities
std::map< std::string, CMathObject * > mDiscontinuityInfix2Object
CObjectInterface::ObjectSet mReducedStateValues
const CObjectInterface * mpAvogadro
CObjectInterface::UpdateSequence mSynchronizeInitialValuesSequenceIntensive
CVectorCore< C_FLOAT64 > mStateReduced
CObjectInterface::UpdateSequence mSimulationValuesSequenceReduced
std::map< std::string, CMathEventN * > mTriggerInfix2Event
EntityType
Definition: CMathEnum.h:195
void initializeMathObjects(const std::vector< const CModelEntity * > &entities, const CMath::SimulationType &simulationType, CMath::sPointers &pointers)
CObjectInterface::UpdateSequence mSynchronizeInitialValuesSequenceExtensive
CObjectInterface::ObjectSet mStateValues
void initializeObjects(CMath::sPointers &pointers)
void createSynchronizeInitialValuesSequence()
void createApplyInitialValuesSequence()
CObjectInterface::UpdateSequence mApplyInitialValuesSequence
CVectorCore< C_FLOAT64 > mEventTriggers
CVectorCore< C_FLOAT64 > mEventRoots
void applyUpdateSequence(const CObjectInterface::UpdateSequence &updateSequence)
void initializeDiscontinuousCreationPointer()
void createDiscontinuityEvents()
size_t mAssignmentCount
void initializeEvents(CMath::sPointers &pointers)
CVectorCore< C_FLOAT64 > mDiscontinuous
CVectorCore< C_FLOAT64 > mInitialEventTriggers
const CVectorCore< C_FLOAT64 > & getState() const
CVectorCore< C_FLOAT64 > mEventRootStates
Header file of class CCopasiContainer.
size_t mIndependentCount
CEvaluationNode * replaceDiscontinuousNode(const CEvaluationNode *pSrc, const std::vector< CEvaluationNode * > &children)
CVectorCore< C_FLOAT64 > mEventDelays
CVectorCore< C_FLOAT64 > mDependentMasses
std::set< const CObjectInterface * > ObjectSet
CVectorCore< C_FLOAT64 > mState
CVectorCore< C_FLOAT64 > mInitialState
CObjectInterface::ObjectSet mSimulationRequiredValues
static CMath::EntityType getEntityType(const CModelEntity *pEntity)
const CVectorCore< C_FLOAT64 > & getValues() const
static bool hasDependencies(const CCopasiObject *pObject)
#define C_FLOAT64
Definition: copasi.h:92
CEvaluationNode * createNodeFromObject(const CObjectInterface *pMathObject)
const CModel & getModel() const
CVectorCore< C_FLOAT64 > mExtensiveRates
CCopasiVector< CEvent > mDiscontinuityEvents
CVectorCore< C_FLOAT64 > mInitialTotalMasses
void createDependencyGraphs()
size_t mEventTargetCount
CVectorCore< C_FLOAT64 > mIntensiveValues
CVectorCore< C_FLOAT64 > mIntensiveRates
CVectorCore< C_FLOAT64 > mInitialExtensiveValues
CVectorCore< C_FLOAT64 > mInitialFluxes
virtual const CObjectInterface * getObject(const CCopasiObjectName &cn) const
const CVectorCore< C_FLOAT64 > & getInitialState() const
Definition: CModel.h:50
CVector< CMathReaction > mReactions
CEvaluationNode * createNodeFromValue(const C_FLOAT64 *pDataValue)
virtual ~CMathContainer()
CVectorCore< C_FLOAT64 > mInitialIntensiveRates
CMathDependencyGraph mInitialDependencies
void createUpdateSimulationValuesSequence()
const CVectorCore< C_FLOAT64 > & getStateReduced() const
void createDiscontinuityDataEvent(const CEvaluationNode *pNode)
void setValues(const CVectorCore< C_FLOAT64 > &values)
CVectorCore< C_FLOAT64 > mFluxes
CVectorCore< C_FLOAT64 > mInitialParticleFluxes
CVectorCore< C_FLOAT64 > mEventPriorities
void map(CCopasiObject *pDataObject, CMathObject *pMathObject)
CVectorCore< C_FLOAT64 > mInitialExtensiveRates
virtual CCopasiObjectName getCN() const
std::vector< CObjectInterface * > UpdateSequence
CVector< CMathEventN > mEvents
void setState(const CVectorCore< C_FLOAT64 > &state)