COPASI API  4.16.103
CTSSAProblem.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/tssanalysis/CTSSAProblem.cpp,v $
3 // $Revision: 1.13 $
4 // $Name: $
5 // $Author: ssahle $
6 // $Date: 2012/04/22 15:41:46 $
7 // End CVS Header
8 
9 // Copyright (C) 2012 - 2011 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  * CTSSAProblem class.
25  * This class describes the time scale separation analysis problem, i.e., it allows to specify
26  * for example initial conditions and number of steps.
27  *
28  */
29 
30 #include <cmath>
31 #include <string>
32 #include <limits.h>
33 
34 #include "copasi.h"
35 #include "CTSSAProblem.h"
36 #include "CTSSATask.h"
37 #include "model/CModel.h"
38 //#include "model/CState.h"
41 
42 /**
43  * Default constructor.
44  */
46  CCopasiProblem(CCopasiTask::timeCourse, pParent),
47  mpDuration(NULL),
48  mpStepSize(NULL),
49  mpStepNumber(NULL),
50  mpTimeSeriesRequested(NULL),
51  mpOutputStartTime(NULL),
52  mStepNumberSetLast(true)
53 {
55  initObjects();
57 }
58 
59 /**
60  * Copy constructor.
61  * @param "const CTSSAProblem &" src
62  */
64  const CCopasiContainer * pParent):
65  CCopasiProblem(src, pParent),
66  mpDuration(NULL),
67  mpStepSize(NULL),
68  mpStepNumber(NULL),
69  mpTimeSeriesRequested(NULL),
70  mpOutputStartTime(NULL),
71  mStepNumberSetLast(src.mStepNumberSetLast)
72 {
74  initObjects();
76 }
77 
78 /**
79  * Destructor.
80  */
83 
85 {
86  mpStepNumber =
87  assertParameter("StepNumber", CCopasiParameter::UINT, (unsigned C_INT32) 100)->getValue().pUINT;
88  mpStepSize =
90  mpDuration =
93  assertParameter("TimeSeriesRequested", CCopasiParameter::BOOL, (bool) true)->getValue().pBOOL;
96 }
97 
99 {
100  // If we have an old COPASI file "Duration" is not set
101  // but we can fix that.
102  if (*mpDuration == 1.0) // the default
104 
105  removeParameter("Deuflhard Tolerance");
106 
107  return true;
108 }
109 
111 {
112  getParameter("StepNumber")->getValueReference()
113  ->setUpdateMethod(this,
114  (void (CTSSAProblem::*)(const C_INT32 &)) &CTSSAProblem::setStepNumber);
115 
116  getParameter("StepSize")->getValueReference()
118 
119  getParameter("Duration")->getValueReference()
121 }
122 
123 /**
124  * Set the number of time steps the trajectory method should integrate.
125  * @param "const unsigned C_INT32 &" stepNumber
126  */
127 void CTSSAProblem::setStepNumber(const unsigned C_INT32 & stepNumber)
128 {
129  *mpStepNumber = stepNumber;
130  mStepNumberSetLast = true;
131  sync();
132 
133  return;
134 }
135 
136 /**
137  * Retrieve the number of time steps the trajectory method should integrate.
138  * @return "const unsigned C_INT32 &" stepNumber
139  */
140 const unsigned C_INT32 & CTSSAProblem::getStepNumber() const
141 {return *mpStepNumber;}
142 
143 /**
144  * Set the size a integration step the trajectory method should do.
145  * @param "const C_FLOAT64 &" stepSize
146  */
147 void CTSSAProblem::setStepSize(const C_FLOAT64 & stepSize)
148 {
149  *mpStepSize = stepSize;
150  mStepNumberSetLast = false;
151  sync();
152 
153  return;
154 }
155 
156 /**
157  * Retrieve the size a integration step the trajectory method should do.
158  * @return "const C_FLOAT64 &" stepSize
159  */
161 {return *mpStepSize;}
162 
163 /**
164  * Set the end time.
165  * @param "const C_FLOAT64 &" duration
166  * @parem bool success
167  */
168 void CTSSAProblem::setDuration(const C_FLOAT64 & duration)
169 {
170  *mpDuration = duration;
171  sync();
172 
173  return;
174 }
175 
176 /**
177  * Retrieve the end time.
178  * @return "const C_FLOAT64 &" duration
179  */
181 {return *mpDuration;}
182 
184 {
185  *mpOutputStartTime = startTime;
186 }
187 
189 {return *mpOutputStartTime;}
190 
192 {
194 }
195 
197 {return *mpTimeSeriesRequested;}
198 
199 /**
200  * This function synchronizes step size and number
201  */
203 {
204  bool success = true;
205 
206  C_FLOAT64 Tmp = *mpDuration;
207  C_FLOAT64 StepSize = *mpStepSize;
208  C_FLOAT64 StepNumber = (C_FLOAT64) * mpStepNumber;
209 
210  if (mStepNumberSetLast)
211  {
212  StepSize = Tmp / (C_FLOAT64) * mpStepNumber;
213 
214  /* Assure that the step size is not to small for machine accuracy */
215  if (fabs(StepSize) < 100.0 * std::numeric_limits< C_FLOAT64 >::epsilon() * fabs(*mpDuration))
216  {
218  MCTSSAProblem + 3, StepSize);
219 
220  StepSize = 100.0 * std::numeric_limits< C_FLOAT64 >::epsilon() * fabs(*mpDuration);
221  /* Assure that the step size has the appropriate sign. */
222  StepSize = (Tmp < 0.0) ? - fabs(StepSize) : fabs(StepSize);
223  StepNumber = fabs(ceil(Tmp / StepSize));
224  }
225  }
226  else
227  {
228  if (fabs(StepSize) < 100.0 * std::numeric_limits< C_FLOAT64 >::epsilon() * fabs(*mpDuration))
229  {
231  MCTSSAProblem + 3, StepSize);
232 
233  StepSize = 100.0 * std::numeric_limits< C_FLOAT64 >::epsilon() * fabs(*mpDuration);
234 
235  /* Assure that the step size has the appropriate sign. */
236  StepSize = (Tmp < 0.0) ? - fabs(StepSize) : fabs(StepSize);
237  }
238 
239  StepNumber = fabs(ceil(Tmp / StepSize));
240 
241  /* Protect against overflow */
242  if ((C_FLOAT64) ULONG_MAX < StepNumber)
243  {
245  MCTSSAProblem + 2, StepNumber);
246 
247  StepNumber = (C_FLOAT64) ULONG_MAX;
248  StepSize = Tmp / StepNumber;
249 
250  success = false;
251  }
252 
253  /* Assure that the step size has the appropriate sign. */
254  StepSize = (Tmp < 0.0) ? - fabs(StepSize) : fabs(StepSize);
255  }
256 
257  *mpStepSize = StepSize;
258  *mpStepNumber = (unsigned C_INT32) StepNumber;
259 
260  if (!success) throw 1;
261 
262  return success;
263 }
264 
265 void CTSSAProblem::printResult(std::ostream * ostream) const
266 {
267  std::ostream & os = *ostream;
268 
269  const CCopasiDataModel* pDataModel = getObjectDataModel();
270  assert(pDataModel != NULL);
271  const CCopasiTask* mpTask =
272  dynamic_cast<const CTSSATask *>((*const_cast<CCopasiDataModel*>(pDataModel)->getTaskList())["Time Scale Separation Analysis"]);
273 
274  if (!mpTask) return;
275 
276  const CCopasiMethod* mpMethod = mpTask->getMethod();
277 
278  this->print(&os);
279 
280  mpMethod->printResult(&os);
281 }
CCopasiDataModel * getObjectDataModel()
void setOutputStartTime(const C_FLOAT64 &endTime)
const C_FLOAT64 & getOutputStartTime() const
virtual void printResult(std::ostream *ostream) const
bool timeSeriesRequested() const
virtual void print(std::ostream *ostream) const
void setStepNumber(const unsigned C_INT32 &stepNumber)
CCopasiObject * getValueReference() const
unsigned C_INT32 * mpStepNumber
Definition: CTSSAProblem.h:49
#define C_INT32
Definition: copasi.h:90
void initObjects()
void setUpdateMethod(CType *pType, void(CType::*method)(const C_FLOAT64 &))
const C_FLOAT64 & getStepSize() const
bool removeParameter(const std::string &name)
#define DESTRUCTOR_TRACE
Definition: copasi.h:206
const Value & getValue() const
const unsigned C_INT32 & getStepNumber() const
unsigned C_INT32 * pUINT
CCopasiParameter * getParameter(const std::string &name)
virtual bool elevateChildren()
#define MCTSSAProblem
C_FLOAT64 * mpStepSize
Definition: CTSSAProblem.h:44
long int flag
Definition: f2c.h:52
void setStepSize(const C_FLOAT64 &stepSize)
CCopasiMethod * getMethod()
C_FLOAT64 * mpOutputStartTime
Definition: CTSSAProblem.h:59
CTSSAProblem(const CCopasiContainer *pParent=NULL)
void initializeParameter()
#define C_FLOAT64
Definition: copasi.h:92
bool * mpTimeSeriesRequested
Definition: CTSSAProblem.h:54
void setDuration(const C_FLOAT64 &duration)
CCopasiParameter * assertParameter(const std::string &name, const CCopasiParameter::Type type, const CType &defaultValue)
void setTimeSeriesRequested(bool flag)
void printResult(std::ostream *ostream) const
C_FLOAT64 * mpDuration
Definition: CTSSAProblem.h:39
#define CONSTRUCTOR_TRACE
Definition: copasi.h:202
const C_FLOAT64 & getDuration() const
bool mStepNumberSetLast
Definition: CTSSAProblem.h:64