TrioCFD 1.9.8
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 // Si rho est constant, on resout avec la pression 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 // On assemble la matrice
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 // maintenant l 'inverse du volume est un DoubleTab
82 // c'est pour faire fonctionner le Piso
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 // cette facon de calculer le volume entrelace pourra etre bonne dans
94 // l'avenir a condition de reflechir au pb des porosites
95 // et SURTOUT au pb du simpler ou l'on ne veut pas passer par la
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 // On fixe les drapeaux de 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 // Matrice de pression :matrice creuse de taille nb_poly x nb_poly
142 // Cette fonction range la matrice dans une structure de matrice morse
143 // bien adaptee aux matrices creuses.
144 // On commence par calculer les tailles des tableaux tab1 et tab2
145 // (coeff_ a la meme taille que tab2)
146 // A chaque polyedre on associe :
147 // - une liste d'entiers voisins[i] = {j>i t.q Mij est non nul }
148 // - une liste de reels valeurs[i] = {Mij pour j dans Voisins[i]}
149 // - un reel terme_diag
150 // Implementation temporaire:
151 // On assemble une matrice de pression pour une equation d'hydraulique
152 // On injecte dans cette matrice les conditions aux limites
153 // On peut faire cela car a priori la matrice de pression n'est pas
154 // partagee par plusieurs equations sur une meme domaine.
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 // Rajout des porosites.
164
165 la_matrice.typer("Matrice_Bloc"); // En fait 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"); // En fait 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 // Le sous blocs vr est dimensionne et nul
182 MBvr.dimensionner(n1-n2,n2,0);
183 MBvr.get_set_tab1() = 1;
184
185 // On traite les faces internes:
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; // Pas de diagonale
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 // Prise en compte des conditions de type periodicite
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 // On traite les conditions aux limites
429 for (int i=0; i<les_cl.size(); i++)
430 {
431
432 // Le traitement depend du type de la condition aux limites :
433 // - Si condition de Neumann_sortie_libre ou Robin_VEF
434 // il faut calculer le coefficient sur la face et le prendre
435 // en compte dans le terme diagonal associe a l'element voisin.
436 // - Si face de Cl avec une autre condition aux limites pas de
437 // contribution a la matrice de pression.
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 // On stocke les coefficients de pression sur les faces reelles
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 Assemble la matrice de pression pour un fluide quasi compressible laplacein(P) est remplace par div(grad(P)/rho).
545 *
546 * @param (DoubleTab& tab_rho) mass volumique
547 * @return (int) renvoie toujours 1
548 */
549int Assembleur_P_VEF::assembler_QC(const DoubleTab& tab_rho, Matrice& matrice)
550{
551 Cerr << "Assemblage de la matrice de pression pour Quasi Compressible en cours..." << 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 du second membre :
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 on est passe en increment de pression
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 << "PASSAGE PAR 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 // On prend la pression minimale comme pression de reference
628 // afin d'avoir la meme pression de reference en sequentiel et parallele
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 Modifier eventuellement la matrice pour la rendre definie si elle ne l'est pas Valeurs par defaut:
646 *
647 * Contraintes:
648 * Acces: entree
649 *
650 * @return (int) renvoie 1 si la matrice est modifiee 0 sinon
651 */
653{
654 int matrice_modifiee=0;
655 Matrice_Bloc& mat_bloc = ref_cast(Matrice_Bloc, matrice.valeur());
656 Matrice_Morse_Sym& A00RR = ref_cast(Matrice_Morse_Sym,mat_bloc.get_bloc(0,0).valeur());
657 // Recherche de l'element sur lequel on impose la pression de reference
658 const bool is_first_proc_with_real_elems = Process::me() == Process::mp_min(le_dom_VEF->nb_elem() ? Process::me() : 1e8);
659 if (is_first_proc_with_real_elems && !A00RR.get_est_definie())
660 {
661 int element_referent=0;
662 double distance=DMAXFLOAT;
663 const DoubleTab& coord=le_dom_VEF->xp();
664 int n = le_dom_VEF->nb_elem();
665 ToDo_Kokkos("critical");
666 for(int i=0; i<n; i++)
667 {
668 double tmp=0;
669 for (int j=0; j<dimension; j++)
670 tmp+=coord(i,j)*coord(i,j);
671 if (inf_strict(tmp,distance) && !est_egal(A00RR(i,i),0.))
672 {
673 distance=tmp;
674 element_referent=i;
675 }
676 }
677 Cerr << "On modifie la ligne (element) " << element_referent << finl;
678 A00RR(element_referent,element_referent)*=2;
679 matrice_modifiee=1;
680 }
681 // has_P_ref=1;
682 A00RR.set_est_definie(1);
683 return matrice_modifiee;
684}
685
687{
688 return le_dom_VEF.valeur();
689}
690
692{
693 return le_dom_Cl_VEF.valeur();
694}
695
697{
698 le_dom_VEF = ref_cast(Domaine_VEF,le_dom_dis);
699}
700
702{
703 le_dom_Cl_VEF = ref_cast(Domaine_Cl_VEF, le_dom_Cl_dis);
704}
705
707{
708 mon_equation=Eqn;
709}
int assembler_mat(Matrice &, const DoubleVect &, int, int) override
const Domaine_dis_base & domaine_dis_base() const override
virtual int modifier_matrice(Matrice &)
Modifier eventuellement la matrice pour la rendre definie si elle ne l'est pas Valeurs par defaut:
int assembler_QC(const DoubleTab &, Matrice &) override
Assemble la matrice de pression pour un fluide quasi compressible laplacein(P) est remplace par div(g...
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
Renvoie la valeur du drapeau resoudre_en_u_ (0 ou 1) Renvoie -1 si le drapeau n'a pas ete initialise.
int set_resoudre_en_u(int flag)
Definit la valeur du drapeau resoudre_en_u__.
int get_resoudre_increment_pression() const
Renvoie la valeur du drapeau resoudre_increment_pression_ (0 ou 1) Renvoie -1 si le drapeau n'a pas e...
int set_resoudre_increment_pression(int flag)
Definit la valeur du drapeau resoudre_increment_pression_.
classe Champ_front_base Classe de base pour la hierarchie des champs aux frontieres.
virtual const DoubleTab & derivee_en_temps() const
virtual bool instationnaire() const
classe Cond_lim_base Classe de base pour la hierarchie des classes qui representent les differentes c...
virtual Frontiere_dis_base & frontiere_dis()
Renvoie la frontiere discretisee a laquelle les conditions aux limites s'appliquent.
Champ_front_base & champ_front()
classe Cond_lim Classe generique servant a representer n'importe quelle classe
Definition Cond_lim.h:31
classe Conds_lim Cette classe represente un vecteur de conditions aux limites.
Definition Conds_lim.h:32
int_t nb_elem_tot() const
Definition Domaine.h:132
int_t nb_elem() const
Definition Domaine.h:131
classe Domaine_Cl_dis_base Les objets Domaine_Cl_dis_base representent les conditions aux limites
int nb_cond_lim() const
Renvoie le nombre de conditions aux limites.
const Cond_lim & les_conditions_limites(int) const
Renvoie la i-ieme condition aux limites.
class Domaine_VEF
Definition Domaine_VEF.h:54
virtual double face_normales(int face, int comp) const
Definition Domaine_VF.h:47
int face_voisins(int num_face, int i) const
renvoie l'element voisin de numface dans la direction i.
Definition Domaine_VF.h:418
classe Domaine_dis_base Cette classe est la base de la hierarchie des domaines discretisees.
const Domaine & domaine() const
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
classe Equation_base Le role d'une equation est le calcul d'un ou plusieurs champs....
virtual const Milieu_base & milieu() const =0
Solveur_Masse_base & solv_masse()
Renvoie le solveur de masse associe a l'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
Classe Matrice_Morse_Sym Represente une matrice M (creuse) symetrique stockee au format Morse.
Classe Matrice_Morse Represente une matrice M (creuse), non necessairement carree.
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
Classe Matrice Classe generique de la hierarchie des matrices.
Definition Matrice.h:34
DoubleVect & porosite_face()
Definition Milieu_base.h:62
const Equation_base & equation() const
Renvoie la reference sur l'equation pointe par MorEqn::mon_equation.
Definition MorEqn.h:62
classe Neumann_sortie_libre Cette classe represente une frontiere ouverte sans vitesse imposee
virtual double flux_impose(int i) const
Renvoie la valeur du flux impose sur la i-eme composante du champ representant le flux a la frontiere...
Definition Neumann.cpp:35
static int dimension
Definition Objet_U.h:99
const Nom & que_suis_je() const
renvoie la chaine identifiant la classe.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
Definition Objet_U.cpp:293
virtual const Nom & le_nom() const
Donne le nom de l'Objet_U Methode a surcharger : renvoie "neant" dans cette implementation.
Definition Objet_U.cpp:319
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
classe Periodique Cette classe represente une condition aux limites periodique.
Definition Periodique.h:31
int face_associee(int i) const
Definition Periodique.h:35
static double mp_min(double)
Definition Process.cpp:386
static double mp_max(double)
Definition Process.cpp:376
static int me()
renvoie mon rang dans le groupe de communication courant.
Definition Process.cpp:125
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
Class Robin_VEF for Robin boundary conditions.
Definition Robin_VEF.h:44
virtual DoubleTab & appliquer(DoubleTab &) const
renvoie appliquer_impl(x/coeffient_temporelle) si on a un coefficient temporel sinon renvoie applique...
Classe de base des flux de sortie.
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")