TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Assembleur_P_PolyMAC_CDO.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 <Neumann_sortie_libre.h>
17#include <Assembleur_P_PolyMAC_CDO.h>
18#include <Domaine_Cl_PolyMAC_family.h>
19#include <Champ_Face_PolyMAC_CDO.h>
20#include <Matrice_Diagonale.h>
21#include <Matrice_Morse_Sym.h>
22#include <Matrice_Bloc_Sym.h>
23#include <Static_Int_Lists.h>
24#include <Domaine_PolyMAC_CDO.h>
25#include <TRUSTTab_parts.h>
26#include <Operateur_Grad.h>
27#include <Matrix_tools.h>
28#include <Milieu_base.h>
29#include <Array_tools.h>
30#include <Dirichlet.h>
31#include <Debog.h>
32#include <Perf_counters.h>
33
34Implemente_instanciable(Assembleur_P_PolyMAC_CDO,"Assembleur_P_PolyMAC_CDO",Assembleur_base);
35
36Sortie& Assembleur_P_PolyMAC_CDO::printOn(Sortie& s) const { return s << que_suis_je() << " " << le_nom(); }
37
39
41{
42 DoubleVect rien;
43 return assembler_mat(la_matrice, rien, 1, 1);
44}
45
47{
48 abort();
49 return 0;
50}
51
52int Assembleur_P_PolyMAC_CDO::assembler_mat(Matrice& la_matrice, const DoubleVect& diag, int incr_pression, int resoudre_en_u)
53{
55 set_resoudre_en_u(resoudre_en_u);
56 Cerr << "Assemblage de la matrice de pression ... ";
57 statistics().begin_count(STD_COUNTERS::matrix_assembly,statistics().get_last_opened_counter_level()+1);
58 la_matrice.typer("Matrice_Morse");
59 Matrice_Morse& mat = ref_cast(Matrice_Morse, la_matrice.valeur());
60
61 const Domaine_PolyMAC_CDO& domaine = ref_cast(Domaine_PolyMAC_CDO, le_dom_PolyMAC_CDO.valeur());
62 const IntTab& e_f = domaine.elem_faces(), &f_e = domaine.face_voisins();
63 const DoubleVect& fs = domaine.face_surfaces(), &pf = mon_equation->milieu().porosite_face(), &pe = mon_equation->milieu().porosite_elem(), &ve = domaine.volumes();
64 const Champ_Face_PolyMAC_CDO& ch = ref_cast(Champ_Face_PolyMAC_CDO, mon_equation->inconnue());
65 int i, j, k, e, f, fb, n_f, ne = domaine.nb_elem(), ne_tot = domaine.nb_elem_tot(), nf = domaine.nb_faces(), nf_tot = domaine.nb_faces_tot(), na_tot =
66 dimension < 3 ? domaine.domaine().nb_som_tot() : domaine.domaine().nb_aretes_tot(), infoo=-1;
67 domaine.init_m2(), ch.fcl();
68
69 DoubleTrav W(e_f.dimension(1), e_f.dimension(1)), W0(e_f.dimension(1), e_f.dimension(1));
70
71
72 //in the absence of pressure BCs, we add P(0) = 0 on process 0
73 has_P_ref = 0;
74 for (int n_bord = 0; n_bord < le_dom_PolyMAC_CDO->nb_front_Cl(); n_bord++)
75 if (sub_type(Neumann_sortie_libre, le_dom_Cl_PolyMAC_CDO->les_conditions_limites(n_bord).valeur()))
76 has_P_ref = 1;
77
78 /* 1. pressure matrix stencil and rec stencil: only on the first pass */
79 if (!stencil_done)
80 {
81 Stencil stencil_M(0, 2), stencil_R(0, 2);
82
83 for (e = 0; e < ne_tot; e++)
84 {
85 for (i = 0, j = domaine.m2d(e), n_f = domaine.m2d(e + 1) - domaine.m2d(e); i < n_f; i++, j++)
86 {
87 for (k = domaine.w2i(j), f = e_f(e, i); f < nf && k < domaine.w2i(j + 1); k++)
88 {
89 fb = e_f(e, domaine.w2j(k));
90 stencil_M.append_line(ne_tot + f, ne_tot + fb);
91 if (e == f_e(f, 0))
92 stencil_R.append_line(f, ne_tot + fb);
93 }
94 if (ch.fcl()(f, 0) != 1 && e < ne)
95 stencil_M.append_line(e, ne_tot + f);
96 if (ch.fcl()(f, 0) != 1 && f < nf)
97 stencil_M.append_line(ne_tot + f, e);
98 if (e == f_e(f, 0) && f < nf)
99 stencil_R.append_line(f, e);
100 }
101 if (e < ne)
102 stencil_M.append_line(e, e);
103 // if (!has_P_ref && !Process::me() && e < ne) stencil_M.append_line(0, e);
104 }
105
106 tableau_trier_retirer_doublons(stencil_M), tableau_trier_retirer_doublons(stencil_R);
107 Matrix_tools::allocate_morse_matrix(ne_tot + nf_tot, ne_tot + nf_tot, stencil_M, mat);
108 Matrix_tools::allocate_morse_matrix(nf_tot + na_tot, ne_tot + nf_tot, stencil_R, rec);
109 tab1.ref_array(mat.get_set_tab1()), tab2.ref_array(mat.get_set_tab2());
110 stencil_done = 1;
111 }
112 else //otherwise, reuse existing
113 {
114 mat.get_set_tab1().ref_array(tab1);
115 mat.get_set_tab2().ref_array(tab2);
116 mat.get_set_coeff().resize(tab2.size_array());
117 mat.set_nb_columns(ne_tot + nf_tot);
118 rec.get_set_coeff() = 0;
119 }
120
121 /* 2. fill the coefficients */
122 for (e = 0; e < ne_tot; e++)
123 {
124 n_f = domaine.m2d(e + 1) - domaine.m2d(e), W0.resize(n_f, n_f), W.resize(n_f, n_f);
125 for (i = 0, j = domaine.m2d(e), W0 = 0; i < n_f; i++, j++)
126 for (k = domaine.w2i(j); k < domaine.w2i(j + 1); k++)
127 W0(i, domaine.w2j(k)) = domaine.w2c(k);
128 if (!diag.size())
129 W = W0; //no diagonal correction -> take W as is
130 else //diagonal correction -> re-invert m2 + diag
131 {
132 //matrix m2 + diagonal correction
133 for (i = 0, j = domaine.m2d(e), W = 0; i < n_f; i++, j++)
134 for (k = domaine.m2i(j); k < domaine.m2i(j + 1); k++)
135 W(i, domaine.m2j(k)) = domaine.m2c(k);
136 for (i = 0; i < n_f; i++)
137 f = e_f(e, i), W(i, i) += diag(f) * domaine.volumes_entrelaces_dir()(f, e != f_e(f, 0)) / domaine.volumes_entrelaces(f) / ve(e);
138 //Cholesky inversion (Lapack) + zeroing small coefficients + manual fill of lower triangular part
139 char uplo = 'U';
140 F77NAME(dpotrf)(&uplo, &n_f, W.addr(), &n_f, &infoo);
141 F77NAME(dpotri)(&uplo, &n_f, W.addr(), &n_f, &infoo);
142 for (i = 0; i < n_f; i++)
143 for (j = i + 1; j < n_f; j++)
144 W(i, j) = W(j, i);
145 for (i = 0; i < n_f; i++)
146 for (j = 0; j < n_f; j++)
147 if (W0(i, j) == 0)
148 W(i, j) = 0;
149 }
150
151 //filling the matrix in (dPe, dPf)
152 //on Neumann BCs, replace the equation on dPf by dPf = 0 and remove dPf from other equations (for symmetry)
153 double mee, mef, mff, rfe, rff; //to add to m[e][e], m[e][f] / m[f][e], m[f][f'], r[f][e], r[f][f']
154 for (i = 0, mee = 0; i < n_f; mee += mef, i++)
155 {
156 for (f = e_f(e, i), mef = 0, rfe = 0, j = 0; f < nf && j < n_f; mef += mff, rfe += rff, j++, mff = 0, rff = 0)
157 {
158 fb = e_f(e, j), mff = fs(f) * fs(fb) * pe(e) * W(i, j) / ve(e), rff = e == f_e(f, 0) ? fs(fb) * pe(e) * W(i, j) / (ve(e) * pf(f)) : 0;
159 if (mff && ch.fcl()(f, 0) != 1 && ch.fcl()(fb, 0) != 1)
160 mat(ne_tot + f, ne_tot + fb) += mff;
161 else if (ch.fcl()(f, 0) == 1 && f == fb)
162 mat(ne_tot + f, ne_tot + fb) += 1;
163 if (rff)
164 rec(f, ne_tot + fb) += rff;
165 }
166 if (ch.fcl()(f, 0) != 1 && e < ne)
167 mat(e, ne_tot + f) -= mef;
168 if (ch.fcl()(f, 0) != 1 && f < nf)
169 mat(ne_tot + f, e) -= mef;
170 if (e == f_e(f, 0) && f < nf)
171 rec(f, e) -= rfe;
172 }
173 if (e < ne)
174 mat(e, e) += mee;
175 }
176
177 if (!has_P_ref && !Process::me())
178 mat(0, 0) *= 2;
179 // {
180 // double coeff = mat(0, 0) / ne;
181 // for (e = 0; e < ne; e++) mat(0, e) += coeff;
182 // }
183 Cerr << statistics().get_time_since_last_open(STD_COUNTERS::matrix_assembly) << " s" << finl;
184 statistics().end_count(STD_COUNTERS::matrix_assembly);
185 return 1;
186}
187
188/*! @brief Assemble the pressure matrix for a quasi-compressible fluid; laplacian(P) is replaced by div(grad(P)/rho).
189 *
190 * @param (DoubleTab& tab_rho) mass density. Default values:
191 * @return (int) always returns 1
192 * @throws PolyMAC_CDO boundary effects:
193 */
194int Assembleur_P_PolyMAC_CDO::assembler_QC(const DoubleTab& tab_rho, Matrice& matrice)
195{
196 Cerr << "Assemblage de la matrice de pression pour Quasi Compressible en cours..." << finl;
197 assembler(matrice);
200 abort();
201 Matrice_Bloc& matrice_bloc = ref_cast(Matrice_Bloc, matrice.valeur());
202 Matrice_Morse_Sym& la_matrice = ref_cast(Matrice_Morse_Sym, matrice_bloc.get_bloc(0, 0).valeur());
203 if ((la_matrice.get_est_definie() != 1) && (1))
204 {
205 Cerr << "Pas de pression imposee --> P(0)=0" << finl;
206 if (je_suis_maitre())
207 la_matrice(0, 0) *= 2;
208 la_matrice.set_est_definie(1);
209 }
210
211 Cerr << "Fin de l'assemblage de la matrice de pression" << finl;
212 return 1;
213}
214
216{
217 Debog::verifier("secmem dans modifier secmem", secmem);
218
219 const Domaine_PolyMAC_CDO& le_dom = le_dom_PolyMAC_CDO.valeur();
220 const Domaine_Cl_PolyMAC_family& le_dom_cl = le_dom_Cl_PolyMAC_CDO.valeur();
221 int nb_cond_lim = le_dom_cl.nb_cond_lim();
222 const IntTab& face_voisins = le_dom.face_voisins();
223
224 // Modification of the right-hand side:
225 int i;
226 for (i = 0; i < nb_cond_lim; i++)
227 {
228 const Cond_lim_base& la_cl_base = le_dom_cl.les_conditions_limites(i).valeur();
229 const Front_VF& la_front_dis = ref_cast(Front_VF, la_cl_base.frontiere_dis());
230 const Champ_front_base& champ_front = la_cl_base.champ_front();
231 int ndeb = la_front_dis.num_premiere_face();
232 int nfin = ndeb + la_front_dis.nb_faces();
233
234 // GF switched to pressure increment formulation
235 if ((sub_type(Neumann_sortie_libre, la_cl_base)) && (!get_resoudre_increment_pression()))
236 {
237 double Pimp, coPolyMAC_CDO;
238 const Neumann_sortie_libre& la_cl_Neumann = ref_cast(Neumann_sortie_libre, la_cl_base);
239 // const Front_VF& la_front_dis = ref_cast(Front_VF,la_cl_base.frontiere_dis());
240 //int ndeb = la_front_dis.num_premiere_face();
241 //int nfin = ndeb + la_front_dis.nb_faces();
242 for (int num_face = ndeb; num_face < nfin; num_face++)
243 {
244 Pimp = la_cl_Neumann.flux_impose(num_face - ndeb);
245 coPolyMAC_CDO = les_coeff_pression[num_face] * Pimp;
246 secmem[face_voisins(num_face, 0)] += coPolyMAC_CDO;
247 }
248 }
249 else if (sub_type(Dirichlet, la_cl_base) && champ_front.instationnaire() && get_resoudre_en_u() )
250 {
251 const DoubleTab& Gpt = champ_front.derivee_en_temps();
252 bool ch_unif = (Gpt.nb_dim() == 1);
253 for (int num_face = ndeb; num_face < nfin; num_face++)
254 {
255 double Stt = 0.;
256 for (int k = 0; k < dimension; k++)
257 {
258 double Gpoint = ch_unif ? Gpt(k) : Gpt(num_face - ndeb, k);
259 Stt -= Gpoint * le_dom.face_normales(num_face, k);
260 }
261 secmem(face_voisins(num_face, 0)) += Stt;
262 }
263 }
264 }
265
266 secmem.echange_espace_virtuel();
267 Debog::verifier("secmem dans modifier secmem fin", secmem);
268 return 1;
269}
270
272{
273 Debog::verifier("pression dans modifier solution in", pression);
274 //face pressures are not considered in the min (solveur_U_P does not update them)
275 DoubleTab_parts ppart(pression);
276 if (!has_P_ref) pression -= mp_min_vect(ppart[0]);
277 return 1;
278}
279
281{
282 return le_dom_PolyMAC_CDO.valeur();
283}
284
286{
287 return le_dom_Cl_PolyMAC_CDO.valeur();
288}
289
291{
292 le_dom_PolyMAC_CDO = ref_cast(Domaine_PolyMAC_CDO, le_dom_dis);
293}
294
296{
297 le_dom_Cl_PolyMAC_CDO = ref_cast(Domaine_Cl_PolyMAC_family, le_dom_Cl_dis);
298}
299
301{
302 mon_equation = Eqn;
303 stencil_done = 0;
304}
int assembler_QC(const DoubleTab &, Matrice &) override
Assemble the pressure matrix for a quasi-compressible fluid; laplacian(P) is replaced by div(grad(P)/...
int assembler_rho_variable(Matrice &, const Champ_Don_base &rho) override
Assembly of the matrix div(porosity/rho * grad P) The type of the "rho" field to be provided depends ...
void completer(const Equation_base &) override
int modifier_secmem(DoubleTab &) override
const Domaine_dis_base & domaine_dis_base() const override
int assembler_mat(Matrice &, const DoubleVect &, int incr_pression, int resoudre_en_u) override
const Domaine_Cl_dis_base & domaine_Cl_dis_base() const override
void associer_domaine_dis_base(const Domaine_dis_base &) override
void associer_domaine_cl_dis_base(const Domaine_Cl_dis_base &) override
int modifier_solution(DoubleTab &) override
int assembler(Matrice &) 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_Don_base base class of Given Fields (not calculated)
const IntTab & fcl() const
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()
static void verifier(const char *const msg, double)
Definition Debog.cpp:21
Dirichlet This class is the base class of the hierarchy of Dirichlet-type boundary conditions.
Definition Dirichlet.h:31
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.
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.
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....
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
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 set_nb_columns(const int)
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
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)
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
static void abort()
Abort routine for TRUST on a fatal error.
Definition Process.cpp:573
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 int je_suis_maitre()
Returns 1 if on the master processor of the current group (i.e. me() == 0), 0 otherwise.
Definition Process.cpp:82
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
void append_line(_TYPE_)
Definition TRUSTTab.tpp:213
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
_SIZE_ size() const
Definition TRUSTVect.tpp:45
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")