MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
HSolvePassive Class Reference

#include <HSolvePassive.h>

+ Inheritance diagram for HSolvePassive:
+ Collaboration diagram for HSolvePassive:

Public Member Functions

void setup (Id seed, double dt)
 
void solve ()
 
- Public Member Functions inherited from HinesMatrix
double getA (unsigned int row, unsigned int col) const
 
double getB (unsigned int row) const
 
unsigned int getSize () const
 
double getVMid (unsigned int row) const
 
 HinesMatrix ()
 
void setup (const vector< TreeNodeStruct > &tree, double dt)
 

Protected Member Functions

void backwardSubstitute ()
 
void forwardEliminate ()
 
void updateMatrix ()
 

Protected Attributes

vector< CompartmentStructcompartment_
 
vector< IdcompartmentId_
 
map< unsigned int, InjectStructinject_
 
vector< TreeNodeStructtree_
 
vector< double > V_
 
- Protected Attributes inherited from HinesMatrix
vector< vdIteratorbackOperand_
 
double dt_
 
vector< double > HJ_
 
vector< double > HJCopy_
 
vector< double > HS_
 
vector< JunctionStructjunction_
 
unsigned int nCompt_
 
vector< vdIteratoroperand_
 
int stage_
 reached. Used in getA. More...
 
vector< double > VMid_
 middle of a time step. More...
 

Private Member Functions

void clear ()
 
double getV (unsigned int row) const
 
void initialize ()
 
void storeTree ()
 
void walkTree (Id seed)
 

Additional Inherited Members

- Protected Types inherited from HinesMatrix
typedef vector< double >::iterator vdIterator
 

Detailed Description

Definition at line 20 of file HSolvePassive.h.

Member Function Documentation

void HSolvePassive::backwardSubstitute ( )
protected

Definition at line 325 of file HSolvePassive.cpp.

References HinesMatrix::backOperand_, HinesMatrix::HS_, HinesMatrix::junction_, HinesMatrix::nCompt_, HinesMatrix::operand_, HinesMatrix::stage_, V_, and HinesMatrix::VMid_.

Referenced by solve(), and HSolveActive::step().

326 {
327  int ic = nCompt_ - 1;
328  vector< double >::reverse_iterator ivmid = VMid_.rbegin();
329  vector< double >::reverse_iterator iv = V_.rbegin();
330  vector< double >::reverse_iterator ihs = HS_.rbegin();
331  vector< vdIterator >::reverse_iterator iop = operand_.rbegin();
332  vector< vdIterator >::reverse_iterator ibop = backOperand_.rbegin();
333  vector< JunctionStruct >::reverse_iterator junction;
334 
335  *ivmid = *ihs / *( ihs + 3 );
336  *iv = 2 * *ivmid - *iv;
337  --ic, ++ivmid, ++iv, ihs += 4;
338 
339  int index;
340  int rank;
341  for ( junction = junction_.rbegin();
342  junction != junction_.rend();
343  junction++ )
344  {
345  index = junction->index;
346  rank = junction->rank;
347 
348  while ( ic > index )
349  {
350  *ivmid = ( *ihs - *( ihs + 2 ) **( ivmid - 1 ) ) / *( ihs + 3 );
351  *iv = 2 * *ivmid - *iv;
352 
353  --ic, ++ivmid, ++iv, ihs += 4;
354  }
355 
356  if ( rank == 1 )
357  {
358  *ivmid = ( *ihs - **iop ***( iop + 2 ) ) / *( ihs + 3 );
359 
360  iop += 3;
361  }
362  else if ( rank == 2 )
363  {
364  vdIterator v0 = *( iop );
365  vdIterator v1 = *( iop + 2 );
366  vdIterator j = *( iop + 4 );
367 
368  *ivmid = ( *ihs
369  - *v0 **( j + 2 )
370  - *v1 **j
371  ) / *( ihs + 3 );
372 
373  iop += 5;
374  }
375  else
376  {
377  *ivmid = *ihs;
378  for ( int i = 0; i < rank; ++i )
379  {
380  *ivmid -= **ibop ***( ibop + 1 );
381  ibop += 2;
382  }
383  *ivmid /= *( ihs + 3 );
384 
385  iop += 3 * rank * ( rank + 1 );
386  }
387 
388  *iv = 2 * *ivmid - *iv;
389  --ic, ++ivmid, ++iv, ihs += 4;
390  }
391 
392  while ( ic >= 0 )
393  {
394  *ivmid = ( *ihs - *( ihs + 2 ) **( ivmid - 1 ) ) / *( ihs + 3 );
395  *iv = 2 * *ivmid - *iv;
396 
397  --ic, ++ivmid, ++iv, ihs += 4;
398  }
399 
400  stage_ = 2; // Backward substitution done.
401 }
vector< double > VMid_
middle of a time step.
Definition: HinesMatrix.h:83
unsigned int nCompt_
Definition: HinesMatrix.h:70
vector< vdIterator > backOperand_
Definition: HinesMatrix.h:86
vector< double > V_
Definition: HSolvePassive.h:38
int stage_
reached. Used in getA.
Definition: HinesMatrix.h:87
vector< vdIterator > operand_
Definition: HinesMatrix.h:85
vector< double > HS_
Definition: HinesMatrix.h:74
vector< JunctionStruct > junction_
Definition: HinesMatrix.h:73
vector< double >::iterator vdIterator
Definition: HinesMatrix.h:68

