COPASI API  4.16.103
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Friends | List of all members
CTrajectoryMethodDsaLsodar Class Reference

#include <CTrajectoryMethodDsaLsodar.h>

Inheritance diagram for CTrajectoryMethodDsaLsodar:
Inheritance graph
[legend]
Collaboration diagram for CTrajectoryMethodDsaLsodar:
Collaboration graph
[legend]

Classes

class  CPartition
 
class  CReactionDependencies
 

Public Member Functions

void calculateAmu (const size_t &index)
 
void calculatePropensities ()
 
void cleanup ()
 
 CTrajectoryMethodDsaLsodar (const CTrajectoryMethodDsaLsodar &src, const CCopasiContainer *pParent=NULL)
 
virtual C_FLOAT64 doSingleStep (C_FLOAT64 currentTime, C_FLOAT64 endTime)
 
virtual bool elevateChildren ()
 
virtual void evalF (const C_FLOAT64 *t, const C_FLOAT64 *y, C_FLOAT64 *ydot)
 
virtual void evalR (const C_FLOAT64 *t, const C_FLOAT64 *y, const C_INT *nr, C_FLOAT64 *r)
 
void fireReaction (const size_t &index)
 
void integrateDeterministicPart (const C_FLOAT64 &deltaT)
 
virtual bool isValidProblem (const CCopasiProblem *pProblem)
 
virtual void start (const CState *initialState)
 
virtual void stateChanged ()
 
virtual Status step (const double &deltaT)
 
 ~CTrajectoryMethodDsaLsodar ()
 
- Public Member Functions inherited from CLsodaMethod
 CLsodaMethod (const CLsodaMethod &src, const CCopasiContainer *pParent=NULL)
 
virtual void evalJ (const C_FLOAT64 *t, const C_FLOAT64 *y, const C_INT *ml, const C_INT *mu, C_FLOAT64 *pd, const C_INT *nRowPD)
 
 ~CLsodaMethod ()
 
- Public Member Functions inherited from CTrajectoryMethod
 CTrajectoryMethod (const CTrajectoryMethod &src, const CCopasiContainer *pParent=NULL)
 
const CVector< C_INT > & getRoots () const
 
void setCurrentState (CState *currentState)
 
void setProblem (CTrajectoryProblem *problem)
 
 ~CTrajectoryMethod ()
 
- Public Member Functions inherited from CCopasiMethod
 CCopasiMethod (const CCopasiMethod &src, const CCopasiContainer *pParent=NULL)
 
const CCopasiMethod::SubTypegetSubType () const
 
const CCopasiTask::TypegetType () const
 
virtual void load (CReadConfig &configBuffer, CReadConfig::Mode mode=CReadConfig::SEARCH)
 
virtual void print (std::ostream *ostream) const
 
virtual void printResult (std::ostream *ostream) const
 
virtual bool setCallBack (CProcessReport *pCallBack)
 
virtual ~CCopasiMethod ()
 
- Public Member Functions inherited from CCopasiParameterGroup
bool addGroup (const std::string &name)
 
bool addParameter (const CCopasiParameter &parameter)
 
bool addParameter (const std::string &name, const CCopasiParameter::Type type)
 
template<class CType >
bool addParameter (const std::string &name, const CCopasiParameter::Type type, const CType &value)
 
void addParameter (CCopasiParameter *pParameter)
 
CCopasiParameterGroupassertGroup (const std::string &name)
 
template<class CType >
CCopasiParameterassertParameter (const std::string &name, const CCopasiParameter::Type type, const CType &defaultValue)
 
index_iterator beginIndex () const
 
name_iterator beginName () const
 
 CCopasiParameterGroup (const CCopasiParameterGroup &src, const CCopasiContainer *pParent=NULL)
 
 CCopasiParameterGroup (const std::string &name, const CCopasiContainer *pParent=NULL, const std::string &objectType="ParameterGroup")
 
void clear ()
 
index_iterator endIndex () const
 
name_iterator endName () const
 
CCopasiParameterGroupgetGroup (const std::string &name)
 
const CCopasiParameterGroupgetGroup (const std::string &name) const
 
CCopasiParameterGroupgetGroup (const size_t &index)
 
const CCopasiParameterGroupgetGroup (const size_t &index) const
 
size_t getIndex (const std::string &name) const
 
std::string getKey (const std::string &name) const
 
std::string getKey (const size_t &index) const
 
virtual const std::string & getName (const size_t &index) const
 
virtual const CObjectInterfacegetObject (const CCopasiObjectName &cn) const
 
CCopasiParametergetParameter (const std::string &name)
 
const CCopasiParametergetParameter (const std::string &name) const
 
CCopasiParametergetParameter (const size_t &index)
 
const CCopasiParametergetParameter (const size_t &index) const
 
CCopasiParameter::Type getType (const std::string &name) const
 
CCopasiParameter::Type getType (const size_t &index) const
 
std::string getUniqueParameterName (const CCopasiParameter *pParameter) const
 
const CCopasiParameter::ValuegetValue (const std::string &name) const
 
const CCopasiParameter::ValuegetValue (const size_t &index) const
 
CCopasiParameter::ValuegetValue (const std::string &name)
 
CCopasiParameter::ValuegetValue (const size_t &index)
 
CCopasiParameterGroupoperator= (const CCopasiParameterGroup &rhs)
 
bool removeParameter (const std::string &name)
 
bool removeParameter (const size_t &index)
 
template<class CType >
bool setValue (const std::string &name, const CType &value)
 
template<class CType >
bool setValue (const size_t &index, const CType &value)
 
size_t size () const
 
bool swap (const size_t &iFrom, const size_t &iTo)
 
bool swap (index_iterator &from, index_iterator &to)
 
virtual ~CCopasiParameterGroup ()
 
- Public Member Functions inherited from CCopasiParameter
 CCopasiParameter (const CCopasiParameter &src, const CCopasiContainer *pParent=NULL)
 
 CCopasiParameter (const std::string &name, const Type &type, const void *pValue=NULL, const CCopasiContainer *pParent=NULL, const std::string &objectType="Parameter")
 
virtual CCopasiObjectName getCN () const
 
virtual const std::string & getKey () const
 
virtual std::string getObjectDisplayName (bool regular=true, bool richtext=false) const
 
const CCopasiParameter::TypegetType () const
 
const ValuegetValue () const
 
ValuegetValue ()
 
virtual voidgetValuePointer () const
 
CCopasiObjectgetValueReference () const
 
bool isValidValue (const C_FLOAT64 &value) const
 
bool isValidValue (const C_INT32 &value) const
 
bool isValidValue (const unsigned C_INT32 &value) const
 
bool isValidValue (const bool &value) const
 
bool isValidValue (const std::string &value) const
 
bool isValidValue (const CCopasiObjectName &value) const
 
bool isValidValue (const std::vector< CCopasiParameter * > &value) const
 
CCopasiParameteroperator= (const CCopasiParameter &rhs)
 
template<class CType >
bool setValue (const CType &value)
 
bool setValue (const std::vector< CCopasiParameter * > &value)
 
virtual ~CCopasiParameter ()
 
- Public Member Functions inherited from CCopasiContainer
virtual bool add (CCopasiObject *pObject, const bool &adopt=true)
 
 CCopasiContainer (const std::string &name, const CCopasiContainer *pParent=NULL, const std::string &type="CN", const unsigned C_INT32 &flag=CCopasiObject::Container)
 
 CCopasiContainer (const CCopasiContainer &src, const CCopasiContainer *pParent=NULL)
 
virtual std::string getChildObjectUnits (const CCopasiObject *pObject) const
 
virtual const objectMapgetObjects () const
 
virtual std::string getUnits () const
 
virtual const CCopasiObjectgetValueObject () const
 
virtual bool remove (CCopasiObject *pObject)
 
virtual ~CCopasiContainer ()
 
- Public Member Functions inherited from CCopasiObject
void addDirectDependency (const CCopasiObject *pObject)
 
 CCopasiObject (const CCopasiObject &src, const CCopasiContainer *pParent=NULL)
 
void clearDirectDependencies ()
 
void clearRefresh ()
 
