COPASI API  4.16.103
CTSSAMethod.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) 2008 - 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 // Copyright (C) 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 /**
16  * CTSSAMethod class.
17  * This class describes the interface to all time scale separation analysis methods.
18  * The various method like ILDM or CSP have to be derived from
19  * this class.
20  *
21  */
22 
23 #ifndef COPASI_CTSSAMethod
24 #define COPASI_CTSSAMethod
25 
26 #include <string>
27 #include <sstream>
28 
33 
36 
37 class CTSSAProblem;
38 class CModel;
39 class CState;
40 
41 class CTSSAMethod : public CCopasiMethod
42 {
43 protected:
44  /**
45  * A pointer to the current state. This is set from outside
46  * with the setState() method and never changed anywhere else.
47  * It�s used to report the results
48  * to the calling TSSATask
49  */
51 
52  /**
53  * A pointer to the time scale separation analysis problem.
54  */
56 
57  // Operations
58 private:
59  /**
60  * Default constructor.
61  */
62  CTSSAMethod();
63 
64 protected:
65  /**
66  * Default constructor.
67  * @param const CCopasiMethod::SubType & subType
68  * @param const CCopasiContainer * pParent (default: NULL)
69  */
70  CTSSAMethod(const CCopasiMethod::SubType & subType,
71  const CCopasiContainer * pParent = NULL);
72 
73 public:
74 
75  /**
76  * Create a time scale separation analysis method for a special problem.
77  * Note: the returned object has to be released after use with delete
78  * a problem is also passed so that the method has a chance to choose an
79  * appropriate simulation method.
80  */
81  static CTSSAMethod *
83 
84  /**
85  * Copy constructor.
86  * @param "const CTSSAMethod &" src
87  * @param const CCopasiContainer * pParent (default: NULL)
88  */
89  CTSSAMethod(const CTSSAMethod & src,
90  const CCopasiContainer * pParent = NULL);
91 
92  /**
93  * Destructor.
94  */
95  ~CTSSAMethod();
96 
97  std::map< std::string, CArrayAnnotation* > mapTableToName;
98  std::vector<std::string> tableNames;
99 
100  const std::vector<std::string> getTableName() const
101  {return tableNames;}
102 
103  const CArrayAnnotation* getTable(std::string name)
104  {return mapTableToName[name];}
105 
106  //virtual void setAnnotationM(int s) = 0;
107  virtual bool setAnnotationM(size_t s) = 0;
108 
109  /**
110  * Set the Model
111  */
112  void setModel(CModel* model);
113 
114  /**
115  * Predefine the CArrayAnnotation for plots
116  */
117  virtual void predifineAnnotation();
118 
119  /**
120  * Set a pointer to the current state.
121  * This method is used by CTSSATask::process()
122  * The results of the simulation are passed via this CState variable
123  * @param "CState *" currentState
124  */
125  void setCurrentState(CState * currentState);
126 
127  /**
128  * Set a pointer to the problem.
129  * This method is used by CTSSA
130  * @param "CTSSAProblem *" problem
131  */
132  void setProblem(CTSSAProblem * problem);
133 
134  /**
135  * This instructs the method to calculate a time step of deltaT
136  * starting with the current state, i.e., the result of the previous
137  * step.
138  * The new state (after deltaT) is expected in the current state.
139  * The return value is the actual timestep taken.
140  * @param "const double &" deltaT
141  */
142  virtual void step(const double & deltaT);
143 
144  /**
145  * This instructs the method to prepare for integration
146  * starting with the initialState given.
147  * @param "const CState *" initialState
148  */
149  virtual void start(const CState * initialState);
150 
151  /**
152  * Check if the method is suitable for this problem
153  * @return bool suitability of the method
154  */
155  virtual bool isValidProblem(const CCopasiProblem * pProblem);
156 
157  /**
158  * Initialize the method parameter
159  */
160  virtual void initializeParameter();
161 
162  /************ The following concerns the both ILDM Methods *******************************/
163 
164 protected:
165 
166  struct Data
167  {
170  };
171 
172  /**
173  * A pointer to the current state in complete model view.
174  */
176 
177  /**
178  * mData.dim is the dimension of the ODE system.
179  */
181 
182  /**
183  * Pointer to the array with left hand side values.
184  */
186 
187  /**
188  * Vector containing the derivatives after calling eval
189  */
191 
192  /**
193  *
194  */
196 
197  /**
198  * Current time.
199  */
201 
202  /**
203  * Jacobian matrix
204  */
206 
207  /**
208  * Jacobian matrix at initial point
209  */
211 
212  /**
213  *
214  */
217  /**
218  *
219  */
222  /**
223  *
224  */
226 
227  /**
228  *
229  */
231 
232  /**
233  *
234  */
236 
237  /**
238  *
239  */
241  /**
242  *
243  */
245 
246  /**
247  *
248  */
249 
251 
252  /**
253  *
254  */
255 
257 
258  /**
259  *
260  */
262 
263  /**
264  *
265  */
267 
268  /**
269  *
270  */
272 
273  /**
274  *
275  */
277 
278  /**
279  *
280  */
282 
283  /**
284  * LSODA state.
285  */
287 
288  /**
289  * Whether to use the reduced model
290  */
292 
293  /**
294  * Relative tolerance.
295  */
297 
298  /**
299  * A vector of absolute tolerances.
300  */
302 
303  /**
304  * Stream to capture LSODA error messages
305  */
306  std::ostringstream mErrorMsg;
307 
308  /**
309  * The LSODA integrator
310  */
312 
313  /**
314  * The state of the integrator
315  */
317 
318  /**
319  * LSODA C_FLOAT64 work area
320  */
322 
323  /**
324  * LSODA C_INT work area
325  */
327 
328  /**
329  * The way LSODA calculates the jacobian
330  */
332 
333  /**
334  * A pointer to the model
335  */
337 
338  /**
339  * Tolerance for Deuflhard criterium
340  */
342 
343  /**
344  *
345  */
347 
348  // Operations
349 
350  /**
351  * Initialize integration method parameters
352  */
353 
355 
356  /**
357  * This methods must be called to elevate subgroups to
358  * derived objects. The default implementation does nothing.
359  * @return bool success
360  */
361  bool elevateChildren();
362 
363  /**
364  * This instructs the method to calculate a time step of deltaT
365  * starting with the current state, i.e., the result of the previous
366  * step.
367  * The new state (after deltaT) is expected in the current state.
368  * The return value is the actual timestep taken.
369  * @param "const double &" deltaT
370  **/
371 
372  /**
373  **/
374  void integrationStep(const double & deltaT);
375 
376  /**
377  * This instructs the method to prepare for integration
378  * starting with the initialState given.
379  * @param "const CState *" initialState
380  */
381  void integrationMethodStart(const CState * initialState);
382 
383  /**
384  * Calculate the individual absolute tolerance
385  */
386  void initializeAtol();
387 
388  static void EvalF(const C_INT * n, const C_FLOAT64 * t, const C_FLOAT64 * y, C_FLOAT64 * ydot);
389 
390  /**
391  * This evaluates the derivatives
392  */
393  void evalF(const C_FLOAT64 * t, const C_FLOAT64 * y, C_FLOAT64 * ydot);
394 
395  /**
396  *
397  */
398  void schur(C_INT &info);
399  void schur_desc(C_INT &info);
400 
401  /**
402  *
403  */
404  void sylvester(C_INT slow, C_INT & info);
405 
406  /**
407  *
408  **/
409  void map_index(C_FLOAT64 *eval_r, C_INT *index, const C_INT & dim);
410 
411  void map_index_desc(C_FLOAT64 *eval_r, C_INT *index, const C_INT & dim);
412  /**
413  *
414  **/
415  void update_nid(C_INT *index, C_INT *nid, const C_INT & dim);
416 
417  /**
418  *
419  **/
420  void update_pid(C_INT *index, C_INT *pid, const C_INT & dim);
421 
422  /**
423  *
424  **/
425  void calculateDerivativesX(C_FLOAT64 * X1, C_FLOAT64 * Y1);
426 
427  void calculateDerivatives(C_FLOAT64 * X1, C_FLOAT64 * Y1);
428 
429  /**
430  * This is not very elegant solution. But I don't know the better one.
431  **/
432 
433  // void calculateNextJacobian(const double & deltaT);
434 
435  /**
436  *
437  **/
438  void mat_anal_mod(C_INT & slow);
439 
440  /**
441  *
442  **/
443  void mat_anal_metab(C_INT & slow);
444 
445  /**
446  *
447  **/
448  void mat_anal_mod_space(C_INT & slow);
449  void mat_anal_fast_space(C_INT & slow);
450  void mat_anal_fast_space_thomas(C_INT & slow);
451  /**
452  *
453  **/
454  double orthog(C_INT & number1, C_INT & number2);
455 
456  /**
457  *vectors contain whole data for all calculationsteps
458  **/
459  std::vector< C_INT > mVec_SlowModes;
460  std::vector< C_FLOAT64 > mCurrentTime;
461  std::vector< CVector<C_FLOAT64> > mVec_TimeScale;
462 
463  /**
464  * stepcounter
465  **/
467 
468 public:
469  /**
470  * Retrieve the current step
471  */
472  const int & getCurrentStep() const;
473 
474  /**
475  * return mVec_TimeScale for visualization in ILDM-tab
476  * in the CQTSSAResultSubWidget
477  **/
479 
480  /**
481  *return required time-value from timevector
482  **/
484 
485  /**
486  * upgrade all vectors with values from actually calculalion for current step
487  **/
488  void setVectors(int slowMode);
489 
490  /**
491  * empty every vector to be able to fill them with new values for a
492  * new calculation also nullify the step counter
493  **/
494  void emptyVectors();
495 
496  /**
497  * create the CArraAnnotations for every ILDM-tab in the CQTSSAResultSubWidget
498  * input for each CArraAnnotations is a seperate CMatrix
499  **/
500  void createAnnotationsM();
501 };
502 
503 #endif // COPASI_CTSSAMethod
void schur(C_INT &info)
void update_pid(C_INT *index, C_INT *pid, const C_INT &dim)
C_FLOAT64 mEPS
Definition: CTSSAMethod.h:346
#define C_INT
Definition: copasi.h:115
void mat_anal_fast_space_thomas(C_INT &slow)
void sylvester(C_INT slow, C_INT &info)
const CArrayAnnotation * getTable(std::string name)
Definition: CTSSAMethod.h:103
void update_nid(C_INT *index, C_INT *nid, const C_INT &dim)
void setCurrentState(CState *currentState)
std::vector< C_FLOAT64 > mCurrentTime
Definition: CTSSAMethod.h:460
CTSSAProblem * mpProblem
Definition: CTSSAMethod.h:55
CVector< C_FLOAT64 > mYdot
Definition: CTSSAMethod.h:190
CMatrix< C_FLOAT64 > mVslow
Definition: CTSSAMethod.h:261
const int & getCurrentStep() const
CMatrix< C_FLOAT64 > mTdInverse
Definition: CTSSAMethod.h:230
virtual void initializeParameter()
CVector< C_FLOAT64 > mY_initial
Definition: CTSSAMethod.h:195
CState * mpState
Definition: CTSSAMethod.h:175
void createAnnotationsM()
CModel * mpModel
Definition: CTSSAMethod.h:336
std::map< std::string, CArrayAnnotation * > mapTableToName
Definition: CTSSAMethod.h:97
CState * mpCurrentState
Definition: CTSSAMethod.h:50
CVector< C_FLOAT64 > mVslow_space
Definition: CTSSAMethod.h:271
CVector< C_FLOAT64 > mDWork
Definition: CTSSAMethod.h:321
virtual void predifineAnnotation()
void initializeIntegrationsParameter()
static CTSSAMethod * createMethod(CCopasiMethod::SubType subType=CCopasiMethod::unset)
Definition: CTSSAMethod.cpp:44
Definition: CState.h:305
CMatrix< C_FLOAT64 > mTd_save
Definition: CTSSAMethod.h:240
void integrationStep(const double &deltaT)
C_FLOAT64 mDtol
Definition: CTSSAMethod.h:341
CVector< C_FLOAT64 > mAtol
Definition: CTSSAMethod.h:301
void schur_desc(C_INT &info)
void setVectors(int slowMode)
std::ostringstream mErrorMsg
Definition: CTSSAMethod.h:306
void map_index(C_FLOAT64 *eval_r, C_INT *index, const C_INT &dim)
CVector< C_INT > mIWork
Definition: CTSSAMethod.h:326
double orthog(C_INT &number1, C_INT &number2)
CMatrix< C_FLOAT64 > mQ
Definition: CTSSAMethod.h:215
CMatrix< C_FLOAT64 > mTdInverse_save
Definition: CTSSAMethod.h:244
const std::vector< std::string > getTableName() const
Definition: CTSSAMethod.h:100
void mat_anal_mod_space(C_INT &slow)
CVector< C_FLOAT64 > mVfast_space
Definition: CTSSAMethod.h:276
void map_index_desc(C_FLOAT64 *eval_r, C_INT *index, const C_INT &dim)
static void EvalF(const C_INT *n, const C_FLOAT64 *t, const C_FLOAT64 *y, C_FLOAT64 *ydot)
CMatrix< C_FLOAT64 > mQ_desc
Definition: CTSSAMethod.h:216
CMatrix< C_FLOAT64 > mJacobian_initial
Definition: CTSSAMethod.h:210
void calculateDerivativesX(C_FLOAT64 *X1, C_FLOAT64 *Y1)
bool elevateChildren()
CMatrix< C_FLOAT64 > mR_desc
Definition: CTSSAMethod.h:221
std::vector< std::string > tableNames
Definition: CTSSAMethod.h:98
Definition: CLSODA.h:24
void calculateDerivatives(C_FLOAT64 *X1, C_FLOAT64 *Y1)
void mat_anal_fast_space(C_INT &slow)
int mCurrentStep
Definition: CTSSAMethod.h:466
bool mReducedModel
Definition: CTSSAMethod.h:291
CVector< C_FLOAT64 > mY_cons
Definition: CTSSAMethod.h:256
virtual bool isValidProblem(const CCopasiProblem *pProblem)
void setModel(CModel *model)
CMatrix< C_FLOAT64 > mQz
Definition: CTSSAMethod.h:235
virtual bool setAnnotationM(size_t s)=0
CVector< C_FLOAT64 > getVec_TimeScale(int step)
CLSODA mLSODA
Definition: CTSSAMethod.h:311
void mat_anal_metab(C_INT &slow)
CMatrix< C_FLOAT64 > mR
Definition: CTSSAMethod.h:220
C_INT mState
Definition: CTSSAMethod.h:316
C_FLOAT64 mRtol
Definition: CTSSAMethod.h:296
std::vector< CVector< C_FLOAT64 > > mVec_TimeScale
Definition: CTSSAMethod.h:461
CMatrix< C_FLOAT64 > mJacobian
Definition: CTSSAMethod.h:205
Header file of class CArrayAnnotation.
#define C_FLOAT64
Definition: copasi.h:92
C_FLOAT64 returnCurrentTime(int step)
void setProblem(CTSSAProblem *problem)
void emptyVectors()
virtual void start(const CState *initialState)
CMatrix< C_FLOAT64 > mTd
Definition: CTSSAMethod.h:225
Definition: CModel.h:50
C_INT mJType
Definition: CTSSAMethod.h:331
virtual void step(const double &deltaT)
C_FLOAT64 mTime
Definition: CTSSAMethod.h:200
void integrationMethodStart(const CState *initialState)
std::vector< C_INT > mVec_SlowModes
Definition: CTSSAMethod.h:459
CTSSAMethod * pMethod
Definition: CTSSAMethod.h:169
C_INT mLsodaStatus
Definition: CTSSAMethod.h:286
void mat_anal_mod(C_INT &slow)
CMatrix< C_FLOAT64 > mVslow_metab
Definition: CTSSAMethod.h:266
void initializeAtol()
CVector< C_FLOAT64 > mCfast
Definition: CTSSAMethod.h:250
C_FLOAT64 * mY
Definition: CTSSAMethod.h:185
void evalF(const C_FLOAT64 *t, const C_FLOAT64 *y, C_FLOAT64 *ydot)