-
Notifications
You must be signed in to change notification settings - Fork 0
/
HinesMatrixProxy.h
135 lines (118 loc) · 5 KB
/
HinesMatrixProxy.h
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
/**********************************************************************
** 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.
**********************************************************************/
#ifndef _HINES_MATRIX_H
#define _HINES_MATRIX_H
#ifdef DO_UNIT_TESTS
# define ASSERT( isOK, message ) \
if ( !(isOK) ) { \
cerr << "\nERROR: Assert '" << #isOK << "' failed on line " << __LINE__ << "\nin file " << __FILE__ << ": " << message << endl; \
exit( 1 ); \
} else { \
cout << ""; \
}
#else
# define ASSERT( unused, message ) do {} while ( false )
#endif
struct JunctionStruct
{
JunctionStruct( unsigned int i, unsigned int r ) :
index( i ),
rank( r )
{ ; }
bool operator< ( const JunctionStruct& other ) const {
return ( index < other.index );
}
unsigned int index; ///< Hines index of the compartment.
unsigned int rank; ///< Number of elements "remaining" in this
///< compartment's group: i.e., number of children
///< with a larger Hines index, +1 for the parent.
};
struct TreeNodeStruct
{
vector< unsigned int > children; ///< Hines indices of child compts
double Ra;
double Rm;
double Cm;
double Em;
double initVm;
};
#include "HSC_PerformSimulation.hpp"
class HinesMatrixProxy
{
public:
HinesMatrixProxy();
void setup( const vector< TreeNodeStruct >& tree, double dt );
unsigned int getSize() const;
double getA( unsigned int row, unsigned int col ) const;
double getB( unsigned int row ) const;
double getVMid( unsigned int row ) const;
protected:
typedef vector< double >::iterator vdIterator;
unsigned int nCompt_;
double dt_;
vector< JunctionStruct > junction_;
vector< double > HS_; /**< Hines, series.
* Flattened array containing the tridiagonal of the approximately
* tridiagonal Hines matrix, stacked against the column vector "b" that
* appears on the RHS of the equation that we're trying to solve: Ax=b.
*/
vector< double > HJ_; /**< Hines, junctions.
* Flattened array containing the off-diagonal elements of the Hines
* matrix */
vector< double > HJCopy_;
vector< double > VMid_; ///< Compartment voltage at the
///< middle of a time step.
vector< vdIterator > operand_;
vector< vdIterator > backOperand_;
int stage_; ///< Which stage the simulation has
///< reached. Used in getA.
HSC_PerformSimulation *hsc_simulation;
ThreadInfo* tInfo;
private:
void clear();
void makeJunctions();
/**< This function creates junction structs to be stored in junction_.
* It does so by first looking through all compartments and finding
* those which have more than zero or one child. The zero-one child
* compts are left alone. coupled_ is populated with the rest of the
* compartments. Each element of coupled_ is sorted (they are all
* unsigned ints) and coupled_ itself is sorted by the first element
* in each element (groupCompare does this comparison in
* HinesMatrixProxy.cpp).
* Note: the children themselves are unsigned ints that store the
* Hines index of the corresponding child compartment.
* So essentially, at each branch, a JunctionStruct is created for
* each child, which contains the hines index of that child and its
* rank, which is group-size() - childIndex - 1. */
void makeMatrix(); /**< Populates HS_ and HJ_.
* All of the electrical circuit analysis goes into this one single
* function (and updateMatrix, of course). */
void makeOperands(); ///< Makes operands in order to make forward
void GPU_KernelSetup();
///< elimination easier.
const vector< TreeNodeStruct > *tree_; ///< Stores compt info for
///< setup.
vector< double > Ga_;
vector< vector< unsigned int > > coupled_;
/**< Contains a list of all children of a given compt. Also contains
* the parent itself. i.e., for each compartment that has more than
* one child, coupled_ stores a vector containing the children of the
* compartment and the compartment itself.
* coupled_ is therefore a vector of such vectors. */
map< unsigned int, vdIterator > operandBase_;
/**< Contains iterators into HJ_ demarcating where a child's neighbours
* begin. Used for iterating through HJ_ along with junction_. */
map< unsigned int, unsigned int > groupNumber_;
/**< Tells you the index of a compartment's group within coupled_,
* given the compartment's Hines index. */
//New CUDA supports
void configureSimulation(const vector< TreeNodeStruct >& tree, double dt, ThreadInfo *& tInfo, int nNeurons, char *configFile);
void configureNeuronTypes(const vector< TreeNodeStruct >& tree, double dt, ThreadInfo*& tInfo, int nNeuronsTotal, char *configFileName);
};
#endif // _HINES_MATRIX_H