MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
VoxelPools Class Reference

#include <VoxelPools.h>

+ Inheritance diagram for VoxelPools:
+ Collaboration diagram for VoxelPools:

Public Member Functions

void advance (const ProcInfo *p)
 Do the numerical integration. Advance the simulation. More...
 
const StoichgetStoich ()
 
void print () const
 Used for debugging. More...
 
void reinit (double dt)
 
void setInitDt (double dt)
 Set initial timestep to use by the solver. More...
 
void setStoich (Stoich *stoich, const OdeSystem *ode)
 
void setVolumeAndDependencies (double vol)
 Handles volume change and subsequent cascading updates. More...
 
void updateAllRateTerms (const vector< RateTerm * > &rates, unsigned int numCoreRates)
 Updates all the rate constants from the reference rates vector. More...
 
void updateRates (const double *s, double *yprime) const
 
void updateRateTerms (const vector< RateTerm * > &rates, unsigned int numCoreRates, unsigned int index)
 
void updateReacVelocities (const double *s, vector< double > &v) const
 
 VoxelPools ()
 
virtual ~VoxelPools ()
 
- Public Member Functions inherited from VoxelPoolsBase
void addProxyTransferIndex (unsigned int comptIndex, unsigned int transferIndex)
 
void addProxyVoxy (unsigned int comptIndex, Id comptId, unsigned int voxel)
 Adds the index of a voxel to which proxy data should go. More...
 
void backwardReacVolumeFactor (unsigned int i, double volume)
 
void filterCrossRateTerms (const vector< Id > &offSolverReacs, const vector< pair< Id, Id > > &offSolverReacCompts)
 
void forwardReacVolumeFactor (unsigned int i, double volume)
 
double getDiffConst (unsigned int) const
 
double getN (unsigned int) const
 
double getNinit (unsigned int) const
 
double getVolume () const
 Return the volume of the voxel. More...
 
double getXreacScaleProducts (unsigned int i) const
 
double getXreacScaleSubstrates (unsigned int i) const
 
bool hasXfer (unsigned int comptIndex) const
 True when this voxel has data to be transferred. More...
 
bool isVoxelJunctionPresent (Id i1, Id i2) const
 
void print () const
 Debugging utility. More...
 
void reinit ()
 
void resetXreacScale (unsigned int size)
 
void resizeArrays (unsigned int totNumPools)
 Allocate # of pools. More...
 
const double * S () const
 
void scaleVolsBufsRates (double ratio, const Stoich *stoichPtr)
 
void setDiffConst (unsigned int, double v)
 
void setN (unsigned int i, double v)
 
void setNinit (unsigned int, double v)
 
void setVolume (double vol)
 Just assigns the volume without any cascading to other values. More...
 
const double * Sinit () const
 
unsigned int size () const
 
vector< double > & Svec ()
 Returns a handle to the mol # vector. More...
 
double * varS ()
 
double * varSinit ()
 
 VoxelPoolsBase ()
 
void xferIn (const vector< unsigned int > &poolIndex, const vector< double > &values, const vector< double > &lastValues, unsigned int voxelIndex)
 
void xferInOnlyProxies (const vector< unsigned int > &poolIndex, const vector< double > &values, unsigned int numProxyPools, unsigned int voxelIndex)
 
void xferOut (unsigned int voxelIndex, vector< double > &values, const vector< unsigned int > &poolIndex)
 Assembles data values for sending out for x-compt reacs. More...
 
virtual ~VoxelPoolsBase ()
 

Additional Inherited Members

- Protected Attributes inherited from VoxelPoolsBase
vector< RateTerm * > rates_
 
const StoichstoichPtr_
 

Detailed Description

This is the class for handling reac-diff voxels used for deterministic computations.

Definition at line 29 of file VoxelPools.h.

Constructor & Destructor Documentation

VoxelPools::VoxelPools ( )

Definition at line 36 of file VoxelPools.cpp.

37 {
38 #ifdef USE_GSL
39  driver_ = 0;
40 #endif
41 }
VoxelPools::~VoxelPools ( )
virtual

