COPASI API  4.16.103
CMoietiesTask.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/moieties/CMoietiesTask.cpp,v $
3 // $Revision: 1.4 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2011/05/26 12:18:54 $
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 #include "copasi.h"
20 
21 #include "CMoietiesTask.h"
22 #include "CMoietiesProblem.h"
23 #include "CMoietiesMethod.h"
24 #include "report/CKeyFactory.h"
25 #include "report/CReport.h"
26 
27 #include "model/CModel.h"
28 #include "model/CState.h"
29 
30 const unsigned int CMoietiesTask::ValidMethods[] =
31 {
34 };
35 
37  const CCopasiContainer * pParent):
38  CCopasiTask(type, pParent)
39 {
40  mpProblem = new CMoietiesProblem(type, this);
42  this->add(mpMethod, true);
43 }
44 
46  const CCopasiContainer * pParent):
47  CCopasiTask(src, pParent)
48 {
49  mpProblem = new CMoietiesProblem(* static_cast< CMoietiesProblem * >(src.mpProblem), this);
51  this->add(mpMethod, true);
52 }
53 
54 // virtual
56 {}
57 
58 // virtual
60 {
61  bool success = CCopasiTask::setCallBack(pCallBack);
62 
63  if (!mpProblem->setCallBack(pCallBack)) success = false;
64 
65  if (!mpMethod->setCallBack(pCallBack)) success = false;
66 
67  return success;
68 }
69 
70 // virtual
72  COutputHandler * pOutputHandler,
73  std::ostream * pOstream)
74 {
75  CMoietiesProblem * pProblem = dynamic_cast<CMoietiesProblem *>(mpProblem);
76  CMoietiesMethod * pMethod = dynamic_cast<CMoietiesMethod *>(mpMethod);
77 
78  if (!pProblem || !pMethod) return false;
79 
80  pMethod->setProblem(pProblem);
81 
82  // Default initialization
83  bool success = CCopasiTask::initialize(of, pOutputHandler, pOstream);
84 
85  success &= mpMethod->isValidProblem(mpProblem);
86 
87  return success;
88 }
89 
90 // virtual
91 bool CMoietiesTask::process(const bool & /* useInitialValues */)
92 {
93  bool success = true;
94 
96 
97  success = static_cast< CMoietiesMethod * >(mpMethod)->process();
98 
99  // The call to process may modify some object pointers. We therefore
100  // have to recompile the output.
101 
102  if (mpOutputHandler != NULL)
103  {
104  std::vector< CCopasiContainer * > ListOfContainer;
105  ListOfContainer.push_back(this);
106 
107  CCopasiDataModel* pDataModel = getObjectDataModel();
108  assert(pDataModel != NULL);
109 
110  size_t Size = CCopasiMessage::size();
111 
112  mpOutputHandler->compile(ListOfContainer, pDataModel);
113 
114  // Remove error messages created by setExpression as this may fail
115  // due to incomplete model specification at this time.
116  while (CCopasiMessage::size() > Size)
118  }
119 
121 
122  return success;
123 }
124 
125 // virtual
127 {
129  return true;
130 }
131 
132 bool CMoietiesTask::setMethodType(const int & type)
133 {
135 
136  if (mpMethod->getSubType() == Type) return true;
137 
138  pdelete(mpMethod);
139 
140  mpMethod = createMethod(Type);
141  this->add(mpMethod, true);
142 
143  return true;
144 }
145 
146 // virtual
148 {
150 
151  return CMoietiesMethod::createMethod(Type);
152 }
CCopasiDataModel * getObjectDataModel()
virtual bool setCallBack(CProcessReport *pCallBack)
CCopasiMethod * mpMethod
Definition: CCopasiTask.h:239
#define pdelete(p)
Definition: copasi.h:215
virtual CCopasiMethod * createMethod(const int &type) const
virtual bool initialize(const OutputFlag &of, COutputHandler *pOutputHandler, std::ostream *pOstream)
void setProblem(CMoietiesProblem *pProblem)
virtual bool process(const bool &useInitialValues)
virtual bool setCallBack(CProcessReport *pCallBack)
virtual void output(const COutputInterface::Activity &activity)
const CCopasiMethod::SubType & getSubType() const
CMoietiesTask(const CCopasiTask::Type &type=CCopasiTask::moieties, const CCopasiContainer *pParent=NULL)
virtual bool setCallBack(CProcessReport *pCallBack)
virtual bool initialize(const OutputFlag &of, COutputHandler *pOutputHandler, std::ostream *pOstream)
virtual bool isValidProblem(const CCopasiProblem *pProblem)
CCopasiProblem * mpProblem
Definition: CCopasiTask.h:234
virtual bool setMethodType(const int &type)
static size_t size()
virtual bool restore()
static CMoietiesMethod * createMethod(const CCopasiMethod::SubType &subType=CCopasiMethod::Householder)
virtual bool compile(std::vector< CCopasiContainer * > listOfContainer, const CCopasiDataModel *pDataModel)
static CCopasiMessage getLastMessage()
static const unsigned int ValidMethods[]
Definition: CMoietiesTask.h:34
virtual bool add(CCopasiObject *pObject, const bool &adopt=true)
bool updateInitialValues()
Definition: CModel.cpp:1461
virtual bool setCallBack(CProcessReport *pCallBack)
COutputHandler * mpOutputHandler
Definition: CCopasiTask.h:464
CModel * getModel() const