8.3
general documentation
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-2024 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 "cs_base.h"
34#include "cs_base_accel.h"
35#include "cs_halo_perio.h"
36#include "cs_mesh_adjacencies.h"
37#include "cs_mesh_quantities.h"
38
39/*----------------------------------------------------------------------------*/
40
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 * inc <-- if 0, solve on increment; 1 otherwise
195 * n_c_iter_max <-- maximum number of iterations for boundary correction
196 * c_eps <-- relative tolerance for boundary correction
197 * coefav <-- B.C. coefficients for boundary face normals
198 * coefbv <-- B.C. coefficients for boundary face normals
199 * pvar <-- variable
200 * c_weight <-- weighted gradient coefficient variable, or NULL
201 * cocgb <-- saved boundary cell covariance array (on device)
202 * cocg <-> cocg covariance matrix for given cell
203 * grad --> gradient of pvar (du_i/dx_j : grad[][i][j])
204 *----------------------------------------------------------------------------*/
205
206template <cs_lnum_t stride>
207void
208cs_gradient_strided_lsq_cuda
209(
210 const cs_mesh_t *m,
211 const cs_mesh_adjacencies_t *madj,
212 const cs_mesh_quantities_t *fvq,
213 const cs_halo_type_t halo_type,
214 int inc,
215 int n_c_iter_max,
216 cs_real_t c_eps,
217 const cs_real_t coefav[][stride],
218 const cs_real_t coefbv[][stride][stride],
219 const cs_real_t pvar[][stride],
220 const cs_real_t *c_weight,
221 const cs_cocg_6_t *cocgb,
222 cs_cocg_6_t *cocg,
223 cs_real_t grad[][stride][3]
224);
225
226/*----------------------------------------------------------------------------
227 * Green-Gauss reconstruction of the gradient of a vector or tensor using
228 * an initial gradient of this quantity (typically lsq).
229 *
230 * parameters:
231 * m <-- pointer to associated mesh structure
232 * fvq <-- pointer to associated finite volume quantities
233 * cpl <-- structure associated with internal coupling, or NULL
234 * inc <-- if 0, solve on increment; 1 otherwise
235 * porous_model <-- type of porous model used
236 * warped_correction <-- apply warped faces correction ?
237 * coefav <-- B.C. coefficients for boundary face normals
238 * coefbv <-- B.C. coefficients for boundary face normals
239 * pvar <-- variable
240 * c_weight <-- weighted gradient coefficient variable
241 * r_grad <-- gradient used for reconstruction
242 * grad --> gradient of pvar (du_i/dx_j : grad[][i][j])
243 *----------------------------------------------------------------------------*/
244
245template <cs_lnum_t stride>
246void
247cs_gradient_strided_gg_r_cuda
248(
249 const cs_mesh_t *m,
250 const cs_mesh_adjacencies_t *madj,
251 const cs_mesh_quantities_t *fvq,
252 cs_halo_type_t halo_type,
253 int inc,
254 int porous_model,
255 bool warped_correction,
256 const cs_real_t coefav[][stride],
257 const cs_real_t coefbv[][stride][stride],
258 const cs_real_t pvar[][stride],
259 const cs_real_t *c_weight,
260 const cs_real_t r_grad[][stride][3],
261 cs_real_t grad[][stride][3]
262);
263
264#endif /* defined(HAVE_CUDA) */
265
266#endif /* defined(__cplusplus) */
267
270/*----------------------------------------------------------------------------*/
#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:104
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