+ Here is the caller graph for this function:

void HSolvePassive::clear ( )
private

Definition at line 35 of file HSolvePassive.cpp.

References compartment_, compartmentId_, HinesMatrix::dt_, inject_, tree_, and V_.

Referenced by setup().

36 {
37  dt_ = 0.0;
38  compartment_.clear();
39  compartmentId_.clear();
40  V_.clear();
41  tree_.clear();
42  inject_.clear();
43 }
vector< Id > compartmentId_
Definition: HSolvePassive.h:37
vector< double > V_
Definition: HSolvePassive.h:38
vector< CompartmentStruct > compartment_
Definition: HSolvePassive.h:36
map< unsigned int, InjectStruct > inject_
Definition: HSolvePassive.h:45
vector< TreeNodeStruct > tree_
Definition: HSolvePassive.h:41
double dt_
Definition: HinesMatrix.h:71

+ Here is the caller graph for this function:

void HSolvePassive::forwardEliminate ( )
protected

Definition at line 246 of file HSolvePassive.cpp.

References HinesMatrix::HS_, HinesMatrix::junction_, HinesMatrix::nCompt_, HinesMatrix::operand_, and HinesMatrix::stage_.

Referenced by solve(), and HSolveActive::step().

247 {
248  unsigned int ic = 0;
249  vector< double >::iterator ihs = HS_.begin();
250  vector< vdIterator >::iterator iop = operand_.begin();
251  vector< JunctionStruct >::iterator junction;
252 
253  double pivot;
254  double division;
255  unsigned int index;
256  unsigned int rank;
257  for ( junction = junction_.begin();
258  junction != junction_.end();
259  junction++ )
260  {
261  index = junction->index;
262  rank = junction->rank;
263 
264  while ( ic < index )
265  {
266  *( ihs + 4 ) -= *( ihs + 1 ) / *ihs **( ihs + 1 );
267  *( ihs + 7 ) -= *( ihs + 1 ) / *ihs **( ihs + 3 );
268 
269  ++ic, ihs += 4;
270  }
271 
272  pivot = *ihs;
273  if ( rank == 1 )
274  {
275  vdIterator j = *iop;
276  vdIterator s = *( iop + 1 );
277 
278  division = *( j + 1 ) / pivot;
279  *( s ) -= division **j;
280  *( s + 3 ) -= division **( ihs + 3 );
281 
282  iop += 3;
283  }
284  else if ( rank == 2 )
285  {
286  vdIterator j = *iop;
287  vdIterator s;
288 
289  s = *( iop + 1 );
290  division = *( j + 1 ) / pivot;
291  *( s ) -= division **j;
292  *( j + 4 ) -= division **( j + 2 );
293  *( s + 3 ) -= division **( ihs + 3 );
294 
295  s = *( iop + 3 );
296  division = *( j + 3 ) / pivot;
297  *( j + 5 ) -= division **j;
298  *( s ) -= division **( j + 2 );
299  *( s + 3 ) -= division **( ihs + 3 );
300 
301  iop += 5;
302  }
303  else
304  {
305  vector< vdIterator >::iterator
306  end = iop + 3 * rank * ( rank + 1 );
307  for ( ; iop < end; iop += 3 )
308  **iop -= **( iop + 2 ) / pivot ***( iop + 1 );
309  }
310 
311  ++ic, ihs += 4;
312  }
313 
314  while ( ic < nCompt_ - 1 )
315  {
316  *( ihs + 4 ) -= *( ihs + 1 ) / *ihs **( ihs + 1 );
317  *( ihs + 7 ) -= *( ihs + 1 ) / *ihs **( ihs + 3 );
318 
319  ++ic, ihs += 4;
320  }
321 
322  stage_ = 1; // Forward elimination done.
323 }
unsigned int nCompt_
Definition: HinesMatrix.h:70
int stage_
reached. Used in getA.
Definition: HinesMatrix.h:87
vector< vdIterator > operand_
Definition: HinesMatrix.h:85
vector< double > HS_
Definition: HinesMatrix.h:74
vector< JunctionStruct > junction_
Definition: HinesMatrix.h:73
vector< double >::iterator vdIterator
Definition: HinesMatrix.h:68

