TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Assembleur_P_VEF.cpp
1/****************************************************************************
2* Copyright (c) 2026, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#include <Assembleur_P_VEF.h>
17#include <Domaine_Cl_VEF.h>
18#include <Domaine_VEF.h>
19#include <Periodique.h>
20#include <Neumann_sortie_libre.h>
21#include <Matrice_Bloc.h>
22#include <Milieu_base.h>
23#include <Robin_VEF.h>
24
25
26Implemente_instanciable(Assembleur_P_VEF,"Assembleur_P_VEF",Assembleur_base);
27
29{
30 return s << que_suis_je() << " " << le_nom() ;
31}
32
34{
36}
37
39{
40 // If rho is constant, solve with pressure P*=P/rho
41 const DoubleVect& volumes_entrelaces_ref=le_dom_VEF->volumes_entrelaces();
42 DoubleVect tab_volumes_entrelaces(volumes_entrelaces_ref);
43 const DoubleVect& tab_volumes_entrelaces_cl=le_dom_Cl_VEF->volumes_entrelaces_Cl();
44 int size=tab_volumes_entrelaces_cl.size();
45 {
46 CDoubleArrView volumes_entrelaces_cl = static_cast<const ArrOfDouble&>(tab_volumes_entrelaces_cl).view_ro();
47 DoubleArrView volumes_entrelaces = static_cast<ArrOfDouble&>(tab_volumes_entrelaces).view_rw();
48 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__), range_1D(0, size), KOKKOS_LAMBDA(const int f)
49 {
50 if (volumes_entrelaces_cl(f)!=0)
51 volumes_entrelaces(f)=volumes_entrelaces_cl(f);
52 });
53 end_gpu_timer(__KERNEL_NAME__);
54 }
55
56 tab_volumes_entrelaces.echange_espace_virtuel();
57 // Assemble the matrix
58 return assembler_mat(la_matrice,tab_volumes_entrelaces,1,1);
59}
60
61
62
63void calculer_inv_volume_special(DoubleTab& tab_inv_volumes_entrelaces, const Domaine_Cl_VEF& domaine_Cl_VEF,const DoubleTab& tab_volumes_entrelaces)
64{
65 tab_inv_volumes_entrelaces=tab_volumes_entrelaces;
66 int taille=tab_volumes_entrelaces.dimension_tot(0);
67 {
68 CDoubleTabView volumes_entrelaces = tab_volumes_entrelaces.view_ro();
69 DoubleTabView inv_volumes_entrelaces = tab_inv_volumes_entrelaces.view_rw();
70 const int dimension = Objet_U::dimension;
71 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__), range_1D(0, taille), KOKKOS_LAMBDA(const int i)
72 {
73 for (int comp=0; comp<dimension; comp++)
74 inv_volumes_entrelaces(i,comp)=1./volumes_entrelaces(i,comp);
75 });
76 end_gpu_timer(__KERNEL_NAME__);
77 }
78}
79void Assembleur_P_VEF::calculer_inv_volume(DoubleTab& inv_volumes_entrelaces, const Domaine_Cl_VEF& domaine_Cl_VEF,const DoubleVect& volumes_entrelaces)
80{
81 // the inverse of the volume is now a DoubleTab
82 // this is to make Piso work
83 const DoubleTab* doubleT = dynamic_cast<const DoubleTab*>(&volumes_entrelaces);
84 if (doubleT)
85 {
86 calculer_inv_volume_special(inv_volumes_entrelaces, domaine_Cl_VEF,*doubleT);
87 return;
88 }
89 int taille=volumes_entrelaces.size_totale();
90 inv_volumes_entrelaces.resize(taille,Objet_U::dimension);
91 if (0)
92 {
93 // this way of computing the interlaced volume may be good in
94 // the future provided the porosity issue is addressed,
95 // and ESPECIALLY the SIMPLER issue where we do not want to go through this
96 DoubleTab tmp;
97 tmp=(inv_volumes_entrelaces);
98 tmp=1;
99 domaine_Cl_VEF.equation().solv_masse().appliquer(tmp);
100 int sz=inv_volumes_entrelaces.size_totale();
101 for (int i=0; i<sz; i++)
102 {
103 inv_volumes_entrelaces(i)=tmp(i);
104 if (!est_egal(inv_volumes_entrelaces(i),1./volumes_entrelaces(i)))
105 Cerr<<i<<" "<<inv_volumes_entrelaces(i)-1./volumes_entrelaces(i)<<" "<<inv_volumes_entrelaces(i)<<finl;;
106 }
108 }
109 else
110 {
111 CDoubleArrView porosite_face = static_cast<const ArrOfDouble&>(equation().milieu().porosite_face()).view_ro();
112 CDoubleArrView volumes_entrelaces_v = static_cast<const ArrOfDouble&>(volumes_entrelaces).view_ro();
113 DoubleTabView inv_volumes_entrelaces_v = inv_volumes_entrelaces.view_rw();
114 const int dim = Objet_U::dimension;
115 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__), range_1D(0, taille), KOKKOS_LAMBDA(const int i)
116 {
117 for (int comp=0; comp<dim; comp++)
118 inv_volumes_entrelaces_v(i,comp)=1./volumes_entrelaces_v(i)*porosite_face(i);
119 });
120 end_gpu_timer(__KERNEL_NAME__);
121 }
122}
123
124
125int Assembleur_P_VEF::assembler_mat(Matrice& la_matrice, const DoubleVect& volumes_entrelaces, int incr_pression, int resoudre_en_u)
126{
127 // Set flags of Assembleur_base
128 set_resoudre_increment_pression(incr_pression);
129 set_resoudre_en_u(resoudre_en_u);
130 const Domaine_Cl_VEF& domaine_Cl_VEF = le_dom_Cl_VEF.valeur();
131 DoubleTab inverse_quantitee_entrelacee;
132 calculer_inv_volume(inverse_quantitee_entrelacee, domaine_Cl_VEF, volumes_entrelaces);
133 remplir(la_matrice, inverse_quantitee_entrelacee);
134 modifier_matrice(la_matrice);
135 return 1;
136}
137
138int Assembleur_P_VEF::remplir(Matrice& la_matrice, const DoubleTab& inverse_quantitee_entrelacee)
139{
140 has_P_ref=0;
141 // Pressure matrix: sparse matrix of size nb_poly x nb_poly
142 // This function stores the matrix in a Morse matrix structure
143 // well suited for sparse matrices.
144 // First, compute the sizes of arrays tab1 and tab2
145 // (coeff_ has the same size as tab2)
146 // For each polyhedron, associate:
147 // - a list of integers neighbors[i] = {j>i such that Mij is nonzero}
148 // - a list of reals values[i] = {Mij for j in Neighbors[i]}
149 // - a real diagonal term
150 // Temporary implementation:
151 // Assemble a pressure matrix for a hydraulic equation
152 // Inject boundary conditions into this matrix
153 // This can be done because the pressure matrix is a priori not
154 // shared between several equations on the same domain.
155
156 const Domaine_VEF& le_dom = le_dom_VEF.valeur();
157 const Domaine_Cl_VEF& le_dom_cl = le_dom_Cl_VEF.valeur();
158 les_coeff_pression.resize(le_dom_cl.nb_faces_Cl());
159 int n1 = le_dom.domaine().nb_elem_tot();
160 int n2 = le_dom.domaine().nb_elem();
161
162
163 // Add porosities.
164
165 la_matrice.typer("Matrice_Bloc"); // Actually Matrice_Bloc_Sym?
166 Matrice_Bloc& matrice=ref_cast(Matrice_Bloc, la_matrice.valeur());
167 matrice.dimensionner(2,2);
168 matrice.get_bloc(0,0).typer("Matrice_Morse_Sym");
169 matrice.get_bloc(0,1).typer("Matrice_Morse");
170 matrice.get_bloc(1,0).typer("Matrice_Morse");
171 matrice.get_bloc(1,1).typer("Matrice_Morse"); // Actually Matrice_Morse_Sym ?
172
173 Matrice_Morse_Sym& MBrr = ref_cast(Matrice_Morse_Sym,matrice.get_bloc(0,0).valeur());
174 Matrice_Morse& MBrv = ref_cast (Matrice_Morse,matrice.get_bloc(0,1).valeur());
175 Matrice_Morse& MBvr = ref_cast (Matrice_Morse, matrice.get_bloc(1,0).valeur());
176 Matrice_Morse& MBvv = ref_cast (Matrice_Morse, matrice.get_bloc(1,1).valeur());
177
178 MBrr.dimensionner(n2,0);
179 MBrv.dimensionner(n2,0);
180 MBvv.dimensionner(n1-n2,0);
181 // The sub-block vr is sized and set to zero
182 MBvr.dimensionner(n1-n2,n2,0);
183 MBvr.get_set_tab1() = 1;
184
185 // Process internal faces:
186 int ndeb = le_dom_VEF->premiere_face_int();
187 int nfin = le_dom_VEF->nb_faces_tot();
188 int nb_faces = le_dom_VEF->nb_faces();
189
190#ifdef TRUST_USE_GPU
191 ArrOfTID rang_voisinRR(n2);
192 ArrOfTID rang_voisinRV(n2);
193 ArrOfTID rang_voisinVV(n1-n2);
194#else
195 ArrOfInt rang_voisinRR(n2);
196 ArrOfInt rang_voisinRV(n2);
197 ArrOfInt rang_voisinVV(n1-n2);
198#endif
199 rang_voisinRR=1; // Diagonale
200 rang_voisinRV=0; // No diagonal
201 rang_voisinVV=1; // Diagonale
202
203 CIntTabView face_voisins = le_dom.face_voisins().view_ro();
204 CIntArrView ind_faces_virt_bord = le_dom_VEF->ind_faces_virt_bord().view_ro();
205 auto rang_voisinRR_v = rang_voisinRR.view_rw();
206 auto rang_voisinRV_v = rang_voisinRV.view_rw();
207 auto rang_voisinVV_v = rang_voisinVV.view_rw();
208 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__), range_1D(ndeb, nfin), KOKKOS_LAMBDA(const int num_face)
209 {
210 int elem1 = face_voisins(num_face, 0);
211 int elem2 = face_voisins(num_face, 1);
212 const bool is_face_virt_bord = (num_face >= nb_faces) && (ind_faces_virt_bord(num_face - nb_faces) != -1);
213 if (!is_face_virt_bord && elem1 != -1 && elem2 != -1)
214 {
215 if (elem1 > elem2)
216 {
217 if(elem1 < n2)
218 Kokkos::atomic_add(&rang_voisinRR_v(elem2), 1);
219 else
220 {
221 if(elem2 < n2)
222 Kokkos::atomic_add(&rang_voisinRV_v(elem2), 1);
223 else
224 Kokkos::atomic_add(&rang_voisinVV_v(elem2 - n2), 1);
225 }
226 }
227 else // elem2 >= elem1
228 {
229 if(elem2 < n2)
230 Kokkos::atomic_add(&rang_voisinRR_v(elem1), 1);
231 else
232 {
233 if(elem1 < n2)
234 Kokkos::atomic_add(&rang_voisinRV_v(elem1), 1);
235 else
236 Kokkos::atomic_add(&rang_voisinVV_v(elem1 - n2), 1);
237 }
238 }
239 }
240 });
241 end_gpu_timer(__KERNEL_NAME__);
242
243 // Account for periodic boundary conditions
244 const Conds_lim& les_cl = le_dom_cl.les_conditions_limites();
245 for (int i=0; i<les_cl.size(); i++)
246 {
247 const Cond_lim& la_cl = les_cl[i];
248
249 if (sub_type(Periodique,la_cl.valeur()))
250 {
251 const Periodique& la_cl_perio = ref_cast(Periodique,la_cl.valeur());
252 const Front_VF& le_bord = ref_cast(Front_VF,la_cl->frontiere_dis());
253 int nb_faces_bord_tot = le_bord.nb_faces_tot();
254 CIntArrView front_num_face = le_bord.num_face().view_ro();
255 CIntArrView face_associee = la_cl_perio.face_associee().view_ro();
256 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__), range_1D(0, nb_faces_bord_tot), KOKKOS_LAMBDA(const int ind_face)
257 {
258 if (ind_face < face_associee(ind_face)) // Process each periodic pair once
259 {
260 int num_face = front_num_face(ind_face);
261 int elem1 = face_voisins(num_face, 0);
262 int elem2 = face_voisins(num_face, 1);
263 if (elem1 != -1 && elem2 != -1)
264 {
265 if (elem1 > elem2)
266 {
267 if(elem1 < n2)
268 Kokkos::atomic_add(&rang_voisinRR_v(elem2), 1);
269 else
270 {
271 if(elem2 < n2)
272 Kokkos::atomic_add(&rang_voisinRV_v(elem2), 1);
273 else
274 Kokkos::atomic_add(&rang_voisinVV_v(elem2 - n2), 1);
275 }
276 }
277 else // elem2 >= elem1
278 {
279 if(elem2 < n2)
280 Kokkos::atomic_add(&rang_voisinRR_v(elem1), 1);
281 else
282 {
283 if(elem1 < n2)
284 Kokkos::atomic_add(&rang_voisinRV_v(elem1), 1);
285 else
286 Kokkos::atomic_add(&rang_voisinVV_v(elem1 - n2), 1);
287 }
288 }
289 }
290 }
291 });
292 end_gpu_timer(__KERNEL_NAME__);
293 }
294 }
295
296 auto& tab1RR = MBrr.get_set_tab1();
297 auto& tab2RR = MBrr.get_set_tab2();
298 auto& tab1RV = MBrv.get_set_tab1();
299 auto& tab2RV = MBrv.get_set_tab2();
300 auto& tab1VV = MBvv.get_set_tab1();
301 auto& tab2VV = MBvv.get_set_tab2();
302
303 tab1RR(0)=1;
304 tab1RV(0)=1;
305 tab1VV(0)=1;
306 auto tab1RR_v = tab1RR.view_rw();
307 auto tab1RV_v = tab1RV.view_rw();
308 auto tab1VV_v = tab1VV.view_rw();
309 using tab1_value_t = typename decltype(tab1RR_v)::value_type;
310 Kokkos::parallel_scan(start_gpu_timer(__KERNEL_NAME__), range_1D(0, n2), KOKKOS_LAMBDA(const int i, tab1_value_t& update, const bool final)
311 {
312 update += rang_voisinRR_v(i);
313 if (final) tab1RR_v(i+1) = update + 1;
314 });
315 end_gpu_timer(__KERNEL_NAME__);
316 Kokkos::parallel_scan(start_gpu_timer(__KERNEL_NAME__), range_1D(0, n2), KOKKOS_LAMBDA(const int i, tab1_value_t& update, const bool final)
317 {
318 update += rang_voisinRV_v(i);
319 if (final) tab1RV_v(i+1) = update + 1;
320 });
321 end_gpu_timer(__KERNEL_NAME__);
322 Kokkos::parallel_scan(start_gpu_timer(__KERNEL_NAME__), range_1D(0, n1-n2), KOKKOS_LAMBDA(const int i, tab1_value_t& update, const bool final)
323 {
324 update += rang_voisinVV_v(i);
325 if (final) tab1VV_v(i+1) = update + 1;
326 });
327 end_gpu_timer(__KERNEL_NAME__);
328 MBrr.dimensionner(n2,tab1RR(n2)-1);
329 MBrv.dimensionner(n2,n1-n2,tab1RV(n2)-1);
330 MBvv.dimensionner(n1-n2,n1-n2,tab1VV(n1-n2)-1);
331
332 auto tab2RR_v = tab2RR.view_rw();
333 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__), range_1D(0, n2), KOKKOS_LAMBDA(const int i)
334 {
335 tab2RR_v(tab1RR_v(i) - 1) = i+1; // Diagonale
336 rang_voisinRR_v(i) = tab1RR_v(i);
337 rang_voisinRV_v(i) = tab1RV_v(i) - 1;
338 });
339 end_gpu_timer(__KERNEL_NAME__);
340 auto tab2VV_v = tab2VV.view_rw();
341 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__), range_1D(0, n1-n2), KOKKOS_LAMBDA(const int i)
342 {
343 tab2VV_v(tab1VV_v(i) - 1) = i+1; // Diagonale
344 rang_voisinVV_v(i) = tab1VV_v(i);
345 });
346 end_gpu_timer(__KERNEL_NAME__);
347
348 int dim = Objet_U::dimension;
349
350 MBrr.dimensionner(n2,tab1RR(n2)-1);
351 MBrv.dimensionner(n2,n1-n2,tab1RV(n2)-1);
352 MBvv.dimensionner(n1-n2,n1-n2,tab1VV(n1-n2)-1);
353
354 auto tab2RV_v = tab2RV.view_rw();
355 DoubleArrView coeffRR = MBrr.get_set_coeff().view_rw();
356 DoubleArrView coeffRV = MBrv.get_set_coeff().view_rw();
357 DoubleArrView coeffVV = MBvv.get_set_coeff().view_rw();
358 CDoubleTabView face_normales = le_dom.face_normales().view_ro();
359 CDoubleTabView inverse_quantitee_entrelacee_v = inverse_quantitee_entrelacee.view_ro();
360 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__), range_1D(ndeb, nfin), KOKKOS_LAMBDA(const int num_face)
361 {
362 int elem1 = face_voisins(num_face, 0);
363 int elem2 = face_voisins(num_face, 1);
364 const bool is_face_virt_bord = (num_face >= nb_faces) && (ind_faces_virt_bord(num_face - nb_faces) != -1);
365 if (!is_face_virt_bord && elem1 != -1 && elem2 != -1)
366 {
367 double val = 0.;
368 for (int d = 0; d < dim; d++)
369 val += face_normales(num_face, d) * face_normales(num_face, d) * inverse_quantitee_entrelacee_v(num_face, d);
370
371 // diagonale :
372 if (elem1 < n2) Kokkos::atomic_add(&coeffRR(tab1RR_v(elem1) - 1), val);
373 else Kokkos::atomic_add(&coeffVV(tab1VV_v(elem1 - n2) - 1), val);
374 if (elem2 < n2) Kokkos::atomic_add(&coeffRR(tab1RR_v(elem2) - 1), val);
375 else Kokkos::atomic_add(&coeffVV(tab1VV_v(elem2 - n2) - 1), val);
376
377 if (elem1 > elem2)
378 {
379 if (elem1 < n2)
380 {
381 auto slot = Kokkos::atomic_fetch_add(&rang_voisinRR_v(elem2), 1);
382 tab2RR_v(slot) = elem1 + 1;
383 coeffRR(slot) -= val;
384 }
385 else
386 {
387 if (elem2 < n2)
388 {
389 auto slot = Kokkos::atomic_fetch_add(&rang_voisinRV_v(elem2), 1);
390 tab2RV_v(slot) = (elem1 - n2) + 1;
391 coeffRV(slot) -= val;
392 }
393 else
394 {
395 auto slot = Kokkos::atomic_fetch_add(&rang_voisinVV_v(elem2 - n2), 1);
396 tab2VV_v(slot) = (elem1 - n2) + 1;
397 coeffVV(slot) -= val;
398 }
399 }
400 }
401 else
402 {
403 if (elem2 < n2)
404 {
405 auto slot = Kokkos::atomic_fetch_add(&rang_voisinRR_v(elem1), 1);
406 tab2RR_v(slot) = elem2 + 1;
407 coeffRR(slot) -= val;
408 }
409 else
410 {
411 if (elem1 < n2)
412 {
413 auto slot = Kokkos::atomic_fetch_add(&rang_voisinRV_v(elem1), 1);
414 tab2RV_v(slot) = (elem2 - n2) + 1;
415 coeffRV(slot) -= val;
416 }
417 else
418 {
419 auto slot = Kokkos::atomic_fetch_add(&rang_voisinVV_v(elem1 - n2), 1);
420 tab2VV_v(slot) = (elem2 - n2) + 1;
421 coeffVV(slot) -= val;
422 }
423 }
424 }
425 }
426 });
427 end_gpu_timer(__KERNEL_NAME__);
428 // Process the boundary conditions
429 for (int i=0; i<les_cl.size(); i++)
430 {
431
432 // Treatment depends on the type of boundary condition:
433 // - For Neumann_sortie_libre or Robin_VEF conditions:
434 // compute the coefficient on the face and account for it
435 // in the diagonal term of the neighboring element.
436 // - For a BC face with any other condition: no
437 // contribution to the pressure matrix.
438
439 const Cond_lim& la_cl = les_cl[i];
440 const Front_VF& le_bord = ref_cast(Front_VF,la_cl->frontiere_dis());
441 int nb_faces_bord_tot = le_bord.nb_faces_tot();
442 if (sub_type(Neumann_sortie_libre,la_cl.valeur()) || sub_type(Robin_VEF,la_cl.valeur()) )
443 {
444 has_P_ref=1;
445 MBrr.set_est_definie(1);
446 CIntArrView front_num_face = le_bord.num_face().view_ro();
447 DoubleArrView coeff_pression = static_cast<ArrOfDouble&>(les_coeff_pression).view_rw();
448 const int coeff_pression_size = les_coeff_pression.size_array();
449 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__), range_1D(0, nb_faces_bord_tot), KOKKOS_LAMBDA(const int ind_face)
450 {
451 int num_face = front_num_face(ind_face);
452 double val = 0.;
453 for (int d = 0; d < dim; d++)
454 val += face_normales(num_face, d) * face_normales(num_face, d) * inverse_quantitee_entrelacee_v(num_face, d);
455
456 int elem = face_voisins(num_face, 0);
457 if (elem < n2) Kokkos::atomic_add(&coeffRR(tab1RR_v(elem) - 1), val);
458 else Kokkos::atomic_add(&coeffVV(tab1VV_v(elem - n2) - 1), val);
459 // Store the pressure coefficients on the real faces
460 if (num_face < coeff_pression_size)
461 coeff_pression(num_face) = val;
462 });
463 end_gpu_timer(__KERNEL_NAME__);
464 }
465 else if (sub_type(Periodique,la_cl.valeur()) )
466 {
467 const Periodique& la_cl_perio = ref_cast(Periodique,la_cl.valeur());
468 CIntArrView front_num_face_coeff = le_bord.num_face().view_ro();
469 CIntArrView face_associee_coeff = la_cl_perio.face_associee().view_ro();
470 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__), range_1D(0, nb_faces_bord_tot), KOKKOS_LAMBDA(const int ind_face)
471 {
472 if (ind_face < face_associee_coeff(ind_face)) // Process each periodic pair once
473 {
474 int num_face = front_num_face_coeff(ind_face);
475 int elem1 = face_voisins(num_face, 0);
476 int elem2 = face_voisins(num_face, 1);
477 double val = 0.;
478 for (int d = 0; d < dim; d++)
479 val += face_normales(num_face, d) * face_normales(num_face, d) * inverse_quantitee_entrelacee_v(num_face, d);
480
481 // diagonale :
482 if (elem1 < n2) Kokkos::atomic_add(&coeffRR(tab1RR_v(elem1) - 1), val);
483 else Kokkos::atomic_add(&coeffVV(tab1VV_v(elem1 - n2) - 1), val);
484 if (elem2 < n2) Kokkos::atomic_add(&coeffRR(tab1RR_v(elem2) - 1), val);
485 else Kokkos::atomic_add(&coeffVV(tab1VV_v(elem2 - n2) - 1), val);
486
487 if (elem1 > elem2)
488 {
489 if (elem1 < n2)
490 {
491 auto slot = Kokkos::atomic_fetch_add(&rang_voisinRR_v(elem2), 1);
492 tab2RR_v(slot) = elem1 + 1;
493 coeffRR(slot) -= val;
494 }
495 else
496 {
497 if (elem2 < n2)
498 {
499 auto slot = Kokkos::atomic_fetch_add(&rang_voisinRV_v(elem2), 1);
500 tab2RV_v(slot) = elem1 - n2 + 1;
501 coeffRV(slot) -= val;
502 }
503 else
504 {
505 auto slot = Kokkos::atomic_fetch_add(&rang_voisinVV_v(elem2 - n2), 1);
506 tab2VV_v(slot) = elem1 - n2 + 1;
507 coeffVV(slot) -= val;
508 }
509 }
510 }
511 else
512 {
513 if (elem2 < n2)
514 {
515 auto slot = Kokkos::atomic_fetch_add(&rang_voisinRR_v(elem1), 1);
516 tab2RR_v(slot) = elem2 + 1;
517 coeffRR(slot) -= val;
518 }
519 else
520 {
521 if (elem1 < n2)
522 {
523 auto slot = Kokkos::atomic_fetch_add(&rang_voisinRV_v(elem1), 1);
524 tab2RV_v(slot) = elem2 - n2 + 1;
525 coeffRV(slot) -= val;
526 }
527 else
528 {
529 auto slot = Kokkos::atomic_fetch_add(&rang_voisinVV_v(elem1 - n2), 1);
530 tab2VV_v(slot) = elem2 - n2 + 1;
531 coeffVV(slot) -= val;
532 }
533 }
534 }
535 }
536 });
537 end_gpu_timer(__KERNEL_NAME__);
538 }
539 }
540 has_P_ref = (int)mp_max(has_P_ref);
541 return 1;
542}
543
544/*! @brief Assembles the pressure matrix for a quasi-compressible fluid: laplacian(P) is replaced by div(grad(P)/rho).
545 *
546 * @param tab_rho Mass density array.
547 * @return Always returns 1.
548 */
549int Assembleur_P_VEF::assembler_QC(const DoubleTab& tab_rho, Matrice& matrice)
550{
551 Cerr << "Assembling pressure matrix for Quasi-Compressible in progress..." << finl;
552 int stat=assembler(matrice);
554 return stat;
555}
556
558{
559 const Domaine_VEF& le_dom = le_dom_VEF.valeur();
560 const Domaine_Cl_VEF& le_dom_cl = le_dom_Cl_VEF.valeur();
561 int nb_cond_lim = le_dom_cl.nb_cond_lim();
562 const IntTab& face_voisins = le_dom.face_voisins();
563
564 // Modification of the right-hand side:
565 for (int i=0; i<nb_cond_lim; i++)
566 {
567 const Cond_lim_base& la_cl_base = le_dom_cl.les_conditions_limites(i).valeur();
568 const Front_VF& la_front_dis = ref_cast(Front_VF,la_cl_base.frontiere_dis());
569 const Champ_front_base& champ_front = la_cl_base.champ_front();
570 int ndeb = la_front_dis.num_premiere_face();
571 int nfin = ndeb + la_front_dis.nb_faces();
572
573 // GF we switched to pressure increment
574 if ((sub_type(Neumann_sortie_libre,la_cl_base)) && (!get_resoudre_increment_pression()))
575 {
576 const Neumann_sortie_libre& la_cl_Neumann = ref_cast(Neumann_sortie_libre, la_cl_base);
577 ToDo_Kokkos("critical");
578 for (int num_face=ndeb; num_face<nfin; num_face++)
579 {
580 double Pimp = la_cl_Neumann.flux_impose(num_face-ndeb);
581 double coef = les_coeff_pression[num_face]*Pimp;
582 secmem[face_voisins(num_face,0)] += coef;
583 }
584 }
585
586 /*if ((sub_type(Robin_VEF,la_cl_base)) )
587 {
588 // [vkr/oswr] we should modify the value of increment_pression_bord in order to respect the oswr algorithm
589 double Pstar_OSWR, coef;
590 const Robin_VEF& la_cl_robin = ref_cast(Robin_VEF, la_cl_base);
591 for (int num_face=ndeb; num_face<nfin; num_face++)
592 {
593 Pstar_OSWR = la_cl_robin.increment_pression_bord(num_face);
594 coef = les_coeff_pression[num_face]*Pstar_OSWR+100;
595 Cerr << "PASSING THROUGH GET RESOUDRE INCR PRESSION" <<finl;
596 secmem[face_voisins(num_face,0)] += coef;
597 }
598 }*/
599
600 else if ( champ_front.instationnaire() && get_resoudre_en_u() )
601 {
602 const DoubleTab& Gpt = champ_front.derivee_en_temps();
603 bool ch_unif = (Gpt.nb_dim()==1);
604 ToDo_Kokkos("critical");
605 for (int num_face=ndeb; num_face<nfin; num_face++)
606 {
607 double Stt = 0.;
608 for (int k=0; k<dimension; k++)
609 {
610 double Gpoint = ch_unif ? Gpt(k) : Gpt(num_face - ndeb, k);
611 Stt -= Gpoint * le_dom.face_normales(num_face, k);
612 }
613 secmem(face_voisins(num_face,0)) += Stt;
614 }
615 }
616 }
617 secmem.echange_espace_virtuel();
618 return 1;
619}
620
622{
623 // Projection :
624 double press_0;
625 if(!has_P_ref)
626 {
627 // Take the minimum pressure as the reference pressure
628 // in order to have the same reference pressure in sequential and parallel
629 press_0=DMAXFLOAT;
630 int nb_elem=le_dom_VEF->domaine().nb_elem();
631 ToDo_Kokkos("critical");
632 for(int n=0; n<nb_elem; n++)
633 if (pression[n] < press_0)
634 press_0 = pression[n];
635 press_0 = Process::mp_min(press_0);
636 ToDo_Kokkos("critical");
637 for(int n=0; n<nb_elem; n++)
638 pression[n] -=press_0;
639
640 pression.echange_espace_virtuel();
641 }
642 return 1;
643}
644
645/*! @brief Optionally modifies the matrix to make it definite if it is not.
646 *
647 * @return 1 if the matrix is modified, 0 otherwise.
648 */
650{
651 int matrice_modifiee=0;
652 Matrice_Bloc& mat_bloc = ref_cast(Matrice_Bloc, matrice.valeur());
653 Matrice_Morse_Sym& A00RR = ref_cast(Matrice_Morse_Sym,mat_bloc.get_bloc(0,0).valeur());
654 // Find the element on which the reference pressure is imposed
655 const bool is_first_proc_with_real_elems = Process::me() == Process::mp_min(le_dom_VEF->nb_elem() ? Process::me() : 1e8);
656 if (is_first_proc_with_real_elems && !A00RR.get_est_definie())
657 {
658 int element_referent=0;
659 double distance=DMAXFLOAT;
660 const DoubleTab& coord=le_dom_VEF->xp();
661 int n = le_dom_VEF->nb_elem();
662 ToDo_Kokkos("critical");
663 for(int i=0; i<n; i++)
664 {
665 double tmp=0;
666 for (int j=0; j<dimension; j++)
667 tmp+=coord(i,j)*coord(i,j);
668 if (inf_strict(tmp,distance) && !est_egal(A00RR(i,i),0.))
669 {
670 distance=tmp;
671 element_referent=i;
672 }
673 }
674 Cerr << "Modifying the row (element) " << element_referent << finl;
675 A00RR(element_referent,element_referent)*=2;
676 matrice_modifiee=1;
677 }
678 // has_P_ref=1;
679 A00RR.set_est_definie(1);
680 return matrice_modifiee;
681}
682
684{
685 return le_dom_VEF.valeur();
686}
687
689{
690 return le_dom_Cl_VEF.valeur();
691}
692
694{
695 le_dom_VEF = ref_cast(Domaine_VEF,le_dom_dis);
696}
697
699{
700 le_dom_Cl_VEF = ref_cast(Domaine_Cl_VEF, le_dom_Cl_dis);
701}
702
704{
705 mon_equation=Eqn;
706}
int assembler_mat(Matrice &, const DoubleVect &, int, int) override
const Domaine_dis_base & domaine_dis_base() const override
virtual int modifier_matrice(Matrice &)
Optionally modifies the matrix to make it definite if it is not.
int assembler_QC(const DoubleTab &, Matrice &) override
Assembles the pressure matrix for a quasi-compressible fluid: laplacian(P) is replaced by div(grad(P)...
void calculer_inv_volume(DoubleTab &inv_volumes_entrelaces, const Domaine_Cl_VEF &domaine_Cl_VEF, const DoubleVect &volumes_entrelaces)
int modifier_solution(DoubleTab &) override
int assembler(Matrice &) override
DoubleTab les_coeff_pression
void completer(const Equation_base &) override
const Equation_base & equation() const
const Domaine_Cl_dis_base & domaine_Cl_dis_base() const override
int remplir(Matrice &, const DoubleTab &)
void associer_domaine_cl_dis_base(const Domaine_Cl_dis_base &) override
int modifier_secmem(DoubleTab &) override
void associer_domaine_dis_base(const Domaine_dis_base &) override
int get_resoudre_en_u() const
Returns the value of the resoudre_en_u_ flag (0 or 1) Returns -1 if the flag has not been initialized...
int set_resoudre_en_u(int flag)
Sets the value of the resoudre_en_u__ flag.
int get_resoudre_increment_pression() const
Returns the value of the resoudre_increment_pression_ flag (0 or 1) Returns -1 if the flag has not be...
int set_resoudre_increment_pression(int flag)
Sets the value of the resoudre_increment_pression_ flag.
class Champ_front_base Base class for the hierarchy of boundary fields.
virtual const DoubleTab & derivee_en_temps() const
virtual bool instationnaire() const
class Cond_lim_base Base class for the hierarchy of classes that represent the different boundary con...
virtual Frontiere_dis_base & frontiere_dis()
Returns the discretized boundary to which the boundary conditions apply.
Champ_front_base & champ_front()
class Cond_lim Generic class used to represent any class
Definition Cond_lim.h:31
class Conds_lim This class represents a vector of boundary conditions.
Definition Conds_lim.h:32
int_t nb_elem_tot() const
Definition Domaine.h:132
int_t nb_elem() const
Definition Domaine.h:131
class Domaine_Cl_dis_base Domaine_Cl_dis_base objects represent discretized boundary conditions
int nb_cond_lim() const
Returns the number of boundary conditions.
const Cond_lim & les_conditions_limites(int) const
Returns the i-th boundary condition.
class Domaine_VEF
Definition Domaine_VEF.h:53
virtual double face_normales(int face, int comp) const
Definition Domaine_VF.h:47
int face_voisins(int num_face, int i) const
Returns the neighbouring element of num_face in direction i.
Definition Domaine_VF.h:418
class Domaine_dis_base This class is the base of the hierarchy of discretized domains.
const Domaine & domaine() const
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
class Equation_base The role of an equation is the calculation of one or more fields....
virtual const Milieu_base & milieu() const =0
Solveur_Masse_base & solv_masse()
Returns the mass solver associated with the equation.
class Front_VF
Definition Front_VF.h:36
int nb_faces() const
Definition Front_VF.h:53
int num_premiere_face() const
Definition Front_VF.h:63
int nb_faces_tot() const
Definition Front_VF.h:58
int num_face(const int) const
Definition Front_VF.h:68
virtual void dimensionner(int N, int M)
virtual const Matrice & get_bloc(int i, int j) const
Matrice_Morse_Sym class - Represents a sparse symmetric matrix M stored in Morse format.
Matrice_Morse class - Represents a (sparse) matrix M, not necessarily square,.
auto & get_set_tab2()
void dimensionner(int n, _SIZE_ nnz)
Size the matrix with n lines and n columns and nnz zero-values coefficients.
auto & get_set_coeff()
auto & get_set_tab1()
void set_est_definie(int)
int get_est_definie() const
Matrice class - Generic class in the matrix hierarchy.
Definition Matrice.h:34
DoubleVect & porosite_face()
Definition Milieu_base.h:62
const Equation_base & equation() const
Returns the reference to the equation pointed to by MorEqn::mon_equation.
Definition MorEqn.h:62
Neumann_sortie_libre This class represents an open boundary without imposed velocity.
virtual double flux_impose(int i) const
Returns the value of the imposed flux on the i-th component of the field representing the flux at the...
Definition Neumann.cpp:35
static int dimension
Definition Objet_U.h:94
const Nom & que_suis_je() const
Returns the string identifying the class.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
Definition Objet_U.cpp:289
virtual const Nom & le_nom() const
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this implementation.
Definition Objet_U.cpp:317
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
class Periodique This class represents a periodic boundary condition.
Definition Periodique.h:31
int face_associee(int i) const
Definition Periodique.h:35
static double mp_min(double)
Definition Process.cpp:391
static double mp_max(double)
Definition Process.cpp:379
static int me()
Returns the rank of the local processor in the current communication group. See Comm_Group::rank() an...
Definition Process.cpp:122
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
Class Robin_VEF for Robin boundary conditions.
Definition Robin_VEF.h:44
virtual DoubleTab & appliquer(DoubleTab &) const
Returns appliquer_impl(x/temporal_coefficient) if a temporal coefficient is set, otherwise returns ap...
Base class for output streams.
Definition Sortie.h:52
int nb_dim() const
Definition TRUSTTab.h:199
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:469
_SIZE_ dimension_tot(int) const override
Definition TRUSTTab.tpp:160
std::enable_if_t< is_default_exec_space< EXEC_SPACE >, ConstView< _TYPE_, _SHAPE_ > > view_ro() const
Definition TRUSTTab.h:261
std::enable_if_t< is_default_exec_space< EXEC_SPACE >, View< _TYPE_, _SHAPE_ > > view_rw()
Definition TRUSTTab.h:291
_SIZE_ size() const
Definition TRUSTVect.tpp:45
_SIZE_ size_totale() const
Definition TRUSTVect.tpp:61
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")