TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Terme_Source_Canal_perio_VEF_P1NC.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 <Terme_Source_Canal_perio_VEF_P1NC.h>
17#include <Domaine_VEF.h>
18#include <Domaine_Cl_VEF.h>
19#include <Periodique.h>
20#include <Probleme_base.h>
21#include <Equation_base.h>
22#include <Fluide_Dilatable_base.h>
23#include <communications.h>
24#include <SFichier.h>
25#include <Convection_Diffusion_std.h>
26
27// May 04: modification for QC source term
28//
29Implemente_instanciable(Terme_Source_Canal_perio_VEF_P1NC,"Canal_perio_VEF_P1NC",Terme_Source_Canal_perio);
30Implemente_instanciable(Terme_Source_Canal_perio_QC_VEF_P1NC,"Canal_perio_QC_VEF_P1NC",Terme_Source_Canal_perio_VEF_P1NC);
31
32
33//// printOn
34//
36{
37 return s << que_suis_je() ;
38}
39
40//
41// //// readOn
42// //
43
45{
47}
48
49//// printOn
50//
51
53{
54 return s << que_suis_je() ;
55}
56
57//
58//// readOn
59//
60
62{
64}
65
67 const Domaine_Cl_dis_base& domaine_Cl_dis)
68{
69 le_dom_VEF = ref_cast(Domaine_VEF, domaine_dis);
70 le_dom_Cl_VEF = ref_cast(Domaine_Cl_VEF, domaine_Cl_dis);
71}
72
73DoubleTab& Terme_Source_Canal_perio_VEF_P1NC::ajouter(DoubleTab& tab_resu) const
74{
75 const Domaine_VF& domaine_VF = le_dom_VEF.valeur();
76 int premiere_face_std = le_dom_VEF->premiere_face_std() ;
77 ArrOfDouble tab_s;
78 tab_s = source();
79 int nb_faces = domaine_VF.nb_faces();
80 int dim = Objet_U::dimension;
81 CDoubleArrView volumes_entrelaces_Cl = le_dom_Cl_VEF->volumes_entrelaces_Cl().view_ro();
82 CDoubleArrView volumes_entrelaces = domaine_VF.volumes_entrelaces().view_ro();
83 CDoubleArrView porosite_face = equation().milieu().porosite_face().view_ro();
84 CDoubleArrView s = tab_s.view_ro();
85 if (tab_s.size_array()==dim)
86 {
87 // Case Navier Stokes, s is uniform
88 DoubleTabView resu = tab_resu.view_rw();
89 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__), nb_faces, KOKKOS_LAMBDA(
90 const int num_face)
91 {
92 double vol = (num_face<premiere_face_std ? volumes_entrelaces_Cl(num_face) : volumes_entrelaces(num_face))*porosite_face(num_face);
93 for (int i=0; i<dim; i++)
94 resu(num_face,i) += s(i)*vol;
95 });
96 end_gpu_timer(__KERNEL_NAME__);
97 }
98 else
99 {
100 // Case Energy, s is non uniform
101 bilan_=0;
102 CIntArrView fd = domaine_VF.faces_doubles().view_ro();
103 DoubleArrView bilan = bilan_.view_rw();
104 DoubleArrView resu = static_cast<DoubleVect&>(tab_resu).view_rw();
105 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__), nb_faces, KOKKOS_LAMBDA(
106 const int num_face)
107 {
108 double vol = (num_face < premiere_face_std ? volumes_entrelaces_Cl(num_face) : volumes_entrelaces(num_face))*porosite_face(num_face);
109 double contrib = s[num_face]*vol;
110 resu(num_face)+= contrib;
111 Kokkos::atomic_add(&bilan(0), contrib*(1-0.5*fd[num_face]));
112 });
113 end_gpu_timer(__KERNEL_NAME__);
114 }
115 return tab_resu;
116}
117
119{
120 debit_e = 0.;
121 const Domaine_VF& domaine_VF = le_dom_VEF.valeur();
122 const Domaine_Cl_dis_base& domaine_Cl_dis = le_dom_Cl_VEF.valeur();
123 int nb_bords = domaine_VF.nb_front_Cl();
124 for (int n_bord=0; n_bord<nb_bords; n_bord++)
125 {
126 const Cond_lim& la_cl = domaine_Cl_dis.les_conditions_limites(n_bord);
127 if (sub_type(Periodique,la_cl.valeur()))
128 {
129 const Front_VF& le_bord = ref_cast(Front_VF,la_cl->frontiere_dis());
130 if (bord_periodique_ == le_bord.le_nom())
131 {
132 const Champ_Inc_base& velocity = (sub_type(Convection_Diffusion_std,equation()) ? ref_cast(Convection_Diffusion_std,equation()).vitesse_transportante() : equation().inconnue());
133 // Check we have really velocity:
134 assert(velocity.le_nom()=="vitesse");
135 int ndeb = le_bord.num_premiere_face();
136 int nfin = ndeb + le_bord.nb_faces()/2;
137 int axe = direction_ecoulement_;
138 int dim = Objet_U::dimension;
139 bool is_dilatable = equation().probleme().is_dilatable();
140 // In the quasi-compressible case, the mass flow rate must be conserved rather than the volumetric flow rate.
141 // For this reason, in the QC case, the velocity vectors are multiplied
142 // by the face-discretized density so that when integrating over the surface,
143 // one obtains a mass flow rate rather than a volumetric flow rate.
144 const DoubleTab& tab_rho_face = is_dilatable ? ref_cast(Fluide_Dilatable_base,equation().milieu()).rho_discvit() : velocity.valeurs() /* array of the same format but not used */;
145 CDoubleArrView rho_face = static_cast<const DoubleVect&>(tab_rho_face).view_ro();
146 CDoubleTabView face_normales = domaine_VF.face_normales().view_ro();
147 CDoubleArrView porosite_face = equation().milieu().porosite_face().view_ro();
148 CDoubleTabView vitesse = velocity.valeurs().view_ro();
149 Kokkos::parallel_reduce(start_gpu_timer(__KERNEL_NAME__),
150 Kokkos::RangePolicy<>(ndeb, nfin), KOKKOS_LAMBDA(
151 const int num_face, double& debit)
152 {
153 double debit_face = 0;
154 if (axe >= 0)
155 debit_face += porosite_face(num_face) * vitesse(num_face, axe) *
156 std::fabs(face_normales(num_face, axe));
157 else
158 {
159 for (int i = 0; i < dim; i++)
160 debit_face += porosite_face(num_face) * vitesse(num_face, i) *
161 face_normales(num_face, i);
162 }
163 debit += (is_dilatable ? rho_face(num_face) : 1) * debit_face;
164 }, Kokkos::Sum<double>(debit_e));
165 end_gpu_timer(__KERNEL_NAME__);
166 }
167 }
168 }
169 debit_e = mp_sum(debit_e);
170}
171
172
173
Class Champ_Inc_base.
DoubleTab & valeurs() override
Returns the array of field values at the current time.
class Cond_lim Generic class used to represent any class
Definition Cond_lim.h:31
Convection_Diffusion_std This class is the base for equations modelling the transport.
class Domaine_Cl_dis_base Domaine_Cl_dis_base objects represent discretized boundary conditions
const Cond_lim & les_conditions_limites(int) const
Returns the i-th boundary condition.
class Domaine_VEF
Definition Domaine_VEF.h:53
class Domaine_VF
Definition Domaine_VF.h:44
int nb_faces() const
Returns the total number of faces.
Definition Domaine_VF.h:471
DoubleVect & volumes_entrelaces()
Definition Domaine_VF.h:99
virtual double face_normales(int face, int comp) const
Definition Domaine_VF.h:47
ArrOfInt & faces_doubles()
Returns 1 for faces belonging to a periodic boundary or a shared item, 0 by default.
Definition Domaine_VF.h:566
class Domaine_dis_base This class is the base of the hierarchy of discretized domains.
int nb_front_Cl() const
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
virtual const Champ_Inc_base & inconnue() const =0
Probleme_base & probleme()
Returns the problem associated with the equation.
const Nom & le_nom() const override
Returns the name of the field.
Base class for a dilatable fluid, inheriting from Fluide_base.
class Front_VF
Definition Front_VF.h:36
int nb_faces() const
Definition Front_VF.h:53
int num_premiere_face() const
Definition Front_VF.h:63
const Nom & le_nom() const override
Returns the name of the geometric boundary.
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
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 Periodique This class represents a periodic boundary condition.
Definition Periodique.h:31
bool is_dilatable() const
static double mp_sum(double)
Computes the sum of x over all processors in the current group.
Definition Process.cpp:145
Base class for output streams.
Definition Sortie.h:52
DoubleVect & bilan()
Definition Source_base.h:88
DoubleVect bilan_
_SIZE_ size_array() const
std::enable_if_t< is_default_exec_space< EXEC_SPACE >, ConstView< _TYPE_, _SHAPE_ > > view_ro() const
Definition TRUSTTab.h:261
std::enable_if_t< is_default_exec_space< EXEC_SPACE >, View< _TYPE_, _SHAPE_ > > view_rw()
Definition TRUSTTab.h:291
DoubleTab & ajouter(DoubleTab &) const override
public_for_cuda void calculer_debit(double &) const override
void associer_domaines(const Domaine_dis_base &, const Domaine_Cl_dis_base &) override
Source term to keep a constant flow rate in a channel with periodic boundary conditions.
ArrOfDouble source() const
Term source calculation (called by VDF and VEF implementations) TODO: returning an ArrOfDouble is baa...