COPASI API  4.16.103
Public Types | Public Member Functions | Public Attributes | Private Attributes | List of all members
CTrajectoryMethodDsaLsodar::CPartition Class Reference
Collaboration diagram for CTrajectoryMethodDsaLsodar::CPartition:
Collaboration graph
[legend]

Public Types

typedef std::multimap< size_t,
size_t > 
speciesToReactionsMap
 

Public Member Functions

 CPartition ()
 
 CPartition (const CPartition &src)
 
void determineStochasticSpecies ()
 
void intialize (std::vector< CReactionDependencies > &reactions, const speciesToReactionsMap &speciesToReactions, const C_FLOAT64 &lowerThreshold, const C_FLOAT64 &upperThreshold, const CState &state)
 
bool rePartition (const CState &state)
 
 ~CPartition ()
 

Public Attributes

CVector< CReactionDependencies * > mDeterministicReactions
 
bool mHasDeterministic
 
bool mHasStochastic
 
CVector< CReactionDependencies * > mStochasticReactions
 
CVector< bool > mStochasticSpecies
 

Private Attributes

size_t mFirstReactionSpeciesIndex
 
C_FLOAT64 mLowerThreshold
 
CVector< bool > mLowSpecies
 
CVector< size_t > mNumLowSpecies
 
size_t mNumReactionSpecies
 
speciesToReactionsMap mSpeciesToReactions
 
C_FLOAT64 mUpperThreshold
 

Detailed Description

Definition at line 139 of file CTrajectoryMethodDsaLsodar.h.

Member Typedef Documentation

typedef std::multimap< size_t, size_t > CTrajectoryMethodDsaLsodar::CPartition::speciesToReactionsMap

Definition at line 142 of file CTrajectoryMethodDsaLsodar.h.

Constructor & Destructor Documentation

CTrajectoryMethodDsaLsodar::CPartition::CPartition ( )

Default constructor

Definition at line 87 of file CTrajectoryMethodDsaLsodar.cpp.

87  :
96  mHasStochastic(false),
97  mHasDeterministic(false),
98  mNumLowSpecies(0),
99  mLowSpecies(0)
100 {}
CVector< CReactionDependencies * > mStochasticReactions
#define C_INVALID_INDEX
Definition: copasi.h:222
CVector< CReactionDependencies * > mDeterministicReactions
CTrajectoryMethodDsaLsodar::CPartition::CPartition ( const CPartition src)

Copy constructor

Parameters
constCPartition & src

Definition at line 102 of file CTrajectoryMethodDsaLsodar.cpp.

102  :
103  mSpeciesToReactions(src.mSpeciesToReactions),
104  mLowerThreshold(src.mLowerThreshold),
105  mUpperThreshold(src.mUpperThreshold),
107  mNumReactionSpecies(src.mNumReactionSpecies),
108  mStochasticReactions(src.mStochasticReactions),
109  mDeterministicReactions(src.mDeterministicReactions),
110  mStochasticSpecies(src.mStochasticSpecies),
111  mHasStochastic(src.mHasStochastic),
112  mHasDeterministic(src.mHasDeterministic),
113  mNumLowSpecies(src.mNumLowSpecies),
114  mLowSpecies(src.mLowSpecies)
115 {}
CVector< CReactionDependencies * > mStochasticReactions
#define C_INVALID_INDEX
Definition: copasi.h:222
CVector< CReactionDependencies * > mDeterministicReactions
CTrajectoryMethodDsaLsodar::CPartition::~CPartition ( )

Destructor

Definition at line 117 of file CTrajectoryMethodDsaLsodar.cpp.

118 {}

Member Function Documentation

void CTrajectoryMethodDsaLsodar::CPartition::determineStochasticSpecies ( )

Definition at line 295 of file CTrajectoryMethodDsaLsodar.cpp.

References CVectorCore< CType >::array(), CTrajectoryMethodDsaLsodar::mFirstReactionSpeciesIndex, and CTrajectoryMethodDsaLsodar::CReactionDependencies::mSpeciesIndex.

296 {
297  // All species which participate in stochastic reactions are treated stochastically
298  CReactionDependencies **ppReaction = mStochasticReactions.array();
299  CReactionDependencies **ppReactionEnd = ppReaction + mStochasticReactions.size();
300 
301  mStochasticSpecies = false;
302 
303  for (; ppReaction != ppReactionEnd; ++ppReaction)
304  {
305  if (*ppReaction != NULL)
306  {
307  size_t * pSpeciesIndex = (*ppReaction)->mSpeciesIndex.array();
308  size_t * pSpeciesIndexEnd = pSpeciesIndex + (*ppReaction)->mSpeciesIndex.size();
309 
310  for (; pSpeciesIndex != pSpeciesIndexEnd; ++pSpeciesIndex)
311  {
312  mStochasticSpecies[*pSpeciesIndex - mFirstReactionSpeciesIndex] = true;
313  }
314  }
315  }
316 }
CVector< CReactionDependencies * > mStochasticReactions
CType * array()
Definition: CVector.h:139
void CTrajectoryMethodDsaLsodar::CPartition::intialize ( std::vector< CReactionDependencies > &  reactions,
const speciesToReactionsMap speciesToReactions,
const C_FLOAT64 lowerThreshold,
const C_FLOAT64 upperThreshold,
const CState state 
)

