COPASI API  4.16.103
CSensTask.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/sensitivities/CSensTask.cpp,v $
3 // $Revision: 1.13 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2011/03/07 19:33:42 $
7 // End CVS Header
8 
9 // Copyright (C) 2011 - 2010 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  * CSensTask class.
25  *
26  */
27 
28 #include "copasi.h"
29 
30 #include "CSensTask.h"
31 #include "CSensProblem.h"
32 #include "CSensMethod.h"
33 #include "model/CModel.h"
34 #include "model/CState.h"
35 //#include "model/CMetabNameInterface.h"
36 #include "report/CKeyFactory.h"
37 #include "report/CReport.h"
38 
39 #define XXXX_Reporting
40 
42  CCopasiTask(CCopasiTask::sens, pParent)
43 {
44  mpProblem = new CSensProblem(this);
45 
47  this->add(mpMethod, true);
48 
49 }
50 
52  const CCopasiContainer * pParent):
53  CCopasiTask(src, pParent)
54 {
55  mpProblem =
56  new CSensProblem(*(CSensProblem *) src.mpProblem, this);
57 
59  this->add(mpMethod, true);
60 }
61 
63 {}
64 
65 // virtual
66 CCopasiMethod * CSensTask::createMethod(const int & type) const
67 {
69 
70  return CSensMethod::createMethod(Type);
71 }
72 
74 {}
75 
76 //TODO: really necessary?
77 void CSensTask::print(std::ostream * ostream) const {(*ostream) << (*this);}
78 
80 {
81  assert(mpProblem && mpMethod);
82 
83  CSensProblem* pProblem =
84  dynamic_cast<CSensProblem *>(mpProblem);
85  assert(pProblem);
86 
87  CSensMethod* pMethod =
88  dynamic_cast<CSensMethod *>(mpMethod);
89  assert(pMethod);
90 
91  bool success = true;
92 
93  if (!pProblem->getModel()->compileIfNecessary(mpCallBack)) success = false;
94 
95  //this does actually more than just update the matrices, but it should do no harm
96  if (!pMethod->initialize(pProblem)) success = false;
97 
98  return success;
99 }
100 
102  COutputHandler * pOutputHandler,
103  std::ostream * pOstream)
104 {
105 
106  bool success = true;
107 
108  //this needs to be done before the initialization of the output
109  if (!updateMatrices()) success = false;
110 
111  if (!CCopasiTask::initialize(of, pOutputHandler, pOstream)) success = false;
112 
113  return success;
114 }
115 
116 bool CSensTask::process(const bool & useInitialValues)
117 {
118  assert(/*mpProblem && */mpMethod);
120 
121  CSensProblem* pProblem =
122  dynamic_cast<CSensProblem *>(mpProblem);
123  assert(pProblem);
124 
125  CSensMethod* pMethod =
126  dynamic_cast<CSensMethod *>(mpMethod);
127  assert(pMethod);
128 
129  if (useInitialValues)
130  pProblem->getModel()->applyInitialValues();
131 
133 
134  bool success = pMethod->process(mpCallBack);
135 
138 
139  return (success);
140 }
141 
142 // virtual
144 {
145  bool success = true;
146 
147  CSensMethod* pMethod =
148  dynamic_cast<CSensMethod *>(mpMethod);
149 
150  if (pMethod != NULL)
151  pMethod->restore(mUpdateModel);
152 
153  return success;
154 }
155 
156 std::ostream &operator<<(std::ostream &os, const CSensTask & /* A */)
157 {
158  return os;
159 }
virtual CCopasiMethod * createMethod(const int &type) const
Definition: CSensTask.cpp:66
virtual bool restore()
Definition: CSensTask.cpp:143
CCopasiMethod * mpMethod
Definition: CCopasiTask.h:239
virtual ~CSensTask()
Definition: CSensTask.cpp:62
virtual bool initialize(const OutputFlag &of, COutputHandler *pOutputHandler, std::ostream *pOstream)
CProcessReport * mpCallBack
Definition: CCopasiTask.h:249
bool restore(const bool &updateModel)
const CCopasiMethod::SubType & getSubType() const
CReport mReport
Definition: CCopasiTask.h:244
void applyInitialValues()
Definition: CModel.cpp:1236
virtual bool process(const bool &useInitialValues)
Definition: CSensTask.cpp:116
virtual bool isValidProblem(const CCopasiProblem *pProblem)
CCopasiProblem * mpProblem
Definition: CCopasiTask.h:234
bool process(CProcessReport *handler)
std::ostream & operator<<(std::ostream &os, const CSensTask &)
Definition: CSensTask.cpp:156
static CSensMethod * createMethod(CCopasiMethod::SubType subType=CCopasiMethod::sensMethod)
Definition: CSensMethod.cpp:34
virtual bool initialize(const OutputFlag &of, COutputHandler *pOutputHandler, std::ostream *pOstream)
Definition: CSensTask.cpp:101
CSensTask(const CCopasiContainer *pParent=NULL)
Definition: CSensTask.cpp:41
bool mUpdateModel
Definition: CCopasiTask.h:223
virtual bool updateMatrices()
Definition: CSensTask.cpp:79
bool initialize(CSensProblem *problem)
bool compileIfNecessary(CProcessReport *pProcessReport)
Definition: CModel.cpp:612
virtual bool add(CCopasiObject *pObject, const bool &adopt=true)
virtual void print(std::ostream *ostream) const
Definition: CSensTask.cpp:77
CModel * getModel() const
virtual void output(const Activity &activity)
Definition: CReport.cpp:107
void cleanup()
Definition: CSensTask.cpp:73