programmer's 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-2018 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"
36 #include "cs_internal_coupling.h"
37 
38 /*----------------------------------------------------------------------------*/
39 
41 
42 /*=============================================================================
43  * Local Macro definitions
44  *============================================================================*/
45 
46 /*============================================================================
47  * Type definition
48  *============================================================================*/
49 
50 /*----------------------------------------------------------------------------
51  * Gradient reconstruction method
52  *----------------------------------------------------------------------------*/
53 
54 typedef enum {
55 
56  CS_GRADIENT_ITER, /* Iterative */
57  CS_GRADIENT_LSQ, /* Least-squares */
58  CS_GRADIENT_LSQ_ITER, /* conservative gradient reconstructed
59  with LSQ */
60  CS_GRADIENT_ITER_OLD /* Iterative (old) */
61 
63 
64 /*============================================================================
65  * Global variables
66  *============================================================================*/
67 
68 /* Short names for gradient types */
69 
70 extern const char *cs_gradient_type_name[];
71 
72 /*============================================================================
73  * Public function prototypes for Fortran API
74  *============================================================================*/
75 
76 /*----------------------------------------------------------------------------
77  * Compute cell gradient of scalar field or component of vector or
78  * tensor field.
79  *----------------------------------------------------------------------------*/
80 
81 void CS_PROCF (cgdcel, CGDCEL)
82 (
83  const cs_int_t *const f_id, /* <-- field id, or -1 */
84  const cs_int_t *const imrgra, /* <-- gradient computation mode */
85  const cs_int_t *const inc, /* <-- 0 or 1: increment or not */
86  const cs_int_t *const iccocg, /* <-- 1 or 0: recompute COCG or not */
87  const cs_int_t *const n_r_sweeps, /* <-- >1: with reconstruction */
88  const cs_int_t *const idimtr, /* <-- 0, 1, 2: scalar, vector, tensor
89  in case of rotation */
90  const cs_int_t *const iphydp, /* <-- use hydrosatatic pressure */
91  const cs_int_t *const ipond, /* <-- >0: weighted gradient computation*/
92  const cs_int_t *const iwarnp, /* <-- verbosity level */
93  const cs_int_t *const imligp, /* <-- type of clipping */
94  const cs_real_t *const epsrgp, /* <-- precision for iterative gradient
95  calculation */
96  const cs_real_t *const extrap, /* <-- extrapolate gradient at boundary */
97  const cs_real_t *const climgp, /* <-- clipping coefficient */
98  cs_real_3_t f_ext[], /* <-- exterior force generating the
99  hydrostatic pressure */
100  const cs_real_t coefap[], /* <-- boundary condition term */
101  const cs_real_t coefbp[], /* <-- boundary condition term */
102  cs_real_t pvar[], /* <-- gradient's base variable */
103  cs_real_t ktvar[], /* <-- gradient coefficient variable */
104  cs_real_3_t grad[] /* <-> gradient */
105 );
106 
107 /*----------------------------------------------------------------------------
108  * Compute cell gradient of vector field.
109  *----------------------------------------------------------------------------*/
110 
111 void CS_PROCF (cgdvec, CGDVEC)
112 (
113  const cs_int_t *const f_id, /* <-- field id, or -1 */
114  const cs_int_t *const imrgra, /* <-- gradient computation mode */
115  const cs_int_t *const inc, /* <-- 0 or 1: increment or not */
116  const cs_int_t *const n_r_sweeps,/* <-- >1: with reconstruction */
117  const cs_int_t *const iwarnp, /* <-- verbosity level */
118  const cs_int_t *const imligp, /* <-- type of clipping */
119  const cs_real_t *const epsrgp, /* <-- precision for iterative
120  gradient calculation */
121  const cs_real_t *const climgp, /* <-- clipping coefficient */
122  const cs_real_3_t coefav[], /* <-- boundary condition term */
123  const cs_real_33_t coefbv[], /* <-- boundary condition term */
124  cs_real_3_t pvar[], /* <-- gradient's base variable */
125  cs_real_33_t gradv[] /* <-> gradient of the variable
126  (du_i/dx_j : gradv[][i][j]) */
127 );
128 
129 /*----------------------------------------------------------------------------
130  * Compute cell gradient of tensor field.
131  *----------------------------------------------------------------------------*/
132 
133 void CS_PROCF (cgdts, CGDTS)
134 (
135  const cs_int_t *const f_id,
136  const cs_int_t *const imrgra, /* <-- gradient computation mode */
137  const cs_int_t *const inc, /* <-- 0 or 1: increment or not */
138  const cs_int_t *const n_r_sweeps, /* <-- >1: with reconstruction */
139  const cs_int_t *const iwarnp, /* <-- verbosity level */
140  const cs_int_t *const imligp, /* <-- type of clipping */
141  const cs_real_t *const epsrgp, /* <-- precision for iterative
142  gradient calculation */
143  const cs_real_t *const climgp, /* <-- clipping coefficient */
144  const cs_real_6_t coefav[], /* <-- boundary condition term */
145  const cs_real_66_t coefbv[], /* <-- boundary condition term */
146 
147  cs_real_6_t pvar[], /* <-- gradient's base variable */
148  cs_real_63_t grad[] /* <-> gradient of the variable
149  (du_i/dx_j : gradv[][i][j]) */
150 );
151 
152 /*=============================================================================
153  * Public function prototypes
154  *============================================================================*/
155 
156 /*----------------------------------------------------------------------------
157  * Initialize gradient computation API.
158  *----------------------------------------------------------------------------*/
159 
160 void
162 
163 /*----------------------------------------------------------------------------
164  * Finalize gradient computation API.
165  *----------------------------------------------------------------------------*/
166 
167 void
169 
170 /*----------------------------------------------------------------------------
171  * Compute cell gradient of scalar field or component of vector or
172  * tensor field.
173  *
174  * parameters:
175  * var_name <-- variable name
176  * gradient_type <-- gradient type
177  * halo_type <-- halo type
178  * inc <-- if 0, solve on increment; 1 otherwise
179  * recompute_cocg <-- should COCG FV quantities be recomputed ?
180  * n_r_sweeps <-- if > 1, number of reconstruction sweeps
181  * tr_dim <-- 2 for tensor with periodicity of rotation,
182  * 0 otherwise
183  * hyd_p_flag <-- flag for hydrostatic pressure
184  * w_stride <-- stride for weighting coefficient
185  * verbosity <-- verbosity level
186  * clip_mode <-- clipping mode
187  * epsilon <-- precision for iterative gradient calculation
188  * extrap <-- boundary gradient extrapolation coefficient
189  * clip_coeff <-- clipping coefficient
190  * f_ext <-- exterior force generating the hydrostatic pressure
191  * bc_coeff_a <-- boundary condition term a
192  * bc_coeff_b <-- boundary condition term b
193  * var <-> gradient's base variable
194  * c_weight <-> weighted gradient coefficient variable, or NULL
195  * cpl <-> structure associated with internal coupling, or NULL
196  * grad --> gradient
197  *----------------------------------------------------------------------------*/
198 
199 void
200 cs_gradient_scalar(const char *var_name,
201  cs_gradient_type_t gradient_type,
202  cs_halo_type_t halo_type,
203  int inc,
204  bool recompute_cocg,
205  int n_r_sweeps,
206  int tr_dim,
207  int hyd_p_flag,
208  int w_stride,
209  int verbosity,
210  int clip_mode,
211  double epsilon,
212  double extrap,
213  double clip_coeff,
214  cs_real_3_t f_ext[],
215  const cs_real_t bc_coeff_a[],
216  const cs_real_t bc_coeff_b[],
217  cs_real_t *restrict var,
218  cs_real_t *restrict c_weight,
220  cs_real_3_t *restrict grad);
221 
222 /*----------------------------------------------------------------------------*/
243 /*----------------------------------------------------------------------------*/
244 
245 void
246 cs_gradient_vector(const char *var_name,
247  cs_gradient_type_t gradient_type,
248  cs_halo_type_t halo_type,
249  int inc,
250  int n_r_sweeps,
251  int verbosity,
252  int clip_mode,
253  double epsilon,
254  double clip_coeff,
255  const cs_real_3_t bc_coeff_a[],
256  const cs_real_33_t bc_coeff_b[],
257  cs_real_3_t *restrict var,
258  cs_real_t *restrict c_weight,
259  cs_real_33_t *restrict gradv);
260 
261 /*----------------------------------------------------------------------------*/
280 /*----------------------------------------------------------------------------*/
281 
282 void
283 cs_gradient_tensor(const char *var_name,
284  cs_gradient_type_t gradient_type,
285  cs_halo_type_t halo_type,
286  int inc,
287  int n_r_sweeps,
288  int verbosity,
289  int clip_mode,
290  double epsilon,
291  double clip_coeff,
292  const cs_real_6_t bc_coeff_a[],
293  const cs_real_66_t bc_coeff_b[],
294  cs_real_6_t *restrict var,
295  cs_real_63_t *restrict grad);
296 
297 /*----------------------------------------------------------------------------*/
332 /*----------------------------------------------------------------------------*/
333 
334 void
335 cs_gradient_scalar_synced_input(const char *var_name,
336  cs_gradient_type_t gradient_type,
337  cs_halo_type_t halo_type,
338  int inc,
339  bool recompute_cocg,
340  int n_r_sweeps,
341  int tr_dim,
342  int hyd_p_flag,
343  int w_stride,
344  int verbosity,
345  int clip_mode,
346  double epsilon,
347  double extrap,
348  double clip_coeff,
349  cs_real_t f_ext[][3],
350  const cs_real_t bc_coeff_a[],
351  const cs_real_t bc_coeff_b[],
352  const cs_real_t var[restrict],
353  const cs_real_t c_weight[restrict],
354  const cs_internal_coupling_t *cpl,
355  cs_real_t grad[restrict][3]);
356 
357 /*----------------------------------------------------------------------------*/
382 /*----------------------------------------------------------------------------*/
383 
384 void
385 cs_gradient_vector_synced_input(const char *var_name,
386  cs_gradient_type_t gradient_type,
387  cs_halo_type_t halo_type,
388  int inc,
389  int n_r_sweeps,
390  int verbosity,
391  int clip_mode,
392  double epsilon,
393  double clip_coeff,
394  const cs_real_t bc_coeff_a[][3],
395  const cs_real_t bc_coeff_b[][3][3],
396  const cs_real_t var[restrict][3],
397  const cs_real_t c_weight[restrict],
398  cs_real_33_t *restrict gradv);
399 
400 /*----------------------------------------------------------------------------*/
419 /*----------------------------------------------------------------------------*/
420 
421 void
422 cs_gradient_tensor_synced_input(const char *var_name,
423  cs_gradient_type_t gradient_type,
424  cs_halo_type_t halo_type,
425  int inc,
426  int n_r_sweeps,
427  int verbosity,
428  int clip_mode,
429  double epsilon,
430  double clip_coeff,
431  const cs_real_t bc_coeff_a[][6],
432  const cs_real_t bc_coeff_b[][6][6],
433  const cs_real_t var[restrict][6],
434  cs_real_63_t *restrict grad);
435 
436 /*----------------------------------------------------------------------------
437  * Determine gradient type by Fortran "imrgra" value
438  *
439  * parameters:
440  * imrgra <-- Fortran gradient option
441  * gradient_type --> gradient type
442  * halo_type --> halo type
443  *----------------------------------------------------------------------------*/
444 
445 void
447  cs_gradient_type_t *gradient_type,
448  cs_halo_type_t *halo_type);
449 
450 /*----------------------------------------------------------------------------*/
451 
453 
454 #endif /* __CS_GRADIENT__ */
Definition: cs_gradient.h:56
#define restrict
Definition: cs_defs.h:122
cs_real_t cs_real_6_t[6]
vector of 6 floating-point values
Definition: cs_defs.h:311
void cs_gradient_finalize(void)
Finalize gradient computation API.
Definition: cs_gradient.c:6397
cs_real_t cs_real_66_t[6][6]
6x6 matrix of floating-point values
Definition: cs_defs.h:316
void cs_gradient_type_by_imrgra(int imrgra, cs_gradient_type_t *gradient_type, cs_halo_type_t *halo_type)
Definition: cs_gradient.c:6981
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, int clip_mode, double epsilon, double clip_coeff, const cs_real_3_t bc_coeff_a[], const cs_real_33_t bc_coeff_b[], cs_real_3_t *restrict var, cs_real_t *restrict c_weight, cs_real_33_t *restrict gradv)
Compute cell gradient of vector field.
Definition: cs_gradient.c:6567
Definition: cs_internal_coupling.h:59
#define BEGIN_C_DECLS
Definition: cs_defs.h:451
int cs_int_t
Fortran-compatible integer.
Definition: cs_defs.h:296
void cs_gradient_scalar_synced_input(const char *var_name, cs_gradient_type_t gradient_type, cs_halo_type_t halo_type, int inc, bool recompute_cocg, int n_r_sweeps, int tr_dim, int hyd_p_flag, int w_stride, int verbosity, int clip_mode, double epsilon, double extrap, double clip_coeff, cs_real_t f_ext[][3], const cs_real_t bc_coeff_a[], const cs_real_t bc_coeff_b[], const cs_real_t var[restrict], const cs_real_t c_weight[restrict], const cs_internal_coupling_t *cpl, cs_real_t grad[restrict][3])
Compute cell gradient of scalar field or component of vector or tensor field.
Definition: cs_gradient.c:6750
Definition: cs_gradient.h:60
void cgdts(const cs_int_t *const f_id, const cs_int_t *const imrgra, const cs_int_t *const inc, const cs_int_t *const n_r_sweeps, const cs_int_t *const iwarnp, const cs_int_t *const imligp, const cs_real_t *const epsrgp, const cs_real_t *const climgp, const cs_real_6_t coefav[], const cs_real_66_t coefbv[], cs_real_6_t pvar[], cs_real_63_t grad[])
Definition: cs_gradient.c:6319
double cs_real_t
Floating-point value.
Definition: cs_defs.h:297
void cs_gradient_scalar(const char *var_name, cs_gradient_type_t gradient_type, cs_halo_type_t halo_type, int inc, bool recompute_cocg, int n_r_sweeps, int tr_dim, int hyd_p_flag, int w_stride, int verbosity, int clip_mode, double epsilon, double extrap, double clip_coeff, cs_real_3_t f_ext[], const cs_real_t bc_coeff_a[], const cs_real_t bc_coeff_b[], cs_real_t *restrict var, cs_real_t *restrict c_weight, cs_internal_coupling_t *cpl, cs_real_3_t *restrict grad)
Compute cell gradient of scalar field or component of vector or tensor field.
Definition: cs_gradient.c:6451
cs_halo_type_t
Definition: cs_halo.h:50
Definition: cs_gradient.h:58
cs_gradient_type_t
Definition: cs_gradient.h:54
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:309
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, int clip_mode, double epsilon, double clip_coeff, const cs_real_t bc_coeff_a[][3], const cs_real_t bc_coeff_b[][3][3], const cs_real_t var[restrict][3], const cs_real_t c_weight[restrict], cs_real_33_t *restrict gradv)
Compute cell gradient of vector field.
Definition: cs_gradient.c:6853
#define END_C_DECLS
Definition: cs_defs.h:452
void cgdvec(const cs_int_t *const f_id, const cs_int_t *const imrgra, const cs_int_t *const inc, const cs_int_t *const n_r_sweeps, const cs_int_t *const iwarnp, const cs_int_t *const imligp, const cs_real_t *const epsrgp, const cs_real_t *const climgp, const cs_real_3_t coefav[], const cs_real_33_t coefbv[], cs_real_3_t pvar[], cs_real_33_t gradv[])
Definition: cs_gradient.c:6266
void cgdcel(const cs_int_t *const f_id, const cs_int_t *const imrgra, const cs_int_t *const inc, const cs_int_t *const iccocg, const cs_int_t *const n_r_sweeps, const cs_int_t *const idimtr, const cs_int_t *const iphydp, const cs_int_t *const ipond, const cs_int_t *const iwarnp, const cs_int_t *const imligp, const cs_real_t *const epsrgp, const cs_real_t *const extrap, const cs_real_t *const climgp, cs_real_3_t f_ext[], const cs_real_t coefap[], const cs_real_t coefbp[], cs_real_t pvar[], cs_real_t ktvar[], cs_real_3_t grad[])
Definition: cs_gradient.c:6177
Definition: cs_gradient.h:57
#define CS_PROCF(x, y)
Definition: cs_defs.h:465
cs_real_t cs_real_33_t[3][3]
3x3 matrix of floating-point values
Definition: cs_defs.h:315
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, int clip_mode, double epsilon, double clip_coeff, const cs_real_6_t bc_coeff_a[], const cs_real_66_t bc_coeff_b[], cs_real_6_t *restrict var, cs_real_63_t *restrict grad)
Compute cell gradient of tensor.
Definition: cs_gradient.c:6654
cs_real_t cs_real_63_t[6][3]
Definition: cs_defs.h:320
const char * cs_gradient_type_name[]
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, int clip_mode, double epsilon, double clip_coeff, const cs_real_t bc_coeff_a[][6], const cs_real_t bc_coeff_b[][6][6], const cs_real_t var[restrict][6], cs_real_63_t *restrict grad)
Compute cell gradient of tensor.
Definition: cs_gradient.c:6924
void cs_gradient_initialize(void)
Initialize gradient computation API.
Definition: cs_gradient.c:6378
integer(c_int), pointer, save imrgra
type of gradient reconstruction
Definition: optcal.f90:353