8.2
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-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.h"
36#include "cs_mesh.h"
37#include "cs_mesh_quantities.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 * 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(const cs_mesh_t *m,
209 const cs_mesh_adjacencies_t *madj,
210 const cs_mesh_quantities_t *fvq,
211 const cs_halo_type_t halo_type,
212 int inc,
213 int n_c_iter_max,
214 cs_real_t c_eps,
215 const cs_real_t (*restrict coefav)[stride],
216 const cs_real_t (*restrict coefbv)[stride][stride],
217 const cs_real_t (*restrict pvar)[stride],
218 const cs_real_t *restrict c_weight,
219 const cs_cocg_6_t *restrict cocgb,
220 cs_cocg_6_t *restrict cocg,
221 cs_real_t (*restrict gradv)[stride][3]);
222
223/*----------------------------------------------------------------------------
224 * Green-Gauss reconstruction of the gradient of a vector or tensor using
225 * an initial gradient of this quantity (typically lsq).
226 *
227 * parameters:
228 * m <-- pointer to associated mesh structure
229 * fvq <-- pointer to associated finite volume quantities
230 * cpl <-- structure associated with internal coupling, or NULL
231 * inc <-- if 0, solve on increment; 1 otherwise
232 * porous_model <-- type of porous model used
233 * warped_correction <-- apply warped faces correction ?
234 * coefav <-- B.C. coefficients for boundary face normals
235 * coefbv <-- B.C. coefficients for boundary face normals
236 * pvar <-- variable
237 * c_weight <-- weighted gradient coefficient variable
238 * r_grad <-- gradient used for reconstruction
239 * grad --> gradient of pvar (du_i/dx_j : grad[][i][j])
240 *----------------------------------------------------------------------------*/
241
242template <cs_lnum_t stride>
243void
244cs_gradient_strided_gg_r_cuda(const cs_mesh_t *m,
245 const cs_mesh_adjacencies_t *madj,
246 const cs_mesh_quantities_t *fvq,
247 cs_halo_type_t halo_type,
248 int inc,
249 int porous_model,
250 bool warped_correction,
251 const cs_real_t (*restrict coefav)[stride],
252 const cs_real_t (*restrict coefbv)[stride][stride],
253 const cs_real_t (*restrict pvar)[stride],
254 const cs_real_t *restrict c_weight,
255 const cs_real_t (*restrict r_grad)[stride][3],
256 cs_real_t (*restrict grad)[stride][3]);
257
258#endif /* defined(HAVE_CUDA) */
259
260#endif /* defined(__cplusplus) */
261
263
264/*----------------------------------------------------------------------------*/
265
void cs_sync_h2d(const void *ptr)
Synchronize data from host to device.
Definition cs_base_accel.cxx:1256
void cs_sync_d2h(void *ptr)
Synchronize data from device to host.
Definition cs_base_accel.cxx:1434
#define restrict
Definition cs_defs.h:141
double cs_real_t
Floating-point value.
Definition cs_defs.h:332
#define CS_REAL_TYPE
Definition cs_defs.h:472
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition cs_defs.h:347
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.c:435
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.c:506
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.c:646
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