Exemple #1
0
void HSolveUtils::rates(
	Id gateId,
	HSolveUtils::Grid grid,
	vector< double >& A,
	vector< double >& B )
{
	double min = HSolveUtils::get< HHGate, double >( gateId, "min" );
	double max = HSolveUtils::get< HHGate, double >( gateId, "max" );
	unsigned int divs = HSolveUtils::get< HHGate, unsigned int >(
		gateId, "divs" );
	
	if ( grid == Grid( min, max, divs ) ) {
		A = HSolveUtils::get< HHGate, vector< double > >( gateId, "tableA" );
		B = HSolveUtils::get< HHGate, vector< double > >( gateId, "tableB" );
		
		return;
	}
	
	A.resize( grid.size() );
	B.resize( grid.size() );
	
	/*
	 * Getting Id of original (prototype) gate, so that we can set fields on
	 * it. Copied gates are read-only.
	 */
	HHGate* gate = reinterpret_cast< HHGate* >( gateId.eref().data() );
	gateId = gate->originalGateId();
	
	/*
	 * Setting interpolation flag on. Will set back to its original value once
	 * we're done.
	 */
	bool useInterpolation = HSolveUtils::get< HHGate, bool >
		( gateId, "useInterpolation" );
	//~ HSolveUtils::set< HHGate, bool >( gateId, "useInterpolation", true );
	Qinfo* qDummy = NULL;
	gate->setUseInterpolation( gateId.eref(), qDummy, true );
	
	unsigned int igrid;
	double* ia = &A[ 0 ];
	double* ib = &B[ 0 ];
	for ( igrid = 0; igrid < grid.size(); ++igrid ) {
		gate->lookupBoth( grid.entry( igrid ), ia, ib );
		
		++ia, ++ib;
	}
	
	// Setting interpolation flag back to its original value.
	//~ HSolveUtils::set< HHGate, bool >
		//~ ( gateId, "useInterpolation", useInterpolation );
	gate->setUseInterpolation( gateId.eref(), qDummy, useInterpolation );
}
Exemple #2
0
bool Shell::isRunning() const
{
	static Id clockId( 1 );
	assert( clockId.element() != 0 );

	return ( reinterpret_cast< const Clock* >( clockId.eref().data() ) )->isRunning();
}
Exemple #3
0
/* Enzymatic Reaction  */
void SbmlReader::setupEnzymaticReaction( const EnzymeInfo & einfo,string enzname, const map< string, Id > &molSidcmptMIdMap,string name1) {
    string enzPool = einfo.enzyme;

    Id comptRef = molSidcmptMIdMap.find(enzPool)->second; //gives compartment of sp
    Id meshEntry = Neutral::child( comptRef.eref(), "mesh" );
    Shell* shell = reinterpret_cast< Shell* >( Id().eref().data() );

    //Creating enz pool to enzyme site
    Id enzPoolId = molSidMIdMap_.find(enzPool)->second;
    Id enzyme_ = shell->doCreate("Enz", enzPoolId, name1, 1);
    //shell->doAddMsg( "Single", meshEntry, "remeshReacs", enzyme_, "remesh");

    Id complex = einfo.complex;
    //Moving enzyme site under enzyme
    shell->doMove(complex,enzyme_);
    shell->doAddMsg("OneToAll",enzyme_,"cplx",complex,"reac");

    shell->doAddMsg("OneToOne",enzyme_,"enz",enzPoolId,"reac");

    vector< Id >::const_iterator sub_itr;
    for ( sub_itr = einfo.substrates.begin(); sub_itr != einfo.substrates.end(); sub_itr++ ) {
        Id S = (*sub_itr);
        Id b = shell->doAddMsg( "OneToOne", enzyme_, "sub" ,S , "reac" );
    }

    vector< Id >::const_iterator prd_itr;
    for ( prd_itr = einfo.products.begin(); prd_itr != einfo.products.end(); prd_itr++ ) {
        Id P = (*prd_itr);
        shell->doAddMsg ("OneToOne",enzyme_,"prd", P,"reac");
    }
    // populate k3,k2,k1 in this order only.
    Field < double > :: set( enzyme_, "k3", einfo.k3 );
    Field < double > :: set( enzyme_, "k2", einfo.k2 );
    Field < double > :: set( enzyme_, "k1", einfo.k1 );
}
Exemple #4
0
bool isDoingReinit()
{
	static Id clockId( 1 );
	assert( clockId.element() != 0 );

	return ( reinterpret_cast< const Clock* >( 
		clockId.eref().data() ) )->isDoingReinit();
}
Exemple #5
0
void testSpikeGen()
{
	Shell* shell = reinterpret_cast< Shell* >( Id().eref().data() );
	Id sid = shell->doCreate( "SpikeGen", Id(), "spike", 1, MooseGlobal );
	SpikeGen& sg = *( reinterpret_cast< SpikeGen* >( sid.eref().data() ) );

	Eref er( sid.eref() );
	ProcInfo p;
	p.dt = 0.001;
	p.currTime = 0.0;
	sg.setThreshold( 1.0 );
	sg.setRefractT( 0.005 );

	sg.reinit( er, &p );
	sg.handleVm( 0.5 );
	sg.process( er, &p );
	assert( !sg.getFired() );
	p.currTime += p.dt;

	sg.handleVm( 0.999 );
	sg.process( er, &p );
	assert( !sg.getFired() );
	p.currTime += p.dt;

	sg.handleVm( 1.001 );
	sg.process( er, &p );
	assert( sg.getFired() );
	p.currTime += p.dt;

	sg.handleVm( 0.999 );
	sg.process( er, &p );
	assert( !sg.getFired() );
	p.currTime += p.dt;

	sg.handleVm( 2.0 ); // Too soon, refractory
	sg.process( er, &p );
	assert( !sg.getFired() );

	p.currTime += 0.005; // Now post-refractory
	sg.handleVm( 2.0 ); // Now not refractory
	sg.process( er, &p );
	assert( sg.getFired() );

	sid.destroy();
	cout << "." << flush;
}
/////////////////////////////////////////////////////////////////
// Now test 'get' across nodes.
// Normally the 'get' call is invoked by the parser, which expects a
// value to come back. Note that the return must be asynchronous:
// the parser cannot block since we need to execute MPI polling
// operations on either side.
/////////////////////////////////////////////////////////////////
void testParGet( Id tnId, vector< Id >& testIds )
{
	unsigned int myNode = MuMPI::INTRA_COMM().Get_rank();
	unsigned int numNodes = MuMPI::INTRA_COMM().Get_size();
	Slot parGetSlot = initShellCinfo()->getSlot( "parallel.getSrc" );
	char name[20];
	string sname;
	if ( myNode == 0 ) {
		cout << "\ntesting parallel get" << flush;
	} else {
		sprintf( name, "foo%d", myNode * 2 );
		sname = name;
		set< string >( tnId.eref(), "name", sname );
	}
	MuMPI::INTRA_COMM().Barrier();
	Eref e = Id::shellId().eref();
	Shell* sh = static_cast< Shell* >( e.data() );
	vector< unsigned int > rids( numNodes, 0 );
	vector< string > ret( numNodes );
	unsigned int origSize = sh->freeRidStack_.size();
	ASSERT( origSize > 0 , "Stack initialized properly" );
	if ( myNode == 0 ) {
		for ( unsigned int i = 1; i < numNodes; i++ ) {
			rids[i] = 
				openOffNodeValueRequest< string >( sh, &ret[i], 1 );
			ASSERT( sh->freeRidStack_.size() == origSize - i, "stack in use" );
			sendTo3< Id, string, unsigned int >(
				Id::shellId().eref(), parGetSlot, i - 1,
				testIds[i - 1], "name", rids[i]
			);
		}
	}
	// Here we explicitly do what the closeOffNodeValueRequest handles.
	MuMPI::INTRA_COMM().Barrier();
	// Cycle a few times to make sure all data gets back to node 0
	for ( unsigned int i = 0; i < 5; i++ ) {
		pollPostmaster();
		MuMPI::INTRA_COMM().Barrier();
	}
	
	// Now go through to check all values have come back.
	if ( myNode == 0 ) {
		ASSERT( sh->freeRidStack_.size() == 1 + origSize - numNodes, 
			"Stack still waiting" );
		for ( unsigned int i = 1; i < numNodes; i++ ) {
			sprintf( name, "foo%d", i * 2 );
			sname = name;
			ASSERT( sh->offNodeData_[ rids[i] ].numPending == 0,
				"Pending requests cleared" );
			ASSERT( sh->offNodeData_[ rids[i] ].data == 
				static_cast< void* >( &ret[i] ), "Pointing to strings" );
			ASSERT( ret[ i ] == sname, "All values returned correctly" );
			// Clean up the debris
			sh->offNodeData_[ rids[i] ].data = 0;
			sh->freeRidStack_.push_back( rids[i] );
		}
	}
}
Exemple #7
0
// Utility function: return the compartment in which the specified
// object is located.
// Simply traverses the tree toward the root till it finds a
// compartment. Pools use a special msg, but this works for reacs too.
ObjId getCompt( Id id )
{
	ObjId pa = Neutral::parent( id.eref() ).id;
	if ( pa == ObjId() )
		return pa;
	else if ( pa.element()->cinfo()->isA( "ChemCompt" ) )
		return pa;
	return getCompt( pa );
}
static Id makeCompt( Id parent, 
		const SwcSegment& seg, const SwcSegment& pa,
		double RM, double RA, double CM,
		unsigned int i, unsigned int j	)
{
	Shell* shell = reinterpret_cast< Shell* >( Id().eref().data() );
	double len = seg.radius() * 2.0;
	string name = "soma";
	Id compt;
	double x0, y0, z0;
	if ( seg.parent() != ~0U ) {
		len = seg.distance( pa );
		stringstream ss;
		ss << SwcSegment::typeName[ seg.type() ] << "_" << i << "_" << j;
		name = ss.str();
		x0 = pa.vec().a0();
		y0 = pa.vec().a1();
		z0 = pa.vec().a2();
	} else {
		x0 = seg.vec().a0() - len;
		y0 = seg.vec().a1();
		z0 = seg.vec().a2();
	}
	assert( len > 0.0 );
	compt = shell->doCreate( "Compartment", parent, name, 1 );
	Eref er = compt.eref();
	moose::CompartmentBase *cptr = reinterpret_cast< moose::CompartmentBase* >(
					compt.eref().data() );
	double xa = seg.radius() * seg.radius() * PI * 1e-12;
	len *= 1e-6;
	double dia = seg.radius() * 2.0e-6;
	cptr->setRm( er, RM / ( len * dia * PI ) );
	cptr->setRa( er, RA * len / xa );
	cptr->setCm( er, CM * ( len * dia * PI ) );
	cptr->setDiameter( dia );
	cptr->setLength( len );
	cptr->setX0( x0 * 1e-6 );
	cptr->setY0( y0 * 1e-6 );
	cptr->setZ0( z0 * 1e-6 );
	cptr->setX( seg.vec().a0() * 1e-6 );
	cptr->setY( seg.vec().a1() * 1e-6 );
	cptr->setZ( seg.vec().a2() * 1e-6 );
	return compt;
}
/**
 * Creates objects on remote nodes.
 * Also tests that objects on /library get created on all nodes.
 * \todo: Needs to be extended by creating objects on remote nodes with
 * parents on different remote nodes.
 */
