TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Modele_turbulence_hyd_LES_Wale_VEF.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 <Modele_turbulence_hyd_LES_Wale_VEF.h>
17#include <Schema_Temps_base.h>
18#include <Equation_base.h>
19#include <Domaine_VEF.h>
20#include <Champ_P1NC.h>
21#include <TRUSTTrav.h>
22#include <Param.h>
23#include <Debog.h>
24
25Implemente_instanciable_sans_constructeur(Modele_turbulence_hyd_LES_Wale_VEF, "Modele_turbulence_hyd_sous_maille_Wale_VEF", Modele_turbulence_hyd_LES_VEF_base);
26
31
32Sortie& Modele_turbulence_hyd_LES_Wale_VEF::printOn(Sortie& s) const { return s << que_suis_je() << " " << le_nom(); }
33
35
37{
39 param.ajouter("cw", &cw_);
40 param.ajouter_condition("value_of_cw_ge_0", "sous_maille_Wale model constant must be positive.");
41}
42
44{
45 const Domaine_VEF& domaine_VEF = ref_cast(Domaine_VEF, le_dom_VF_.valeur());
46 double temps = mon_equation_->inconnue().temps();
47 DoubleTab& tab_visco_turb = la_viscosite_turbulente_->valeurs();
48 const int nb_elem = domaine_VEF.nb_elem();
49 const DoubleTab& la_vitesse = mon_equation_->inconnue().valeurs();
50 const Domaine_Cl_VEF& domaine_Cl_VEF = ref_cast(Domaine_Cl_VEF, le_dom_Cl_.valeur());
51
52 if (tab_visco_turb.size() != nb_elem)
53 {
54 Cerr << "Size error for the array containing the values of the turbulent viscosity." << finl;
55 exit();
56 }
57 Debog::verifier("Modele_turbulence_hyd_LES_Wale_VEF::calculer_viscosite_turbulente visco_turb 0", tab_visco_turb);
58
59 const int nb_elem_tot = domaine_VEF.nb_elem_tot();
60 DoubleTrav tab_duidxj(nb_elem_tot,dimension,dimension);
61 // Patrick: we work on the filtered field.
62 //const Champ_P1NC& ch=(const Champ_P1NC&) mon_equation->inconnue();
63 //DoubleTab ubar(la_vitesse);
64 //ch.filtrer_L2(ubar);
65 //Champ_P1NC::calcul_gradient(ubar,duidxj,domaine_Cl_VEF);
66 Champ_P1NC::calcul_gradient(la_vitesse,tab_duidxj,domaine_Cl_VEF);
67
68 double cw = cw_; // Necessary to avoid kernel crash
69 int dim = Objet_U::dimension;
70
71 CDoubleArrView l = l_.view_ro();
72 CDoubleTabView3 duidxj = tab_duidxj.view_ro<3>();
73 DoubleArrView visco_turb = static_cast<DoubleVect&>(tab_visco_turb).view_rw();
74
75 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__),
76 nb_elem,
77 KOKKOS_LAMBDA (int elem)
78 {
79 double gij2[3][3];
80 double sd[3][3];
81
82 // Compute the term gij2.
83 for (int i = 0; i < dim; i++)
84 for (int j = 0; j < dim; j++)
85 {
86 gij2[i][j] = 0;
87 for (int k = 0; k < dim; k++)
88 gij2[i][j] += duidxj(elem,i,k) * duidxj(elem,k,j);
89 }
90
91 // Compute the term gkk2.
92 double gkk2 = 0;
93 for (int k = 0; k < dim; k++)
94 gkk2 += gij2[k][k];
95
96 // Compute sd.
97 for (int i = 0; i < dim; i++)
98 for (int j = 0; j < dim; j++)
99 {
100 sd[i][j] = 0.5 * (gij2[i][j] + gij2[j][i]);
101 if (i == j)
102 sd[i][j] -= gkk2 / 3.; // Term behind the Kronecker tensor.
103 }
104
105 // Compute sd2 and Sij2.
106 double sd2 = 0.;
107 double Sij2 = 0.;
108 for (int i = 0; i < dim; i++)
109 for (int j = 0; j < dim; j++)
110 {
111 sd2 += sd[i][j] * sd[i][j];
112 //Displacement of the Sij computation
113 double Sij = 0.5 * (duidxj(elem,i,j) + duidxj(elem,j,i));
114 Sij2 += Sij * Sij;
115 }
116
117 // Compute OP1 and OP2.
118 // Replace pow by sqrt and multiply, faster
119 //OP1=pow(sd2,1.5);
120 double OP1 = sd2 * sqrt(sd2);
121 //OP2=pow(Sij2,2.5)+pow(sd2,1.25);
122 double OP2 = Sij2 * Sij2 * sqrt(Sij2) + sd2 * sqrt(sqrt(sd2));
123
124 if (OP1 != 0.) // so sd2 and OP2 are consequently non-zero
125 visco_turb(elem) = cw * cw * l(elem) * l(elem) * OP1 / OP2;
126 else
127 visco_turb(elem) = 0;
128 }); // end of loop over elements
129 end_gpu_timer(__KERNEL_NAME__);
130
131 Debog::verifier("Modele_turbulence_hyd_LES_Wale_VEF::calculer_viscosite_turbulente visco_turb 1", tab_visco_turb);
132
133 la_viscosite_turbulente_->changer_temps(temps);
134 return la_viscosite_turbulente_;
135}
class Champ_Fonc_base Base class of fields that are functions of a calculated quantity
static DoubleTab & calcul_gradient(const DoubleTab &, DoubleTab &, const Domaine_Cl_VEF &)
static void verifier(const char *const msg, double)
Definition Debog.cpp:21
class Domaine_VEF
Definition Domaine_VEF.h:53
int nb_elem_tot() const
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
Class Modele_turbulence_hyd_LES_VEF_base.
class Modele_turbulence_hyd_LES_Wale_VEF This class implements the WALE subgrid model
public_for_cuda Champ_Fonc_base & calculer_viscosite_turbulente() override
virtual void set_param(Param &) const
Definition Objet_U.h:130
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 const Nom & le_nom() const
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this implementation.
Definition Objet_U.cpp:317
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
Helper class to factorize the readOn method of Objet_U classes.
Definition Param.h:112
void ajouter_condition(const char *condition, const char *message, const char *name=0)
Declare a post-read logical condition that must hold on the parameter values.
Definition Param.cpp:496
void ajouter(const char *keyword, const int *value, Param::Nature nat=Param::OPTIONAL)
Register an integer parameter.
Definition Param.cpp:364
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
virtual void declare_support_masse_volumique(int ok)
The constructor of a derived class that uses the density field must call this function with the value...
std::enable_if_t< is_default_exec_space< EXEC_SPACE >, ConstView< _TYPE_, _SHAPE_ > > view_ro() const
Definition TRUSTTab.h:261
_SIZE_ size() const
Definition TRUSTVect.tpp:45