Definition at line 43 of file VoxelPools.cpp.

44 {
45  for ( unsigned int i = 0; i < rates_.size(); ++i )
46  delete( rates_[i] );
47 #ifdef USE_GSL
48  if ( driver_ )
49  gsl_odeiv2_driver_free( driver_ );
50 #endif
51 }
vector< RateTerm * > rates_

Member Function Documentation

void VoxelPools::advance ( const ProcInfo p)

Do the numerical integration. Advance the simulation.

Definition at line 89 of file VoxelPools.cpp.

References ProcInfo::currTime, ProcInfo::dt, VoxelPoolsBase::stoichPtr_, and Stoich::updateFuncs().

90 {
91  double t = p->currTime - p->dt;
92 #ifdef USE_GSL
93  int status = gsl_odeiv2_driver_apply( driver_, &t, p->currTime, varS());
94  if ( status != GSL_SUCCESS )
95  {
96  cout << "Error: VoxelPools::advance: GSL integration error at time "
97  << t << "\n";
98  cout << "Error info: " << status << ", " <<
99  gsl_strerror( status ) << endl;
100  if ( status == GSL_EMAXITER )
101  cout << "Max number of steps exceeded\n";
102  else if ( status == GSL_ENOPROG )
103  cout << "Timestep has gotten too small\n";
104  else if ( status == GSL_EBADFUNC )
105  cout << "Internal error\n";
106  assert( 0 );
107  }
108 
109 #elif USE_BOOST_ODE
110 
111 
112  // NOTE: Make sure to assing vp to BoostSys vp. In next call, it will be used by
113  // updateRates func. Unlike gsl call, we can't pass extra void* to gslFunc.
114  VoxelPools* vp = reinterpret_cast< VoxelPools* >( sys_.params );
115  sys_.vp = vp;
116  /*-----------------------------------------------------------------------------
117  NOTE: 04/21/2016 11:31:42 AM
118 
119  We need to call updateFuncs here (unlike in GSL solver) because there
120  is no way we can update const vector_type_& y in evalRatesUsingBoost
121  function. In gsl implmentation one could do it, because const_cast can
122  take away the constantness of double*. This probably makes the call bit
123  cleaner.
124  *-----------------------------------------------------------------------------*/
125  vp->stoichPtr_->updateFuncs( &Svec()[0], p->currTime );
126 
127  /*-----------------------------------------------------------------------------
128  * Using integrate function works with with default stepper type.
129  *
130  * NOTICE to developer:
131  * If you are planning your own custom typdedef of stepper_type_ (see
132  * file BoostSystem.h), the you may run into troble. Have a look at this
133  * http://boostw.boost.org/doc/libs/1_56_0/boost/numeric/odeint/integrate/integrate.hpp
134  *-----------------------------------------------------------------------------
135  */
136 
137  double absTol = sys_.epsAbs;
138  double relTol = sys_.epsRel;
139 
140 
147  const double fixedDt = 0.1;
148 
149  if( sys_.method == "rk2" )
150  odeint::integrate_const( rk_midpoint_stepper_type_()
151  , sys_ , Svec()
152  , p->currTime - p->dt, p->currTime, std::min( p->dt, fixedDt )
153  );
154  else if( sys_.method == "rk4" )
155  odeint::integrate_const( rk4_stepper_type_()
156  , sys_ , Svec()
157  , p->currTime - p->dt, p->currTime, std::min( p->dt, fixedDt )
158  );
159  else if( sys_.method == "rk5")
160  odeint::integrate_const( rk_karp_stepper_type_()
161  , sys_ , Svec()
162  , p->currTime - p->dt, p->currTime, std::min( p->dt, fixedDt )
163  );
164  else if( sys_.method == "rk5a")
165  odeint::integrate_adaptive(
166  odeint::make_controlled<rk_karp_stepper_type_>( absTol, relTol)
167  , sys_
168  , Svec()
169  , p->currTime - p->dt
170  , p->currTime
171  , p->dt
172  );
173  else if ("rk54" == sys_.method )
174  odeint::integrate_const( rk_karp_stepper_type_()
175  , sys_ , Svec()
176  , p->currTime - p->dt, p->currTime, std::min( p->dt, fixedDt )
177  );
178  else if ("rk54a" == sys_.method )
179  odeint::integrate_adaptive(
180  odeint::make_controlled<rk_karp_stepper_type_>( absTol, relTol )
181  , sys_, Svec()
182  , p->currTime - p->dt
183  , p->currTime
184  , p->dt
185  );
186  else if ("rk5" == sys_.method )
187  odeint::integrate_const( rk_dopri_stepper_type_()
188  , sys_ , Svec()
189  , p->currTime - p->dt, p->currTime, std::min( p->dt, fixedDt )
190  );
191  else if ("rk5a" == sys_.method )
192  odeint::integrate_adaptive(
193  odeint::make_controlled<rk_dopri_stepper_type_>( absTol, relTol )
194  , sys_, Svec()
195  , p->currTime - p->dt
196  , p->currTime
197  , p->dt
198  );
199  else if( sys_.method == "rk8" )
200  odeint::integrate_const( rk_felhberg_stepper_type_()
201  , sys_ , Svec()
202  , p->currTime - p->dt, p->currTime, std::min( p->dt, fixedDt )
203  );
204  else if( sys_.method == "rk8a" )
205  odeint::integrate_adaptive(
206  odeint::make_controlled<rk_felhberg_stepper_type_>( absTol, relTol )
207  , sys_, Svec()
208  , p->currTime - p->dt
209  , p->currTime
210  , p->dt
211  );
212 
213  else
214  odeint::integrate_adaptive(
215  odeint::make_controlled<rk_karp_stepper_type_>( absTol, relTol )
216  , sys_, Svec()
217  , p->currTime - p->dt
218  , p->currTime
219  , p->dt
220  );
221 #endif
222  if ( !stoichPtr_->getAllowNegative() ) // clean out negatives
223  {
224  unsigned int nv = stoichPtr_->getNumVarPools();
225  double* vs = varS();
226  for ( unsigned int i = 0; i < nv; ++i )
227  {
228  if ( signbit(vs[i]) )
229  vs[i] = 0.0;
230  }
231  }
232 }
void updateFuncs(double *s, double t) const
Updates the function values, within s.
Definition: Stoich.cpp:2118
const Stoich * stoichPtr_
double currTime
Definition: ProcInfo.h:19
vector< double > & Svec()
Returns a handle to the mol # vector.
bool getAllowNegative() const
Definition: Stoich.cpp:315
double dt
Definition: ProcInfo.h:18
unsigned int getNumVarPools() const
Returns number of local pools that are updated by solver.
Definition: Stoich.cpp:510

