Garfield++ 4.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
luc.c File Reference
#include <math.h>
#include <stdio.h>
#include "NR.h"

Go to the source code of this file.

Macros

#define TINY   1.0e-20
 

Functions

void ludcmp (double **a, int n, int *index, double *d)
 
void lubksb (double **a, int n, int *index, double *b)
 

Macro Definition Documentation

◆ TINY

#define TINY   1.0e-20

Definition at line 6 of file luc.c.

Function Documentation

◆ lubksb()

void lubksb ( double **  a,
int  n,
int *  index,
double *  b 
)

Definition at line 90 of file luc.c.

90 {
91 int i, ii = 0, ip, j;
92 double sum;
93
94 for (i = 1; i <= n; i++) /* forward substitution. */
95 {
96 ip = index[i];
97 sum = b[ip];
98 b[ip] = b[i];
99 if (ii) {
100#ifdef _OPENMP
101#pragma omp parallel for private(j) reduction(- : sum)
102#endif
103 for (j = ii; j <= i; j++) sum = sum - a[i][j] * b[j];
104 } else if (sum)
105 ii = i;
106 b[i] = sum;
107 }
108
109 for (i = n; i >= 1; i--) /* back substitution. */
110 {
111 sum = b[i];
112#ifdef _OPENMP
113#pragma omp parallel for private(j) reduction(- : sum)
114#endif
115 for (j = i + 1; j <= n; j++) sum = sum - a[i][j] * b[j];
116 b[i] = sum / a[i][i];
117 }
118}

Referenced by InvertMatrix().

◆ ludcmp()

void ludcmp ( double **  a,
int  n,
int *  index,
double *  d 
)

Definition at line 12 of file luc.c.

12 {
13 int i, j, k;
14 int imax = 1;
15 double big, sum, dum;
16 double *vv; /* vv stores the implicit scaling of each row */
17
18 vv = dvector(1, n); /* No looping yet. */
19 *d = 1.0; /* loop over rows to get implicit scaling info. */
20#ifdef _OPENMP
21#pragma omp parallel for private(j, big)
22#endif
23 for (i = 1; i <= n; i++) {
24 big = 0.0;
25 for (j = 1; j <= n; j++)
26 if (fabs(a[i][j]) > big) big = fabs(a[i][j]);
27 if (big == 0.0) nrerror("Singular matrix in routine LUDCMP");
28 vv[i] = 1.0 / big;
29 }
30
31 for (j = 1; j <= n; j++) /* outer loop of Crout's method */
32 {
33 for (i = 1; i < j; i++) {
34 sum = a[i][j];
35#ifdef _OPENMP
36#pragma omp parallel for private(k) reduction(- : sum)
37#endif
38 for (k = 1; k < i; k++) // OMPChk: parallelization may not help much
39 sum = sum - a[i][k] * a[k][j];
40 a[i][j] = sum;
41 }
42
43 big = 0.0; /* search for largest pivotal element. */
44 for (i = j; i <= n; i++) {
45 sum = a[i][j];
46#ifdef _OPENMP
47#pragma omp parallel for private(k) reduction(- : sum)
48#endif
49 for (k = 1; k < j; k++) // OMPChk: parallelization may not help much
50 sum = sum - a[i][k] * a[k][j];
51 a[i][j] = sum;
52
53 dum = vv[i] * fabs(sum);
54 if (dum >= big) { /* is the figure of merit better */
55 big = dum; /* than the best? */
56 imax = i;
57 }
58 }
59
60 if (j != imax) {
61#ifdef _OPENMP
62#pragma omp parallel for private(k, dum)
63#endif
64 for (k = 1; k <= n; k++) {
65 dum = a[imax][k];
66 a[imax][k] = a[j][k];
67 a[j][k] = dum;
68 }
69 *d = -(*d); /* change the parity of d. */
70 vv[imax] = vv[j]; /* interchange the scale factor. */
71 }
72 index[j] = imax;
73 if (a[j][j] == 0.0) /* for some applications on singular */
74 a[j][j] = TINY; /* matrices, it is desirable to */
75 /* substitute TINY for zero. */
76
77 if (j != n) /* finally, divide by the pivot element. */
78 {
79 dum = 1.0 / a[j][j];
80#ifdef _OPENMP
81#pragma omp parallel for private(i) // OMPCheck: may not help much
82#endif
83 for (i = j + 1; i <= n; i++) a[i][j] = a[i][j] * dum;
84 }
85 }
86
87 free_dvector(vv, 1, n);
88}
NRGLOBAL void nrerror()
#define TINY
Definition: luc.c:6
DoubleAc fabs(const DoubleAc &f)
Definition: DoubleAc.h:615
void free_dvector(double *v, long nl, long)
Definition: nrutil.c:470
double * dvector(long nl, long nh)
Definition: nrutil.c:63

Referenced by InvertMatrix().