Definition at line 120 of file CTrajectoryMethodDsaLsodar.cpp.

References CState::beginIndependent(), C_FLOAT64, and CTrajectoryMethodDsaLsodar::mFirstReactionSpeciesIndex.

Referenced by CTrajectoryMethodDsaLsodar::start().

125 {
126  mSpeciesToReactions = speciesToReactions;
127  mLowerThreshold = lowerThreshold;
128  mUpperThreshold = upperThreshold;
129 
132 
133  mStochasticReactions.resize(reactions.size());
134  mStochasticReactions = NULL;
135 
136  mDeterministicReactions.resize(reactions.size());
138 
139  mNumLowSpecies.resize(reactions.size());
140  mNumLowSpecies = 0;
141 
143  mStochasticSpecies = false;
144 
146  mLowSpecies = false;
147 
148  mHasStochastic = false;
149  mHasDeterministic = false;
150 
151  // Create the initial partition by first counting species with low particle number per reaction
152  const C_FLOAT64 * pValue = state.beginIndependent() - 1 + mFirstReactionSpeciesIndex;
153  const C_FLOAT64 * pValueEnd = pValue + mNumReactionSpecies;
154  bool * pLowSpecies = mLowSpecies.array();
155 
156  C_FLOAT64 CriticalValue = (mLowerThreshold + mUpperThreshold) * 0.5;
157 
158  size_t Index = mFirstReactionSpeciesIndex;
159 
160  for (; pValue != pValueEnd; ++pValue, ++Index, ++pLowSpecies)
161  {
162  if (*pValue < CriticalValue)
163  {
164  *pLowSpecies = true;
165  std::pair< speciesToReactionsMap::const_iterator, speciesToReactionsMap::const_iterator > Range
166  = mSpeciesToReactions.equal_range(Index);
167 
168  for (; Range.first != Range.second; ++Range.first)
169  {
170  mNumLowSpecies[Range.first->second]++;
171  }
172  }
173  }
174 
175  // Reactions for which the count of species with low numbers is non zero
176  // are treated stochastically.
177  const size_t * pLow = mNumLowSpecies.array();
178  const size_t * pLowEnd = pLow + mNumLowSpecies.size();
179  std::vector< CReactionDependencies >::iterator itReaction = reactions.begin();
180  CReactionDependencies ** ppStochastic = mStochasticReactions.array();
181  CReactionDependencies ** ppDeterministic = mDeterministicReactions.array();
182 
183  for (; pLow != pLowEnd; ++pLow, ++itReaction, ++ppStochastic, ++ppDeterministic)
184  {
185  if (*pLow != 0)
186  {
187  *ppStochastic = &(*itReaction);
188  mHasStochastic = true;
189  }
190  else
191  {
192  *ppDeterministic = &(*itReaction);
193  mHasDeterministic = true;
194  }
195  }
196 
198 }
CVector< CReactionDependencies * > mStochasticReactions
void resize(size_t size, const bool &copy=false)
Definition: CVector.h:301
size_t size() const
Definition: CVector.h:100
#define C_FLOAT64
Definition: copasi.h:92
CType * array()
Definition: CVector.h:139
CVector< CReactionDependencies * > mDeterministicReactions
C_FLOAT64 * beginIndependent()
Definition: CState.cpp:328
bool CTrajectoryMethodDsaLsodar::CPartition::rePartition ( const CState state)

Definition at line 200 of file CTrajectoryMethodDsaLsodar.cpp.

References CState::beginIndependent(), C_FLOAT64, and CTrajectoryMethodDsaLsodar::mFirstReactionSpeciesIndex.

Referenced by CTrajectoryMethodDsaLsodar::doSingleStep().

