TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Source_Travail_pression_Elem_base.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 <Source_Travail_pression_Elem_base.h>
17#include <Champ_Inc_P0_base.h>
18#include <Champ_Face_base.h>
19#include <Pb_Multiphase.h>
20#include <Matrix_tools.h>
21#include <Array_tools.h>
22#include <Domaine_VF.h>
23#include <cfloat>
24
25Implemente_base(Source_Travail_pression_Elem_base, "Source_Travail_pression_Elem_base", Sources_Multiphase_base);
26// XD travail_pression source_base travail_pression NO_BRACE Source term which corresponds to the additional pressure
27// XD_CONT work term that appears when dealing with compressible multiphase fluids
28
31
32void Source_Travail_pression_Elem_base::dimensionner_blocs(matrices_t matrices, const tabs_t& semi_impl) const
33{
34 const Domaine_VF& domaine = ref_cast(Domaine_VF, equation().domaine_dis());
35 const IntTab& e_f = domaine.elem_faces(), &f_e = domaine.face_voisins();
36 const DoubleTab& inco = equation().inconnue().valeurs();
37 int i, j, e, eb, ne = domaine.nb_elem(), f,n, N = inco.line_size(), m,
38 M = ref_cast(QDM_Multiphase, ref_cast(Pb_Multiphase, equation().probleme()).equation_qdm()).pression().valeurs().line_size();
39
40 for (auto &&n_m : matrices)
41 if (n_m.first == "pression" || (n_m.first == "alpha" && !semi_impl.count("alpha")) || n_m.first == "vitesse")
42 {
43 Matrice_Morse& mat = *n_m.second, mat2;
44 Stencil sten(0, 2);
45
46 if (n_m.first == "pression") /* pression : dependance locale, implicite */
47 for (e = 0; e < ne; e++)
48 for (n = 0, m = 0; n < N; n++, m += (M > 1)) sten.append_line(N * e + n, M * e + m);
49 else if (n_m.first == "vitesse")
50 for (e = 0; e < ne; e++)
51 for (i = 0; i < e_f.dimension(1); i++)
52 {
53 if ((f = e_f(e, i)) >= 0)
54 for (n = 0; n < N; n++) sten.append_line(N * e + n, N * f + n);
55 }
56 else for (e = 0; e < ne; e++)
57 for (i = 0; i < e_f.dimension(1); i++)
58 if ((f = e_f(e, i)) >= 0)
59 for (j = 0; j < 2 && (eb = f_e(f, j)) >= 0; j++)
60 for (n = 0; n < N; n++) sten.append_line(N * e + n, N * eb + n);
61 tableau_trier_retirer_doublons(sten);
62 Matrix_tools::allocate_morse_matrix(inco.size_totale(), equation().probleme().get_champ(n_m.first).valeurs().size_totale(), sten, mat2);
63 mat.nb_colonnes() ? mat += mat2 : mat = mat2;
64 }
65}
66
67void Source_Travail_pression_Elem_base::ajouter_blocs(matrices_t matrices, DoubleTab& secmem, const tabs_t& semi_impl) const
68{
69 const Pb_Multiphase& pbm = ref_cast(Pb_Multiphase, equation().probleme());
70 const Domaine_VF& domaine = ref_cast(Domaine_VF, equation().domaine_dis());
71 const DoubleVect& pe = equation().milieu().porosite_elem(), &pf = equation().milieu().porosite_face(),
72 &fs = domaine.face_surfaces(), &ve = domaine.volumes();
73
74 const Champ_Inc_base& ch_a = pbm.equation_masse().inconnue(),
75 &ch_v = pbm.equation_qdm().inconnue(),
76 &ch_p = ref_cast(QDM_Multiphase, pbm.equation_qdm()).pression();
77
78 /* trois tableaux de alpha : present / passe et champ convecte (peut etre semi-implicite) */
79 const DoubleTab& alpha = ch_a.valeurs(), &c_alpha = semi_impl.count("alpha") ? semi_impl.at("alpha") : alpha,
80 &p_alpha = ch_a.passe(), &press = ch_p.valeurs(), &vit = ch_v.valeurs();
81
82 const IntTab& fcl = ref_cast(Champ_Inc_P0_base, ch_a).fcl(), &f_e = domaine.face_voisins(),
83 &fcl_v = ref_cast(Champ_Face_base, ch_v).fcl();
84
85 DoubleTab b_alpha = ch_a.valeur_aux_bords();
86 Matrice_Morse *Mp = matrices.count("pression") ? matrices.at("pression") : nullptr,
87 *Ma = matrices.count("alpha") && !semi_impl.count("alpha") ? matrices.at("alpha") : nullptr,
88 *Mv = matrices.count("vitesse") ? matrices.at("vitesse") : nullptr;
89
90 int i, j, e, eb, f, n, N = alpha.line_size(), m, M = press.line_size();
91 double dt = equation().schema_temps().pas_de_temps();
92
93 //partie -p d alpha_k / dt et ses derivees
94 for (e = 0; e < domaine.nb_elem(); e++)
95 {
96 for (n = 0, m = 0; n < N; n++, m += (M > 1))
97 secmem(e, n) -= pe(e) * ve(e) * press(e, m) * (alpha(e, n) - p_alpha(e, n)) / dt;
98 if (Mp)
99 for (n = 0, m = 0; n < N; n++, m += (M > 1))
100 (*Mp)(N * e + n, M * e + m) += pe(e) * ve(e) * (alpha(e, n) - p_alpha(e, n)) / dt;
101 if (Ma)
102 for (n = 0, m = 0; n < N; n++, m += (M > 1))
103 (*Ma)(N * e + n, N * e + n) += pe(e) * ve(e) * press(e, m) / dt;
104 }
105
106 //partie -p div (alpha_k v_k)
107 DoubleTrav dv_flux(N), dc_flux(2, N); //derivees du flux convectif a la face par rapport a la vitesse / au champ convecte amont / aval
108 /* convection aux faces internes (fcl(f, 0) == 0), de Neumann_val_ext ou de Dirichlet */
109 for (f = 0; f < domaine.nb_faces(); f++)
110 if (!fcl(f, 0) || (fcl(f, 0) > 4 && fcl(f, 0) < 7))
111 {
112 for (dv_flux = 0, dc_flux = 0, i = 0; i < 2; i++)
113 for (e = f_e(f, i), n = 0; n < N; n++)
114 {
115 const double v = vit(f, n) ? vit(f, n) : DBL_MIN,
116 fac = pf(f) * fs(f) * (1. + (v * (i ? -1 : 1) > 0 ? 1. : -1) * alp) / 2;
117
118 dv_flux(n) += fac * (e >= 0 ? c_alpha(e, n) - pbm.alpha_inf_phase(n) : b_alpha(f, n) - pbm.alpha_inf_phase(n)); //f est reelle -> indice trivial dans b_alpha
119 dc_flux(i, n) = e >= 0 ? fac * vit(f, n) : 0;
120 }
121
122 //second membre
123 for (i = 0; i < 2; i++)
124 if ((e = f_e(f, i)) >= 0)
125 if (e < domaine.nb_elem())
126 for (n = 0, m = 0; n < N; n++, m += (M > 1))
127 secmem(e, n) -= (i ? -1 : 1) * press(e, m) * dv_flux(n) * vit(f, n);
128 //derivees : vitesse
129 if (Mv && (fcl_v(f, 0) < 2 || fcl_v(f, 0) == 5)) // XXX : pas pour CL Dirichlet !
130 for (i = 0; i < 2; i++)
131 if ((e = f_e(f, i)) >= 0)
132 if (e < domaine.nb_elem())
133 for (n = 0, m = 0; n < N; n++, m += (M > 1))
134 (*Mv)(N * e + n, N * f + n) += (i ? -1 : 1) * press(e, m) * dv_flux(n);
135 //derivees : pression
136 if (Mp)
137 for (i = 0; i < 2; i++)
138 if ((e = f_e(f, i)) >= 0)
139 if (e < domaine.nb_elem())
140 for (n = 0, m = 0; n < N; n++, m += (M > 1))
141 (*Mp)(N * e + n, M * e + m) += (i ? -1 : 1) * dv_flux(n) * vit(f, n);
142 //derivees : alpha
143 if (Ma)
144 for (i = 0; i < 2; i++)
145 if ((e = f_e(f, i)) >= 0)
146 if (e < domaine.nb_elem())
147 for (j = 0; j < 2; j++)
148 if ((eb = f_e(f, j)) >= 0)
149 for (n = 0, m = 0; n < N; n++, m += (M > 1))
150 (*Ma)(N * e + n, N * eb + n) += (i ? -1 : 1) * press(e, m) * dc_flux(j, n);
151 }
152}
: class Champ_Inc_P0_base
Classe Champ_Inc_base.
DoubleTab & passe(int i=1) override
Renvoie les valeurs du champs a l'instant t-i.
DoubleTab & valeurs() override
Renvoie le tableau des valeurs du champ au temps courant.
DoubleTab valeur_aux_bords() const override
renvoie la valeur du champ aux faces de bord
virtual DoubleTab & valeurs()=0
class Domaine_VF
Definition Domaine_VF.h:44
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
virtual const Champ_Inc_base & inconnue() const =0
Schema_Temps_base & schema_temps()
Renvoie le schema en temps associe a l'equation.
Classe Matrice_Morse Represente une matrice M (creuse), non necessairement carree.
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_elem()
Definition Milieu_base.h:58
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
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
Definition Objet_U.cpp:293
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
classe Pb_Multiphase Cette classe represente un probleme de thermohydraulique multiphase de type "3*N...
double alpha_inf_phase(int i) const
virtual Equation_base & equation_qdm()
virtual Equation_base & equation_masse()
classe QDM_Multiphase Cette classe porte les termes de l'equation de la dynamique
double pas_de_temps() const
Renvoie le pas de temps (delta_t) courant.
Classe de base des flux de sortie.
Definition Sortie.h:52
Classe Source_Travail_pression_Elem_base.
void dimensionner_blocs(matrices_t matrices, const tabs_t &semi_impl={}) const override
void ajouter_blocs(matrices_t matrices, DoubleTab &secmem, const tabs_t &semi_impl={}) const override
const Champ_base & get_champ(const Motcle &nom) const override
void append_line(_TYPE_)
Definition TRUSTTab.tpp:213
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
_SIZE_ size_totale() const
Definition TRUSTVect.tpp:61
int line_size() const
Definition TRUSTVect.tpp:67