1 #ifndef __CS_SLES_MUMPS_H__ 2 #define __CS_SLES_MUMPS_H__ 3 4 /*============================================================================ 5 * Sparse Linear Equation Solvers using MUMPS (a sparse direct solver library) 6 *============================================================================*/ 7 8 /* 9 This file is part of Code_Saturne, a general-purpose CFD tool. 10 11 Copyright (C) 1998-2021 EDF S.A. 12 13 This program is free software; you can redistribute it and/or modify it under 14 the terms of the GNU General Public License as published by the Free Software 15 Foundation; either version 2 of the License, or (at your option) any later 16 version. 17 18 This program is distributed in the hope that it will be useful, but WITHOUT 19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 20 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 21 details. 22 23 You should have received a copy of the GNU General Public License along with 24 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin 25 Street, Fifth Floor, Boston, MA 02110-1301, USA. 26 */ 27 28 /*----------------------------------------------------------------------------*/ 29 30 /*---------------------------------------------------------------------------- 31 * MUMPS headers 32 *----------------------------------------------------------------------------*/ 33 34 #include <dmumps_c.h> 35 #include <smumps_c.h> 36 37 /*---------------------------------------------------------------------------- 38 * Local headers 39 *----------------------------------------------------------------------------*/ 40 41 #include "cs_base.h" 42 #include "cs_halo_perio.h" 43 #include "cs_matrix.h" 44 #include "cs_param_sles.h" 45 #include "cs_time_plot.h" 46 #include "cs_sles.h" 47 48 /*----------------------------------------------------------------------------*/ 49 50 BEGIN_C_DECLS 51 52 /*============================================================================ 53 * Macro definitions 54 *============================================================================*/ 55 56 #define CS_SLES_MUMPS_JOB_INIT -1 57 58 /* Set of macros defined in order to match MUMPS documentation (because of the 59 * difference between C/FORTRAN programming language 60 */ 61 #define ICNTL(I) icntl[(I)-1] 62 #define CNTL(I) cntl[(I)-1] 63 #define INFOG(I) infog[(I)-1] 64 #define INFO(I) info[(I)-1] 65 #define RINFOG(I) rinfog[(I)-1] 66 #define RINFO(I) rinfo[(I)-1] 67 68 /*============================================================================ 69 * Type definitions 70 *============================================================================*/ 71 72 /*----------------------------------------------------------------------------*/ 73 /*! 74 * \brief Function pointer for user settings of a MUMPS solver. 75 * This function is called at the end of the setup stage. 76 * 77 * Note: if the context pointer is non-NULL, it must point to valid data 78 * when the selection function is called so that value or structure should 79 * not be temporary (i.e. local); 80 * 81 * \param[in] slesp pointer to the related cs_param_sles_t structure 82 * \param[in, out] context pointer to optional (untyped) value or structure 83 * \param[in, out] dmumps pointer to DMUMPS_STRUC_C (double-precision) 84 * \param[in, out] smumps pointer to SMUMPS_STRUC_C (single-precision) 85 */ 86 /*----------------------------------------------------------------------------*/ 87 88 typedef void 89 (cs_sles_mumps_setup_hook_t) (const cs_param_sles_t *slesp, 90 void *context, 91 DMUMPS_STRUC_C *dmumps, 92 SMUMPS_STRUC_C *smumps); 93 94 /* MUMPS solver context (opaque) */ 95 96 typedef struct _cs_sles_mumps_t cs_sles_mumps_t; 97 98 /*============================================================================ 99 * Global variables 100 *============================================================================*/ 101 102 /*============================================================================= 103 * User function prototypes 104 *============================================================================*/ 105 106 /*----------------------------------------------------------------------------*/ 107 /*! 108 * \brief Function pointer for user settings of a MUMPS solver. 109 * This function is called at the end of the setup stage. 110 * 111 * Note: if the context pointer is non-NULL, it must point to valid data 112 * when the selection function is called so that structure should 113 * not be temporary (i.e. local); 114 * 115 * \param[in] slesp pointer to the related cs_param_sles_t structure 116 * \param[in, out] context pointer to optional (untyped) value or structure 117 * \param[in, out] dmumps pointer to DMUMPS_STRUC_C (double-precision) 118 * \param[in, out] smumps pointer to SMUMPS_STRUC_C (single-precision) 119 */ 120 /*----------------------------------------------------------------------------*/ 121 122 void 123 cs_user_sles_mumps_hook(const cs_param_sles_t *slesp, 124 void *context, 125 DMUMPS_STRUC_C *dmumps, 126 SMUMPS_STRUC_C *smumps); 127 128 /*============================================================================= 129 * Public function prototypes 130 *============================================================================*/ 131 132 /*----------------------------------------------------------------------------*/ 133 /*! 134 * \brief Define and associate a MUMPS linear system solver for a given field 135 * or equation name. 136 * 137 * If this system did not previously exist, it is added to the list of 138 * "known" systems. Otherwise, its definition is replaced by the one 139 * defined here. 140 * 141 * This is a utility function: if finer control is needed, see 142 * \ref cs_sles_define and \ref cs_sles_mumps_create. 143 * 144 * Note that this function returns a pointer directly to the sparse direct 145 * solver management structure. This may be used to set further options. 146 * If needed, \ref cs_sles_find may be used to obtain a pointer to the matching 147 * \ref cs_sles_t container. 148 * 149 * \param[in] f_id associated field id, or < 0 150 * \param[in] name associated name if f_id < 0, or NULL 151 * \param[in] slesp pointer to a cs_param_sles_t structure 152 * \param[in] setup_hook pointer to optional setup epilogue function 153 * \param[in,out] context pointer to optional (untyped) value or 154 * structure for setup_hook, or NULL 155 * 156 * \return pointer to newly created sparse direct solver info object. 157 */ 158 /*----------------------------------------------------------------------------*/ 159 160 cs_sles_mumps_t * 161 cs_sles_mumps_define(int f_id, 162 const char *name, 163 const cs_param_sles_t *slesp, 164 cs_sles_mumps_setup_hook_t *setup_hook, 165 void *context); 166 167 /*----------------------------------------------------------------------------*/ 168 /*! 169 * \brief Create MUMPS linear system solver info and context. 170 * 171 * \param[in] slesp pointer to a cs_param_sles_t structure 172 * \param[in] setup_hook pointer to optional setup epilogue function 173 * \param[in,out] context pointer to optional (untyped) value or 174 * structure for setup_hook, or NULL 175 * 176 * \return pointer to associated linear system object. 177 */ 178 /*----------------------------------------------------------------------------*/ 179 180 cs_sles_mumps_t * 181 cs_sles_mumps_create(const cs_param_sles_t *slesp, 182 cs_sles_mumps_setup_hook_t *setup_hook, 183 void *context); 184 185 /*----------------------------------------------------------------------------*/ 186 /*! 187 * \brief Create MUMPS linear system solver info and context based on existing 188 * info and context. 189 * 190 * \param[in] context pointer to reference info and context 191 * (actual type: cs_sles_mumps_t *) 192 * 193 * \return pointer to newly created solver info object. 194 * (actual type: cs_sles_mumps_t *) 195 */ 196 /*----------------------------------------------------------------------------*/ 197 198 void * 199 cs_sles_mumps_copy(const void *context); 200 201 /*----------------------------------------------------------------------------*/ 202 /*! 203 * \brief Free MUMPS linear equation solver setup context. 204 * 205 * This function frees resolution-related data, such as 206 * buffers and preconditioning but does not free the whole context, 207 * as info used for logging (especially performance data) is maintained. 208 * 209 * \param[in, out] context pointer to sparse direct solver info and context 210 * (actual type: cs_sles_mumps_t *) 211 */ 212 /*----------------------------------------------------------------------------*/ 213 214 void 215 cs_sles_mumps_free(void *context); 216 217 /*----------------------------------------------------------------------------*/ 218 /*! 219 * \brief Destroy MUMPS linear system solver info and context. 220 * 221 * \param[in, out] context pointer to sparse direct solver info and context 222 * (actual type: cs_sles_mumps_t **) 223 */ 224 /*----------------------------------------------------------------------------*/ 225 226 void 227 cs_sles_mumps_destroy(void **context); 228 229 /*----------------------------------------------------------------------------*/ 230 /*! 231 * \brief Setup MUMPS linear equation solver. 232 * 233 * \param[in, out] context pointer to sparse direct solver info and context 234 * (actual type: cs_sles_mumps_t *) 235 * \param[in] name pointer to system name 236 * \param[in] a associated matrix 237 * \param[in] verbosity associated verbosity 238 */ 239 /*----------------------------------------------------------------------------*/ 240 241 void 242 cs_sles_mumps_setup(void *context, 243 const char *name, 244 const cs_matrix_t *a, 245 int verbosity); 246 247 /*----------------------------------------------------------------------------*/ 248 /*! 249 * \brief Call MUMPS linear equation solver. 250 * 251 * \param[in, out] context pointer to sparse direct solver info and 252 * context (actual type: cs_sles_mumps_t *) 253 * \param[in] name pointer to system name 254 * \param[in] a matrix 255 * \param[in] verbosity associated verbosity 256 * \param[in] precision solver precision 257 * \param[in] r_norm residue normalization 258 * \param[out] n_iter number of "equivalent" iterations 259 * \param[out] residue residue 260 * \param[in] rhs right hand side 261 * \param[in, out] vx system solution 262 * \param[in] aux_size number of elements in aux_vectors (in bytes) 263 * \param aux_vectors optional working area 264 * (internal allocation if NULL) 265 * 266 * \return convergence state 267 */ 268 /*----------------------------------------------------------------------------*/ 269 270 cs_sles_convergence_state_t 271 cs_sles_mumps_solve(void *context, 272 const char *name, 273 const cs_matrix_t *a, 274 int verbosity, 275 double precision, 276 double r_norm, 277 int *n_iter, 278 double *residue, 279 const cs_real_t *rhs, 280 cs_real_t *vx, 281 size_t aux_size, 282 void *aux_vectors); 283 284 /*----------------------------------------------------------------------------*/ 285 /*! 286 * \brief Log sparse linear equation solver info. 287 * 288 * \param[in] context pointer to sparse direct solver info and context 289 * (actual type: cs_sles_mumps_t *) 290 * \param[in] log_type log type 291 */ 292 /*----------------------------------------------------------------------------*/ 293 294 void 295 cs_sles_mumps_log(const void *context, 296 cs_log_t log_type); 297 298 /*----------------------------------------------------------------------------*/ 299 300 END_C_DECLS 301 302 #endif /* __CS_SLES_MUMPS_H__ */ 303