bool dependsOn (DataObjectSet candidates, const DataObjectSet &context=DataObjectSet()) const
 
void getAllDependencies (DataObjectSet &dependencies, const DataObjectSet &context) const
 
virtual const DataObjectSetgetDirectDependencies (const DataObjectSet &context=DataObjectSet()) const
 
CCopasiContainergetObjectAncestor (const std::string &type) const
 
CCopasiDataModelgetObjectDataModel ()
 
const CCopasiDataModelgetObjectDataModel () const
 
const std::string & getObjectName () const
 
CCopasiContainergetObjectParent () const
 
const std::string & getObjectType () const
 
virtual const
CObjectInterface::ObjectSet
getPrerequisites () const
 
virtual RefreshgetRefresh () const
 
UpdateMethodgetUpdateMethod () const
 
bool hasCircularDependencies (DataObjectSet &candidates, DataObjectSet &verified, const DataObjectSet &context) const
 
bool hasUpdateMethod () const
 
bool isArray () const
 
bool isContainer () const
 
bool isDataModel () const
 
bool isMatrix () const
 
bool isNameVector () const
 
bool isNonUniqueName () const
 
virtual bool isPrerequisiteForContext (const CObjectInterface *pObject, const CMath::SimulationContextFlag &context, const CObjectInterface::ObjectSet &changedObjects) const
 
bool isReference () const
 
bool isRoot () const
 
bool isSeparator () const
 
bool isStaticString () const
 
bool isValueBool () const
 
bool isValueDbl () const
 
bool isValueInt () const
 
bool isValueInt64 () const
 
bool isValueString () const
 
bool isVector () const
 
virtual bool mustBeDeleted (const DataObjectSet &deletedObjects) const
 
void removeDirectDependency (const CCopasiObject *pObject)
 
void setDirectDependencies (const DataObjectSet &directDependencies)
 
bool setObjectName (const std::string &name)
 
virtual bool setObjectParent (const CCopasiContainer *pParent)
 
void setObjectValue (const C_FLOAT64 &value)
 
void setObjectValue (const C_INT32 &value)
 
void setObjectValue (const bool &value)
 
template<class CType >
void setRefresh (CType *pType, void(CType::*method)(void))
 
template<class CType >
void setUpdateMethod (CType *pType, void(CType::*method)(const C_FLOAT64 &))
 
template<class CType >
void setUpdateMethod (CType *pType, void(CType::*method)(const C_INT32 &))
 
template<class CType >
void setUpdateMethod (CType *pType, void(CType::*method)(const bool &))
 
virtual ~CCopasiObject ()
 
- Public Member Functions inherited from CObjectInterface
 CObjectInterface ()
 
virtual ~CObjectInterface ()
 

Protected Member Functions

 CTrajectoryMethodDsaLsodar (const CCopasiMethod::SubType &subType=DsaLsodar, const CCopasiContainer *pParent=NULL)
 
- Protected Member Functions inherited from CLsodaMethod
 CLsodaMethod (const CCopasiMethod::SubType &subType=deterministic, const CCopasiContainer *pParent=NULL)
 
void destroyRootMask ()
 
- Protected Member Functions inherited from CTrajectoryMethod
 CTrajectoryMethod (const CCopasiMethod::SubType &subType, const CCopasiContainer *pParent=NULL)
 
- Protected Member Functions inherited from CCopasiMethod
 CCopasiMethod (const CCopasiTask::Type &taskType, const SubType &subType, const CCopasiContainer *pParent=NULL)
 
- Protected Member Functions inherited from CCopasiParameterGroup
 CCopasiParameterGroup ()
 