Id testParCreate( vector< Id >& testIds )
{
	unsigned int myNode = MuMPI::INTRA_COMM().Get_rank();
	unsigned int numNodes = MuMPI::INTRA_COMM().Get_size();
	if ( myNode == 0 )
		cout << flush << "\nTest ParCreate";
	MuMPI::INTRA_COMM().Barrier();
	cout << "b" << myNode << flush;
	MuMPI::INTRA_COMM().Barrier();
	Eref shellE = Id::shellId().eref();
	assert( shellE.e != 0 );
	if ( myNode == 0 ) {
		Slot remoteCreateSlot = 
			initShellCinfo()->getSlot( "parallel.createSrc" );
		for ( unsigned int i = 1; i < numNodes; i++ ) {
			char name[20];
			sprintf( name, "tn%d", i );
			string sname = name;
			unsigned int tgt = ( i < myNode ) ? i : i - 1;
			Id newId = Id::makeIdOnNode( i );
			testIds.push_back( newId );
			// cout << "Create op: sendTo4( shellId, slot, " << tgt << ", " << "Neutral, " << sname << ", root, " << newId << endl;
			sendTo4< string, string, Nid, Nid >(
				shellE, remoteCreateSlot, tgt,
				"Neutral", sname, 
				Id(), newId
			);
		}
		Id libid = Id::localId( "/library" ); // a global
		ASSERT( libid.good(), "create libkids" );
		ASSERT( libid.isGlobal(), "create libkids" );
		SetConn c( shellE );
		Shell::staticCreate( &c, "Neutral", "foo", Id::UnknownNode, libid );
	}
	MuMPI::INTRA_COMM().Barrier();
	pollPostmaster(); // There is a barrier in the polling operation itself
	MuMPI::INTRA_COMM().Barrier();
	pollPostmaster();
	MuMPI::INTRA_COMM().Barrier();
	pollPostmaster();
	MuMPI::INTRA_COMM().Barrier();
	char name[20];
	sprintf( name, "/tn%d", myNode );
	string sname = name;
	Id kidid = Id::localId( "/library/foo" );
	ASSERT( kidid.good(), "create libkids" );
	ASSERT( kidid.isGlobal(), "create libkids" );
	bool ret = set( kidid.eref(), "destroy" );
	ASSERT( ret, "destroy libkids" );
	if ( myNode != 0 ) {
		Id tnId = Id::localId( sname );
		ASSERT( tnId.good(), "postmaster created obj on remote node" );
		return tnId;
	}
	return Id();
}
vector< Id > HSolve::children( Id obj )
{
    //~ return Field< vector< Id > >::get( obj, "children" );
    //~ return Field< vector< Id > >::fastGet( obj.eref(), "children" );
    //~ return localGet< Neutral, vector< Id > >( obj.eref(), "children" );

    vector< Id > c;
    Neutral::children( obj.eref(), c );
    return c;
}
Exemple #11
0
void ZombieCaConc::vSetSolver( const Eref& e, Id hsolve )
{
	if ( !hsolve.element()->cinfo()->isA( "HSolve" ) ) {
		cout << "Error: ZombieCaConc::vSetSolver: Object: " <<
				hsolve.path() << " is not an HSolve. Aborted\n";
		hsolve_ = 0;
		return;
	}
	hsolve_ = reinterpret_cast< HSolve* >( hsolve.eref().data() );
}
/**
 * This routine tests sending many packets over in one go. Tests
 * how many polls are needed for everything to execute, and whether
 * the execution order is clean.
 */
