COPASI API  4.16.103
CMathEvent.h
Go to the documentation of this file.
1 // Copyright (C) 2011 - 2014 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_CMathEvent
7 #define COPASI_CMathEvent
8 
9 #include "copasi/model/CEvent.h"
11 
14 
15 class CProcessQueue;
16 class CMathContainer;
17 class CMathObject;
18 class CEventAssignment;
19 
21 {
22 public:
24  {
25  public:
26  /**
27  * Default constructor
28  */
29  CAssignment();
30 
31  /**
32  * Destructor
33  */
34  ~CAssignment();
35 
36  void initialize(CMath::sPointers & pointers);
37 
38  /**
39  * Copy an existing object
40  * @param const CAssignment & src
41  * @param CMathContainer & container
42  * @param const size_t & valueOffset
43  * @param const size_t & objectOffset
44  */
45  void copy(const CAssignment & src, CMathContainer & container, const size_t & valueOffset, const size_t & objectOffset);
46 
47  bool compile(CEventAssignment * pDataAssignment,
48  CMathContainer & container);
49 
50  void setTarget(CMathObject * pTarget);
51 
52  void setExpression(CMathObject * pExpression);
53 
54  private:
57  };
58 
59  class CTrigger
60  {
61  public:
62  class CRoot
63  {
64  public:
65  /**
66  * Default constructor
67  */
68  CRoot();
69 
70  /**
71  * Destructor
72  */
73  ~CRoot();
74 
75  void initialize(CMath::sPointers & pointers);
76 
77  /**
78  * Copy an existing object
79  * @param const CRoot & src
80  * @param CMathContainer & container
81  * @param const size_t & valueOffset
82  * @param const size_t & objectOffset
83  */
84  void copy(const CRoot & src, CMathContainer & container, const size_t & valueOffset, const size_t & objectOffset);
85 
86  bool compile(CEvaluationNode * pRootNode,
87  const bool & equality,
88  CMathContainer & container);
89 
91 
92  public:
95  bool mEquality;
96  bool mDiscrete;
97  };
98 
99  /**
100  * Default constructor
101  */
102  CTrigger();
103 
104  /**
105  * Destructor
106  */
107  ~CTrigger();
108 
109  void allocate(const CEvent * pDataEvent,
110  const CMathContainer & container);
111 
112  void allocateDiscontinuous(const size_t & nRoots,
113  const CMathContainer & container);
114 
115  void initialize(CMath::sPointers & pointers);
116 
117  /**
118  * Copy an existing object
119  * @param const CTrigger & src
120  * @param CMathContainer & container
121  * @param const size_t & valueOffset
122  * @param const size_t & objectOffset
123  */
124  void copy(const CTrigger & src, CMathContainer & container, const size_t & valueOffset, const size_t & objectOffset);
125 
126  bool compile(CEvent * pDataEvent,
127  CMathContainer & container);
128 
129  const CVector< CRoot > & getRoots() const;
130 
131  /**
132  * Set the trigger expression
133  * @param const std::string & infix
134  * @param CMathContainer & container
135  */
136  void setExpression(const std::string & infix, CMathContainer & container);
137 
138  private:
139  static size_t countRoots(const CEvaluationNode * pNode,
140  const CMath::Variables< size_t > & variables);
141 
142  static size_t countRootsDefault(const std::vector< size_t > & children);
143 
144  static size_t countRootsEQ(const CEvaluationNode * pNode,
145  const std::vector< size_t > & children);
146 
147  static size_t countRootsFUNCTION(const CEvaluationNode * pNode,
148  const std::vector< size_t > & children);
149 
150  static size_t countRootsVARIABLE(const CEvaluationNode * pNode,
151  const CMath::Variables< size_t > & variables);
152 
153  static CEvaluationNode * compile(const CEvaluationNode * pNode,
154  const CMath::Variables< CEvaluationNode * > & variables,
156  CMathContainer & container);
157 
158  static CEvaluationNode * compileAND(const CEvaluationNode * pNode,
159  const std::vector< CEvaluationNode * > & children,
160  const CMath::Variables< CEvaluationNode * > & variables,
162  CMathContainer & container);
163 
164  static CEvaluationNode * compileEQ(const CEvaluationNode * pNode,
165  const std::vector< CEvaluationNode * > & children,
166  const CMath::Variables< CEvaluationNode * > & variables,
168  CMathContainer & container);
169 
170  static CEvaluationNode * compileNE(const CEvaluationNode * pNode,
171  const std::vector< CEvaluationNode * > & children,
172  const CMath::Variables< CEvaluationNode * > & variables,
174  CMathContainer & container);
175 
176  static CEvaluationNode * compileLE(const CEvaluationNode * pNode,
177  const std::vector< CEvaluationNode * > & children,
178  const CMath::Variables< CEvaluationNode * > & variables,
180  CMathContainer & container);
181 
182  static CEvaluationNode * compileNOT(const CEvaluationNode * pNode,
183  const std::vector< CEvaluationNode * > & children,
184  const CMath::Variables< CEvaluationNode * > & variables,
186  CMathContainer & container);
187 
188  static CEvaluationNode * compileFUNCTION(const CEvaluationNode * pNode,
189  const std::vector< CEvaluationNode * > & children,
190  const CMath::Variables< CEvaluationNode * > & variables,
192  CMathContainer & container);
193 
194  static CEvaluationNode * compileVARIABLE(const CEvaluationNode * pNode,
195  const std::vector< CEvaluationNode * > & children,
196  const CMath::Variables< CEvaluationNode * > & variables,
198  CMathContainer & container);
199 
204  };
205 
206  /**
207  * Default constructor
208  */
209  CMathEventN();
210 
211  /**
212  * Destructor
213  */
214  ~CMathEventN();
215 
216  static void allocate(CMathEventN * pEvent,
217  const CEvent * pDataEvent,
218  const CMathContainer & container);
219 
220  void initialize(CMath::sPointers & pointers);
221 
222  /**
223  * Copy an existing object
224  * @param const CMathEventN & src
225  * @param CMathContainer & container
226  * @param const size_t & valueOffset
227  * @param const size_t & objectOffset
228  */
229  void copy(const CMathEventN & src, CMathContainer & container, const size_t & valueOffset, const size_t & objectOffset);
230 
231  bool compile(CEvent * pDataEvent,
232  CMathContainer & container);
233 
234  bool compile(CMathContainer & container);
235 
236  /**
237  * Set the trigger expression
238  * @param const std::string & infix
239  * @param CMathContainer & container
240  */
241  void setTriggerExpression(const std::string & infix, CMathContainer & container);
242 
243  /**
244  * Set the delay expression
245  * @param const std::string & infix
246  * @param CMathContainer & container
247  */
248  void setDelayExpression(const std::string & infix, CMathContainer & container);
249 
250  /**
251  * Set the priority expression
252  * @param const std::string & infix
253  * @param CMathContainer & container
254  */
255  void setPriorityExpression(const std::string & infix, CMathContainer & container);
256 
257  /**
258  * Add an assignment
259  * @param CMathObject * pTarget
260  * @param CMathObject * pExpression
261  */
262  void addAssignment(CMathObject * pTarget, CMathObject * pExpression);
263 
264  const CTrigger & getTrigger() const;
265 
266  const CVector< CAssignment > & getAssignments() const;
267 
268 private:
277 };
278 
280 {
281 private:
283  {
284  friend class CMathEvent;
285 
286  // Operations
287  public:
288  /**
289  * Default constructor
290  * @param const CCopasiContainer * pParent (default: NULL)
291  */
292  CAssignment(const CCopasiContainer * pParent = NULL);
293 
294  /**
295  * Copy constructor
296  * @param "const CAssignment &" src
297  * @param "const CCopasiContainer * pParent (default: NULL)
298  */
299  CAssignment(const CAssignment & src,
300  const CCopasiContainer * pParent = NULL);
301 
302  /**
303  * Destructor
304  */
305  ~CAssignment();
306 
307  /**
308  * Compile the root finder
309  * @param const CEventAssignment * pEvent
310  * @param std::vector< CCopasiContainer * > listOfContainer
311  */
312  bool compile(const CEventAssignment * pAssignment,
313  std::vector< CCopasiContainer * > listOfContainer);
314 
315  // Attributes
316  private:
317  /**
318  * Pointer to the value to be modified by the assignment
319  */
321 
322  /**
323  * Expression to calculate the new value.
324  */
326  };
327 
328  // Operations
329 public:
330  /**
331  * Default constructor
332  * @param const CCopasiContainer * pParent (default: NULL)
333  */
334  CMathEvent(const CCopasiContainer * pParent = NULL);
335 
336  /**
337  * Copy constructor
338  * @param "const CMathEvent &" src
339  * @param "const CCopasiContainer * pParent (default: NULL)
340  */
341  CMathEvent(const CMathEvent & src,
342  const CCopasiContainer * pParent = NULL);
343 
344  /**
345  * Destructor
346  */
347  ~CMathEvent();
348 
349  /**
350  * Compile the root finder
351  * @param const CEvent * pEvent
352  * @param std::vector< CCopasiContainer * > listOfContainer
353  */
354  bool compile(const CEvent * pEvent,
355  std::vector< CCopasiContainer * > listOfContainer);
356 
357  /**
358  * The event fires and the appropriate actions are scheduled
359  * in the process queue.
360  * @param const C_FLOAT64 & time
361  * @param const bool & equality
362  * @param CProcessQueue & processQueue
363  */
364  void fire(const C_FLOAT64 & time,
365  const bool & equality,
366  CProcessQueue & processQueue);
367 
368  /**
369  * Calculate and retrieve the new target values
370  * @return CVector< C_FLOAT64 > targetValues
371  */
373 
374  /**
375  * Set the target values
376  * @param const CVector< C_FLOAT64 > & targetValues
377  * @return bool stateChanged
378  */
379  bool setTargetValues(const CVector< C_FLOAT64 > & targetValues);
380 
381  /**
382  * Calculate and assign the new target values
383  * @return bool stateChanged
384  */
385  bool executeAssignment();
386 
387  /**
388  * Apply all needed refreshes so that the delay expression are
389  * correctly calculated.
390  */
391  void applyDelayRefreshes();
392 
393  /**
394  * Retrieve the trigger for this event.
395  * @return CMathTrigger & mathTrigger
396  */
398 
399  /**
400  * Retrieve the order in which this event shall be processed
401  * @return const size_t & order
402  */
403  const size_t & getOrder() const;
404 
405  /**
406  * Check whether to delay the assignment
407  * @return const bool & delayAssignment
408  */
409  const bool & delayAssignment() const;
410 
411  /**
412  * Retrieve the time for calculating the assignment expression
413  * @param const C_FLOAT64 & currentTime
414  * @return C_FLOAT64 calculationTime
415  */
416  C_FLOAT64 getCalculationTime(const C_FLOAT64 & currentTime);
417 
418  /**
419  * Retrieve the time for executing the assignmentS
420  * @param const C_FLOAT64 & currentTime
421  * @return C_FLOAT64 executionTime
422  */
423  C_FLOAT64 getAssignmentTime(const C_FLOAT64 & currentTime);
424 
425  /**
426  * Retrieve the type of the event
427  * @return const CEvent::Type & type
428  */
429  const CEvent::Type & getType() const;
430 
431 private:
432  /**
433  * Apply all needed refreshes so that the assignment expressions are
434  * correctly calculated.
435  */
436  void applyValueRefreshes();
437 
438  /**
439  * Apply all needed refreshes to update all values depending on the
440  * assignment targets.
441  */
443 
444  /**
445  * Calculate the time for delays. This accounts for small errors relative
446  * to the current time.
447  * @param const C_FLOAT64 & currentTime
448  * @return C_FLOAT64 delayedTime
449  */
450  C_FLOAT64 calculateDelayedTime(const C_FLOAT64 & currentTime);
451 
452  // Attributes
453 private:
454  /**
455  * Trigger expression.
456  */
458 
459  /**
460  * The order in which the event is processed in case of simultaneous
461  * assignments
462  */
463  size_t mOrder;
464 
465  /**
466  * Boolean value indicating whether the event involves a delay.
467  */
469 
470  /**
471  * Delay expression.
472  */
474 
475  /**
476  * Boolean value indicating whether the calculation or the assignment is delayed.
477  */
479 
480  /**
481  * List of assignments
482  */
484 
485  /**
486  * A sequence of refresh calls needed to prepare
487  * to calculate the delay value.
488  */
489  std::vector< Refresh * > mDelayValueRefreshes;
490 
491  /**
492  * A sequence of refresh calls needed to prepare
493  * to calculate the current values of the assignments.
494  */
495  std::vector< Refresh * > mAssignmentValueRefreshes;
496 
497  /**
498  * A sequence of refresh calls needed to calculate all
499  * values which depend on the target values of the assignments.
500  */
501  std::vector< Refresh * > mDependentValueRefreshes;
502 
503  /**
504  * The type of the event
505  */
507 };
508 
509 #endif // COPASI_CMathEvent
Definition: CEvent.h:152
Header file of class CExpression.
void setExpression(const std::string &infix, CMathContainer &container)
Definition: CMathEvent.cpp:292
static CEvaluationNode * compileVARIABLE(const CEvaluationNode *pNode, const std::vector< CEvaluationNode * > &children, const CMath::Variables< CEvaluationNode * > &variables, CMathEventN::CTrigger::CRoot *&pRoot, CMathContainer &container)
Definition: CMathEvent.cpp:813
const size_t & getOrder() const
bool compile(CEventAssignment *pDataAssignment, CMathContainer &container)
Definition: CMathEvent.cpp:47
static size_t countRoots(const CEvaluationNode *pNode, const CMath::Variables< size_t > &variables)
Definition: CMathEvent.cpp:315
std::vector< Refresh * > mDependentValueRefreshes
Definition: CMathEvent.h:501
bool mPersistentTrigger
Definition: CMathEvent.h:275
void setExpression(CMathObject *pExpression)
Definition: CMathEvent.cpp:78
static size_t countRootsVARIABLE(const CEvaluationNode *pNode, const CMath::Variables< size_t > &variables)
Definition: CMathEvent.cpp:478
CMathObject * mpTarget
Definition: CMathEvent.h:55
bool compile(CEvent *pDataEvent, CMathContainer &container)
Definition: CMathEvent.cpp:916
CMathTrigger mTrigger
Definition: CMathEvent.h:457
const CVector< CRoot > & getRoots() const
Definition: CMathEvent.cpp:287
void copy(const CMathEventN &src, CMathContainer &container, const size_t &valueOffset, const size_t &objectOffset)
Definition: CMathEvent.cpp:894
void setTriggerExpression(const std::string &infix, CMathContainer &container)
Definition: CMathEvent.cpp:972
bool compile(const CEvent *pEvent, std::vector< CCopasiContainer * > listOfContainer)
static CEvaluationNode * compileNE(const CEvaluationNode *pNode, const std::vector< CEvaluationNode * > &children, const CMath::Variables< CEvaluationNode * > &variables, CMathEventN::CTrigger::CRoot *&pRoot, CMathContainer &container)
Definition: CMathEvent.cpp:693
CMathObject * mpAssignment
Definition: CMathEvent.h:56
void applyValueRefreshes()
const bool & delayAssignment() const
bool compile(CEvent *pDataEvent, CMathContainer &container)
Definition: CMathEvent.cpp:247
void setDelayExpression(const std::string &infix, CMathContainer &container)
Definition: CMathEvent.cpp:977
bool setTargetValues(const CVector< C_FLOAT64 > &targetValues)
bool executeAssignment()
void initialize(CMath::sPointers &pointers)
Definition: CMathEvent.cpp:200
void fire(const C_FLOAT64 &time, const bool &equality, CProcessQueue &processQueue)
static CEvaluationNode * compileAND(const CEvaluationNode *pNode, const std::vector< CEvaluationNode * > &children, const CMath::Variables< CEvaluationNode * > &variables, CMathEventN::CTrigger::CRoot *&pRoot, CMathContainer &container)
Definition: CMathEvent.cpp:619
Type
Definition: CEvent.h:155
std::vector< Refresh * > mDelayValueRefreshes
Definition: CMathEvent.h:489
static CEvaluationNode * compileEQ(const CEvaluationNode *pNode, const std::vector< CEvaluationNode * > &children, const CMath::Variables< CEvaluationNode * > &variables, CMathEventN::CTrigger::CRoot *&pRoot, CMathContainer &container)
Definition: CMathEvent.cpp:655
CVector< CRoot > mRoots
Definition: CMathEvent.h:202
bool mFireAtInitialTime
Definition: CMathEvent.h:274
static size_t countRootsFUNCTION(const CEvaluationNode *pNode, const std::vector< size_t > &children)
Definition: CMathEvent.cpp:466
const CEvent::Type & getType() const
void setPriorityExpression(const std::string &infix, CMathContainer &container)
Definition: CMathEvent.cpp:984
CTrigger mTrigger
Definition: CMathEvent.h:270
void copy(const CTrigger &src, CMathContainer &container, const size_t &valueOffset, const size_t &objectOffset)
Definition: CMathEvent.cpp:226
CMathObject * mpPriority
Definition: CMathEvent.h:273
CExpression mDelay
Definition: CMathEvent.h:473
void addAssignment(CMathObject *pTarget, CMathObject *pExpression)
Definition: CMathEvent.cpp:991
CMathObject * mpInitialTrigger
Definition: CMathEvent.h:201
void setTarget(CMathObject *pTarget)
Definition: CMathEvent.cpp:73
CMathTrigger & getMathTrigger()
bool mHaveDelay
Definition: CMathEvent.h:468
void initialize(CMath::sPointers &pointers)
Definition: CMathEvent.cpp:868
void initialize(CMath::sPointers &pointers)
Definition: CMathEvent.cpp:29
CVector< C_FLOAT64 > getTargetValues()
C_FLOAT64 getAssignmentTime(const C_FLOAT64 &currentTime)
static CEvaluationNode * compileLE(const CEvaluationNode *pNode, const std::vector< CEvaluationNode * > &children, const CMath::Variables< CEvaluationNode * > &variables, CMathEventN::CTrigger::CRoot *&pRoot, CMathContainer &container)
Definition: CMathEvent.cpp:722
void allocateDiscontinuous(const size_t &nRoots, const CMathContainer &container)
Definition: CMathEvent.cpp:194
CExpression mExpression
Definition: CMathEvent.h:325
CMathObject * mpDelay
Definition: CMathEvent.h:272
bool compile(CEvaluationNode *pRootNode, const bool &equality, CMathContainer &container)
Definition: CMathEvent.cpp:121
static size_t countRootsDefault(const std::vector< size_t > &children)
Definition: CMathEvent.cpp:431
static CEvaluationNode * compileFUNCTION(const CEvaluationNode *pNode, const std::vector< CEvaluationNode * > &children, const CMath::Variables< CEvaluationNode * > &variables, CMathEventN::CTrigger::CRoot *&pRoot, CMathContainer &container)
Definition: CMathEvent.cpp:789
size_t mOrder
Definition: CMathEvent.h:463
const CVector< CAssignment > & getAssignments() const
CAssignment(const CCopasiContainer *pParent=NULL)
bool mDelayAssignment
Definition: CMathEvent.h:478
CVector< CAssignment > mAssignments
Definition: CMathEvent.h:271
CEvent::Type mType
Definition: CMathEvent.h:506
CMathObject * mpTrigger
Definition: CMathEvent.h:200
void allocate(const CEvent *pDataEvent, const CMathContainer &container)
Definition: CMathEvent.cpp:163
C_FLOAT64 getCalculationTime(const C_FLOAT64 &currentTime)
CEvaluationNode * createTriggerExpressionNode() const
Definition: CMathEvent.cpp:148
bool mDelayAssignment
Definition: CMathEvent.h:276
#define C_FLOAT64
Definition: copasi.h:92
void applyDelayRefreshes()
bool compile(const CEventAssignment *pAssignment, std::vector< CCopasiContainer * > listOfContainer)
static size_t countRootsEQ(const CEvaluationNode *pNode, const std::vector< size_t > &children)
Definition: CMathEvent.cpp:447
CCopasiVector< CAssignment > mAssignments
Definition: CMathEvent.h:483
std::vector< Refresh * > mAssignmentValueRefreshes
Definition: CMathEvent.h:495
static void allocate(CMathEventN *pEvent, const CEvent *pDataEvent, const CMathContainer &container)
Definition: CMathEvent.cpp:838
C_FLOAT64 calculateDelayedTime(const C_FLOAT64 &currentTime)
void copy(const CRoot &src, CMathContainer &container, const size_t &valueOffset, const size_t &objectOffset)
Definition: CMathEvent.cpp:110
CMathEvent(const CCopasiContainer *pParent=NULL)
const CTrigger & getTrigger() const
Definition: CMathEvent.cpp:863
Header file of class CEvent.
static CEvaluationNode * compileNOT(const CEvaluationNode *pNode, const std::vector< CEvaluationNode * > &children, const CMath::Variables< CEvaluationNode * > &variables, CMathEventN::CTrigger::CRoot *&pRoot, CMathContainer &container)
Definition: CMathEvent.cpp:774
CEvent::Type mType
Definition: CMathEvent.h:269
void applyDependentRefreshes()
void initialize(CMath::sPointers &pointers)
Definition: CMathEvent.cpp:93
void copy(const CAssignment &src, CMathContainer &container, const size_t &valueOffset, const size_t &objectOffset)
Definition: CMathEvent.cpp:38