9.0
general documentation
Loading...
Searching...
No Matches
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
67
68/*----------------------------------------------------------------------------
69 * Gradient limiter mode
70 *----------------------------------------------------------------------------*/
71
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 val_f[][3],
333 const cs_real_t c_weight[],
334 const cs_internal_coupling_t *cpl,
335 cs_real_t grad[][3][3]);
336
337/*----------------------------------------------------------------------------*/
338/*
339 * \brief Compute cell gradient of tensor.
340 *
341 * This variant of the \ref cs_gradient_tensor function assumes ghost cell
342 * values for input arrays (var and optionally c_weight)
343 * have already been synchronized.
344 *
345 * \param[in] var_name variable name
346 * \param[in] gradient_type gradient type
347 * \param[in] halo_type halo type
348 * \param[in] inc if 0, solve on increment; 1 otherwise
349 * \param[in] n_r_sweeps if > 1, number of reconstruction sweeps
350 * (only used by CS_GRADIENT_GREEN_ITER)
351 * \param[in] verbosity verbosity level
352 * \param[in] clip_mode clipping mode
353 * \param[in] epsilon precision for iterative gradient calculation
354 * \param[in] clip_coeff clipping coefficient
355 * \param[in] bc_coeffs_ts boundary condition structure
356 * \param[in, out] var gradient's base variable:
357 * \param[out] grad gradient
358 (\f$ \der{t_ij}{x_k} \f$ is grad[][ij][k])
359 */
360/*----------------------------------------------------------------------------*/
361
362void
363cs_gradient_tensor_synced_input(const char *var_name,
364 cs_gradient_type_t gradient_type,
365 cs_halo_type_t halo_type,
366 int inc,
367 int n_r_sweeps,
368 int verbosity,
369 cs_gradient_limit_t clip_mode,
370 double epsilon,
371 double clip_coeff,
372 const cs_field_bc_coeffs_t *bc_coeffs_ts,
373 const cs_real_t var[][6],
374 const cs_real_t val_f[][6],
375 cs_real_63_t *grad);
376
377/*----------------------------------------------------------------------------*/
378/*
379 * \brief Compute the gradient of a scalar field at a given cell
380 * using least-squares reconstruction.
381 *
382 * This assumes ghost cell values which might be used are already
383 * synchronized.
384 *
385 * When boundary conditions are provided, both the bc_coeff_a and bc_coeff_b
386 * arrays must be given. If boundary values are known, bc_coeff_a
387 * can point to the boundary values array, and bc_coeff_b set to nullptr.
388 * If bc_coeff_a is nullptr, bc_coeff_b is ignored.
389 *
390 * \param[in] m pointer to associated mesh structure
391 * \param[in] fvq pointer to associated finite volume quantities
392 * \param[in] c_id cell id
393 * \param[in] halo_type halo type
394 * \param[in] bc_coeffs boundary condition structure
395 * \param[in] var gradient's base variable
396 * \param[in] c_weight cell variable weight, or nullptr
397 * \param[out] grad gradient
398 */
399/*----------------------------------------------------------------------------*/
400
401void
403 const cs_mesh_quantities_t *fvq,
404 cs_lnum_t c_id,
405 cs_halo_type_t halo_type,
406 const cs_field_bc_coeffs_t *bc_coeffs,
407 const cs_real_t var[],
408 const cs_real_t c_weight[],
409 cs_real_t grad[3]);
410
411/*----------------------------------------------------------------------------*/
412/*
413 * \brief Compute the gradient of a vector field at a given cell
414 * using least-squares reconstruction.
415 *
416 * This assumes ghost cell values which might be used are already
417 * synchronized.
418 *
419 * When boundary conditions are provided, both the bc_coeff_a and bc_coeff_b
420 * arrays must be given. If boundary values are known, bc_coeff_a
421 * can point to the boundary values array, and bc_coeff_b set to nullptr.
422 * If bc_coeff_a is nullptr, bc_coeff_b is ignored.
423 *
424 * \param[in] m pointer to associated mesh structure
425 * \param[in] fvq pointer to associated finite volume quantities
426 * \param[in] c_id cell id
427 * \param[in] halo_type halo type
428 * \param[in] bc_coeffs boundary condition structure
429 * \param[in] var gradient's base variable
430 * \param[in] c_weight cell variable weight, or nullptr
431 * \param[out] grad gradient
432 */
433/*----------------------------------------------------------------------------*/
434
435void
437 const cs_mesh_quantities_t *fvq,
438 cs_lnum_t c_id,
439 cs_halo_type_t halo_type,
440 const cs_field_bc_coeffs_t *bc_coeffs_v,
441 const cs_real_t var[][3],
442 const cs_real_t c_weight[],
443 cs_real_t grad[3][3]);
444
445/*----------------------------------------------------------------------------*/
446/*
447 * \brief Compute the gradient of a tensor field at a given cell
448 * using least-squares reconstruction.
449 *
450 * This assumes ghost cell values which might be used are already
451 * synchronized.
452 *
453 * When boundary conditions are provided, both the bc_coeff_a and bc_coeff_b
454 * arrays must be given. If boundary values are known, bc_coeff_a
455 * can point to the boundary values array, and bc_coeff_b set to nullptr.
456 * If bc_coeff_a is nullptr, bc_coeff_b is ignored.
457 *
458 * \param[in] m pointer to associated mesh structure
459 * \param[in] fvq pointer to associated finite volume quantities
460 * \param[in] c_id cell id
461 * \param[in] halo_type halo type
462 * \param[in] bc_coeffs_ts boundary condition structure
463 * \param[in] var gradient's base variable
464 * \param[in] c_weight cell variable weight, or nullptr
465 * \param[out] grad gradient
466 */
467/*----------------------------------------------------------------------------*/
468
469void
471 const cs_mesh_quantities_t *fvq,
472 cs_lnum_t c_id,
473 cs_halo_type_t halo_type,
474 const cs_field_bc_coeffs_t *bc_coeffs_ts,
475 const cs_real_t var[][6],
476 const cs_real_t c_weight[],
477 cs_real_t grad[6][3]);
478
479/*----------------------------------------------------------------------------
480 * Determine gradient type by Fortran "imrgra" value
481 *
482 * parameters:
483 * imrgra <-- Fortran gradient option
484 * gradient_type --> gradient type
485 * halo_type --> halo type
486 *----------------------------------------------------------------------------*/
487
488void
490 cs_gradient_type_t *gradient_type,
491 cs_halo_type_t *halo_type);
492
493/*----------------------------------------------------------------------------*/
500/*----------------------------------------------------------------------------*/
501
502void
504
505/*----------------------------------------------------------------------------*/
506
508
509#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_6_t[6]
vector of 6 floating-point values
Definition cs_defs.h:361
#define END_C_DECLS
Definition cs_defs.h:543
cs_real_t cs_real_63_t[6][3]
Definition cs_defs.h:376
int cs_lnum_t
local mesh entity id
Definition cs_defs.h:335
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition cs_defs.h:359
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:9598
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:9273
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[]
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:9647
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:9569
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_finalize(void)
Finalize gradient computation API.
Definition cs_gradient.cpp:8365
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:9525
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:9194
void cs_gradient_initialize(void)
Initialize gradient computation API.
Definition cs_gradient.cpp:8344
void cs_gradient_free_quantities(void)
Free saved gradient quantities.
Definition cs_gradient.cpp:8400
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[], const cs_internal_coupling_t *cpl, cs_real_t grad[][3][3])
Compute cell gradient of vector field.
Definition cs_gradient.cpp:9110
cs_halo_type_t
Definition cs_halo.h:56
Field boundary condition descriptor (for variables)
Definition cs_field.h:121
Definition cs_internal_coupling.h:63
Definition cs_mesh_quantities.h:92
Definition cs_mesh.h:85