void testParCommandSequence()
{
	const unsigned int numSeq = 10;
	unsigned int myNode = MuMPI::INTRA_COMM().Get_rank();
	unsigned int numNodes = MuMPI::INTRA_COMM().Get_size();
	Eref shellE = Id::shellId().eref();
	char name[20];
	string sname;
	if ( myNode == 0 ) {
		cout << "\ntesting parallel command sequence" << flush;
	}
	if ( myNode == 0 ) {
		Slot remoteCreateSlot = 
			initShellCinfo()->getSlot( "parallel.createSrc" );
		Slot parSetSlot = 
			initShellCinfo()->getSlot( "parallel.setSrc" );
		for ( unsigned int j = 0; j < numSeq; j++ ) {
			for ( unsigned int i = 1; i < numNodes; i++ ) {
				char name[20];
				sprintf( name, "zug%d.%d", i, j );
				string sname = name;
				unsigned int tgt = ( i < myNode ) ? i : i - 1;
				Id newId = Id::makeIdOnNode( i );
				// cout << "Create op: sendTo4( shellId, slot, " << tgt << ", " << "Neutral, " << sname << ", root, " << newId << endl;
				sendTo4< string, string, Nid, Nid >(
					Id::shellId().eref(), remoteCreateSlot, tgt,
					"Table", sname, 
					Id(), newId
				);
				sname = sname + ".extra";
				sendTo3< Id, string, string >(
					Id::shellId().eref(), parSetSlot, tgt,
					newId, "name", sname
				);
			}
		}
	}
	for ( unsigned int i = 0 ; i < 5; i++ ) {
		pollPostmaster();
		MuMPI::INTRA_COMM().Barrier();
	}
	if ( myNode != 0 ) {
		for ( unsigned int j = 0; j < numSeq; j++ ) {
			sprintf( name, "/zug%d.%d.extra", myNode, j );
			sname = name;
			Id checkId = Id::localId( sname );
			// cout << "On " << myNode << ", checking id for " << sname << ": " << checkId << endl;
			ASSERT( checkId.good(), "parallel command sequencing" );

			// Clean up.
			set( checkId.eref(), "destroy" );
		}
		cout << myNode << flush;
	}
}
Exemple #13
0
void Gsolve::setStoich( Id stoich )
{
	// This call is done _before_ setting the path on stoich
	assert( stoich.element()->cinfo()->isA( "Stoich" ) );
	stoich_ = stoich;
	stoichPtr_ = reinterpret_cast< Stoich* >( stoich.eref().data() );
	sys_.stoich = stoichPtr_;
	sys_.isReady = false;
	for ( unsigned int i = 0; i < pools_.size(); ++i )
		pools_[i].setStoich( stoichPtr_ );
}
Exemple #14
0
void checkChildren( Id parent, const string& info )
{
    vector< Id > ret;
    Neutral::children( parent.eref(), ret );
    cout << info << " checkChildren of " <<
         parent.element()->getName() << ": " <<
         ret.size() << " children\n";
    for ( vector< Id >::iterator i = ret.begin(); i != ret.end(); ++i )
    {
        cout << i->element()->getName() << endl;
    }
}
void SigNeur::buildTree( Id soma, const vector< Id >& compts )
{
	const Finfo* axialFinfo;
	const Finfo* raxialFinfo;
	if ( soma.eref().e->cinfo() == initSymCompartmentCinfo() ) {
		axialFinfo = initSymCompartmentCinfo()->findFinfo( "raxial1" );
		raxialFinfo = initSymCompartmentCinfo()->findFinfo( "raxial2" );
	} else {
		axialFinfo = initCompartmentCinfo()->findFinfo( "axial" );
		raxialFinfo = initCompartmentCinfo()->findFinfo( "raxial" );
	}
	assert( axialFinfo != 0 );
	assert( raxialFinfo != 0 );
	
	// Soma may be in middle of messaging structure for cell, so we need
	// to traverse both ways. But nothing below soma should 
	// change direction in the traversal.
	innerBuildTree( 0, soma.eref(), soma.eref(), 
		axialFinfo->msg(), raxialFinfo->msg() );
	// innerBuildTree( 0, soma.eref(), soma.eref(), raxialFinfo->msg() );
}
/**
 * For now don't deal with taper
 */
