TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Source_Force_Tchen_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_Force_Tchen_base.h>
17#include <Champ_Face_base.h>
18#include <Pb_Multiphase.h>
19#include <Matrix_tools.h>
20#include <Array_tools.h>
21#include <math.h>
22
23Implemente_base(Source_Force_Tchen_base, "Source_Force_Tchen_base", Sources_Multiphase_base);
24
25Sortie& Source_Force_Tchen_base::printOn(Sortie& os) const { return os; }
26
28{
29 // phase identification
30 const Pb_Multiphase *pbm = sub_type(Pb_Multiphase, equation().probleme()) ? &ref_cast(Pb_Multiphase, equation().probleme()) : nullptr;
31
32 if (!pbm || pbm->nb_phases() == 1) Process::exit(que_suis_je() + " : not needed for single-phase flow!");
33 for (int n = 0; n < pbm->nb_phases(); n++) // search for n_l, n_g: {liquid,gas}_continuous phase in priority
34 if (pbm->nom_phase(n).debute_par("liquide") && (n_l < 0 || pbm->nom_phase(n).finit_par("continu"))) n_l = n;
35
36 if (n_l < 0) Process::exit(que_suis_je() + " : liquid phase not found!");
37
38 return is;
39}
40
41void Source_Force_Tchen_base::dimensionner_blocs(matrices_t matrices, const tabs_t& semi_impl) const
42{
43 const Champ_Face_base& ch = ref_cast(Champ_Face_base, equation().inconnue());
44 if (!matrices.count(ch.le_nom().getString())) return; // nothing to do
45
46 Matrice_Morse& mat = *matrices.at(ch.le_nom().getString()), mat2;
47 const Domaine_VF& domaine = ref_cast(Domaine_VF, equation().domaine_dis());
48 const DoubleTab& inco = ch.valeurs();
49 const IntTab& fcl = ch.fcl();
50
51 /* stencil: block-diagonal for face velocities, then each component of element velocities */
52 Stencil stencil(0, 2);
53
54 int N = inco.line_size(), nf = domaine.nb_faces();
55
56 /* faces */
57 for (int f = 0; f < nf; f++)
58 if (fcl(f, 0) < 2)
59 for (int k = 0 ; k<N ; k++)
60 if (k != n_l) // gas phase
61 stencil.append_line( N * f + k , N * f + n_l) ;
62
63 /* elements si aux */
65
66 tableau_trier_retirer_doublons(stencil);
67 Matrix_tools::allocate_morse_matrix(inco.size_totale(), inco.size_totale(), stencil, mat2);
68 mat.nb_colonnes() ? mat += mat2 : mat = mat2;
69}
70
71void Source_Force_Tchen_base::ajouter_blocs(matrices_t matrices, DoubleTab& secmem, const tabs_t& semi_impl) const
72{
73 const Champ_Face_base& ch = ref_cast(Champ_Face_base, equation().inconnue());
74 Matrice_Morse *mat = matrices.count(ch.le_nom().getString()) ? matrices.at(ch.le_nom().getString()) : nullptr;
75 const Domaine_VF& domaine = ref_cast(Domaine_VF, equation().domaine_dis());
76 const IntTab& f_e = domaine.face_voisins(), &fcl = ch.fcl();
77 const DoubleVect& pf = equation().milieu().porosite_face(), &vf = domaine.volumes_entrelaces();
78 const DoubleTab& inco = ch.valeurs(), &pvit = ch.passe(), &alpha = ref_cast(Pb_Multiphase, equation().probleme()).equation_masse().inconnue().passe(),
79 &rho = equation().milieu().masse_volumique().passe(), &vf_dir = domaine.volumes_entrelaces_dir();
80
81 double pas_tps = equation().probleme().schema_temps().pas_de_temps();
82 int N = inco.line_size(), nf = domaine.nb_faces();
83
84 /* elements si aux */
85 ajouter_blocs_aux(matrices, secmem);
86
87 /* faces */
88 for (int f = 0; f < nf; f++)
89 if (fcl(f, 0) < 2)
90 for (int k = 0 ; k<N ; k++)
91 if (k != n_l) // gas phase
92 {
93 double alpha_loc = f_e(f, 1)>=0 ? alpha(f_e(f, 0), k) * vf_dir(f, 0)/vf(f) + alpha(f_e(f, 1), k) * vf_dir(f, 1)/vf(f) : alpha(f_e(f, 0), k) ;
94 double rho_loc = f_e(f, 1)>=0 ? rho(f_e(f, 0), n_l) * vf_dir(f, 0)/vf(f) + rho(f_e(f, 1), n_l) * vf_dir(f, 1)/vf(f) : rho(f_e(f, 0), n_l) ;
95 double fac = pf(f) * vf(f) * alpha_loc * rho_loc ;
96
97 secmem(f, k ) += fac * (inco(f, n_l)-pvit(f, n_l))/pas_tps;
98 secmem(f,n_l) -= fac * (inco(f, n_l)-pvit(f, n_l))/pas_tps;
99 if (mat)
100 {
101 (*mat)( N * f + k , N * f + n_l) -= fac/pas_tps ;
102 (*mat)( N * f + n_l, N * f + n_l) += fac/pas_tps ;
103 }
104 }
105}
const IntTab & fcl() const
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.
virtual DoubleTab & passe(int i=1)
Definition Champ_Proto.h:50
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
Probleme_base & probleme()
Returns the problem 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,.
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)
virtual const Champ_base & masse_volumique() const
Returns the mass density of the medium (const version).
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
virtual int debute_par(const char *const n) const
Definition Nom.cpp:314
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
Multiphase thermohydraulics problem of type "3*N equations":
const Nom & nom_phase(int i) const
int nb_phases() const
const Schema_Temps_base & schema_temps() const
Returns the time scheme associated with the problem.
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
double pas_de_temps() const
Returns the current time step (delta_t).
Base class for output streams.
Definition Sortie.h:52
Tchen force in a multiphase flow.
virtual void dimensionner_blocs_aux(Stencil &) const =0
void ajouter_blocs(matrices_t matrices, DoubleTab &secmem, const tabs_t &semi_impl={}) const override
virtual void ajouter_blocs_aux(matrices_t, DoubleTab &) const =0
void dimensionner_blocs(matrices_t matrices, const tabs_t &semi_impl={}) const override
void append_line(_TYPE_)
Definition TRUSTTab.tpp:213
_SIZE_ size_totale() const
Definition TRUSTVect.tpp:61
int line_size() const
Definition TRUSTVect.tpp:67