COPASI API  4.16.103
CMCAProblem.cpp
Go to the documentation of this file.
1 /* Begin CVS Header
2 $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/steadystate/CMCAProblem.cpp,v $
3 $Revision: 1.17 $
4 $Name: $
5 $Author: shoops $
6 $Date: 2010/09/09 12:02:06 $
7 End CVS Header */
8 
9 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
11 // and The University of Manchester.
12 // All rights reserved.
13 
14 // Copyright (C) 2001 - 2007 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc. and EML Research, gGmbH.
16 // All rights reserved.
17 
18 /**
19  * CMCAProblem class.
20  * This class describes the metabolic control analysis problem, i.e., it allows to specify
21  * for example initial conditions.
22  *
23  * Created for Copasi by Ralph Gauges 2004
24  */
25 
26 #include <string>
27 
28 #include "copasi.h"
29 #include "CMCAProblem.h"
30 #include "CMCATask.h"
31 #include "CSteadyStateTask.h"
32 
35 #include "model/CModel.h"
36 #include "model/CState.h"
37 #include "report/CKeyFactory.h"
38 
39 /**
40  * Default constructor.
41  * @param "CModel *" pModel
42  */
44  CCopasiProblem(CCopasiTask::mca, pParent),
45  mInitialState()
46 {
47  // addParameter("SteadyStateRequested", CCopasiParameter::BOOL, true);
48  addParameter("Steady-State", CCopasiParameter::KEY, std::string(""));
50 }
51 
52 /**
53  * Copy constructor.
54  * @param "const CMCAProblem &" src
55  */
57  const CCopasiContainer * pParent):
58  CCopasiProblem(src, pParent)
60 
61 /**
62  * Destructor.
63  */
66 
67 /**
68  * Set the model the problem is dealing with.
69  * @param "CModel *" pModel
70  */
72 {
73  mpModel = pModel;
74  return true;
75 }
76 
77 /**
78  * Load a mca problem
79  * @param "CReadConfig &" configBuffer
80  */
81 void CMCAProblem::load(CReadConfig & configBuffer,
83 {
84  if (configBuffer.getVersion() < "4.0")
85  {
86  bool SteadyStateRequested;
87  configBuffer.getVariable("RepxSteadyStateAnalysis", "bool" ,
88  &SteadyStateRequested,
90 
91  setSteadyStateRequested(SteadyStateRequested);
92  }
93 }
94 
95 /**
96  * Set the initial state of the problem.
97  * @param const CState & initialState
98  */
99 void CMCAProblem::setInitialState(const CState & initialState)
100 {
101  mInitialState = initialState;
102 }
103 
104 #ifdef XXXX
105 /**
106  * Set the initial state of the problem.
107  * @param const CStateX & InitialState
108  */
109 void CMCAProblem::setInitialState(const CStateX & initialState)
110 {
111  mInitialState = initialState;
112  mpModel = const_cast<CModel *>(mInitialState.getModel());
113 }
114 
115 /**
116  * Retrieve the initial state of the problem.
117  * @return "const CState &" pInitialState
118  */
119 const CState & CMCAProblem::getInitialState() const
120 {return mInitialState;}
121 #endif // XXXX
122 
123 /**
124  * Set whether the steady state analysis is requested.
125  * @param bool * steadyStateRequested
126  */
127 void CMCAProblem::setSteadyStateRequested(const bool & steadyStateRequested)
128 {
129  CSteadyStateTask * pSubTask = NULL;
130  CCopasiDataModel* pDataModel = getObjectDataModel();
131  assert(pDataModel != NULL);
132 
133  if (pDataModel && pDataModel->getTaskList())
134  pSubTask = dynamic_cast<CSteadyStateTask *>((*pDataModel->getTaskList())["Steady-State"]);
135 
136  if (steadyStateRequested && pSubTask)
137  setValue("Steady-State", pSubTask->getKey());
138  else
139  setValue("Steady-State", std::string(""));
140 }
141 
142 /**
143  * Retrieve whether the steady state analysis is requested.
144  * @return bool steadyStateRequested
145  */
147 {return (* getValue("Steady-State").pKEY != "");}
148 
150 {
151  CSteadyStateTask * pSubTask = NULL;
152 
154  {
155  pSubTask = dynamic_cast<CSteadyStateTask *>(CCopasiRootContainer::getKeyFactory()->get(* getValue("Steady-State").pKEY));
156 
157  if (pSubTask == NULL)
158  {
159  const CCopasiDataModel * pDataModel = getObjectDataModel();
160  assert(pDataModel != NULL);
161 
162  if (pDataModel && pDataModel->getTaskList())
163  {
164  pSubTask = dynamic_cast<CSteadyStateTask *>((*pDataModel->getTaskList())["Steady-State"]);
165  }
166  }
167  }
168 
169  return pSubTask;
170 }
171 
172 void CMCAProblem::printResult(std::ostream * ostream) const
173 {
174  //this functionality is expected from the problem. However it is implemented in
175  //the task.
176 
177  CMCATask* parent = dynamic_cast<CMCATask*>(getObjectParent());
178 
179  if (!parent) return;
180 
181  parent->printResult(ostream);
182 }
183 
184 //print the description
185 std::ostream &operator<<(std::ostream &os, const CMCAProblem & o)
186 {
187  os << "Problem Description:" << std::endl;
188 
189  //os << "Subtask: " << std::endl;
190 
191  if (o.isSteadyStateRequested())
192  {
193  os << "Calculation of a steady state is requested before the MCA." << std::endl << std::endl;
194 
195  if (o.getSubTask())
196  {
197  //os << "" << std::endl;
198  o.getSubTask()->getDescription().print(&os);
199  }
200  else
201  {
202  os << "However an error occurred. Please report this as a bug." << std::endl;
203  }
204  }
205  else
206  {
207  os << "MCA is performed on the current state (which is not necessarily a steady state)." << std::endl;
208  }
209 
210  os << std::endl;
211 
212  return os;
213 }
214 
215 void CMCAProblem::print(std::ostream * ostream) const
216 {*ostream << *this;}
CCopasiDataModel * getObjectDataModel()
virtual void print(std::ostream *ostream) const
void setSteadyStateRequested(const bool &steadyStateRequested)
CCopasiObject * get(const std::string &key)
void setInitialState(const CState &initialState)
Definition: CMCAProblem.cpp:99
Definition: CState.h:305
virtual void printResult(std::ostream *ostream) const
std::string getVersion()
Definition: CReadConfig.cpp:76
#define C_UNUSED(p)
Definition: copasi.h:220
virtual ~CMCAProblem()
Definition: CMCAProblem.cpp:64
#define DESTRUCTOR_TRACE
Definition: copasi.h:206
void printResult(std::ostream *ostream) const
Definition: CMCATask.cpp:201
bool isSteadyStateRequested() const
const CDescription & getDescription() const
CMCAProblem(const CCopasiContainer *pParent=NULL)
Definition: CMCAProblem.cpp:43
std::ostream & operator<<(std::ostream &os, const CMCAProblem &o)
virtual bool setModel(CModel *pModel)
Definition: CMCAProblem.cpp:71
const Value & getValue() const
CCopasiVectorN< CCopasiTask > * getTaskList()
CSteadyStateTask * getSubTask() const
bool setValue(const std::string &name, const CType &value)
void load(CReadConfig &configBuffer, CReadConfig::Mode mode=CReadConfig::NEXT)
Definition: CMCAProblem.cpp:81
static CKeyFactory * getKeyFactory()
virtual const std::string & getKey() const
virtual void print(std::ostream *ostream) const
bool addParameter(const CCopasiParameter &parameter)
CState mInitialState
Definition: CMCAProblem.h:39
Definition: CModel.h:50
C_INT32 getVariable(const std::string &name, const std::string &type, void *pout, CReadConfig::Mode mode=CReadConfig::NEXT)
Definition: CReadConfig.cpp:81
CModel * mpModel
CCopasiContainer * getObjectParent() const
#define CONSTRUCTOR_TRACE
Definition: copasi.h:202