NEURON
matrixmap.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 #include "matrixmap.h"
3 #include <vector>
4 using std::vector;
5 
6 #include "spmatrix.h"
7 extern spREAL *spGetElement(char*, int ,int);
8 
10  : m_(mat), plen_(0), ptree_(NULL), pm_(NULL) {
11 }
12 
14  : m_(*mat), plen_(0), ptree_(NULL), pm_(NULL) {
15 }
16 
18  mmfree();
19 }
20 
22  // safe to delete NULL pointers
23  delete [] ptree_;
24  delete [] pm_;
25  ptree_ = NULL;
26  pm_ = NULL;
27 }
28 
29 void MatrixMap::add(double fac) {
30  for (int i=0 ; i < plen_; ++i) {
31 //printf("i=%d %g += %g * %g\n", i, *ptree_[i], fac, *pm_[i]);
32  *ptree_[i] += fac * (*pm_[i]);
33  }
34 }
35 
36 void MatrixMap::alloc(int start, int nnode, Node** nodes, int* layer) {
37  NrnThread* _nt = nrn_threads;
38  mmfree();
39  // how many elements
40  int nrow = m_.nrow();
41  int ncol = m_.ncol();
42 //printf("MatrixMap::alloc nrow=%d ncol=%d\n", nrow, ncol);
43 
44  plen_ = 0;
45  vector<int> nonzero_i, nonzero_j;
46  m_.nonzeros(nonzero_i, nonzero_j);
47  pm_ = new double*[nonzero_i.size()];
48  ptree_ = new double*[nonzero_i.size()];
49  for (int k = 0; k < nonzero_i.size(); k++) {
50  const int i = nonzero_i[k];
51  const int j = nonzero_j[k];
52  int it;
53  if (i < nnode) {
54  it = nodes[i] -> eqn_index_ + layer[i];
55 //printf("i=%d it=%d area=%g\n", i, it, nodes[i]->area);
56  if (layer[i] > 0 && !nodes[i] -> extnode) {
57  it = 0;
58  }
59  } else {
60  it = start + i - nnode;
61  }
62  int jt;
63  pm_[plen_] = m_.mep(i, j);
64  if (j < nnode) {
65  jt = nodes[j] -> eqn_index_ + layer[j];
66  if (layer[j] > 0 && !nodes[j] -> extnode) {
67  jt = 0;
68  }
69  } else {
70  jt = start + j - nnode;
71  }
72 //printf("MatrixMap::alloc getElement(%d,%d)\n", it, jt);
73  ptree_[plen_] = spGetElement(_nt->_sp13mat, it, jt);
74  ++plen_;
75  }
76 }
77 
78 
Represent main neuron object computed by single thread.
Definition: multicore.h:58
double ** pm_
Definition: matrixmap.h:62
void add(double fac)
Definition: matrixmap.cpp:29
double ** ptree_
Definition: matrixmap.h:63
static philox4x32_key_t k
Definition: nrnran123.cpp:11
MatrixMap(Matrix *)
Definition: matrixmap.cpp:13
j< sec-> nnode
Definition: treeset.cpp:905
void start()
Definition: hel2mos.cpp:205
void alloc(int, int, Node **, int *)
Definition: matrixmap.cpp:36
#define extnode
Definition: md1redef.h:9
NrnThread * nrn_threads
Definition: multicore.cpp:45
char * _sp13mat
Definition: multicore.h:79
size_t j
#define spREAL
Definition: spmatrix.h:127
int ncol()
Definition: matrixmap.h:30
int nrow()
Definition: matrixmap.h:29
#define i
Definition: md1redef.h:12
void mmfree()
Definition: matrixmap.cpp:21
spREAL * spGetElement(char *, int, int)
Definition: spbuild.c:195
Definition: section.h:132
int plen_
Definition: matrixmap.h:61
return NULL
Definition: cabcode.cpp:461
MatrixPtr Matrix
Definition: sputils.c:601
Matrix & m_
Definition: matrixmap.h:58