TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Perte_Charge_Singuliere_PolyMAC_HFV_Face.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 <Perte_Charge_Singuliere_PolyMAC_HFV_Face.h>
17#include <Op_Grad_PolyMAC_HFV_Face.h>
18#include <Champ_Face_PolyMAC_HFV.h>
19#include <Domaine_PolyMAC_MPFA.h>
20#include <Equation_base.h>
21#include <Probleme_base.h>
22#include <Matrice_Morse.h>
23#include <Pb_Multiphase.h>
24#include <Matrix_tools.h>
25#include <Array_tools.h>
26#include <Domaine.h>
27
28Implemente_instanciable(Perte_Charge_Singuliere_PolyMAC_HFV_Face, "Perte_Charge_Singuliere_Face_PolyMAC_HFV|Perte_Charge_Singuliere_Face_PolyMAC_MPFA", Perte_Charge_Singuliere_PolyMAC_CDO_Face);
29
31
33
35{
37 // eq_masse needs champ_conserve!
38 if (sub_type(Pb_Multiphase, mon_equation->probleme())) ref_cast(Pb_Multiphase, mon_equation->probleme()).equation_masse().init_champ_conserve();
39}
40
41void Perte_Charge_Singuliere_PolyMAC_HFV_Face::dimensionner_blocs(matrices_t matrices, const tabs_t& semi_impl) const
42{
43 const Domaine_Poly_base& domaine = ref_cast(Domaine_Poly_base, equation().domaine_dis());
44 const IntTab& f_e = domaine.face_voisins(), &fcl = ref_cast(Champ_Face_PolyMAC_HFV, equation().inconnue()).fcl();
45 const std::string& nom_inco = equation().inconnue().le_nom().getString();
46 if (!matrices.count(nom_inco) || !sub_type(Domaine_PolyMAC_MPFA, domaine)) return;
47 Matrice_Morse& mat = *matrices.at(nom_inco), mat2;
48 int i, j, e, f, n, N = equation().inconnue().valeurs().line_size(), d, D = dimension, nf_tot = domaine.nb_faces_tot();
49 //DoubleTrav aar_f(N); //alpha * alpha * rho at each face
50 Stencil stencil(0, 2);
51
52
53 for (i = 0; i < num_faces.size(); i++)
54 if ((f = num_faces(i)) < domaine.nb_faces() && fcl(f, 0) < 2)
55 for (j = 0; j < 2 && (e = f_e(f, j)) >= 0; j++) //upwind / downwind element if PolyMAC_HFV V2
56 if (e < domaine.nb_elem())
57 for (d = 0; d < D; d++)
58 for (n = 0; n < N; n++) stencil.append_line(N * (nf_tot + D * e + d) + n, N * f + n);
59 tableau_trier_retirer_doublons(stencil);
60 Matrix_tools::allocate_morse_matrix(equation().inconnue().valeurs().size_totale(), equation().inconnue().valeurs().size_totale(), stencil, mat2);
61 mat.nb_colonnes() ? mat += mat2 : mat = mat2;
62}
63
64void Perte_Charge_Singuliere_PolyMAC_HFV_Face::ajouter_blocs(matrices_t matrices, DoubleTab& secmem, const tabs_t& semi_impl) const
65{
66 const Domaine_Poly_base& domaine = ref_cast(Domaine_Poly_base, equation().domaine_dis());
67 //const DoubleVect& volumes_entrelaces = domaine_PolyMAC_HFV.volumes_entrelaces();
68 const DoubleVect& pf = equation().milieu().porosite_face(), &fs = domaine.face_surfaces(), &vf = domaine.volumes_entrelaces();
69 const Pb_Multiphase *pbm = sub_type(Pb_Multiphase, equation().probleme()) ? &ref_cast(Pb_Multiphase, equation().probleme()) : nullptr;
70 const DoubleTab& vit = la_vitesse->valeurs(), &nf = domaine.face_normales(), &vfd = domaine.volumes_entrelaces_dir(), &xv = domaine.xv(), &xp = domaine.xp(),
71 *alpha = pbm ? &pbm->equation_masse().inconnue().passe() : nullptr, *a_r = pbm ? &pbm->equation_masse().champ_conserve().passe() : nullptr;
72 const IntTab& f_e = domaine.face_voisins(), &fcl = ref_cast(Champ_Face_PolyMAC_HFV, equation().inconnue()).fcl();
73 const std::string& nom_inco = equation().inconnue().le_nom().getString();
74 Matrice_Morse *mat = matrices.count(nom_inco) ? matrices.at(nom_inco) : nullptr;
75 int i, j, e, f, n, N = equation().inconnue().valeurs().line_size();
76 int poly_v2 = sub_type(Domaine_PolyMAC_MPFA, domaine), semi = (int)semi_impl.count(nom_inco), d, D = dimension, nf_tot = domaine.nb_faces_tot();
77 DoubleTrav aar_f(N); //alpha * alpha * rho at each face
78 for (i = 0; i < num_faces.size(); i++)
79 if ((f = num_faces(i)) < domaine.nb_faces())
80 {
81 double fac = (direction_perte_charge() < 0 ? fs(f) : std::fabs(nf(f,direction_perte_charge()))) * pf(f) * K();
82 if (pbm)
83 for (aar_f = 0, j = 0; j < 2 && (e = f_e(f, j)) >= 0; j++)
84 for (n = 0; n < N; n++) aar_f(n) += vfd(f, j) / vf(f) * (*a_r)(e, n) * (*alpha)(e, n);
85 else aar_f = 1;
86
87 if (!poly_v2 || fcl(f, 0) < 2) //contribution to the face: except for Dirichlet/Neumann faces in V2
88 {
89 for (n = 0; n < N; n++) secmem(f, n) -= 0.5 * fac * aar_f(n) * vit(f, n) * std::fabs(vit(f, n));
90 if (mat)
91 for (n = 0; n < N; n++) (*mat)(N * f + n, N * f + n) += fac * aar_f(n) * std::fabs(vit(f, n));
92 }
93 if (poly_v2)
94 for (j = 0; j < 2 && (e = f_e(f, j)) >= 0; j++)
95 if (e < domaine.nb_elem()) //upwind / downwind element if PolyMAC_HFV V2
96 {
97 for (d = 0; d < D; d++)
98 for (n = 0; n < N; n++) /* right-hand side */
99 secmem(nf_tot + D * e + d, n) += (j ? -1 : 1) * fs(f) * (xv(f, d) - xp(e, d)) * 0.5 * fac * aar_f(n) * vit(f, n) * std::fabs(vit(f, n));
100 if (mat && !semi && fcl(f, 0) < 2)
101 for (d = 0; d < D; d++)
102 for (n = 0; n < N; n++) /* derivative (not possible in semi-implicit) */
103 (*mat)(N * (nf_tot + D * e + d) + n, N * f + n) -= (j ? -1 : 1) * fs(f) * (xv(f, d) - xp(e, d)) * fac * aar_f(n) * std::fabs(vit(f, n));
104 }
105 }
106}
: class Champ_Face_PolyMAC_HFV
DoubleTab & passe(int i=1) override
Returns field values at instant t-i.
DoubleTab & valeurs() override
Returns the array of field values at the current time.
class Domaine_Poly_base
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
Champ_Inc_base & champ_conserve() const
virtual const Champ_Inc_base & inconnue() const =0
const Nom & le_nom() const override
Returns the name of the field.
Matrice_Morse class - Represents a (sparse) matrix M, not necessarily square,.
int nb_colonnes() const override
Return local number of columns (=size on the current proc).
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_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
const std::string & getString() const
Definition Nom.h:92
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 Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
Multiphase thermohydraulics problem of type "3*N equations":
virtual Equation_base & equation_masse()
class Perte_Charge_Singuliere_PolyMAC_CDO_Face
class Perte_Charge_Singuliere_PolyMAC_HFV_Face
void dimensionner_blocs(matrices_t matrices, const tabs_t &semi_impl={}) const override
void completer() override
Updates internal references of the Source_base object.
void ajouter_blocs(matrices_t matrices, DoubleTab &secmem, const tabs_t &semi_impl={}) const override
int direction_perte_charge() const
Returns the pressure drop direction.
Base class for output streams.
Definition Sortie.h:52
virtual void completer()
Updates internal references of the Source_base object.
void append_line(_TYPE_)
Definition TRUSTTab.tpp:213
int line_size() const
Definition TRUSTVect.tpp:67