+ Here is the caller graph for this function:

double HSolvePassive::getV ( unsigned int  row) const
private

Definition at line 407 of file HSolvePassive.cpp.

References V_.

408 {
409  return V_[ row ];
410 }
vector< double > V_
Definition: HSolvePassive.h:38
void HSolvePassive::initialize ( )
private

Definition at line 100 of file HSolvePassive.cpp.

References CompartmentStruct::CmByDt, compartment_, compartmentId_, HinesMatrix::dt_, CompartmentStruct::EmByRm, Field< A >::get(), inject_, HSolveUtils::leakageChannels(), HinesMatrix::nCompt_, and V_.

Referenced by setup().

101 {
102  nCompt_ = compartmentId_.size();
103 
104  double Vm, Cm, Em, Rm, inject;
105  double EmLeak, GmLeak;
106  double EmGmThev, GmThev;
107 
108  vector< Id > leakage;
109  vector< Id >::iterator ileakage;
110 
111  for ( unsigned int ic = 0; ic < compartmentId_.size(); ++ic )
112  {
113  Id cc = compartmentId_[ ic ];
114 
115  Vm = Field< double >::get( cc, "Vm" );
116  Cm = Field< double >::get( cc, "Cm" );
117  Em = Field< double >::get( cc, "Em" );
118  Rm = Field< double >::get( cc, "Rm" );
119  inject = Field< double >::get( cc, "inject" );
120  V_.push_back( Vm );
121 
122  /*
123  * If there are 'n' leakage channels with reversal potentials:
124  * E[ 1 ] ... E[ n ]
125  * and resistances:
126  * R[ 1 ] ... R[ n ]
127  * respectively, then the membrane circuit can be represented by the
128  * Thevenin equivalent circuit with:
129  *
130  * R_thevenin = 1 / sum( 1 / R[ i ] )
131  * = 1 / sum( G[ i ] )
132  * E_thevenin = sum( E[ i ] / R[ i ] ) * R_thevenin
133  * = sum( E[ i ] * G[ i ] ) * R_thevenin
134  *
135  * Here we have to add original membrane potential Em as E[ 0 ] and
136  * resistance Rm as R[ 0 ].
137  */
138  GmThev = 1.0 / Rm;
139  EmGmThev = Em / Rm;
140 
142  for ( ileakage = leakage.begin();
143  ileakage != leakage.end();
144  ileakage++ )
145  {
146  EmLeak = Field< double >::get( *ileakage, "Ek" );
147  GmLeak = Field< double >::get( *ileakage, "Gk" );
148  GmThev += GmLeak;
149  EmGmThev += EmLeak * GmLeak;
150  }
151 
152 // RmThev = 1.0 / GmThev;
153 
154  CompartmentStruct compartment;
155  compartment.CmByDt = 2.0 * Cm / dt_;
156  compartment.EmByRm = EmGmThev;
157  compartment_.push_back( compartment );
158 
159  if ( inject != 0.0 )
160  {
161  inject_[ ic ].injectVarying = 0.0;
162  inject_[ ic ].injectBasal = inject;
163  }
164  }
165 }
static int leakageChannels(Id compartment, vector< Id > &ret)
vector< Id > compartmentId_
Definition: HSolvePassive.h:37
unsigned int nCompt_
Definition: HinesMatrix.h:70
vector< double > V_
Definition: HSolvePassive.h:38
vector< CompartmentStruct > compartment_
Definition: HSolvePassive.h:36
map< unsigned int, InjectStruct > inject_
Definition: HSolvePassive.h:45
Definition: Id.h:17
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
double dt_
Definition: HinesMatrix.h:71

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void HSolvePassive::setup ( Id  seed,
double  dt 
)

Definition at line 14 of file HSolvePassive.cpp.

References clear(), HinesMatrix::dt_, initialize(), HinesMatrix::setup(), storeTree(), tree_, and walkTree().

Referenced by HSolveActive::setup().

