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 /*----------------------------------------------------------------------------*/
245 /*----------------------------------------------------------------------------*/
246 
247 void
248 cs_gradient_vector(const char *var_name,
249  cs_gradient_type_t gradient_type,
250  cs_halo_type_t halo_type,
251  int inc,
252  int n_r_sweeps,
253  int verbosity,
254  int clip_mode,
255  double epsilon,
256  double clip_coeff,
257  const cs_real_3_t bc_coeff_a[],
258  const cs_real_33_t bc_coeff_b[],
259  cs_real_3_t *restrict var,
260  cs_real_t *restrict c_weight,
262  cs_real_33_t *restrict gradv);
263 
264 /*----------------------------------------------------------------------------*/
283 /*----------------------------------------------------------------------------*/
284 
285 void
286 cs_gradient_tensor(const char *var_name,
287  cs_gradient_type_t gradient_type,
288  cs_halo_type_t halo_type,
289  int inc,
290  int n_r_sweeps,
291  int verbosity,
292  int clip_mode,
293  double epsilon,
294  double clip_coeff,
295  const cs_real_6_t bc_coeff_a[],
296  const cs_real_66_t bc_coeff_b[],
297  cs_real_6_t *restrict var,
298  cs_real_63_t *restrict grad);
299 
300 /*----------------------------------------------------------------------------*/
335 /*----------------------------------------------------------------------------*/
336 
337 void
338 cs_gradient_scalar_synced_input(const char *var_name,
339  cs_gradient_type_t gradient_type,
340  cs_halo_type_t halo_type,
341  int inc,
342  bool recompute_cocg,
343  int n_r_sweeps,
344  int tr_dim,
345  int hyd_p_flag,
346  int w_stride,
347  int verbosity,
348  int clip_mode,
349  double epsilon,
350  double extrap,
351  double clip_coeff,
352  cs_real_t f_ext[][3],
353  const cs_real_t bc_coeff_a[],
354  const cs_real_t bc_coeff_b[],
355  const cs_real_t var[restrict],
356  const cs_real_t c_weight[restrict],
357  const cs_internal_coupling_t *cpl,
358  cs_real_t grad[restrict][3]);
359 
360 /*----------------------------------------------------------------------------*/
387 /*----------------------------------------------------------------------------*/
388 
389 void
390 cs_gradient_vector_synced_input(const char *var_name,
391  cs_gradient_type_t gradient_type,
392  cs_halo_type_t halo_type,
393  int inc,
394  int n_r_sweeps,
395  int verbosity,
396  int clip_mode,
397  double epsilon,
398  double clip_coeff,
399  const cs_real_t bc_coeff_a[][3],
400  const cs_real_t bc_coeff_b[][3][3],
401  const cs_real_t var[restrict][3],
402  const cs_real_t c_weight[restrict],
403  const cs_internal_coupling_t *cpl,
404  cs_real_33_t *restrict gradv);
405 
406 /*----------------------------------------------------------------------------*/
425 /*----------------------------------------------------------------------------*/
426 
427 void
428 cs_gradient_tensor_synced_input(const char *var_name,
429  cs_gradient_type_t gradient_type,
430  cs_halo_type_t halo_type,
431  int inc,
432  int n_r_sweeps,
433  int verbosity,
434  int clip_mode,
435  double epsilon,
436  double clip_coeff,
437  const cs_real_t bc_coeff_a[][6],
438  const cs_real_t bc_coeff_b[][6][6],
439  const cs_real_t var[restrict][6],
440  cs_real_63_t *restrict grad);
441 
442 /*----------------------------------------------------------------------------
443  * Determine gradient type by Fortran "imrgra" value
444  *
445  * parameters:
446  * imrgra <-- Fortran gradient option
447  * gradient_type --> gradient type
448  * halo_type --> halo type
449  *----------------------------------------------------------------------------*/
450 
451 void
453  cs_gradient_type_t *gradient_type,
454  cs_halo_type_t *halo_type);
455 
456 /*----------------------------------------------------------------------------*/
457 
459 
460 #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:6859
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:7451
Definition: cs_internal_coupling.h:59
#define BEGIN_C_DECLS
Definition: cs_defs.h:453
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:7216
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:6781
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:6913
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_internal_coupling_t *cpl, cs_real_33_t *restrict gradv)
Compute cell gradient of vector field.
Definition: cs_gradient.c:7031
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], const cs_internal_coupling_t *cpl, cs_real_33_t *restrict gradv)
Compute cell gradient of vector field.
Definition: cs_gradient.c:7321
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
#define END_C_DECLS
Definition: cs_defs.h:454
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:6715
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:6626
Definition: cs_gradient.h:57
#define CS_PROCF(x, y)
Definition: cs_defs.h:467
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:7120
cs_real_t cs_real_63_t[6][3]
Definition: cs_defs.h:321
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:7394
void cs_gradient_initialize(void)
Initialize gradient computation API.
Definition: cs_gradient.c:6840
integer(c_int), pointer, save imrgra
type of gradient reconstruction
Definition: optcal.f90:353