9.0
general documentation
Loading...
Searching...
No Matches
cs_gradient_priv.h
Go to the documentation of this file.
1#pragma once
2
3/*============================================================================
4 * Private functions for gradient reconstruction.
5 *============================================================================*/
6
7/*
8 This file is part of code_saturne, a general-purpose CFD tool.
9
10 Copyright (C) 1998-2025 EDF S.A.
11
12 This program is free software; you can redistribute it and/or modify it under
13 the terms of the GNU General Public License as published by the Free Software
14 Foundation; either version 2 of the License, or (at your option) any later
15 version.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20 details.
21
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
24 Street, Fifth Floor, Boston, MA 02110-1301, USA.
25*/
26
27/*----------------------------------------------------------------------------*/
28
29/*----------------------------------------------------------------------------
30 * Local headers
31 *----------------------------------------------------------------------------*/
32
33#include "base/cs_base.h"
34#include "base/cs_base_accel.h"
35#include "base/cs_halo_perio.h"
38
39/*----------------------------------------------------------------------------*/
40
42
43/*============================================================================
44 * Macro definitions
45 *============================================================================*/
46
47/*=============================================================================
48 * Local type definitions
49 *============================================================================*/
50
51/* Type for symmetric least-squares covariance matrices
52 as they are adimensional, single-precision should be usable here */
53
54typedef cs_real_t cs_cocg_t;
55typedef cs_real_t cs_cocg_6_t[6];
56typedef cs_real_t cs_cocg_33_t[3][3];
57
58/*============================================================================
59 * Global variables
60 *============================================================================*/
61
62/*=============================================================================
63 * Semi-private inline functions
64 *============================================================================*/
65
66#if defined(__cplusplus)
67
68#if defined(HAVE_ACCEL)
69
70/*----------------------------------------------------------------------------
71 * Synchronize strided gradient ghost cell values on accelerator device.
72 *
73 * template parameters:
74 * stride 1 for scalars, 3 for vectors, 6 for symmetric tensors
75 *
76 * parameters:
77 * m <-- pointer to associated mesh structure
78 * halo_type <-- halo type (extended or not)
79 * grad --> gradient of a variable
80 *----------------------------------------------------------------------------*/
81
82inline static void
83cs_sync_scalar_gradient_halo_d(const cs_mesh_t *m,
84 cs_halo_type_t halo_type,
85 cs_real_t (*restrict grad)[3])
86{
87 if (m->halo != NULL) {
88 cs_halo_sync_d(m->halo, halo_type, CS_REAL_TYPE, 3, (cs_real_t *)grad);
89
90 if (m->have_rotation_perio) {
91 cs_sync_d2h((void *)grad);
92 cs_halo_perio_sync_var_vect(m->halo, halo_type, (cs_real_t *)grad, 3);
93 cs_sync_h2d((void *)grad);
94 }
95 }
96}
97
98/*----------------------------------------------------------------------------
99 * Synchronize strided gradient ghost cell values on accelerator device.
100 *
101 * template parameters:
102 * stride 1 for scalars, 3 for vectors, 6 for symmetric tensors
103 *
104 * parameters:
105 * m <-- pointer to associated mesh structure
106 * halo_type <-- halo type (extended or not)
107 * grad --> gradient of a variable
108 *----------------------------------------------------------------------------*/
109
110template <cs_lnum_t stride>
111static void
112cs_sync_strided_gradient_halo_d(const cs_mesh_t *m,
113 cs_halo_type_t halo_type,
114 cs_real_t (*restrict grad)[stride][3])
115{
116 if (m->halo != NULL) {
117 cs_halo_sync_d(m->halo, halo_type, CS_REAL_TYPE, stride*3,
118 (cs_real_t *)grad);
119
120 if (m->have_rotation_perio) {
121 cs_sync_d2h((void *)grad);
122 if (stride == 1)
123 cs_halo_perio_sync_var_vect(m->halo, halo_type, (cs_real_t *)grad, 3);
124 else if (stride == 3)
125 cs_halo_perio_sync_var_tens(m->halo, halo_type, (cs_real_t *)grad);
126 else if (stride == 6)
128 halo_type,
129 (cs_real_t *)grad);
130 cs_sync_h2d((void *)grad);
131 }
132 }
133}
134
135#endif /* defined(HAVE_ACCEL) */
136
137/*=============================================================================
138 * Semi-private function prototypes
139 *============================================================================*/
140
141#if defined(HAVE_CUDA)
142
143/*----------------------------------------------------------------------------
144 * Compute cell gradient using least-squares reconstruction for non-orthogonal
145 * meshes (nswrgp > 1).
146 *
147 * Optionally, a volume force generating a hydrostatic pressure component
148 * may be accounted for.
149 *
150 * cocg is computed to account for variable B.C.'s (flux).
151 *
152 * parameters:
153 * m <-- pointer to associated mesh structure
154 * fvq <-- pointer to associated finite volume quantities
155 * halo_type <-- halo type (extended or not)
156 * recompute_cocg <-- flag to recompute cocg
157 * inc <-- if 0, solve on increment; 1 otherwise
158 * bc_coeffs <-- B.C. structure for boundary face normals
159 * pvar <-- variable
160 * c_weight <-- weighted gradient coefficient variable,
161 * or NULL
162 * cocgb <-- saved boundary cell covariance array (on device)
163 * cocg <-> associated cell covariance array (on device)
164 * grad <-> gradient of pvar (halo prepared for periodicity
165 * of rotation)
166 *----------------------------------------------------------------------------*/
167
168void
169cs_gradient_scalar_lsq_cuda(const cs_mesh_t *m,
170 const cs_mesh_quantities_t *fvq,
171 cs_halo_type_t halo_type,
172 bool recompute_cocg,
173 cs_real_t inc,
174 const cs_field_bc_coeffs_t *bc_coeffs,
175 const cs_real_t pvar[],
176 const cs_real_t *restrict c_weight,
177 cs_cocg_6_t *restrict cocgb,
178 cs_cocg_6_t *restrict cocg,
179 cs_real_3_t *restrict grad);
180
181/*----------------------------------------------------------------------------
182 * Compute cell gradient of a vector or tensor using least-squares
183 * reconstruction for non-orthogonal meshes.
184 *
185 * template parameters:
186 * e2n type of assembly algorithm used
187 * stride 3 for vectors, 6 for symmetric tensors
188 *
189 * parameters:
190 * m <-- pointer to associated mesh structure
191 * madj <-- pointer to mesh adjacencies structure
192 * fvq <-- pointer to associated finite volume quantities
193 * halo_type <-- halo type (extended or not)
194 * val_f <-- face value for gradient
195 * pvar <-- variable
196 * c_weight <-- weighted gradient coefficient variable, or NULL
197 * cocgb <-- saved boundary cell covariance array (on device)
198 * cocg <-> cocg covariance matrix for given cell
199 * grad --> gradient of pvar (du_i/dx_j : grad[][i][j])
200 *----------------------------------------------------------------------------*/
201
202template <cs_lnum_t stride>
203void
204cs_gradient_strided_lsq_cuda
205(
206 const cs_mesh_t *m,
207 const cs_mesh_adjacencies_t *madj,
208 const cs_mesh_quantities_t *fvq,
209 const cs_halo_type_t halo_type,
210 const cs_real_t val_f[][stride],
211 const cs_real_t pvar[][stride],
212 const cs_real_t *c_weight,
213 const cs_cocg_6_t *cocgb,
214 cs_cocg_6_t *cocg,
215 cs_real_t grad[][stride][3]
216);
217
218/*----------------------------------------------------------------------------
219 * Green-Gauss reconstruction of the gradient of a vector or tensor using
220 * an initial gradient of this quantity (typically lsq).
221 *
222 * parameters:
223 * m <-- pointer to associated mesh structure
224 * madj <-- pointer to mesh adjacencies structure
225 * fvq <-- pointer to associated finite volume quantities
226 * halo_type <-- halo type (extended or not)
227 * warped_correction <-- apply warped faces correction ?
228 * val_f <-- face value for gradient
229 * pvar <-- variable
230 * c_weight <-- weighted gradient coefficient variable
231 * r_grad <-- gradient used for reconstruction
232 * grad --> gradient of pvar (du_i/dx_j : grad[][i][j])
233 *----------------------------------------------------------------------------*/
234
235template <cs_lnum_t stride>
236void
237cs_gradient_strided_gg_r_cuda
238(
239 const cs_mesh_t *m,
240 const cs_mesh_adjacencies_t *madj,
241 const cs_mesh_quantities_t *fvq,
242 cs_halo_type_t halo_type,
243 bool warped_correction,
244 const cs_real_t val_f[][stride],
245 const cs_real_t pvar[][stride],
246 const cs_real_t *c_weight,
247 const cs_real_t r_grad[][stride][3],
248 cs_real_t grad[][stride][3]
249);
250
251/*----------------------------------------------------------------------------
252 * Green-Gauss reconstruction of the gradient of a vector or tensor using
253 * an initial gradient of this quantity (typically lsq).
254 *
255 * parameters:
256 * m <-- pointer to associated mesh structure
257 * fvq <-- pointer to associated finite volume quantities
258 * cpl <-- structure associated with internal coupling, or NULL
259 * inc <-- if 0, solve on increment; 1 otherwise
260 * warped_correction <-- apply warped faces correction ?
261 * coefav <-- B.C. coefficients for boundary face normals
262 * coefbv <-- B.C. coefficients for boundary face normals
263 * pvar <-- variable
264 * c_weight <-- weighted gradient coefficient variable
265 * r_grad <-- gradient used for reconstruction
266 * grad --> gradient of pvar (du_i/dx_j : grad[][i][j])
267 *----------------------------------------------------------------------------*/
268
269template <cs_lnum_t stride>
270void
271cs_gradient_strided_gg_r_cuda
272(
273 const cs_mesh_t *m,
274 const cs_mesh_adjacencies_t *madj,
275 const cs_mesh_quantities_t *fvq,
276 cs_halo_type_t halo_type,
277 int inc,
278 bool warped_correction,
279 const cs_real_t coefav[][stride],
280 const cs_real_t coefbv[][stride][stride],
281 const cs_real_t pvar[][stride],
282 const cs_real_t *c_weight,
283 const cs_real_t r_grad[][stride][3],
284 cs_real_t grad[][stride][3]
285);
286
287#endif /* defined(HAVE_CUDA) */
288
289#endif /* defined(__cplusplus) */
290
292
293/*----------------------------------------------------------------------------*/
#define restrict
Definition cs_defs.h:145
double cs_real_t
Floating-point value.
Definition cs_defs.h:342
#define CS_REAL_TYPE
Definition cs_defs.h:486
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition cs_defs.h:359
cs_halo_type_t
Definition cs_halo.h:56
void cs_halo_perio_sync_var_vect(const cs_halo_t *halo, cs_halo_type_t sync_mode, cs_real_t var[], int incvar)
Definition cs_halo_perio.cpp:384
void cs_halo_perio_sync_var_tens(const cs_halo_t *halo, cs_halo_type_t sync_mode, cs_real_t var[])
Definition cs_halo_perio.cpp:455
void cs_halo_perio_sync_var_sym_tens_grad(const cs_halo_t *halo, cs_halo_type_t sync_mode, cs_real_t var[])
Definition cs_halo_perio.cpp:595
static void cs_sync_d2h(void *ptr)
Synchronize data from device to host.
Definition cs_mem.h:1031
static void cs_sync_h2d(const void *ptr)
Synchronize data from host to device.
Definition cs_mem.h:997
Field boundary condition descriptor (for variables)
Definition cs_field.h:121
Definition cs_mesh_adjacencies.h:82
Definition cs_mesh_quantities.h:92
Definition cs_mesh.h:85
int have_rotation_perio
Definition cs_mesh.h:143
cs_halo_t * halo
Definition cs_mesh.h:156