COPASI API  4.16.103
CLNAProblem.cpp
Go to the documentation of this file.
1 // Copyright (C) 2011 - 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 /**
7  * CLNAProblem class.
8  * This class describes the LNA analysis problem.
9  *
10  * Created for Copasi by Juergen Pahle 2010
11  */
12 
13 #include <string>
14 
15 #include "copasi.h"
16 #include "CLNAProblem.h"
17 #include "CLNATask.h"
19 
20 #include "model/CModel.h"
21 #include "model/CState.h"
23 #include "report/CKeyFactory.h"
25 
26 /**
27  * Default constructor.
28  * @param "CModel *" pModel
29  */
31  CCopasiProblem(CCopasiTask::lna, pParent),
32  mInitialState()
33 {
34  addParameter("Steady-State", CCopasiParameter::KEY, std::string(""));
36 }
37 
38 /**
39  * Copy constructor.
40  * @param "const CLNAProblem &" src
41  */
43  const CCopasiContainer * pParent):
44  CCopasiProblem(src, pParent)
46 
47 /**
48  * Destructor.
49  */
52 
53 /**
54  * Set the model the problem is dealing with.
55  * @param "CModel *" pModel
56  */
58 {
59  mpModel = pModel;
60  return true;
61 }
62 
63 /**
64  * Load a lna problem
65  * @param "CReadConfig &" configBuffer
66  */
67 void CLNAProblem::load(CReadConfig & configBuffer,
69 {
70  if (configBuffer.getVersion() < "4.0")
71  {
72  bool SteadyStateRequested;
73  configBuffer.getVariable("RepxSteadyStateAnalysis", "bool" ,
74  &SteadyStateRequested,
76 
77  setSteadyStateRequested(SteadyStateRequested);
78  }
79 }
80 
81 /**
82  * Set the initial state of the problem.
83  * @param const CState & initialState
84  */
85 void CLNAProblem::setInitialState(const CState & initialState)
86 {
87  mInitialState = initialState;
88 }
89 
90 #ifdef XXXX
91 /**
92  * Set the initial state of the problem.
93  * @param const CStateX & InitialState
94  */
95 void CLNAProblem::setInitialState(const CStateX & initialState)
96 {
97  mInitialState = initialState;
98  mpModel = const_cast<CModel *>(mInitialState.getModel());
99 }
100 
101 /**
102  * Retrieve the initial state of the problem.
103  * @return "const CState &" pInitialState
104  */
105 const CState & CLNAProblem::getInitialState() const
106 {
107  return mInitialState;
108 }
109 #endif // XXXX
110 
111 /**
112  * Set whether the steady state analysis is requested.
113  * @param bool * steadyStateRequested
114  */
115 void CLNAProblem::setSteadyStateRequested(const bool & steadyStateRequested)
116 {
117  CSteadyStateTask * pSubTask = NULL;
118  CCopasiDataModel* pDataModel = getObjectDataModel();
119  assert(pDataModel != NULL);
120 
121  if (pDataModel && pDataModel->getTaskList())
122  pSubTask = dynamic_cast<CSteadyStateTask *>((*pDataModel->getTaskList())["Steady-State"]);
123 
124  if (steadyStateRequested && pSubTask)
125  setValue("Steady-State", pSubTask->getKey());
126  else
127  setValue("Steady-State", std::string(""));
128 }
129 
130 /**
131  * Retrieve whether the steady state analysis is requested.
132  * @return bool steadyStateRequested
133  */
135 {return (* getValue("Steady-State").pKEY != "");}
136 
138 {
140  return dynamic_cast<CSteadyStateTask *>(CCopasiRootContainer::getKeyFactory()->get(* getValue("Steady-State").pKEY));
141  else
142  return NULL;
143 }
144 
145 void CLNAProblem::printResult(std::ostream * ostream) const
146 {
147  //this functionality is expected from the problem. However it is implemented in
148  //the task.
149 
150  CLNATask* parent = dynamic_cast<CLNATask*>(getObjectParent());
151 
152  if (!parent) return;
153 
154  parent->printResult(ostream);
155 }
156 
157 //print the description
158 std::ostream &operator<<(std::ostream &os, const CLNAProblem & o)
159 {
160  os << "Problem Description:" << std::endl;
161 
162  if (o.isSteadyStateRequested())
163  {
164  os << "Calculation of a steady state is requested before the LNA." << std::endl << std::endl;
165 
166  if (o.getSubTask())
167  {
168  o.getSubTask()->getDescription().print(&os);
169  }
170  else
171  {
172  os << "However an error occurred. Please report this as a bug." << std::endl;
173  }
174  }
175  else
176  {
177  os << "LNA is performed on the current state (which is not necessarily a steady state)." << std::endl;
178  }
179 
180  os << std::endl;
181 
182  return os;
183 }
184 
185 void CLNAProblem::print(std::ostream * ostream) const
186 {
187  *ostream << *this;
188 }
virtual void print(std::ostream *ostream) const
CCopasiDataModel * getObjectDataModel()
virtual ~CLNAProblem()
Definition: CLNAProblem.cpp:50
std::ostream & operator<<(std::ostream &os, const CLNAProblem &o)
void setInitialState(const CState &initialState)
Definition: CLNAProblem.cpp:85
CCopasiObject * get(const std::string &key)
virtual void printResult(std::ostream *ostream) const
Definition: CState.h:305
CLNAProblem(const CCopasiContainer *pParent=NULL)
Definition: CLNAProblem.cpp:30
std::string getVersion()
Definition: CReadConfig.cpp:76
#define C_UNUSED(p)
Definition: copasi.h:220
#define DESTRUCTOR_TRACE
Definition: copasi.h:206
void setSteadyStateRequested(const bool &steadyStateRequested)
const CDescription & getDescription() const
CState mInitialState
Definition: CLNAProblem.h:39
const Value & getValue() const
CCopasiVectorN< CCopasiTask > * getTaskList()
bool setValue(const std::string &name, const CType &value)
void printResult(std::ostream *ostream) const
Definition: CLNATask.cpp:215
CSteadyStateTask * getSubTask() const
static CKeyFactory * getKeyFactory()
virtual const std::string & getKey() const
virtual void print(std::ostream *ostream) const
bool addParameter(const CCopasiParameter &parameter)
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
bool isSteadyStateRequested() const
void load(CReadConfig &configBuffer, CReadConfig::Mode mode=CReadConfig::NEXT)
Definition: CLNAProblem.cpp:67
virtual bool setModel(CModel *pModel)
Definition: CLNAProblem.cpp:57
CCopasiContainer * getObjectParent() const
#define CONSTRUCTOR_TRACE
Definition: copasi.h:202