MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
testKinetics.cpp File Reference
#include "header.h"
#include "../shell/Shell.h"
#include "ReadKkit.h"
#include "ReadCspace.h"
#include "EnzBase.h"
#include "MMenz.h"
#include "ReacBase.h"
#include "Reac.h"
+ Include dependency graph for testKinetics.cpp:

Go to the source code of this file.

Functions

double estT (double s)
 
bool isClose (double x, double y, double tol)
 
void testKinetics ()
 
void testKineticsProcess ()
 
void testMMenz ()
 
void testMMenzProcess ()
 
void testMpiKinetics ()
 
void testPoolVolumeScaling ()
 
void testReacVolumeScaling ()
 
void testReadCspace ()
 
void testReadKkit ()
 
void testTwoReacGetNeighbors ()
 
void testVolSort ()
 
void testWriteKkit (Id id)
 

Function Documentation

double estT ( double  s)

Definition at line 223 of file testKinetics.cpp.

References moose::log(), and s0.

Referenced by testMMenzProcess().

224 {
225  double E = 1.0;
226  double Km = 1.0;
227  double kcat = 1.0;
228  double s0 = 1.0;
229  double c = -Km * log( s0 ) - s0;
230  double t = (-1.0 /( E * kcat ) ) * ( ( Km * log( s ) + s ) + c );
231  return t;
232 }
void log(string msg, serverity_level_ type=debug, bool redirectToConsole=true, bool removeTicks=true)
Log to console (and to a log-file)
static SrcFinfo0 s0("s0","")

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool isClose ( double  x,
double  y,
double  tol 
)

Definition at line 35 of file testKinetics.cpp.

36 {
37  return ( fabs( x - y ) < tol * 1e-8 );
38 }
void testKinetics ( )

Definition at line 331 of file testKinetics.cpp.

References testMMenz(), testPoolVolumeScaling(), testReacVolumeScaling(), testReadCspace(), testTwoReacGetNeighbors(), and testVolSort().

332 {
334  testMMenz();
337  testReadCspace();
338  testVolSort();
339 
340  // This is now handled with real models in the regression tests.
341  // testWriteKkit( Id() );
342 }
void testMMenz()
void testReacVolumeScaling()
void testTwoReacGetNeighbors()
void testPoolVolumeScaling()
void testVolSort()
void testReadCspace()

+ Here is the call graph for this function:

void testKineticsProcess ( )

Definition at line 348 of file testKinetics.cpp.

References testMMenzProcess().

349 {
351 }
void testMMenzProcess()

+ Here is the call graph for this function:

void testMMenz ( )

Definition at line 198 of file testKinetics.cpp.

References Eref::data(), Shell::doCreate(), Shell::doDelete(), doubleEq(), Id::eref(), MMenz::vEnz(), MMenz::vGetKcat(), MMenz::vGetKm(), MMenz::vProcess(), MMenz::vReinit(), MMenz::vSetKcat(), MMenz::vSetKm(), and MMenz::vSub().

Referenced by testKinetics().

199 {
200  Shell* shell = reinterpret_cast< Shell* >( Id().eref().data() );
201  Id mmid = shell->doCreate( "MMenz", Id(), "mm", 1 ); // mmenz
202  MMenz m;
203  ProcInfo p;
204 
205  m.vSetKm( mmid.eref(), 5.0 );
206  m.vSetKcat( mmid.eref(), 4.0 );
207  m.vReinit( mmid.eref(), &p );
208  m.vSub( 2 );
209  m.vEnz( 3 );
210  assert( doubleEq( m.vGetKm( mmid.eref() ), 5.0 ) );
211  assert( doubleEq( m.vGetKcat( mmid.eref() ), 4.0 ) );
212  m.vProcess( mmid.eref(), &p );
213 
214  shell->doDelete( mmid );
215  cout << "." << flush;
216 }
double vGetKm(const Eref &e) const
Definition: MMenz.cpp:115
void vSetKm(const Eref &e, double v)
Definition: MMenz.cpp:108
char * data() const
Definition: Eref.cpp:41
Eref eref() const
Definition: Id.cpp:125
void vProcess(const Eref &e, ProcPtr p)
Definition: MMenz.cpp:82
Id doCreate(string type, ObjId parent, string name, unsigned int numData, NodePolicy nodePolicy=MooseBlockBalance, unsigned int preferredNode=1)
Definition: Shell.cpp:181
bool doubleEq(double x, double y)
Definition: doubleEq.cpp:16
void vSub(double n)
Definition: MMenz.cpp:72
double vGetKcat(const Eref &e) const
Definition: MMenz.cpp:141
void vSetKcat(const Eref &e, double v)
Definition: MMenz.cpp:134
void vEnz(double n)
Definition: MMenz.cpp:77
bool doDelete(ObjId oid)
Definition: Shell.cpp:259
Definition: Id.h:17
void vReinit(const Eref &e, ProcPtr p)
Definition: MMenz.cpp:91
Definition: MMenz.h:18
Definition: Shell.h:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testMMenzProcess ( )

