TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Masse_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 <Masse_VEF_P1NC.h>
17#include <Domaine_Cl_VEF.h>
18#include <Domaine_VEF.h>
19#include <Dirichlet.h>
20#include <Dirichlet_homogene.h>
21#include <Symetrie.h>
22#include <Equation_base.h>
23#include <Matrice_Morse.h>
24#include <Milieu_base.h>
25#include <Device.h>
26
27Implemente_instanciable(Masse_VEF_P1NC,"Masse_VEF_P1NC",Solveur_Masse_base);
28
29
30// printOn()
31/////
32
34{
35 return s << que_suis_je() << " " << le_nom();
36}
37
38//// readOn
39//
40
42{
43 return s ;
44}
45
46
47
48///////////////////////////////////////////////////////////////
49//
50// Implementation of the Masse_VEF_P1NC class member functions
51//
52//////////////////////////////////////////////////////////////
53
54
55DoubleTab& Masse_VEF_P1NC::appliquer_impl(DoubleTab& tab_sm) const
56{
57 const Domaine_Cl_VEF& domaine_Cl_VEF = ref_cast(Domaine_Cl_VEF,le_dom_Cl_VEF.valeur());
58 const Domaine_VEF& domaine_VEF = le_dom_VEF.valeur();
59 const DoubleVect& tab_volumes_entrelaces = domaine_VEF.volumes_entrelaces();
60
61 int nfa = domaine_VEF.nb_faces();
62 int num_std = domaine_VEF.premiere_face_std();
63 int num_int = domaine_VEF.premiere_face_int();
64 int nbcomp = tab_sm.line_size();
65
66 if (nfa != tab_sm.dimension(0))
67 {
68 Cerr << "Error in Masse_VEF_P1NC: ";
69 Cerr << "number of faces: " << nfa
70 << " size of right-hand side: " << tab_sm.dimension(0) << finl;
71 exit();
72 }
73
74 // Process standard faces that carry no boundary conditions
75 CDoubleArrView porosite_face = equation().milieu().porosite_face().view_ro();
76 CDoubleArrView volumes_entrelaces = tab_volumes_entrelaces.view_ro();
77 DoubleTabView sm = tab_sm.view_rw();
78
79 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__),
80 Kokkos::MDRangePolicy<Kokkos::Rank<2>>({num_std,0}, {nfa,nbcomp}),
81 KOKKOS_LAMBDA(int face, int comp)
82 {
83 sm(face, comp) /= (volumes_entrelaces(face) * porosite_face(face));
84 });
85 end_gpu_timer(__KERNEL_NAME__);
86
87 // Process non-standard faces
88 // boundary faces are non-standard faces that may carry boundary conditions
89 // internal non-standard faces carry no boundary conditions
90
91 // Process boundary conditions
92 CIntTabView face_voisins = domaine_VEF.face_voisins().view_ro();
93 CDoubleTabView normales = domaine_VEF.face_normales().view_ro();
94 CDoubleArrView volumes_entrelaces_Cl = domaine_Cl_VEF.volumes_entrelaces_Cl().view_ro();
95 for (int n_bord = 0; n_bord < domaine_VEF.nb_front_Cl(); n_bord++)
96 {
97 const Cond_lim& la_cl = domaine_Cl_VEF.les_conditions_limites(n_bord);
98 const Front_VF& le_bord = ref_cast(Front_VF,la_cl->frontiere_dis());
99 int num1 = le_bord.num_premiere_face();
100 int num2 = num1 + le_bord.nb_faces();
101
102 if ((sub_type(Dirichlet,la_cl.valeur())) ||
103 (sub_type(Dirichlet_homogene,la_cl.valeur())))
104 {
105 // For Dirichlet faces set sm to 0
106 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__),
107 range_1D(num1, num2),
108 KOKKOS_LAMBDA(const int face)
109 {
110 for (int comp = 0; comp < nbcomp; comp++)
111 sm(face, comp) = 0;
112 });
113 end_gpu_timer(__KERNEL_NAME__);
114 }
115 else if ((sub_type(Symetrie,la_cl.valeur())) && (domaine_Cl_VEF.equation().inconnue().nature_du_champ()==vectoriel))
116 {
117 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__),
118 range_1D(num1, num2),
119 KOKKOS_LAMBDA(const int face)
120 {
121 double psc = 0;
122 double surf = 0;
123 for (int comp = 0; comp < nbcomp; comp++)
124 {
125 psc += sm(face,comp) * normales(face,comp);
126 surf += normales(face,comp) * normales(face,comp);
127 }
128 psc /= surf;
129 for(int comp = 0; comp < nbcomp; comp++)
130 {
131 sm(face,comp) -= psc * normales(face,comp);
132 sm(face,comp) /= (volumes_entrelaces_Cl(face) *
133 porosite_face(face));
134 }
135 });
136 end_gpu_timer(__KERNEL_NAME__);
137 }
138 else
139 {
140 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__),
141 range_1D(num1, num2),
142 KOKKOS_LAMBDA(
143 const int face)
144 {
145 int elem = face_voisins(face, 0);
146 if (elem == -1) elem = face_voisins(face, 1);
147 for (int comp = 0; comp < nbcomp; comp++)
148 sm(face, comp) /= (volumes_entrelaces_Cl(face) * porosite_face(face));
149 });
150 end_gpu_timer(__KERNEL_NAME__);
151 }
152 }
153
154 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__),
155 range_2D({num_int,0}, {num_std,nbcomp}),
156 KOKKOS_LAMBDA(int face, int comp)
157 {
158 sm(face,comp) /= (volumes_entrelaces_Cl(face) * porosite_face(face));
159 });
160 end_gpu_timer(__KERNEL_NAME__);
161
162 //tab_sm.echange_espace_virtuel();
163 //Debog::verifier("Masse_VEF_P1NC::appliquer, tab_sm=",tab_sm);
164 return tab_sm;
165}
166
167
168//
170{
171 le_dom_VEF = ref_cast(Domaine_VEF, le_dom_dis_base);
172}
173
175{
176 le_dom_Cl_VEF = ref_cast(Domaine_Cl_VEF, le_dom_Cl_dis_base);
177}
178
179
180Matrice_Base& Masse_VEF_P1NC::ajouter_masse(double dt, Matrice_Base& matrice, int penalisation) const
181{
182 if (penalisation||(le_dom_Cl_VEF->equation().inconnue().nature_du_champ()!=vectoriel))
183 return Solveur_Masse_base::ajouter_masse(dt,matrice,penalisation);
184 // Otherwise temporarily change the field nature so that appliquer_impl does not project onto n.
185 Champ_Inc_base& inco=ref_cast_non_const( Champ_Inc_base,le_dom_Cl_VEF->equation().inconnue());
186 inco.fixer_nature_du_champ(multi_scalaire);
187 Solveur_Masse_base::ajouter_masse(dt,matrice,penalisation);
188 inco.fixer_nature_du_champ(vectoriel);
189 return matrice;
190
191
192}
193
194
195DoubleTab& Masse_VEF_P1NC::ajouter_masse(double dt, DoubleTab& x, const DoubleTab& y, int penalisation, bool use_old_volumes) const
196{
197 if (penalisation||(le_dom_Cl_VEF->equation().inconnue().nature_du_champ()!=vectoriel))
198 return Solveur_Masse_base::ajouter_masse(dt, x, y, penalisation, use_old_volumes);
199
200 // Otherwise temporarily change the field nature so that appliquer_impl does not project onto n.
201 Champ_Inc_base& inco=ref_cast_non_const( Champ_Inc_base,le_dom_Cl_VEF->equation().inconnue());
202 inco.fixer_nature_du_champ(multi_scalaire);
203 Solveur_Masse_base::ajouter_masse(dt, x, y, penalisation, use_old_volumes);
204 inco.fixer_nature_du_champ(vectoriel);
205 return x;
206}
207
208DoubleTab& Masse_VEF_P1NC::corriger_solution(DoubleTab& x, const DoubleTab& y, int incr) const
209{
210 // assert(penalisation_==1);
211
212 return Solveur_Masse_base::corriger_solution( x, y, incr) ;
213}
Class Champ_Inc_base.
class Cond_lim Generic class used to represent any class
Definition Cond_lim.h:31
Classe Dirichlet_homogene This class is the base class of the hierarchy of homogeneous Dirichlet-type...
Dirichlet This class is the base class of the hierarchy of Dirichlet-type boundary conditions.
Definition Dirichlet.h:31
DoubleVect & volumes_entrelaces_Cl()
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
int premiere_face_std() const
Definition Domaine_VEF.h:79
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
int premiere_face_int() const
A face is internal if and only if it separates two elements.
Definition Domaine_VF.h:463
int face_voisins(int num_face, int i) const
Returns the neighbouring element of num_face in direction i.
Definition Domaine_VF.h:418
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
virtual Nature_du_champ fixer_nature_du_champ(Nature_du_champ nat)
Sets the nature of a field: scalar, multiscalar, vectorial.
virtual Nature_du_champ nature_du_champ() const
Definition Field_base.h:77
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
DoubleTab & corriger_solution(DoubleTab &x, const DoubleTab &y, int incr=0) const override
void associer_domaine_cl_dis_base(const Domaine_Cl_dis_base &) override
void associer_domaine_dis_base(const Domaine_dis_base &) override
Matrice_Base & ajouter_masse(double dt, Matrice_Base &matrice, int penalisation=1) const override
DoubleTab & appliquer_impl(DoubleTab &sm) const override
Matrice_Base class - Base class of the matrix hierarchy.
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
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
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
Solveur_Masse_base Represents the mass matrix of an equation.
virtual Matrice_Base & ajouter_masse(double dt, Matrice_Base &matrice, int penalisation=1) const
virtual DoubleTab & corriger_solution(DoubleTab &x, const DoubleTab &y, int incr=0) const
Base class for output streams.
Definition Sortie.h:52
Symetrie On symmetry faces, the following properties hold:
Definition Symetrie.h:37
std::enable_if_t< is_default_exec_space< EXEC_SPACE >, View< _TYPE_, _SHAPE_ > > view_rw()
Definition TRUSTTab.h:291
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
int line_size() const
Definition TRUSTVect.tpp:67