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