TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Terme_Boussinesq_base.h
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#ifndef Terme_Boussinesq_base_included
17#define Terme_Boussinesq_base_included
18
19#include <Convection_Diffusion_Temperature.h>
20#include <Equation_base.h>
21#include <Probleme_base.h>
22#include <TRUST_Vector.h>
23#include <TRUST_Ref.h>
24
25#include <Parser_U.h>
26#include <Domaine.h>
27
29class Champ_Don_base;
30class Param;
31
32/*! @brief Classe Terme_Boussinesq_base This class represents the gravity term appearing in the momentum equation
33 *
34 * divided by the reference density.
35 * We are in the framework of the Boussinesq hypothesis: the density is
36 * assumed constant and equal to its reference value except in the
37 * body force term where a small variation of the density as a function
38 * of one or more scalars transported by the flow (temperature and/or
39 * one or more concentrations) is taken into account.
40 * Special case of Terme_Boussinesq_base for temperature:
41 * the gravity term has the expression: beta*(T-T0) where beta
42 * represents the thermal expansion coefficient and T0 a reference
43 * value for temperature.
44 * Special case of Terme_Boussinesq_base for concentration:
45 * the gravity term has the expression: beta*(C-C0)
46 * or (beta[0]*(C[0]-C0[0]) + .....+ beta[i]*(C[i]-C0[i])) in
47 * the case of a vector of concentrations.
48 * beta represents the variation of density as a function
49 * of the constituent concentration and C0 a reference value
50 * for the concentration.
51 *
52 *
53 */
55{
56 Declare_base(Terme_Boussinesq_base);
57
58public :
59
60 void associer_pb(const Probleme_base& pb) override ;
61 inline const Champ_Don_base& gravite() const { return la_gravite_.valeur(); }
62 inline int verification() const { return verif_; }
63 inline double Scalaire0(int i) const { return Scalaire0_[i]; }
64 inline const Champ_Don_base& beta() const { return beta_.valeur(); }
65 inline const Convection_Diffusion_std& equation_scalaire() const { return equation_scalaire_.valeur(); }
66 DoubleTab& calculer(DoubleTab& resu) const override
67 {
68 resu=0;
69 return ajouter(resu);
70 }
71 void mettre_a_jour(double temps) override
72 {
73 for (int i=0; i<Scalaire0_.size_array(); i++)
74 {
75 fct_Scalaire0_[i].setVar(0,temps);
76 Scalaire0_[i] = fct_Scalaire0_[i].eval();
77 }
78 }
79 inline const ArrOfDouble& getScalaire0() const { return Scalaire0_; }
80
81protected :
82 void set_param(Param& param) const override;
83 int lire_motcle_non_standard(const Motcle&, Entree&) override;
84
85 OBS_PTR(Champ_Don_base) la_gravite_;
86 int verif_=1;
87 ArrOfDouble Scalaire0_; // T0=Scalaire0_(0) ou C0(i)=Scalaire0_(i)
88 Nom NomScalaire_; // Temperature ou Concentration
89 VECT(Parser_U) fct_Scalaire0_;
91 OBS_PTR(Convection_Diffusion_std) equation_scalaire_;
92 inline void check() const;
93};
94
96{
97 // No verification other than at the first time step, if verification is not disabled and only for temperature
98 if (equation_scalaire().probleme().schema_temps().nb_pas_dt()>0 || equation_scalaire().probleme().reprise_effectuee() || verif_==0 || !sub_type(Convection_Diffusion_Temperature,equation_scalaire())) return;
99
100 // New: verify that average(T)==T0 only at the start of the computation
101 const double T0 = Scalaire0(0);
102 double moyenne_T = mp_moyenne_vect(equation_scalaire().inconnue().valeurs());
103 if (inf_ou_egal(moyenne_T,T0-10) || sup_ou_egal(moyenne_T,T0+10))
104 {
105 Cerr << "New criteria in TRUST for the Boussinesq source term definition:" << finl;
106 Cerr << "To avoid an incorrect choice for T0 value" << finl;
107 Cerr << "the initial average temperature on the domain " << equation_scalaire().probleme().domaine().le_nom() << finl;
108 Cerr << "should be between +/-10 degrees around T0 value." << finl;
109 Cerr << "The initial average temperature is : " << moyenne_T << finl;
110 Cerr << "T0 value is : " << T0 << finl;
111 Cerr << "So, you need to change T0 or the initial temperature field to respect this criteria defined by default." << finl;
112 Cerr << "If you want to overcome this criteria, which it is not recommended," << finl;
113 Cerr << "you can specify, into the Boussinesq source term definition, the option:" << finl;
114 Cerr << "verif_boussinesq 0" << finl;
116 }
117}
118
119// Method to compute the value on a cell-centered field for a uniform or multi-component field
120inline double valeur(const DoubleTab& valeurs, const int elem, const int dim)
121{
122 if(valeurs.nb_dim()==1)
123 return valeurs(elem);
124 else
125 return valeurs(elem,dim);
126}
127
128// Method to compute the value on a face bounded by elem1 and elem2 for a uniform or multi-component field
129inline double valeur(const DoubleTab& valeurs_champ, int elem1, int elem2, const int compo)
130{
131 if (valeurs_champ.dimension(0)==1)
132 return valeurs_champ(0,compo); // Uniform field
133 else
134 {
135 if (elem2<0) elem2 = elem1; // boundary face
136 if (valeurs_champ.nb_dim()==1)
137 return 0.5*(valeurs_champ(elem1)+valeurs_champ(elem2));
138 else
139 return 0.5*(valeurs_champ(elem1,compo)+valeurs_champ(elem2,compo));
140 }
141}
142KOKKOS_INLINE_FUNCTION
143double valeur(CDoubleTabView valeurs_champ, int valeurs_champ_dimension0, int nb_dim, int elem1, int elem2, const int compo, int nb_compo)
144{
145 if (valeurs_champ_dimension0==1)
146 return valeurs_champ(compo,0); // Uniform field
147 else
148 {
149 if (elem2 < 0) elem2 = elem1; // boundary face
150 if (nb_dim == 1)
151 return 0.5*(valeurs_champ(elem1,0)+valeurs_champ(elem2,0));
152 else
153 return 0.5*(valeurs_champ(elem1,compo)+valeurs_champ(elem2,compo));
154 }
155}
156
157#endif
158
class Champ_Don_base base class of Given Fields (not calculated)
Convection_Diffusion_Temperature Special case of Convection_Diffusion_std.
Convection_Diffusion_std This class is the base for equations modelling the transport.
const Nom & le_nom() const override
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this implementation.
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
Probleme_base & probleme()
Returns the problem associated with the equation.
A character string (Nom) in uppercase.
Definition Motcle.h:26
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
Helper class to factorize the readOn method of Objet_U classes.
Definition Param.h:112
class Parser_U Version of the Parser class, deriving from Objet_U.
Definition Parser_U.h:32
class Probleme_base It is a Probleme_U that is not a coupling.
const Domaine & domaine() const
Returns the domain associated with the problem.
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
Source_base A Source_base object is a term appearing on the right-hand side of an.
Definition Source_base.h:42
virtual DoubleTab & ajouter(DoubleTab &) const
int nb_dim() const
Definition TRUSTTab.h:199
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
Classe Terme_Boussinesq_base This class represents the gravity term appearing in the momentum equatio...
void set_param(Param &param) const override
OBS_PTR(Champ_Don_base) la_gravite_
void associer_pb(const Probleme_base &pb) override
OBS_PTR(Convection_Diffusion_std) equation_scalaire_
double Scalaire0(int i) const
const Convection_Diffusion_std & equation_scalaire() const
void mettre_a_jour(double temps) override
DOES NOTHING - to override in derived classes.
const Champ_Don_base & gravite() const
const ArrOfDouble & getScalaire0() const
DoubleTab & calculer(DoubleTab &resu) const override
VECT(Parser_U) fct_Scalaire0_
OBS_PTR(Champ_Don_base) beta_
int lire_motcle_non_standard(const Motcle &, Entree &) override
Reads non-simple-type parameters of an Objet_U from an input stream.
const Champ_Don_base & beta() const