COPASI API  4.16.103
CMathModel.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) 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 #ifndef COPASI_CMathModel
12 #define COPASI_CMathModel
13 
14 #include "utilities/CVector.h"
15 #include "utilities/CMatrix.h"
16 
18 
19 #include "copasi/math/CMathEvent.h"
20 
21 class CModel;
22 
24 {
25  // Operations
26 public:
27  /**
28  * Default constructor
29  * @param const CCopasiContainer * pParent (default: NULL)
30  */
31  CMathModel(const CCopasiContainer * pParent = NULL);
32 
33  /**
34  * Copy constructor
35  * @param "const CMathModel &" src
36  * @param "const CCopasiContainer * pParent (default: NULL)
37  */
38  CMathModel(const CMathModel & src,
39  const CCopasiContainer * pParent = NULL);
40 
41  /**
42  * Destructor
43  */
44  virtual ~CMathModel();
45 
46  /**
47  * Compile the mathematical model based on given the model.
48  * @param CModel * pModel
49  * @return bool success
50  */
51  bool compile(CModel * pModel);
52 
53  /**
54  * Evaluate all root values for the current state of the model. If
55  * ignoreDiscrete is true discrete roots evaluate to 1.0.
56  * @param CVectorCore< double > & rootValues
57  * @param const bool & ignoreDiscrete
58  */
59  void evaluateRoots(CVectorCore< C_FLOAT64 > & rootValues,
60  const bool & ignoreDiscrete);
61 
62  /**
63  * Retreive the initial time
64  * @return const C_FLOAT64 & initialTime
65  */
66  const C_FLOAT64 & getInitialTime() const;
67 
68  /**
69  * Process events scheduled at the given which a are checked for
70  * equality or not
71  * @param const C_FLOAT64 & time
72  * @param const bool & equality
73  * @param CProcessQueue::resolveSimultaneousAssignments pResolveSimultaneousAssignments
74  * @return bool stateChanged
75  */
76  bool processQueue(const C_FLOAT64 & time,
77  const bool & equality,
78  CProcessQueue::resolveSimultaneousAssignments pResolveSimultaneousAssignments);
79 
80  /**
81  * Check whether the roots which have value 1 lead to firing of
82  * events and schedule them if needed. This method is intended to be
83  * called from integration methods, which can distinguish between equality
84  * and inequality.
85  * @param const C_FLOAT64 & time
86  * @param const bool & equality
87  * @param const bool & correct
88  * @param const CVector< C_INT > & roots
89  */
90  void processRoots(const C_FLOAT64 & time,
91  const bool & equality,
92  const bool & correct,
93  const CVector< C_INT > & roots);
94 
95  /**
96  * Check whether the roots which have value 1 lead to firing of
97  * events and schedule them if needed. This method is intended to be
98  * called during discrete event processing e.g. while processing the
99  * event queue.
100  * @param const C_FLOAT64 & time
101  * @param const bool & equality
102  * @param const bool & correct
103  * @param const CVector< C_INT > & roots
104  */
105  void processRoots(const C_FLOAT64 & time,
106  const CVector< C_INT > & roots);
107 
108  /**
109  * Retrieve the next execution time scheduled in the process queue
110  * @return const C_FLOAT64 & processQueueExecutionTime
111  */
112  const C_FLOAT64 & getProcessQueueExecutionTime() const;
113 
114  const CProcessQueue & getProcessQueue() const;
116 
117  /**
118  * Initialize all values of the math model with their initial values.
119  */
120  void applyInitialValues();
121 
122  /**
123  * Retrieve the number of roots used in checking for discontinuities.
124  * @return size_t numRoots
125  */
126  size_t getNumRoots() const;
127 
128  /**
129  * Calculate the time derivative of all roots
130  * @param CVector< C_FLOAT64 > & rootDerivatives
131  */
132  void calculateRootDerivatives(CVector< C_FLOAT64 > & rootDerivatives);
133 
134  /**
135  * Retrieve a vector of root finders
136  * @return const CVector< CMathTrigger::CRootFinder * > & rootFinders
137  */
139 
140  /**
141  * Build a list of refresh calls needed to assure that required objects
142  * are up to date.
143  * @param const std::set< const CCopasiObject * > & requiredObjects
144  * @return std::vector< Refresh * > refreshList
145  */
146  std::vector< Refresh * > buildRequiredRefreshList(const std::set< const CCopasiObject * > & requiredObjects) const;
147 
148  /**
149  * Build a list of refresh calls needed to assure that all objects
150  * depending on the changed objects are up to date.
151  * @param const std::set< const CCopasiObject * > & changedObjects
152  * @return std::vector< Refresh * > refreshList
153  */
154  std::vector< Refresh * > buildDependendRefreshList(const std::set< const CCopasiObject * > & changedObjects) const;
155 
156 private:
157  /**
158  * Determine whether there are any initial roots and mark them.
159  * @param CVector< C_INT > & foundRoots
160  * @return bool found
161  */
162  bool determineInitialRoots(CVector< C_INT > & foundRoots);
163 
164  /**
165  * Calculate the Jacobian for the roots.
166  * @param CMatrix< C_FLOAT64 > & jacobian
167  * @param const CVector< C_FLOAT64 > & rates
168  */
170  const CVector< C_FLOAT64 > & rates);
171 
172  // Attributes
173 private:
174  /**
175  * The model
176  */
178 
179  /**
180  * The event process queue
181  */
183 
184  /**
185  * List of events
186  */
188 
189  /**
190  * A vector of pointers to the current root finder values
191  */
193 
194  /**
195  * A vector indicating whether a root may only change during
196  * discrete events.
197  */
199 
200  /**
201  * The sequence of refresh calls needed to calculate the current
202  * root values.
203  */
204  std::vector< Refresh * > mRootRefreshes;
205 
206  /**
207  * A map from the index of a root value to the associated event
208  */
210 
211  /**
212  * A map from the index of a root value to the associated root finder
213  */
215 };
216 
217 #endif // COPASI_CMathModel
const C_FLOAT64 & getProcessQueueExecutionTime() const
Definition: CMathModel.cpp:357
CVector< C_FLOAT64 * > mRootValues
Definition: CMathModel.h:192
void calculateRootJacobian(CMatrix< C_FLOAT64 > &jacobian, const CVector< C_FLOAT64 > &rates)
Definition: CMathModel.cpp:591
std::vector< Refresh * > buildRequiredRefreshList(const std::set< const CCopasiObject * > &requiredObjects) const
Definition: CMathModel.cpp:452
void evaluateRoots(CVectorCore< C_FLOAT64 > &rootValues, const bool &ignoreDiscrete)
Definition: CMathModel.cpp:169
void applyInitialValues()
Definition: CMathModel.cpp:372
std::vector< Refresh * > buildDependendRefreshList(const std::set< const CCopasiObject * > &changedObjects) const
Definition: CMathModel.cpp:461
const C_FLOAT64 & getInitialTime() const
Definition: CMathModel.cpp:206
CProcessQueue mProcessQueue
Definition: CMathModel.h:182
virtual ~CMathModel()
Definition: CMathModel.cpp:55
CModel * mpModel
Definition: CMathModel.h:177
CMathModel(const CCopasiContainer *pParent=NULL)
Definition: CMathModel.cpp:21
std::vector< Refresh * > mRootRefreshes
Definition: CMathModel.h:204
iterator(* resolveSimultaneousAssignments)(const std::multimap< CKey, CAction > &, const C_FLOAT64 &, const bool &, const size_t &)
CVector< bool > mRootDiscrete
Definition: CMathModel.h:198
#define C_FLOAT64
Definition: copasi.h:92
Definition: CModel.h:50
CVector< CMathTrigger::CRootFinder * > mRootIndex2RootFinder
Definition: CMathModel.h:214
CCopasiVector< CMathEvent > mEvents
Definition: CMathModel.h:187
void calculateRootDerivatives(CVector< C_FLOAT64 > &rootDerivatives)
Definition: CMathModel.cpp:417
const CProcessQueue & getProcessQueue() const
Definition: CMathModel.cpp:362
CVector< CMathEvent * > mRootIndex2Event
Definition: CMathModel.h:209
size_t getNumRoots() const
Definition: CMathModel.cpp:412
bool determineInitialRoots(CVector< C_INT > &foundRoots)
Definition: CMathModel.cpp:550
const CVector< CMathTrigger::CRootFinder * > & getRootFinders() const
Definition: CMathModel.cpp:447
void processRoots(const C_FLOAT64 &time, const bool &equality, const bool &correct, const CVector< C_INT > &roots)
Definition: CMathModel.cpp:218
bool compile(CModel *pModel)
Definition: CMathModel.cpp:58
bool processQueue(const C_FLOAT64 &time, const bool &equality, CProcessQueue::resolveSimultaneousAssignments pResolveSimultaneousAssignments)
Definition: CMathModel.cpp:211