8.3
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-2024 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 "cs_defs.h"
34
35/*----------------------------------------------------------------------------
36 * Standard C library headers
37 *----------------------------------------------------------------------------*/
38
39/*----------------------------------------------------------------------------
40 * Local headers
41 *----------------------------------------------------------------------------*/
42
43#include "cs_cdo_assembly.h"
44#include "cs_cdo_connect.h"
45#include "cs_param_types.h"
46#include "cs_matrix.h"
47#include "cs_matrix_assembler.h"
48#include "cs_range_set.h"
49
50/*----------------------------------------------------------------------------*/
51
53
54/*============================================================================
55 * Macro definitions
56 *============================================================================*/
57
58/*============================================================================
59 * Type definitions
60 *============================================================================*/
61
62typedef enum {
63
69
91typedef enum {
92
97
99
101
119typedef enum {
120
125
127
129
130
131typedef struct {
132
133 /* If the block is associated to one or several matrices, one keeps
134 * the information about the class of the matrix
135 */
136
138
139 /* An element is for instance a vertex, edge, face or cell */
140
143 int stride;
145 /* Description how is stored the matrix values for this block.
146 *
147 * When stride > 1, there are several options to store the matrix
148 * (all possibilities are not available up to now)
149 *
150 * unrolled: True means that a vector-valued DoF for instance is treated as
151 * a scalar-valued DoF which is three times larger.
152 *
153 * interlaced: True means that a vector-valued DoF is stored as follows:
154 * U0x U0y U0z U1x U1y U1z ... UNx UNy UNz
155 * false means that its representation is as follows:
156 * U0x U1x ... UNx U0y U1y ... UNy U0z U1z ... UNz
157 */
158
161
163
164
174typedef struct {
175
176 /*
177 * \var matrix
178 * matrix of the system to solve
179 *
180 * \var matrix_class
181 * class of the matrix
182 *
183 * \var mav
184 * structure to manage the assembly of matrix values
185 *
186 * \var assembly_func
187 * function pointer to operate the assembly stage
188 *
189 * \var slave_assembly_func
190 * function pointer to operate the assembly stage when the system helper
191 * is declared as slave (this is the same for all matrices). Useful for
192 * coupled systems.
193 */
194
199
200 /* The following structures can be shared if the same block configuration
201 is requested */
202
207
209
210
218typedef struct {
219
220 /*
221 * \var n_matrices
222 * number of matrices to consider
223 *
224 * \var matrices
225 * matrix of the system to solve (the matrix id in the list of matrices
226 * corresponding to the matrix at row i and column j is i*n_matrices+j)
227 *
228 * \var mav_array
229 * array of structures to manage the assembly of matrix values
230 *
231 * \var assembly_func
232 * function pointer to operate the assembly stage (this is the same for
233 * all matrices)
234 *
235 * \var slave_assembly_func
236 * function pointer to operate the assembly stage when the system helper
237 * is declared as slave (this is the same for all matrices)
238 */
239
245
246 /* The two following structures are always shared. They correspond to the
247 scalar-valued version. */
248
251
255
257
266typedef struct {
267
286
288
289 /* The following structures can be shared if the same block configuration is
290 requested. In this case, shared_structures is set to true. By default,
291 there is no sharing. */
292
296
298
299
307typedef struct {
308
309 /*
310 * \var matrix
311 * matrix of the system to solve
312 *
313 * \var mav
314 * structure to manage the assembly of matrix values
315 */
316
319
320 /* Private structures */
321
326
328
329
335typedef struct {
336
337 /* \var info
338 * Set of metadata to describe the block
339 */
340
342
354
355 bool owner;
356
357 int id;
358
366
368
377typedef struct {
378
415
419
421 cs_real_t *rhs; /* shared */
422 cs_real_t *_rhs; /* private */
424
427
429
430/*============================================================================
431 * Inline public function prototypes
432 *============================================================================*/
433
434/*----------------------------------------------------------------------------*/
442/*----------------------------------------------------------------------------*/
443
446{
447 switch (solver_class) {
448
451 break;
452
454#if defined(HAVE_HYPRE)
456#else
458#endif
459 break;
460
461 default:
463 break;
464
465 }
466}
467
468/*----------------------------------------------------------------------------*/
480/*----------------------------------------------------------------------------*/
481
484 int block_id)
485{
486 if (sh == NULL)
488 if (block_id < 0 || block_id >= sh->n_blocks)
490
491 cs_cdo_system_block_t *b = sh->blocks[block_id];
492
493 assert(b != NULL);
494 return b->info.matrix_class;
495}
496
497/*============================================================================
498 * Public function prototypes
499 *============================================================================*/
500
501/*----------------------------------------------------------------------------*/
509/*----------------------------------------------------------------------------*/
510
511void
513 cs_cdo_connect_t *connect);
514
515/*----------------------------------------------------------------------------*/
528/*----------------------------------------------------------------------------*/
529
532 int n_col_blocks,
533 const cs_lnum_t *col_block_sizes,
534 int n_blocks);
535
536/*----------------------------------------------------------------------------*/
552/*----------------------------------------------------------------------------*/
553
556 int block_id,
558 cs_flag_t location,
559 cs_lnum_t n_elements,
560 int stride,
561 bool interlaced,
562 bool unrolled);
563
564/*----------------------------------------------------------------------------*/
578/*----------------------------------------------------------------------------*/
579
582 int block_id,
584 cs_flag_t location,
585 cs_lnum_t n_elements,
586 int stride);
587
588/*----------------------------------------------------------------------------*/
603/*----------------------------------------------------------------------------*/
604
607 int block_id,
608 const cs_adjacency_t *adjacency,
609 cs_flag_t location,
610 cs_lnum_t n_elements,
611 int stride,
612 bool interlaced);
613
614/*----------------------------------------------------------------------------*/
625/*----------------------------------------------------------------------------*/
626
629 int block_id,
630 cs_lnum_t n_dofs);
631
632/*----------------------------------------------------------------------------*/
641/*----------------------------------------------------------------------------*/
642
645 int block_id);
646
647/*----------------------------------------------------------------------------*/
661/*----------------------------------------------------------------------------*/
662
665 int block_id);
666
667/*----------------------------------------------------------------------------*/
681/*----------------------------------------------------------------------------*/
682
685 int block_id,
686 int sub_id);
687
688/*----------------------------------------------------------------------------*/
696/*----------------------------------------------------------------------------*/
697
698void
700 int block_id);
701
702/*----------------------------------------------------------------------------*/
710/*----------------------------------------------------------------------------*/
711
712void
714 cs_real_t **p_rhs);
715
716/*----------------------------------------------------------------------------*/
722/*----------------------------------------------------------------------------*/
723
724void
726
727/*----------------------------------------------------------------------------*/
733/*----------------------------------------------------------------------------*/
734
735void
737
738/*----------------------------------------------------------------------------*/
744/*----------------------------------------------------------------------------*/
745
746void
748
749/*----------------------------------------------------------------------------*/
754/*----------------------------------------------------------------------------*/
755
756void
758
759/*----------------------------------------------------------------------------*/
763/*----------------------------------------------------------------------------*/
764
765void
767
768/*----------------------------------------------------------------------------*/
769
771
772#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:78
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_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:1170
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:1127
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:1982
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:1052
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:1404
cs_cdo_system_block_type_t
type of block composing a (block) matrix
Definition: cs_cdo_system.h:91
@ CS_CDO_SYSTEM_BLOCK_EXT
Definition: cs_cdo_system.h:96
@ CS_CDO_SYSTEM_N_BLOCK_TYPES
Definition: cs_cdo_system.h:98
@ CS_CDO_SYSTEM_BLOCK_DEFAULT
Definition: cs_cdo_system.h:93
@ CS_CDO_SYSTEM_BLOCK_UNASS
Definition: cs_cdo_system.h:95
@ CS_CDO_SYSTEM_BLOCK_SPLIT
Definition: cs_cdo_system.h:94
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:2043
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:445
void cs_cdo_system_allocate_assembly(void)
Initialize shared assembly structures from the existing helper structures.
Definition: cs_cdo_system.cpp:2108
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:1492
cs_cdo_system_block_t * cs_cdo_system_add_sblock(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 split block definition at position "block_id" in the helper structure. Only metadata are set at...
Definition: cs_cdo_system.cpp:1271
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:1076
cs_cdo_system_matrix_class_t
Class of matrices to consider.
Definition: cs_cdo_system.h:119
@ CS_CDO_SYSTEM_MATRIX_HYPRE
Definition: cs_cdo_system.h:124
@ CS_CDO_SYSTEM_N_MATRIX_CLASSES
Definition: cs_cdo_system.h:126
@ CS_CDO_SYSTEM_MATRIX_NONE
Definition: cs_cdo_system.h:121
@ CS_CDO_SYSTEM_MATRIX_CS
Definition: cs_cdo_system.h:122
@ CS_CDO_SYSTEM_MATRIX_PETSC
Definition: cs_cdo_system.h:123
void cs_cdo_system_destroy_all(void)
Free all members associated to system helpers.
Definition: cs_cdo_system.cpp:2170
cs_cdo_system_type_t
Definition: cs_cdo_system.h:62
@ CS_CDO_SYSTEM_COUPLED
Definition: cs_cdo_system.h:65
@ CS_CDO_SYSTEM_SADDLE_POINT
Definition: cs_cdo_system.h:66
@ CS_CDO_SYSTEM_DEFAULT
Definition: cs_cdo_system.h:64
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:483
#define BEGIN_C_DECLS
Definition: cs_defs.h:542
double cs_real_t
Floating-point value.
Definition: cs_defs.h:342
#define END_C_DECLS
Definition: cs_defs.h:543
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:335
unsigned short int cs_flag_t
Definition: cs_defs.h:344
struct _cs_interface_set_t cs_interface_set_t
Definition: cs_interface.h:61
struct _cs_matrix_structure_t cs_matrix_structure_t
Definition: cs_matrix.h:106
struct _cs_matrix_t cs_matrix_t
Definition: cs_matrix.h:110
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:643
@ CS_PARAM_SOLVER_CLASS_CS
Definition: cs_param_types.h:645
@ CS_PARAM_SOLVER_CLASS_HYPRE
Definition: cs_param_types.h:646
Definition: mesh.f90:26
Definition: cs_mesh_adjacencies.h:68
Definition: cs_cdo_connect.h:61
Definition: cs_cdo_system.h:131
int stride
Definition: cs_cdo_system.h:143
cs_cdo_system_matrix_class_t matrix_class
Definition: cs_cdo_system.h:137
cs_flag_t location
Definition: cs_cdo_system.h:141
bool interlaced
Definition: cs_cdo_system.h:160
cs_lnum_t n_elements
Definition: cs_cdo_system.h:142
bool unrolled
Definition: cs_cdo_system.h:159
Definition: cs_cdo_system.h:335
void * block_pointer
Definition: cs_cdo_system.h:365
cs_cdo_system_block_info_t info
Definition: cs_cdo_system.h:341
cs_cdo_system_block_type_t type
Definition: cs_cdo_system.h:353
int id
Definition: cs_cdo_system.h:357
bool owner
Definition: cs_cdo_system.h:355
Structure associated to the default type of block.
Definition: cs_cdo_system.h:174
cs_matrix_t * matrix
Definition: cs_cdo_system.h:195
cs_cdo_assembly_func_t * slave_assembly_func
Definition: cs_cdo_system.h:198
cs_interface_set_t * interface_set
Definition: cs_cdo_system.h:204
cs_matrix_assembler_values_t * mav
Definition: cs_cdo_system.h:196
cs_range_set_t * range_set
Definition: cs_cdo_system.h:203
cs_matrix_assembler_t * matrix_assembler
Definition: cs_cdo_system.h:205
cs_cdo_assembly_func_t * assembly_func
Definition: cs_cdo_system.h:197
cs_matrix_structure_t * matrix_structure
Definition: cs_cdo_system.h:206
Definition: cs_cdo_system.h:377
cs_real_t ** rhs_array
Definition: cs_cdo_system.h:423
cs_lnum_t * col_block_sizes
Definition: cs_cdo_system.h:417
cs_cdo_system_type_t type
Definition: cs_cdo_system.h:414
cs_cdo_system_block_t ** blocks
Definition: cs_cdo_system.h:426
cs_lnum_t full_rhs_size
Definition: cs_cdo_system.h:420
cs_lnum_t * max_col_block_sizes
Definition: cs_cdo_system.h:418
cs_real_t * _rhs
Definition: cs_cdo_system.h:422
int n_col_blocks
Definition: cs_cdo_system.h:416
cs_real_t * rhs
Definition: cs_cdo_system.h:421
int n_blocks
Definition: cs_cdo_system.h:425
Structure associated to the split type of block.
Definition: cs_cdo_system.h:218
bool matrix_struct_ownership
Definition: cs_cdo_system.h:252
cs_cdo_assembly_func_t * slave_assembly_func
Definition: cs_cdo_system.h:244
cs_interface_set_t * interface_set
Definition: cs_cdo_system.h:250
int n_matrices
Definition: cs_cdo_system.h:240
cs_matrix_assembler_values_t ** mav_array
Definition: cs_cdo_system.h:242
cs_matrix_t ** matrices
Definition: cs_cdo_system.h:241
cs_range_set_t * range_set
Definition: cs_cdo_system.h:249
cs_matrix_assembler_t * matrix_assembler
Definition: cs_cdo_system.h:253
cs_cdo_assembly_func_t * assembly_func
Definition: cs_cdo_system.h:243
cs_matrix_structure_t * matrix_structure
Definition: cs_cdo_system.h:254
Structure associated to the unassembled type of block.
Definition: cs_cdo_system.h:266
bool shared_structures
Definition: cs_cdo_system.h:293
const cs_adjacency_t * adjacency
Definition: cs_cdo_system.h:287
cs_real_t * values
Definition: cs_cdo_system.h:284
cs_real_t * _values
Definition: cs_cdo_system.h:285
cs_interface_set_t * interface_set
Definition: cs_cdo_system.h:295
cs_range_set_t * range_set
Definition: cs_cdo_system.h:294
Structure associated to the extended type of block.
Definition: cs_cdo_system.h:307
cs_matrix_t * matrix
Definition: cs_cdo_system.h:317
cs_interface_set_t * interface_set
Definition: cs_cdo_system.h:323
cs_matrix_assembler_values_t * mav
Definition: cs_cdo_system.h:318
cs_range_set_t * range_set
Definition: cs_cdo_system.h:322
cs_matrix_assembler_t * matrix_assembler
Definition: cs_cdo_system.h:324
cs_matrix_structure_t * matrix_structure
Definition: cs_cdo_system.h:325
Definition: cs_mesh.h:85
Definition: cs_range_set.h:57