Definition at line 234 of file testKinetics.cpp.

References Eref::data(), Shell::doAddMsg(), Shell::doCreate(), Shell::doDelete(), Shell::doReinit(), Shell::doSetClock(), Shell::doStart(), doubleApprox(), Shell::doUseClock(), Id::eref(), estT(), and Field< A >::set().

Referenced by testKineticsProcess().

235 {
236  Shell* shell = reinterpret_cast< Shell* >( Id().eref().data() );
238  // This set is the test kinetic calculation using MathFunc
240  Id nid = shell->doCreate( "Neutral", Id(), "n", 1 );
242  // This set is the reference kinetic calculation using MMEnz
244  Id pid = shell->doCreate( "Pool", nid, "p", 1 ); // substrate
245  Id qid = shell->doCreate( "Pool", nid, "q", 1 ); // enz mol
246  Id rid = shell->doCreate( "Pool", nid, "r", 1 ); // product
247  Id mmid = shell->doCreate( "MMenz", nid, "mm", 1 ); // mmenz
248 
249  Id tabid2 = shell->doCreate( "Table", nid, "tab2", 1 ); //output plot
250 
251  Field< double >::set( mmid, "Km", 1.0 );
252  Field< double >::set( mmid, "kcat", 1.0 );
253  Field< double >::set( pid, "nInit", 1.0 );
254  Field< double >::set( qid, "nInit", 1.0 );
255  Field< double >::set( rid, "nInit", 0.0 );
256 
257  shell->doAddMsg( "Single", ObjId( mmid ), "sub", ObjId( pid ), "reac" );
258  shell->doAddMsg( "Single", ObjId( mmid ), "prd", ObjId( rid ), "reac" );
259  shell->doAddMsg( "Single", ObjId( qid ), "nOut", ObjId( mmid ), "enzDest" );
260  shell->doAddMsg( "Single", ObjId( pid ), "nOut", ObjId( tabid2 ), "input" );
261  shell->doSetClock( 0, 0.01 );
262  shell->doSetClock( 1, 0.01 );
263  shell->doUseClock( "/n/mm,/n/tab2", "process", 0 );
264  shell->doUseClock( "/n/#[ISA=Pool]", "process", 1 );
265 
267  // Now run models and compare outputs
269 
270  shell->doReinit();
271  shell->doStart( 10 );
272 
273  vector< double > vec = Field< vector< double > >::get( tabid2, "vec" );
274  assert( vec.size() == 1001 );
275  for ( unsigned int i = 0; i < vec.size(); ++i ) {
276  double t = 0.01 * i;
277  double et = estT( vec[i] );
278  assert( doubleApprox( t, et ) );
279  }
280 
281  shell->doDelete( nid );
282  cout << "." << flush;
283 }
void doStart(double runtime, bool notify=false)
Definition: Shell.cpp:332
char * data() const
Definition: Eref.cpp:41
void doSetClock(unsigned int tickNum, double dt)
Definition: Shell.cpp:377
Definition: SetGet.h:236
Definition: ObjId.h:20
Eref eref() const
Definition: Id.cpp:125
static bool set(const ObjId &dest, const string &field, A arg)
Definition: SetGet.h:245
Id doCreate(string type, ObjId parent, string name, unsigned int numData, NodePolicy nodePolicy=MooseBlockBalance, unsigned int preferredNode=1)
Definition: Shell.cpp:181
bool doubleApprox(double x, double y)
Definition: doubleEq.cpp:24
void doReinit()
Definition: Shell.cpp:362
ObjId doAddMsg(const string &msgType, ObjId src, const string &srcField, ObjId dest, const string &destField)
Definition: Shell.cpp:269
bool doDelete(ObjId oid)
Definition: Shell.cpp:259
Definition: Id.h:17
void doUseClock(string path, string field, unsigned int tick)
Definition: Shell.cpp:382
double estT(double s)
Definition: Shell.h:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testMpiKinetics ( )

Definition at line 344 of file testKinetics.cpp.

345 {
346 }
void testPoolVolumeScaling ( )

Definition at line 40 of file testKinetics.cpp.

References Eref::data(), Shell::doAddMsg(), Shell::doCreate(), Shell::doDelete(), doubleEq(), Id::eref(), Field< A >::get(), NA, PI, Field< A >::set(), and Id::value().

Referenced by testKinetics().

41 {
42  Shell* shell = reinterpret_cast< Shell* >( Id().eref().data() );
43  Id comptId = shell->doCreate( "CylMesh", Id(), "cyl", 1 );
44  Id meshId( comptId.value() + 1 );
45  Id poolId = shell->doCreate( "Pool", comptId, "pool", 1 );
46 
47  ObjId mid = shell->doAddMsg( "OneToOne",
48  ObjId( poolId, 0 ), "requestVolume",
49  ObjId( meshId, 0 ), "get_volume" );
50 
51  assert( mid != ObjId() );
52 
53  vector< double > coords( 9, 0.0 );
54  double x1 = 100e-6;
55  double r0 = 10e-6;
56  double r1 = 5e-6;
57  double lambda = x1;
58  coords[3] = x1;
59  coords[6] = r0;
60  coords[7] = r1;
61  coords[8] = lambda;
62 
63  Field< vector< double > >::set( comptId, "coords", coords );
64 
65  double volume = Field< double >::get( poolId, "volume" );
66  assert( doubleEq( volume, PI * x1 * (r0+r1) * (r0+r1) / 4.0 ) );
67 
68  Field< double >::set( poolId, "n", 400 );
69  double volscale = 1 / ( NA * volume );
70  double conc = Field< double >::get( poolId, "conc" );
71  assert( doubleEq( conc, 400 * volscale ) );
72  Field< double >::set( poolId, "conc", 500 * volscale );
73  double n = Field< double >::get( poolId, "n" );
74  assert( doubleEq( n, 500 ) );
75 
76  Field< double >::set( poolId, "nInit", 650 );
77  double concInit = Field< double >::get( poolId, "concInit" );
78  assert( doubleEq( concInit, 650 * volscale ) );
79  Field< double >::set( poolId, "concInit", 10 * volscale );
80  n = Field< double >::get( poolId, "nInit" );
81  assert( doubleEq( n, 10 ) );
82 
83  shell->doDelete( comptId );
84  cout << "." << flush;
85 }
char * data() const
Definition: Eref.cpp:41
const double NA
Definition: consts.cpp:15
unsigned int value() const
Definition: Id.cpp:197
Definition: SetGet.h:236
Definition: ObjId.h:20
Eref eref() const
Definition: Id.cpp:125
static bool set(const ObjId &dest, const string &field, A arg)
Definition: SetGet.h:245
Id doCreate(string type, ObjId parent, string name, unsigned int numData, NodePolicy nodePolicy=MooseBlockBalance, unsigned int preferredNode=1)
Definition: Shell.cpp:181
bool doubleEq(double x, double y)
Definition: doubleEq.cpp:16
ObjId doAddMsg(const string &msgType, ObjId src, const string &srcField, ObjId dest, const string &destField)
Definition: Shell.cpp:269
const double PI
Definition: consts.cpp:12
bool doDelete(ObjId oid)
Definition: Shell.cpp:259
Definition: Id.h:17
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
Definition: Shell.h:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testReacVolumeScaling ( )

Definition at line 87 of file testKinetics.cpp.

References Eref::data(), Shell::doAddMsg(), Shell::doCreate(), Shell::doDelete(), doubleEq(), Id::eref(), Field< A >::get(), NA, Field< A >::set(), and Id::value().

Referenced by testKinetics().

88 {
89  Shell* shell = reinterpret_cast< Shell* >( Id().eref().data() );
90  Id comptId = shell->doCreate( "CubeMesh", Id(), "cube", 1 );
91  Id meshId( comptId.value() + 1 );
92  Id subId = shell->doCreate( "Pool", comptId, "sub", 1 );
93  Id prdId = shell->doCreate( "Pool", comptId, "prd", 1 );
94  Id reacId = shell->doCreate( "Reac", comptId, "reac", 1 );
95 
96  double vol1 = 1e-15;
97 
98  ObjId mid = shell->doAddMsg( "OneToOne",
99  subId, "requestVolume", meshId, "get_volume" );
100  assert( mid != ObjId() );
101  mid = shell->doAddMsg( "OneToOne",
102  prdId, "requestVolume", meshId, "get_volume" );
103  assert( mid != ObjId() );
104 
105  vector< double > coords( 9, 10.0e-6 );
106  coords[0] = coords[1] = coords[2] = 0;
107 
108  Field< vector< double > >::set( comptId, "coords", coords );
109 
110  double volume = Field< double >::get( comptId, "volume" );
111  assert( doubleEq( volume, vol1 ) );
112 
113  ObjId ret = shell->doAddMsg( "Single", reacId, "sub", subId, "reac" );
114  assert( ret != ObjId() );
115  ret = shell->doAddMsg( "Single", reacId, "prd", prdId, "reac" );
116  assert( ret != ObjId() );
117 
118  Field< double >::set( reacId, "Kf", 2 );
119  Field< double >::set( reacId, "Kb", 3 );
120  double x = Field< double >::get( reacId, "kf" );
121  assert( doubleEq( x, 2 ) );
122  x = Field< double >::get( reacId, "kb" );
123  assert( doubleEq( x, 3 ) );
124 
125  ret = shell->doAddMsg( "Single", reacId, "sub", subId, "reac" );
126  assert( ret != ObjId() );
127  double conv = 1.0 / ( NA * vol1 );
128  x = Field< double >::get( reacId, "kf" );
129  assert( doubleEq( x, 2 * conv ) );
130  x = Field< double >::get( reacId, "kb" );
131  assert( doubleEq( x, 3 ) );
132 
133  ret = shell->doAddMsg( "Single", reacId, "sub", subId, "reac" );
134  assert( ret != ObjId() );
135  ret = shell->doAddMsg( "Single", reacId, "prd", prdId, "reac" );
136  assert( ret != ObjId() );
137  x = Field< double >::get( reacId, "kf" );
138  assert( doubleEq( x, 2 * conv * conv ) );
139  x = Field< double >::get( reacId, "kb" );
140  assert( doubleEq( x, 3 * conv ) );
141 
142  shell->doDelete( comptId );
143  cout << "." << flush;
144 }
char * data() const
Definition: Eref.cpp:41
const double NA
Definition: consts.cpp:15
unsigned int value() const
Definition: Id.cpp:197
Definition: SetGet.h:236
Definition: ObjId.h:20
Eref eref() const
Definition: Id.cpp:125
static bool set(const ObjId &dest, const string &field, A arg)
Definition: SetGet.h:245
Id doCreate(string type, ObjId parent, string name, unsigned int numData, NodePolicy nodePolicy=MooseBlockBalance, unsigned int preferredNode=1)
Definition: Shell.cpp:181
bool doubleEq(double x, double y)
Definition: doubleEq.cpp:16
ObjId doAddMsg(const string &msgType, ObjId src, const string &srcField, ObjId dest, const string &destField)
Definition: Shell.cpp:269
bool doDelete(ObjId oid)
Definition: Shell.cpp:259
Definition: Id.h:17
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
Definition: Shell.h:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testReadCspace ( )

Definition at line 191 of file testKinetics.cpp.

References ReadCspace::testReadModel().

Referenced by testKinetics().

192 {
193  ReadCspace rc;
194  rc.testReadModel();
195  cout << "." << flush;
196 }
void testReadModel()
Definition: ReadCspace.cpp:361

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testReadKkit ( )

Definition at line 19 of file testKinetics.cpp.

References Eref::data(), Shell::doDelete(), ReadKkit::dumpPlots(), Id::eref(), ReadKkit::read(), and ReadKkit::run().

20 {
21  ReadKkit rk;
22  // rk.read( "test.g", "dend", 0 );
23  Id base = rk.read( "foo.g", "dend", Id() );
24  assert( base != Id() );
25  // Id kinetics = s->doFind( "/kinetics" );
26 
27  Shell* s = reinterpret_cast< Shell* >( Id().eref().data() );
28  rk.run();
29  rk.dumpPlots( "dend.plot" );
30 
31  s->doDelete( base );
32  cout << "." << flush;
33 }
char * data() const
Definition: Eref.cpp:41
void dumpPlots(const string &filename)
Definition: ReadKkit.cpp:347
Eref eref() const
Definition: Id.cpp:125
Id read(const string &filename, const string &cellname, Id parent, const string &solverClass="Stoich")
Definition: ReadKkit.cpp:276
bool doDelete(ObjId oid)
Definition: Shell.cpp:259
Definition: Id.h:17
void run()
Definition: ReadKkit.cpp:321
Definition: Shell.h:43

+ Here is the call graph for this function:

void testTwoReacGetNeighbors ( )

Definition at line 147 of file testKinetics.cpp.

References Eref::data(), Shell::doAddMsg(), Shell::doCreate(), Shell::doDelete(), Id::element(), Id::eref(), Element::getNeighbors(), Reac::initCinfo(), and Id::value().

Referenced by testKinetics().