unsigned int numSegments( Id compt, double lambda )
{
	double length = 0.0;
	// double dia = 0.0;
	assert( compt.good() );
	bool ret = get< double >( compt.eref(), "length", length );
	assert( ret );
	// ret = get< double >( compt.eref(), "diameter", dia );
	assert( ret );
	assert( length > 0.0 && lambda > 0.0 );
	return ( 1 + length / lambda );
}
Exemple #17
0
void Cell::setupSolver( Id cell, Id seed ) const
{
	Id solver = Id::nextId();
	vector< int > dims( 1, 1 );
	dims.push_back( 0 ); // isGlobal
	shell_->innerCreate( "HSolve", cell, solver, solverName_, dims );
	
	//~ Id solver = shell_->doCreate( "HSolve", cell, solverName_ );
	HSolve* data = reinterpret_cast< HSolve* >( solver.eref().data() );
	data->setSeed( seed );
	//~ shell_->doUseClock( solver.path(), "proc", solverClock_ );
}
Exemple #18
0
void ZombieMMenz::setSolver( Id solver, Id orig )
{
	static const DestFinfo* enz = dynamic_cast< const DestFinfo* >(
		EnzBase::initCinfo()->findFinfo( "enzDest" ) );
	static const SrcFinfo* sub = dynamic_cast< const SrcFinfo* >(
		EnzBase::initCinfo()->findFinfo( "toSub" ) );
	static const SrcFinfo* prd = dynamic_cast< const SrcFinfo* >(
		EnzBase::initCinfo()->findFinfo( "toPrd" ) );
	assert( enz );
	assert( sub );
	assert( prd );

	stoich_ = reinterpret_cast< Stoich* >( solver.eref().data() );

	/// Now set up the RateTerm
	vector< Id > subvec;
	vector< Id > prdvec;
	unsigned int rateIndex = stoich_->convertIdToReacIndex( orig );
	unsigned int num = orig.element()->getNeighbours( subvec, enz );
	unsigned int enzIndex = stoich_->convertIdToPoolIndex( subvec[0] );
	MMEnzymeBase* meb;

	double numKm = 1.0; // Dummy default initial values, later to be reset
	double kcat = 1.0;
	/*
	double numKm = base->zGetNumKm( orig.eref(), 0 );
	double kcat = base->zGetKcat( orig.eref(), 0 );
	*/

	num = orig.element()->getNeighbours( subvec, sub );
	if ( num == 1 ) {
		unsigned int subIndex = stoich_->convertIdToPoolIndex( subvec[0] );
		meb = new MMEnzyme1( numKm, kcat, enzIndex, subIndex );
	} else if ( num > 1 ) {
		vector< unsigned int > v;
		for ( unsigned int i = 0; i < num; ++i )
			v.push_back( stoich_->convertIdToPoolIndex( subvec[i] ) );
		ZeroOrder* rateTerm = new NOrder( 1.0, v );
		meb = new MMEnzyme( numKm, kcat, enzIndex, rateTerm );
	} else {
		cout << "Error: ZombieMMenz::zombify: No substrates for "  <<
			orig.path() << endl;
		cout << "Will ignore and continue, but don't be surprised if "
		"simulation fails.\n";
		// assert( 0 );
		return;
	}
	num = orig.element()->getNeighbours( prdvec, prd );
	stoich_->installMMenz( meb, rateIndex, subvec, prdvec );
}
/**
 * Recursive function to compare all descendants and cram matches into ret.
 * Returns number of matches.
 */
