MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
testHSolve.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 #ifndef DO_UNIT_TESTS
11 void testHSolve()
12 {;}
13 #else
14 
15 #include <vector>
16 #include <map>
17 using namespace std;
18 
19 #include "HinesMatrix.h"
20 
21 extern void testHinesMatrix(); // Defined in HinesMatrix.cpp
22 extern void testHSolvePassive(); // Defined in HSolvePassive.cpp
23 extern void testHSolveUtils(); // Defined in HSolveUtils.cpp
24 extern void runRallpackBenchmarks(); /* Defined in RallPacks.cpp */
25 
26 void testHSolve()
27 {
28  testHSolveUtils();
29  testHinesMatrix();
30  testHSolvePassive();
31 }
32 
34 // Helper functions called in testHinesMatrix, testHSolvePassive, etc.
36 
37 void makeFullMatrix(
38  const vector< TreeNodeStruct >& tree,
39  double dt,
40  vector< vector< double > >& matrix )
41 {
42  unsigned int size = tree.size();
43 
44  /*
45  * Some convenience variables
46  */
47  vector< double > CmByDt;
48  vector< double > Ga;
49  for ( unsigned int i = 0; i < tree.size(); i++ ) {
50  CmByDt.push_back( tree[ i ].Cm / ( dt / 2.0 ) );
51  Ga.push_back( 2.0 / tree[ i ].Ra );
52  }
53 
54  /* Each entry in 'coupled' is a list of electrically coupled compartments.
55  * These compartments could be linked at junctions, or even in linear segments
56  * of the cell.
57  */
58  vector< vector< unsigned int > > coupled;
59  for ( unsigned int i = 0; i < tree.size(); i++ )
60  if ( tree[ i ].children.size() >= 1 ) {
61  coupled.push_back( tree[ i ].children );
62  coupled.back().push_back( i );
63  }
64 
65  matrix.clear();
66  matrix.resize( size );
67  for ( unsigned int i = 0; i < size; ++i )
68  matrix[ i ].resize( size );
69 
70  // Setting diagonal elements
71  for ( unsigned int i = 0; i < size; i++ )
72  matrix[ i ][ i ] = CmByDt[ i ] + 1.0 / tree[ i ].Rm;
73 
74  double gi;
75  vector< vector< unsigned int > >::iterator group;
76  vector< unsigned int >::iterator ic;
77  for ( group = coupled.begin(); group != coupled.end(); ++group ) {
78  double gsum = 0.0;
79 
80  for ( ic = group->begin(); ic != group->end(); ++ic )
81  gsum += Ga[ *ic ];
82 
83  for ( ic = group->begin(); ic != group->end(); ++ic ) {
84  gi = Ga[ *ic ];
85 
86  matrix[ *ic ][ *ic ] += gi * ( 1.0 - gi / gsum );
87  }
88  }
89 
90  // Setting off-diagonal elements
91  double gij;
92  vector< unsigned int >::iterator jc;
93  for ( group = coupled.begin(); group != coupled.end(); ++group ) {
94  double gsum = 0.0;
95 
96  for ( ic = group->begin(); ic != group->end(); ++ic )
97  gsum += Ga[ *ic ];
98 
99  for ( ic = group->begin(); ic != group->end() - 1; ++ic ) {
100  for ( jc = ic + 1; jc != group->end(); ++jc ) {
101  gij = Ga[ *ic ] * Ga[ *jc ] / gsum;
102 
103  matrix[ *ic ][ *jc ] = -gij;
104  matrix[ *jc ][ *ic ] = -gij;
105  }
106  }
107  }
108 }
109 
110 #endif
void makeFullMatrix(const vector< TreeNodeStruct > &tree, double dt, vector< vector< double > > &matrix)
static SrcFinfo0 * group()
Definition: Group.cpp:17
vector< vector< T > > resize(vector< vector< T > >table, unsigned int n, T init)
void testHSolve()
Definition: testHSolve.cpp:11