TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Modifier_pour_fluide_dilatable.cpp
1/****************************************************************************
2* Copyright (c) 2025, 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 <Modifier_pour_fluide_dilatable.h>
17#include <Fluide_Dilatable_base.h>
18#include <Modele_turbulence_hyd_base.h>
19#include <Equation_base.h>
20#include <Probleme_base.h>
21#include <Domaine_VF.h>
22#include <TRUSTVect.h>
23
24static void multiplier_ou_diviser(DoubleVect& x, const DoubleVect& y, int diviser)
25{
26 if (!diviser)
27 tab_multiply_any_shape(x, y, VECT_REAL_ITEMS);
28 else
29 tab_divide_any_shape(x, y, VECT_REAL_ITEMS);
31 //Debog::verifier("multiplier_ou_diviser x/y after x:",x);
32}
33
34// Modif B.M: only the real part of the array is filled.
35void multiplier_diviser_rho(DoubleVect& tab, const Fluide_Dilatable_base& le_fluide, int diviser)
36{
37 const Domaine_VF& zvf = ref_cast(Domaine_VF, le_fluide.vitesse().domaine_dis_base());
38 // Descriptors of the element and face arrays:
39 const Domaine& domaine = zvf.domaine();
40 const MD_Vector& md_elem = domaine.les_elems().get_md_vector();
41 const MD_Vector& md_faces = zvf.md_vector_faces();
42 const MD_Vector& md_faces_bord = zvf.md_vector_faces_bord();
43
44 if (tab.get_md_vector() == md_faces_bord)
45 {
46 const DoubleTab& rho = ref_cast(Fluide_Dilatable_base,le_fluide).rho_discvit();
47 DoubleTrav rho_bord;
48 // B.M. creating a copy to avoid manipulating size checks in multiply_any_shape
49 // or creating a DoubleTab pointing to rho...
50 zvf.creer_tableau_faces_bord(rho_bord, RESIZE_OPTIONS::NOCOPY_NOINIT);
51 rho_bord.inject_array(rho, rho_bord.size());
52 multiplier_ou_diviser(tab, rho_bord, diviser);
53 return;
54 }
55
56 if (tab.get_md_vector() == md_faces)
57 {
58 const DoubleTab& rho_faces = ref_cast(Fluide_Dilatable_base,le_fluide).rho_discvit();
59 multiplier_ou_diviser(tab, rho_faces, diviser);
60 return;
61 }
62
63 const DoubleTab& rho = le_fluide.masse_volumique().valeurs();
64 if (tab.get_md_vector() == md_elem && rho.get_md_vector() == md_elem)
65 {
66 multiplier_ou_diviser(tab, rho, diviser);
67 return;
68 }
69
70 if (tab.get_md_vector() == md_elem && rho.get_md_vector() == md_faces)
71 {
72 // rho must be computed at elements
73 DoubleTrav tab_rho_elem;
74 domaine.creer_tableau_elements(tab_rho_elem, RESIZE_OPTIONS::NOCOPY_NOINIT);
75 const int nb_elem_tot = domaine.nb_elem_tot();
76 const int nfe = zvf.elem_faces().dimension(1);
77 const double facteur = 1. / nfe;
78 CDoubleArrView tab_rho = static_cast<const DoubleVect&>(le_fluide.masse_volumique().valeurs()).view_ro();
79 CIntTabView elem_faces = zvf.elem_faces().view_ro();
80 DoubleArrView rho_elem = static_cast<DoubleVect&>(tab_rho_elem).view_wo();
81 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__), nb_elem_tot, KOKKOS_LAMBDA(const int elem)
82 {
83 double x = 0.;
84 for (int face = 0; face < nfe; face++)
85 {
86 int f = elem_faces(elem, face);
87 x += tab_rho[f];
88 }
89 rho_elem[elem] = x * facteur;
90 });
91 end_gpu_timer(__KERNEL_NAME__);
92 multiplier_ou_diviser(tab, tab_rho_elem, diviser);
93 return;
94 }
95
96 Cerr << "Error in Modifier_pour_fluide_dilatable.cpp: multiplier_rho. Invalid discretization of tab and rho." << finl;
98}
99
100/*! @brief Multiplies the array val by the density if the fluid is dilatable.
101 *
102 * @brief The array val can have various localizations (determined from get_md_vector())
103 * and can be of type DoubleTab with arbitrary dimension(i>0) (multiple components).
104 *
105 */
106void multiplier_par_rho_si_dilatable(DoubleVect& val, const Milieu_base& mil)
107{
108 if (sub_type(Fluide_Dilatable_base, mil))
109 multiplier_diviser_rho(val, ref_cast(Fluide_Dilatable_base, mil), 0 /* multiplier */);
110 else
111 {
112 Cerr << "What ?? The method multiplier_par_rho_si_dilatable should not be called since your fluid is not dilatable !!" << finl;
114 }
115}
116
117/*! @brief Same as multiplier_par_rho_si_dilatable but divides by rho.
118 *
119 */
120void diviser_par_rho_si_dilatable(DoubleVect& val, const Milieu_base& mil)
121{
122 if (sub_type(Fluide_Dilatable_base, mil))
123 multiplier_diviser_rho(val, ref_cast(Fluide_Dilatable_base, mil), 1 /* diviser */);
124 else
125 {
126 Cerr << "What ?? The method diviser_par_rho_si_dilatable should not be called since your fluid is not dilatable !!" << finl;
128 }
129}
130
131void correction_nut_et_cisaillement_paroi_si_qc(Modele_turbulence_hyd_base& mod)
132{
133 // check if the fluid is QC (quasi-compressible)
134 if (sub_type(Fluide_Dilatable_base, mod.equation().probleme().milieu()))
135 {
136 const Fluide_Dilatable_base& le_fluide = ref_cast(Fluide_Dilatable_base, mod.equation().probleme().milieu());
137 // 1 multiply nu_t by rho
138
139 DoubleTab& nut = ref_cast_non_const(DoubleTab, mod.viscosite_turbulente().valeurs());
140 multiplier_diviser_rho(nut, le_fluide, 0 /* multiplier */);
141
142 // 2 Modify the wall shear stress
143 const DoubleTab& cisaillement_paroi = mod.loi_paroi().Cisaillement_paroi();
144 DoubleTab& cisaillement = ref_cast_non_const(DoubleTab, cisaillement_paroi);
145 multiplier_diviser_rho(cisaillement, le_fluide, 0 /* multiplier */);
146 cisaillement.echange_espace_virtuel();
147 }
148 else
149 {
150 Cerr << "What ?? The method Correction_nut_et_cisaillement_paroi_si_qc should not be called since your fluid is not dilatable !!" << finl;
152 }
153}
DoubleTab & valeurs() override
Overrides Champ_base::valeurs() Returns the array of values.
const Domaine_dis_base & domaine_dis_base() const override
virtual DoubleTab & valeurs()=0
class Domaine_VF
Definition Domaine_VF.h:44
const MD_Vector & md_vector_faces() const
Definition Domaine_VF.h:158
void creer_tableau_faces_bord(Array_base &, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT) const
int elem_faces(int i, int j) const
Returns the index of the i-th face of element num_elem; the face numbering convention is.
Definition Domaine_VF.h:542
const MD_Vector & md_vector_faces_bord() const
Definition Domaine_VF.h:157
const Domaine & domaine() const
Probleme_base & probleme()
Returns the problem associated with the equation.
Base class for a dilatable fluid, inheriting from Fluide_base.
const Champ_Inc_base & vitesse() const
: This class is an OWN_PTR but the pointed object is shared among multiple
Definition MD_Vector.h:48
Milieu_base This class is the base of the (physical) medium hierarchy.
Definition Milieu_base.h:50
virtual const Champ_base & masse_volumique() const
Returns the mass density of the medium (const version).
Base class for the turbulence model hierarchy for Navier-Stokes equations.
const Turbulence_paroi_base & loi_paroi() const
const Champ_Fonc_base & viscosite_turbulente() const
Equation_base & equation()
Returns the equation associated with the turbulence model.
virtual const Milieu_base & milieu() const
Returns the physical medium 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
TRUSTArray & inject_array(const TRUSTArray &source, _SIZE_ nb_elements=-1, _SIZE_ first_element_dest=0, _SIZE_ first_element_source=0)
_SIZE_ size() const
Definition TRUSTVect.tpp:45
virtual const MD_Vector & get_md_vector() const
Definition TRUSTVect.h:123
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")
const DoubleTab & Cisaillement_paroi() const