int allChildren( Id start, const string& insideBrace, unsigned int index,
	vector< Id >& ret )
{
	unsigned int nret = ret.size();
	vector< Id > kids;
	Neutral::getChildren( start.eref(), kids );
	vector< Id >::iterator i;
	for ( i = kids.begin(); i != kids.end(); i++ ) {
		if ( matchName( start, *i, "#", insideBrace, index ) )
			ret.push_back( *i );
		allChildren( *i, insideBrace, index, ret );
	}
	return ret.size() - nret;
}
void SigNeur::schedule( Eref me )
{
	static const Finfo* lookupChildFinfo =
		initNeutralCinfo()->findFinfo( "lookupChild" );
	Id kinId;
	lookupGet< Id, string >( me, lookupChildFinfo, kinId, "kinetics" );
	assert( kinId.good() );

	Id cellId;
	lookupGet< Id, string >( me, lookupChildFinfo, cellId, "cell" );
	assert( cellId.good() );

	SetConn c( Id::shellId().eref() );
	Shell::setClock( &c, 0, cellDt_, 0 );
	Shell::setClock( &c, 1, cellDt_, 1 );
	Shell::setClock( &c, 2, cellDt_, 2 );
	Shell::setClock( &c, 3, sigDt_, 0 );
	Shell::setClock( &c, 4, sigDt_, 1 );

	set< string >( cellId.eref(), "method", cellMethod_ );
	set< string >( kinId.eref(), "method", dendMethod_ );
	if ( separateSpineSolvers_ ) {
		vector< Id > kids;
		get< vector< Id > >( spine_.eref(), "childList", kids );
		cout << "Setting separate spine method " << spineMethod_ <<
			" to " << kids.size() << " spines\n";
		for ( vector< Id >::iterator i = kids.begin(); 
			i != kids.end(); ++i )
			set< string >( i->eref(), "method", spineMethod_ );
	}

	Shell::useClock( &c, "t3", "/sig/kinetics", "process" );
	Shell::useClock( &c, "t3", "/sig/kinetics/solve/hub", "process" );
	Shell::useClock( &c, "t3", "/sig/kinetics/solve/integ", "process" );

	Shell::useClock( &c, "t4", "/sig/cell/##[][TYPE==Adaptor]", "process" );
}
/**
 * wildcardFieldComparison returns true if the value of the
 * specified field matches the value in the comparsion string mid.
 * Format is FIELD(name)=val
 * If the format or the value does not match, return 0
 */
