COPASI API  4.16.103
CState.h
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/model/CState.h,v $
3 // $Revision: 1.39 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2011/04/01 15:06:43 $
7 // End CVS Header
8 
9 // Copyright (C) 2011 - 2010 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
16 // and The University of Manchester.
17 // All rights reserved.
18 
19 // Copyright (C) 2001 - 2007 by Pedro Mendes, Virginia Tech Intellectual
20 // Properties, Inc. and EML Research, gGmbH.
21 // All rights reserved.
22 
23 /**
24  * CState class.
25  * The class CState stores the state in time of a model. The state
26  * is described for the full model, i.e., updates of all internal
27  * metabolites is expected. The order of metabolites is as in the vector
28  * retrieved by CModel::getMetabolites.
29  * The information is intended to be used with integration routines,
30  * but is not restricted to those.
31  *
32  * Created for COPASI by Stefan Hoops 2002
33  */
34 
35 #ifndef COPASI_CState
36 #define COPASI_CState
37 
38 #include <map>
39 
40 #include "utilities/CVector.h"
41 
42 class CState;
43 class CModel;
44 class CModelEntity;
45 
47 {
48  // Operations
49 private:
50  /**
51  * Default Constructor (inaccessible)
52  */
54 
55 public:
56  /**
57  * Specific constructor
58  * @param CModel & model
59  * @param CState & initialState
60  * @param CState & currentState
61  */
62  CStateTemplate(CModel & model,
63  CState & initialState,
64  CState & currentState);
65 
66  /**
67  * Destructor
68  */
70 
71  /**
72  * Add an entity to the template.
73  * @param CModelEntity * entity
74  */
75  void add(CModelEntity * entity);
76 
77  /**
78  * Remove an entity from the template.
79  * @param CModelEntity * entity
80  */
81  void remove(CModelEntity * entity);
82 
83  /**
84  * Retrieve the index of an entity in the template.
85  * Returns C_INVALID_INDEX if the entity is not found.
86  * @param const CModelEntity * entity
87  * @return size_t index
88  */
89  size_t getIndex(const CModelEntity * entity) const;
90 
91  /**
92  * Reorder the template.
93  * @param const CVector< CModelEntity * > & newOrder
94  */
95  void reorder(const CVector< CModelEntity * > & newOrder);
96 
97  /**
98  * Set the user preferred order of the entities.
99  * @param const CVector< CModelEntity * > & userOrder
100  */
101  void setUserOrder(const CVector< CModelEntity * > & userOrder);
102 
103  /**
104  * Retrieve a pivot vector which can be used to reconstruct the user order.
105  * @return const CVector<size_t> & userOrder
106  */
107  const CVector<size_t> & getUserOrder() const;
108 
109  /**
110  * Retrieve the array of pointers to all entities.
111  * @return CModelEntities ** entities
112  */
114 
115  /**
116  * Retrieve the array of pointers to all independent entities.
117  * @return CModelEntities ** independentEntities
118  */
120 
121  /**
122  * Retrieve pointer just beyond the independent entities.
123  * @return CModelEntities ** endIndependentEntities
124  */
126 
127  /**
128  * Retrieve the array of pointers to all dependent entities,
129  * which are only dependent species for a reduced model.
130  * @return CModelEntities ** dependentEntities
131  */
133 
134  /**
135  * Retrieve pointer just beyond the dependent entities.
136  * @return CModelEntities ** endDependentEntities
137  */
139 
140  /**
141  * Retrieve the array of pointers to all fixed entities.
142  * @return CModelEntities ** fixedEntities
143  */
145 
146  /**
147  * Retrieve pointer just beyond the fixed entities.
148  * @return CModelEntities ** endFixedEntities
149  */
150  CModelEntity ** endFixed();
151 
152  /**
153  * Retrieve the array of pointers to all entities.
154  * @return CModelEntities *const* entities
155  */
156  CModelEntity *const* getEntities() const;
157 
158  /**
159  * Retrieve the array of pointers to all independent entities.
160  * @return CModelEntities *const* independentEntities
161  */
162  CModelEntity *const* beginIndependent() const;
163 
164  /**
165  * Retrieve pointer just beyond the independent entities.
166  * @return CModelEntities *const* endIndependentEntities
167  */
168  CModelEntity *const* endIndependent() const;
169 
170  /**
171  * Retrieve the array of pointers to all dependent entities,
172  * which are only dependent species for a reduced model.
173  * @return CModelEntities *const* dependentEntities
174  */
175  CModelEntity *const* beginDependent() const;
176 
177  /**
178  * Retrieve pointer just beyond the dependent entities.
179  * @return CModelEntities ** endDependentEntities
180  */
181  CModelEntity *const* endDependent() const;
182 
183  /**
184  * Retrieve the array of pointers to all fixed entities.
185  * @return CModelEntities *const* fixedEntities
186  */
187  CModelEntity *const* beginFixed() const;
188 
189  /**
190  * Retrieve pointer just beyond the fixed entities.
191  * @return CModelEntities *const* endFixedEntities
192  */
193  CModelEntity *const* endFixed() const;
194 
195  /**
196  * Retrieve the number of independent entities.
197  * @return size_t numIndependent
198  */
199  size_t getNumIndependent() const;
200 
201  /**
202  * Retrieve the number of dependent entities.
203  * @return size_t numDependent
204  */
205  size_t getNumDependent() const;
206 
207  /**
208  * Retrieve the number of variable entities, i.e., the sum of
209  * independent and dependent variables.
210  * @return size_t numVariable
211  */
212  size_t getNumVariable() const;
213 
214  /**
215  * Retrieve the number of fixed entities.
216  * @return size_t numFixed
217  */
218  size_t getNumFixed() const;
219 
220  /**
221  * Retrieve size of the template, i.e., the number of entities.
222  * @return size_t size
223  */
224  const size_t & size() const;
225 
226 protected:
227  /**
228  * Resize the template
229  */
230  void resize();
231 
232  // Attributes
233 private:
234  /**
235  * A reference to the model
236  */
238 
239  /**
240  * A reference to the initial state of the model
241  */
243 
244  /**
245  * A reference to the current state of the model
246  */
248 
249  /**
250  * The array of entities
251  */
253 
254  /**
255  * The allocate size of the template
256  */
257  size_t mSize;
258 
259  /**
260  * A pointer to the independent entities
261  */
263 
264  /**
265  * A pointer to the dependent entities
266  */
268 
269  /**
270  * A pointer to the fixed entities
271  */
273 
274  /**
275  * A pointer just beyond the entities
276  */
278 
279  /**
280  * The index in which the next added entity must be inserted.
281  */
282  size_t mInsert;
283 
284  /**
285  * A map of pointer to entities to the index it appear in the template
286  */
287  std::map< CModelEntity *, size_t > mIndexMap;
288 
289  /**
290  * A pivot vector storing the user order of the entities
291  */
293 
294  /**
295  * The array of initial values of all entities
296  */
298 
299  /**
300  * The array of current values of all entities
301  */
303 };
304 
305 class CState
306 {
307 public:
308 
309  friend std::ostream &operator << (std::ostream &os, const CState & s);
310 
311  /**
312  * Constructor
313  */
314  CState();
315 
316  /**
317  * Copy constructor
318  * @param const CState & src
319  */
320  CState(const CState & src);
321 
322  /**
323  * Destructor
324  */
325  ~CState();
326 
327  /**
328  * Assignment operator
329  * @param const CState & rhs
330  * @return CState & lhs
331  */
332  CState & operator=(const CState & rhs);
333 
334  /**
335  * Retrieve the time of the state
336  * @return const C_FLOAT64 & time
337  */
338  const C_FLOAT64 & getTime() const;
339 
340  /**
341  * Set the time of the state
342  * @param const C_FLOAT64 & time
343  */
344  void setTime(const C_FLOAT64 & time);
345 
346  /**
347  * Retrieve the array of pointers of values of all independent entities.
348  * @return C_FLOAT64 * independentValues
349  */
351 
352  /**
353  * Retrieve pointer just beyond the values of all independent entities.
354  * @return C_FLOAT64 * endIndependentValues
355  */
357 
358  /**
359  * Retrieve the array of pointers of values of all dependent entities,
360  * which are only dependent species for a reduced model.
361  * @return C_FLOAT64 * dependentValues
362  */
364 
365  /**
366  * Retrieve pointer just beyond the values of all dependent entities.
367  * @return C_FLOAT64 * endDependentValues
368  */
370 
371  /**
372  * Retrieve the array of pointers of values of all fixed entities.
373  * @return C_FLOAT64 * fixedValues
374  */
375  C_FLOAT64 * beginFixed();
376 
377  /**
378  * Retrieve pointer just beyond the values of all fixed entities.
379  * @return C_FLOAT64 * endFixedValues
380  */
381  C_FLOAT64 * endFixed();
382 
383  /**
384  * Retrieve the array of pointers of values of all independent entities.
385  * @return const C_FLOAT64 * independentValues
386  */
387  const C_FLOAT64 * beginIndependent() const;
388 
389  /**
390  * Retrieve pointer just beyond the values of all independent entities.
391  * @return const C_FLOAT64 * endIndependentValues
392  */
393  const C_FLOAT64 * endIndependent() const;
394 
395  /**
396  * Retrieve the array of pointers of values of all dependent entities,
397  * which are only dependent species for a reduced model.
398  * @return const C_FLOAT64 * dependentValues
399  */
400  const C_FLOAT64 * beginDependent() const;
401 
402  /**
403  * Retrieve pointer just beyond the values of all dependent entities.
404  * @return const C_FLOAT64 * endDependentValues
405  */
406  const C_FLOAT64 * endDependent() const;
407 
408  /**
409  * Retrieve the array of pointers of values of all fixed entities.
410  * @return const C_FLOAT64 * fixedValues
411  */
412  const C_FLOAT64 * beginFixed() const;
413 
414  /**
415  * Retrieve pointer just beyond the values of all fixed entities.
416  * @return const C_FLOAT64 * endFixedValues
417  */
418  const C_FLOAT64 * endFixed() const;
419 
420  /**
421  * Retrieve the number of independent entities.
422  * @return size_t numIndependent
423  */
424  size_t getNumIndependent() const;
425 
426  /**
427  * Retrieve the number of dependent entities.
428  * @return size_t numDependent
429  */
430  size_t getNumDependent() const;
431 
432  /**
433  * Retrieve the number of variable entities, i.e., the sum of
434  * independent and dependent variables.
435  * @return size_t numVariable
436  */
437  size_t getNumVariable() const;
438 
439  /**
440  * Retrieve the number of fixed entities.
441  * @return size_t numFixed
442  */
443  size_t getNumFixed() const;
444 
445  /**
446  * Check whether the current state is valid (contains no NaN)
447  * @return bool isValid
448  */
449  bool isValid() const;
450 
451 protected:
452  // These methods are only accessible from CStateTemplate
453  friend class CStateTemplate;
454  C_FLOAT64 * resize(const size_t & size);
455 
456  /**
457  * Update the pointers to the different types of entities
458  * @param const size_t & numIndependent
459  * @param const size_t & numDependent
460  * @param const size_t & numFixed
461  */
462  void updateIterator(const size_t & numIndependent,
463  const size_t & numDependent,
464  const size_t & numFixed);
465 
466 private:
467  /**
468  * Array of entity values
469  */
471 
472  /**
473  * Size of the state
474  */
475  size_t mSize;
476 
477  /**
478  * Pointer to the beginning of values of independent entities.
479  */
481 
482  /**
483  * Pointer to the beginning of values of dependent entities.
484  */
486 
487  /**
488  * Pointer to the beginning of values of fixed entities.
489  */
491 
492  /**
493  * Pointer just beyond the values of fixed entities.
494  */
496 
497  /**
498  * Indicates whether the state is of a reduced or complete model
499  */
501 };
502 
503 #endif
C_FLOAT64 * mpEnd
Definition: CState.h:495
friend std::ostream & operator<<(std::ostream &os, const CState &s)
Definition: CState.cpp:398
CState()
Definition: CState.cpp:279
CVector< size_t > mUserOrder
Definition: CState.h:292
void setUserOrder(const CVector< CModelEntity * > &userOrder)
Definition: CState.cpp:189
size_t getNumFixed() const
Definition: CState.cpp:228
size_t getNumIndependent() const
Definition: CState.cpp:222
void add(CModelEntity *entity)
Definition: CState.cpp:63
C_FLOAT64 * mpBeginFixed
Definition: CState.h:490
C_FLOAT64 * mpBeginIndependent
Definition: CState.h:480
CModelEntity ** mpEnd
Definition: CState.h:277
Definition: CState.h:305
size_t getIndex(const CModelEntity *entity) const
Definition: CState.cpp:231
CModelEntity ** endDependent()
Definition: CState.cpp:211
size_t getNumVariable() const
Definition: CState.cpp:346
const size_t & size() const
Definition: CState.cpp:242
CModelEntity ** mpBeginDependent
Definition: CState.h:267
CModelEntity ** beginDependent()
Definition: CState.cpp:210
void setTime(const C_FLOAT64 &time)
Definition: CState.cpp:326
CModelEntity ** mpBeginIndependent
Definition: CState.h:262
C_FLOAT64 * mpBeginDependent
Definition: CState.h:485
C_FLOAT64 * endDependent()
Definition: CState.cpp:331
C_FLOAT64 * endIndependent()
Definition: CState.cpp:329
C_FLOAT64 * endFixed()
Definition: CState.cpp:333
size_t getNumDependent() const
Definition: CState.cpp:344
bool mUpdateDependentRequired
Definition: CState.h:500
size_t getNumFixed() const
Definition: CState.cpp:348
C_FLOAT64 * mpCurrentValues
Definition: CState.h:302
CModelEntity ** endFixed()
Definition: CState.cpp:213
CModelEntity ** mpEntities
Definition: CState.h:252
CState & mInitialState
Definition: CState.h:242
CModelEntity ** beginFixed()
Definition: CState.cpp:212
size_t getNumIndependent() const
Definition: CState.cpp:342
CModelEntity ** beginIndependent()
Definition: CState.cpp:208
size_t mSize
Definition: CState.h:475
CState & mCurrentState
Definition: CState.h:247
std::map< CModelEntity *, size_t > mIndexMap
Definition: CState.h:287
bool isValid() const
Definition: CState.cpp:351
const C_FLOAT64 & getTime() const
Definition: CState.cpp:325
void resize()
Definition: CState.cpp:245
size_t getNumDependent() const
Definition: CState.cpp:224
#define C_FLOAT64
Definition: copasi.h:92
void updateIterator(const size_t &numIndependent, const size_t &numDependent, const size_t &numFixed)
Definition: CState.cpp:388
size_t mInsert
Definition: CState.h:282
size_t mSize
Definition: CState.h:257
C_FLOAT64 * mpValues
Definition: CState.h:470
Definition: CModel.h:50
C_FLOAT64 * beginFixed()
Definition: CState.cpp:332
const CVector< size_t > & getUserOrder() const
Definition: CState.cpp:201
C_FLOAT64 * beginDependent()
Definition: CState.cpp:330
CModel & mModel
Definition: CState.h:237
C_FLOAT64 * resize(const size_t &size)
Definition: CState.cpp:365
~CState()
Definition: CState.cpp:301
CModelEntity ** endIndependent()
Definition: CState.cpp:209
CModelEntity ** mpBeginFixed
Definition: CState.h:272
C_FLOAT64 * beginIndependent()
Definition: CState.cpp:328
void reorder(const CVector< CModelEntity * > &newOrder)
Definition: CState.cpp:98
CModelEntity ** getEntities()
Definition: CState.cpp:204
C_FLOAT64 * mpInitialValues
Definition: CState.h:297
CState & operator=(const CState &rhs)
Definition: CState.cpp:303
size_t getNumVariable() const
Definition: CState.cpp:226