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-2015 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 
37 /*----------------------------------------------------------------------------*/
38 
40 
41 /*=============================================================================
42  * Local Macro definitions
43  *============================================================================*/
44 
45 /*============================================================================
46  * Type definition
47  *============================================================================*/
48 
49 /*----------------------------------------------------------------------------
50  * Gradient reconstruction method
51  *----------------------------------------------------------------------------*/
52 
53 typedef enum {
54 
55  CS_GRADIENT_ITER, /* Iterative */
56  CS_GRADIENT_LSQ, /* Least-squares */
57  CS_GRADIENT_LSQ_ITER_OLD, /* LSQ followed by iterative (old) */
58  CS_GRADIENT_ITER_OLD /* Iterative (old) */
59 
61 
62 /*============================================================================
63  * Global variables
64  *============================================================================*/
65 
66 /* Short names for gradient types */
67 
68 extern const char *cs_gradient_type_name[];
69 
70 /*============================================================================
71  * Public function prototypes for Fortran API
72  *============================================================================*/
73 
74 /*----------------------------------------------------------------------------
75  * Compute cell gradient of scalar field or component of vector or
76  * tensor field.
77  *----------------------------------------------------------------------------*/
78 
79 void CS_PROCF (cgdcel, CGDCEL)
80 (
81  const cs_int_t *const f_id, /* <-- field id, or -1 */
82  const cs_int_t *const imrgra, /* <-- gradient computation mode */
83  const cs_int_t *const inc, /* <-- 0 or 1: increment or not */
84  const cs_int_t *const iccocg, /* <-- 1 or 0: recompute COCG or not */
85  const cs_int_t *const n_r_sweeps, /* <-- >1: with reconstruction */
86  const cs_int_t *const idimtr, /* <-- 0, 1, 2: scalar, vector, tensor
87  in case of rotation */
88  const cs_int_t *const iphydp, /* <-- use hydrosatatic pressure */
89  const cs_int_t *const ipond, /* <-- >0: weighted gradient computation*/
90  const cs_int_t *const iwarnp, /* <-- verbosity level */
91  const cs_int_t *const imligp, /* <-- type of clipping */
92  const cs_real_t *const epsrgp, /* <-- precision for iterative gradient
93  calculation */
94  const cs_real_t *const extrap, /* <-- extrapolate gradient at boundary */
95  const cs_real_t *const climgp, /* <-- clipping coefficient */
96  cs_real_3_t f_ext[], /* <-- exterior force generating the
97  hydrostatic pressure */
98  const cs_real_t coefap[], /* <-- boundary condition term */
99  const cs_real_t coefbp[], /* <-- boundary condition term */
100  cs_real_t pvar[], /* <-- gradient's base variable */
101  cs_real_t ktvar[], /* <-- gradient coefficient variable */
102  cs_real_3_t grad[] /* <-> gradient */
103 );
104 
105 /*----------------------------------------------------------------------------
106  * Compute cell gradient of vector field.
107  *----------------------------------------------------------------------------*/
108 
109 void CS_PROCF (cgdvec, CGDVEC)
110 (
111  const cs_int_t *const f_id, /* <-- field id, or -1 */
112  const cs_int_t *const imrgra, /* <-- gradient computation mode */
113  const cs_int_t *const inc, /* <-- 0 or 1: increment or not */
114  const cs_int_t *const n_r_sweeps,/* <-- >1: with reconstruction */
115  const cs_int_t *const iwarnp, /* <-- verbosity level */
116  const cs_int_t *const imligp, /* <-- type of clipping */
117  const cs_real_t *const epsrgp, /* <-- precision for iterative
118  gradient calculation */
119  const cs_real_t *const climgp, /* <-- clipping coefficient */
120  const cs_real_3_t coefav[], /* <-- boundary condition term */
121  const cs_real_33_t coefbv[], /* <-- boundary condition term */
122  cs_real_3_t pvar[], /* <-- gradient's base variable */
123  cs_real_33_t gradv[] /* <-> gradient of the variable
124  (du_i/dx_j : gradv[][i][j]) */
125 );
126 
127 /*----------------------------------------------------------------------------
128  * Compute cell gradient of tensor field.
129  *----------------------------------------------------------------------------*/
130 
131 void CS_PROCF (cgdts, CGDTS)
132 (
133  const cs_int_t *const f_id,
134  const cs_int_t *const imrgra, /* <-- gradient computation mode */
135  const cs_int_t *const inc, /* <-- 0 or 1: increment or not */
136  const cs_int_t *const n_r_sweeps, /* <-- >1: with reconstruction */
137  const cs_int_t *const iwarnp, /* <-- verbosity level */
138  const cs_int_t *const imligp, /* <-- type of clipping */
139  const cs_real_t *const epsrgp, /* <-- precision for iterative
140  gradient calculation */
141  const cs_real_t *const climgp, /* <-- clipping coefficient */
142  const cs_real_6_t coefav[], /* <-- boundary condition term */
143  const cs_real_66_t coefbv[], /* <-- boundary condition term */
144 
145  cs_real_6_t pvar[], /* <-- gradient's base variable */
146  cs_real_63_t grad[] /* <-> gradient of the variable
147  (du_i/dx_j : gradv[][i][j]) */
148 );
149 
150 /*=============================================================================
151  * Public function prototypes
152  *============================================================================*/
153 
154 /*----------------------------------------------------------------------------
155  * Initialize gradient computation API.
156  *----------------------------------------------------------------------------*/
157 
158 void
160 
161 /*----------------------------------------------------------------------------
162  * Finalize gradient computation API.
163  *----------------------------------------------------------------------------*/
164 
165 void
167 
168 /*----------------------------------------------------------------------------
169  * Compute cell gradient of scalar field or component of vector or
170  * tensor field.
171  *
172  * parameters:
173  * var_name <-- variable name
174  * gradient_type <-- gradient type
175  * halo_type <-- halo type
176  * inc <-- if 0, solve on increment; 1 otherwise
177  * recompute_cocg <-- should COCG FV quantities be recomputed ?
178  * n_r_sweeps <-- if > 1, number of reconstruction sweeps
179  * tr_dim <-- 2 for tensor with periodicity of rotation,
180  * 0 otherwise
181  * hyd_p_flag <-- flag for hydrostatic pressure
182  * w_stride <-- stride for weighting coefficient
183  * verbosity <-- verbosity level
184  * clip_mode <-- clipping mode
185  * epsilon <-- precision for iterative gradient calculation
186  * extrap <-- boundary gradient extrapolation coefficient
187  * clip_coeff <-- clipping coefficient
188  * f_ext <-- exterior force generating the hydrostatic pressure
189  * bc_coeff_a <-- boundary condition term a
190  * bc_coeff_b <-- boundary condition term b
191  * var <-> gradient's base variable
192  * c_weight <-- weighted gradient coefficient variable,
193  * or NULL
194  * grad --> gradient
195  *----------------------------------------------------------------------------*/
196 
197 void
198 cs_gradient_scalar(const char *var_name,
199  cs_gradient_type_t gradient_type,
200  cs_halo_type_t halo_type,
201  int inc,
202  bool recompute_cocg,
203  int n_r_sweeps,
204  int tr_dim,
205  int hyd_p_flag,
206  int w_stride,
207  int verbosity,
208  int clip_mode,
209  double epsilon,
210  double extrap,
211  double clip_coeff,
212  cs_real_3_t f_ext[],
213  const cs_real_t bc_coeff_a[],
214  const cs_real_t bc_coeff_b[],
215  cs_real_t *restrict var,
216  cs_real_t *restrict c_weight,
217  cs_real_3_t *restrict grad);
218 
219 /*----------------------------------------------------------------------------
220  * Compute cell gradient of a vector field.
221  *
222  * parameters:
223  * var_name <-- variable name
224  * gradient_type <-- gradient type
225  * halo_type <-- halo type
226  * inc <-- if 0, solve on increment; 1 otherwise
227  * n_r_sweeps <-- if > 1, number of reconstruction sweeps
228  * verbosity <-- verbosity level
229  * clip_mode <-- clipping mode
230  * epsilon <-- precision for iterative gradient calculation
231  * clip_coeff <-- clipping coefficient
232  * bc_coeff_a <-- boundary condition term a
233  * bc_coeff_b <-- boundary condition term b
234  * var <-> gradient's base variable
235  * gradv --> gradient (du_i/dx_j : gradv[][i][j])
236  *----------------------------------------------------------------------------*/
237 
238 void
239 cs_gradient_vector(const char *var_name,
240  cs_gradient_type_t gradient_type,
241  cs_halo_type_t halo_type,
242  int inc,
243  int n_r_sweeps,
244  int verbosity,
245  int clip_mode,
246  double epsilon,
247  double clip_coeff,
248  const cs_real_3_t bc_coeff_a[],
249  const cs_real_33_t bc_coeff_b[],
250  cs_real_3_t *restrict var,
251  cs_real_33_t *restrict gradv);
252 
253 /*----------------------------------------------------------------------------*/
272 /*----------------------------------------------------------------------------*/
273 
274 void
275 cs_gradient_tensor(const char *var_name,
276  cs_gradient_type_t gradient_type,
277  cs_halo_type_t halo_type,
278  int inc,
279  int n_r_sweeps,
280  int verbosity,
281  int clip_mode,
282  double epsilon,
283  double clip_coeff,
284  const cs_real_6_t bc_coeff_a[],
285  const cs_real_66_t bc_coeff_b[],
286  cs_real_6_t *restrict var,
287  cs_real_63_t *restrict grad);
288 
289 /*----------------------------------------------------------------------------
290  * Determine gradient type by Fortran "imrgra" value
291  *
292  * parameters:
293  * imrgra <-- Fortran gradient option
294  * gradient_type --> gradient type
295  * halo_type --> halo type
296  *----------------------------------------------------------------------------*/
297 
298 void
300  cs_gradient_type_t *gradient_type,
301  cs_halo_type_t *halo_type);
302 
303 /*----------------------------------------------------------------------------*/
304 
306 
307 #endif /* __CS_GRADIENT__ */
Definition: cs_gradient.h:55
#define restrict
Definition: cs_defs.h:122
Definition: cs_gradient.h:57
cs_real_t cs_real_6_t[6]
vector of 6 floating-point values
Definition: cs_defs.h:309
void cs_gradient_finalize(void)
Finalize gradient computation API.
Definition: cs_gradient.c:5046
cs_real_t cs_real_66_t[6][6]
6x6 matrix of floating-point values
Definition: cs_defs.h:312
void cs_gradient_type_by_imrgra(int imrgra, cs_gradient_type_t *gradient_type, cs_halo_type_t *halo_type)
Definition: cs_gradient.c:5583
#define BEGIN_C_DECLS
Definition: cs_defs.h:429
int cs_int_t
Fortran-compatible integer.
Definition: cs_defs.h:295
Definition: cs_gradient.h:58
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:4965
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_33_t *restrict gradv)
Compute cell gradient of vector field.
Definition: cs_gradient.c:5349
cs_halo_type_t
Definition: cs_halo.h:49
cs_gradient_type_t
Definition: cs_gradient.h:53
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:307
#define END_C_DECLS
Definition: cs_defs.h:430
double cs_real_t
Definition: cs_defs.h:296
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:4913
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:4837
Definition: cs_gradient.h:56
#define CS_PROCF(x, y)
Definition: cs_defs.h:453
cs_real_t cs_real_33_t[3][3]
3x3 matrix of floating-point values
Definition: cs_defs.h:311
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:5512
cs_real_t cs_real_63_t[6][3]
Definition: cs_defs.h:316
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_real_3_t *restrict grad)
Compute cell gradient of scalar field or component of vector or tensor field.
Definition: cs_gradient.c:5098
const char * cs_gradient_type_name[]
void cs_gradient_initialize(void)
Initialize gradient computation API.
Definition: cs_gradient.c:5027
integer(c_int), pointer, save imrgra
type of gradient reconstruction
Definition: optcal.f90:266