15 {
16  clear();
17  dt_ = dt;
18  walkTree( seed );
19  initialize();
20  storeTree();
22 }
void walkTree(Id seed)
void setup(const vector< TreeNodeStruct > &tree, double dt)
Definition: HinesMatrix.cpp:25
vector< TreeNodeStruct > tree_
Definition: HSolvePassive.h:41
double dt_
Definition: HinesMatrix.h:71

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void HSolvePassive::solve ( )

Definition at line 24 of file HSolvePassive.cpp.

References backwardSubstitute(), forwardEliminate(), and updateMatrix().

25 {
26  updateMatrix();
29 }
void forwardEliminate()
void backwardSubstitute()

+ Here is the call graph for this function:

void HSolvePassive::storeTree ( )
private

Definition at line 167 of file HSolvePassive.cpp.

References HSolveUtils::children(), TreeNodeStruct::children, TreeNodeStruct::Cm, compartmentId_, TreeNodeStruct::Em, Field< A >::get(), TreeNodeStruct::initVm, HinesMatrix::nCompt_, TreeNodeStruct::Ra, TreeNodeStruct::Rm, and tree_.

Referenced by setup().

168 {
169  double Ra, Rm, Cm, Em, initVm;
170 
171  // Create a map from the MOOSE Id to Hines' index.
172  map< Id, unsigned int > hinesIndex;
173  for ( unsigned int ic = 0; ic < nCompt_; ++ic )
174  hinesIndex[ compartmentId_[ ic ] ] = ic;
175 
176  vector< Id > childId;
177  vector< Id >::iterator child;
178 
179  vector< Id >::iterator ic;
180 
181  for ( ic = compartmentId_.begin(); ic != compartmentId_.end(); ++ic )
182  {
183  childId.clear();
184 
185  HSolveUtils::children( *ic, childId );
186  Ra = Field< double >::get( *ic, "Ra" );
187  Cm = Field< double >::get( *ic, "Cm" );
188  Rm = Field< double >::get( *ic, "Rm" );
189  Em = Field< double >::get( *ic, "Em" );
190  initVm = Field< double >::get( *ic, "initVm" );
191 
192  TreeNodeStruct node;
193  // Push hines' indices of children
194  for ( child = childId.begin(); child != childId.end(); ++child )
195  node.children.push_back( hinesIndex[ *child ] );
196 
197  node.Ra = Ra;
198  node.Rm = Rm;
199  node.Cm = Cm;
200  node.Em = Em;
201  node.initVm = initVm;
202 
203  tree_.push_back( node );
204  }
205 }
static int children(Id compartment, vector< Id > &ret)
Definition: HSolveUtils.cpp:47
vector< unsigned int > children
Hines indices of child compts.
Definition: HinesMatrix.h:47
vector< Id > compartmentId_
Definition: HSolvePassive.h:37
unsigned int nCompt_
Definition: HinesMatrix.h:70
vector< TreeNodeStruct > tree_
Definition: HSolvePassive.h:41
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void HSolvePassive::updateMatrix ( )
protected

Definition at line 211 of file HSolvePassive.cpp.

References compartment_, HinesMatrix::HJ_, HinesMatrix::HJCopy_, HinesMatrix::HS_, inject_, InjectStruct::injectBasal, InjectStruct::injectVarying, HinesMatrix::stage_, V_, and value.

Referenced by solve().

212 {
213  /*
214  * Copy contents of HJCopy_ into HJ_. Cannot do a vector assign() because
215  * iterators to HJ_ get invalidated in MS VC++
216  */
217  if ( HJ_.size() != 0 )
218  memcpy( &HJ_[ 0 ], &HJCopy_[ 0 ], sizeof( double ) * HJ_.size() );
219 
220  vector< double >::iterator ihs = HS_.begin();
221  vector< double >::iterator iv = V_.begin();
222 
223  vector< CompartmentStruct >::iterator ic;
224  for ( ic = compartment_.begin(); ic != compartment_.end(); ++ic )
225  {
226  *ihs = *( 2 + ihs );
227  *( 3 + ihs ) = *iv * ic->CmByDt + ic->EmByRm;
228 
229  ihs += 4, ++iv;
230  }
231 
232  map< unsigned int, InjectStruct >::iterator inject;
233  for ( inject = inject_.begin(); inject != inject_.end(); inject++ )
234  {
235  unsigned int ic = inject->first;
236  InjectStruct& value = inject->second;
237 
238  HS_[ 4 * ic + 3 ] += value.injectVarying + value.injectBasal;
239 
240  value.injectVarying = 0.0;
241  }
242 
243  stage_ = 0; // Update done.
244 }
uint32_t value
Definition: moosemodule.h:42
double injectBasal
Definition: HSolveStruct.h:41
vector< double > V_
Definition: HSolvePassive.h:38
vector< CompartmentStruct > compartment_
Definition: HSolvePassive.h:36
int stage_
reached. Used in getA.
Definition: HinesMatrix.h:87
map< unsigned int, InjectStruct > inject_
Definition: HSolvePassive.h:45
double injectVarying
Definition: HSolveStruct.h:40
vector< double > HJCopy_
Definition: HinesMatrix.h:82
vector< double > HS_
Definition: HinesMatrix.h:74
vector< double > HJ_
Definition: HinesMatrix.h:79

