COPASI API  4.16.103
CTrajectoryProblem.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 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 // 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) 2002 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 /**
16  * CTrajectoryProblem class.
17  * This class describes the trajectory problem, i.e., it allows to specify
18  * for example initial conditions and number of steps.
19  *
20  * Created for COPASI by Stefan Hoops 2002
21  */
22 
23 #include <limits.h>
24 #include <cmath>
25 #include <string>
26 
27 #include "copasi.h"
28 #include "CTrajectoryProblem.h"
29 #include "model/CModel.h"
30 //#include "model/CState.h"
33 
34 /**
35  * Default constructor.
36  */
38  CCopasiProblem(CCopasiTask::timeCourse, pParent),
39  mpDuration(NULL),
40  mpStepSize(NULL),
41  mpStepNumber(NULL),
42  mpTimeSeriesRequested(NULL),
43  mpOutputStartTime(NULL),
44  mpOutputEvent(NULL),
45  mpContinueSimultaneousEvents(NULL),
46  mStepNumberSetLast(true)
47 {
49  initObjects();
51 }
52 
53 /**
54  * Copy constructor.
55  * @param "const CTrajectoryProblem &" src
56  */
58  const CCopasiContainer * pParent):
59  CCopasiProblem(src, pParent),
60  mpDuration(NULL),
61  mpStepSize(NULL),
62  mpStepNumber(NULL),
63  mpTimeSeriesRequested(NULL),
64  mpOutputStartTime(NULL),
65  mpOutputEvent(NULL),
66  mpContinueSimultaneousEvents(NULL),
67  mStepNumberSetLast(src.mStepNumberSetLast)
68 {
70  initObjects();
72 }
73 
74 /**
75  * Destructor.
76  */
79 
81 {
82  mpStepNumber =
83  assertParameter("StepNumber", CCopasiParameter::UINT, (unsigned C_INT32) 100)->getValue().pUINT;
84  mpStepSize =
86  mpDuration =
89  assertParameter("TimeSeriesRequested", CCopasiParameter::BOOL, (bool) true)->getValue().pBOOL;
93  assertParameter("Output Event", CCopasiParameter::BOOL, (bool) false)->getValue().pBOOL;
95  assertParameter("Continue on Simultaneous Events", CCopasiParameter::BOOL, (bool) false)->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  return true;
106 }
107 
109 {
110  getParameter("StepNumber")->getValueReference()
111  ->setUpdateMethod(this,
113 
114  getParameter("StepSize")->getValueReference()
116 
117  getParameter("Duration")->getValueReference()
119 }
120 
121 /**
122  * Set the number of time steps the trajectory method should integrate.
123  * @param "const unsigned C_INT32 &" stepNumber
124  */
125 void CTrajectoryProblem::setStepNumber(const unsigned C_INT32 & stepNumber)
126 {
127  *mpStepNumber = stepNumber;
128  mStepNumberSetLast = true;
129  sync();
130 
131  return;
132 }
133 
134 /**
135  * Retrieve the number of time steps the trajectory method should integrate.
136  * @return "const unsigned C_INT32 &" stepNumber
137  */
139 {return *mpStepNumber;}
140 
141 /**
142  * Set the size a integration step the trajectory method should do.
143  * @param "const C_FLOAT64 &" stepSize
144  */
146 {
147  *mpStepSize = stepSize;
148  mStepNumberSetLast = false;
149  sync();
150 
151  return;
152 }
153 
154 /**
155  * Retrieve the size a integration step the trajectory method should do.
156  * @return "const C_FLOAT64 &" stepSize
157  */
159 {return *mpStepSize;}
160 
161 /**
162  * Set the end time.
163  * @param "const C_FLOAT64 &" duration
164  * @parem bool success
165  */
167 {
168  *mpDuration = duration;
169  sync();
170 
171  return;
172 }
173 
174 /**
175  * Retrieve the end time.
176  * @return "const C_FLOAT64 &" duration
177  */
179 {return *mpDuration;}
180 
182 {
183  *mpOutputStartTime = startTime;
184 }
185 
187 {return *mpOutputStartTime;}
188 
190 {
192 }
193 
195 {return *mpTimeSeriesRequested;}
196 
197 void CTrajectoryProblem::setOutputEvent(const bool & outputEvent)
198 {
199  *mpOutputEvent = outputEvent;
200 }
201 
203 {return *mpOutputEvent;}
204 
205 void CTrajectoryProblem::setContinueSimultaneousEvents(const bool & continueSimultaneousEvents)
206 {
207  *mpContinueSimultaneousEvents = continueSimultaneousEvents;
208 }
209 
211 {
213 }
214 
215 /**
216  * Load a trajectory problem
217  * @param "CReadConfig &" configBuffer
218  */
221 {
222  if (configBuffer.getVersion() < "4.0")
223  {
224  CCopasiDataModel* pDataModel = getObjectDataModel();
225  assert(pDataModel != NULL);
226  mpModel = pDataModel->getModel();
227  configBuffer.getVariable("EndTime", "C_FLOAT64",
228  mpDuration,
230  configBuffer.getVariable("Points", "C_INT32",
231  mpStepNumber);
232  mStepNumberSetLast = true;
233 
234  sync();
235  }
236 }
237 
238 /**
239  * This function synchronizes step size and number
240  */
242 {
243  bool success = true;
244 
246  return success;
247 
248  C_FLOAT64 Tmp = *mpDuration;
249  C_FLOAT64 StepSize = *mpStepSize;
250  C_FLOAT64 StepNumber = (C_FLOAT64) * mpStepNumber;
251 
252  if (mStepNumberSetLast)
253  {
254  StepSize = Tmp / (C_FLOAT64) * mpStepNumber;
255 
256  /* Assure that the step size is not to small for machine accuracy */
257  if (fabs(StepSize) < 100.0 * std::numeric_limits< C_FLOAT64 >::epsilon() * fabs(*mpDuration))
258  {
260  MCTrajectoryProblem + 3, StepSize);
261 
262  StepSize = 100.0 * std::numeric_limits< C_FLOAT64 >::epsilon() * fabs(*mpDuration);
263  /* Assure that the step size has the appropriate sign. */
264  StepSize = (Tmp < 0.0) ? - fabs(StepSize) : fabs(StepSize);
265  StepNumber = fabs(ceil(Tmp / StepSize));
266  }
267  }
268  else
269  {
270  if (fabs(StepSize) < 100.0 * std::numeric_limits< C_FLOAT64 >::epsilon() * fabs(*mpDuration))
271  {
273  MCTrajectoryProblem + 3, StepSize);
274 
275  StepSize = 100.0 * std::numeric_limits< C_FLOAT64 >::epsilon() * fabs(*mpDuration);
276 
277  /* Assure that the step size has the appropriate sign. */
278  StepSize = (Tmp < 0.0) ? - fabs(StepSize) : fabs(StepSize);
279  }
280 
281  StepNumber = fabs(ceil(Tmp / StepSize));
282 
283  /* Protect against overflow */
284  if ((C_FLOAT64) ULONG_MAX < StepNumber)
285  {
287  MCTrajectoryProblem + 2, StepNumber);
288 
289  StepNumber = (C_FLOAT64) ULONG_MAX;
290  StepSize = Tmp / StepNumber;
291  }
292 
293  /* Assure that the step size has the appropriate sign. */
294  StepSize = (Tmp < 0.0) ? - fabs(StepSize) : fabs(StepSize);
295  }
296 
297  *mpStepSize = StepSize;
298  *mpStepNumber = (unsigned C_INT32) StepNumber;
299 
300  return success;
301 }
CCopasiDataModel * getObjectDataModel()
void setContinueSimultaneousEvents(const bool &continueSimultaneousEvents)
const unsigned C_INT32 & getStepNumber() const
CCopasiObject * getValueReference() const
void setDuration(const C_FLOAT64 &duration)
std::string getVersion()
Definition: CReadConfig.cpp:76
#define C_UNUSED(p)
Definition: copasi.h:220
#define C_INT32
Definition: copasi.h:90
unsigned C_INT32 * mpStepNumber
void setUpdateMethod(CType *pType, void(CType::*method)(const C_FLOAT64 &))
#define DESTRUCTOR_TRACE
Definition: copasi.h:206
const C_FLOAT64 & getStepSize() const
#define MCTrajectoryProblem
void setStepSize(const C_FLOAT64 &stepSize)
const C_FLOAT64 & getDuration() const
void setOutputEvent(const bool &outputEvent)
void setTimeSeriesRequested(bool flag)
const Value & getValue() const
void setStepNumber(const unsigned C_INT32 &stepNumber)
unsigned C_INT32 * pUINT
virtual bool elevateChildren()
CCopasiParameter * getParameter(const std::string &name)
long int flag
Definition: f2c.h:52
C_FLOAT64 * mpOutputStartTime
const C_FLOAT64 & getOutputStartTime() const
bool timeSeriesRequested() const
#define C_FLOAT64
Definition: copasi.h:92
CCopasiParameter * assertParameter(const std::string &name, const CCopasiParameter::Type type, const CType &defaultValue)
void setOutputStartTime(const C_FLOAT64 &endTime)
C_INT32 getVariable(const std::string &name, const std::string &type, void *pout, CReadConfig::Mode mode=CReadConfig::NEXT)
Definition: CReadConfig.cpp:81
CModel * mpModel
void load(CReadConfig &configBuffer, CReadConfig::Mode mode=CReadConfig::NEXT)
const bool & getContinueSimultaneousEvents() const
#define min(a, b)
Definition: f2c.h:175
CTrajectoryProblem(const CCopasiContainer *pParent=NULL)
#define CONSTRUCTOR_TRACE
Definition: copasi.h:202
const bool & getOutputEvent() const