MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
mthrdslv.c File Reference
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include "mthrdslv.h"
Include dependency graph for mthrdslv.c:

Go to the source code of this file.

Macros

#define BIGINT   (1 << 30)
 
#define MINPIV   1.0e-8
 

Typedefs

typedef long int integer
 
typedef double doublereal
 

Functions

int naivfct (RMAT a, integer neq, integer *nzr, IMAT ri, integer *nzc, IMAT ci, NZMAT nz, integer *piv, doublereal minpiv)
 
int naivslv (RMAT a, integer neq, integer *nzc, IMAT ci, doublereal *rhs, doublereal *sol, integer *piv)
 

Macro Definition Documentation

#define BIGINT   (1 << 30)

Definition at line 71 of file mthrdslv.c.

#define MINPIV   1.0e-8

Definition at line 73 of file mthrdslv.c.

Referenced by naivfct().

Typedef Documentation

typedef double doublereal

Definition at line 63 of file mthrdslv.c.

typedef long int integer

Definition at line 62 of file mthrdslv.c.

Function Documentation

int naivfct ( RMAT  a,
integer  neq,
integer nzr,
IMAT  ri,
integer nzc,
IMAT  ci,
NZMAT  nz,
integer piv,
doublereal  minpiv 
)

Definition at line 76 of file mthrdslv.c.

References grad::fabs(), MINPIV, NAIVE_ENOPIV, NAIVE_ENULCOL, NAIVE_ERANGE, and NAIVE_MAX.

Referenced by NaiveSolver::Factor().

79 {
80  char todo[neq];
81  integer i, j, k, pvr, pvc, nr, nc, r;
82  integer *pri, *pci;
83  char *prik;
84  doublereal den, mul, mulpiv, fari;
85 #if 0
86  doublereal fapvr;
87 #endif
88  doublereal *par, *papvr;
89 
90  if (neq <= 0 || (unsigned long)neq > NAIVE_MAX) {
91  return NAIVE_ERANGE;
92  }
93 
94  if (!minpiv) {
95  minpiv = MINPIV;
96  }
97  for (pvr = 0; pvr < neq; pvr++) {
98  todo[pvr] = 1;
99  }
100  for (i = 0; i < neq; i++) {
101  if (!nzr[i]) { return NAIVE_ENULCOL + i; }
102  nc = neq + 1;
103  nr = nzr[i];
104  mul = 0.0;
105  pri = ri[i];
106  pvr = pri[0];
107  mulpiv = 0.;
108 #if 0
109  fapvr = 0.;
110  for (k = 0; k < nr; k++) {
111  r = pri[k];
112  if (todo[r]) {
113  fari = fabs(a[r][i]);
114  if (fari > mul) {
115  mulpiv = fari*minpiv;
116  if (nzc[r] <= nc || mulpiv > fapvr) {
117  nc = nzc[pvr = r];
118  fapvr = fari;
119  }
120  mul = fari;
121  } else if (nzc[r] < nc && fari > mulpiv) {
122  nc = nzc[pvr = r];
123  }
124  }
125  }
126 #endif
127  for (k = 0; k < nr; k++) {
128  r = pri[k];
129  if (todo[r]) {
130  fari = fabs(a[r][i]);
131  if (fari > mul) {
132  mul = fari;
133  }
134  }
135  }
136  mulpiv = mul*minpiv;
137  for (k = 0; k < nr; k++) {
138  r = pri[k];
139  if (todo[r]) {
140  fari = fabs(a[r][i]);
141  if (fari >= mulpiv && nzc[r] < nc) {
142  nc = nzc[pvr = r];
143  }
144  }
145  }
146  if (nc == neq + 1) { return NAIVE_ENOPIV + i; }
147  if (mulpiv == 0.) { return NAIVE_ENOPIV + i; }
148 
149  piv[i] = pvr;
150  todo[pvr] = 0;
151  papvr = a[pvr];
152  den = papvr[i] = 1.0/papvr[i];
153 
154  for (k = 0; k < nr; k++) {
155  if (!todo[r = pri[k]]) { continue; }
156  par = a[r];
157  mul = par[i] = par[i]*den;
158  prik = nz[r];
159  pci = ci[pvr];
160  for (j = 0; j < nc; j++) {
161  if ((pvc = pci[j]) <= i) { continue; }
162  if (prik[pvc]) {
163  par[pvc] -= mul*papvr[pvc];
164  } else {
165  par[pvc] = -mul*papvr[pvc];
166  prik[pvc] = 1;
167  ri[pvc][nzr[pvc]++] = r;
168  ci[r][nzc[r]++] = pvc;
169  }
170  }
171  }
172  }
173  return 0;
174 }
#define NAIVE_MAX
Definition: mthrdslv.h:71
GradientExpression< UnaryExpr< FuncFabs, Expr > > fabs(const GradientExpression< Expr > &u)
Definition: gradient.h:2973
#define NAIVE_ERANGE
Definition: mthrdslv.h:75
#define MINPIV
Definition: mthrdslv.c:73
#define NAIVE_ENOPIV
Definition: mthrdslv.h:74
#define NAIVE_ENULCOL
Definition: mthrdslv.h:73
static const doublereal a
Definition: hfluid_.h:289
double doublereal
Definition: colamd.c:52
long int integer
Definition: colamd.c:51

Here is the call graph for this function:

int naivslv ( RMAT  a,
integer  neq,
integer nzc,
IMAT  ci,
doublereal rhs,
doublereal sol,
integer piv 
)

Definition at line 190 of file mthrdslv.c.

References c, NAIVE_ERANGE, and NAIVE_MAX.

Referenced by NaiveSolver::Solve().

193 {
194  doublereal fwd[neq];
195 
196  integer i, k, nc, r, c;
197  integer *pci;
198  doublereal s;
199  doublereal *par;
200 
201  if (neq <= 0 || (unsigned long)neq > NAIVE_MAX) {
202  return NAIVE_ERANGE;
203  }
204 
205  fwd[0] = rhs[piv[0]];
206  for (i = 1; i < neq; i++) {
207  nc = nzc[r = piv[i]];
208  s = rhs[r];
209  par = a[r];
210  pci = ci[r];
211  for (k = 0; k < nc; k++) {
212  if ((c = pci[k]) < i) {
213  s -= par[c]*fwd[c];
214  }
215  }
216  fwd[i] = s;
217  }
218 
219  r = piv[--neq];
220  sol[neq] = fwd[neq]*a[r][neq];
221  for (i = neq - 1; i >= 0; i--) {
222  nc = nzc[r = piv[i]];
223  s = fwd[i];
224  par = a[r];
225  pci = ci[r];
226  for (k = 0; k < nc; k++) {
227  if ((c = pci[k]) > i) {
228  s -= par[c]*sol[c];
229  }
230  }
231  sol[i] = s*par[i];
232  }
233 
234  return 0;
235 }
#define NAIVE_MAX
Definition: mthrdslv.h:71
#define NAIVE_ERANGE
Definition: mthrdslv.h:75
static std::stack< cleanup * > c
Definition: cleanup.cc:59
static const doublereal a
Definition: hfluid_.h:289
double doublereal
Definition: colamd.c:52
long int integer
Definition: colamd.c:51