1 /* Siconos is a program dedicated to modeling, simulation and control
2  * of non smooth dynamical systems.
3  *
4  * Copyright 2021 INRIA.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17 */
18 
19 #ifndef NumericsMatrix_internal_H
20 #define NumericsMatrix_internal_H
21 
22 /*!\file NumericsMatrix_internal.h
23  * \brief non-public functions and data structures
24  */
25 
26 #include "SiconosConfig.h"
27 #include "NumericsMatrix.h"
28 
29 #if defined(__cplusplus) && !defined(BUILD_AS_CPP)
30 extern "C"
31 {
32 #endif
33 
34   /** Free the internalData of a NumericsMatrix
35    * \param m the matrix */
36   void NM_internalData_free(NumericsMatrix* m);
37 
38 
39 #ifdef WITH_UMFPACK
40 #include <umfpack.h>
41 
42 
43 #ifdef SICONOS_INT64
44 #define UMFPACKPREFIX(X) umfpack_dl ## X
45 #else
46 #define UMFPACKPREFIX(X) umfpack_di ## X
47 #endif
48 
49 #define UMFPACK_FN(X) UMFPACKPREFIX(_ ## X)
50 
51 /** \struct NM_UMFPACK_WS NumericsMatrix_internal.h
52  * Structure for holding the data UMFPACK needs
53  */
54 typedef struct {
55   void* symbolic; /**< for the symbolic analysis */
56   void* numeric;  /**< for the numerical factorization */
57   double control[UMFPACK_CONTROL]; /**< control parameters */
58   double info[UMFPACK_INFO]; /**< information from UMFPACK */
59   CS_INT* wi; /**< integer workspace, size n */
60   double* wd; /**< double workspace, size: with iterative refinement: 5n, without: n */
61   double* x; /**< solution of the problem, size n */
62 } NM_UMFPACK_WS;
63 
64   /** Get (and create if necessary) the working data for UMPFACK
65    * \param A the matrix to be factorized
66    */
67   NM_UMFPACK_WS* NM_UMFPACK_ws(NumericsMatrix* A);
68 
69   /** Free the working data for UMFPACK
70    * \param p a NSM_linear_solver_params object holding the data
71    */
72   void NM_UMFPACK_free(void* p);
73 
74   /** Display extra information about the solve
75    * \param umfpack_ws the working space of UMFPACK
76    */
77   void NM_UMFPACK_extra_display(NM_UMFPACK_WS* umfpack_ws);
78 
79   /** Factorize a matrix
80    * \param A the matrix to factorize
81    * \return the workspace containing the factorized form and other infos
82    */
83   NM_UMFPACK_WS* NM_UMFPACK_factorize(NumericsMatrix* A);
84 
85 #endif
86 
87 #ifdef WITH_SUPERLU
88 
89 typedef struct NM_SuperLU_WS NM_SuperLU_WS;
90 
91   /** Get (and create if necessary) the working data for SuperLU
92    * \param A the matrix to be factorized
93    */
94   NM_SuperLU_WS* NM_SuperLU_ws(NumericsMatrix* A);
95 
96   /** Free the working data for SuperLU
97    * \param p a NSM_linear_solver_params object holding the data
98    */
99   void NM_SuperLU_free(void* p);
100 
101   /** Display extra information about the solve
102    * \param superlu_ws the working space of SuperLU
103    */
104   void NM_SuperLU_extra_display(NM_SuperLU_WS* superlu_ws);
105 
106   /** Factorize a matrix using SuperLU
107    * \param A the matrix to factorize
108    * \return the workspace containing the factorized form and other infos
109    */
110   NM_SuperLU_WS* NM_SuperLU_factorize(NumericsMatrix* A);
111 
112   /** Solve Ax = b using SuperLU
113    * \param A the matrix
114    * \param[in,out] b on input the rhs, on output the solution
115    * \param superlu_ws the workspace for SuperLU
116    * \return the information code
117    */
118   int NM_SuperLU_solve(NumericsMatrix* A, double* b, NM_SuperLU_WS* superlu_ws);
119 
120 
121 #endif
122 
123 
124 #ifdef WITH_SUPERLU_MT
125 
126 typedef struct NM_SuperLU_MT_WS NM_SuperLU_MT_WS;
127 
128   /** Get (and create if necessary) the working data for SuperLU_MT
129    * \param A the matrix to be factorized
130    */
131   NM_SuperLU_MT_WS* NM_SuperLU_MT_ws(NumericsMatrix* A);
132 
133   /** Free the working data for SuperLU_MT
134    * \param p a NSM_linear_solver_params object holding the data
135    */
136   void NM_SuperLU_MT_free(void* p);
137 
138   /** Display extra information about the solve
139    * \param superlu_mt_ws the working space of SuperLU_MT
140    */
141   void NM_SuperLU_MT_extra_display(NM_SuperLU_MT_WS* superlu_mt_ws);
142 
143   /** Factorize a matrix using SuperLU_MT
144    * \param A the matrix to factorize
145    * \return the workspace containing the factorized form and other infos
146    */
147   NM_SuperLU_MT_WS* NM_SuperLU_MT_factorize(NumericsMatrix* A);
148 
149   /** Solve Ax = b using SuperLU_MT
150    * \param A the matrix
151    * \param[in,out] b on input the rhs, on output the solution
152    * \param superlu_mt_ws the workspace for SuperLU_MT
153    * \return the information code
154    */
155   int NM_SuperLU_MT_solve(NumericsMatrix* A, double* b, NM_SuperLU_MT_WS* superlu_mt_ws);
156 
157 
158 #endif
159 
160 
161 #ifdef WITH_MKL_PARDISO
162 
163 typedef struct NM_MKL_pardiso_WS NM_MKL_pardiso_WS;
164 
165   /** Get (and create if necessary) the working data for MKL_pardiso
166    * \param A the matrix to be factorized
167    */
168   NM_MKL_pardiso_WS* NM_MKL_pardiso_ws(NumericsMatrix* A);
169 
170   /** Free the working data for MKL_pardiso
171    * \param p a NSM_linear_solver_params object holding the data
172    */
173   void NM_MKL_pardiso_free(void* p);
174 
175   /** Display extra information about the solve
176    * \param MKL_pardiso_ws the working space of MKL_pardiso
177    */
178   void NM_MKL_pardiso_extra_display(NM_MKL_pardiso_WS* MKL_pardiso_ws);
179 
180   /** Factorize a matrix using MKL_pardiso
181    * \param A the matrix to factorize
182    * \return the workspace containing the factorized form and other infos
183    */
184   NM_MKL_pardiso_WS* NM_MKL_pardiso_factorize(NumericsMatrix* A);
185 
186   /** Solve Ax = b using MKL_pardiso
187    * \param A the matrix
188    * \param[in,out] b on input the rhs, on output the solution
189    * \param superlu_ws the workspace for MKL_pardiso
190    * \return the information code
191    */
192   int NM_MKL_pardiso_solve(NumericsMatrix* A, double* b, NM_MKL_pardiso_WS* superlu_ws);
193 
194 
195 #endif
196 
197 #if defined(__cplusplus) && !defined(BUILD_AS_CPP)
198 }
199 #endif
200 
201 #endif
202