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