148 {
149  Shell* shell = reinterpret_cast< Shell* >( Id().eref().data() );
150  Id comptId = shell->doCreate( "CubeMesh", Id(), "cube", 1 );
151  Id meshId( comptId.value() + 1 );
152  Id subId = shell->doCreate( "Pool", comptId, "sub", 1 );
153  Id prdId = shell->doCreate( "Pool", comptId, "prd", 1 );
154  Id reacId = shell->doCreate( "Reac", comptId, "reac", 1 );
155 
156  ObjId mid = shell->doAddMsg( "OneToOne",
157  subId, "requestVolume", meshId, "get_volume" );
158  assert( mid != ObjId() );
159  mid = shell->doAddMsg( "OneToOne",
160  prdId, "requestVolume", meshId, "get_volume" );
161  assert( mid != ObjId() );
162 
163  ObjId ret = shell->doAddMsg( "Single", reacId, "sub", subId, "reac" );
164  assert( ret != ObjId() );
165  ret = shell->doAddMsg( "Single", reacId, "sub", subId, "reac" );
166  assert( ret != ObjId() );
167 
168  ret = shell->doAddMsg( "Single", reacId, "prd", prdId, "reac" );
169  assert( ret != ObjId() );
170 
171  vector< Id > pools;
172  unsigned int num = reacId.element()->getNeighbors( pools,
173  Reac::initCinfo()->findFinfo( "toSub" ) );
174  assert( num == 2 );
175  assert( pools[0] == subId );
176  assert( pools[1] == subId );
177 
178  pools.clear();
179  num = reacId.element()->getNeighbors( pools,
180  Reac::initCinfo()->findFinfo( "sub" ) );
181  assert( num == 2 );
182  assert( pools[0] == subId );
183  assert( pools[1] == subId );
184 
185  shell->doDelete( comptId );
186  cout << "." << flush;
187 }
char * data() const
Definition: Eref.cpp:41
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
unsigned int value() const
Definition: Id.cpp:197
Definition: ObjId.h:20
Eref eref() const
Definition: Id.cpp:125
Id doCreate(string type, ObjId parent, string name, unsigned int numData, NodePolicy nodePolicy=MooseBlockBalance, unsigned int preferredNode=1)
Definition: Shell.cpp:181
static const Cinfo * initCinfo()
Definition: Reac.cpp:18
ObjId doAddMsg(const string &msgType, ObjId src, const string &srcField, ObjId dest, const string &destField)
Definition: Shell.cpp:269
bool doDelete(ObjId oid)
Definition: Shell.cpp:259
Definition: Id.h:17
unsigned int getNeighbors(vector< Id > &ret, const Finfo *finfo) const
Definition: Element.cpp:949
Definition: Shell.h:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testVolSort ( )

Definition at line 292 of file testKinetics.cpp.

References findVolOrder().

Referenced by testKinetics().

293 {
294  vector< unsigned int > findVolOrder( const vector< double >& vols );
295  vector< double > vols( 8 );
296  vols[0] = 7;
297  vols[1] = 8;
298  vols[2] = 6;
299  vols[3] = 5;
300  vols[4] = 1;
301  vols[5] = 2;
302  vols[6] = 3;
303  vols[7] = 4;
304  vector< unsigned int > order = findVolOrder( vols );
305  // The order is the rank of the volume entry, largest should be 0.
306  assert( order[0] == 1 );
307  assert( order[1] == 0 );
308  assert( order[2] == 2 );
309  assert( order[3] == 3 );
310  assert( order[4] == 7 );
311  assert( order[5] == 6 );
312  assert( order[6] == 5 );
313  assert( order[7] == 4 );
314 
315  // This is a sequence which failed in a model test, despite the
316  // above test working.
317  vols.resize(5);
318  vols[0] = 1e-15;
319  vols[1] = 3e-15;
320  vols[2] = -1;
321  vols[3] = 2e-15;
322  vols[4] = 5e-15;
323  order = findVolOrder( vols );
324  assert( order[0] == 4 );
325  assert( order[1] == 1 );
326  assert( order[2] == 3 );
327  assert( order[3] == 0 );
328  assert( order[4] == 2 );
329 }
vector< unsigned int > findVolOrder(const vector< double > &vols)
Definition: ReadKkit.cpp:723

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testWriteKkit ( Id  id)

Definition at line 285 of file testKinetics.cpp.

References writeKkit().

286 {
287  extern void writeKkit( Id model, const string& s );
288  writeKkit( id, "kkitWriteTest.g" );
289  cout << "." << flush;
290 }
void writeKkit(Id model, const string &fname)
Definition: WriteKkit.cpp:525
Definition: Id.h:17

+ Here is the call graph for this function: