NEST main@caf0ae8
 
Loading...
Searching...
No Matches
cm_tree.h
Go to the documentation of this file.
1/*
2 * cm_tree.h
3 *
4 * This file is part of NEST.
5 *
6 * Copyright (C) 2004 The NEST Initiative
7 *
8 * NEST is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * NEST is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with NEST. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#ifndef CM_TREE_H
24#define CM_TREE_H
25
26#include <stdlib.h>
27
28#include "nest_time.h"
29#include "ring_buffer.h"
30
31// compartmental model
33
34// Includes from libnestutil:
35#include "dict_util.h"
36#include "numerics.h"
37
38// Includes from nestkernel:
39#include "exceptions.h"
40#include "kernel_manager.h"
42
43
44namespace nest
45{
46
48{
49private:
51 double xx_;
52 double yy_;
53
54public:
58 long p_index;
61 std::vector< Compartment > children;
62
66 double ca; // compartment capacitance [uF]
67 double gc; // coupling conductance with parent (meaningless if root) [uS]
68 double gl; // leak conductance of compartment [uS]
69 double el; // leak current reversal potential [mV]
70
72 double v_comp;
73
75 double gg0;
77 double gl__div__2;
78 double gc__div__2;
81 double ff;
82 double gg;
83 double hh;
86
89
90 Compartment( const long compartment_index, const long parent_index );
91 Compartment( const long compartment_index, const long parent_index, const Dictionary& compartment_params );
93
94 // initialization
95 void pre_run_hook();
96 std::map< std::string, double* > get_recordables();
97
99 void construct_matrix_element( const long lag );
100
102 inline void gather_input( const std::pair< double, double >& in );
103 inline std::pair< double, double > io();
104 inline double calc_v( const double v_in );
105}; // Compartment
106
107
108/*
109Short helper functions for solving the matrix equation. Can hopefully be inlined
110*/
111inline void
112Compartment::gather_input( const std::pair< double, double >& in )
113{
114 xx_ += in.first;
115 yy_ += in.second;
116}
117
118inline std::pair< double, double >
120{
121 // include inputs from child compartments
122 gg -= xx_;
123 ff -= yy_;
124
125 // output values
126 double g_val( hh * hh / gg );
127 double f_val( ff * hh / gg );
128
129 return std::make_pair( g_val, f_val );
130}
131
132inline double
133Compartment::calc_v( const double v_in )
134{
135 // reset recursion variables
136 xx_ = 0.0;
137 yy_ = 0.0;
138
139 // compute voltage
140 v_comp = ( ff - v_in * hh ) / gg;
141
142 return v_comp;
143}
144
145
147{
148private:
153 std::vector< long > compartment_indices_;
154 std::vector< Compartment* > compartments_;
155 std::vector< Compartment* > leafs_;
156
157 long size_ = 0;
158
160 void solve_matrix_downsweep( Compartment* compartment_ptr, std::vector< Compartment* >::iterator leaf_it );
161 void solve_matrix_upsweep( Compartment* compartment, double vv );
162
164 void set_parents();
165 void set_compartments();
166 void set_leafs();
167
168public:
169 CompTree();
171
173 void add_compartment( const long parent_index );
174 void add_compartment( const long parent_index, const Dictionary& compartment_params );
175 void add_compartment( Compartment* compartment, const long parent_index );
176
178 void pre_run_hook();
179
182 void init_pointers();
183
185 void set_syn_buffers( std::vector< RingBuffer >& syn_buffers );
186
188 std::map< std::string, double* > get_recordables();
189
191 Compartment* get_compartment( const long compartment_index ) const;
192 Compartment* get_compartment( const long compartment_index, Compartment* compartment, const long raise_flag ) const;
193 Compartment* get_compartment_opt( const long compartment_indx ) const;
195 get_root() const
196 {
197 return &root_;
198 };
199
201 long
202 get_size() const
203 {
204 return size_;
205 };
206
208 std::vector< double > get_voltage() const;
209 double get_compartment_voltage( const long compartment_index );
210
212 void construct_matrix( const long lag );
214 void solve_matrix();
215
217 void print_tree() const;
218}; // CompTree
219
220} // namespace
221
222#endif /* #ifndef CM_TREE_H */
Dictionary class for interface to Python and C++ API.
Definition dictionary.h:213
Definition cm_tree.h:147
Compartment * get_compartment_opt(const long compartment_indx) const
Get the compartment corresponding to the provided index in the tree.
Definition cm_tree.cpp:270
void set_leafs()
Creates a vector of compartment pointers of compartments that are also leafs of the tree.
Definition cm_tree.cpp:322
Compartment * get_compartment(const long compartment_index) const
get a compartment pointer from the tree
Definition cm_tree.cpp:230
void set_parents()
functions for pointer initialization
Definition cm_tree.cpp:290
void set_syn_buffers(std::vector< RingBuffer > &syn_buffers)
associate each receptor with a spike buffer
Definition cm_tree.cpp:338
long get_size() const
get tree size (number of compartments)
Definition cm_tree.h:202
void add_compartment(const long parent_index)
add a compartment to the tree structure
Definition cm_tree.cpp:170
Compartment * get_root() const
Definition cm_tree.h:195
void pre_run_hook()
initialize the tree for simulation
Definition cm_tree.cpp:370
std::vector< double > get_voltage() const
get voltage values
Definition cm_tree.cpp:389
CompTree()
Definition cm_tree.cpp:156
void print_tree() const
print function
Definition cm_tree.cpp:483
std::vector< Compartment * > leafs_
Definition cm_tree.h:155
void solve_matrix_upsweep(Compartment *compartment, double vv)
Definition cm_tree.cpp:468
Compartment root_
structural data containers for the compartment model
Definition cm_tree.h:152
double get_compartment_voltage(const long compartment_index)
Return voltage of single compartment voltage, indicated by the compartment_index.
Definition cm_tree.cpp:403
std::vector< long > compartment_indices_
Definition cm_tree.h:153
void init_pointers()
fix all pointers in the tree, the tree structure should not be modified between calling this function...
Definition cm_tree.cpp:279
std::vector< Compartment * > compartments_
Definition cm_tree.h:154
void set_compartments()
Creates a vector of compartment pointers, organized in the order in which they were added by add_comp...
Definition cm_tree.cpp:307
void solve_matrix_downsweep(Compartment *compartment_ptr, std::vector< Compartment * >::iterator leaf_it)
recursion functions for matrix inversion
Definition cm_tree.cpp:436
void construct_matrix(const long lag)
construct the numerical integration matrix and vector
Definition cm_tree.cpp:412
std::map< std::string, double * > get_recordables()
make all state variables accessible for recording
Definition cm_tree.cpp:350
~CompTree()
Definition cm_tree.h:170
long size_
Definition cm_tree.h:157
void solve_matrix()
solve the matrix equation for next timestep voltage
Definition cm_tree.cpp:424
Definition cm_compartmentcurrents.h:404
Definition cm_tree.h:48
double gl__div__2
Definition cm_tree.h:77
double el
Definition cm_tree.h:69
double yy_
Definition cm_tree.h:52
Compartment * parent
tree structure indices
Definition cm_tree.h:60
double ca
electrical parameters
Definition cm_tree.h:66
double gl__times__el
Definition cm_tree.h:79
std::vector< Compartment > children
Definition cm_tree.h:61
double gg0
auxiliary variables for efficienchy
Definition cm_tree.h:75
double gl
Definition cm_tree.h:68
double xx_
aggragators for numerical integration
Definition cm_tree.h:51
double gc
Definition cm_tree.h:67
double ff
for numerical integration
Definition cm_tree.h:81
double gc__div__2
Definition cm_tree.h:78
double hh
Definition cm_tree.h:83
CompartmentCurrents compartment_currents
vector for synapses
Definition cm_tree.h:88
~Compartment()
Definition cm_tree.h:92
double v_comp
voltage variable
Definition cm_tree.h:72
double gg
Definition cm_tree.h:82
long comp_index
compartment index
Definition cm_tree.h:56
void construct_matrix_element(const long lag)
matrix construction
Definition cm_tree.cpp:116
std::pair< double, double > io()
Definition cm_tree.h:119
RingBuffer currents
buffer for currents
Definition cm_tree.h:64
void pre_run_hook()
Definition cm_tree.cpp:88
double calc_v(const double v_in)
Definition cm_tree.h:133
double ca__div__dt
Definition cm_tree.h:76
std::map< std::string, double * > get_recordables()
Definition cm_tree.cpp:104
int n_passed
passage counter for recursion
Definition cm_tree.h:85
long p_index
parent compartment index
Definition cm_tree.h:58
void gather_input(const std::pair< double, double > &in)
maxtrix inversion
Definition cm_tree.h:112
Buffer Layout.
Definition ring_buffer.h:83
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33