TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
PDF_model.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// Model developped by Michel Belliard
17// Implementation : Georis Billo
18
19#include <PDF_model.h>
20#include <algorithm>
21#include <Param.h>
22
23Implemente_instanciable(PDF_model,"PDF_model",Objet_U) ;
24// XD bloc_pdf_model objet_lecture nul BRACE not_set
25
27{
29 return os;
30}
31
33{
34 // (xdata documentation is in the TRAD_2.org because we need a special bloc_lecture object)
35 Param param(que_suis_je());
36 param.ajouter_flag("moving_IB", &PDF_mobile_); // XD_ADD_P rien
37 // XD_CONT flag to activate moving_IB
38 param.ajouter_flag("use_pseudo_level_set_moving_PDF", &use_pseudo_level_set_moving_PDF_); // XD_ADD_P rien
39 // XD_CONT flag to activate use_pseudo_level_set_moving_PDF
40 param.ajouter_non_std("velocity_shape_IBM_function",(this),Param::OPTIONAL);
41 param.ajouter("IBM_spring_parameter",&raid_, Param::OPTIONAL); // XD_ADD_P floattant
42 // XD_CONT spring coefficient for moving IBM
43 param.ajouter("eta",&eta_, Param::REQUIRED); // XD_ADD_P floattant
44 // XD_CONT penalization coefficient
45 param.ajouter("bilan_PDF",&pdf_bilan_,Param::OPTIONAL); // XD_ADD_P entier
46 // XD_CONT type of PDF term balance (alone/with time/with convection)
47 param.ajouter("temps_relaxation_coefficient_PDF",&temps_relax_,Param::OPTIONAL); // XD_ADD_P floattant
48 // XD_CONT time relaxation on the forcing term to help
49 param.ajouter("echelle_relaxation_coefficient_PDF",&echelle_relax_,Param::OPTIONAL); // XD_ADD_P floattant
50 // XD_CONT time relaxation on the forcing term to help convergence
51 param.ajouter("regularization_coefficient_PDF",&regul_coeff_PDF_,Param::OPTIONAL); // XD_ADD_P floattant
52 // XD_CONT regularization coefficient for the forcing term (dead cell)
53 param.ajouter_flag("local",&local_); // XD_ADD_P rien
54 // XD_CONT whether the prescribed velocity is expressed in the global or local basis
55 param.ajouter_non_std("vitesse_imposee_data",(this),Param::OPTIONAL); // XD_ADD_P field_base
56 // XD_CONT Prescribed velocity as a field
57 param.ajouter_non_std("vitesse_imposee_fonction",(this),Param::OPTIONAL); // XD_ADD_P listchaine
58 // XD_CONT Prescribed velocity as a set of ananlytical component
59 param.ajouter_non_std("variable_imposee_data",(this),Param::OPTIONAL); // XD_ADD_P field_base
60 // XD_CONT Prescribed variable as a field
61 param.ajouter_non_std("variable_imposee_fonction",(this),Param::OPTIONAL); // XD_ADD_P listchaine
62 // XD_CONT Prescribed variable as a set of ananlytical component
63 param.lire_avec_accolades_depuis(is);
64 if (type_variable_imposee_ == -1)
65 {
66 Cerr << "PDF_model: you must specify either 'variable(vitesse)_imposee_data' or 'variable(vitesse)_imposee_fonction'" << finl;
68 }
69 coefku_ = 1./eta_;
70 return is;
71}
72
74{
75 Cerr << " PDF_model is reading imposed variable... " << finl;
76 if (un_mot == "variable_imposee_fonction" || un_mot == "vitesse_imposee_fonction")
77 {
79 Nom expr_vit_imp;
80 is >> dim_variable_;
81 parsers_.dimensionner(dim_variable_);
82 for (int i = 0; i < dim_variable_; i++)
83 {
84 is >> expr_vit_imp;
85 std::string sx(expr_vit_imp);
86 std::transform(sx.begin(), sx.end(), sx.begin(), ::toupper);
87 parsers_[i].setString(sx);
88 parsers_[i].setNbVar(4);
89 parsers_[i].addVar("x");
90 parsers_[i].addVar("y");
91 parsers_[i].addVar("z");
92 parsers_[i].addVar("t");
93 parsers_[i].parseString();
94 }
95 }
96 else if (un_mot == "variable_imposee_data" || un_mot == "vitesse_imposee_data")
97 {
99 is >> variable_imposee_lu_;
100 dim_variable_ = variable_imposee_lu_->valeurs().dimension(1);
101 }
102 else if (un_mot == "velocity_shape_IBM_function")
103 {
105 PDF_mobile_ = 1;
106
107 Nom expr_vit_shape;
108 int dim_vitesse_shape;
109 is >> dim_vitesse_shape;
110 assert(dim_vitesse_shape == Objet_U::dimension);
111 parsers_vitesse_shape_.dimensionner(dim_vitesse_shape);
112 for (int i = 0; i < dim_vitesse_shape; i++)
113 {
114 is >> expr_vit_shape;
115 std::string sx(expr_vit_shape);
116 std::transform(sx.begin(), sx.end(), sx.begin(), ::toupper);
117 parsers_vitesse_shape_[i].setString(sx);
118 parsers_vitesse_shape_[i].setNbVar(4);
119 parsers_vitesse_shape_[i].addVar("x");
120 parsers_vitesse_shape_[i].addVar("y");
121 parsers_vitesse_shape_[i].addVar("z");
122 parsers_vitesse_shape_[i].addVar("t");
123 parsers_vitesse_shape_[i].parseString();
124 }
125 }
126 else
127 {
128 Cerr << "PDF_model: token not understood: " << un_mot << finl;
130 }
131
132 if (un_mot == "vitesse_imposee_fonction" || un_mot == "vitesse_imposee_data")
133 {
135 {
136 Cerr << "PDF_model for a vector: Objet_U::dimension != dim_variable_: " << dim_variable_ << finl;
138 }
139 }
140 Cerr << " imposed variable dimension = " << dim_variable_ << finl;
141 if (local_ == 1 && (dim_variable_ != Objet_U::dimension))
142 {
143 Cerr << "PDF_model with local system for a vector only (Objet_U::dimension != dim_variable_) = " << dim_variable_ << finl;
145 }
146
147 return 1;
148}
149
151{
152 int nb_comp= Objet_U::dimension;
153 Noms nom_c11(nb_comp);
154 Noms unites11(nb_comp);
155 pb.discretisation().discretiser_champ("champ_elem",pb.domaine_dis(),vectoriel,nom_c11,unites11,nb_comp,0.,vitesse_shape_IBM_);
156 vitesse_shape_IBM_->valeurs() = 0.;
157}
158
159void PDF_model::affecter_variable_imposee(Domaine_VF& le_dom, const DoubleTab& coords)
160{
161 if (type_variable_imposee_ == 1)
162 {
163 // for node data
164 int nb_som_tot = le_dom.nb_som_tot();
165
166 DoubleTab& variable_imposee_ref = variable_imposee_->valeurs();
167
168 int dim = Objet_U::dimension;
169
170 ArrOfDouble x(dim);
171
172 for (int i = 0; i < nb_som_tot; i++)
173 {
174 for (int j = 0; j < dim; j++)
175 {
176 x[j] = coords(i,j);
177 }
178 for (int j = 0; j < dim_variable_; j++)
179 {
180 variable_imposee_ref(i,j) = get_variable_imposee(x,j);
181 }
182 // Cerr << "variable_imposee_ref(i) = " << variable_imposee_ref(i,0)<<" "<< variable_imposee_ref(i,1)<<" " << variable_imposee_ref(i,2) << finl;
183 }
184 }
185 else
186 {
187 Cerr << __FILE__ << ", line " << (int)__LINE__ << " : Unexpected error." << finl;
188 exit();
189 }
190}
191
192void PDF_model::affecter_vitesse_shape_IBM(Domaine_VF& le_dom_VF, const DoubleTab& coords, double temps)
193{
194 // for element data
195 const Domaine& le_dom = le_dom_VF.domaine();
196 int nb_elem_tot = le_dom.nb_elem_tot();
197 int nb_som_elem = le_dom.nb_som_elem();
198 const IntTab& elems = le_dom.les_elems() ;
199
200 DoubleTab& vitesse_depl_ref = vitesse_shape_IBM_->valeurs();
201 int dim = Objet_U::dimension;
202
203 ArrOfDouble x(dim);
204
205 for (int elem = 0; elem < nb_elem_tot; elem++)
206 {
207 for (int k = 0; k < dim; k++)
208 {
209 x[k] = 0.;
210 for (int nod=0; nod<nb_som_elem; nod++)
211 {
212 int nod_glob = elems(elem, nod);
213 x[k] += coords(nod_glob,k) / nb_som_elem;
214 }
215 }
216
217 for (int k = 0; k < dim; k++)
218 {
219 for (int i = 0; i < dim; i++) parsers_vitesse_shape_[k].setVar(i,x[i]);
220 parsers_vitesse_shape_[k].setVar(3, temps);
221 vitesse_depl_ref(elem,k) = parsers_vitesse_shape_[k].eval();
222 }
223// Cerr << "vitesse_depl_ref(elem) = " << vitesse_depl_ref(elem,0)<<" "<< vitesse_depl_ref(elem,1)<<" " << vitesse_depl_ref(elem,2) << finl;
224 }
225}
226
227double PDF_model::get_variable_imposee(ArrOfDouble& x,int comp)
228{
229 int dim = Objet_U::dimension;
230 for (int i = 0; i < dim; i++)
231 {
232 parsers_[comp].setVar(i,x[i]);
233 }
234 return parsers_[comp].eval();
235}
void discretiser_champ(const Motcle &directive, const Domaine_dis_base &z, const Nom &nom, const Nom &unite, int nb_comp, int nb_pas_dt, double temps, OWN_PTR(Champ_Inc_base)&champ, const Nom &sous_type=NOM_VIDE) const
int nb_som_elem() const
Returns the number of vertices of the geometric elements that make up the domain.
Definition Domaine.h:474
int_t nb_elem_tot() const
Definition Domaine.h:132
IntTab_t & les_elems()
Definition Domaine.h:129
class Domaine_VF
Definition Domaine_VF.h:44
const Domaine & domaine() const
int nb_som_tot() const
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
A character string (Nom) in uppercase.
Definition Motcle.h:26
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
An array of character strings (VECT(Nom)).
Definition Noms.h:26
Base class for TRUST objects (Objet_U).
Definition Objet_U.h:68
friend class Entree
Definition Objet_U.h:71
static int dimension
Definition Objet_U.h:94
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
: class PDF_model
Definition PDF_model.h:34
int pdf_bilan_
Definition PDF_model.h:63
int vitesse_PDF_donnee_
Definition PDF_model.h:66
bool PDF_mobile_
Definition PDF_model.h:64
int dim_variable_
Definition PDF_model.h:55
double echelle_relax_
Definition PDF_model.h:59
double get_variable_imposee(ArrOfDouble &, int)
void affecter_vitesse_shape_IBM(Domaine_VF &, const DoubleTab &, double)
double eta_
Definition PDF_model.h:56
bool local_
Definition PDF_model.h:62
bool use_pseudo_level_set_moving_PDF_
Definition PDF_model.h:65
void discretiser_vitesse_shape_IBM(const Probleme_base &)
int type_variable_imposee_
Definition PDF_model.h:61
double coefku_
Definition PDF_model.h:57
void affecter_variable_imposee(Domaine_VF &, const DoubleTab &)
double raid_
Definition PDF_model.h:68
int lire_motcle_non_standard(const Motcle &, Entree &) override
Reads non-simple-type parameters of an Objet_U from an input stream.
Definition PDF_model.cpp:73
double temps_relax_
Definition PDF_model.h:58
double regul_coeff_PDF_
Definition PDF_model.h:60
@ OPTIONAL
Definition Param.h:115
@ REQUIRED
Definition Param.h:115
class Probleme_base It is a Probleme_U that is not a coupling.
const Discretisation_base & discretisation() const
Returns the discretization associated with the problem.
const Domaine_dis_base & domaine_dis() const
Returns the discretized domain associated with the problem (const version).
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
Base class for output streams.
Definition Sortie.h:52