TrioCFD 1.9.9_beta
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 /* must be able to add / subtract equations between components */
47 int i, e, n, N = inco.line_size();
48 if (N == 1) return; //no evanescence in single-phase flow!
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; //to force the coefficient ordering in the matrix (speeds up row-by-row operations)
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; //no evanescence in single-phase or if p is degenerate
84
85 double a_eps = alpha_res_, a_eps_min = alpha_res_min_, a_m, a_max; //threshold triggering the evanescence treatment
86
87 /* recherche de phases evanescentes et traitement des seconds membres */
88 IntTrav maj(inco.dimension_tot(0)); //maj(i): majority phase of row i
89 DoubleTrav coeff(inco.dimension_tot(0), inco.line_size(), 2); //coeff(i, n, 0/1): coefficient applied to the existing equation / to the eq. "inco = v_maj", and their derivatives w.r.t. 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); //target value to which inco(e, n) is relaxed
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"); //are we on the diagonal block, on the pressure block?
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); //majority phase
124 double dval = is_m ? 0 : milc.has_saturation(n, k) ? (press ? milc.get_saturation(n, k).dP_Tsat(p(e, m)) : 0) : diag; //derivative of val (zero if not on the right block)
125 int cval = is_m ? -1 : milc.has_saturation(n, k) ? M * e + m : N * e + k; //column index associated with this derivative
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; //column index (common to both rows thanks to 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)); //derivative of flux w.r.t. 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
Returns the array of field values at the current time.
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()
Returns the time scheme associated with the equation.
const Nom & le_nom() const override
Returns the name of the field.
Matrice_Morse class - Represents a (sparse) matrix M, not necessarily square,.
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
Returns the mass density of the medium (const version).
Composite medium representing a multiphase fluid and its properties:
bool has_saturation(int k, int l) const
Saturation_base & get_saturation(int k, int l) const
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
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
Manages evanescence in an element-based equation (mass, energy, etc.).
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
Generic base class in the operator hierarchy for evanescence management terms.
@ REQUIRED
Definition Param.h:115
Multiphase thermohydraulics problem of type "3*N equations":
virtual Equation_base & equation_qdm()
virtual Equation_base & equation_masse()
static void abort()
Abort routine for TRUST on a fatal error.
Definition Process.cpp:573
Carries the terms of the momentum equation for multiphase flow without turbulence modelling.
SETS scheme (semi-implicit + stabilisation steps, TRACE-style).
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 Base class for all implicit time schemes.
Base class for output streams.
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