static bool wildcardFieldComparison( Id id, const string& mid )
{
	// where = could be the usual comparison operators and val
	// could be a number. No strings yet

	string::size_type pos = mid.find(')');
	if ( pos == string::npos )
		return 0;
	string fieldName = mid.substr( 0, pos );
	string::size_type pos2 = mid.find_last_of( "=<>" );
	if ( pos2 == string::npos )
		return 0;
	string op = mid.substr( pos + 1, pos2 - pos );

	string testValue = mid.substr( pos2 + 1 );

	if ( testValue.length() == 0 )
		return 0;

	const Finfo* f = id()->findFinfo( fieldName );
	if ( !f )
		return 0;

	// At this point we don't want to compare multivalue fields.
	if ( f->ftype()->nValues() != 1 )
		return 0;
	
	string actualValue;
	bool ret = f->strGet( id.eref(), actualValue );
	if ( ret == 0 )
		return 0;
	if ( op == "==" || op == "=" )
		return ( testValue == actualValue );
	if ( op == "!=" )
		return ( testValue != actualValue );
	
	double v1 = atof( actualValue.c_str() );
	double v2 = atof( testValue.c_str() );
	if ( op == ">" )
		return ( v1 > v2 );
	if ( op == ">=" )
		return ( v1 >= v2 );
	if ( op == "<" )
		return ( v1 < v2 );
	if ( op == "<=" )
		return ( v1 <= v2 );

	return 0;
}
Exemple #22
0
void Gsolve::setDsolve( Id dsolve )
{
	if ( dsolve == Id () ) {
		dsolvePtr_ = 0;
		dsolve_ = Id();
	} else if ( dsolve.element()->cinfo()->isA( "Dsolve" ) ) {
		dsolve_ = dsolve;
		dsolvePtr_ = reinterpret_cast< ZombiePoolInterface* >( 
						dsolve.eref().data() );
	} else {
		cout << "Warning: Gsolve::setDsolve: Object '" << dsolve.path() <<
				"' should be class Dsolve, is: " << 
				dsolve.element()->cinfo()->name() << endl;
	}
}
void testCompartment()
{
	unsigned int size = 1;
	Eref sheller( Id().eref() );
	Shell* shell = reinterpret_cast< Shell* >( sheller.data() );
        Id comptId = shell->doCreate("Compartment", Id(), "compt", size);
	assert( Id::isValid(comptId));
	Eref compter = comptId.eref();
	Compartment* c = reinterpret_cast< Compartment* >( comptId.eref().data() );
	ProcInfo p;
	p.dt = 0.002;
	c->setInject( compter, 1.0 );
	c->setRm( compter, 1.0 );
	c->setRa( compter, 0.0025 );
	c->setCm( compter, 1.0 );
	c->setEm( compter, 0.0 );
	c->setVm( compter, 0.0 );

	// First, test charging curve for a single compartment
	// We want our charging curve to be a nice simple exponential
	// Vm = 1.0 - 1.0 * exp( - t / 1.0 );
	double delta = 0.0;
	double Vm = 0.0;
	double tau = 1.0;
	double Vmax = 1.0;
	for ( p.currTime = 0.0; p.currTime < 2.0; p.currTime += p.dt ) 
	{
		Vm = c->getVm( compter );
		double x = Vmax - Vmax * exp( -p.currTime / tau );
		delta += ( Vm - x ) * ( Vm - x );
		c->process( compter, &p );
	}
	assert( delta < 1.0e-6 );
        shell->doDelete(comptId);
	cout << "." << flush;
}
Exemple #24
0
// static function
bool Neutral::isDescendant( Id me, Id ancestor )
{
	static const Finfo* pf = neutralCinfo->findFinfo( "parentMsg" );
	static const DestFinfo* pf2 = dynamic_cast< const DestFinfo* >( pf );
	static const FuncId pafid = pf2->getFid();

	Eref e = me.eref();
	
	while ( e.element()->id() != Id() && e.element()->id() != ancestor ) {
		ObjId mid = e.element()->findCaller( pafid );
		assert( mid != ObjId() );
		ObjId fid = Msg::getMsg( mid )->findOtherEnd( e.objId() );
		e = fid.eref();
	}
	return ( e.element()->id() == ancestor );
}
Exemple #25
0
/**
 * Launches Parser. Blocking when the parser blocks.
 */
void Shell::launchParser()
{
	Id shellId;
	Shell* s = reinterpret_cast< Shell* >( shellId.eref().data() );
	bool quit = 0;

	cout << "moose : " << flush;
	while ( !quit ) {
		string temp;
		cin >> temp;
		if ( temp == "quit" || temp == "q" ) {
			s->doQuit();
			quit = 1;
		}
	}
	cout << "\nQuitting Moose\n" << flush;
}
Exemple #26
0
/*    set up Michalies Menten reaction  */
void SbmlReader::setupMMEnzymeReaction( Reaction * reac,string rid,string rname,const map< string, Id > &molSidcmptMIdMap ) {
    string::size_type loc = rid.find( "_MM_Reaction_" );
    if( loc != string::npos ) {
        int strlen = rid.length();
        rid.erase( loc,strlen-loc );
    }
    unsigned int num_modifr = reac->getNumModifiers();
    for ( unsigned int m = 0; m < num_modifr; m++ ) {
        const ModifierSpeciesReference* modifr=reac->getModifier( m );
        std::string sp = modifr->getSpecies();
        Id enzyme_;
        Id E = molSidMIdMap_.find(sp)->second;

        Id comptRef = molSidcmptMIdMap.find(sp)->second; //gives compartment of sp
        Id meshEntry = Neutral::child( comptRef.eref(), "mesh" );
        Shell* shell = reinterpret_cast< Shell* >( Id().eref().data() );
        enzyme_ = shell->doCreate("MMenz",E,rname,1);
        //shell->doAddMsg( "Single", meshEntry, "remeshReacs", enzyme_, "remesh");
        shell->doAddMsg("Single",E,"nOut",enzyme_,"enzDest");

        KineticLaw * klaw=reac->getKineticLaw();
        vector< double > rate;
        rate.clear();
        getKLaw( klaw,true,rate );
        if ( errorFlag_ )
            return;
        else if ( !errorFlag_ ) {
            for ( unsigned int rt = 0; rt < reac->getNumReactants(); rt++ ) {
                const SpeciesReference* rct = reac->getReactant( rt );
                sp=rct->getSpecies();
                Id S = molSidMIdMap_.find(sp)->second;
                shell->doAddMsg( "OneToOne", enzyme_, "sub" ,S , "reac" );
            }
            for ( unsigned int pt = 0; pt < reac->getNumProducts(); pt++ ) {
                const SpeciesReference* pdt = reac->getProduct(pt);
                sp = pdt->getSpecies();
                Id P = molSidMIdMap_.find(sp)->second;
                shell->doAddMsg( "OneToOne", enzyme_, "prd" ,P, "reac" );
            }
            Field < double > :: set( enzyme_, "kcat", rate[0] );
            Field < double > :: set( enzyme_, "numKm", rate[1] );
        }

    }
}
void Ksolve::setStoich( Id stoich )
{
    assert( stoich.element()->cinfo()->isA( "Stoich" ) );
    stoich_ = stoich;
    stoichPtr_ = reinterpret_cast< Stoich* >( stoich.eref().data() );
    if ( !isBuilt_ )
    {
        OdeSystem ode;
        ode.epsAbs = epsAbs_;
        ode.epsRel = epsRel_;
        // ode.initStepSize = getEstimatedDt();
        ode.initStepSize = 0.01; // This will be overridden at reinit.
        ode.method = method_;
#ifdef USE_GSL
        ode.gslSys.dimension = stoichPtr_->getNumAllPools();
        if ( ode.gslSys.dimension == 0 )
            return; // No pools, so don't bother.
        innerSetMethod( ode, method_ );
        ode.gslSys.function = &VoxelPools::gslFunc;
        ode.gslSys.jacobian = 0;
        innerSetMethod( ode, method_ );
        unsigned int numVoxels = pools_.size();
        for ( unsigned int i = 0 ; i < numVoxels; ++i )
        {
            ode.gslSys.params = &pools_[i];
            pools_[i].setStoich( stoichPtr_, &ode );
            // pools_[i].setIntDt( ode.initStepSize ); // We're setting it up anyway
        }
#elif USE_BOOST
        ode.dimension = stoichPtr_->getNumAllPools();
        ode.boostSys.epsAbs = epsAbs_;
        ode.boostSys.epsRel = epsRel_;
        ode.boostSys.method = method_;
        if ( ode.dimension == 0 )
            return; // No pools, so don't bother.
        unsigned int numVoxels = pools_.size();
        for ( unsigned int i = 0 ; i < numVoxels; ++i )
        {
            ode.boostSys.params = &pools_[i];
            pools_[i].setStoich( stoichPtr_, &ode );
        }
#endif
        isBuilt_ = true;
    }
}
Exemple #28
0
void ReadCell::addChannelMessage( Id chan )
{
	/*
	* Get child objects of type Mstring, named addmsg1, 2, etc.
	* These define extra messages to be assembled at setup.
	* Similar to what was done with GENESIS.
	*/
	vector< Id > kids;
	Neutral::children( chan.eref(), kids );
	Shell *shell = reinterpret_cast< Shell* >( Id().eref().data() );
	Id cwe = shell->getCwe();
	shell->setCwe( chan );
	for ( vector< Id >::iterator i = kids.begin(); i != kids.end(); ++i )
	{
		// Ignore kid if its name does not begin with "addmsg"..
		const string& name = i->element()->getName();
		if ( name.find( "addmsg", 0 ) != 0 )
			continue;

		string s = Field< string >::get( *i, "value" );
		vector< string > token;
		tokenize( s, " 	", token );
		assert( token.size() == 4 );
		ObjId src = shell->doFind( token[0] );
		ObjId dest = shell->doFind( token[2] );

		// I would like to assert, or warn here, but there are legitimate 
		// cases where not all possible messages are actually available 
		// to set up. So I just bail.
		if ( src.bad() || dest.bad()) {
#ifndef NDEBUG
				/*
			cout << "ReadCell::addChannelMessage( " << chan.path() << 
				"): " << name << " " << s << 
				": Bad src " << src << " or dest " << dest << endl;
				*/
#endif
			continue; 
		}
		ObjId mid = 
			shell->doAddMsg( "single", src, token[1], dest, token[3] );
		assert( !mid.bad());
	}
	shell->setCwe( cwe );
}
Exemple #29
0
/**
 * @brief Add a table to streamer.
 *
 * @param table Id of table.
 */
void Streamer::addTable( Id table )
{
    // If this table is not already in the vector, add it.
    for( size_t i = 0; i < tableIds_.size(); i++)
        if( table.path() == tableIds_[i].path() )
            return;                             /* Already added. */

    Table* t = reinterpret_cast<Table*>(table.eref().data());
    tableIds_.push_back( table );
    tables_.push_back( t );
    tableTick_.push_back( table.element()->getTick() );

    // NOTE: If user can make sure that names are unique in table, using name is
    // better than using the full path.
    if( t->getColumnName().size() > 0 )
        columns_.push_back( t->getColumnName( ) );
    else
        columns_.push_back( moose::moosePathToUserPath( table.path() ) );
}
void SteadyState::setStoich( Id value ) {
	if ( !value.element()->cinfo()->isA( "Stoich" ) ) {
		cout << "Error: SteadyState::setStoich: Must be of Stoich class\n";
		return;
	}

	stoich_ = value;
	Stoich* stoichPtr = reinterpret_cast< Stoich* >( value.eref().data());
	numVarPools_ = Field< unsigned int >::get( stoich_, "numVarPools" );
	nReacs_ = Field< unsigned int >::get( stoich_, "numRates" );
	setupSSmatrix();
	double vol = LookupField< unsigned int, double >::get(
				stoichPtr->getCompartment(), "oneVoxelVolume", 0 );
	pool_.setVolume( vol );
	pool_.setStoich( stoichPtr, 0 );
	pool_.updateAllRateTerms( stoichPtr->getRateTerms(),
				   stoichPtr->getNumCoreRates() );
	isInitialized_ = 1;
}