+ Here is the caller graph for this function:

void HSolvePassive::walkTree ( Id  seed)
private

Definition at line 45 of file HSolvePassive.cpp.

References HSolveUtils::adjacent(), and compartmentId_.

Referenced by setup().

46 {
47  //~ // Dirty call to explicitly call the compartments reinitFunc.
48  //~ // Should be removed eventually, and replaced with a cleaner way to
49  //~ // initialize the model being read.
50  //~ HSolveUtils::initialize( seed );
51 
52  // Find leaf node
53  Id previous;
54  vector< Id > adjacent;
55  HSolveUtils::adjacent( seed, adjacent );
56  if ( adjacent.size() > 1 )
57  while ( !adjacent.empty() )
58  {
59  previous = seed;
60  seed = adjacent[ 0 ];
61 
62  adjacent.clear();
63  HSolveUtils::adjacent( seed, previous, adjacent );
64  }
65 
66  // Depth-first search
67  vector< vector< Id > > cstack;
68  Id above;
69  Id current;
70  cstack.resize( 1 );
71  cstack[ 0 ].push_back( seed );
72  while ( !cstack.empty() )
73  {
74  vector< Id >& top = cstack.back();
75 
76  if ( top.empty() )
77  {
78  cstack.pop_back();
79  if ( !cstack.empty() )
80  cstack.back().pop_back();
81  }
82  else
83  {
84  if ( cstack.size() > 1 )
85  above = cstack[ cstack.size() - 2 ].back();
86 
87  current = top.back();
88  compartmentId_.push_back( current );
89 
90  cstack.resize( cstack.size() + 1 );
91  HSolveUtils::adjacent( current, above, cstack.back() );
92  }
93  }
94 
95  // Compartments get ordered according to their hines' indices once this
96  // list is reversed.
97  reverse( compartmentId_.begin(), compartmentId_.end() );
98 }
static int adjacent(Id compartment, vector< Id > &ret)
Definition: HSolveUtils.cpp:36
vector< Id > compartmentId_
Definition: HSolvePassive.h:37
Definition: Id.h:17

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

vector< CompartmentStruct > HSolvePassive::compartment_
protected

Definition at line 36 of file HSolvePassive.h.

Referenced by clear(), HSolve::getIm(), initialize(), and updateMatrix().

map< unsigned int, InjectStruct > HSolvePassive::inject_
protected

inject map. contains the list of compartments that have current injections into them.

Definition at line 45 of file HSolvePassive.h.

Referenced by HSolve::addInject(), clear(), HSolve::getInject(), initialize(), HSolve::setInject(), and updateMatrix().

vector< TreeNodeStruct > HSolvePassive::tree_
protected

Tree info. The tree is used to acquire various values during setup. It contains the user-defined original values of all compartment parameters. Therefore, it is also used during reinit.

Definition at line 41 of file HSolvePassive.h.

Referenced by clear(), HSolve::getCm(), HSolve::getEm(), HSolve::getIm(), HSolve::getInitVm(), HSolve::getRa(), HSolve::getRm(), HSolveActive::reinitCompartments(), HSolve::setCm(), HSolve::setEm(), HSolve::setInitVm(), HSolve::setRa(), HSolve::setRm(), setup(), and storeTree().

vector< double > HSolvePassive::V_
protected

Compartment Vm. V_ is addressed using a compartment index. V_ stores the Vm value of each compartment.

Definition at line 38 of file HSolvePassive.h.

Referenced by backwardSubstitute(), clear(), HSolve::getIk(), HSolve::getIm(), getV(), HSolve::getVm(), initialize(), HSolveActive::readSynapses(), HSolveActive::reinitChannels(), HSolveActive::reinitCompartments(), HSolve::setVm(), and updateMatrix().


The documentation for this class was generated from the following files: