////////////////////////// //MsgDest functions. ///////////////////////// void MarkovGslSolver::process( const Eref& e, ProcPtr info ) { double nextt = info->currTime + info->dt; double t = info->currTime; double sum = 0; for ( unsigned int i = 0; i < nVars_; ++i ) stateGsl_[i] = state_[i]; while ( t < nextt ) { int status = gsl_odeiv_evolve_apply ( gslEvolve_, gslControl_, gslStep_, &gslSys_, &t, nextt, &internalStepSize_, stateGsl_); //Simple idea borrowed from Dieter Jaeger's implementation of a Markov //channel to deal with potential round-off error. sum = 0; for ( unsigned int i = 0; i < nVars_; i++ ) sum += stateGsl_[i]; for ( unsigned int i = 0; i < nVars_; i++ ) stateGsl_[i] /= sum; if ( status != GSL_SUCCESS ) break; } for ( unsigned int i = 0; i < nVars_; ++i ) state_[i] = stateGsl_[i]; stateOut()->send( e, info->threadIndexInGroup, state_ ); }
void MarkovGslSolver::reinit( const Eref& e, ProcPtr info ) { state_ = initialState_; if ( initialState_.empty() ) { cerr << "MarkovGslSolver::reinit : " "Initial state has not been set. Solver has not been initialized." "Call init() before running.\n"; } stateOut()->send( e, info->threadIndexInGroup, state_ ); }
void MarkovSolverBase::reinit( const Eref& e, ProcPtr p ) { if ( initialState_.empty() ) { cerr << "MarkovSolverBase::reinit : Initial state has not been " "set.\n"; return; } state_ = initialState_; stateOut()->send( e, p->threadIndexInGroup, state_ ); }
const Cinfo* MarkovGslSolver::initCinfo() { /////////////////////////////////////////////////////// // Field definitions /////////////////////////////////////////////////////// static ReadOnlyValueFinfo< MarkovGslSolver, bool > isInitialized( "isInitialized", "True if the message has come in to set solver parameters.", &MarkovGslSolver::getIsInitialized ); static ValueFinfo< MarkovGslSolver, string > method( "method", "Numerical method to use.", &MarkovGslSolver::setMethod, &MarkovGslSolver::getMethod ); static ValueFinfo< MarkovGslSolver, double > relativeAccuracy( "relativeAccuracy", "Accuracy criterion", &MarkovGslSolver::setRelativeAccuracy, &MarkovGslSolver::getRelativeAccuracy ); static ValueFinfo< MarkovGslSolver, double > absoluteAccuracy( "absoluteAccuracy", "Another accuracy criterion", &MarkovGslSolver::setAbsoluteAccuracy, &MarkovGslSolver::getAbsoluteAccuracy ); static ValueFinfo< MarkovGslSolver, double > internalDt( "internalDt", "internal timestep to use.", &MarkovGslSolver::setInternalDt, &MarkovGslSolver::getInternalDt ); /////////////////////////////////////////////////////// // DestFinfo definitions /////////////////////////////////////////////////////// static DestFinfo init( "init", "Initialize solver parameters.", new OpFunc1< MarkovGslSolver, vector< double > > ( &MarkovGslSolver::init ) ); static DestFinfo handleQ( "handleQ", "Handles information regarding the instantaneous rate matrix from " "the MarkovRateTable class.", new OpFunc1< MarkovGslSolver, vector< vector< double > > >( &MarkovGslSolver::handleQ) ); static DestFinfo process( "process", "Handles process call", new ProcOpFunc< MarkovGslSolver >( &MarkovGslSolver::process ) ); static DestFinfo reinit( "reinit", "Handles reinit call", new ProcOpFunc< MarkovGslSolver >( &MarkovGslSolver::reinit ) ); /////////////////////////////////////////////////////// // Shared definitions /////////////////////////////////////////////////////// static Finfo* procShared[] = { &process, &reinit }; static SharedFinfo proc( "proc", "Shared message for process and reinit", procShared, sizeof( procShared ) / sizeof( const Finfo* ) ); static Finfo* MarkovGslFinfos[] = { &isInitialized, // ValueFinfo &method, // ValueFinfo &relativeAccuracy, // ValueFinfo &absoluteAccuracy, // ValueFinfo &internalDt, // ValueFinfo &init, // DestFinfo &handleQ, // DestFinfo &proc, // SharedFinfo stateOut(), // SrcFinfo }; static Cinfo MarkovGslSolverCinfo( "MarkovGslSolver", Neutral::initCinfo(), MarkovGslFinfos, sizeof(MarkovGslFinfos)/sizeof(Finfo *), new Dinfo< MarkovGslSolver > ); return &MarkovGslSolverCinfo; }
void MarkovSolverBase::process( const Eref& e, ProcPtr p ) { computeState(); stateOut()->send( e, p->threadIndexInGroup, state_ ); }
const Cinfo* MarkovSolverBase::initCinfo() { ///////////////////// //SharedFinfos ///////////////////// static DestFinfo handleVm("handleVm", "Handles incoming message containing voltage information.", new OpFunc1< MarkovSolverBase, double >(&MarkovSolverBase::handleVm) ); static Finfo* channelShared[] = { &handleVm }; static SharedFinfo channel("channel", "This message couples the MarkovSolverBase to the Compartment. The " "compartment needs Vm in order to look up the correct matrix " "exponential for computing the state.", channelShared, sizeof( channelShared ) / sizeof( Finfo* ) ); ////////////////////// //DestFinfos ////////////////////// static DestFinfo process( "process", "Handles process call", new ProcOpFunc< MarkovSolverBase >( &MarkovSolverBase::process ) ); static DestFinfo reinit( "reinit", "Handles reinit call", new ProcOpFunc< MarkovSolverBase >( &MarkovSolverBase::reinit ) ); static Finfo* processShared[] = { &process, &reinit }; static SharedFinfo proc( "proc", "This is a shared message to receive Process message from the" "scheduler. The first entry is a MsgDest for the Process " "operation. It has a single argument, ProcInfo, which " "holds lots of information about current time, thread, dt and" "so on. The second entry is a MsgDest for the Reinit " "operation. It also uses ProcInfo.", processShared, sizeof( processShared ) / sizeof( Finfo* ) ); static DestFinfo ligandConc("ligandconc", "Handles incoming message containing ligand concentration.", new OpFunc1< MarkovSolverBase, double >(&MarkovSolverBase::handleLigandConc) ); static DestFinfo init("init", "Setups the table of matrix exponentials associated with the" " solver object.", new OpFunc2< MarkovSolverBase, Id, double >(&MarkovSolverBase::init) ); ////////////////////// //*ValueFinfos ///////////////////// static ReadOnlyValueFinfo< MarkovSolverBase, Matrix > Q("Q", "Instantaneous rate matrix.", &MarkovSolverBase::getQ ); static ReadOnlyValueFinfo< MarkovSolverBase, Vector > state("state", "Current state of the channel.", &MarkovSolverBase::getState ); static ValueFinfo< MarkovSolverBase, Vector > initialstate("initialstate", "Initial state of the channel.", &MarkovSolverBase::setInitialState, &MarkovSolverBase::getInitialState ); static ValueFinfo< MarkovSolverBase, double > xmin( "xmin", "Minimum value for x axis of lookup table", &MarkovSolverBase::setXmin, &MarkovSolverBase::getXmin ); static ValueFinfo< MarkovSolverBase, double > xmax( "xmax", "Maximum value for x axis of lookup table", &MarkovSolverBase::setXmax, &MarkovSolverBase::getXmax ); static ValueFinfo< MarkovSolverBase, unsigned int > xdivs( "xdivs", "# of divisions on x axis of lookup table", &MarkovSolverBase::setXdivs, &MarkovSolverBase::getXdivs ); static ReadOnlyValueFinfo< MarkovSolverBase, double > invdx( "invdx", "Reciprocal of increment on x axis of lookup table", &MarkovSolverBase::getInvDx ); static ValueFinfo< MarkovSolverBase, double > ymin( "ymin", "Minimum value for y axis of lookup table", &MarkovSolverBase::setYmin, &MarkovSolverBase::getYmin ); static ValueFinfo< MarkovSolverBase, double > ymax( "ymax", "Maximum value for y axis of lookup table", &MarkovSolverBase::setYmax, &MarkovSolverBase::getYmax ); static ValueFinfo< MarkovSolverBase, unsigned int > ydivs( "ydivs", "# of divisions on y axis of lookup table", &MarkovSolverBase::setYdivs, &MarkovSolverBase::getYdivs ); static ReadOnlyValueFinfo< MarkovSolverBase, double > invdy( "invdy", "Reciprocal of increment on y axis of lookup table", &MarkovSolverBase::getInvDy ); static Finfo* markovSolverFinfos[] = { &channel, //SharedFinfo &proc, //SharedFinfo stateOut(), //SrcFinfo &ligandConc, //DestFinfo &init, //DestFinfo &Q, //ReadOnlyValueFinfo &state, //ReadOnlyValueFinfo &initialstate, //ReadOnlyValueFinfo &xmin, //ValueFinfo &xmax, //ValueFinfo &xdivs, //ValueFinfo &invdx, //ReadOnlyValueFinfo &ymin, //ValueFinfo &ymax, //ValueFinfo &ydivs, //ValueFinfo &invdy //ReadOnlyValueFinfo }; static Cinfo markovSolverBaseCinfo( "MarkovSolverBase", Neutral::initCinfo(), markovSolverFinfos, sizeof( markovSolverFinfos ) / sizeof( Finfo* ), new Dinfo< MarkovSolverBase > ); return &markovSolverBaseCinfo; }
void MarkovSolverBase::process( const Eref& e, ProcPtr p ) { computeState(); stateOut()->send( e, state_ ); }