1 #ifndef __CS_FIELD_OPERATOR_H__
2 #define __CS_FIELD_OPERATOR_H__
3 
4 /*============================================================================
5  * Field based algebraic operators.
6  *============================================================================*/
7 
8 /*
9   This file is part of Code_Saturne, a general-purpose CFD tool.
10 
11   Copyright (C) 1998-2021 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_defs.h"
35 #include "cs_field.h"
36 #include "cs_gradient.h"
37 
38 /*----------------------------------------------------------------------------*/
39 
40 BEGIN_C_DECLS
41 
42 /*=============================================================================
43  * Macro definitions
44  *============================================================================*/
45 
46 /*============================================================================
47  * Type definitions
48  *============================================================================*/
49 
50 /*----------------------------------------------------------------------------
51  * Field values interpolation type
52  *----------------------------------------------------------------------------*/
53 
54 typedef enum {
55 
56   CS_FIELD_INTERPOLATE_MEAN,      /* mean element value (P0 interpolation) */
57   CS_FIELD_INTERPOLATE_GRADIENT   /* mean + gradient correction (pseudo-P1) */
58 
59 } cs_field_interpolate_t;
60 
61 /*=============================================================================
62  * Public function prototypes
63  *============================================================================*/
64 
65 /*----------------------------------------------------------------------------
66  * Compute cell gradient of scalar field or component of vector or
67  * tensor field.
68  *
69  * parameters:
70  *   f              <-- pointer to field
71  *   use_previous_t <-- should we use values from the previous time step ?
72  *   inc            <-- if 0, solve on increment; 1 otherwise
73  *   recompute_cocg <-- should COCG FV quantities be recomputed ?
74  *   grad           --> gradient
75  *----------------------------------------------------------------------------*/
76 
77 void
78 cs_field_gradient_scalar(const cs_field_t          *f,
79                          bool                       use_previous_t,
80                          int                        inc,
81                          bool                       recompute_cocg,
82                          cs_real_3_t      *restrict grad);
83 
84 /*----------------------------------------------------------------------------
85  * Compute cell gradient of scalar field or component of vector or
86  * tensor field.
87  *
88  * parameters:
89  *   f              <-- pointer to field
90  *   use_previous_t <-- should we use values from the previous time step ?
91  *   inc            <-- if 0, solve on increment; 1 otherwise
92  *   recompute_cocg <-- should COCG FV quantities be recomputed ?
93  *   hyd_p_flag     <-- flag for hydrostatic pressure
94  *   f_ext          <-- exterior force generating the hydrostatic pressure
95  *   grad           --> gradient
96  *----------------------------------------------------------------------------*/
97 
98 void
99 cs_field_gradient_potential(const cs_field_t          *f,
100                             bool                       use_previous_t,
101                             int                        inc,
102                             bool                       recompute_cocg,
103                             int                        hyd_p_flag,
104                             cs_real_3_t                f_ext[],
105                             cs_real_3_t      *restrict grad);
106 
107 /*----------------------------------------------------------------------------
108  * Compute cell gradient of scalar field or component of vector or
109  * tensor field.
110  *
111  * parameters:
112  *   f              <-- pointer to field
113  *   use_previous_t <-- should we use values from the previous time step ?
114  *   inc            <-- if 0, solve on increment; 1 otherwise
115  *   grad           --> gradient
116  *----------------------------------------------------------------------------*/
117 
118 void
119 cs_field_gradient_vector(const cs_field_t          *f,
120                          bool                       use_previous_t,
121                          int                        inc,
122                          cs_real_33_t     *restrict grad);
123 
124 /*----------------------------------------------------------------------------
125  * Compute cell gradient of tensor field.
126  *
127  * parameters:
128  *   f              <-- pointer to field
129  *   use_previous_t <-- should we use values from the previous time step ?
130  *   inc            <-- if 0, solve on increment; 1 otherwise
131  *   grad           --> gradient
132  *----------------------------------------------------------------------------*/
133 
134 void
135 cs_field_gradient_tensor(const cs_field_t          *f,
136                          bool                       use_previous_t,
137                          int                        inc,
138                          cs_real_63_t     *restrict grad);
139 
140 /*----------------------------------------------------------------------------
141  * Interpolate field values at a given set of points.
142  *
143  * parameters:
144  *   f                  <-- pointer to field
145  *   interpolation_type <-- interpolation type
146  *   n_points           <-- number of points at which interpolation
147  *                          is required
148  *   point_location     <-- location of points in mesh elements
149  *                          (based on the field location)
150  *   point_coords       <-- point coordinates
151  *   val                --> interpolated values
152  *----------------------------------------------------------------------------*/
153 
154 void
155 cs_field_interpolate(cs_field_t              *f,
156                      cs_field_interpolate_t   interpolation_type,
157                      cs_lnum_t                n_points,
158                      const cs_lnum_t          point_location[],
159                      const cs_real_3_t        point_coords[],
160                      cs_real_t               *val);
161 
162 /*----------------------------------------------------------------------------*/
163 /*!
164  * \brief Find local extrema of a given scalar field at each cell
165  *
166  * This assumes the field values have been synchronized.
167  *
168  * \param[in]       f_id        scalar field id
169  * \param[in]       halo_type   halo type
170  * \param[in, out]  local_max   local maximum value
171  * \param[in, out]  local_min   local minimum value
172  */
173 /*----------------------------------------------------------------------------*/
174 
175 void
176 cs_field_local_extrema_scalar(int              f_id,
177                               cs_halo_type_t   halo_type,
178                               cs_real_t       *local_max,
179                               cs_real_t       *local_min);
180 
181 /*----------------------------------------------------------------------------*/
182 /*!
183  * \brief Shift field values in order to set its spatial average to a given
184  * value.
185  *
186  * \param[in]   f   pointer to field
187  * \param[in]   va  real value of volume average to be set
188  */
189 /*----------------------------------------------------------------------------*/
190 
191 void
192 cs_field_set_volume_average(cs_field_t     *f,
193                             const cs_real_t mean);
194 
195 /*----------------------------------------------------------------------------*/
196 /*!
197  * \brief Synchronize current parallel and periodic field values.
198  *
199  * This function currently only upates fields based on CS_MESH_LOCATION_CELLS.
200  *
201  * \param[in, out]   f           pointer to field
202  * \param[in]        halo_type   halo type
203  */
204 /*----------------------------------------------------------------------------*/
205 
206 void
207 cs_field_synchronize(cs_field_t      *f,
208                      cs_halo_type_t   halo_type);
209 
210 /*----------------------------------------------------------------------------*/
211 
212 END_C_DECLS
213 
214 #endif /* __CS_FIELD_OPERATOR_H__ */
215