9.2
general documentation
cs_cdo_system.h
Go to the documentation of this file.
1#ifndef CS_CDO_SYSTEM_H
2#define CS_CDO_SYSTEM_H
3
4/*============================================================================
5 * Structure and functions used to manipulate elementary structures related to
6 * the definition/usage of linear systems (objects manipulated with this
7 * structure are matrices, matrix strcutures and assemblers, range set and
8 * interface set for parallel synchronization/operations)
9 *============================================================================*/
10
11/*
12 This file is part of code_saturne, a general-purpose CFD tool.
13
14 Copyright (C) 1998-2026 EDF S.A.
15
16 This program is free software; you can redistribute it and/or modify it under
17 the terms of the GNU General Public License as published by the Free Software
18 Foundation; either version 2 of the License, or (at your option) any later
19 version.
20
21 This program is distributed in the hope that it will be useful, but WITHOUT
22 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
23 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
24 details.
25
26 You should have received a copy of the GNU General Public License along with
27 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
28 Street, Fifth Floor, Boston, MA 02110-1301, USA.
29*/
30
31/*----------------------------------------------------------------------------*/
32
33#include "base/cs_defs.h"
34
35/*----------------------------------------------------------------------------
36 * Standard C library headers
37 *----------------------------------------------------------------------------*/
38
39/*----------------------------------------------------------------------------
40 * Local headers
41 *----------------------------------------------------------------------------*/
42
43#include "alge/cs_matrix.h"
45#include "base/cs_param_types.h"
46#include "base/cs_range_set.h"
47#include "cdo/cs_cdo_assembly.h"
48#include "cdo/cs_cdo_connect.h"
49
50/*============================================================================
51 * Macro definitions
52 *============================================================================*/
53
54/*============================================================================
55 * Type definitions
56 *============================================================================*/
57
58typedef enum {
59
65
87typedef enum {
88
93
95
97
115typedef enum {
116
121
123
125
126
127typedef struct {
128
129 /* If the block is associated to one or several matrices, one keeps
130 * the information about the class of the matrix
131 */
132
134
135 /* An element is for instance a vertex, edge, face or cell */
136
139 int stride;
141 /* Description how is stored the matrix values for this block.
142 *
143 * When stride > 1, there are several options to store the matrix
144 * (all possibilities are not available up to now)
145 *
146 * unrolled: True means that a vector-valued DoF for instance is treated as
147 * a scalar-valued DoF which is three times larger.
148 *
149 * interlaced: True means that a vector-valued DoF is stored as follows:
150 * U0x U0y U0z U1x U1y U1z ... UNx UNy UNz
151 * false means that its representation is as follows:
152 * U0x U1x ... UNx U0y U1y ... UNy U0z U1z ... UNz
153 */
154
157
159
160
170typedef struct {
171
172 /*
173 * \var matrix
174 * matrix of the system to solve
175 *
176 * \var matrix_class
177 * class of the matrix
178 *
179 * \var mav
180 * structure to manage the assembly of matrix values
181 *
182 * \var assembly_func
183 * function pointer to operate the assembly stage
184 *
185 * \var slave_assembly_func
186 * function pointer to operate the assembly stage when the system helper
187 * is declared as slave (this is the same for all matrices). Useful for
188 * coupled systems.
189 */
190
195
196 /* The following structures can be shared if the same block configuration
197 is requested */
198
203
205
206
214typedef struct {
215
216 /*
217 * \var n_matrices
218 * number of matrices to consider
219 *
220 * \var matrices
221 * matrix of the system to solve (the matrix id in the list of matrices
222 * corresponding to the matrix at row i and column j is i*n_matrices+j)
223 *
224 * \var mav_array
225 * array of structures to manage the assembly of matrix values
226 *
227 * \var assembly_func
228 * function pointer to operate the assembly stage (this is the same for
229 * all matrices)
230 *
231 * \var slave_assembly_func
232 * function pointer to operate the assembly stage when the system helper
233 * is declared as slave (this is the same for all matrices)
234 */
235
241
242 /* The two following structures are always shared. They correspond to the
243 scalar-valued version. */
244
247
251
253
262typedef struct {
263
282
284
285 /* The following structures can be shared if the same block configuration is
286 requested. In this case, shared_structures is set to true. By default,
287 there is no sharing. */
288
292
294
295
303typedef struct {
304
305 /*
306 * \var matrix
307 * matrix of the system to solve
308 *
309 * \var mav
310 * structure to manage the assembly of matrix values
311 */
312
315
316 /* Private structures */
317
322
324
325
331typedef struct {
332
333 /* \var info
334 * Set of metadata to describe the block
335 */
336
338
350
351 bool owner;
352
353 int id;
354
362
364
373typedef struct {
374
411
415
417 cs_real_t *rhs; /* shared */
418 cs_real_t *_rhs; /* private */
420
423
425
426/*============================================================================
427 * Inline public function prototypes
428 *============================================================================*/
429
430/*----------------------------------------------------------------------------*/
438/*----------------------------------------------------------------------------*/
439
442{
443 switch (solver_class) {
444
447 break;
448
450#if defined(HAVE_HYPRE)
452#else
454#endif
455 break;
456
457 default:
459 break;
460
461 }
462}
463
464/*----------------------------------------------------------------------------*/
476/*----------------------------------------------------------------------------*/
477
480 int block_id)
481{
482 if (sh == NULL)
484 if (block_id < 0 || block_id >= sh->n_blocks)
486
487 cs_cdo_system_block_t *b = sh->blocks[block_id];
488
489 assert(b != NULL);
490 return b->info.matrix_class;
491}
492
493/*============================================================================
494 * Public function prototypes
495 *============================================================================*/
496
497/*----------------------------------------------------------------------------*/
505/*----------------------------------------------------------------------------*/
506
507void
509 cs_cdo_connect_t *connect);
510
511/*----------------------------------------------------------------------------*/
524/*----------------------------------------------------------------------------*/
525
528 int n_col_blocks,
529 const cs_lnum_t *col_block_sizes,
530 int n_blocks);
531
532/*----------------------------------------------------------------------------*/
548/*----------------------------------------------------------------------------*/
549
552 int block_id,
554 cs_flag_t location,
555 cs_lnum_t n_elements,
556 int stride,
557 bool interlaced,
558 bool unrolled);
559
560/*----------------------------------------------------------------------------*/
574/*----------------------------------------------------------------------------*/
575
578 int block_id,
580 cs_flag_t location,
581 cs_lnum_t n_elements,
582 int stride);
583
584/*----------------------------------------------------------------------------*/
599/*----------------------------------------------------------------------------*/
600
603 int block_id,
604 const cs_adjacency_t *adjacency,
605 cs_flag_t location,
606 cs_lnum_t n_elements,
607 int stride,
608 bool interlaced);
609
610/*----------------------------------------------------------------------------*/
621/*----------------------------------------------------------------------------*/
622
625 int block_id,
626 cs_lnum_t n_dofs);
627
628/*----------------------------------------------------------------------------*/
637/*----------------------------------------------------------------------------*/
638
641 int block_id);
642
643/*----------------------------------------------------------------------------*/
657/*----------------------------------------------------------------------------*/
658
661 int block_id);
662
663/*----------------------------------------------------------------------------*/
677/*----------------------------------------------------------------------------*/
678
681 int block_id,
682 int sub_id);
683
684/*----------------------------------------------------------------------------*/
692/*----------------------------------------------------------------------------*/
693
694void
696 int block_id);
697
698/*----------------------------------------------------------------------------*/
706/*----------------------------------------------------------------------------*/
707
708void
710 cs_real_t **p_rhs);
711
712/*----------------------------------------------------------------------------*/
718/*----------------------------------------------------------------------------*/
719
720void
722
723/*----------------------------------------------------------------------------*/
729/*----------------------------------------------------------------------------*/
730
731void
733
734/*----------------------------------------------------------------------------*/
740/*----------------------------------------------------------------------------*/
741
742void
744
745/*----------------------------------------------------------------------------*/
750/*----------------------------------------------------------------------------*/
751
752void
754
755/*----------------------------------------------------------------------------*/
759/*----------------------------------------------------------------------------*/
760
761void
763
764#endif /* CS_CDO_SYSTEM_H */
void() cs_cdo_assembly_func_t(const cs_sdm_t *m, const cs_lnum_t *dof_ids, const cs_range_set_t *rset, cs_cdo_assembly_t *eqa, cs_matrix_assembler_values_t *mav)
Assemble a cellwise matrix into the global matrix Block or no block versions are handled.
Definition: cs_cdo_assembly.h:74
cs_range_set_t * cs_cdo_system_get_range_set(const cs_cdo_system_helper_t *sh, int block_id)
Retrieve the range set structure associated to the given block_id.
Definition: cs_cdo_system.cpp:1562
cs_cdo_system_block_t * cs_cdo_system_add_nblock(cs_cdo_system_helper_t *sh, int block_id, cs_cdo_system_matrix_class_t matclass, cs_flag_t location, cs_lnum_t n_elements, int stride)
Add a nested block definition at position "block_id" in the helper structure. Only metadata are set a...
Definition: cs_cdo_system.cpp:1268
cs_cdo_system_block_t * cs_cdo_system_add_dblock(cs_cdo_system_helper_t *sh, int block_id, cs_cdo_system_matrix_class_t matclass, cs_flag_t location, cs_lnum_t n_elements, int stride, bool interlaced, bool unrolled)
Add a default block definition at position "block_id" in the helper structure Only metadata are set a...
Definition: cs_cdo_system.cpp:1166
void cs_cdo_system_helper_free(cs_cdo_system_helper_t **p_helper)
Free a cs_cdo_system_helper_t structure.
Definition: cs_cdo_system.cpp:1123
void cs_cdo_system_helper_finalize_assembly(cs_cdo_system_helper_t *sh)
Finalize the assembly after the cellwise building and assembly.
Definition: cs_cdo_system.cpp:1981
void cs_cdo_system_init_sharing(cs_mesh_t *mesh, cs_cdo_connect_t *connect)
Allocate and initialize matrix-related structures according to the type of discretization used for th...
Definition: cs_cdo_system.cpp:1049
cs_cdo_system_block_t * cs_cdo_system_add_ublock(cs_cdo_system_helper_t *sh, int block_id, const cs_adjacency_t *adjacency, cs_flag_t location, cs_lnum_t n_elements, int stride, bool interlaced)
Add an unassembled block definition at position "block_id" in the helper structure Only metadata are ...
Definition: cs_cdo_system.cpp:1402
cs_cdo_system_block_type_t
type of block composing a (block) matrix
Definition: cs_cdo_system.h:87
@ CS_CDO_SYSTEM_BLOCK_NESTED
Definition: cs_cdo_system.h:90
@ CS_CDO_SYSTEM_N_BLOCK_TYPES
Definition: cs_cdo_system.h:94
@ CS_CDO_SYSTEM_BLOCK_DEFAULT
Definition: cs_cdo_system.h:89
@ CS_CDO_SYSTEM_BLOCK_EXTERN
Definition: cs_cdo_system.h:92
@ CS_CDO_SYSTEM_BLOCK_UNASS
Definition: cs_cdo_system.h:91
void cs_cdo_system_helper_reset(cs_cdo_system_helper_t *sh)
Free matrix and rhs after the solve step.
Definition: cs_cdo_system.cpp:2042
static cs_cdo_system_matrix_class_t cs_cdo_system_which_matrix_class(cs_param_solver_class_t solver_class)
Get the best available class of matrix knowing the solver class.
Definition: cs_cdo_system.h:441
void cs_cdo_system_allocate_assembly(void)
Initialize shared assembly structures from the existing helper structures.
Definition: cs_cdo_system.cpp:2107
cs_cdo_system_block_t * cs_cdo_system_add_xblock(cs_cdo_system_helper_t *sh, int block_id, cs_lnum_t n_dofs)
Add an external block definition at position "block_id" in the helper structure. Only metadata are se...
Definition: cs_cdo_system.cpp:1491
cs_cdo_system_helper_t * cs_cdo_system_helper_create(cs_cdo_system_type_t type, int n_col_blocks, const cs_lnum_t *col_block_sizes, int n_blocks)
Create a system_helper structure from its set of metadata. n_col_blocks and n_blocks may differ accor...
Definition: cs_cdo_system.cpp:1073
cs_cdo_system_matrix_class_t
Class of matrices to consider.
Definition: cs_cdo_system.h:115
@ CS_CDO_SYSTEM_MATRIX_HYPRE
Definition: cs_cdo_system.h:120
@ CS_CDO_SYSTEM_N_MATRIX_CLASSES
Definition: cs_cdo_system.h:122
@ CS_CDO_SYSTEM_MATRIX_NONE
Definition: cs_cdo_system.h:117
@ CS_CDO_SYSTEM_MATRIX_CS
Definition: cs_cdo_system.h:118
@ CS_CDO_SYSTEM_MATRIX_PETSC
Definition: cs_cdo_system.h:119
void cs_cdo_system_destroy_all(void)
Free all members associated to system helpers.
Definition: cs_cdo_system.cpp:2169
cs_cdo_system_type_t
Definition: cs_cdo_system.h:58
@ CS_CDO_SYSTEM_COUPLED
Definition: cs_cdo_system.h:61
@ CS_CDO_SYSTEM_SADDLE_POINT
Definition: cs_cdo_system.h:62
@ CS_CDO_SYSTEM_DEFAULT
Definition: cs_cdo_system.h:60
cs_matrix_t * cs_cdo_system_get_matrix(const cs_cdo_system_helper_t *sh, int block_id)
Retrieve the matrix associated to the given block_id. If the type of block is either CS_CDO_SYSTEM_BL...
Definition: cs_cdo_system.cpp:1628
void cs_cdo_system_helper_init_system(cs_cdo_system_helper_t *sh, cs_real_t **p_rhs)
Allocate and initialize the matrix, rhs and the matrix assembler values.
Definition: cs_cdo_system.cpp:1809
void cs_cdo_system_build_block(cs_cdo_system_helper_t *sh, int block_id)
Build the associated structures for the given system_helper structure If a member is already allocate...
Definition: cs_cdo_system.cpp:1721
cs_matrix_t * cs_cdo_system_get_sub_matrix(cs_cdo_system_helper_t *sh, int block_id, int sub_id)
Retrieve the (sub-)matrix associated to a split block with id equal to block_id. sub_id is the id in ...
Definition: cs_cdo_system.cpp:1680
static cs_cdo_system_matrix_class_t cs_cdo_system_get_matrix_class(const cs_cdo_system_helper_t *sh, int block_id)
Get the matrix class related to the given block_id CS_CDO_SYSTEM_MATRIX_NONE is returned if not store...
Definition: cs_cdo_system.h:479
double cs_real_t
Floating-point value.
Definition: cs_defs.h:332
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:325
unsigned short int cs_flag_t
Definition: cs_defs.h:334
struct _cs_interface_set_t cs_interface_set_t
Definition: cs_interface.h:57
struct _cs_matrix_structure_t cs_matrix_structure_t
Definition: cs_matrix.h:104
struct _cs_matrix_t cs_matrix_t
Definition: cs_matrix.h:108
struct _cs_matrix_assembler_t cs_matrix_assembler_t
Definition: cs_matrix_assembler.h:61
struct _cs_matrix_assembler_values_t cs_matrix_assembler_values_t
Definition: cs_matrix_assembler.h:65
cs_param_solver_class_t
Class of iterative solvers to consider for solver the linear system.
Definition: cs_param_types.h:752
@ CS_PARAM_SOLVER_CLASS_CS
Definition: cs_param_types.h:754
@ CS_PARAM_SOLVER_CLASS_HYPRE
Definition: cs_param_types.h:755
Definition: mesh.f90:26
Definition: cs_mesh_adjacencies.h:68
Definition: cs_cdo_connect.h:57
Definition: cs_cdo_system.h:127
int stride
Definition: cs_cdo_system.h:139
cs_cdo_system_matrix_class_t matrix_class
Definition: cs_cdo_system.h:133
cs_flag_t location
Definition: cs_cdo_system.h:137
bool interlaced
Definition: cs_cdo_system.h:156
cs_lnum_t n_elements
Definition: cs_cdo_system.h:138
bool unrolled
Definition: cs_cdo_system.h:155
Definition: cs_cdo_system.h:331
void * block_pointer
Definition: cs_cdo_system.h:361
cs_cdo_system_block_info_t info
Definition: cs_cdo_system.h:337
cs_cdo_system_block_type_t type
Definition: cs_cdo_system.h:349
int id
Definition: cs_cdo_system.h:353
bool owner
Definition: cs_cdo_system.h:351
Structure associated to the default type of block.
Definition: cs_cdo_system.h:170
cs_matrix_t * matrix
Definition: cs_cdo_system.h:191
cs_cdo_assembly_func_t * slave_assembly_func
Definition: cs_cdo_system.h:194
cs_interface_set_t * interface_set
Definition: cs_cdo_system.h:200
cs_matrix_assembler_values_t * mav
Definition: cs_cdo_system.h:192
cs_range_set_t * range_set
Definition: cs_cdo_system.h:199
cs_matrix_assembler_t * matrix_assembler
Definition: cs_cdo_system.h:201
cs_cdo_assembly_func_t * assembly_func
Definition: cs_cdo_system.h:193
cs_matrix_structure_t * matrix_structure
Definition: cs_cdo_system.h:202
Definition: cs_cdo_system.h:373
cs_real_t ** rhs_array
Definition: cs_cdo_system.h:419
cs_lnum_t * col_block_sizes
Definition: cs_cdo_system.h:413
cs_cdo_system_type_t type
Definition: cs_cdo_system.h:410
cs_cdo_system_block_t ** blocks
Definition: cs_cdo_system.h:422
cs_lnum_t full_rhs_size
Definition: cs_cdo_system.h:416
cs_lnum_t * max_col_block_sizes
Definition: cs_cdo_system.h:414
cs_real_t * _rhs
Definition: cs_cdo_system.h:418
int n_col_blocks
Definition: cs_cdo_system.h:412
cs_real_t * rhs
Definition: cs_cdo_system.h:417
int n_blocks
Definition: cs_cdo_system.h:421
Structure associated to the nested type of block.
Definition: cs_cdo_system.h:214
bool matrix_struct_ownership
Definition: cs_cdo_system.h:248
cs_cdo_assembly_func_t * slave_assembly_func
Definition: cs_cdo_system.h:240
cs_interface_set_t * interface_set
Definition: cs_cdo_system.h:246
int n_matrices
Definition: cs_cdo_system.h:236
cs_matrix_assembler_values_t ** mav_array
Definition: cs_cdo_system.h:238
cs_matrix_t ** matrices
Definition: cs_cdo_system.h:237
cs_range_set_t * range_set
Definition: cs_cdo_system.h:245
cs_matrix_assembler_t * matrix_assembler
Definition: cs_cdo_system.h:249
cs_cdo_assembly_func_t * assembly_func
Definition: cs_cdo_system.h:239
cs_matrix_structure_t * matrix_structure
Definition: cs_cdo_system.h:250
Structure associated to the unassembled type of block.
Definition: cs_cdo_system.h:262
bool shared_structures
Definition: cs_cdo_system.h:289
const cs_adjacency_t * adjacency
Definition: cs_cdo_system.h:283
cs_real_t * values
Definition: cs_cdo_system.h:280
cs_real_t * _values
Definition: cs_cdo_system.h:281
cs_interface_set_t * interface_set
Definition: cs_cdo_system.h:291
cs_range_set_t * range_set
Definition: cs_cdo_system.h:290
Structure associated to the extended type of block.
Definition: cs_cdo_system.h:303
cs_matrix_t * matrix
Definition: cs_cdo_system.h:313
cs_interface_set_t * interface_set
Definition: cs_cdo_system.h:319
cs_matrix_assembler_values_t * mav
Definition: cs_cdo_system.h:314
cs_range_set_t * range_set
Definition: cs_cdo_system.h:318
cs_matrix_assembler_t * matrix_assembler
Definition: cs_cdo_system.h:320
cs_matrix_structure_t * matrix_structure
Definition: cs_cdo_system.h:321
Definition: cs_mesh.h:85
Definition: cs_range_set.h:53