@@ -18,48 +18,43 @@ void MatrixMap::mmfree() {
18
18
}
19
19
20
20
void MatrixMap::add (double fac) {
21
- for (int i = 0 ; i < plen_; ++i) {
22
- *ptree_[i] += fac * (*pm_[i]);
21
+ NrnThread* _nt = nrn_threads;
22
+ for (int i = 0 ; i < pm_.size (); ++i) {
23
+ auto [im, jm] = pm_[i];
24
+ auto [it, jt] = ptree_[i];
25
+ *_nt->_sp13mat ->mep (it, jt) += fac * m_.getval (im, jm);
26
+ }
27
+ }
28
+
29
+ int MatrixMap::compute_id (int i, int start, int nnode, Node** nodes, int * layer) const {
30
+ int it;
31
+ if (i < nnode) {
32
+ it = nodes[i]->eqn_index_ + layer[i];
33
+ if (layer[i] > 0 && !nodes[i]->extnode ) {
34
+ it = 0 ;
35
+ }
36
+ } else {
37
+ it = start + i - nnode;
23
38
}
39
+ return it;
24
40
}
25
41
26
42
void MatrixMap::alloc (int start, int nnode, Node** nodes, int * layer) {
27
- static double place_holder = 0 ;
28
- NrnThread* _nt = nrn_threads;
29
43
mmfree ();
30
44
31
- plen_ = 0 ;
32
45
std::vector<int > nonzero_i, nonzero_j;
33
46
m_.nonzeros (nonzero_i, nonzero_j);
34
- pm_.resize (nonzero_i.size ());
35
- ptree_.resize (nonzero_i.size ());
47
+ pm_.reserve (nonzero_i.size ());
48
+ ptree_.reserve (nonzero_i.size ());
36
49
for (int k = 0 ; k < nonzero_i.size (); k++) {
37
50
const int i = nonzero_i[k];
38
51
const int j = nonzero_j[k];
39
- int it;
40
- if (i < nnode) {
41
- it = nodes[i]->eqn_index_ + layer[i];
42
- if (layer[i] > 0 && !nodes[i]->extnode ) {
43
- it = 0 ;
44
- }
45
- } else {
46
- it = start + i - nnode;
47
- }
48
- int jt;
49
- pm_[plen_] = m_.mep (i, j);
50
- if (j < nnode) {
51
- jt = nodes[j]->eqn_index_ + layer[j];
52
- if (layer[j] > 0 && !nodes[j]->extnode ) {
53
- jt = 0 ;
54
- }
55
- } else {
56
- jt = start + j - nnode;
57
- }
52
+ int it = compute_id (i, start, nnode, nodes, layer);
53
+ int jt = compute_id (j, start, nnode, nodes, layer);
58
54
if (it == 0 || jt == 0 ) {
59
- ptree_[plen_] = &place_holder;
60
- } else {
61
- ptree_[plen_] = _nt->_sp13mat ->mep (it - 1 , jt - 1 );
55
+ continue ;
62
56
}
63
- ++plen_;
57
+ pm_.emplace_back (i, j);
58
+ ptree_.emplace_back (it - 1 , jt - 1 );
64
59
}
65
60
}
0 commit comments