20 #include "../mesh/VoxelJunction.h"
26 #include "../randnum/RNG.h"
27 #include "../basecode/global.h"
56 for (
unsigned int i = 0; i <
rates_.size(); ++i )
65 const GssaSystem* g,
unsigned int rindex,
double time )
93 const vector< unsigned int >& deps,
const Stoich* stoich )
95 for ( vector< unsigned int >::const_iterator
96 i = deps.begin(); i != deps.end(); ++i )
115 for ( vector< double >::const_iterator
116 i =
v_.begin(); i !=
v_.end(); ++i )
118 if ( r < ( sum += fabs( *i ) ) )
122 return static_cast< unsigned int >( i -
v_.begin() );
145 for ( vector< double >::const_iterator
146 i =
v_.begin(); i !=
v_.end(); ++i )
165 assert(
t_ > currTime );
200 for (
unsigned int i =
v_.size(); i > 0; --i )
202 if ( fabs(
v_[i-1] ) > 0.0 )
208 assert( rindex <
v_.size() );
212 double sign = std::copysign( 1,
v_[rindex] );
214 double sign = double(
v_[rindex] >= 0) - double(0 >
v_[rindex] );
243 vector<double>
error(numVarPools, 0.0);
244 map<double, vector<Eref>> groupByVal;
246 for (
unsigned int i = 0; i < numVarPools; ++i )
249 double base = std::floor( n[i] );
250 assert( base >= 0.0 );
251 double frac = n[i] - base;
271 double extra = std::accumulate( error.begin(), error.end(), 0.0 );
272 if( std::abs(extra) > 0.1 )
274 cout <<
"WARNING: Extra " << extra
275 <<
" molecules in system after converting fractional to integer e.g. 1.1 = 1 (~90% of times) or 2 (~10% of times)." << endl;
280 for (
unsigned int i = 0; i < numVarPools; ++i )
286 n[i] = std::nearbyint(n[i]);
288 n[i] = round( n[i] );
308 unsigned int numCoreRates )
310 for (
unsigned int i = 0; i <
rates_.size(); ++i )
312 rates_.resize( rates.size() );
314 for (
unsigned int i = 0; i < numCoreRates; ++i )
316 for (
unsigned int i = numCoreRates; i < rates.size(); ++i )
323 unsigned int numCoreRates,
unsigned int index )
327 if ( index >=
rates_.size() )
330 if ( index >= numCoreRates )
331 rates_[index] = rates[index]->copyWithVolScaling(
336 rates_[index] = rates[index]->copyWithVolScaling(
345 const double* s, vector< double >& v )
const
350 vector< RateTerm* >::const_iterator i;
352 v.resize(
rates_.size(), 0.0 );
353 vector< double >::iterator j = v.begin();
358 assert( !std::isnan( *( j-1 ) ) );
363 unsigned int r,
const double* s )
const
365 double v =
rates_[r]->operator()( s );
401 unsigned int voxelIndex,
const GssaSystem* g )
403 unsigned int offset = voxelIndex * xf.
xferPoolIdx.size();
404 vector< double >::const_iterator i = xf.
values.begin() + offset;
405 vector< double >::const_iterator j = xf.
lastValues.begin() + offset;
406 vector< double >::iterator m = xf.
subzero.begin() + offset;
408 bool hasChanged =
false;
409 for ( vector< unsigned int >::const_iterator
414 double dx = *i++ - *j++;
415 double base = floor( dx );
double getXreacScaleProducts(unsigned int i) const
void updateFuncs(double *s, double t) const
Updates the function values, within s.
const Stoich * stoichPtr_
bool refreshAtot(const GssaSystem *g)
vector< unsigned int > numFire_
unsigned int nColumns() const
void recalcTime(const GssaSystem *g, double currTime)
vector< unsigned int > xferPoolIdx
vector< vector< unsigned int > > dependency
void xferIn(XferInfo &xf, unsigned int voxelIndex, const GssaSystem *g)
void setNumReac(unsigned int n)
double getReacVelocity(unsigned int r, const double *s) const
void updateDependentRates(const vector< unsigned int > &deps, const Stoich *stoich)
void setSeed(const unsigned long seed)
If seed if 0 then set seed to a random number else set seed to the given number.
const KinSparseMatrix & getStoichiometryMatrix() const
Updates the rates for cross-compartment reactions.
void advance(const ProcInfo *p)
double getVolume() const
Return the volume of the voxel.
void setStoich(const Stoich *stoichPtr)
void fireReac(unsigned int reacIndex, vector< double > &S, double direction) const
void log(string msg, serverity_level_ type=debug, bool redirectToConsole=true, bool removeTicks=true)
Log to console (and to a log-file)
virtual ~GssaVoxelPools()
vector< double > & Svec()
Returns a handle to the mol # vector.
moose::RNG< double > rng_
RNG.
double getXreacScaleSubstrates(unsigned int i) const
unsigned long __rng_seed__
A global seed for all RNGs in moose. When moose.seed( x ) is called, this variable is set...
KinSparseMatrix transposeN
Transpose of stoichiometry matrix.
void updateReacVelocities(const GssaSystem *g, const double *s, vector< double > &v) const
void setVolumeAndDependencies(double vol)
unsigned int getNumRates() const
const double SAFETY_FACTOR
unsigned int getNumVarPools() const
Returns number of local pools that are updated by solver.
void updateAllRateTerms(const vector< RateTerm * > &rates, unsigned int numCoreRates)
vector< unsigned int > numFire() const
void updateDependentMathExpn(const GssaSystem *g, unsigned int rindex, double time)
vector< double > lastValues
unsigned int getNumCoreRates() const
Number of rate terms for reactions purely on this compartment.
void updateRateTerms(const vector< RateTerm * > &rates, unsigned int numCoreRates, unsigned int index)
const vector< RateTerm * > & getRateTerms() const
Returns a reference to the entire rates_ vector.
virtual void setVolumeAndDependencies(double vol)
T uniform(const T a, const T b)
Generate a uniformly distributed random number between a and b.
double t_
Time at which next event will occur.
vector< RateTerm * > rates_