NEURON
matrixmap.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 #include "matrixmap.h"
3 #include <vector>
4 
5 #include "spmatrix.h"
6 
8  : m_(mat) {}
9 
11  : m_(*mat) {}
12 
14  pm_.clear();
15  pm_.shrink_to_fit();
16  ptree_.clear();
17  ptree_.shrink_to_fit();
18 }
19 
20 void MatrixMap::add(double fac) {
21  for (int i = 0; i < pm_.size(); ++i) {
22  auto [it, jt] = pm_[i];
23  *ptree_[i] += fac * m_(it, jt);
24  }
25 }
26 
27 int MatrixMap::compute_index(int i, int start, int nnode, Node** nodes, int* layer) const {
28  int it;
29  if (i < nnode) {
30  it = nodes[i]->eqn_index_ + layer[i];
31  if (layer[i] > 0 && !nodes[i]->extnode) {
32  it = 0;
33  }
34  } else {
35  it = start + i - nnode;
36  }
37  return it;
38 }
39 
40 void MatrixMap::alloc(int start, int nnode, Node** nodes, int* layer) {
41  NrnThread* _nt = nrn_threads;
42  mmfree();
43 
44  std::vector<std::pair<int, int>> nzs = m_.nonzeros();
45  pm_.reserve(nzs.size());
46  ptree_.reserve(nzs.size());
47  for (const auto& [i, j]: nzs) {
48  int it = compute_index(i, start, nnode, nodes, layer);
49  int jt = compute_index(j, start, nnode, nodes, layer);
50  if (it != 0 && jt != 0) {
51  pm_.emplace_back(i, j);
52  ptree_.emplace_back(spGetElement(_nt->_sp13mat, it, jt));
53  }
54  }
55 }
void add(double fac)
Definition: matrixmap.cpp:20
void mmfree()
Definition: matrixmap.cpp:13
void alloc(int, int, Node **, int *)
Definition: matrixmap.cpp:40
int compute_index(int, int, int, Node **, int *) const
Definition: matrixmap.cpp:27
std::vector< std::pair< int, int > > pm_
Definition: matrixmap.h:118
MatrixMap(Matrix *)
Definition: matrixmap.cpp:10
std::vector< double * > ptree_
Definition: matrixmap.h:119
Matrix & m_
Definition: matrixmap.h:115
virtual std::vector< std::pair< int, int > > nonzeros() const
Definition: ocmatrix.cpp:41
#define extnode
Definition: md1redef.h:16
#define i
Definition: md1redef.h:19
spREAL * spGetElement(char *, int, int)
Definition: spbuild.cpp:151
NrnThread * nrn_threads
Definition: multicore.cpp:56
size_t j
Definition: section.h:105
int eqn_index_
Definition: section.h:187
Represent main neuron object computed by single thread.
Definition: multicore.h:58
char * _sp13mat
Definition: multicore.h:94