TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Op_Evanescence_Homogene_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 <Op_Evanescence_Homogene_Elem_base.h>
17#include <Schema_Implicite_base.h>
18#include <Champ_Inc_P0_base.h>
19#include <Milieu_composite.h>
20#include <Champ_Uniforme.h>
21#include <Pb_Multiphase.h>
22#include <Matrix_tools.h>
23#include <Domaine_VF.h>
24#include <Param.h>
25#include <SETS.h>
26
27
28Implemente_base(Op_Evanescence_Homogene_Elem_base,"Op_Evanescence_Homogene_Elem_base",Operateur_Evanescence_base);
29
31
33{
34 Param param(que_suis_je());
35 param.ajouter("alpha_res", &alpha_res_, Param::REQUIRED);
36 param.ajouter("alpha_res_min", &alpha_res_min_);
37 param.lire_avec_accolades_depuis(is);
38 return is;
39}
40
41void Op_Evanescence_Homogene_Elem_base::dimensionner_blocs(matrices_t matrices, const tabs_t& semi_impl) const
42{
43 const Domaine_VF& domaine = ref_cast(Domaine_VF, equation().domaine_dis());
44 const DoubleTab& inco = equation().inconnue().valeurs();
45
46 /* on doit pouvoir ajouter / soustraire les equations entre composantes */
47 int i, e, n, N = inco.line_size();
48 if (N == 1) return; //pas d'evanescence en simple phase!
49 for (auto &&n_m : matrices)
50 if (n_m.second->nb_colonnes())
51 {
52 Matrice_Morse& mat = *n_m.second, mat2;
53 Stencil sten(0, 2);
54
55
56 std::set<int> idx;
57 for (e = 0; e < domaine.nb_elem(); e++, idx.clear())
58 {
59 for (i = N * e, n = 0; n < N; n++, i++)
60 for (auto j = mat.get_tab1()(i) - 1; j < mat.get_tab1()(i + 1) - 1; j++)
61 idx.insert(mat.get_tab2()(j) - 1);
62 for (i = N * e, n = 0; n < N; n++, i++)
63 for (auto &&c : idx) sten.append_line(i, c);
64 }
66 mat = mat2; //pour forcer l'ordre des coefficients dans la matrice (accelere les operations ligne a ligne)
67 }
68}
69
70void Op_Evanescence_Homogene_Elem_base::ajouter_blocs(matrices_t matrices, DoubleTab& secmem, const tabs_t& semi_impl) const
71{
72 const Milieu_composite& milc = ref_cast(Milieu_composite, equation().milieu());
73 const Champ_Inc_P0_base& ch = ref_cast(Champ_Inc_P0_base, equation().inconnue());
74 const Domaine_VF& domaine = ref_cast(Domaine_VF, equation().domaine_dis());
75 const Pb_Multiphase& pb = ref_cast(Pb_Multiphase, equation().probleme());
76 const DoubleTab& inco = ch.valeurs(), &alpha = pb.equation_masse().inconnue().valeurs(), &rho = equation().milieu().masse_volumique().valeurs(), &p = ref_cast(QDM_Multiphase, pb.equation_qdm()).pression().valeurs();
77
78 const SETS *sch = sub_type(Schema_Implicite_base, pb.equation_qdm().schema_temps()) && sub_type(SETS, ref_cast(Schema_Implicite_base, pb.equation_qdm().schema_temps()).solveur().valeur())
79 ? &ref_cast(SETS, ref_cast(Schema_Implicite_base, pb.equation_qdm().schema_temps()).solveur().valeur()) : nullptr;
80
81 int e, k, n, N = inco.line_size(), m, M = p.line_size(), is_m = ch.le_nom() == "alpha", cR = (rho.dimension_tot(0) == 1),
82 iter = sch ? sch->iteration_ : 0, p_degen = is_m && sch ? sch->p_degen_ : 0;
83 if (N == 1 || p_degen || (is_m && !iter)) return; //pas d'evanescence en simple phase ou si p est degenere
84
85 double a_eps = alpha_res_, a_eps_min = alpha_res_min_, a_m, a_max; //seuil de declenchement du traitement de l'evanescence
86
87 /* recherche de phases evanescentes et traitement des seconds membres */
88 IntTrav maj(inco.dimension_tot(0)); //maj(i) : phase majoritaire de la ligne i
89 DoubleTrav coeff(inco.dimension_tot(0), inco.line_size(), 2); //coeff(i, n, 0/1) : coeff a appliquer a l'equation existante / a l'eq. "inco = v_maj", leurs derivees en alpha
90 Matrice_Morse& mat_diag = *matrices.at(ch.le_nom().getString());
91 for (e = 0; e < domaine.nb_elem(); e++)
92 {
93 /* phase majoritaire */
94 for (a_max = 0, k = -1, n = 0; n < N; n++)
95 if ((a_m = alpha(e, n)) > a_max) k = n, a_max = a_m;
96 if (k >= 0) maj(e) = k;
97 else abort();
98
99 /* coeff d'evanescence, second membre */
100 for (n = 0, m = 0; n < N; n++, m += (M > 1))
101 if (n != k && (a_m = alpha(e, n)) < a_eps)
102 {
103 double val = is_m ? 0 : milc.has_saturation(n, k) ? milc.get_saturation(n, k).Tsat(p(e, m)) : inco(e, k); //valeur a laquelle on veut ramener inco(e, n)
104 coeff(e, n, 0) = (a_eps == a_eps_min ? (a_m < a_eps) : std::min(std::max((a_eps - a_m) / (a_eps - a_eps_min), 0.), 1.));
105 coeff(e, n, 1) = mat_diag(N * e + k, N * e + k) * coeff(e, n, 0);
106 double flux = coeff(e, n, 0) * secmem(e, n) + coeff(e, n, 1) * (inco(e, n) - val);
107 secmem(e, k) += (p_degen ? rho(!cR * e, k) : 1) * flux, secmem(e, n) -= (p_degen ? rho(!cR * e, n) : 1) * flux;
108 }
109 }
110
111 /* lignes de matrices */
112 for (auto &&n_m : matrices)
113 if (n_m.second->nb_colonnes())
114 {
115 int diag = (n_m.first == ch.le_nom().getString()), press = (n_m.first == "pression"); //est-on sur le bloc diagonal, sur le bloc pression?
116 Matrice_Morse& mat = *n_m.second;
117 auto i(mat.get_tab1()(0));
118 auto j(i);
119 for (e = 0; e < domaine.nb_elem(); e++)
120 for (n = 0, m = 0; n < N; n++, m += (M > 1))
121 if (coeff(e, n, 0))
122 {
123 k = maj(e); //phase majoritaire
124 double dval = is_m ? 0 : milc.has_saturation(n, k) ? (press ? milc.get_saturation(n, k).dP_Tsat(p(e, m)) : 0) : diag; //derivee de val (nulle si on n'est pas sur le bon bloc)
125 int cval = is_m ? -1 : milc.has_saturation(n, k) ? M * e + m : N * e + k; //indice de colonne associe a cette derivee
126 for (i = mat.get_tab1()(N * e + n) - 1, j = mat.get_tab1()(N * e + k) - 1; i < mat.get_tab1()(N * e + n + 1) - 1; i++, j++)
127 {
128 assert(mat.get_tab2()(j) == mat.get_tab2()(i));
129 int c = mat.get_tab2()(i) - 1; //indice de colonne (commun aux deux lignes grace au dimensionner_blocs())
130 double dflux = -coeff(e, n, 0) * mat.get_set_coeff()(i) + coeff(e, n, 1) * (diag * (c == N * e + n) - dval * (c == cval)); //derivee de flux en secmem, inco, val
131 mat.get_set_coeff()(i) += (p_degen ? rho(!cR * e, n) : 1) * dflux;
132 mat.get_set_coeff()(j) -= (p_degen ? rho(!cR * e, k) : 1) * dflux;
133 }
134 }
135 }
136}
: class Champ_Inc_P0_base
DoubleTab & valeurs() override
Renvoie le tableau des valeurs du champ au temps courant.
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.
const Nom & le_nom() const override
Renvoie le nom du champ.
Classe Matrice_Morse Represente une matrice M (creuse), non necessairement carree.
const auto & get_tab2() const
const auto & get_tab1() const
auto & get_set_coeff()
int nb_colonnes() const override
Return local number of columns (=size on the current proc).
int nb_lignes() const override
Return local number of lines (=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)
virtual const Champ_base & masse_volumique() const
Renvoie la masse volumique du milieu.
Classe Milieu_composite Cette classe represente un fluide reel ainsi que.
bool has_saturation(int k, int l) const
Saturation_base & get_saturation(int k, int l) const
const Equation_base & equation() const
Renvoie la reference sur l'equation pointe par MorEqn::mon_equation.
Definition MorEqn.h:62
const std::string & getString() const
Definition Nom.h:92
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 Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
Classe Op_Evanescence_Homogene_Elem_base.
void ajouter_blocs(matrices_t matrices, DoubleTab &secmem, const tabs_t &semi_impl={}) const override
void dimensionner_blocs(matrices_t matrices, const tabs_t &semi_impl={}) const override
classe Operateur_Evanescence Classe generique de la hierarchie des operateurs representant un terme
@ REQUIRED
Definition Param.h:115
classe Pb_Multiphase Cette classe represente un probleme de thermohydraulique multiphase de type "3*N...
virtual Equation_base & equation_qdm()
virtual Equation_base & equation_masse()
static void abort()
Routine de sortie de Trio-U sur une erreur abort().
Definition Process.cpp:570
classe QDM_Multiphase Cette classe porte les termes de l'equation de la dynamique
classe SETS (semi-implicite + etapes de stabilisation, a la TRACE)
Definition SETS.h:35
int p_degen_
Definition SETS.h:79
int iteration_
Definition SETS.h:78
void Tsat(const SpanD P, SpanD res, int ncomp=1, int ind=0) const
class Schema_Implicite_base Classe de base pour tous les schemas en temps implicite
Classe de base des flux de sortie.
Definition Sortie.h:52
_SIZE_ dimension_tot(int) const override
Definition TRUSTTab.tpp:160
void append_line(_TYPE_)
Definition TRUSTTab.tpp:213
int line_size() const
Definition TRUSTVect.tpp:67