+ Here is the call graph for this function:

const Stoich* VoxelPools::getStoich ( )
void VoxelPools::print ( ) const

Used for debugging.

For debugging: Print contents of voxel pool.

Definition at line 369 of file VoxelPools.cpp.

References VoxelPoolsBase::print().

370 {
371  cout << "numAllRates = " << rates_.size() <<
372  ", numLocalRates= " << stoichPtr_->getNumCoreRates() << endl;
374 }
const Stoich * stoichPtr_
void print() const
Debugging utility.
unsigned int getNumCoreRates() const
Number of rate terms for reactions purely on this compartment.
Definition: Stoich.cpp:574
vector< RateTerm * > rates_

+ Here is the call graph for this function:

void VoxelPools::reinit ( double  dt)

Definition at line 56 of file VoxelPools.cpp.

References VoxelPoolsBase::reinit().

57 {
59 #ifdef USE_GSL
60  if ( !driver_ )
61  return;
62  gsl_odeiv2_driver_reset( driver_ );
63  gsl_odeiv2_driver_reset_hstart( driver_, dt / 10.0 );
64 #endif
65 }

+ Here is the call graph for this function:

void VoxelPools::setInitDt ( double  dt)

Set initial timestep to use by the solver.

Definition at line 234 of file VoxelPools.cpp.

