TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Assembleur_P_PolyMAC_MPFA.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_PolyMAC_MPFA.h>
17#include <Op_Grad_PolyMAC_MPFA_Face.h>
18#include <Neumann_sortie_libre.h>
19#include <Champ_Face_PolyMAC_MPFA.h>
20#include <Masse_PolyMAC_MPFA_Face.h>
21#include <Domaine_PolyMAC_MPFA.h>
22#include <Domaine_Cl_PolyMAC_family.h>
23#include <Matrice_Diagonale.h>
24#include <Navier_Stokes_std.h>
25#include <Matrice_Morse_Sym.h>
26#include <Schema_Temps_base.h>
27#include <Matrice_Bloc_Sym.h>
28#include <Static_Int_Lists.h>
29#include <Operateur_Grad.h>
30#include <Pb_Multiphase.h>
31#include <Matrix_tools.h>
32#include <Array_tools.h>
33#include <Dirichlet.h>
34#include <Debog.h>
35#include <Piso.h>
36#include <Perf_counters.h>
37
38Implemente_instanciable(Assembleur_P_PolyMAC_MPFA, "Assembleur_P_PolyMAC_MPFA", Assembleur_P_PolyMAC_HFV);
39
40Sortie& Assembleur_P_PolyMAC_MPFA::printOn(Sortie& s) const { return s << que_suis_je() << " " << le_nom(); }
41
43
44int Assembleur_P_PolyMAC_MPFA::assembler_mat(Matrice& la_matrice,const DoubleVect& diag,int incr_pression,int resoudre_en_u)
45{
47 set_resoudre_en_u(resoudre_en_u);
48 Cerr << "Assemblage de la matrice de pression ... ";
49 statistics().begin_count(STD_COUNTERS::matrix_assembly,statistics().get_last_opened_counter_level()+1);
50 la_matrice.typer("Matrice_Morse");
51 Matrice_Morse& mat = ref_cast(Matrice_Morse, la_matrice.valeur());
52
53 const Domaine_PolyMAC_MPFA& domaine = ref_cast(Domaine_PolyMAC_MPFA, le_dom_PolyMAC_CDO.valeur());
54 const Op_Grad_PolyMAC_MPFA_Face& grad = ref_cast(Op_Grad_PolyMAC_MPFA_Face, ref_cast(Navier_Stokes_std, equation()).operateur_gradient().valeur());
55 grad.update_grad(domaine.domaine().deformable());
56 const DoubleTab& fgrad_c = grad.fgrad_c;
57 const IntTab& f_e = domaine.face_voisins(), &fgrad_d = grad.fgrad_d, &fgrad_e = grad.fgrad_e;
58 const DoubleVect& pf = equation().milieu().porosite_face(), &fs = domaine.face_surfaces();
59 int i, j, e, eb, f, ne = domaine.nb_elem(), ne_tot = domaine.nb_elem_tot();
60
61 //en l'absence de CLs en pression, on ajoute P(0) = 0 sur le process 0
62 has_P_ref=0;
63 for (int n_bord=0; n_bord<le_dom_PolyMAC_CDO->nb_front_Cl(); n_bord++)
64 if (sub_type(Neumann_sortie_libre, le_dom_Cl_PolyMAC_CDO->les_conditions_limites(n_bord).valeur()) )
65 has_P_ref=1;
66
67 /* 1. stencil de la matrice en pression : seulement au premier passage */
68 if (!stencil_done)
69 {
70 Stencil stencil(0, 2);
71
72 for (f = 0; f < domaine.nb_faces(); f++)
73 for (i = 0; i < 2 && (e = f_e(f, i)) >= 0; i++)
74 if (e < ne)
75 for (j = fgrad_d(f); j < fgrad_d(f + 1); j++)
76 if ((eb = fgrad_e(j)) < ne_tot) stencil.append_line(e, eb);
77
78 tableau_trier_retirer_doublons(stencil);
79 Matrix_tools::allocate_morse_matrix(ne_tot, ne_tot, stencil, mat);
80 mat.sort_stencil();
81 tab1.ref_array(mat.get_set_tab1()), tab2.ref_array(mat.get_set_tab2());
82 stencil_done = 1;
83 }
84 else //sinon, on recycle
85 {
86 mat.get_set_tab1().ref_array(tab1);
87 mat.get_set_tab2().ref_array(tab2);
88 mat.get_set_coeff().resize(tab2.size_array());
89 mat.set_nb_columns(ne_tot);
90 }
91
92 /* 2. remplissage des coefficients : style Op_Diff_PolyMAC_HFV_Elem */
93 for (f = 0; f < domaine.nb_faces(); f++)
94 for (i = 0; i < 2 && (e = f_e(f, i)) >= 0; i++)
95 if (e < ne)
96 for (j = fgrad_d(f); j < fgrad_d(f + 1); j++)
97 if ((eb = fgrad_e(j)) < ne_tot)
98 mat(e, eb) += (i ? 1 : -1) * pf(f) * fs(f) * fgrad_c(j, 0);
99
100 const bool is_first_proc_with_real_elems = Process::me() == Process::mp_min(domaine.nb_elem() ? Process::me() : 1e8);
101 if (!has_P_ref && is_first_proc_with_real_elems) mat(0, 0) *= 2;
102 statistics().end_count(STD_COUNTERS::matrix_assembly);
103 return 1;
104}
105
106/* equation sum_k alpha_k = 1 en Pb_Multiphase */
107void Assembleur_P_PolyMAC_MPFA::dimensionner_continuite(matrices_t matrices, int aux_only) const
108{
109 if (aux_only) return; //rien a faire
110 int e, n, N = ref_cast(Pb_Multiphase, equation().probleme()).nb_phases(), ne_tot = le_dom_PolyMAC_CDO->nb_elem_tot();
111 Stencil stencil(0, 2);
112
113 for (e = 0; e < le_dom_PolyMAC_CDO->nb_elem(); e++)
114 for (n = 0; n < N; n++) stencil.append_line(e, N * e + n);
115 Matrix_tools::allocate_morse_matrix(ne_tot, N * ne_tot, stencil, *matrices.at("alpha"));
116}
117
118void Assembleur_P_PolyMAC_MPFA::assembler_continuite(matrices_t matrices, DoubleTab& secmem, int aux_only) const
119{
120 if (aux_only) return;
121 const DoubleTab& alpha = ref_cast(Pb_Multiphase, equation().probleme()).equation_masse().inconnue().valeurs();
122 Matrice_Morse& mat = *matrices.at("alpha");
123 const DoubleVect& ve = le_dom_PolyMAC_CDO->volumes(), &pe = equation().milieu().porosite_elem();
124 int e, n, N = alpha.line_size();
125 /* second membre : on multiplie par porosite * volume pour que le systeme en P soit symetrique en cartesien */
126 for (e = 0; e < le_dom_PolyMAC_CDO->nb_elem(); e++)
127 for (secmem(e) = -pe(e) * ve(e), n = 0; n < N; n++) secmem(e) += pe(e) * ve(e) * alpha(e, n);
128 /* matrice */
129 for (e = 0; e < le_dom_PolyMAC_CDO->nb_elem(); e++)
130 for (n = 0; n < N; n++) mat(e, N * e + n) = -pe(e) * ve(e);
131}
const Equation_base & equation() const
void dimensionner_continuite(matrices_t matrices, int aux_only=0) const override
void assembler_continuite(matrices_t matrices, DoubleTab &secmem, int aux_only=0) const override
int assembler_mat(Matrice &, const DoubleVect &, int incr_pression, int resoudre_en_u) override
int set_resoudre_en_u(int flag)
Definit la valeur du drapeau resoudre_en_u__.
int set_resoudre_increment_pression(int flag)
Definit la valeur du drapeau resoudre_increment_pression_.
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
virtual const Milieu_base & milieu() const =0
Classe Matrice_Morse Represente une matrice M (creuse), non necessairement carree.
auto & get_set_tab2()
void set_nb_columns(const int)
auto & get_set_coeff()
auto & get_set_tab1()
Classe Matrice Classe generique de la hierarchie des matrices.
Definition Matrice.h:34
static void allocate_morse_matrix(const int nb_lines, const int nb_columns, const Stencil &stencil, Matrice_Morse &matrix, const bool &attach_stencil_to_matrix=false)
DoubleVect & porosite_elem()
Definition Milieu_base.h:58
DoubleVect & porosite_face()
Definition Milieu_base.h:62
classe Navier_Stokes_std Cette classe porte les termes de l'equation de la dynamique
classe Neumann_sortie_libre Cette classe represente une frontiere ouverte sans vitesse imposee
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
class Op_Grad_PolyMAC_MPFA_Face
void update_grad(int full_stencil=0) const
classe Pb_Multiphase Cette classe represente un probleme de thermohydraulique multiphase de type "3*N...
static double mp_min(double)
Definition Process.cpp:386
static int me()
renvoie mon rang dans le groupe de communication courant.
Definition Process.cpp:125
Classe de base des flux de sortie.
Definition Sortie.h:52
void append_line(_TYPE_)
Definition TRUSTTab.tpp:213
int line_size() const
Definition TRUSTVect.tpp:67