UCFD_SPARSE  v1.1
Documentation
Loading...
Searching...
No Matches
inverse.c
Go to the documentation of this file.
1
30#include "inverse.h"
31
32// TODO : Bespoke code generation
33
38{
39 int row, col, kdx, nrow;
40 UCFD_FLOAT val;
41
42 if (BLOCK == 1) { // 1-equation RANS model
43 A[0] = 1.0/A[0];
44 }
45
46 else {
47 for (row=1; row<BLOCK; row++) { // Skip first row
48 nrow = BLOCK*row;
49 A[nrow] /= A[0];
50 for (col=1; col<BLOCK; col++) {
51 // Lower triangular matrix
52 if (row > col) {
53 val = 0.0;
54 for (kdx=0; kdx<col; kdx++)
55 val += A[nrow+kdx] * A[col + BLOCK*kdx];
56 A[nrow+col] = (A[nrow+col] - val)/A[(BLOCK+1)*col];
57 }
58
59 // Upper triangular matrix
60 else {
61 val = 0.0;
62 for (kdx=0; kdx<row; kdx++)
63 val += A[nrow+kdx]*A[BLOCK*kdx+col];
64 A[nrow+col] -= val;
65 }
66 }
67 }
68 }
69}
70
71
76{
77 int row, col, nrow;
78 UCFD_FLOAT val;
79
80 if (BLOCK == 1) { // 1-equation RANS model
81 b[0] *= LU[0];
82 }
83
84 else {
85 // Forward substitution
86 for (row=1; row<BLOCK; row++) {
87 nrow = row*BLOCK;
88 val = 0.0;
89 for (col=0; col<row; col++)
90 val += LU[nrow+col]*b[col];
91 b[row] -= val;
92 }
93
94 // Backward substitution
95 b[BLOCK-1] /= LU[BLOCK*BLOCK-1];
96 for (row=BLOCK-2; row>-1; row--) {
97 val = 0.0;
98 for (col=row+1; col<BLOCK; col++)
99 val += LU[nrow+col]*b[col];
100 b[row] = (b[row] - val)/LU[nrow+row];
101 }
102 }
103}
104
106{
107 int row, col, scol;
108 UCFD_FLOAT val;
109
110 if (BLOCK == 1) { // 1-equation RANS model
111 B[0] *= LU[0];
112 }
113
114 else {
115 // Forward substitution
116 for (scol=0; scol<BLOCK; scol++) B[scol*BLOCK] /= LU[0];
117 for (row=1; row<BLOCK; row++) {
118 for (scol=0; scol<BLOCK; scol++) {
119 val = 0.0;
120 for (col=0; col<row; col++)
121 val += B[scol*BLOCK+col] * LU[col*BLOCK+row];
122 B[scol*BLOCK+row] = (B[scol*BLOCK+row] - val)/LU[row*BLOCK+row];
123 }
124 }
125
126 // Backward substitution
127 for (row=BLOCK-2; row>-1; row--) {
128 for (scol=0; scol<BLOCK; scol++) {
129 val = 0.0;
130 for (col=row+1; col<BLOCK; col++)
131 val += B[scol*BLOCK+col] * LU[col*BLOCK+row];
132 B[scol*BLOCK+row] -= val;
133 }
134 }
135 }
136}
double UCFD_FLOAT
Definition: config.h:29
void lusub(UCFD_FLOAT *LU, UCFD_FLOAT *b)
Forward/Backward substitution function.
Definition: inverse.c:75
void lusubmattrans(UCFD_FLOAT *LU, UCFD_FLOAT *B)
Forward/Backward substitution for transposed matrix.
Definition: inverse.c:105
void ludcmp(UCFD_FLOAT *A)
LU Decomposition function.
Definition: inverse.c:37