9.1
general documentation
cs_gradient.h
Go to the documentation of this file.
1#ifndef __CS_GRADIENT_H__
2#define __CS_GRADIENT_H__
3
4/*============================================================================
5 * Gradient reconstruction.
6 *============================================================================*/
7
8/*
9 This file is part of code_saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2025 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 * Local headers
32 *----------------------------------------------------------------------------*/
33
34#include "base/cs_base.h"
35#include "base/cs_halo.h"
37#include "mesh/cs_mesh.h"
39
40/*----------------------------------------------------------------------------*/
41
43
44/*=============================================================================
45 * Local Macro definitions
46 *============================================================================*/
47
48/*============================================================================
49 * Type definition
50 *============================================================================*/
51
52/*----------------------------------------------------------------------------
53 * Gradient reconstruction method
54 *----------------------------------------------------------------------------*/
55
56#define CS_IPRIME_F_LSQ 0
57#define CS_IF_LSQ 1
58
59#define B_DIRECTION_LSQ CS_IPRIME_F_LSQ //CS_IF_LSQ
60
61typedef enum {
62
72
73/*----------------------------------------------------------------------------
74 * Gradient limiter mode
75 *----------------------------------------------------------------------------*/
76
77typedef enum {
78
89
90/*============================================================================
91 * Global variables
92 *============================================================================*/
93
94/* Short names for gradient types */
95
96extern const char *cs_gradient_type_name[];
97
98/*=============================================================================
99 * Public function prototypes
100 *============================================================================*/
101
102/*----------------------------------------------------------------------------
103 * Initialize gradient computation API.
104 *----------------------------------------------------------------------------*/
105
106void
108
109/*----------------------------------------------------------------------------
110 * Finalize gradient computation API.
111 *----------------------------------------------------------------------------*/
112
113void
115
116/*----------------------------------------------------------------------------*/
123/*----------------------------------------------------------------------------*/
124
125void
127
128/*----------------------------------------------------------------------------*/
129/*
130 * \brief Compute cell gradient of scalar field or component of vector or
131 * tensor field.
132 *
133 * \param[in] var_name variable name
134 * \param[in] gradient_type gradient type
135 * \param[in] halo_type halo type
136 * \param[in] inc if 0, solve on increment; 1 otherwise
137 * \param[in] n_r_sweeps if > 1, number of reconstruction sweeps
138 * (only used by CS_GRADIENT_GREEN_ITER)
139 * \param[in] hyd_p_flag flag for hydrostatic pressure
140 * \param[in] w_stride stride for weighting coefficient
141 * \param[in] verbosity verbosity level
142 * \param[in] clip_mode clipping mode
143 * \param[in] epsilon precision for iterative gradient calculation
144 * \param[in] clip_coeff clipping coefficient
145 * \param[in] f_ext exterior force generating the
146 * hydrostatic pressure
147 * \param[in] bc_coeffs boundary condition structure
148 * \param[in, out] var gradient's base variable
149 * \param[in, out] c_weight cell variable weight, or nullptr
150 * \param[in] cpl associated internal coupling, or nullptr
151 * \param[out] grad gradient
152 */
153/*----------------------------------------------------------------------------*/
154
155void
156cs_gradient_scalar(const char *var_name,
157 cs_gradient_type_t gradient_type,
158 cs_halo_type_t halo_type,
159 int inc,
160 int n_r_sweeps,
161 int hyd_p_flag,
162 int w_stride,
163 int verbosity,
164 cs_gradient_limit_t clip_mode,
165 double epsilon,
166 double clip_coeff,
167 cs_real_3_t f_ext[],
168 const cs_field_bc_coeffs_t *bc_coeffs,
169 cs_real_t var[],
170 cs_real_t *c_weight,
171 const cs_internal_coupling_t *cpl,
172 cs_real_t grad[][3]);
173
174/*----------------------------------------------------------------------------*/
175/*
176 * \brief Compute cell gradient of vector field.
177 *
178 * \param[in] var_name variable name
179 * \param[in] gradient_type gradient type
180 * \param[in] halo_type halo type
181 * \param[in] inc if 0, solve on increment; 1 otherwise
182 * \param[in] n_r_sweeps if > 1, number of reconstruction sweeps
183 * (only used by CS_GRADIENT_GREEN_ITER)
184 * \param[in] verbosity verbosity level
185 * \param[in] clip_mode clipping mode
186 * \param[in] epsilon precision for iterative gradient calculation
187 * \param[in] clip_coeff clipping coefficient
188 * \param[in] bc_coeffs_v boundary condition structure
189 * \param[in, out] var gradient's base variable
190 * \param[in, out] c_weight cell variable weight, or nullptr
191 * \param[in] cpl associated internal coupling, or nullptr
192 * \param[out] gradv gradient
193 (\f$ \der{u_i}{x_j} \f$ is gradv[][i][j])
194 */
195/*----------------------------------------------------------------------------*/
196
197void
198cs_gradient_vector(const char *var_name,
199 cs_gradient_type_t gradient_type,
200 cs_halo_type_t halo_type,
201 int inc,
202 int n_r_sweeps,
203 int verbosity,
204 cs_gradient_limit_t clip_mode,
205 double epsilon,
206 double clip_coeff,
207 const cs_field_bc_coeffs_t *bc_coeffs_v,
208 cs_real_t var[][3],
209 cs_real_t *c_weight,
210 const cs_internal_coupling_t *cpl,
211 cs_real_t gradv[][3][3]);
212
213/*----------------------------------------------------------------------------*/
214/*
215 * \brief Compute cell gradient of tensor.
216 *
217 * \param[in] var_name variable name
218 * \param[in] gradient_type gradient type
219 * \param[in] halo_type halo type
220 * \param[in] inc if 0, solve on increment; 1 otherwise
221 * \param[in] n_r_sweeps if > 1, number of reconstruction sweeps
222 * (only used by CS_GRADIENT_GREEN_ITER)
223 * \param[in] verbosity verbosity level
224 * \param[in] clip_mode clipping mode
225 * \param[in] epsilon precision for iterative gradient calculation
226 * \param[in] clip_coeff clipping coefficient
227 * \param[in] bc_coeffs_ts boundary condition structure
228 * \param[in, out] var gradient's base variable
229 * \param[out] grad gradient
230 (\f$ \der{t_ij}{x_k} \f$ is grad[][ij][k])
231 */
232/*----------------------------------------------------------------------------*/
233
234void
235cs_gradient_tensor(const char *var_name,
236 cs_gradient_type_t gradient_type,
237 cs_halo_type_t halo_type,
238 int inc,
239 int n_r_sweeps,
240 int verbosity,
241 cs_gradient_limit_t clip_mode,
242 double epsilon,
243 double clip_coeff,
244 const cs_field_bc_coeffs_t *bc_coeffs_ts,
245 cs_real_6_t *var,
246 cs_real_63_t *grad);
247
248/*----------------------------------------------------------------------------*/
249/*
250 * \brief Compute cell gradient of scalar field or component of vector or
251 * tensor field.
252 *
253 * This variant of the \ref cs_gradient_scalar function assumes ghost cell
254 * values for input arrays (var and optionally c_weight)
255 * have already been synchronized.
256 *
257 * \param[in] var_name variable name
258 * \param[in] gradient_type gradient type
259 * \param[in] halo_type halo type
260 * \param[in] inc if 0, solve on increment; 1 otherwise
261 * \param[in] n_r_sweeps if > 1, number of reconstruction sweeps
262 * (only used by CS_GRADIENT_GREEN_ITER)
263 * \param[in] hyd_p_flag flag for hydrostatic pressure
264 * \param[in] w_stride stride for weighting coefficient
265 * \param[in] verbosity verbosity level
266 * \param[in] clip_mode clipping mode
267 * \param[in] epsilon precision for iterative gradient calculation
268 * \param[in] clip_coeff clipping coefficient
269 * \param[in] f_ext exterior force generating the
270 * hydrostatic pressure
271 * \param[in] bc_coeffs boundary condition structure
272 * \param[in] var gradient's base variable
273 * \param[in] val_f boundary face value
274 * \param[in] c_weight cell variable weight, or nullptr
275 * \param[out] grad gradient
276 */
277/*----------------------------------------------------------------------------*/
278
279void
281 cs_gradient_type_t gradient_type,
282 cs_halo_type_t halo_type,
283 int inc,
284 int n_r_sweeps,
285 int hyd_p_flag,
286 int w_stride,
287 int verbosity,
288 cs_gradient_limit_t clip_mode,
289 double epsilon,
290 double clip_coeff,
291 cs_real_t f_ext[][3],
292 const cs_field_bc_coeffs_t *bc_coeffs,
293 const cs_real_t var[],
294 const cs_real_t val_f[],
295 const cs_real_t *c_weight,
296 cs_real_t grad[][3]);
297
298/*----------------------------------------------------------------------------*/
299/*
300 * \brief Compute cell gradient of vector field.
301 *
302 * This variant of the \ref cs_gradient_vector function assumes ghost cell
303 * values for input arrays (var and optionally c_weight)
304 * have already been synchronized.
305 *
306 * \param[in] var_name variable name
307 * \param[in] gradient_type gradient type
308 * \param[in] halo_type halo type
309 * \param[in] inc if 0, solve on increment; 1 otherwise
310 * \param[in] n_r_sweeps if > 1, number of reconstruction sweeps
311 * (only used by CS_GRADIENT_GREEN_ITER)
312 * \param[in] verbosity verbosity level
313 * \param[in] clip_mode clipping mode
314 * \param[in] epsilon precision for iterative gradient calculation
315 * \param[in] clip_coeff clipping coefficient
316 * \param[in] bc_coeffs_v boundary condition structure
317 * \param[in] var gradient's base variable
318 * \param[in] c_weight cell variable weight, or nullptr
319 * \param[out] grad gradient
320 (\f$ \der{u_i}{x_j} \f$ is gradv[][i][j])
321 */
322/*----------------------------------------------------------------------------*/
323
324void
325cs_gradient_vector_synced_input(const char *var_name,
326 cs_gradient_type_t gradient_type,
327 cs_halo_type_t halo_type,
328 int inc,
329 int n_r_sweeps,
330 int verbosity,
331 cs_gradient_limit_t clip_mode,
332 double epsilon,
333 double clip_coeff,
334 const cs_field_bc_coeffs_t *bc_coeffs_v,
335 const cs_real_t var[][3],
336 const cs_real_t val_f[][3],
337 const cs_real_t c_weight[],
338 cs_real_t grad[][3][3]);
339
340/*----------------------------------------------------------------------------*/
341/*
342 * \brief Compute cell gradient of tensor.
343 *
344 * This variant of the \ref cs_gradient_tensor function assumes ghost cell
345 * values for input arrays (var and optionally c_weight)
346 * have already been synchronized.
347 *
348 * \param[in] var_name variable name
349 * \param[in] gradient_type gradient type
350 * \param[in] halo_type halo type
351 * \param[in] inc if 0, solve on increment; 1 otherwise
352 * \param[in] n_r_sweeps if > 1, number of reconstruction sweeps
353 * (only used by CS_GRADIENT_GREEN_ITER)
354 * \param[in] verbosity verbosity level
355 * \param[in] clip_mode clipping mode
356 * \param[in] epsilon precision for iterative gradient calculation
357 * \param[in] clip_coeff clipping coefficient
358 * \param[in] bc_coeffs_ts boundary condition structure
359 * \param[in, out] var gradient's base variable:
360 * \param[out] grad gradient
361 (\f$ \der{t_ij}{x_k} \f$ is grad[][ij][k])
362 */
363/*----------------------------------------------------------------------------*/
364
365void
366cs_gradient_tensor_synced_input(const char *var_name,
367 cs_gradient_type_t gradient_type,
368 cs_halo_type_t halo_type,
369 int inc,
370 int n_r_sweeps,
371 int verbosity,
372 cs_gradient_limit_t clip_mode,
373 double epsilon,
374 double clip_coeff,
375 const cs_field_bc_coeffs_t *bc_coeffs_ts,
376 const cs_real_t var[][6],
377 const cs_real_t val_f[][6],
378 cs_real_63_t *grad);
379
380/*----------------------------------------------------------------------------*/
381/*
382 * \brief Compute the gradient of a scalar field at a given cell
383 * using least-squares reconstruction.
384 *
385 * This assumes ghost cell values which might be used are already
386 * synchronized.
387 *
388 * When boundary conditions are provided, both the bc_coeff_a and bc_coeff_b
389 * arrays must be given. If boundary values are known, bc_coeff_a
390 * can point to the boundary values array, and bc_coeff_b set to nullptr.
391 * If bc_coeff_a is nullptr, bc_coeff_b is ignored.
392 *
393 * \param[in] m pointer to associated mesh structure
394 * \param[in] fvq pointer to associated finite volume quantities
395 * \param[in] c_id cell id
396 * \param[in] halo_type halo type
397 * \param[in] bc_coeffs boundary condition structure
398 * \param[in] var gradient's base variable
399 * \param[in] c_weight cell variable weight, or nullptr
400 * \param[out] grad gradient
401 */
402/*----------------------------------------------------------------------------*/
403
404void
406 const cs_mesh_quantities_t *fvq,
407 cs_lnum_t c_id,
408 cs_halo_type_t halo_type,
409 const cs_field_bc_coeffs_t *bc_coeffs,
410 const cs_real_t var[],
411 const cs_real_t c_weight[],
412 cs_real_t grad[3]);
413
414/*----------------------------------------------------------------------------*/
415/*
416 * \brief Compute the gradient of a vector field at a given cell
417 * using least-squares reconstruction.
418 *
419 * This assumes ghost cell values which might be used are already
420 * synchronized.
421 *
422 * When boundary conditions are provided, both the bc_coeff_a and bc_coeff_b
423 * arrays must be given. If boundary values are known, bc_coeff_a
424 * can point to the boundary values array, and bc_coeff_b set to nullptr.
425 * If bc_coeff_a is nullptr, bc_coeff_b is ignored.
426 *
427 * \param[in] m pointer to associated mesh structure
428 * \param[in] fvq pointer to associated finite volume quantities
429 * \param[in] c_id cell id
430 * \param[in] halo_type halo type
431 * \param[in] bc_coeffs boundary condition structure
432 * \param[in] var gradient's base variable
433 * \param[in] c_weight cell variable weight, or nullptr
434 * \param[out] grad gradient
435 */
436/*----------------------------------------------------------------------------*/
437
438void
440 const cs_mesh_quantities_t *fvq,
441 cs_lnum_t c_id,
442 cs_halo_type_t halo_type,
443 const cs_field_bc_coeffs_t *bc_coeffs_v,
444 const cs_real_t var[][3],
445 const cs_real_t c_weight[],
446 cs_real_t grad[3][3]);
447
448/*----------------------------------------------------------------------------*/
449/*
450 * \brief Compute the gradient of a tensor field at a given cell
451 * using least-squares reconstruction.
452 *
453 * This assumes ghost cell values which might be used are already
454 * synchronized.
455 *
456 * When boundary conditions are provided, both the bc_coeff_a and bc_coeff_b
457 * arrays must be given. If boundary values are known, bc_coeff_a
458 * can point to the boundary values array, and bc_coeff_b set to nullptr.
459 * If bc_coeff_a is nullptr, bc_coeff_b is ignored.
460 *
461 * \param[in] m pointer to associated mesh structure
462 * \param[in] fvq pointer to associated finite volume quantities
463 * \param[in] c_id cell id
464 * \param[in] halo_type halo type
465 * \param[in] bc_coeffs_ts boundary condition structure
466 * \param[in] var gradient's base variable
467 * \param[in] c_weight cell variable weight, or nullptr
468 * \param[out] grad gradient
469 */
470/*----------------------------------------------------------------------------*/
471
472void
474 const cs_mesh_quantities_t *fvq,
475 cs_lnum_t c_id,
476 cs_halo_type_t halo_type,
477 const cs_field_bc_coeffs_t *bc_coeffs_ts,
478 const cs_real_t var[][6],
479 const cs_real_t c_weight[],
480 cs_real_t grad[6][3]);
481
482/*----------------------------------------------------------------------------
483 * Determine gradient type by Fortran "imrgra" value
484 *
485 * parameters:
486 * imrgra <-- Fortran gradient option
487 * gradient_type --> gradient type
488 * halo_type --> halo type
489 *----------------------------------------------------------------------------*/
490
491void
493 cs_gradient_type_t *gradient_type,
494 cs_halo_type_t *halo_type);
495
496/*----------------------------------------------------------------------------*/
503/*----------------------------------------------------------------------------*/
504
505void
507
508/*----------------------------------------------------------------------------*/
509
511
512#endif /* __CS_GRADIENT__ */
#define BEGIN_C_DECLS
Definition: cs_defs.h:554
double cs_real_t
Floating-point value.
Definition: cs_defs.h:357
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:374
cs_real_t cs_real_6_t[6]
vector of 6 floating-point values
Definition: cs_defs.h:376
#define END_C_DECLS
Definition: cs_defs.h:555
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:350
cs_real_t cs_real_63_t[6][3]
Definition: cs_defs.h:391
void cs_gradient_scalar(const char *var_name, cs_gradient_type_t gradient_type, cs_halo_type_t halo_type, int inc, int n_r_sweeps, int hyd_p_flag, int w_stride, int verbosity, cs_gradient_limit_t clip_mode, double epsilon, double clip_coeff, cs_real_3_t f_ext[], const cs_field_bc_coeffs_t *bc_coeffs, cs_real_t var[], cs_real_t *c_weight, const cs_internal_coupling_t *cpl, cs_real_t grad[][3])
void cs_gradient_type_by_imrgra(int imrgra, cs_gradient_type_t *gradient_type, cs_halo_type_t *halo_type)
Definition: cs_gradient.cpp:9080
void cs_gradient_scalar_cell(const cs_mesh_t *m, const cs_mesh_quantities_t *fvq, cs_lnum_t c_id, cs_halo_type_t halo_type, const cs_field_bc_coeffs_t *bc_coeffs, const cs_real_t var[], const cs_real_t c_weight[], cs_real_t grad[3])
Compute the gradient of a scalar field at a given cell using least-squares reconstruction.
Definition: cs_gradient.cpp:8755
void cs_gradient_vector(const char *var_name, cs_gradient_type_t gradient_type, cs_halo_type_t halo_type, int inc, int n_r_sweeps, int verbosity, cs_gradient_limit_t clip_mode, double epsilon, double clip_coeff, const cs_field_bc_coeffs_t *bc_coeffs_v, cs_real_t var[][3], cs_real_t *c_weight, const cs_internal_coupling_t *cpl, cs_real_t gradv[][3][3])
cs_gradient_type_t
Definition: cs_gradient.h:61
@ CS_GRADIENT_LSQ
Definition: cs_gradient.h:64
@ CS_GRADIENT_GREEN_LSQ
Definition: cs_gradient.h:65
@ CS_GRADIENT_GREEN_R
Definition: cs_gradient.h:69
@ CS_GRADIENT_GREEN_ITER
Definition: cs_gradient.h:63
@ CS_GRADIENT_GREEN_VTX
Definition: cs_gradient.h:67
const char * cs_gradient_type_name[]
cs_gradient_limit_t
Definition: cs_gradient.h:77
@ CS_GRADIENT_LIMIT_CELL
Definition: cs_gradient.h:80
@ CS_GRADIENT_LIMIT_NONE
Definition: cs_gradient.h:79
@ CS_GRADIENT_LIMIT_FACE
Definition: cs_gradient.h:83
void cs_gradient_porosity_balance(int inc)
compute the steady balance due to porous modelling for the pressure gradient.
Definition: cs_gradient.cpp:9129
void cs_gradient_tensor_cell(const cs_mesh_t *m, const cs_mesh_quantities_t *fvq, cs_lnum_t c_id, cs_halo_type_t halo_type, const cs_field_bc_coeffs_t *bc_coeffs_ts, const cs_real_t var[][6], const cs_real_t c_weight[], cs_real_t grad[6][3])
Compute the gradient of a tensor field at a given cell using least-squares reconstruction.
Definition: cs_gradient.cpp:9051
void cs_gradient_tensor(const char *var_name, cs_gradient_type_t gradient_type, cs_halo_type_t halo_type, int inc, int n_r_sweeps, int verbosity, cs_gradient_limit_t clip_mode, double epsilon, double clip_coeff, const cs_field_bc_coeffs_t *bc_coeffs_ts, cs_real_6_t *var, cs_real_63_t *grad)
void cs_gradient_scalar_synced_input(const char *var_name, cs_gradient_type_t gradient_type, cs_halo_type_t halo_type, int inc, int n_r_sweeps, int hyd_p_flag, int w_stride, int verbosity, cs_gradient_limit_t clip_mode, double epsilon, double clip_coeff, cs_real_t f_ext[][3], const cs_field_bc_coeffs_t *bc_coeffs, const cs_real_t var[], const cs_real_t val_f[], const cs_real_t *c_weight, cs_real_t grad[][3])
void cs_gradient_finalize(void)
Finalize gradient computation API.
Definition: cs_gradient.cpp:7619
void cs_gradient_vector_cell(const cs_mesh_t *m, const cs_mesh_quantities_t *fvq, cs_lnum_t c_id, cs_halo_type_t halo_type, const cs_field_bc_coeffs_t *bc_coeffs_v, const cs_real_t var[][3], const cs_real_t c_weight[], cs_real_t grad[3][3])
Compute the gradient of a vector field at a given cell using least-squares reconstruction.
Definition: cs_gradient.cpp:9007
void cs_gradient_tensor_synced_input(const char *var_name, cs_gradient_type_t gradient_type, cs_halo_type_t halo_type, int inc, int n_r_sweeps, int verbosity, cs_gradient_limit_t clip_mode, double epsilon, double clip_coeff, const cs_field_bc_coeffs_t *bc_coeffs_ts, const cs_real_t var[][6], const cs_real_t val_f[][6], cs_real_63_t *grad)
Compute cell gradient of tensor.
Definition: cs_gradient.cpp:8674
void cs_gradient_initialize(void)
Initialize gradient computation API.
Definition: cs_gradient.cpp:7598
void cs_gradient_vector_synced_input(const char *var_name, cs_gradient_type_t gradient_type, cs_halo_type_t halo_type, int inc, int n_r_sweeps, int verbosity, cs_gradient_limit_t clip_mode, double epsilon, double clip_coeff, const cs_field_bc_coeffs_t *bc_coeffs_v, const cs_real_t var[][3], const cs_real_t val_f[][3], const cs_real_t c_weight[], cs_real_t grad[][3][3])
Compute cell gradient of vector field.
Definition: cs_gradient.cpp:8590
void cs_gradient_free_quantities(void)
Free saved gradient quantities.
Definition: cs_gradient.cpp:7654
cs_halo_type_t
Definition: cs_halo.h:57
Field boundary condition descriptor (for variables)
Definition: cs_field.h:120
Definition: cs_internal_coupling.h:64
Definition: cs_mesh_quantities.h:92
Definition: cs_mesh.h:85