SNOWPACK  SNOWPACK-3.6.0
Solver.h
Go to the documentation of this file.
1 /* **********************************************************************************************/
2 /* stand-alone */
3 /* Derived from RESEARCH VERSION 9.0 */
4 /* **********************************************************************************************/
5 /* **********************************************************************************/
6 /* Copyright WSL Institute for Snow and Avalanche Research SLF-DAVOS */
7 /* **********************************************************************************/
8 /* This file is part of Snowpack.
9  Snowpack is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  Snowpack is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with Snowpack. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #ifndef SOLVER_H
24 #define SOLVER_H
25 
26 #include <cstddef> //needed for size_t
27 
57 typedef struct
58 {
59  int nChunks;
61  char **pChunks;
64 
65 typedef struct
66 {
67  int Row0;
68  int Row1;
69  size_t nCol;
70  int nColBlock;
71  int iColBlock;
72  int iFloat;
74 
75 typedef struct
76 {
77  size_t Dim;
78  int *pPerm;
79  int nRowBlock;
81  int nColBlock;
85  int *pBlockJump;
86  int SizeUpper;
87  double *pUpper;
89 
90 typedef struct SD_COL_DATA
91 {
92  size_t Col;
93  struct SD_COL_DATA *Next;
94 } SD_COL_DATA;
95 
96 typedef struct SD_ROW_DATA
97 {
99 } SD_ROW_DATA;
100 
101 typedef struct
102 {
103  size_t nRow;
104  int *pPerm;
105  int *pPermInv;
108 
112  int nFreeCol;
113  size_t nCol;
115 
116 typedef struct SD_COL_BLOCK_DATA
117 {
118  size_t Col0, Col1;
121 
122 typedef union
123 {
125  struct
126  {
127  int Row0;
128  int Row1;
129  } Any;
130  struct
131  {
132  int Row0;
133  int Row1;
135  } Data;
137 
138 typedef struct
139 {
140  size_t nRow;
141  int *pPerm;
142 
149 
160 
161 typedef struct
162 {
163  int nEq;
165 
167  union
171  } Mat;
173 
174 typedef enum SD_MATRIX_WHAT
175 {
176  /*
177  * For symbolically factorizing and optimizing the structure of the [L] and [U] matrices
178  * after the connectivity of the matrix [A] has been defined by calling
179  * ds_DefineConnectivity (...)
180  */
182  /*
183  * For numerically factorizing the matrix [A] = [L][U] in to the lower resp. upper
184  * triangular matrices [L] resp. [U] after [A] has been symbolically factorized by calling
185  * ds_Solve(SymbolicFactorize,...) and assembled by calling ds_AssemblLocalMatrix(...) for
186  * each element.
187  */
189  /*
190  * For solving for a new right hand side load vector {B} after the matrix [A] has been
191  * numerically factorized by calling ds_Solve(NumericFactorize,...)
192  */
194  /*
195  * For both numerically factorizing the matrix [A] and solving for a 1st right hand side
196  * vector {B} i.e. is equivalent to the calls ds_Solve(NumericFactorize,...) &
197  * ds_Solve(BackForwardSubst,...)
198  */
200  /*
201  * For resetting all real coefficients of the matrix [A] to zero before reassembling a new
202  * matrix [A] with identical connectivity by calling ds_AssembleLocalMatrix(...) with
203  * changed local element matrices [ElMat] but the same element equations list Eq[...]
204  */
206  /*
207  * For releasing all storage space needed for solving the current problem defined by the
208  * data pointed to by *pMat
209  */
211 
213 
215 //functions that are really used
216 
259 int ds_DefineConnectivity( SD_MATRIX_DATA *const pMat0, const int& nEq, int Eq[], const int& nEl, const int& Dim );
260 
281 int ds_Initialize( const size_t& MatDim, SD_MATRIX_DATA **ppMat );
282 
310 int ds_AssembleMatrix( SD_MATRIX_DATA *pMat0, const int& nEq, int Eq[], const int& Dim, const double *ElMat );
311 
317 int ds_Solve( const SD_MATRIX_WHAT& Code, SD_MATRIX_DATA *pMat, double *pX );
318 
321 #endif
int * pPerm
Definition: Solver.h:78
Definition: Solver.h:116
int Row0
Definition: Solver.h:67
int nEq
Definition: Solver.h:163
char ** pChunks
Definition: Solver.h:61
Definition: Solver.h:210
SD_CHUNK_DATA PoolCol
Definition: Solver.h:110
int ds_DefineConnectivity(SD_MATRIX_DATA *const pMat0, const int &nEq, int Eq[], const int &nEl, const int &Dim)
This function is needed for defining the system (matrix) connectivity i.e. the non-zero coefficients ...
Definition: Solver.cc:1884
int ds_Initialize(const size_t &MatDim, SD_MATRIX_DATA **ppMat)
This is the first function to be called prior to begin to work with any matrix. The user must gives t...
Definition: Solver.cc:422
int ds_Solve(const SD_MATRIX_WHAT &Code, SD_MATRIX_DATA *pMat, double *pX)
Definition: Solver.cc:546
int * pPerm
Definition: Solver.h:104
StateType State
Definition: Solver.h:166
int * pBlockJump
Definition: Solver.h:85
The CHUNK_DATA is used to keep track of allocated memory chunks ( block of memory )...
Definition: Solver.h:57
size_t Col1
Definition: Solver.h:118
size_t Dim
Definition: Solver.h:77
The data structure to store the matrix for numerical factorization is a simple one. The matrix structure is after the mmd sorting algorithm and the symbolic factorization mainly composed of clustered non-zero matrix coefficients which form blocks. In this case we use a data strucutre to represent these row and column blocks. NOTE: The row blocks are simply what in the literature is specified as supernodes. We have kept the data structure as simple as possible to minimize the numerical operations and so the execution time. NOTE: When we define a system we have the possibility to define a multiplicity factor. This allows us to perform all initialization tasks ( input of incidences, symbolic factorization, block format calculation ) with all indices modulo the multiplicity factor to save time and memory. Thus the computed block format is always the same for any specified multiplicity factor only the block bounds are different. ATTENTION: The size of the permutation vector is only Dim/(Multiplicity Factor).
Definition: Solver.h:65
SD_MATRIX_WHAT
Definition: Solver.h:174
int nColBlock
Definition: Solver.h:81
int nColBlock
Definition: Solver.h:70
struct SD_COL_BLOCK_DATA * Next
Definition: Solver.h:119
int ds_AssembleMatrix(SD_MATRIX_DATA *pMat0, const int &nEq, int Eq[], const int &Dim, const double *ElMat)
This function assemble the element square matrix [ElMat] for one element with nEq*M x nEq*M real coef...
Definition: Solver.cc:630
int nDeletedEq
Definition: Solver.h:164
int Row1
Definition: Solver.h:68
SD_ROW_BLOCK_DATA * pRowBlock
Definition: Solver.h:80
int * pPerm
Definition: Solver.h:141
SD_TMP_CON_MATRIX_DATA TmpCon
Definition: Solver.h:169
Definition: Solver.h:96
int nChunks
Definition: Solver.h:59
int nFreeCol
Definition: Solver.h:112
Definition: Solver.h:181
Definition: Solver.h:205
double * pUpper
Definition: Solver.h:87
Definition: Solver.h:138
int ReleaseBlockMatrix(SD_BLOCK_MATRIX_DATA *pMat)
Release all the data allocated for the numerical factorization algorithm.
Definition: Solver.cc:1860
Definition: Solver.h:188
Definition: Solver.h:199
SD_COL_DATA * FreeCol
Definition: Solver.h:111
SD_ROW_BLOCK_DATA UnusedData
Definition: Solver.h:124
Definition: Solver.h:75
struct SD_COL_DATA * Next
Definition: Solver.h:93
int SizeBlockJump
Definition: Solver.h:84
int iColBlock
Definition: Solver.h:71
SD_ROW_DATA * pRow
Definition: Solver.h:109
int * pSizeColBlock
Definition: Solver.h:83
SD_COL_BLOCK_DATA * FreeColBlock
Definition: Solver.h:147
int iFloat
Definition: Solver.h:72
int * pSupernode
Definition: Solver.h:107
StateType
Definition: Solver.h:159
int Row1
Definition: Solver.h:128
int * pPermInv
Definition: Solver.h:105
SD_CHUNK_DATA PoolColBlock
Definition: Solver.h:146
SD_COL_BLOCK_DATA * ColBlock
Definition: Solver.h:134
int nSupernode
Definition: Solver.h:106
size_t Col
Definition: Solver.h:92
int TotChunkSize
Definition: Solver.h:62
int SizeUpper
Definition: Solver.h:86
SD_CON_MATRIX_DATA Con
Definition: Solver.h:168
int ReleaseConMatrix(SD_CON_MATRIX_DATA *pMat)
Definition: Solver.cc:407
size_t nRow
Definition: Solver.h:103
Definition: Solver.h:159
int * pFirstColBlock
Definition: Solver.h:82
When the user define a matrix, the software return a pointer to an opaque type i.e. a pointer to void as index to reference the matrix. This pointer is actually the pointer to the SD_MATRIX_DATA data structure. This date structure is defined as a union of differnet matrix data representations, and the type of data actually stored depend on the evolution of the algorithn.
Definition: Solver.h:161
int Row0
Definition: Solver.h:127
size_t nCol
Definition: Solver.h:69
size_t nRow
Definition: Solver.h:140
int nColBlock
Definition: Solver.h:145
int pChunksSize
Definition: Solver.h:60
Definition: Solver.h:193
int nRowBlock
Definition: Solver.h:143
Definition: Solver.h:159
SD_COL_DATA * Col
Definition: Solver.h:98
Definition: Solver.h:101
int nRowBlock
Definition: Solver.h:79
Definition: Solver.h:159
SD_BLOCK_MATRIX_DATA Block
Definition: Solver.h:170
size_t nCol
Definition: Solver.h:113
Definition: Solver.h:90
SD_TMP_ROW_BLOCK_DATA * pRowBlock
Definition: Solver.h:144
Definition: Solver.h:122