- Protected Member Functions inherited from CCopasiContainer
template<class CType >
CCopasiObjectaddMatrixReference (const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
 
template<class CType >
CCopasiObjectaddObjectReference (const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
 
template<class CType >
CCopasiObjectaddVectorReference (const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
 
void initObjects ()
 
- Protected Member Functions inherited from CCopasiObject
 CCopasiObject ()
 
 CCopasiObject (const std::string &name, const CCopasiContainer *pParent=NULL, const std::string &type="CN", const unsigned C_INT32 &flag=0)
 

Protected Attributes

C_FLOAT64 mA0
 
CVector< C_FLOAT64mAmu
 
bool mDoCorrection
 
size_t mFirstReactionSpeciesIndex
 
bool mMaxStepsReached
 
size_t mNextReactionIndex
 
C_FLOAT64 mNextReactionTime
 
size_t mNumReactions
 
CPartition mPartition
 
C_FLOAT64mpLowerLimit
 
unsigned C_INT32mpMaxSteps
 
unsigned C_INT32mpPartitioningInterval
 
C_FLOAT64mpPartitioningSteps
 
CRandommpRandomGenerator
 
C_FLOAT64mpUpperLimit
 
std::vector
< CReactionDependencies
mReactionDependencies
 
size_t mStepsAfterPartitionSystem
 
- Protected Attributes inherited from CLsodaMethod
C_INT mLsodaStatus
 
CState mMethodState
 
bool mNoODE
 
CModelmpModel
 
bool * mpReducedModel
 
RootMasking mRootMasking
 
C_FLOAT64 mTime
 
- Protected Attributes inherited from CTrajectoryMethod
CStatempCurrentState
 
CTrajectoryProblemmpProblem
 
CVector< C_INTmRoots
 
- Protected Attributes inherited from CCopasiMethod
CProcessReportmpCallBack
 
- Protected Attributes inherited from CCopasiParameter
std::string mKey
 
CCopasiObjectmpValueReference
 
size_t mSize
 
Value mValue
 
- Protected Attributes inherited from CCopasiContainer
objectMap mObjects
 

Private Member Functions

void initializeParameter ()
 

Friends

CTrajectoryMethodCTrajectoryMethod::createMethod (CCopasiMethod::SubType subType)
 

Additional Inherited Members

- Public Types inherited from CTrajectoryMethod
enum  Status { FAILURE = -1, NORMAL = 0, ROOT = 1 }
 
- Public Types inherited from CCopasiMethod
enum  SubType {
  unset = 0, RandomSearch, RandomSearchMaster, SimulatedAnnealing,
  CoranaWalk, DifferentialEvolution, ScatterSearch, GeneticAlgorithm,
  EvolutionaryProgram, SteepestDescent, HybridGASA, GeneticAlgorithmSR,
  HookeJeeves, LevenbergMarquardt, NelderMead, SRES,
  Statistics, ParticleSwarm, Praxis, TruncatedNewton,
  Newton, deterministic, LSODAR, directMethod,
  stochastic, tauLeap, adaptiveSA, hybrid,
  hybridLSODA, hybridODE45, DsaLsodar, tssILDM,
  tssILDMModified, tssCSP, mcaMethodReder, scanMethod,
  lyapWolf, sensMethod, EFMAlgorithm, EFMBitPatternTreeAlgorithm,
  EFMBitPatternAlgorithm, Householder, crossSectionMethod, linearNoiseApproximation
}
 
- Public Types inherited from CCopasiParameterGroup
typedef parameterGroup::iterator index_iterator
 
typedef
CCopasiContainer::objectMap::iterator 
name_iterator
 
typedef std::vector
< CCopasiParameter * > 
parameterGroup
 
- Public Types inherited from CCopasiParameter
enum  Type {
  DOUBLE = 0, UDOUBLE, INT, UINT,
  BOOL, GROUP, STRING, CN,
  KEY, FILE, EXPRESSION, INVALID
}
 
- Public Types inherited from CCopasiContainer
typedef std::multimap
< std::string, CCopasiObject * > 
objectMap
 
- Public Types inherited from CCopasiObject
typedef std::set< const
CCopasiObject * > 
DataObjectSet
 
typedef std::vector< Refresh * > DataUpdateSequence
 
- Public Types inherited from CObjectInterface
typedef std::set< const
CObjectInterface * > 
ObjectSet
 
typedef std::vector
< CObjectInterface * > 
UpdateSequence
 
- Static Public Member Functions inherited from CLsodaMethod
static void EvalF (const C_INT *n, const C_FLOAT64 *t, const C_FLOAT64 *y, C_FLOAT64 *ydot)
 
static void EvalJ (const C_INT *n, const C_FLOAT64 *t, const C_FLOAT64 *y, const C_INT *ml, const C_INT *mu, C_FLOAT64 *pd, const C_INT *nRowPD)
 
static void EvalR (const C_INT *n, const C_FLOAT64 *t, const C_FLOAT64 *y, const C_INT *nr, C_FLOAT64 *r)
 
- Static Public Member Functions inherited from CTrajectoryMethod
static CTrajectoryMethodcreateMethod (CCopasiMethod::SubType subType=CCopasiMethod::deterministic)
 
- Static Public Member Functions inherited from CCopasiObject
static std::vector< Refresh * > buildUpdateSequence (const DataObjectSet &objects, const DataObjectSet &uptoDateObjects, const DataObjectSet &context=DataObjectSet())
 
static void setRenameHandler (CRenameHandler *rh)
 
- Static Public Attributes inherited from CCopasiMethod
static const std::string SubTypeName []
 
static const char * XMLSubType []
 
- Static Public Attributes inherited from CCopasiParameter
static const std::string TypeName []
 
static const char * XMLType []
 
- Static Public Attributes inherited from CCopasiContainer
static const std::vector
< CCopasiContainer * > 
EmptyList
 
- Protected Types inherited from CLsodaMethod
enum  RootMasking { NONE = 0, ALL, DISCRETE }
 
- Protected Types inherited from CCopasiObject
enum  Flag {
  Container = 0x1, Vector = 0x2, Matrix = 0x4, NameVector = 0x8,
  Reference = 0x10, ValueBool = 0x20, ValueInt = 0x40, ValueInt64 = 0x80,
  ValueDbl = 0x100, NonUniqueName = 0x200, StaticString = 0x400, ValueString = 0x800,
  Separator = 0x1000, ModelEntity = 0x2000, Array = 0x4000, DataModel = 0x8000,
  Root = 0x10000, Gui = 0x20000
}
 
- Static Protected Attributes inherited from CCopasiObject
static CRenameHandlersmpRenameHandler = NULL
 

Detailed Description

Definition at line 52 of file CTrajectoryMethodDsaLsodar.h.

Constructor & Destructor Documentation

CTrajectoryMethodDsaLsodar::CTrajectoryMethodDsaLsodar ( const CCopasiMethod::SubType subType = DsaLsodar,
const CCopasiContainer pParent = NULL 
)
protected

Default constructor.

Parameters
constCCopasiMethod::SubType & subType (default: DsaLsodar)
constCCopasiContainer * pParent (default: NULL)

Default constructor.

Definition at line 321 of file CTrajectoryMethodDsaLsodar.cpp.

References CRandom::createGenerator(), initializeParameter(), mpRandomGenerator, and CRandom::mt19937.

322  :
323  CLsodaMethod(subType, pParent)
324 {
327 }
static CRandom * createGenerator(CRandom::Type type=CRandom::mt19937, unsigned C_INT32 seed=0)
Definition: CRandom.cpp:49
CLsodaMethod(const CCopasiMethod::SubType &subType=deterministic, const CCopasiContainer *pParent=NULL)
CTrajectoryMethodDsaLsodar::CTrajectoryMethodDsaLsodar ( const CTrajectoryMethodDsaLsodar src,
const CCopasiContainer pParent = NULL 
)

Copy constructor

Parameters
constCTrajectoryMethodDsaLsodar & src
constCCopasiContainer * pParent (default: NULL)

Definition at line 329 of file CTrajectoryMethodDsaLsodar.cpp.

References CRandom::createGenerator(), initializeParameter(), mpRandomGenerator, and CRandom::mt19937.

330  :
331  CLsodaMethod(src, pParent)
332 {
335 }
static CRandom * createGenerator(CRandom::Type type=CRandom::mt19937, unsigned C_INT32 seed=0)
Definition: CRandom.cpp:49
CLsodaMethod(const CCopasiMethod::SubType &subType=deterministic, const CCopasiContainer *pParent=NULL)
CTrajectoryMethodDsaLsodar::~CTrajectoryMethodDsaLsodar ( )

Destructor.

Definition at line 340 of file CTrajectoryMethodDsaLsodar.cpp.

References cleanup(), and DESTRUCTOR_TRACE.

341 {
342  cleanup();
344 }
#define DESTRUCTOR_TRACE
Definition: copasi.h:206

Member Function Documentation

void CTrajectoryMethodDsaLsodar::calculateAmu ( const size_t &  index)

Calculates an amu value for a given reaction.

Parameters
constsize_t & index

Definition at line 869 of file CTrajectoryMethodDsaLsodar.cpp.

References CVectorCore< CType >::array(), C_FLOAT64, mAmu, mDoCorrection, CTrajectoryMethodDsaLsodar::CReactionDependencies::mMethodSubstrates, CTrajectoryMethodDsaLsodar::CReactionDependencies::mModelSubstrates, CTrajectoryMethodDsaLsodar::CReactionDependencies::mpParticleFlux, mReactionDependencies, CTrajectoryMethodDsaLsodar::CReactionDependencies::mSubstrateMultiplier, and CVectorCore< CType >::size().

Referenced by calculatePropensities(), and fireReaction().

870 {
871  CReactionDependencies & Dependencies = mReactionDependencies[index];
872  C_FLOAT64 & Amu = mAmu[index];
873 
874  Amu = *Dependencies.mpParticleFlux;
875 
876  if (Amu < 0.0)
877  {
878  // TODO CRITICAL Create a warning message
879  Amu = 0.0;
880  }
881 
882  if (!mDoCorrection)
883  {
884  return;
885  }
886 
887  C_FLOAT64 SubstrateMultiplier = 1.0;
888  C_FLOAT64 SubstrateDevisor = 1.0;
889  C_FLOAT64 Multiplicity;
890  C_FLOAT64 LowerBound;
891  C_FLOAT64 Number;
892 
893  bool ApplyCorrection = false;
894 
895  C_FLOAT64 * pMultiplier = Dependencies.mSubstrateMultiplier.array();
896  C_FLOAT64 * endMultiplier = pMultiplier + Dependencies.mSubstrateMultiplier.size();
897  C_FLOAT64 ** ppLocalSubstrate = Dependencies.mMethodSubstrates.array();
898  C_FLOAT64 ** ppModelSubstrate = Dependencies.mModelSubstrates.array();
899 
900  for (; pMultiplier != endMultiplier; ++pMultiplier, ++ppLocalSubstrate, ++ppModelSubstrate)
901  {
902  Multiplicity = *pMultiplier;
903 
904  // TODO We should check the error introduced through rounding.
905  **ppLocalSubstrate = floor(**ppModelSubstrate + 0.5);
906 
907  if (Multiplicity > 1.01)
908  {
909  ApplyCorrection = true;
910 
911  Number = **ppLocalSubstrate;
912 
913  LowerBound = Number - Multiplicity;
914  SubstrateDevisor *= pow(Number, Multiplicity - 1.0); //optimization
915  Number -= 1.0;
916 
917  while (Number > LowerBound)
918  {
919  SubstrateMultiplier *= Number;
920  Number -= 1.0;
921  }
922  }
923  }
924 
925  // at least one substrate particle number is zero
926  if (SubstrateMultiplier < 0.5 || SubstrateDevisor < 0.5)
927  {
928  Amu = 0.0;
929  return;
930  }
931 
932  // rate_factor is the rate function divided by substrate_factor.
933  // It would be more efficient if this was generated directly, since in effect we
934  // are multiplying and then dividing by the same thing (substrate_factor)!
935  //C_FLOAT64 rate_factor = mpModel->getReactions()[index]->calculateParticleFlux();
936  if (ApplyCorrection)
937  {
938  Amu *= SubstrateMultiplier / SubstrateDevisor;
939  }
940 
941  return;
942 }
std::vector< CReactionDependencies > mReactionDependencies
#define C_FLOAT64
Definition: copasi.h:92
void CTrajectoryMethodDsaLsodar::calculatePropensities ( )

Calculate the propensities of all stochastic reactions

Definition at line 944 of file CTrajectoryMethodDsaLsodar.cpp.

References CVectorCore< CType >::array(), C_FLOAT64, calculateAmu(), mA0, mAmu, CLsodaMethod::mMethodState, mNumReactions, mPartition, CLsodaMethod::mpModel, CTrajectoryMethodDsaLsodar::CPartition::mStochasticReactions, CModel::setState(), and CModel::updateSimulatedValues().

Referenced by doSingleStep(), and start().

945 {
946  // It suffices to recalculate the propensities for stochastic reactions.
947  CReactionDependencies **ppStochastic = mPartition.mStochasticReactions.array();
948 
949  for (size_t Index = 0; Index != this->mNumReactions; ++Index, ++ppStochastic)
950  {
951  if (*ppStochastic != NULL)
952  {
953  calculateAmu(Index);
954  }
955  }
956 
958  mpModel->updateSimulatedValues(false); //for assignments
959 
960  // calculate the total propensity
961  C_FLOAT64 * pAmu = mAmu.array();
962  C_FLOAT64 * endAmu = pAmu + mNumReactions;
963 
964  mA0 = 0.0;
965 
966  // We must only consider the propensities for stochastic reactions
967  ppStochastic = mPartition.mStochasticReactions.array();
968 
969  for (; pAmu != endAmu; ++pAmu, ++ppStochastic)
970  {
971  if (*ppStochastic != NULL)
972  {
973  mA0 += *pAmu;
974  assert(mA0 >= 0.0);
975  }
976  }
977 
978  return;
979 }
void calculateAmu(const size_t &index)
void updateSimulatedValues(const bool &updateMoieties)
Definition: CModel.cpp:1851
CVector< CReactionDependencies * > mStochasticReactions
CModel * mpModel
Definition: CLsodaMethod.h:159
CState mMethodState
Definition: CLsodaMethod.h:74
void setState(const CState &state)
Definition: CModel.cpp:1785
#define C_FLOAT64
Definition: copasi.h:92
CType * array()
Definition: CVector.h:139
void CTrajectoryMethodDsaLsodar::cleanup ( )

Cleans up memory, etc.

Definition at line 774 of file CTrajectoryMethodDsaLsodar.cpp.

References CLsodaMethod::mpModel, and mpRandomGenerator.

Referenced by ~CTrajectoryMethodDsaLsodar().

775 {
776  delete mpRandomGenerator;
777  mpRandomGenerator = NULL;
778  mpModel = NULL;
779  return;
780 }
CModel * mpModel
Definition: CLsodaMethod.h:159
C_FLOAT64 CTrajectoryMethodDsaLsodar::doSingleStep ( C_FLOAT64  currentTime,
C_FLOAT64  endTime 
)
virtual

Simulates the system over the next interval of time. The current time and the end time of the current step() are given as arguments.

Parameters
currentTimeA C_FLOAT64 specifying the current time
endTimeA C_FLOAT64 specifying the end time of the step()
Returns
A C_FLOAT giving the new time

Definition at line 441 of file CTrajectoryMethodDsaLsodar.cpp.

References CVectorCore< CType >::array(), C_FLOAT64, C_INVALID_INDEX, calculatePropensities(), fireReaction(), CRandom::getRandomOO(), integrateDeterministicPart(), mA0, mAmu, CTrajectoryMethodDsaLsodar::CPartition::mHasDeterministic, CTrajectoryMethodDsaLsodar::CPartition::mHasStochastic, min, CLsodaMethod::mMethodState, mNextReactionIndex, mNextReactionTime, mNumReactions, mPartition, CTrajectoryMethod::mpCurrentState, CLsodaMethod::mpModel, mpPartitioningInterval, mpPartitioningSteps, mpRandomGenerator, mStepsAfterPartitionSystem, CTrajectoryMethodDsaLsodar::CPartition::mStochasticReactions, CTrajectoryMethodDsaLsodar::CPartition::rePartition(), CState::setTime(), and CModel::setTime().

Referenced by step().

442 {
443  C_FLOAT64 DeltaT = 0.0;
444  bool FireReaction = false;
445 
446  // if there are stochastic reactions
447  if (mPartition.mHasStochastic) // there is at least one stochastic reaction
448  {
450  {
451  if (mA0 != 0)
452  {
453  mNextReactionTime = curTime - log(mpRandomGenerator->getRandomOO()) / mA0;
454 
455  // We are sure that we have at least 1 reaction
456  mNextReactionIndex = 0;
457 
458  C_FLOAT64 sum = 0.0;
460 
461  C_FLOAT64 * pAmu = mAmu.array();
462  C_FLOAT64 * endAmu = pAmu + mNumReactions;
463  CReactionDependencies **ppStochastic = mPartition.mStochasticReactions.array();
464 
465  // Only consider stochastic reactions
466  for (; (sum <= rand) && (pAmu != endAmu); ++pAmu, ++mNextReactionIndex, ++ppStochastic)
467  {
468  if (*ppStochastic != NULL)
469  {
470  sum += *pAmu;
471  }
472  }
473 
474  assert(mNextReactionIndex > 0);
475 
476  mNextReactionIndex--;
477  }
478  else
479  {
480  mNextReactionTime = std::numeric_limits< C_FLOAT64 >::infinity();
481  mNextReactionIndex = C_INVALID_INDEX;
482  }
483  }
484 
485  if (mNextReactionTime <= endTime)
486  {
487  FireReaction = true;
488  DeltaT = mNextReactionTime - curTime;
489  }
490  else
491  {
492  DeltaT = std::min(*mpPartitioningSteps, endTime - curTime);
493  }
494  }
495  else
496  {
497  DeltaT = std::min(*mpPartitioningSteps, endTime - curTime);
498  }
499 
500  // if there are deterministic reactions
501  if (mPartition.mHasDeterministic) // there is at least one deterministic reaction
502  {
505 
506  // Now the model state and mMethodState are identical and the propensities are
507  // calculated accordingly.
508  }
509 
510  if (FireReaction)
511  {
514 
515  fireReaction(mNextReactionIndex);
516 
517  mNextReactionTime = std::numeric_limits< C_FLOAT64 >::infinity();
518  mNextReactionIndex = C_INVALID_INDEX;
519 
520  // Now the model state and mMethodState are identical and the propensities are
521  // calculated accordingly.
522  }
523 
525  {
527  {
529  }
530 
532  }
533 
534  return DeltaT;
535 }
virtual C_FLOAT64 getRandomOO()
Definition: CRandom.cpp:254
CVector< CReactionDependencies * > mStochasticReactions
#define C_INVALID_INDEX
Definition: copasi.h:222
CModel * mpModel
Definition: CLsodaMethod.h:159
void setTime(const C_FLOAT64 &time)
Definition: CState.cpp:326
CState mMethodState
Definition: CLsodaMethod.h:74
void integrateDeterministicPart(const C_FLOAT64 &deltaT)
void setTime(const C_FLOAT64 &time)
Definition: CModel.cpp:1187
#define C_FLOAT64
Definition: copasi.h:92
CType * array()
Definition: CVector.h:139
void fireReaction(const size_t &index)
#define min(a, b)
Definition: f2c.h:175
bool CTrajectoryMethodDsaLsodar::elevateChildren ( )
virtual

This methods must be called to elevate subgroups to derived objects. The default implementation does nothing.

Returns
bool success

Reimplemented from CLsodaMethod.

Definition at line 398 of file CTrajectoryMethodDsaLsodar.cpp.

References CLsodaMethod::elevateChildren(), and initializeParameter().

399 {
400  bool success = CLsodaMethod::elevateChildren();
401 
403  return success;
404 }
virtual bool elevateChildren()
void CTrajectoryMethodDsaLsodar::evalF ( const C_FLOAT64 t,
const C_FLOAT64 y,
C_FLOAT64 ydot 
)
virtual

This evaluates the derivatives

Reimplemented from CLsodaMethod.

Definition at line 729 of file CTrajectoryMethodDsaLsodar.cpp.

References CVectorCore< CType >::array(), C_FLOAT64, CModel::calculateDerivatives(), CModel::calculateDerivativesX(), mFirstReactionSpeciesIndex, CLsodaMethod::mMethodState, CLsodaMethod::mNoODE, mPartition, CLsodaMethod::mpModel, CLsodaMethod::mpReducedModel, CTrajectoryMethodDsaLsodar::CPartition::mStochasticSpecies, CModel::setState(), CState::setTime(), CVectorCore< CType >::size(), and CModel::updateSimulatedValues().

730 {
731  // If we have no ODEs add a constant one.
732  if (mNoODE)
733  {
734  *ydot = 1.0;
735  return;
736  }
737 
738  mMethodState.setTime(*t);
739 
742 
743  if (*mpReducedModel)
745  else
747 
748  // Mask derivatives of stochastic species;
749  bool * pStochastic = mPartition.mStochasticSpecies.array();
750  bool * pStochasticEnd = pStochastic + mPartition.mStochasticSpecies.size();
751  C_FLOAT64 * pYdot = ydot + mFirstReactionSpeciesIndex - 1;
752 
753  for (; pStochastic != pStochasticEnd; ++pStochastic, ++pYdot)
754  {
755  if (*pStochastic)
756  {
757  *pYdot = 0;
758  }
759  }
760 
761  return;
762 }
void updateSimulatedValues(const bool &updateMoieties)
Definition: CModel.cpp:1851
CModel * mpModel
Definition: CLsodaMethod.h:159
void setTime(const C_FLOAT64 &time)
Definition: CState.cpp:326
CState mMethodState
Definition: CLsodaMethod.h:74
void setState(const CState &state)
Definition: CModel.cpp:1785
bool * mpReducedModel
Definition: CLsodaMethod.h:52
size_t size() const
Definition: CVector.h:100
void calculateDerivativesX(C_FLOAT64 *derivativesX)
Definition: CModel.cpp:1941
#define C_FLOAT64
Definition: copasi.h:92
CType * array()
Definition: CVector.h:139
void calculateDerivatives(C_FLOAT64 *derivatives)
Definition: CModel.cpp:1903
void CTrajectoryMethodDsaLsodar::evalR ( const C_FLOAT64 t,
const C_FLOAT64 y,
const C_INT nr,
C_FLOAT64 r 
)
virtual

This evaluates the roots

Reimplemented from CLsodaMethod.

Definition at line 765 of file CTrajectoryMethodDsaLsodar.cpp.

766 {
767 }
void CTrajectoryMethodDsaLsodar::fireReaction ( const size_t &  index)

Executes the specified reaction in the system once.

Parameters
constsize_t & index

Executes the specified reaction in the system once.

Parameters
indexA size_t specifying the index of the reaction, which will be fired.
timeThe current time

Definition at line 803 of file CTrajectoryMethodDsaLsodar.cpp.

References CVectorCore< CType >::array(), C_FLOAT64, calculateAmu(), CLsodaMethod::destroyRootMask(), CState::getTime(), mA0, mAmu, CTrajectoryMethodDsaLsodar::CReactionDependencies::mCalculations, CTrajectoryMethodDsaLsodar::CReactionDependencies::mDependentReactions, CLsodaMethod::mLsodaStatus, CTrajectoryMethodDsaLsodar::CReactionDependencies::mMethodSpecies, CLsodaMethod::mMethodState, CTrajectoryMethodDsaLsodar::CReactionDependencies::mModelSpecies, mNumReactions, mPartition, mReactionDependencies, CTrajectoryMethodDsaLsodar::CReactionDependencies::mSpeciesMultiplier, CTrajectoryMethodDsaLsodar::CPartition::mStochasticReactions, CLsodaMethod::mTime, and CVectorCore< CType >::size().

Referenced by doSingleStep().

804 {
805  CReactionDependencies & Dependencies = mReactionDependencies[index];
806 
807  // Update the method internal and model species numbers
808  C_FLOAT64 ** ppModelSpecies = Dependencies.mModelSpecies.array();
809  C_FLOAT64 ** ppLocalSpecies = Dependencies.mMethodSpecies.array();
810  C_FLOAT64 * pMultiplier = Dependencies.mSpeciesMultiplier.array();
811  C_FLOAT64 * endMultiplier = pMultiplier + Dependencies.mSpeciesMultiplier.size();
812 
813  for (; pMultiplier != endMultiplier; ++pMultiplier, ++ppLocalSpecies, ++ppModelSpecies)
814  {
815  **ppLocalSpecies += *pMultiplier;
816  **ppModelSpecies = **ppLocalSpecies;
817  }
818 
819  // Calculate all values which depend on the firing reaction
820  std::vector< Refresh * >::const_iterator itCalcualtion = Dependencies.mCalculations.begin();
821  std::vector< Refresh * >::const_iterator endCalcualtion = Dependencies.mCalculations.end();
822 
823  while (itCalcualtion != endCalcualtion)
824  {
825  (**itCalcualtion++)();
826  }
827 
828  // We do not need to update the the method state since the only independent state
829  // values are species of type reaction which are all controlled by the method.
830 
831  // calculate the propensities which depend on the firing reaction
832  size_t * pDependentReaction = Dependencies.mDependentReactions.array();
833  size_t * endDependentReactions = pDependentReaction + Dependencies.mDependentReactions.size();
834 
835  // It suffices to recalculate the propensities for stochastic reactions.
836  for (; pDependentReaction != endDependentReactions; ++pDependentReaction)
837  {
838  if (mPartition.mStochasticReactions[*pDependentReaction] != NULL)
839  {
840  calculateAmu(*pDependentReaction);
841  }
842  }
843 
844  // calculate the total propensity
845  C_FLOAT64 * pAmu = mAmu.array();
846  C_FLOAT64 * endAmu = pAmu + mNumReactions;
847 
848  mA0 = 0.0;
849 
850  // We must only consider the propensities for stochastic reactions
851  CReactionDependencies ** ppStochastic = mPartition.mStochasticReactions.array();
852 
853  for (; pAmu != endAmu; ++pAmu, ++ppStochastic)
854  {
855  if (*ppStochastic != NULL)
856  {
857  mA0 += *pAmu;
858  }
859  }
860 
862  mLsodaStatus = 1;
863 
864  destroyRootMask();
865 
866  return;
867 }
void calculateAmu(const size_t &index)
C_INT mLsodaStatus
Definition: CLsodaMethod.h:107
CVector< CReactionDependencies * > mStochasticReactions
CState mMethodState
Definition: CLsodaMethod.h:74
std::vector< CReactionDependencies > mReactionDependencies
void destroyRootMask()
C_FLOAT64 mTime
Definition: CLsodaMethod.h:102
const C_FLOAT64 & getTime() const
Definition: CState.cpp:325
#define C_FLOAT64
Definition: copasi.h:92
CType * array()
Definition: CVector.h:139
void CTrajectoryMethodDsaLsodar::initializeParameter ( )
private

Initialize the method parameter

Definition at line 346 of file CTrajectoryMethodDsaLsodar.cpp.

References CCopasiParameterGroup::assertParameter(), C_FLOAT64, C_INT32, CCopasiParameterGroup::getParameter(), CCopasiParameter::getValue(), mpLowerLimit, mpMaxSteps, mpPartitioningInterval, mpPartitioningSteps, mpUpperLimit, CCopasiParameter::Value::pDOUBLE, CCopasiParameter::Value::pUDOUBLE, CCopasiParameter::Value::pUINT, CCopasiParameterGroup::removeParameter(), CCopasiParameterGroup::setValue(), CCopasiParameter::UDOUBLE, and CCopasiParameter::UINT.

Referenced by CTrajectoryMethodDsaLsodar(), and elevateChildren().

347 {
348  CCopasiParameter *pParm;
349 
350  mpMaxSteps =
351  assertParameter("Max Internal Steps", CCopasiParameter::UINT, (C_INT32) 1000000)->getValue().pUINT;
352  mpLowerLimit =
354  mpUpperLimit =
357  assertParameter("Partitioning Interval", CCopasiParameter::UINT, (unsigned C_INT32) 1)->getValue().pUINT;
359  assertParameter("Partitioning Stepsize", CCopasiParameter::UDOUBLE, (C_FLOAT64) 0.001)->getValue().pUDOUBLE;
360 
361  // Check whether we have a method with the old parameter names
362  if ((pParm = getParameter("HYBRID.MaxSteps")) != NULL)
363  {
364  setValue("Max Internal Steps", *pParm->getValue().pUINT);
365  removeParameter("HYBRID.MaxSteps");
366 
367  if ((pParm = getParameter("HYBRID.LowerStochLimit")) != NULL)
368  {
369  setValue("Lower Limit", *pParm->getValue().pDOUBLE);
370  removeParameter("HYBRID.LowerStochLimit");
371  }
372 
373  if ((pParm = getParameter("HYBRID.UpperStochLimit")) != NULL)
374  {
375  setValue("Upper Limit", *pParm->getValue().pDOUBLE);
376  removeParameter("HYBRID.UpperStochLimit");
377  }
378 
379  if ((pParm = getParameter("HYBRID.PartitioningInterval")) != NULL)
380  {
381  setValue("Partitioning Interval", *pParm->getValue().pUINT);
382  removeParameter("HYBRID.PartitioningInterval");
383  }
384 
385  if ((pParm = getParameter("UseRandomSeed")) != NULL)
386  {
387  removeParameter("UseRandomSeed");
388  }
389 
390  if ((pParm = getParameter("")) != NULL)
391  {
392  removeParameter("");
393  }
394  }
395 }
#define C_INT32
Definition: copasi.h:90
bool removeParameter(const std::string &name)
const Value & getValue() const
bool setValue(const std::string &name, const CType &value)
unsigned C_INT32 * pUINT
CCopasiParameter * getParameter(const std::string &name)
#define C_FLOAT64
Definition: copasi.h:92
CCopasiParameter * assertParameter(const std::string &name, const CCopasiParameter::Type type, const CType &defaultValue)
void CTrajectoryMethodDsaLsodar::integrateDeterministicPart ( const C_FLOAT64 deltaT)

Integrates the deterministic reactions of the system over the specified time interval.

Parameters
constC_FLOAT64 & deltaT.

Definition at line 784 of file CTrajectoryMethodDsaLsodar.cpp.

References CLsodaMethod::mMethodState, CLsodaMethod::mpModel, CLsodaMethod::mpReducedModel, CModel::setState(), CLsodaMethod::step(), and CModel::updateSimulatedValues().

Referenced by doSingleStep().

785 {
786  CLsodaMethod::step(deltaT);
787 
790 
791  return;
792 }
void updateSimulatedValues(const bool &updateMoieties)
Definition: CModel.cpp:1851
CModel * mpModel
Definition: CLsodaMethod.h:159
virtual Status step(const double &deltaT)
CState mMethodState
Definition: CLsodaMethod.h:74
void setState(const CState &state)
Definition: CModel.cpp:1785
bool * mpReducedModel
Definition: CLsodaMethod.h:52
bool CTrajectoryMethodDsaLsodar::isValidProblem ( const CCopasiProblem pProblem)
virtual

Check if the method is suitable for this problem

Returns
bool suitability of the method

Reimplemented from CTrajectoryMethod.

Definition at line 984 of file CTrajectoryMethodDsaLsodar.cpp.

References CCopasiMessage::ERROR, CModel::getCompartments(), CTrajectoryProblem::getDuration(), CModel::getEvents(), CModel::getMetabolites(), CCopasiProblem::getModel(), CModel::getModelValues(), CModel::getNumMetabs(), CModel::getNumModelValues(), CCopasiParameter::getValue(), CTrajectoryMethod::isValidProblem(), MCTrajectoryMethod, mpLowerLimit, mpUpperLimit, CModelEntity::ODE, CCopasiParameter::Value::pDOUBLE, CCopasiParameter::Value::pINT, CCopasiVector< T >::size(), and CModel::suitableForStochasticSimulation().

985 {
986  if (!CTrajectoryMethod::isValidProblem(pProblem)) return false;
987 
988  const CTrajectoryProblem * pTP = dynamic_cast<const CTrajectoryProblem *>(pProblem);
989 
990  if (pTP->getDuration() < 0.0)
991  {
992  //back integration not possible
994  return false;
995  }
996 
997  //check for rules
998  size_t i, imax = pTP->getModel()->getNumModelValues();
999 
1000  for (i = 0; i < imax; ++i)
1001  {
1002  if (pTP->getModel()->getModelValues()[i]->getStatus() == CModelEntity::ODE)
1003  {
1004  //ode rule found
1006  return false;
1007  }
1008 
1009  /* if (pTP->getModel()->getModelValues()[i]->getStatus()==CModelEntity::ASSIGNMENT)
1010  if (pTP->getModel()->getModelValues()[i]->isUsed())
1011  {
1012  //used assignment found
1013  CCopasiMessage(CCopasiMessage::EXCEPTION, MCTrajectoryMethod + 19);
1014  return false;
1015  }*/
1016  }
1017 
1018  imax = pTP->getModel()->getNumMetabs();
1019 
1020  for (i = 0; i < imax; ++i)
1021  {
1022  if (pTP->getModel()->getMetabolites()[i]->getStatus() == CModelEntity::ODE)
1023  {
1024  //ode rule found
1026  return false;
1027  }
1028  }
1029 
1030  imax = pTP->getModel()->getCompartments().size();
1031 
1032  for (i = 0; i < imax; ++i)
1033  {
1034  if (pTP->getModel()->getCompartments()[i]->getStatus() == CModelEntity::ODE)
1035  {
1036  //ode rule found
1038  return false;
1039  }
1040  }
1041 
1042  //TODO: rewrite CModel::suitableForStochasticSimulation() to use
1043  // CCopasiMessage
1044  std::string message = pTP->getModel()->suitableForStochasticSimulation();
1045 
1046  if (message != "")
1047  {
1048  //model not suitable, message describes the problem
1049  CCopasiMessage(CCopasiMessage::ERROR, message.c_str());
1050  return false;
1051  }
1052 
1053  /* Max Internal Steps */
1054  if (* getValue("Max Internal Steps").pINT <= 0)
1055  {
1056  //max steps should be at least 1
1058  return false;
1059  }
1060 
1061  /* Lower Limit, Upper Limit */
1062  *mpLowerLimit = * getValue("Lower Limit").pDOUBLE;
1063  *mpUpperLimit = * getValue("Upper Limit").pDOUBLE;
1064 
1065  if (*mpLowerLimit > *mpUpperLimit)
1066  {
1068  return false;
1069  }
1070 
1071  /* Partitioning Interval */
1072  // nothing to be done here so far
1073 
1074  /* Use Random Seed */
1075  // should be checked in the widget later on
1076 
1077  /* Random Seed */
1078  // nothing to be done here
1079 
1080  //events are not supported at the moment
1081  if (pTP->getModel()->getEvents().size() > 0)
1082  {
1084  return false;
1085  }
1086 
1087  return true;
1088 }
CCopasiVectorN< CEvent > & getEvents()
Definition: CModel.cpp:1110
const CCopasiVector< CMetab > & getMetabolites() const
Definition: CModel.cpp:1051
const CCopasiVectorN< CModelValue > & getModelValues() const
Definition: CModel.cpp:1060
virtual size_t size() const
size_t getNumMetabs() const
Definition: CModel.cpp:1118
virtual bool isValidProblem(const CCopasiProblem *pProblem)
#define MCTrajectoryMethod
const C_FLOAT64 & getDuration() const
const Value & getValue() const
CCopasiVectorNS< CCompartment > & getCompartments()
Definition: CModel.cpp:1145
size_t getNumModelValues() const
Definition: CModel.cpp:1139
std::string suitableForStochasticSimulation() const
Definition: CModel.cpp:3901
CModel * getModel() const
void CTrajectoryMethodDsaLsodar::start ( const CState initialState)
virtual

This instructs the method to prepare for integration starting with the initialState given.

Parameters
const CState *initialState

Reimplemented from CLsodaMethod.

Definition at line 538 of file CTrajectoryMethodDsaLsodar.cpp.

References CCopasiVector< T >::begin(), CStateTemplate::beginIndependent(), CState::beginIndependent(), CCopasiObject::buildUpdateSequence(), C_FLOAT64, C_INVALID_INDEX, calculatePropensities(), CModel::deterministic, CCopasiVector< T >::end(), CStateTemplate::endFixed(), CStateTemplate::getIndex(), CModel::getModelType(), CModel::getReactions(), CModel::getStateTemplate(), CModelEntity::getStatus(), CCopasiObject::getValuePointer(), CModelEntity::getValueReference(), CTrajectoryMethodDsaLsodar::CPartition::intialize(), mAmu, mDoCorrection, mFirstReactionSpeciesIndex, CLsodaMethod::mMethodState, mNextReactionIndex, mNextReactionTime, mNumReactions, mPartition, mpLowerLimit, CLsodaMethod::mpModel, mpUpperLimit, mReactionDependencies, CModelEntity::REACTIONS, CVector< CType >::resize(), CModel::setState(), CCopasiVector< T >::size(), CLsodaMethod::start(), and CModel::updateSimulatedValues().

539 {
540  CLsodaMethod::start(initialState);
541 
543  mDoCorrection = true;
544  else
545  mDoCorrection = false;
546 
547  //initialize the vector of ints that contains the particle numbers
548  //for the discrete simulation. This also floors all particle numbers in the model.
549 
551 
554  mAmu = 0.0;
555 
556  const CStateTemplate & StateTemplate = mpModel->getStateTemplate();
557 
558  CModelEntity *const* ppEntity = StateTemplate.beginIndependent();
559  CModelEntity *const* endEntity = StateTemplate.endFixed();
561 
563  size_t IndexSpecies = 1;
564 
565  for (; ppEntity != endEntity; ++ppEntity, ++pValue, ++IndexSpecies)
566  {
567  if (dynamic_cast< const CMetab * >(*ppEntity) != NULL)
568  {
569  *pValue = floor(*pValue + 0.5);
570 
571  if (mFirstReactionSpeciesIndex == 0 &&
572  (*ppEntity)->getStatus() == CModelEntity::REACTIONS)
573  {
574  mFirstReactionSpeciesIndex = IndexSpecies;
575  }
576  }
577  }
578 
579  // Update the model state so that the species are all represented by integers.
581  mpModel->updateSimulatedValues(false); //for assignments
582 
583  // TODO CRITICAL Handle species of type ASSIGNMENT.
584  // These need to be checked whether they are sufficiently close to an integer
585 
586  // Build the reaction dependencies
587  C_FLOAT64 * pMethodStateValue = mMethodState.beginIndependent() - 1;
588  size_t IndexReactions = 0;
589  std::multimap< size_t, size_t> SpeciesToReactions;
590 
593  std::vector< CReactionDependencies >::iterator itDependencies = mReactionDependencies.begin();
594 
595  for (; it != end; ++it)
596  {
597  const CCopasiVector<CChemEqElement> & Balances = (*it)->getChemEq().getBalances();
598  const CCopasiVector<CChemEqElement> & Substrates = (*it)->getChemEq().getSubstrates();
599 
600  // This reactions does not change anything we ignore it
601  if (Balances.size() == 0 && Substrates.size() == 0)
602  {
603  continue;
604  }
605 
606  itDependencies->mpParticleFlux = (C_FLOAT64 *)(*it)->getParticleFluxReference()->getValuePointer();
607 
608  itDependencies->mSpeciesMultiplier.resize(Balances.size());
609  itDependencies->mMethodSpecies.resize(Balances.size());
610  itDependencies->mModelSpecies.resize(Balances.size());
611 
612  std::set< size_t > SpeciesIndexSet;
613 
614  std::set< const CCopasiObject * > changed;
615 
616  // The time is always updated
617  changed.insert(mpModel->getValueReference());
618 
621 
622  size_t Index = 0;
623 
624  for (; itBalance != endBalance; ++itBalance)
625  {
626  const CMetab * pMetab = (*itBalance)->getMetabolite();
627 
628  if (pMetab->getStatus() == CModelEntity::REACTIONS)
629  {
630  size_t SpeciesIndex = StateTemplate.getIndex(pMetab);
631 
632  itDependencies->mSpeciesMultiplier[Index] = floor((*itBalance)->getMultiplicity() + 0.5);
633  itDependencies->mMethodSpecies[Index] = pMethodStateValue + SpeciesIndex;
634  itDependencies->mModelSpecies[Index] = (C_FLOAT64 *) pMetab->getValueReference()->getValuePointer();
635 
636  changed.insert(pMetab->getValueReference());
637 
638  SpeciesToReactions.insert(std::make_pair(SpeciesIndex, IndexReactions));
639  SpeciesIndexSet.insert(SpeciesIndex);
640 
641  Index++;
642  }
643  }
644 
645  // Correct allocation for metabolites which are not determined by reactions
646  itDependencies->mSpeciesMultiplier.resize(Index, true);
647  itDependencies->mMethodSpecies.resize(Index, true);
648  itDependencies->mModelSpecies.resize(Index, true);
649 
650  itDependencies->mSubstrateMultiplier.resize(Substrates.size());
651  itDependencies->mMethodSubstrates.resize(Substrates.size());
652  itDependencies->mModelSubstrates.resize(Substrates.size());
653 
654  CCopasiVector< CChemEqElement >::const_iterator itSubstrate = Substrates.begin();
655  CCopasiVector< CChemEqElement >::const_iterator endSubstrate = Substrates.end();
656 
657  Index = 0;
658 
659  for (; itSubstrate != endSubstrate; ++itSubstrate, ++Index)
660  {
661  const CMetab * pMetab = (*itSubstrate)->getMetabolite();
662 
663  size_t SpeciesIndex = StateTemplate.getIndex(pMetab);
664 
665  itDependencies->mSubstrateMultiplier[Index] = floor((*itSubstrate)->getMultiplicity() + 0.5);
666  itDependencies->mMethodSubstrates[Index] = pMethodStateValue + SpeciesIndex;
667  itDependencies->mModelSubstrates[Index] = (C_FLOAT64 *) pMetab->getValueReference()->getValuePointer();
668 
669  if (pMetab->getStatus() == CModelEntity::REACTIONS)
670  {
671  SpeciesIndexSet.insert(SpeciesIndex);
672  }
673  }
674 
675  itDependencies->mSpeciesIndex.resize(SpeciesIndexSet.size());
676  size_t * pSpeciesIndex = itDependencies->mSpeciesIndex.array();
677  std::set< size_t >::const_iterator itSet = SpeciesIndexSet.begin();
678  std::set< size_t >::const_iterator endSet = SpeciesIndexSet.end();
679 
680  for (; itSet != endSet; ++itSet, ++pSpeciesIndex)
681  {
682  *pSpeciesIndex = *itSet;
683  }
684 
685  std::set< const CCopasiObject * > dependend;
686 
688  itDependencies->mDependentReactions.resize(mNumReactions);
689 
690  Index = 0;
691  size_t Count = 0;
692 
693  for (; itReaction != end; ++itReaction, ++Index)
694  {
695  if ((*itReaction)->getParticleFluxReference()->dependsOn(changed))
696  {
697  dependend.insert((*itReaction)->getParticleFluxReference());
698  itDependencies->mDependentReactions[Count] = Index;
699 
700  Count++;
701  }
702  }
703 
704  itDependencies->mDependentReactions.resize(Count, true);
705 
706  itDependencies->mCalculations = CCopasiObject::buildUpdateSequence(dependend, changed);
707 
708  ++itDependencies;
709  ++IndexReactions;
710  }
711 
712  mNumReactions = IndexReactions;
713 
715  mAmu.resize(mNumReactions, true);
716 
717  mPartition.intialize(mReactionDependencies, SpeciesToReactions,
719 
720  mNextReactionTime = std::numeric_limits< C_FLOAT64 >::infinity();
722 
724 
725  return;
726 }
virtual size_t size() const
iterator begin()
void updateSimulatedValues(const bool &updateMoieties)
Definition: CModel.cpp:1851
virtual void start(const CState *initialState)
void resize(size_t size, const bool &copy=false)
Definition: CVector.h:301
#define C_INVALID_INDEX
Definition: copasi.h:222
size_t getIndex(const CModelEntity *entity) const
Definition: CState.cpp:231
CModel * mpModel
Definition: CLsodaMethod.h:159
Definition: CMetab.h:178
CState mMethodState
Definition: CLsodaMethod.h:74
iterator end()
std::vector< CType * >::const_iterator const_iterator
Definition: CCopasiVector.h:57
std::vector< CReactionDependencies > mReactionDependencies
CModelEntity ** endFixed()
Definition: CState.cpp:213
void setState(const CState &state)
Definition: CModel.cpp:1785
void intialize(std::vector< CReactionDependencies > &reactions, const speciesToReactionsMap &speciesToReactions, const C_FLOAT64 &lowerThreshold, const C_FLOAT64 &upperThreshold, const CState &state)
CModelEntity ** beginIndependent()
Definition: CState.cpp:208
#define C_FLOAT64
Definition: copasi.h:92
const CStateTemplate & getStateTemplate() const
Definition: CModel.cpp:1172
const ModelType & getModelType() const
Definition: CModel.cpp:2339
CCopasiVectorNS< CReaction > & getReactions()
Definition: CModel.cpp:1039
static std::vector< Refresh * > buildUpdateSequence(const DataObjectSet &objects, const DataObjectSet &uptoDateObjects, const DataObjectSet &context=DataObjectSet())
virtual void * getValuePointer() const
const CModelEntity::Status & getStatus() const
C_FLOAT64 * beginIndependent()
Definition: CState.cpp:328
CCopasiObject * getValueReference() const
void CTrajectoryMethodDsaLsodar::stateChanged ( )
virtual

Inform the trajectory method that the state has changed outside its control

Reimplemented from CLsodaMethod.

Definition at line 407 of file CTrajectoryMethodDsaLsodar.cpp.

References CLsodaMethod::mMethodState, CTrajectoryMethod::mpCurrentState, and CLsodaMethod::stateChanged().

408 {
411 }
CState mMethodState
Definition: CLsodaMethod.h:74
virtual void stateChanged()
CTrajectoryMethod::Status CTrajectoryMethodDsaLsodar::step ( const double &  deltaT)
virtual

This instructs the method to calculate a time step of deltaT starting with the current state, i.e., the result of the previous step. The new state (after deltaT) is expected in the current state. The return value is the actual time step taken.

Parameters
const double &deltaT
Returns
Status status

Reimplemented from CLsodaMethod.

Definition at line 414 of file CTrajectoryMethodDsaLsodar.cpp.

References C_FLOAT64, doSingleStep(), CCopasiMessage::EXCEPTION, CState::getTime(), MCTrajectoryMethod, min, CLsodaMethod::mMethodState, CTrajectoryMethod::mpCurrentState, mpMaxSteps, CTrajectoryMethod::NORMAL, and CState::setTime().

415 {
416  // do several steps:
417  C_FLOAT64 Time = mpCurrentState->getTime();
418  C_FLOAT64 EndTime = Time + deltaT;
419 
420  C_FLOAT64 Tolerance = 100.0 * (fabs(EndTime) * std::numeric_limits< C_FLOAT64 >::epsilon() + std::numeric_limits< C_FLOAT64 >::min());
421 
422  size_t Steps = 0;
423 
424  while (fabs(Time - EndTime) > Tolerance)
425  {
426  Time += doSingleStep(Time, EndTime);
427 
428  if (++Steps > *mpMaxSteps)
429  {
431  }
432  }
433 
434  mMethodState.setTime(EndTime); // make sure the end time is exactly the time reach to next interval
436 
437  return NORMAL;
438 }
virtual C_FLOAT64 doSingleStep(C_FLOAT64 currentTime, C_FLOAT64 endTime)
void setTime(const C_FLOAT64 &time)
Definition: CState.cpp:326
CState mMethodState
Definition: CLsodaMethod.h:74
#define MCTrajectoryMethod
const C_FLOAT64 & getTime() const
Definition: CState.cpp:325
#define C_FLOAT64
Definition: copasi.h:92
#define min(a, b)
Definition: f2c.h:175

Friends And Related Function Documentation

Member Data Documentation

C_FLOAT64 CTrajectoryMethodDsaLsodar::mA0
protected

Total propensity (sum over mAmu[i])

Definition at line 434 of file CTrajectoryMethodDsaLsodar.h.

Referenced by calculatePropensities(), doSingleStep(), and fireReaction().

CVector< C_FLOAT64 > CTrajectoryMethodDsaLsodar::mAmu
protected

A vector of reaction propensities

Definition at line 429 of file CTrajectoryMethodDsaLsodar.h.

Referenced by calculateAmu(), calculatePropensities(), doSingleStep(), fireReaction(), and start().

bool CTrajectoryMethodDsaLsodar::mDoCorrection
protected

A boolean flag indicating whether correction for higher order reactions need to be applied

Definition at line 424 of file CTrajectoryMethodDsaLsodar.h.

Referenced by calculateAmu(), and start().

size_t CTrajectoryMethodDsaLsodar::mFirstReactionSpeciesIndex
protected
bool CTrajectoryMethodDsaLsodar::mMaxStepsReached
protected

Definition at line 399 of file CTrajectoryMethodDsaLsodar.h.

size_t CTrajectoryMethodDsaLsodar::mNextReactionIndex
protected

The index of the next reaction which fires

Definition at line 419 of file CTrajectoryMethodDsaLsodar.h.

Referenced by doSingleStep(), and start().

C_FLOAT64 CTrajectoryMethodDsaLsodar::mNextReactionTime
protected

The time the next reaction fires

Definition at line 414 of file CTrajectoryMethodDsaLsodar.h.

Referenced by doSingleStep(), and start().

size_t CTrajectoryMethodDsaLsodar::mNumReactions
protected

The particle and reaction numbers

Definition at line 409 of file CTrajectoryMethodDsaLsodar.h.

Referenced by calculatePropensities(), doSingleStep(), fireReaction(), and start().

CPartition CTrajectoryMethodDsaLsodar::mPartition
protected

The partition of the system

Definition at line 444 of file CTrajectoryMethodDsaLsodar.h.

Referenced by calculatePropensities(), doSingleStep(), evalF(), fireReaction(), and start().

C_FLOAT64* CTrajectoryMethodDsaLsodar::mpLowerLimit
protected

Pointer to the method parameter "Lower Limit"

Definition at line 371 of file CTrajectoryMethodDsaLsodar.h.

Referenced by initializeParameter(), isValidProblem(), and start().

unsigned C_INT32* CTrajectoryMethodDsaLsodar::mpMaxSteps
protected

Pointer to the method parameter "Max Internal Steps"

Definition at line 366 of file CTrajectoryMethodDsaLsodar.h.

Referenced by initializeParameter(), and step().

unsigned C_INT32* CTrajectoryMethodDsaLsodar::mpPartitioningInterval
protected

Pointer to the method parameter "Partitioning Interval"

Definition at line 381 of file CTrajectoryMethodDsaLsodar.h.

Referenced by doSingleStep(), and initializeParameter().

C_FLOAT64* CTrajectoryMethodDsaLsodar::mpPartitioningSteps
protected

Pointer to the method parameter "Partitioning Stepsize"

Definition at line 386 of file CTrajectoryMethodDsaLsodar.h.

Referenced by doSingleStep(), and initializeParameter().

CRandom* CTrajectoryMethodDsaLsodar::mpRandomGenerator
protected

The random number generator.

Definition at line 391 of file CTrajectoryMethodDsaLsodar.h.

Referenced by cleanup(), CTrajectoryMethodDsaLsodar(), and doSingleStep().

C_FLOAT64* CTrajectoryMethodDsaLsodar::mpUpperLimit
protected

Pointer to the method parameter "Upper Limit"

Definition at line 376 of file CTrajectoryMethodDsaLsodar.h.

Referenced by initializeParameter(), isValidProblem(), and start().

std::vector< CReactionDependencies > CTrajectoryMethodDsaLsodar::mReactionDependencies
protected

A vector containing dependency information to minimize the required updates.

Definition at line 439 of file CTrajectoryMethodDsaLsodar.h.

Referenced by calculateAmu(), fireReaction(), and start().

size_t CTrajectoryMethodDsaLsodar::mStepsAfterPartitionSystem
protected

Number of elementary steps after the last partitioning.

Definition at line 404 of file CTrajectoryMethodDsaLsodar.h.

Referenced by doSingleStep().


The documentation for this class was generated from the following files: