-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHSolveHub.cpp
909 lines (761 loc) · 23.8 KB
/
HSolveHub.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
/**********************************************************************
** This program is part of 'MOOSE', the
** Messaging Object Oriented Simulation Environment.
** copyright (C) 2003-2007 Upinder S. Bhalla, Niraj Dudani and NCBS
** It is made available under the terms of the
** GNU Lesser General Public License version 2.1
** See the file COPYING.LIB for the full notice.
**********************************************************************/
#include "moose.h"
#include "element/Neutral.h"
#include "biophysics/Compartment.h"
#include "biophysics/HHChannel.h"
#include "biophysics/CaConc.h"
#include "HSolveStruct.h"
#include "HinesMatrixProxy.h"
#include "HSolvePassive.h"
#include "RateLookup.h"
#include "HSolveActive.h"
#include "ThisFinfo.h"
#include "SolveFinfo.h"
#include "HSolveHub.h"
// Defined below.
const Cinfo* initHSolveHubCinfoInner();
Finfo* initCompartmentZombieFinfo();
Finfo* initHHChannelZombieFinfo();
Finfo* initCaConcZombieFinfo();
/**
* This function is required to initialize the replacement Finfos
* (i.e., SolveFinfo:s standing in for ThisFinfo:s for zombified objects).
* We will need to ensure that this function is called explicitly during
* the initialization of MOOSE (currently done in maindir/initCinfos.cpp).
*/
const Cinfo* initHSolveHubCinfo()
{
static const Cinfo* HSolveHubCinfo = initHSolveHubCinfoInner();
static Finfo* f1 = initCompartmentZombieFinfo();
static Finfo* f2 = initHHChannelZombieFinfo();
static Finfo* f3 = initCaConcZombieFinfo();
// Only to avoid compiler warnings.
f1 = 0;
f2 = 0;
f3 = 0;
return HSolveHubCinfo;
}
const Cinfo* initHSolveHubCinfoInner()
{
static Finfo* zombieShared[] =
{
new SrcFinfo( "process", Ftype1< ProcInfo >::global() ),
new SrcFinfo( "reinit", Ftype1< ProcInfo >::global() ),
};
static Finfo* compartmentChannelShared[] =
{
new DestFinfo(
"channel",
Ftype2< double, double >::global(),
RFCAST( &HSolveHub::compartmentChannelFunc ) ),
new SrcFinfo(
"Vm",
Ftype1< double >::global() ),
};
static Finfo* HSolveHubFinfos[] =
{
///////////////////////////////////////////////////////
// Field definitions
///////////////////////////////////////////////////////
///////////////////////////////////////////////////////
// MsgSrc definitions
///////////////////////////////////////////////////////
///////////////////////////////////////////////////////
// MsgDest definitions
///////////////////////////////////////////////////////
new DestFinfo( "integ-hub",
Ftype1< HSolveActive* >::global(),
RFCAST( &HSolveHub::hubFunc ),
"In this message, the hub receives a handle (a pointer) to the "
"solver. This is used by the hub to access the fields of the solver." ),
new DestFinfo( "destroy", Ftype0::global(),
&HSolveHub::destroy ),
new DestFinfo( "child", Ftype1< int >::global(),
RFCAST( &HSolveHub::childFunc ),
"override the Neutral::childFunc here, so that when this is deleted "
"all the zombies are reanimated." ),
new DestFinfo( "compartmentInjectMsg", Ftype1< double >::global(),
RFCAST( &HSolveHub::compartmentInjectMsgFunc ) ),
new SharedFinfo( "compartmentChannel", compartmentChannelShared,
sizeof( compartmentChannelShared ) / sizeof( Finfo* ),
"This message allows communication between external channels and "
"the Hines' solver." ),
///////////////////////////////////////////////////////
// Shared definitions
///////////////////////////////////////////////////////
new SharedFinfo( "compartmentSolve", zombieShared,
sizeof( zombieShared ) / sizeof( Finfo* ),
"This is identical to the message sent from clock Ticks to objects. "
"Here it is used to take over the Process message, usually only as "
"a handle from the solver to the object." ),
new SharedFinfo( "hhchannelSolve", zombieShared,
sizeof( zombieShared ) / sizeof( Finfo* ) ),
new SharedFinfo( "caconcSolve", zombieShared,
sizeof( zombieShared ) / sizeof( Finfo* ) ),
};
static string doc[] =
{
"Name",
"HSolveHub",
"Author",
"Niraj Dudani, 2007, NCBS",
"Description",
"HSolveHub: Ensures that field and message requests to solved objects "
"are cleanly redirected to their respective HSolve object.",
};
static Cinfo HSolveHubCinfo(
doc,
sizeof( doc ) / sizeof( string ),
initNeutralCinfo(),
HSolveHubFinfos,
sizeof( HSolveHubFinfos ) / sizeof( Finfo* ),
ValueFtype1< HSolveHub >::global()
);
return &HSolveHubCinfo;
}
static const Cinfo* HSolveHubCinfo = initHSolveHubCinfo();
static const Finfo* compartmentSolveFinfo =
initHSolveHubCinfo()->findFinfo( "compartmentSolve" );
static const Finfo* hhchannelSolveFinfo =
initHSolveHubCinfo()->findFinfo( "hhchannelSolve" );
static const Finfo* caconcSolveFinfo =
initHSolveHubCinfo()->findFinfo( "caconcSolve" );
static const Finfo* hubCompartmentInjectFinfo =
initHSolveHubCinfo()->findFinfo( "compartmentInjectMsg" );
static const Finfo* hubCompartmentChannelFinfo =
initHSolveHubCinfo()->findFinfo( "compartmentChannel" );
/*
* Finfos from biophysical objects. Needed so that 'set' operations are done
* on the solver as well as the objects. Also needed for redirecting any dest
* messages on these finfos to the solver (e.g.: to the inject field).
*/
static const Finfo* compartmentInjectFinfo =
initCompartmentCinfo()->findFinfo( "injectMsg" );
static const Finfo* compartmentChannelFinfo =
initCompartmentCinfo()->findFinfo( "channel" );
static const Finfo* compartmentVmFinfo =
initCompartmentCinfo()->findFinfo( "Vm" );
static const Finfo* channelGbarFinfo =
initHHChannelCinfo()->findFinfo( "Gbar" );
static const Finfo* channelEkFinfo =
initHHChannelCinfo()->findFinfo( "Ek" );
static const Finfo* channelGkFinfo =
initHHChannelCinfo()->findFinfo( "Gk" );
static const Finfo* channelXFinfo =
initHHChannelCinfo()->findFinfo( "X" );
static const Finfo* channelYFinfo =
initHHChannelCinfo()->findFinfo( "Y" );
static const Finfo* channelZFinfo =
initHHChannelCinfo()->findFinfo( "Z" );
static const Finfo* caConcCaFinfo =
initCaConcCinfo()->findFinfo( "Ca" );
/////////////////////////////////////////////////////////////////////////
// Replacement fields for aspiring zombies
/////////////////////////////////////////////////////////////////////////
Finfo* initCompartmentZombieFinfo()
{
static Finfo* compartmentFields[] =
{
new ValueFinfo( "Vm",
ValueFtype1< double >::global(),
GFCAST( &HSolveHub::getVm ),
RFCAST( &HSolveHub::setVm )
),
new ValueFinfo( "Im",
ValueFtype1< double >::global(),
GFCAST( &HSolveHub::getIm ),
&dummyFunc
),
new ValueFinfo( "inject",
ValueFtype1< double >::global(),
GFCAST( &HSolveHub::getInject ),
RFCAST( &HSolveHub::setInject )
),
};
static const ThisFinfo* tf = dynamic_cast< const ThisFinfo* >(
initCompartmentCinfo()->getThisFinfo() );
assert( tf != 0 );
static SolveFinfo compartmentZombieFinfo(
compartmentFields,
sizeof( compartmentFields ) / sizeof( Finfo* ),
tf,
"These fields will replace the original compartment fields so that the lookups refer to the solver rather "
"than the compartment."
);
return &compartmentZombieFinfo;
}
Finfo* initHHChannelZombieFinfo()
{
static Finfo* hhchannelFields[] =
{
new ValueFinfo( "Gbar", ValueFtype1< double >::global(),
GFCAST( &HSolveHub::getHHChannelGbar ),
RFCAST( &HSolveHub::setHHChannelGbar )
),
new ValueFinfo( "Ek", ValueFtype1< double >::global(),
GFCAST( &HSolveHub::getEk ),
RFCAST( &HSolveHub::setEk )
),
new ValueFinfo( "Gk", ValueFtype1< double >::global(),
GFCAST( &HSolveHub::getGk ),
RFCAST( &HSolveHub::setGk )
),
new ValueFinfo( "Ik", ValueFtype1< double >::global(),
GFCAST( &HSolveHub::getIk ),
&dummyFunc
),
new ValueFinfo( "X", ValueFtype1< double >::global(),
GFCAST( &HSolveHub::getX ),
RFCAST( &HSolveHub::setX )
),
new ValueFinfo( "Y", ValueFtype1< double >::global(),
GFCAST( &HSolveHub::getY ),
RFCAST( &HSolveHub::setY )
),
new ValueFinfo( "Z", ValueFtype1< double >::global(),
GFCAST( &HSolveHub::getZ ),
RFCAST( &HSolveHub::setZ )
),
};
static const ThisFinfo* tf = dynamic_cast< const ThisFinfo* >(
initHHChannelCinfo()->getThisFinfo() );
assert( tf != 0 );
static SolveFinfo hhchannelZombieFinfo(
hhchannelFields,
sizeof( hhchannelFields ) / sizeof( Finfo* ),
tf
);
return &hhchannelZombieFinfo;
}
Finfo* initCaConcZombieFinfo()
{
static Finfo* caconcFields[] =
{
new ValueFinfo( "Ca", ValueFtype1< double >::global(),
GFCAST( &HSolveHub::getCa ),
RFCAST( &HSolveHub::setCa )
),
};
static const ThisFinfo* tf = dynamic_cast< const ThisFinfo* >(
initCaConcCinfo()->getThisFinfo() );
assert( tf != 0 );
static SolveFinfo caconcZombieFinfo(
caconcFields,
sizeof( caconcFields ) / sizeof( Finfo* ),
tf
);
return &caconcZombieFinfo;
}
static Finfo* compartmentZombieFinfo = initCompartmentZombieFinfo();
static Finfo* hhchannelZombieFinfo = initHHChannelZombieFinfo();
static Finfo* caconcZombieFinfo = initCaConcZombieFinfo();
/////////////////////////////////////////////////////////////////////////
// End of static initializers.
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
// Constructor
/////////////////////////////////////////////////////////////////////////
HSolveHub::HSolveHub()
: integ_( 0 )
{ ; }
/////////////////////////////////////////////////////////////////////////
// Field access functions (for Hub)
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
// Dest functions (for Hub)
/////////////////////////////////////////////////////////////////////////
void HSolveHub::hubFunc( const Conn* c, HSolveActive* integ )
{
static_cast< HSolveHub* >( c->data() )->
innerHubFunc( c->target(), integ );
}
void HSolveHub::innerHubFunc( Eref hub, HSolveActive* integ )
{
hub_ = hub;
integ_ = integ;
manageCompartments();
manageHHChannels();
manageCaConcs();
}
/**
* In this destructor we need to put messages back to process,
* and we need to replace the SolveFinfos on zombies with the
* original ThisFinfo. This should really just use the clearFunc.
*/
void HSolveHub::destroy( const Conn* c )
{
static Finfo* origCompartmentFinfo =
const_cast< Finfo* >(
initCompartmentCinfo()->getThisFinfo() );
static Finfo* origHHChannelFinfo =
const_cast< Finfo* >(
initHHChannelCinfo()->getThisFinfo() );
Element* hub = c->target().e;
unsigned int eIndex = c->target().i;
Conn* i = hub->targets( compartmentSolveFinfo->msg(), eIndex );
while ( i->good() ) {
i->target().e->setThisFinfo( origCompartmentFinfo );
i->increment();
}
delete i;
i = hub->targets( hhchannelSolveFinfo->msg(), eIndex );
while ( i->good() ) {
i->target().e->setThisFinfo( origHHChannelFinfo );
i->increment();
}
delete i;
Neutral::destroy( c );
}
void HSolveHub::childFunc( const Conn* c, int stage )
{
// clear messages: first clean out zombies before the messages are
// all deleted.
if ( stage == 1 )
clearFunc( c->target() );
// Then fall back into what the Neutral version does
Neutral::childFunc( c, stage );
}
/////////////////////////////////////////////////////////////////////////
// Class functions
/////////////////////////////////////////////////////////////////////////
void HSolveHub::idlist2elist(
const vector< Id >& idlist,
vector< Element* >& elist )
{
vector< Id >::const_iterator id;
for ( id = idlist.begin(); id != idlist.end(); id++ )
elist.push_back( ( *id )() );
}
void HSolveHub::manageCompartments()
{
const vector< Id >& idlist = integ_->getCompartments();
vector< Element* > elist;
idlist2elist( idlist, elist );
const vector< vector< Id > >& externalChannelIds =
integ_->getExternalChannels();
vector< Element* > extChanList;
const Finfo* initFinfo = initCompartmentCinfo()->findFinfo( "init" );
vector< Element* >::const_iterator i;
for ( i = elist.begin(); i != elist.end(); i++ ) {
zombify( hub_, *i, compartmentSolveFinfo, compartmentZombieFinfo );
// Compartment receives 2 shared messages from Tick's "process"
Eref( *i ).dropAll( initFinfo->msg() );
redirectDynamicMessages( *i );
}
/*
* Redirecting dest/shared messages
*/
for ( unsigned int ic = 0; ic < elist.size(); ic++ ) {
// The 'retain' flag at the end is 1: we do not delete the original
// message to the compartment.
redirectDestMessages(
hub_, elist[ ic ],
hubCompartmentInjectFinfo, compartmentInjectFinfo,
ic, compartmentInjectMap_,
&elist, 0,
1 );
extChanList.clear();
idlist2elist( externalChannelIds[ ic ], extChanList );
redirectDestMessages(
hub_, elist[ ic ],
hubCompartmentChannelFinfo, compartmentChannelFinfo,
ic, compartmentChannelMap_,
&elist, &extChanList,
1 );
}
}
void HSolveHub::manageHHChannels()
{
const vector< Id >& idlist = integ_->getHHChannels();
vector< Element* > elist;
idlist2elist( idlist, elist );
vector< Element* >::const_iterator i;
for ( i = elist.begin(); i != elist.end(); i++ ) {
zombify( hub_, *i, hhchannelSolveFinfo, hhchannelZombieFinfo );
redirectDynamicMessages( *i );
}
}
void HSolveHub::manageCaConcs()
{
const vector< Id >& idlist = integ_->getCaConcs();
vector< Element* > elist;
idlist2elist( idlist, elist );
vector< Element* >::const_iterator i;
for ( i = elist.begin(); i != elist.end(); i++ ) {
zombify( hub_, *i, caconcSolveFinfo, caconcZombieFinfo );
redirectDynamicMessages( *i );
}
}
/**
* Clears out all the messages to zombie objects
*/
void HSolveHub::clearFunc( Eref hub )
{
clearMsgsFromFinfo( hub, compartmentSolveFinfo );
clearMsgsFromFinfo( hub, hhchannelSolveFinfo );
hub.dropAll( compartmentInjectFinfo->msg() );
}
void HSolveHub::clearMsgsFromFinfo( Eref hub, const Finfo * f )
{
Conn* c = hub.e->targets( f->msg(), hub.i );
vector< Element* > list;
while ( c->good() ) {
list.push_back( c->target().e );
c->increment();
}
delete c;
hub.dropAll( f->msg() );
vector< Element* >::iterator i;
for ( i = list.begin(); i != list.end(); i++ ) unzombify( *i );
}
void HSolveHub::unzombify( Element* e )
{
const Cinfo* ci = e->cinfo();
bool ret = ci->schedule( e, ConnTainer::Default );
assert( ret );
e->setThisFinfo( const_cast< Finfo* >( ci->getThisFinfo() ) );
redirectDynamicMessages( e );
}
/**
* This operation turns the target element e into a zombie controlled
* by the hub/solver. It gets rid of any process message coming into
* the zombie and replaces it with one from the solver.
*/
void HSolveHub::zombify(
Eref hub, Eref e,
const Finfo* hubFinfo, Finfo* solveFinfo )
{
// Replace the original procFinfo with one from the hub.
const Finfo* procFinfo = e->findFinfo( "process" );
e.dropAll( procFinfo->msg() );
bool ret = hub.add( hubFinfo->msg(), e, procFinfo->msg(),
ConnTainer::Default );
assert( ret );
// Redirect original messages from the zombie to the hub.
// Pending.
// Replace the 'ThisFinfo' on the solved element
e->setThisFinfo( solveFinfo );
}
/**
* This function redirects messages arriving at zombie elements onto
* the hub.
* e is the zombie element whose messages are being redirected to the hub.
* eFinfo is the Finfo holding those messages.
* hubFinfo is the Finfo on the hub which will now handle the messages.
* eIndex is the index to look up the element.
*/
void HSolveHub::redirectDestMessages(
Eref hub,
Eref e,
const Finfo* hubFinfo,
const Finfo* eFinfo,
unsigned int eIndex,
vector< unsigned int >& map,
vector< Element * >* elist,
vector< Element * >* include,
bool retain )
{
Conn* i = e.e->targets( eFinfo->msg(), e.i );
vector< Eref > srcElements;
vector< int > srcMsg;
vector< const ConnTainer* > dropList;
while( i->good() ) {
Element* tgt = i->target().e;
// Handle messages going outside purview of solver.
bool inElist = find( elist->begin(), elist->end(), tgt ) != elist->end();
bool inInclude =
include == 0 ||
find( include->begin(), include->end(), tgt ) != include->end();
if ( ! inElist && inInclude ) {
map.push_back( eIndex );
srcElements.push_back( i->target() );
srcMsg.push_back( i->targetMsg() );
if ( !retain )
dropList.push_back( i->connTainer() );
}
i->increment();
}
delete i;
e.dropVec( eFinfo->msg(), dropList );
for ( unsigned int j = 0; j != srcElements.size(); j++ ) {
bool ret = srcElements[j].add( srcMsg[j], hub, hubFinfo->msg(),
ConnTainer::Default );
assert( ret );
}
}
/**
* Here we replace the existing DynamicFinfos and their messages with
* new ones for the updated access functions.
*
* It would be nice to retain everything and only replace the
* access functions, but this gets too messy as it requires poking the
* new funcVecs into the remote Msgs. So instead we delete the
* old DynamicFinfos and recreate them.
*/
// Assumption e is a simple element. Replace it with Eref to make it general
void HSolveHub::redirectDynamicMessages( Element* e )
{
vector< Finfo* > flist;
// We get a list of DynamicFinfos independent of the Finfo vector on
// the Element, because we will be messing up the iterators on the
// element.
e->listLocalFinfos( flist );
vector< Finfo* >::iterator i;
// Go through flist noting messages, deleting finfo, and rebuilding.
for( i = flist.begin(); i != flist.end(); ++i )
{
const DynamicFinfo *df = dynamic_cast< const DynamicFinfo* >( *i );
if ( df == 0 )
continue;
vector< Eref > srcElements;
vector< const Finfo* > srcFinfos;
Conn* c = e->targets( ( *i )->msg(), 0 ); //zero index for SE
// note messages.
while( c->good() ) {
srcElements.push_back( c->target() );
srcFinfos.push_back(
c->target().e->findFinfo( c->targetMsg() ) );
c->increment();
}
delete c;
string name = df->name();
bool ret = e->dropFinfo( df );
assert( ret );
const Finfo* origFinfo = e->findFinfo( name );
assert( origFinfo );
unsigned int max = srcFinfos.size();
for ( unsigned int i = 0; i < max; i++ ) {
ret = srcElements[ i ].add( srcFinfos[ i ]->name(),
e, name );
/*
ret = srcElements[ i ].add( srcFinfos[ i ]->msg(),
e, origFinfo->msg(), ConnTainer::Default );
*/
// ret = srcFinfos[ i ]->add( srcElements[ i ], e, origFinfo );
assert( ret );
}
}
}
/**
* Looks up the solver from the zombie element e. Returns the solver
* element, or null on failure.
* It needs the originating Finfo on the solver that connects to the zombie,
* as the srcFinfo.
* Also passes back the index of the zombie element on this set of
* messages. This is NOT the absolute Conn index.
*/
HSolveHub* HSolveHub::getHubFromZombie( Eref e, unsigned int& index )
{
Conn* c = e.e->targets( "process", e.i );
if ( c->good() ) {
index = c->targetIndex();
HSolveHub* nh = static_cast< HSolveHub* >( c->target().data() );
c->increment();
assert( !c->good() ); // Should only be one process incoming.
return dynamic_cast< HSolveHub* >( nh );
}
delete c;
return 0;
}
/////////////////////////////////////////////////////////////////////////
// Field access functions (Biophysics)
/////////////////////////////////////////////////////////////////////////
void HSolveHub::setVm( const Conn* c, double value )
{
Eref e = c->target();
set< double >( e, compartmentVmFinfo, value );
unsigned int index;
HSolveHub* nh = getHubFromZombie( e, index );
if ( nh )
nh->integ_->setVm( index, value );
}
double HSolveHub::getVm( Eref e )
{
unsigned int index;
HSolveHub* nh = getHubFromZombie( e, index );
if ( nh )
return nh->integ_->getVm( index );
return 0.0;
}
void HSolveHub::setInject( const Conn* c, double value )
{
Eref e = c->target();
set< double >( e, compartmentInjectFinfo, value );
unsigned int index;
HSolveHub* nh = getHubFromZombie( e, index );
if ( nh )
nh->integ_->setInject( index, value );
}
double HSolveHub::getInject( Eref e )
{
unsigned int index;
HSolveHub* nh = getHubFromZombie( e, index );
if ( nh )
return nh->integ_->getInject( index );
return 0.0;
}
double HSolveHub::getIm( Eref e )
{
unsigned int index;
HSolveHub* nh = getHubFromZombie( e, index );
if ( nh )
return nh->integ_->getIm( index );
return 0.0;
}
void HSolveHub::setHHChannelGbar( const Conn* c, double value )
{
Eref e = c->target();
set< double >( e, channelGbarFinfo, value );
unsigned int index;
HSolveHub* nh = getHubFromZombie( e, index );
if ( nh )
nh->integ_->setHHChannelGbar( index, value );
}
double HSolveHub::getHHChannelGbar( Eref e )
{
unsigned int index;
HSolveHub* nh = getHubFromZombie( e, index );
if ( nh )
return nh->integ_->getHHChannelGbar( index );
return 0.0;
}
void HSolveHub::setEk( const Conn* c, double value )
{
Eref e = c->target();
set< double >( e, channelEkFinfo, value );
unsigned int index;
HSolveHub* nh = getHubFromZombie( e, index );
if ( nh )
nh->integ_->setEk( index, value );
}
double HSolveHub::getEk( Eref e )
{
unsigned int index;
HSolveHub* nh = getHubFromZombie( e, index );
if ( nh )
return nh->integ_->getEk( index );
return 0.0;
}
void HSolveHub::setGk( const Conn* c, double value )
{
Eref e = c->target();
set< double >( e, channelGkFinfo, value );
unsigned int index;
HSolveHub* nh = getHubFromZombie( e, index );
if ( nh )
nh->integ_->setGk( index, value );
}
double HSolveHub::getGk( Eref e )
{
unsigned int index;
HSolveHub* nh = getHubFromZombie( e, index );
if ( nh )
return nh->integ_->getGk( index );
return 0.0;
}
double HSolveHub::getIk( Eref e )
{
unsigned int index;
HSolveHub* nh = getHubFromZombie( e, index );
if ( nh )
return nh->integ_->getIk( index );
return 0.0;
}
void HSolveHub::setX( const Conn* c, double value )
{
Eref e = c->target();
set< double >( e, channelXFinfo, value );
unsigned int index;
HSolveHub* nh = getHubFromZombie( e, index );
if ( nh )
nh->integ_->setX( index, value );
}
double HSolveHub::getX( Eref e )
{
unsigned int index;
HSolveHub* nh = getHubFromZombie( e, index );
if ( nh )
return nh->integ_->getX( index );
return 0.0;
}
void HSolveHub::setY( const Conn* c, double value )
{
Eref e = c->target();
set< double >( e, channelYFinfo, value );
unsigned int index;
HSolveHub* nh = getHubFromZombie( e, index );
if ( nh )
nh->integ_->setY( index, value );
}
double HSolveHub::getY( Eref e )
{
unsigned int index;
HSolveHub* nh = getHubFromZombie( e, index );
if ( nh )
return nh->integ_->getY( index );
return 0.0;
}
void HSolveHub::setZ( const Conn* c, double value )
{
Eref e = c->target();
set< double >( e, channelZFinfo, value );
unsigned int index;
HSolveHub* nh = getHubFromZombie( e, index );
if ( nh )
nh->integ_->setZ( index, value );
}
double HSolveHub::getZ( Eref e )
{
unsigned int index;
HSolveHub* nh = getHubFromZombie( e, index );
if ( nh )
return nh->integ_->getZ( index );
return 0.0;
}
void HSolveHub::setCa( const Conn* c, double value )
{
Eref e = c->target();
set< double >( e, caConcCaFinfo, value );
unsigned int index;
HSolveHub* nh = getHubFromZombie( e, index );
if ( nh )
nh->integ_->setCa( index, value );
}
double HSolveHub::getCa( Eref e )
{
unsigned int index;
HSolveHub* nh = getHubFromZombie( e, index );
if ( nh )
return nh->integ_->getCa( index );
return 0.0;
}
/////////////////////////////////////////////////////////////////////////
// Dest functions (Biophysics)
/////////////////////////////////////////////////////////////////////////
void HSolveHub::compartmentInjectMsgFunc( const Conn* c, double value )
{
Element* hub = c->target().e;
unsigned int index = c->targetIndex();
HSolveHub* nh = static_cast< HSolveHub* >( hub->data() );
assert( nh != 0 );
assert( index < nh->compartmentInjectMap_.size() );
nh->integ_->addInject( nh->compartmentInjectMap_[ index ], value );
}
void HSolveHub::compartmentChannelFunc( const Conn* c, double v1, double v2 )
{
Element* hub = c->target().e;
unsigned int index = c->targetIndex();
HSolveHub* nh = static_cast< HSolveHub* >( hub->data() );
assert( nh != 0 );
assert( index < nh->compartmentChannelMap_.size() );
nh->integ_->addGkEk(
nh->compartmentChannelMap_[ index ],
v1, v2 );
}