MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
testSigNeur.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 ** This program is part of 'MOOSE', the
3 ** Messaging Object Oriented Simulation Environment,
4 ** also known as GENESIS 3 base code.
5 ** copyright (C) 2003-2005 Upinder S. Bhalla. and NCBS
6 ** It is made available under the terms of the
7 ** GNU Lesser General Public License version 2.1
8 ** See the file COPYING.LIB for the full notice.
9 **********************************************************************/
10 #ifdef DO_UNIT_TESTS
11 
12 #include "header.h"
13 #include "Adaptor.h"
14 #include "../shell/Shell.h"
15 #include "../shell/Wildcard.h"
16 
17 void testAdaptor()
18 {
19  Adaptor foo;
20  foo.setInputOffset( 1 );
21  foo.setOutputOffset( 2 );
22  foo.setScale( 10 );
23 
24  for ( unsigned int i = 0; i < 10; ++i )
25  foo.input( i );
26 
27 
28  assert( doubleEq( foo.getOutput(), 0.0 ) );
29  foo.innerProcess();
30 
31  assert( doubleEq( foo.getOutput(), ( -1.0 + 4.5) * 10.0 + 2.0 ) );
32 
33  // shell->doDelete( nid );
34  cout << "." << flush;
35 }
36 
38 void testAdaptorRequestField()
39 {
40  Shell* shell = reinterpret_cast< Shell* >( ObjId().data() );
41  Id model = shell->doCreate( "Neutral", Id(), "model", 1 );
42  Id adaptor = shell->doCreate( "Adaptor", model, "adaptor", 1 );
43  Id onepool = shell->doCreate( "Pool", model, "onepool", 1 );
44  Id twopool = shell->doCreate( "Pool", model, "twopool", 2 );
45  Id tenpool = shell->doCreate( "Pool", model, "tenpool", 10 );
46  ObjId mid = shell->doAddMsg( "Single", adaptor, "requestOut",
47  onepool, "getNInit" );
48  assert( !mid.bad() );
49  mid = shell->doAddMsg( "Single", adaptor, "requestOut",
50  ObjId( twopool, 0 ), "getNInit" );
51  assert( !mid.bad() );
52  mid = shell->doAddMsg( "Single", adaptor, "requestOut",
53  ObjId( twopool, 1 ), "getNInit" );
54  assert( !mid.bad() );
55  mid = shell->doAddMsg( "OneToAll", adaptor, "requestOut",
56  tenpool, "getNInit" );
57  assert( !mid.bad() );
58  Field< double >::set( onepool, "nInit", 1.0 );
59  Field< double >::set( ObjId( twopool, 0 ), "nInit", 20.0 );
60  Field< double >::set( ObjId( twopool, 1 ), "nInit", 30.0 );
61  for ( unsigned int i = 0; i < 10; ++i )
63  set( ObjId( tenpool, i ), "nInit", (i + 1 ) * 100 );
64  ProcInfo p;
65  SetGet1< ProcPtr >::set( adaptor, "reinit", &p );
66  double ret = Field< double >::get( adaptor, "outputValue" );
67  assert( doubleEq( ret, ( 1.0 + 50.0 + 5500.0 )/13.0 ) );
68 
69  const Finfo *f = adaptor.element()->cinfo()->findFinfo( "requestOut" );
70  const SrcFinfo* sf = dynamic_cast< const SrcFinfo* >( f );
71  assert( sf );
72  vector< ObjId > temp;
73  temp = adaptor.element()->getMsgTargets( 0, sf );
74  assert ( temp.size() == 13 );
75  assert( temp[0] == ObjId( onepool, 0 ) );
76  assert( temp[1] == ObjId( twopool, 0 ) );
77  assert( temp[2] == ObjId( twopool, 1 ) );
78  for ( int i = 0; i < 10; ++i )
79  assert( temp[i + 3] == ObjId( tenpool, i ) );
80 
81  shell->doDelete( model );
82  cout << "." << flush;
83 }
84 
85 
87 // Test of multiscale model setup. Model structure is as follows:
88 //
89 // Elec:
90 // Single elec compt soma with HH channels. 5 spines on it. GluR on spines.
91 // Ca pool in spine head fed by GluR.
92 // Chem:
93 // PSD: GluR pool.
94 // Head: Ca pool. GluR pool. 'Enz' to take to PSD.
95 // Reac balances with PSD.
96 // Dend: Ca pool binds to 'kinase'. Kinase phosph K chan.
97 // Dephosph by reac.
98 // Ca is pumped out into a buffered non-reactive pool
99 //
100 // Diffusion:
101 // Ca from spine head goes to dend
102 //
103 // Adaptors:
104 // Electrical Ca in spine head -> Ca pool in spine head
105 // Chem GluR in PSD -> Electrical GluR Gbar
106 // Chem K in soma -> Electrical K Gbar.
107 //
109 
110 #if 0
111 // Defined in testBiophysics.cpp
112 extern Id makeSquid();
113 // Defined in testMesh.cpp
114 extern Id makeSpine( Id compt, Id cell, unsigned int index, double frac,
115  double len, double dia, double theta );
116 
117 Id makeSpineWithReceptor( Id compt, Id cell, unsigned int index, double frac )
118 {
119  Shell* shell = reinterpret_cast< Shell* >( ObjId( Id(), 0 ).data() );
120  double spineLength = 5.0e-6;
121  double spineDia = 4.0e-6;
122  Id spineCompt = makeSpine( compt, cell, index, frac,
123  spineLength, spineDia, 0.0 );
124 
125  Id gluR = shell->doCreate( "SynChan", spineCompt, "gluR", 1 );
126  Field< double >::set( gluR, "tau1", 1e-3 );
127  Field< double >::set( gluR, "tau2", 1e-3 );
128  Field< double >::set( gluR, "Gbar", 1e-5 );
129  Field< double >::set( gluR, "Ek", 10.0e-3 );
130  ObjId mid = shell->doAddMsg( "Single", ObjId( spineCompt ), "channel",
131  ObjId( gluR ), "channel" );
132  assert( ! mid.bad() );
133 
134 
135  Id caPool = shell->doCreate( "CaConc", spineCompt, "ca", 1 );
136  Field< double >::set( caPool, "CaBasal", 1e-4 ); // millimolar
137  Field< double >::set( caPool, "tau", 0.01 ); // seconds
138  double B = 1.0 / (
139  FaradayConst * spineLength * spineDia * spineDia * 0.25 * PI );
140  B = B / 20.0;
141  Field< double >::set( caPool, "B", B ); // Convert from current to conc
142  mid = shell->doAddMsg( "Single", ObjId( gluR ), "IkOut",
143  ObjId( caPool ), "current" );
144  assert( ! mid.bad() );
145 
146  return spineCompt;
147 }
148 
149 Id buildSigNeurElec( vector< Id >& spines )
150 {
151  Shell* shell = reinterpret_cast< Shell* >( ObjId( Id(), 0 ).data() );
152  vector< int > dims( 1, 1 );
153  double comptLength = 100e-6;
154  double comptDia = 4e-6;
155  unsigned int numSpines = 5;
156 
157  Id nid = makeSquid();
158  Id compt( "/n/compt" );
159  Field< double >::set( compt, "inject", 0.0 );
160  Field< double >::set( compt, "x0", 0 );
161  Field< double >::set( compt, "y0", 0 );
162  Field< double >::set( compt, "z0", 0 );
163  Field< double >::set( compt, "x", comptLength );
164  Field< double >::set( compt, "y", 0 );
165  Field< double >::set( compt, "z", 0 );
166  Field< double >::set( compt, "length", comptLength );
167  Field< double >::set( compt, "diameter", comptDia );
168 
169  // Make a SpikeGen as a synaptic input to the spines.
170  Id synInput = shell->doCreate( "SpikeGen", nid, "synInput", dims.size() );
171  Field< double >::set( synInput, "refractT", 47e-3 );
172  Field< double >::set( synInput, "threshold", -1.0 );
173  Field< bool >::set( synInput, "edgeTriggered", false );
174  SetGet1< double >::set( synInput, "Vm", 0.0 );
175 
176  spines.resize( numSpines );
177 
178  for ( unsigned int i = 0; i < numSpines; ++i ) {
179  double frac = ( 0.5 + i ) / numSpines;
180  spines[i] = makeSpineWithReceptor( compt, nid, i, frac );
181  stringstream ss;
182  ss << "/n/head" << i << "/gluR";
183  string name = ss.str();
184  Id gluR( name );
185  assert( gluR != Id() );
186  Field< unsigned int >::set( gluR, "num_synapse", 1 );
187  Id syn( name + "/synapse" );
188  assert( syn != Id() );
189  ObjId mid = shell->doAddMsg( "Single", ObjId( synInput ), "event",
190  ObjId( syn ), "addSpike" );
191  assert( ! mid.bad() );
192  Field< double >::set( syn, "weight", 0.2 );
193  Field< double >::set( syn, "delay", i * 1.0e-4 );
194  }
195 
196  return nid;
197 }
198 
199 
200 void buildSigNeurChem( Id nid, Id neuroMesh, Id spineMesh, Id psdMesh )
201 {
202  Shell* shell = reinterpret_cast< Shell* >( ObjId( Id(), 0 ).data() );
203  vector< int > dims( 1, 1 );
204 
206  // Stuff in PSD
208  Id psdMeshEntries( "/n/psdMesh/mesh" );
209  assert( psdMeshEntries != Id() );
210  Id psdGluR = shell->doCreate( "Pool", psdMesh, "psdGluR", 1 );
211  ObjId mid = shell->doAddMsg( "Single", psdGluR, "mesh", psdMeshEntries, "mesh" );
212  assert( ! mid.bad() );
213  Field< double >::set( psdGluR, "nInit", 0 );
215  // Stuff in spine head
217  Id spineMeshEntries( "/n/spineMesh/mesh" );
218 
219  Id headCa = shell->doCreate( "Pool", spineMesh, "Ca" , 1);
220  mid = shell->doAddMsg( "Single", spineMeshEntries, "mesh", headCa, "mesh" );
221  assert( ! mid.bad() );
222 
223  Field< double >::set( headCa, "concInit", 1e-4 );
224 
225  Id headGluR = shell->doCreate( "Pool", spineMesh, "headGluR", 1 );
226  mid = shell->doAddMsg( "Single", spineMeshEntries, "mesh", headGluR, "mesh" );
227  assert( ! mid.bad() );
228  Field< double >::set( headGluR, "nInit", 100 );
229 
230  Id toPsd = shell->doCreate( "Pool", spineMesh, "toPsd", 1 );
231  mid = shell->doAddMsg( "Single", spineMeshEntries, "mesh", toPsd, "mesh" );
232  assert( ! mid.bad() );
233  Field< double >::set( toPsd, "concInit", 0 );
234 
235  Id toPsdInact = shell->doCreate( "Pool", spineMesh, "toPsdInact", 1 );
236  mid = shell->doAddMsg( "Single", spineMeshEntries, "mesh", toPsdInact, "mesh" );
237  assert( ! mid.bad() );
238  Field< double >::set( toPsdInact, "concInit", 1e-3 );
239 
240  Id turnOnPsd = shell->doCreate( "Reac", spineMesh, "turnOnPsd", 1);
241  mid = shell->doAddMsg( "OneToOne", turnOnPsd, "sub", headCa, "reac" );
242  assert( ! mid.bad() );
243  mid = shell->doAddMsg( "OneToOne", turnOnPsd, "sub", toPsdInact, "reac" );
244  assert( ! mid.bad() );
245  mid = shell->doAddMsg( "OneToOne", turnOnPsd, "prd", toPsd, "reac" );
246  assert( ! mid.bad() );
247  Field< double >::set( turnOnPsd, "Kf", 0.1e3 );
248  Field< double >::set( turnOnPsd, "Kb", 0.1 );
249 
250 
251  Id toPsdEnz = shell->doCreate( "Enz", toPsd, "enz" , 1);
252  Id toPsdEnzCplx = shell->doCreate( "Pool", toPsdEnz, "cplx", 1 );
253  shell->doAddMsg( "Single", spineMeshEntries, "mesh", toPsdEnzCplx, "mesh" );
254  mid = shell->doAddMsg( "OneToOne", toPsdEnz, "enz", toPsd, "reac" );
255  assert( ! mid.bad() );
256  mid = shell->doAddMsg( "OneToOne", toPsdEnz, "sub", headGluR, "reac" );
257  assert( ! mid.bad() );
258  mid = shell->doAddMsg( "OneToOne", toPsdEnz, "prd", psdGluR, "reac" );
259  assert( ! mid.bad() );
260  mid = shell->doAddMsg( "OneToOne", toPsdEnz, "cplx", toPsdEnzCplx, "reac" );
261  assert( ! mid.bad() );
262  Field< double >::set( toPsdEnz, "Km", 1.0e-3 ); // 1 uM
263  Field< double >::set( toPsdEnz, "kcat", 1.0 ); // 1/sec.
264 
265  // Must be in same compartment as reagent.
266  Id fromPsd = shell->doCreate( "Reac", psdMesh, "fromPsd", 1 );
267 
268  mid = shell->doAddMsg( "OneToOne", fromPsd, "sub", psdGluR, "reac" );
269  assert( ! mid.bad() );
270  mid = shell->doAddMsg( "OneToOne", fromPsd, "prd", headGluR, "reac" );
271  assert( ! mid.bad() );
272  Field< double >::set( fromPsd, "Kf", 0.05 );
273  Field< double >::set( fromPsd, "Kb", 0.0 );
274 
275  // Id toPsdEnzCplx( toPsdEnz.value() + 1 );
276  Id foo( "/n/spineMesh/toPsd/enz/cplx" );
277  assert( toPsdEnzCplx != Id() );
278  assert( toPsdEnzCplx == foo );
279 
281  // Stuff in dendrite
283  Id dendMeshEntries( "/n/neuroMesh/mesh" );
284 
285  Id dendCa = shell->doCreate( "Pool", neuroMesh, "Ca", 1 );
286  mid = shell->doAddMsg( "Single", dendMeshEntries, "mesh", dendCa, "mesh" );
287  assert( ! mid.bad() );
288  Field< double >::set( dendCa, "concInit", 1e-4 ); // 0.1 uM.
289  double conc = Field< double >::get( dendCa, "concInit" );
290  assert( doubleEq( conc, 1e-4 ) );
291 
292  Id bufCa = shell->doCreate( "BufPool", neuroMesh, "bufCa", 1 );
293  mid = shell->doAddMsg( "Single", dendMeshEntries, "mesh", bufCa, "mesh" );
294  assert( ! mid.bad() );
295  Field< double >::set( bufCa, "concInit", 1e-4 ); // 0.1 uM.
296  conc = Field< double >::get( bufCa, "concInit" );
297  assert( doubleEq( conc, 1e-4 ) );
298 
299  Id pumpCa = shell->doCreate( "Reac", neuroMesh, "pumpCa" , 1);
300  mid = shell->doAddMsg( "OneToOne", pumpCa, "sub", dendCa, "reac" );
301  assert( ! mid.bad() );
302  mid = shell->doAddMsg( "OneToOne", pumpCa, "prd", bufCa, "reac" );
303  assert( ! mid.bad() );
304  Field< double >::set( pumpCa, "Kf", 0.1 );
305  Field< double >::set( pumpCa, "Kb", 0.1 );
306 
307  Id dendKinaseInact = shell->doCreate( "Pool", neuroMesh, "inact_kinase", 1 );
308  mid = shell->doAddMsg( "Single", dendMeshEntries, "mesh", dendKinaseInact, "mesh" );
309  assert( ! mid.bad() );
310  Field< double >::set( dendKinaseInact, "concInit", 1e-3 ); // 1 uM.
311 
312  Id dendKinase = shell->doCreate( "Pool", neuroMesh, "Ca.kinase", 1 );
313  mid = shell->doAddMsg( "Single", dendMeshEntries, "mesh", dendKinase, "mesh" );
314  assert( ! mid.bad() );
315  Field< double >::set( dendKinase, "concInit", 0.0 ); // 1 uM.
316 
317 
318  Id dendTurnOnKinase = shell->doCreate( "Reac", neuroMesh, "turnOnKinase", 1);
319  mid = shell->doAddMsg(
320  "OneToOne", dendTurnOnKinase, "sub", dendCa, "reac" );
321  mid = shell->doAddMsg(
322  "OneToOne", dendTurnOnKinase, "sub", dendKinaseInact, "reac" );
323  assert( ! mid.bad() );
324  mid = shell->doAddMsg(
325  "OneToOne", dendTurnOnKinase, "prd", dendKinase, "reac" );
326  assert( ! mid.bad() );
327  Field< double >::set( dendTurnOnKinase, "Kf", 0.5e3 );
328  Field< double >::set( dendTurnOnKinase, "Kb", 0.1 );
329 
330  Id dendKinaseEnz = shell->doCreate( "Enz", dendKinase, "enz" , 1);
331  Id dendKinaseEnzCplx = shell->doCreate( "Pool", dendKinaseEnz, "cplx", 1 );
332  mid = shell->doAddMsg( "Single", dendMeshEntries, "mesh", dendKinaseEnzCplx, "mesh" );
333  assert( ! mid.bad() );
334  Id kChan = shell->doCreate( "Pool", neuroMesh, "kChan", 1);
335  mid = shell->doAddMsg( "Single", dendMeshEntries, "mesh", kChan, "mesh" );
336  assert( ! mid.bad() );
337  Field< double >::set( kChan, "concInit", 1e-3 ); // 1 uM.
338 
339  Id kChan_p = shell->doCreate( "Pool", neuroMesh, "kChan_p", 1);
340  mid = shell->doAddMsg( "Single", dendMeshEntries, "mesh", kChan_p, "mesh" );
341  assert( ! mid.bad() );
342  Field< double >::set( kChan_p, "concInit", 0 ); // 0 uM.
343 
344  mid = shell->doAddMsg("OneToOne", dendKinaseEnz, "enz", dendKinase, "reac" );
345  assert( ! mid.bad() );
346  mid = shell->doAddMsg("OneToOne", dendKinaseEnz, "sub", kChan, "reac" );
347  assert( ! mid.bad() );
348  mid = shell->doAddMsg("OneToOne", dendKinaseEnz, "prd", kChan_p, "reac" );
349  assert( ! mid.bad() );
350  mid = shell->doAddMsg("OneToOne", dendKinaseEnz, "cplx", dendKinaseEnzCplx, "reac" );
351  assert( ! mid.bad() );
352  Field< double >::set( dendKinaseEnz, "Km", 5e-3 ); // 5 uM
353  Field< double >::set( dendKinaseEnz, "kcat", 0.1 ); // 0.1/sec.
354 
355  Id dendPhosphatase = shell->doCreate( "Reac", neuroMesh, "phosphatase", 1);
356  mid = shell->doAddMsg("OneToOne", dendPhosphatase, "sub", kChan_p, "reac" );
357  assert( ! mid.bad() );
358  mid = shell->doAddMsg("OneToOne", dendPhosphatase, "prd", kChan, "reac" );
359  assert( ! mid.bad() );
360  Field< double >::set( dendPhosphatase, "Kf", 0.1 );
361  Field< double >::set( dendPhosphatase, "Kb", 0.0 );
362 
363 
364  Id bar( "/n/neuroMesh/Ca.kinase/enz/cplx" );
365  assert( dendKinaseEnzCplx != Id() );
366  assert( dendKinaseEnzCplx == bar );
367  shell->doAddMsg( "Single", spineMeshEntries, "mesh", dendKinaseEnzCplx, "mesh" );
368 }
369 
370 void buildSigNeurNeuroMesh( Id nid, Id& neuroMesh, Id& spineMesh, Id& psdMesh )
371 {
372  const double diffLength = 1e-6;
373  Shell* shell = reinterpret_cast< Shell* >( ObjId( Id(), 0 ).data() );
374  vector< int > dims( 1, 1 );
375 
376  neuroMesh = shell->doCreate( "NeuroMesh", nid, "neuroMesh", dims.size() );
377  Field< bool >::set( neuroMesh, "separateSpines", true );
378  Field< double >::set( neuroMesh, "diffLength", diffLength );
379  Field< string >::set( neuroMesh, "geometryPolicy", "cylinder" );
380  spineMesh = shell->doCreate( "SpineMesh", nid, "spineMesh", dims.size());
381  ObjId mid;
382  mid = shell->doAddMsg( "OneToOne", neuroMesh, "spineListOut", spineMesh, "spineList" );
383  assert( ! mid.bad() );
384  psdMesh = shell->doCreate( "PsdMesh", nid, "psdMesh", dims.size() );
385  mid = shell->doAddMsg( "OneToOne", neuroMesh, "psdListOut", psdMesh, "psdList" );
386  assert( ! mid.bad() );
387 }
388 
389 void makeChemInNeuroMesh()
390 {
391  double spineLength = 5.0e-6;
392  double spineDia = 4.0e-6;
393  double comptLength = 100.0e-6;
394  double comptDia = 4.0e-6;
395  vector< Id > spines;
396  Id nid = buildSigNeurElec( spines );
397  Id neuroMesh, spineMesh, psdMesh;
398  buildSigNeurNeuroMesh( nid, neuroMesh, spineMesh, psdMesh );
399  buildSigNeurChem( nid, neuroMesh, spineMesh, psdMesh );
401  // Make NeuroMesh
403  Field< Id >::set( neuroMesh, "cell", nid );
404  // shell->doReinit();
405  // Qinfo::clearQ( 0 );
406  // Qinfo::clearQ( 0 );
407  // Deprecated. Qinfo::waitProcCycles( 4 );
408 
410  // Check that stuff has been built
412  const unsigned int numComptsInDend = 100;
413  const unsigned int numSpines = 5;
414  unsigned int size;
415 
416  // 25 Apr 2013: this doesn't work, though it should. Need to clean up.
417  //size = psdMeshEntries.element()->dataHandler()->totalEntries();
418 
419  Id psdMeshEntries( "/n/psdMesh/mesh" );
420  size = Id( "/n/spineMesh/mesh" ).element()->numData();
421  assert( size == numSpines );
422  size = Id( "/n/psdMesh/mesh" ).element()->numData();
423  assert( size == numSpines );
424 
425  size = Id( "/n/spineMesh/headGluR" ).element()->numData();
426  // size = Field< unsigned int >::get( headGluR, "linearSize");
427  assert( size == numSpines );
428  double vol;
429  vol = Field< double >::get( Id( "/n/spineMesh/headGluR" ), "volume" );
430  assert( doubleEq( vol, spineLength * spineDia * spineDia * PI / 4.0 ) );
431 
432  size = Id( "/n/spineMesh/toPsd" ).element()->numData();
433  // size = Field< unsigned int >::get( toPsdEnz, "linearSize");
434  assert( size == numSpines );
435  size = Id( "/n/spineMesh/fromPsd" ).element()->numData();
436  // size = Field< unsigned int >::get( fromPsd, "linearSize");
437  assert( size == 1 ); // It is a reac.
438 
439  size = Id( "/n/psdMesh/psdGluR" ).element()->numData();
440  // size = Field< unsigned int >::get( psdGluR, "linearSize");
441  assert( size == numSpines );
442  vol = Field< double >::get( Id( "/n/psdMesh/psdGluR" ), "volume" );
443  double thick = Field< double >::get( Id( "/n/psdMesh" ), "thickness" );
444  assert( doubleEq( vol, thick * spineDia * spineDia * PI / 4.0 ) );
445 
446  size = Id( "/n/neuroMesh/Ca" ).element()->numData();
447  // size = Field< unsigned int >::get( dendCa, "linearSize");
448  assert( size == numComptsInDend );
449  vol = Field< double >::get( Id( "/n/neuroMesh/Ca" ), "volume" );
450  assert( doubleEq( vol, comptLength * comptDia * comptDia * PI / (4.0 * numComptsInDend ) ) );
451 
452  size = Id( "/n/neuroMesh/pumpCa" ).element()->numData();
453  // size = Field< unsigned int >::get( pumpCa, "linearSize");
454  assert( size == 1 );
455  size = Id( "/n/neuroMesh/dendKinaseEnz" ).element()->numData();
456  // size = Field< unsigned int >::get( dendKinaseEnz, "linearSize");
457  assert( size == 1 );
458 
459 
460  Shell* shell = reinterpret_cast< Shell* >( ObjId( Id(), 0 ).data() );
461  shell->doDelete( nid );
462  cout << "." << flush;
463 }
464 
465 Id makeChemInCubeMesh()
466 {
467  Shell* shell = reinterpret_cast< Shell* >( ObjId( Id(), 0 ).data() );
468  vector< int > dims( 1, 1 );
469  double dendSide = 10.8e-6; // Matches vol cylinder of 100x4 microns.
470  double spineSide = 6.8e-6; // Matches vol of 5 spines of 5x4 microns.
471  double psdSide = 8.565e-7; // Matches 'vol' of 5 psds of 4 microns
472  // diameter. Assume thickness of 0.01 micron, since area not
473  // comparable otherwise.
474 
475  Id nid( "/n" );
476  if ( nid == Id() )
477  nid = shell->doCreate( "Neutral", Id(), "n", 1 );
478  Id neuroMesh = shell->doCreate( "CubeMesh", nid, "neuroMesh", 1);
479  Id spineMesh = shell->doCreate( "CubeMesh", nid, "spineMesh", 1);
480  Id psdMesh = shell->doCreate( "CubeMesh", nid, "psdMesh", 1);
481 
482  vector< double > coords( 9, dendSide );
483  coords[0] = 0.0;
484  coords[1] = 0.0;
485  coords[2] = 0.0;
486  Field< vector< double > >::set( neuroMesh, "coords", coords );
487  Field< bool >::set( neuroMesh, "preserveNumEntries", true );
488 
489  coords.clear();
490  coords.resize( 9, spineSide );
491  coords[0] = dendSide;
492  coords[1] = 0.0;
493  coords[2] = 0.0;
494  coords[3] = spineSide + dendSide;
495  Field< vector< double > >::set( spineMesh, "coords", coords );
496  Field< bool >::set( spineMesh, "preserveNumEntries", true );
497 
498  coords.clear();
499  coords.resize( 9, psdSide );
500  coords[0] = dendSide + spineSide;
501  coords[1] = 0.0;
502  coords[2] = 0.0;
503  coords[3] = psdSide + spineSide + dendSide;
504  Field< vector< double > >::set( psdMesh, "coords", coords );
505  Field< bool >::set( psdMesh, "preserveNumEntries", true );
506 
507  buildSigNeurChem( nid, neuroMesh, spineMesh, psdMesh );
508 
510  // Check that stuff has been built
512  unsigned int size;
513 
514  Id psdMeshEntries( "/n/psdMesh/mesh" );
515  size = Id( "/n/spineMesh/mesh" ).element()->numData();
516  assert( size == 1 );
517  size = Id( "/n/psdMesh/mesh" ).element()->numData();
518  assert( size == 1 );
519 
520  size = Id( "/n/spineMesh/headGluR" ).element()->numData();
521  assert( size == 1 );
522  double vol;
523  vol = Field< double >::get( Id( "/n/spineMesh/headGluR" ), "volume" );
524  assert( doubleEq( vol, pow( spineSide, 3.0 ) ) );
525 
526  size = Id( "/n/spineMesh/toPsd" ).element()->numData();
527  assert( size == 1 );
528  size = Id( "/n/spineMesh/fromPsd" ).element()->numData();
529  assert( size == 1 ); // It is a reac.
530 
531  size = Id( "/n/psdMesh/psdGluR" ).element()->numData();
532  assert( size == 1 );
533  vol = Field< double >::get( Id( "/n/psdMesh/psdGluR" ), "volume" );
534  assert( doubleEq( vol, pow( psdSide, 3.0 ) ) );
535 
536  size = Id( "/n/neuroMesh/Ca" ).element()->numData();
537  assert( size == 1 );
538  vol = Field< double >::get( Id( "/n/neuroMesh/Ca" ), "volume" );
539  assert( doubleEq( vol, pow( dendSide, 3.0 ) ) );
540 
541  size = Id( "/n/neuroMesh/pumpCa" ).element()->numData();
542  assert( size == 1 );
543  size = Id( "/n/neuroMesh/dendKinaseEnz" ).element()->numData();
544  assert( size == 1 );
546  // Sanity check
548  vol = dendSide * dendSide * dendSide;
549  double conc = Field< double >::get( Id( "/n/neuroMesh/Ca"), "concInit");
550  double nInit = Field< double >::get( Id( "/n/neuroMesh/Ca"), "nInit");
551  assert( doubleEq( conc, 1e-4 ) );
552  assert( doubleEq( nInit, 1e-4 * NA * vol ) );
553 
554  conc = Field< double >::get( Id( "/n/neuroMesh/bufCa"), "concInit");
555  nInit = Field< double >::get( Id( "/n/neuroMesh/bufCa"), "nInit");
556  assert( doubleEq( conc, 1e-4 ) );
557  assert( doubleEq( nInit, 1e-4 * NA * vol ) );
558 
559  double concK;
560  double numK;
561  concK = Field< double >::get( Id( "/n/neuroMesh/turnOnKinase"), "Kf" );
562  assert( doubleEq( concK, 500 ) );
563  numK = Field< double >::get( Id( "/n/neuroMesh/turnOnKinase"), "kf" );
564  assert( doubleEq( numK, 500 / ( NA * vol ) ) );
565  concK = Field< double >::get( Id( "/n/neuroMesh/Ca.kinase/enz" ), "Km");
566  assert( doubleEq( concK, 0.005 ) );
567  numK = Field< double >::get( Id( "/n/neuroMesh/Ca.kinase/enz" ),"kcat");
568  assert( doubleEq( numK, 0.1 ) );
569  numK = Field< double >::get( Id( "/n/neuroMesh/Ca.kinase/enz" ), "k1");
570  assert( doubleEq( numK, ( 0.1 + 0.4 ) / ( 0.005 * NA * vol ) ) );
571  numK = Field< double >::get( Id( "/n/neuroMesh/Ca.kinase/enz" ), "k2");
572  assert( doubleEq( numK, 0.4 ) );
573  numK = Field< double >::get( Id( "/n/neuroMesh/Ca.kinase/enz" ), "k3");
574  assert( doubleEq( numK, 0.1 ) );
575 
576 
577  vol = spineSide * spineSide * spineSide;
578  concK = Field< double >::get( Id( "/n/spineMesh/turnOnPsd"), "Kf" );
579  assert( doubleEq( concK, 100 ) );
580  numK = Field< double >::get( Id( "/n/spineMesh/turnOnPsd"), "kf" );
581  assert( doubleEq( numK, 100 / ( NA * vol ) ) );
582  concK = Field< double >::get( Id( "/n/spineMesh/toPsd/enz" ), "Km");
583  assert( doubleEq( concK, 0.001 ) );
584  numK = Field< double >::get( Id( "/n/spineMesh/toPsd/enz" ),"kcat");
585  assert( doubleEq( numK, 1 ) );
586  numK = Field< double >::get( Id( "/n/spineMesh/toPsd/enz" ), "k1");
587  assert( doubleEq( numK, ( 1.0 + 4.0 ) / ( 0.001 * NA * vol ) ) );
588  numK = Field< double >::get( Id( "/n/spineMesh/toPsd/enz" ), "k2");
589  assert( doubleEq( numK, 4 ) );
590  numK = Field< double >::get( Id( "/n/spineMesh/toPsd/enz" ), "k3");
591  assert( doubleEq( numK, 1 ) );
592  return nid;
593 }
594 
595 void testChemInCubeMesh()
596 {
597  Shell* shell = reinterpret_cast< Shell* >( ObjId( Id(), 0 ).data() );
598  vector< int > dims( 1, 1 );
599  Id nid = makeChemInCubeMesh();
600 
601  /*
602  vector< Id > ids;
603  simpleWildcardFind( "/n/##[ISA=PoolBase]", ids );
604  for( vector< Id >::iterator i = ids.begin(); i != ids.end(); ++i ) {
605  cout << i->path() <<
606  " : concInit = " << Field< double >::get( *i, "concInit" ) <<
607  "; nInit = " << Field< double >::get( *i, "nInit" ) <<
608  "; volume = " << Field< double >::get( *i, "volume" )
609  << endl;
610  }
611  ids.clear();
612  simpleWildcardFind( "/n/##[ISA=ReacBase]", ids );
613  for( vector< Id >::iterator i = ids.begin(); i != ids.end(); ++i ) {
614  cout << i->element()->getName() <<
615  ": Kf = " << Field< double >::get( *i, "Kf" ) <<
616  "; Kb = " << Field< double >::get( *i, "Kb" ) <<
617  ": kf = " << Field< double >::get( *i, "kf" ) <<
618  "; kb = " << Field< double >::get( *i, "kb" )
619  << endl;
620  }
621  ids.clear();
622  simpleWildcardFind( "/n/##[ISA=EnzBase]", ids );
623  for( vector< Id >::iterator i = ids.begin(); i != ids.end(); ++i ) {
624  cout << i->path() <<
625  ": Km = " << Field< double >::get( *i, "Km" ) <<
626  "; kcat = " << Field< double >::get( *i, "kcat" ) <<
627  "; k1 = " << Field< double >::get( *i, "k1" ) <<
628  "; k2 = " << Field< double >::get( *i, "k2" ) <<
629  "; k3 = " << Field< double >::get( *i, "k3" ) <<
630  endl;
631  }
632  */
633 
635  // Run it
637  Id tab = shell->doCreate( "Table", nid, "tab", dims.size() );
638  ObjId mid = shell->doAddMsg( "Single", tab, "requestData",
639  Id( "/n/psdMesh/psdGluR" ), "get_n" );
640  assert( ! mid.bad() );
641  Id tabCa = shell->doCreate( "Table", nid, "tabCa", dims.size() );
642  mid = shell->doAddMsg( "Single", tabCa, "requestData",
643  Id( "/n/spineMesh/Ca" ), "get_conc" );
644 
645  assert( ! mid.bad() );
646  Id tab2 = shell->doCreate( "Table", nid, "tab2", dims.size() );
647  mid = shell->doAddMsg( "Single", tab2, "requestData",
648  Id( "/n/neuroMesh/kChan_p" ), "get_conc" );
649 
650  assert( ! mid.bad() );
651  Id tab4 = shell->doCreate( "Table", nid, "tab4", dims.size() );
652  mid = shell->doAddMsg( "Single", tab4, "requestData",
653  Id( "/n/neuroMesh/Ca.kinase" ), "get_conc" );
654 
655  assert( ! mid.bad() );
656  Id tab3 = shell->doCreate( "Table", nid, "tab3", dims.size() );
657  mid = shell->doAddMsg( "Single", tab3, "requestData",
658  Id( "/n/spineMesh/toPsd" ), "get_conc" );
659 
660  assert( ! mid.bad() );
662  // Schedule, Reset, and run.
664 
665  shell->doSetClock( 5, 1.0e-2 );
666  shell->doSetClock( 6, 1.0e-2 );
667  shell->doSetClock( 7, 1.0 );
668 
669  shell->doUseClock( "/n/neuroMesh/##,/n/spineMesh/##,/n/psdMesh/##", "process", 5 );
670  shell->doUseClock( "/n/tab#", "process", 7 );
671 
672  shell->doReinit();
673  shell->doReinit();
674  shell->doStart( 100.0 );
675 
676  SetGet2< string, string >::set( tabCa, "xplot", "SigNeurChem.plot", "spineCa" );
677  SetGet2< string, string >::set( tab, "xplot", "SigNeurChem.plot", "psdGluR_N" );
678  SetGet2< string, string >::set( tab2, "xplot", "SigNeurChem.plot", "kChan_p" );
679  SetGet2< string, string >::set( tab4, "xplot", "SigNeurChem.plot", "dendKinase" );
680  SetGet2< string, string >::set( tab3, "xplot", "SigNeurChem.plot", "toPsd" );
681 
683  // Build a solver, reset and run
685 
686  Id solver = shell->doCreate( "GslStoich", nid, "solver", dims.size() );
687  assert( solver != Id() );
688  Field< string >::set( solver, "path", "/n/##" );
689  Field< string >::set( solver, "method", "rk5" );
690  shell->doSetClock( 5, 1.0 );
691  shell->doSetClock( 6, 1.0 );
692  shell->doUseClock( "/n/solver", "process", 5 );
693  shell->doReinit();
694  shell->doStart( 100.0 );
695 
696  SetGet2< string, string >::set( tabCa, "xplot", "SigNeurChem.plot", "spineCa2" );
697  SetGet2< string, string >::set( tab, "xplot", "SigNeurChem.plot", "psdGluR_N2" );
698  SetGet2< string, string >::set( tab2, "xplot", "SigNeurChem.plot", "kChan_p2" );
699  SetGet2< string, string >::set( tab3, "xplot", "SigNeurChem.plot", "toPsd2" );
700 
701  shell->doDelete( nid );
702  cout << "." << flush;
703 }
704 
705 void testSigNeurElec()
706 {
707  Shell* shell = reinterpret_cast< Shell* >( ObjId( Id(), 0 ).data() );
708  vector< int > dims( 1, 1 );
709 
710  vector< Id > spines;
711  Id nid = buildSigNeurElec( spines );
712  Id compt( "/n/compt" );
714  // Graph
716  /*
717  vector< Id > ret;
718  simpleWildcardFind( "/n/##[ISA=Compartment]", ret );
719  for ( vector< Id >::iterator i = ret.begin(); i != ret.end(); ++i ) {
720  double Ra = Field< double >::get( *i, "Ra" );
721  double Rm = Field< double >::get( *i, "Rm" );
722  double Em = Field< double >::get( *i, "Em" );
723  double Cm = Field< double >::get( *i, "Cm" );
724  string name = i->element()->getName();
725  cout << name << ": Ra = " << Ra << ", Rm = " << Rm <<
726  ", Cm = " << Cm << ", Em = " << Em << endl;
727  }
728  */
729  Id tab = shell->doCreate( "Table", nid, "tab", dims.size() );
730  ObjId mid = shell->doAddMsg( "Single", ObjId( tab, 0 ),
731  "requestData", ObjId( spines[2], 0 ), "get_Vm" );
732  assert( ! mid.bad() );
733  Id tab2 = shell->doCreate( "Table", nid, "tab2", dims.size() );
734  mid = shell->doAddMsg( "Single", ObjId( tab2, 0 ),
735  "requestData", ObjId( compt, 0 ), "get_Vm" );
736 
737  assert( ! mid.bad() );
738  Id ca2( "/n/head2/ca" );
739  Id tabCa = shell->doCreate( "Table", nid, "tab3", dims.size() );
740  mid = shell->doAddMsg( "Single", ObjId( tabCa, 0 ),
741  "requestData", ObjId( ca2, 0 ), "get_Ca" );
742  assert( ! mid.bad() );
744  // Schedule, Reset, and run.
746 
747  shell->doSetClock( 0, 1.0e-5 );
748  shell->doSetClock( 1, 1.0e-5 );
749  shell->doSetClock( 2, 1.0e-5 );
750  shell->doSetClock( 3, 1.0e-4 );
751 
752  shell->doUseClock( "/n/compt,/n/shaft#,/n/head#", "init", 0 );
753  shell->doUseClock( "/n/compt,/n/shaft#,/n/head#", "process", 1 );
754  shell->doUseClock( "/n/synInput", "process", 1 );
755  shell->doUseClock( "/n/compt/Na,/n/compt/K", "process", 2 );
756  shell->doUseClock( "/n/head#/#", "process", 2 );
757  shell->doUseClock( "/n/tab#", "process", 3 );
758 
759  shell->doReinit();
760  shell->doReinit();
761  shell->doStart( 0.1 );
762 
763  SetGet2< string, string >::set( tab, "xplot", "SigNeur.plot", "spineVm" );
764  SetGet2< string, string >::set( tab2, "xplot", "SigNeur.plot", "comptVm" );
765  SetGet2< string, string >::set( tabCa, "xplot", "SigNeur.plot", "headCa" );
766 
768  // Build hsolver, Schedule, Reset, and run.
770  Id hsolve = shell->doCreate( "HSolve", nid, "hsolve", dims.size() );
771  shell->doUseClock( "/n/hsolve", "process", 1 );
772  Field< double >::set( hsolve, "dt", 2.0e-5 );
773  Field< string >::set( hsolve, "target", "/n/compt" );
774  shell->doSetClock( 0, 2.0e-5 );
775  shell->doSetClock( 1, 2.0e-5 );
776  shell->doSetClock( 2, 2.0e-5 );
777  shell->doSetClock( 3, 1.0e-4 );
778 
779 
780  shell->doReinit();
781  shell->doStart( 0.1 );
782 
783  SetGet2< string, string >::set( tab, "xplot", "SigNeur.plot", "spineVm_hsolve" );
784  SetGet2< string, string >::set( tab2, "xplot", "SigNeur.plot", "comptVm_hsolve" );
785  SetGet2< string, string >::set( tabCa, "xplot", "SigNeur.plot", "headCa_hsolve" );
786 
787  shell->doDelete( nid );
788  cout << "." << flush;
789 }
790 
791 Id addPlot( const string& objPath, const string& field,
792  const string& plotname )
793 {
794  Shell* shell = reinterpret_cast< Shell* >( ObjId( Id(), 0 ).data() );
795  vector< int > dims( 1, 1 );
796 
797  Id nid( "/n" );
798  assert( nid != Id() );
799  Id obj( objPath );
800  assert( obj != Id() );
801  Id tab = shell->doCreate( "Table", nid, plotname, dims.size() );
802  ObjId mid = shell->doAddMsg( "Single", tab, "requestData", obj, field );
803  assert( ! mid.bad() );
804  return tab;
805 }
806 
807 Id buildAdaptorsInCubeMesh( vector< Id >& plots )
808 {
809  Shell* shell = reinterpret_cast< Shell* >( ObjId( Id(), 0 ).data() );
810  vector< int > dims( 1, 1 );
811  plots.clear();
812 
813  vector< Id > spines;
814  Id nid = buildSigNeurElec( spines );
815 
816  cout << "Cm = " << Field< double >::get( Id( "/n/head2" ), "Cm" ) << endl;
817 
818  Id compt( "/n/compt" );
819  Field< double >::set( compt, "inject", 0.0e-9 );
820  Id synInput( "/n/synInput" );
821  Field< double >::set( synInput, "refractT", 87e-3 );
822  Id Na( "/n/compt/Na" );
823  double gbar = Field< double >::get( Na, "Gbar" );
824  Field< double >::set( Na, "Gbar", gbar * 1.5 );
825 
826  makeChemInCubeMesh();
827  Id elecCa( "/n/head2/ca" );
828  Id chemCa( "/n/spineMesh/Ca" );
829 
830  Id elecGluR( "/n/head2/gluR" );
831  Id chemGluR( "/n/psdMesh/psdGluR" );
832 
833  Id elecK( "/n/compt/K" );
834  Id chemK( "/n/neuroMesh/kChan" );
835 
837  // Fake diffusion between spines and dend
839  Id dendCa( "/n/neuroMesh/Ca" );
840  Id spineMesh( "/n/spineMesh" );
841  Id diffReac = shell->doCreate( "Reac", spineMesh, "diff", 1 );
842  ObjId mid = shell->doAddMsg( "Single", diffReac, "sub", chemCa, "reac");
843  assert( ! mid.bad() );
844  mid = shell->doAddMsg( "Single", diffReac, "prd", dendCa, "reac");
845  assert( ! mid.bad() );
846  double dendVol = Field< double >::get( dendCa, "volume" );
847  double spineVol = Field< double >::get( chemCa, "volume" );
848  Field< double >::set( diffReac, "Kf", 1 ); // from spine to dend
849  Field< double >::set( diffReac, "Kb", spineVol / dendVol );
850 
852  // Adaptors
854  Id adaptCa = shell->doCreate( "Adaptor", nid, "adaptCa", dims.size() );
855  mid = shell->doAddMsg( "OneToAll",
856  elecCa, "concOut", adaptCa, "input" );
857  assert( ! mid.bad() );
858  /*
859  mid = shell->doAddMsg( "OneToAll",
860  adaptCa, "requestOut", elecCa, "get_Ca" );
861  assert( ! mid.bad() );
862  */
863 
864  mid = shell->doAddMsg( "OneToAll",
865  adaptCa, "output", chemCa, "set_conc" );
866  assert( ! mid.bad() );
867  Field< double >::set( adaptCa, "outputOffset", 0.0001 ); // 100 nM
868  Field< double >::set( adaptCa, "scale", 0.05 ); // .06 to .003 mM
869 
870  Id adaptGluR = shell->doCreate( "Adaptor", nid, "adaptGluR", dims.size() );
871  mid = shell->doAddMsg( "OneToAll",
872  adaptGluR, "requestOut", chemGluR, "get_n" );
873  assert( ! mid.bad() );
874  mid = shell->doAddMsg( "OneToAll",
875  adaptGluR, "output", elecGluR, "set_Gbar" );
876  assert( ! mid.bad() );
877  // max n = 100, max Gar =
878  Field< double >::set( adaptGluR, "scale", 1e-4/100 ); // from n to pS
879 
880  Id adaptK = shell->doCreate( "Adaptor", nid, "adaptK", dims.size() );
881  mid = shell->doAddMsg( "OneToAll",
882  adaptK, "requestOut", chemK, "get_conc" );
883  assert( ! mid.bad() );
884  mid = shell->doAddMsg( "OneToAll",
885  adaptK, "output", elecK, "set_Gbar" );
886  assert( ! mid.bad() );
887  Field< double >::set( adaptK, "scale", 0.3 ); // from mM to Siemens
888  // The starting Gbar is 0.0002827.
889 
891  // Set up the plots, both elec and chem.
893  // plots.push_back( addPlot( "/n/head0", "get_Vm", "spineVm0" ) );
894  plots.push_back( addPlot( "/n/head1", "get_Vm", "spineVm1" ) );
895  plots.push_back( addPlot( "/n/head2", "get_Vm", "spineVm2" ) );
896  // plots.push_back( addPlot( "/n/head3", "get_Vm", "spineVm3" ) );
897  // plots.push_back( addPlot( "/n/head4", "get_Vm", "spineVm4" ) );
898  plots.push_back( addPlot( "/n/compt", "get_Vm", "dendVm" ) );
899  plots.push_back( addPlot( "/n/head2/ca", "get_Ca", "spineElecCa" ) );
900  // plots.push_back( addPlot( "/n/spineMesh/Ca", "get_conc", "spineChemCa") );
901  // plots.push_back( addPlot( "/n/neuroMesh/Ca", "get_conc", "dendChemCa"));
902  plots.push_back( addPlot( "/n/psdMesh/psdGluR", "get_n", "psdGluR_N" ));
903  // plots.push_back( addPlot( "/n/head2/gluR", "get_Gbar", "elecGluR_Gbar" ) );
904  plots.push_back( addPlot( "/n/head2/gluR", "get_Ik", "elecGluR_Ik2" ) );
905  // plots.push_back( addPlot( "/n/head0/gluR", "get_Gk", "elecGluR_Gk0" ) );
906  // plots.push_back( addPlot( "/n/head1/gluR", "get_Gk", "elecGluR_Gk1" ) );
907  plots.push_back( addPlot( "/n/head2/gluR", "get_Gk", "elecGluR_Gk2" ) );
908  // plots.push_back( addPlot( "/n/head3/gluR", "get_Gk", "elecGluR_Gk3" ) );
909  // plots.push_back( addPlot( "/n/head4/gluR", "get_Gk", "elecGluR_Gk4" ) );
910  // plots.push_back( addPlot( "/n/neuroMesh/kChan", "get_conc", "kChan_conc" ) );
911  // plots.push_back( addPlot( "/n/compt/K", "get_Gbar", "kChan_Gbar" ) );
912  plots.push_back( addPlot( "/n/spineMesh/toPsd", "get_conc", "toPsd") );
913 
915  return nid;
916 }
917 
918 void testAdaptorsInCubeMesh()
919 {
920  Shell* shell = reinterpret_cast< Shell* >( ObjId( Id(), 0 ).data() );
921  vector< int > dims( 1, 1 );
922  vector< Id > plots;
923  Id nid = buildAdaptorsInCubeMesh( plots );
924 
926  // Schedule, Reset, and run.
928 
929  shell->doSetClock( 0, 20.0e-6 );
930  shell->doSetClock( 1, 20.0e-6 );
931  shell->doSetClock( 2, 20.0e-6 );
932  shell->doSetClock( 5, 1.0e-3 );
933  shell->doSetClock( 6, 1.0e-3 );
934  shell->doSetClock( 8, 1.0e-4 );
935 
936  shell->doUseClock( "/n/compt,/n/shaft#,/n/head#", "init", 0 );
937  shell->doUseClock( "/n/compt,/n/shaft#,/n/head#", "process", 1 );
938  shell->doUseClock( "/n/synInput", "process", 1 );
939  shell->doUseClock( "/n/compt/Na,/n/compt/K", "process", 2 );
940  shell->doUseClock( "/n/head#/#", "process", 2 );
941  shell->doUseClock( "/n/#Mesh/##", "process", 5 );
942  shell->doUseClock( "/n/adapt#", "process", 6 );
943  shell->doUseClock( "/n/#[ISA=Table]", "process", 8 );
944 
945  shell->doReinit();
946  shell->doReinit();
947  shell->doStart( 10 );
948 
949  for ( vector< Id >::iterator i = plots.begin(); i != plots.end(); ++i )
950  {
951  SetGet2< string, string >::set( *i, "xplot", "adapt.plot",
952  i->element()->getName() );
953  }
955  // Now put in a chemical solver to do the whole chem model
957  Id solver = shell->doCreate( "GslStoich", nid, "solver", dims.size() );
958  assert( solver != Id() );
959  Field< string >::set( solver, "path", "/n/##" );
960  Field< string >::set( solver, "method", "rk5" );
961  shell->doSetClock( 5, 1.0e-3 );
962  shell->doSetClock( 6, 1.0e-3 );
963  shell->doUseClock( "/n/solver", "process", 5 );
964  shell->doReinit();
965  shell->doStart( 10.0 );
966 
967  for ( vector< Id >::iterator i = plots.begin(); i != plots.end(); ++i )
968  {
969  SetGet2< string, string >::set( *i, "xplot", "k_adapt.plot",
970  i->element()->getName() );
971  }
973  // Build hsolver too.
975  Id hsolve = shell->doCreate( "HSolve", nid, "hsolve", dims.size() );
976  shell->doUseClock( "/n/hsolve", "process", 1 );
977  Field< double >::set( hsolve, "dt", 20.0e-6 );
978  Field< string >::set( hsolve, "target", "/n/compt" );
979  shell->doReinit();
980  shell->doStart( 10.0 );
981 
982  for ( vector< Id >::iterator i = plots.begin(); i != plots.end(); ++i )
983  {
984  SetGet2< string, string >::set( *i, "xplot", "hk_adapt.plot",
985  i->element()->getName() );
986  }
988 
989  shell->doDelete( nid );
990  cout << "." << flush;
991 }
992 #endif
993 
994 // This tests stuff without using the messaging.
995 void testSigNeur()
996 {
997  testAdaptor();
998 }
999 
1000 // This is applicable to tests that use the messaging and scheduling.
1001 void testSigNeurProcess()
1002 {
1003  testAdaptorRequestField();
1004  // After 2 June 2013, checkin 4579, the tests in
1005  // testSigNeurElec
1006  // testChemInCubeMesh
1007  // testAdaptorsInCubeMesh() // Does a chem+elec model with adaptors
1008  // have been moved to a
1009  // separate Python snippet called testSigNeur.py. These tests take
1010  // too long to run in unit tests and anyway it does not test as much
1011  // as generate an output that I can compare with the expected one.
1012  /*
1013  makeChemInNeuroMesh();
1014  Id nid = makeChemInCubeMesh();
1015  Shell* shell = reinterpret_cast< Shell* >( ObjId( Id(), 0 ).data() );
1016  shell->doDelete( nid );
1017  cout << "." << flush;
1018  */
1019 }
1020 
1021 #else // DO_UNIT_TEST
1023 {;}
1025 {;}
1026 #endif
void doStart(double runtime, bool notify=false)
Definition: Shell.cpp:332
char * data() const
Definition: ObjId.cpp:113
const double NA
Definition: consts.cpp:15
vector< ObjId > getMsgTargets(DataId srcDataId, const SrcFinfo *finfo) const
Definition: Element.cpp:856
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
void doSetClock(unsigned int tickNum, double dt)
Definition: Shell.cpp:377
bool bad() const
Definition: ObjId.cpp:18
Definition: SetGet.h:236
void testSigNeurProcess()
const double FaradayConst
Definition: consts.cpp:17
Definition: ObjId.h:20
static bool set(const ObjId &dest, const string &field, A arg)
Definition: SetGet.h:245
void innerProcess()
Definition: Adaptor.cpp:354
Id doCreate(string type, ObjId parent, string name, unsigned int numData, NodePolicy nodePolicy=MooseBlockBalance, unsigned int preferredNode=1)
Definition: Shell.cpp:181
void setInputOffset(double offset)
Definition: Adaptor.cpp:310
void setScale(double scale)
Definition: Adaptor.cpp:328
void setOutputOffset(double offset)
Definition: Adaptor.cpp:319
bool doubleEq(double x, double y)
Definition: doubleEq.cpp:16
void testSigNeur()
double getOutput() const
Definition: Adaptor.cpp:337
const Cinfo * cinfo() const
Definition: Element.cpp:66
virtual unsigned int numData() const =0
Returns number of data entries across all nodes.
void doReinit()
Definition: Shell.cpp:362
static char name[]
Definition: mfield.cpp:401
ObjId doAddMsg(const string &msgType, ObjId src, const string &srcField, ObjId dest, const string &destField)
Definition: Shell.cpp:269
static bool set(const ObjId &dest, const string &field, A arg)
Definition: SetGet.h:153
const double PI
Definition: consts.cpp:12
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
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
void input(double val)
Definition: Adaptor.cpp:347
Definition: Shell.h:43
const Finfo * findFinfo(const string &name) const
Definition: Cinfo.cpp:224
Definition: Finfo.h:12
static bool set(const ObjId &dest, const string &field, A1 arg1, A2 arg2)
Definition: SetGet.h:365