235 {
236 #ifdef USE_GSL
237  gsl_odeiv2_driver_reset_hstart( driver_, dt );
238 #endif
239 }
void VoxelPools::setStoich ( Stoich stoich,
const OdeSystem ode 
)

setStoich: Assigns the ODE system and Stoich. Stoich may be modified to create a new RateTerm vector in case the volume of this VoxelPools is new.

Definition at line 67 of file VoxelPools.cpp.

References OdeSystem::epsAbs, OdeSystem::epsRel, OdeSystem::initStepSize, and VoxelPoolsBase::reinit().

Referenced by SteadyState::setStoich().

68 {
69  stoichPtr_ = s;
70 #ifdef USE_GSL
71  if ( ode )
72  {
73  sys_ = ode->gslSys;
74  if ( driver_ )
75  gsl_odeiv2_driver_free( driver_ );
76 
77  driver_ = gsl_odeiv2_driver_alloc_y_new(
78  &sys_, ode->gslStep, ode->initStepSize,
79  ode->epsAbs, ode->epsRel
80  );
81  }
82 #elif USE_BOOST_ODE
83  if( ode )
84  sys_ = ode->boostSys;
85 #endif
87 }
const Stoich * stoichPtr_
double epsAbs
Definition: OdeSystem.h:36
double epsRel
Definition: OdeSystem.h:37
double initStepSize
Definition: OdeSystem.h:35

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void VoxelPools::setVolumeAndDependencies ( double  vol)
virtual

Handles volume change and subsequent cascading updates.

Handle volume updates. Inherited Virtual func.

Reimplemented from VoxelPoolsBase.

Definition at line 380 of file VoxelPools.cpp.

References VoxelPoolsBase::setVolumeAndDependencies().

381 {
385 }
const Stoich * stoichPtr_
unsigned int getNumCoreRates() const
Number of rate terms for reactions purely on this compartment.
Definition: Stoich.cpp:574
const vector< RateTerm * > & getRateTerms() const
Returns a reference to the entire rates_ vector.
Definition: Stoich.cpp:589
virtual void setVolumeAndDependencies(double vol)
void updateAllRateTerms(const vector< RateTerm * > &rates, unsigned int numCoreRates)
Updates all the rate constants from the reference rates vector.
Definition: VoxelPools.cpp:282

+ Here is the call graph for this function:

void VoxelPools::updateAllRateTerms ( const vector< RateTerm * > &  rates,
unsigned int  numCoreRates 
)
virtual

Updates all the rate constants from the reference rates vector.

Implements VoxelPoolsBase.

Definition at line 282 of file VoxelPools.cpp.

Referenced by SteadyState::setStoich().

284 {
285  // Clear out old rates if any
286  for ( unsigned int i = 0; i < rates_.size(); ++i )
287  delete( rates_[i] );
288 
289  rates_.resize( rates.size() );
290  for ( unsigned int i = 0; i < numCoreRates; ++i )
291  rates_[i] = rates[i]->copyWithVolScaling( getVolume(), 1, 1 );
292  for ( unsigned int i = numCoreRates; i < rates.size(); ++i )
293  {
294  rates_[i] = rates[i]->copyWithVolScaling( getVolume(),
295  getXreacScaleSubstrates(i - numCoreRates),
296  getXreacScaleProducts(i - numCoreRates ) );
297  }
298 }
double getXreacScaleProducts(unsigned int i) const
double getVolume() const
Return the volume of the voxel.
double getXreacScaleSubstrates(unsigned int i) const
vector< RateTerm * > rates_

+ Here is the caller graph for this function:

void VoxelPools::updateRates ( const double *  s,
double *  yprime 
) const

Core computation function. Updates the reaction velocities vector yprime given the current mol 'n' vector s.

Definition at line 318 of file VoxelPools.cpp.

References KinSparseMatrix::computeRowRate(), SparseMatrix< T >::nColumns(), and SparseMatrix< T >::nRows().

Referenced by SteadyState::classifyState().

319 {
321  vector< double > v( N.nColumns(), 0.0 );
322  vector< double >::iterator j = v.begin();
323  // totVar should include proxyPools only if this voxel uses them
324  unsigned int totVar = stoichPtr_->getNumVarPools() +
326  // totVar should include proxyPools if this voxel does not use them
327  unsigned int totInvar = stoichPtr_->getNumBufPools();
328  assert( N.nColumns() == 0 ||
329  N.nRows() == stoichPtr_->getNumAllPools() );
330  assert( N.nColumns() == rates_.size() );
331 
332  for ( vector< RateTerm* >::const_iterator
333  i = rates_.begin(); i != rates_.end(); i++)
334  {
335  *j++ = (**i)( s );
336  assert( !std::isnan( *( j-1 ) ) );
337  }
338 
339  for (unsigned int i = 0; i < totVar; ++i)
340  *yprime++ = N.computeRowRate( i , v );
341  for (unsigned int i = 0; i < totInvar ; ++i)
342  *yprime++ = 0.0;
343 }
const Stoich * stoichPtr_
unsigned int nColumns() const
Definition: SparseMatrix.h:92
const KinSparseMatrix & getStoichiometryMatrix() const
Updates the rates for cross-compartment reactions.
Definition: Stoich.cpp:1221
unsigned int nRows() const
Definition: SparseMatrix.h:87
double computeRowRate(unsigned int row, const vector< double > &v) const
unsigned int getNumBufPools() const
Returns number of local buffered pools.
Definition: Stoich.cpp:515
unsigned int getNumVarPools() const
Returns number of local pools that are updated by solver.
Definition: Stoich.cpp:510
unsigned int getNumAllPools() const
Definition: Stoich.cpp:520
unsigned int getNumProxyPools() const
Definition: Stoich.cpp:525
vector< RateTerm * > rates_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void VoxelPools::updateRateTerms ( const vector< RateTerm * > &  rates,
unsigned int  numCoreRates,
unsigned int  index 
)
virtual

updateRateTerms updates the rate consts of a belonging to the specified index on the rates vector. It does recaling and assigning using values from the internal rates vector.

Implements VoxelPoolsBase.

Definition at line 300 of file VoxelPools.cpp.

302 {
303  // During setup or expansion of the reac system, it is possible to
304  // call this function before the rates_ term is assigned. Disable.
305  if ( index >= rates_.size() )
306  return;
307  delete( rates_[index] );
308  if ( index >= numCoreRates )
309  rates_[index] = rates[index]->copyWithVolScaling(
310  getVolume(),
311  getXreacScaleSubstrates(index - numCoreRates),
312  getXreacScaleProducts(index - numCoreRates ) );
313  else
314  rates_[index] = rates[index]->copyWithVolScaling(
315  getVolume(), 1.0, 1.0 );
316 }
double getXreacScaleProducts(unsigned int i) const
double getVolume() const
Return the volume of the voxel.
double getXreacScaleSubstrates(unsigned int i) const
vector< RateTerm * > rates_
void VoxelPools::updateReacVelocities ( const double *  s,
vector< double > &  v 
) const

updateReacVelocities computes the velocity v of each reaction from the vector s of pool #s. This is a utility function for programs like SteadyState that need to analyze velocity.

updateReacVelocities computes the velocity v of each reaction. This is a utility function for programs like SteadyState that need to analyze velocity.

Definition at line 350 of file VoxelPools.cpp.

References SparseMatrix< T >::nColumns().

352 {
354  assert( N.nColumns() == rates_.size() );
355 
356  vector< RateTerm* >::const_iterator i;
357  v.clear();
358  v.resize( rates_.size(), 0.0 );
359  vector< double >::iterator j = v.begin();
360 
361  for ( i = rates_.begin(); i != rates_.end(); i++)
362  {
363  *j++ = (**i)( s );
364  assert( !std::isnan( *( j-1 ) ) );
365  }
366 }
const Stoich * stoichPtr_
unsigned int nColumns() const
Definition: SparseMatrix.h:92
const KinSparseMatrix & getStoichiometryMatrix() const
Updates the rates for cross-compartment reactions.
Definition: Stoich.cpp:1221
vector< RateTerm * > rates_

+ Here is the call graph for this function:


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