201 {
202  // Modify the partition if species values move beyond the threshold
203  const C_FLOAT64 * pValue = state.beginIndependent() - 1 + mFirstReactionSpeciesIndex;
204  const C_FLOAT64 * pValueEnd = pValue + mNumReactionSpecies;
205  bool * pLowSpecies = mLowSpecies.array();
206 
207  bool PartitionChanged = false;
208 
209  size_t Index = 0;
210 
211  for (; pValue != pValueEnd; ++pValue, ++Index, ++pLowSpecies)
212  {
213  if (!*pLowSpecies && *pValue < mLowerThreshold)
214  {
215  *pLowSpecies = true;
216  PartitionChanged = true;
217 
218  mStochasticSpecies[Index] = true;
219 
220  std::pair< speciesToReactionsMap::const_iterator, speciesToReactionsMap::const_iterator > Range
221  = mSpeciesToReactions.equal_range(Index + mFirstReactionSpeciesIndex);
222 
223  for (; Range.first != Range.second; ++Range.first)
224  {
225  mNumLowSpecies[Range.first->second]++;
226  }
227  }
228  else if (*pLowSpecies && *pValue > mUpperThreshold)
229  {
230  *pLowSpecies = false;
231  PartitionChanged = true;
232 
233  mStochasticSpecies[Index] = true;
234 
235  std::pair< speciesToReactionsMap::const_iterator, speciesToReactionsMap::const_iterator > Range
236  = mSpeciesToReactions.equal_range(Index);
237 
238  for (; Range.first != Range.second; ++Range.first)
239  {
240  mNumLowSpecies[Range.first->second]--;
241  }
242  }
243  }
244 
245  if (!PartitionChanged)
246  {
247  return false;
248  }
249 
250  PartitionChanged = false;
251 
252  // Reactions for which the count of species with low numbers is non zero
253  // are treated stochastically.
254  const size_t * pLow = mNumLowSpecies.array();
255  const size_t * pLowEnd = pLow + mNumLowSpecies.size();
256  CReactionDependencies ** ppStochastic = mStochasticReactions.array();
257  CReactionDependencies ** ppDeterministic = mDeterministicReactions.array();
258  mHasStochastic = false;
259  mHasDeterministic = false;
260 
261  for (; pLow != pLowEnd; ++pLow, ++ppStochastic, ++ppDeterministic)
262  {
263  if (*pLow != 0)
264  {
265  mHasStochastic = true;
266 
267  if (*ppDeterministic != NULL)
268  {
269  PartitionChanged = true;
270  *ppStochastic = *ppDeterministic;
271  *ppDeterministic = NULL;
272  }
273  }
274  else
275  {
276  mHasDeterministic = true;
277 
278  if (*ppStochastic != NULL)
279  {
280  PartitionChanged = true;
281  *ppDeterministic = *ppStochastic;
282  *ppStochastic = NULL;
283  }
284  }
285  }
286 
287  if (PartitionChanged)
288  {
289  // determineStochasticSpecies();
290  }
291 
292  return PartitionChanged;
293 }
CVector< CReactionDependencies * > mStochasticReactions
size_t size() const
Definition: CVector.h:100
#define C_FLOAT64
Definition: copasi.h:92
CType * array()
Definition: CVector.h:139
CVector< CReactionDependencies * > mDeterministicReactions
C_FLOAT64 * beginIndependent()
Definition: CState.cpp:328

Member Data Documentation

CVector< CReactionDependencies * > CTrajectoryMethodDsaLsodar::CPartition::mDeterministicReactions

A vector containing pointers to stochastic reaction dependencies

Definition at line 207 of file CTrajectoryMethodDsaLsodar.h.

size_t CTrajectoryMethodDsaLsodar::CPartition::mFirstReactionSpeciesIndex
private

The index of the first species determined by reactions in the state

Definition at line 191 of file CTrajectoryMethodDsaLsodar.h.

bool CTrajectoryMethodDsaLsodar::CPartition::mHasDeterministic

A Boolean flag indicating whether the system has deterministic reactions

Definition at line 222 of file CTrajectoryMethodDsaLsodar.h.

Referenced by CTrajectoryMethodDsaLsodar::doSingleStep().

bool CTrajectoryMethodDsaLsodar::CPartition::mHasStochastic

A Boolean flag indicating whether the system has stochastic reactions

Definition at line 217 of file CTrajectoryMethodDsaLsodar.h.

Referenced by CTrajectoryMethodDsaLsodar::doSingleStep().

C_FLOAT64 CTrajectoryMethodDsaLsodar::CPartition::mLowerThreshold
private

The threshold for switching to stochastic treatment

Definition at line 181 of file CTrajectoryMethodDsaLsodar.h.

CVector< bool > CTrajectoryMethodDsaLsodar::CPartition::mLowSpecies
private

A vector containing the current treatment of the species

Definition at line 233 of file CTrajectoryMethodDsaLsodar.h.

CVector< size_t > CTrajectoryMethodDsaLsodar::CPartition::mNumLowSpecies
private

A vector containing the number of low species for each reaction

Definition at line 228 of file CTrajectoryMethodDsaLsodar.h.

size_t CTrajectoryMethodDsaLsodar::CPartition::mNumReactionSpecies
private

The number of species determined by reactions

Definition at line 196 of file CTrajectoryMethodDsaLsodar.h.

speciesToReactionsMap CTrajectoryMethodDsaLsodar::CPartition::mSpeciesToReactions
private

A map from a species index to the indexes of the reactions it participates in

Definition at line 176 of file CTrajectoryMethodDsaLsodar.h.

CVector< CReactionDependencies * > CTrajectoryMethodDsaLsodar::CPartition::mStochasticReactions

A vector containing pointers to stochastic reaction dependencies

Definition at line 202 of file CTrajectoryMethodDsaLsodar.h.

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

CVector< bool > CTrajectoryMethodDsaLsodar::CPartition::mStochasticSpecies

A vector indicating whether a species is treated stochastically or not.

Definition at line 212 of file CTrajectoryMethodDsaLsodar.h.

Referenced by CTrajectoryMethodDsaLsodar::evalF().

C_FLOAT64 CTrajectoryMethodDsaLsodar::CPartition::mUpperThreshold
private

The threshold for switching to deterministic treatment

Definition at line 186 of file CTrajectoryMethodDsaLsodar.h.


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