示例#1
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;
}
示例#2
0
//Simple tests on whether the exponential lookup tables are being set
//to the correct size and the lookup function tests.
//Cannot test the interpolation routines here as there is not matrix
//exponential method in the base class.
//testMarkovSolver() defined in MarkovSolver.cpp contains this test.
void testMarkovSolverBase()
{

	const Cinfo* rateTableCinfo = MarkovRateTable::initCinfo();
	const Cinfo* interpol2dCinfo = Interpol2D::initCinfo();
	const Cinfo* vectorTableCinfo = VectorTable::initCinfo();
	const Cinfo* solverBaseCinfo = MarkovSolverBase::initCinfo();

	Id vecTableId = Id::nextId();
	Id int2dId = Id::nextId();

	vector< Id > rateTableIds;
	vector< Id > solverBaseIds;

	vector< Element* > rateTableElements;
	vector< Eref* > rateTableErefs;

	vector< Element* > solverBaseElements;
	vector< Eref* > solverBaseErefs;

	vector< MarkovRateTable* > rateTables;
	vector< MarkovSolverBase* > solverBases;

	vector< DimInfo > single;
	string str;

	unsigned int numCopies = 4;

	for ( unsigned int i = 0; i < numCopies; ++i )
	{
		rateTableIds.push_back( Id::nextId() );
		str = string("ratetable") + static_cast< char >( 65 + i );
		rateTableElements.push_back( new Element( rateTableIds[i], rateTableCinfo, 
																		str, single, 1 ) );
		rateTableErefs.push_back( new Eref( rateTableElements[i], 0 ) );
		rateTables.push_back( reinterpret_cast< MarkovRateTable* >(
															rateTableErefs[i]->data() ) );

		solverBaseIds.push_back( Id::nextId() );
		str = string("solverbase") + static_cast< char >( 65 + i );
		solverBaseElements.push_back( new Element( solverBaseIds[i], solverBaseCinfo,
																	str, single, 1 ) );
		solverBaseErefs.push_back( new Eref( solverBaseElements[i], 0 ) );
		solverBases.push_back( reinterpret_cast< MarkovSolverBase* >(
															solverBaseErefs[i]->data() ) );				
	}

	Element *eInt2d = new Element( int2dId, interpol2dCinfo, "int2d", single, 1 );
	Element *eVecTable = new Element( vecTableId, vectorTableCinfo, "vecTable",
																		single, 1 );

	Interpol2D *int2dTable;
	VectorTable* vecTable;

	Eref int2dEref( eInt2d, 0 );
	int2dTable = reinterpret_cast< Interpol2D* >( int2dEref.data() );

	Eref vecTableEref( eVecTable, 0 );
	vecTable = reinterpret_cast< VectorTable* >( vecTableEref.data() );

	//////////////////////////////
	//ratetables[0]		//Only 2D rates.
	//ratetables[1]		//1D and 2D rates.
	//ratetables[2]		//Only ligand dependent rates.
	//ratetables[3]  	//Only voltage dependent rates.
	//////////////////////////////

	////////
	//Case 1 :
	//Rates (1,2) and (2,3) are ligand and voltage dependent.
	///////
	rateTables[0]->init( 3 );

	setupInterpol2D( int2dTable, 201, -0.05, 0.10, 151, 1e-9, 50e-9 );
	rateTables[0]->setInt2dChildTable( 1, 2, int2dId );

	setupInterpol2D( int2dTable, 175, -0.02, 0.19, 151, 3e-9, 75e-9 );
	rateTables[0]->setInt2dChildTable( 2, 3, int2dId );

	solverBases[0]->init( rateTableIds[0], 0.1 );
	
	assert( solverBases[0]->getXdivs() == 201 );
	assert( doubleEq( solverBases[0]->getXmin(), -0.05 ) ); 
	assert( doubleEq( solverBases[0]->getXmax(), 0.19 ) );
	assert( solverBases[0]->getYdivs() == 151 );
	
	//1D and 2D rates.
	rateTables[1]->init( 5 );	

	///////
	//Case 2 :
	//Rates (1,2) and (1,3) are ligand and voltage dependent.
	//Rates (2,1) and (3,1) are voltage and ligand dependent respectively.
	//////
	setupInterpol2D( int2dTable, 250, -0.10, 0.75, 101, 10e-9, 25e-8 );
	rateTables[1]->setInt2dChildTable( 1, 2, int2dId );

	setupInterpol2D( int2dTable, 275, -0.05, 0.55, 141, 5e-9, 40e-7 );
	rateTables[1]->setInt2dChildTable( 1, 3, int2dId );

	//Voltage dependent.
	setupVectorTable( vecTable, 145, -0.17, 0.73 );
	rateTables[1]->setVtChildTable( 2, 1, vecTableId, 0 );

	//Ligand dependent
	setupVectorTable( vecTable, 375, 7e-9, 75e-7 );
	rateTables[1]->setVtChildTable( 3, 1, vecTableId, 1 );

	solverBases[1]->init( rateTableIds[1], 0.1 );

	assert( solverBases[1]->getXdivs() == 275 ); 
	assert( solverBases[1]->getYdivs() == 375 );
	assert( doubleEq( solverBases[1]->getXmin(), -0.17 ) );
	assert( doubleEq( solverBases[1]->getXmax(), 0.75 ) );
	assert( doubleEq( solverBases[1]->getYmin(), 5e-9 ) );
	assert( doubleEq( solverBases[1]->getYmax(), 75e-7 ) );

	////////
	//Case 3 : Only ligand dependent rates.
	//Rates (1, 2), (3, 5), (2, 4), (4, 1).
	///////

	rateTables[2]->init( 5 );
		
	setupVectorTable( vecTable, 155, 7e-9, 50e-9 );
	rateTables[2]->setVtChildTable( 1, 2, vecTableId, 1 );

	setupVectorTable( vecTable, 190, 4e-9, 35e-9 ); 
	rateTables[2]->setVtChildTable( 3, 5, vecTableId, 1 );

	setupVectorTable( vecTable, 120, 7e-9, 90e-9 );
	rateTables[2]->setVtChildTable( 2, 4, vecTableId, 1 );

	setupVectorTable( vecTable, 250, 10e-9, 100e-9 );
	rateTables[2]->setVtChildTable( 4, 1, vecTableId, 1 );

	solverBases[2]->init( rateTableIds[2], 0.1 );

	assert( doubleEq( 1e-308 * solverBases[2]->getYmin(), 1e-308 * DBL_MAX ) );
	assert( doubleEq( 1e308 * solverBases[2]->getYmax(), 1e308 * DBL_MIN ) );
	assert( solverBases[2]->getYdivs() == 0u );

	assert( doubleEq( solverBases[2]->getXmin(), 4e-9 ) );
	assert( doubleEq( solverBases[2]->getXmax(), 100e-9 ) );
	assert( solverBases[2]->getXdivs() == 250 );

	///////
	//Case 4 : Only voltage dependent rates.
	//Rates (3,6), (5, 6), (1, 4). 
	//////

	rateTables[3]->init( 7 );

	setupVectorTable( vecTable, 100, -0.05, 0.1 );
	rateTables[3]->setVtChildTable( 3, 6, vecTableId, 1 );

	setupVectorTable( vecTable, 190, -0.15, 0.2 );
	rateTables[3]->setVtChildTable( 5, 6, vecTableId, 1 );

	setupVectorTable( vecTable, 140, -0.2, 0.1 );
	rateTables[3]->setVtChildTable( 1, 4, vecTableId, 1 );

	solverBases[3]->init( rateTableIds[3], 0.1 );

	assert( doubleEq( 1e-308 * solverBases[3]->getYmin(), 1e-308 * DBL_MAX ) );
	assert( doubleEq( 1e308 * solverBases[3]->getYmax(), 1e308 * DBL_MIN ) );
	assert( solverBases[3]->getYdivs() == 0u );

	assert( doubleEq( solverBases[3]->getXmin(), -0.2 ) );
	assert( doubleEq( solverBases[3]->getXmax(), 0.2 ) );
	assert( solverBases[3]->getXdivs() == 190 );

	for ( unsigned int i = 0; i < numCopies; ++i )
	{
		rateTableIds[i].destroy();
		solverBaseIds[i].destroy();
		delete rateTableErefs[i];
		delete solverBaseErefs[i];
	}

	int2dId.destroy();
	vecTableId.destroy();

	cout << "." << flush;
}