NEURON
lineq.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 /*LINTLIBRARY*/
3 #include "lineq.h"
4 #include <math.h>
5 
6 struct elm **rowst; /* link to first element in row */
7 struct elm **colst; /* link to a column element */
8 unsigned neqn; /* number of equations */
9 unsigned *eqord; /* row order for pivots */
10 unsigned *varord; /* column order for pivots */
11 double *rhs; /* initially- right hand side
12  finally - answer */
13 #define SMALL 0.
14 
15 int matsol(void)
16 {
17  struct elm *pivot;
18  struct elm *el;
19  struct elm *hold;
20  int i, j;
21  double max;
22 
23  /* Upper triangularization */
24  for (i=1 ; i <= neqn ; i++)
25  {
26  if (fabs((pivot = getelm(ELM0, eqord[i], varord[i]))->value) <= SMALL)
27  {
28  /* use max row element as pivot */
29  remelm(pivot);
30  max = SMALL;
31  pivot = ELM0;
32  for (el = rowst[eqord[i]] ; el != ELM0 ;
33  el = el->c_right)
34  if (fabs(el->value) > max)
35  max = fabs((pivot = el)->value);
36  if (pivot == ELM0)
37  return(0);
38  else
39  {
40  for (j = i; j<= neqn ; j++)
41  if (varord[j] == pivot->col)
42  break;
43  varord[j] = varord[i];
44  varord[i] = pivot->col;
45  }
46  }
47  /* Eliminate all elements in pivot column */
48  for (el = colst[pivot->col] ; el != ELM0 ; el = hold)
49  {
50  hold = el->r_down; /* el will be freed below */
51  if (el != pivot)
52  {
53  subrow(pivot, el);
54  remelm(el);
55  }
56  }
57  /* Remove pivot row from further upper triangle work */
58  for (el = rowst[pivot->row] ; el != ELM0 ; el = el->c_right)
59  {
60  if (el->r_up != ELM0)
61  el->r_up->r_down = el->r_down;
62  else
63  colst[el->col] = el->r_down;
64  if (el->r_down != ELM0)
65  el->r_down->r_up = el->r_up;
66  }
67  }
68  bksub();
69  return(1);
70 }
#define i
Definition: md1redef.h:19
int matsol(void)
Definition: lineq.cpp:15
#define SMALL
Definition: lineq.cpp:13
struct elm ** rowst
Definition: lineq.cpp:6
unsigned * varord
Definition: lineq.cpp:10
struct elm ** colst
Definition: lineq.cpp:7
unsigned neqn
Definition: lineq.cpp:8
unsigned * eqord
Definition: lineq.cpp:9
double * rhs
Definition: lineq.cpp:11
#define subrow
Definition: lineq.h:11
#define remelm
Definition: lineq.h:12
#define getelm
Definition: lineq.h:8
#define ELM0
Definition: lineq.h:27
#define bksub
Definition: lineq.h:9
fabs
Definition: extdef.h:3
size_t j
static uint32_t value
Definition: scoprand.cpp:25
Definition: lineq.h:17
double value
Definition: lineq.h:20
unsigned col
Definition: lineq.h:19
struct elm * c_right
Definition: lineq.h:24
struct elm * r_up
Definition: lineq.h:21
unsigned row
Definition: lineq.h:18
struct elm * r_down
Definition: lineq.h:22