TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Porosites_champ.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 <Porosites_champ.h>
17#include <Champ_Don_base.h>
18#include <Sous_Domaine.h>
19#include <Domaine_VF.h>
20
21/*! @brief renvoit le tableau res, res=org si flag=0, res= porosite*org sinon attention ne pas modifier res car sinon on ne sait pas ce que l'on fait sur org (d'ou le renvoi const)
22 *
23 */
24const DoubleTab& modif_par_porosite_si_flag(const DoubleTab& org, DoubleTab& res, int flag, const DoubleVect& porosite)
25{
26 mapToDevice(porosite); // Copy porosity onto device cause rarely used in Operators so local_min_abs_vect() was generally done on CPU !
27 // Switch mp_min_vect to local_min_abs_vect to avoid mp_min call during the calculation of operators (convection, diffusion,...)
28 if ((flag == 0) || (local_min_abs_vect(porosite) == 1))
29 res.ref(org);
30 else
31 {
32 assert(org.dimension_tot(0) == porosite.size_totale());
33 res = org;
34 tab_multiply_any_shape(res, porosite, VECT_ALL_ITEMS);
35 }
36 return res;
37}
38
39// TODO : REMOVE for V1.9.3 ...
40Implemente_instanciable(Porosites_champ,"Porosites_champ",Interprete);
44{
45 Cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << finl;
46 Cerr << "TRUST-V1.9.1 : Porosites_champ interpret is no more available !" << finl;
47 Cerr << "You should define the porosity in the medium bloc, for example like this : " << finl;
48 Cerr << "porosites_champ champ_fonc_xyz dom 1 1-0.5*(y>1)*(y<2) " << finl;
50 return is;
51}
52
53
54Implemente_instanciable(Porosites,"Porosites",Objet_U);
55// XD porosites objet_u porosites NO_BRACE To define the volume porosity and surface porosity that are uniform in every
56// XD_CONT direction in space on a sub-area. NL2 Porosity was only usable in VDF discretization, and now available for
57// XD_CONT VEF P1NC/P0. NL2 Observations : NL2 - Surface porosity values must be given in every direction in space (set
58// XD_CONT this value to 1 if there is no porosity), NL2 - Prior to defining porosity, the problem must have been
59// XD_CONT discretized.NL2 Can \'t be used in VEF discretization, use Porosites_champ instead.
60// XD attr aco chaine(into=["{"]) aco REQ Opening curly bracket.
61// XD attr sous_zone|sous_zone1 chaine sous_zone REQ Name of the sub-area to which porosity are allocated.
62// XD attr bloc bloc_lecture_poro bloc REQ Surface and volume porosity values.
63// XD attr sous_zone2 chaine sous_zone2 OPT Name of the 2nd sub-area to which porosity are allocated.
64// XD attr bloc2 bloc_lecture_poro bloc2 OPT Surface and volume porosity values.
65// XD attr acof chaine(into=["}"]) acof REQ Closing curly bracket.
66
67// XD bloc_lecture_poro objet_lecture nul BRACE Surface and volume porosity values.
68// XD attr volumique floattant volumique REQ Volume porosity value.
69// XD attr surfacique list surfacique REQ Surface porosity values (in X, Y, Z directions).
70
71Sortie& Porosites::printOn(Sortie& os) const { return Objet_U::printOn(os); }
72
74{
75 is_read_ = true;
76 Nom mot;
77 Motcle motcle;
78 is >> mot;
79 double vol = 1.;
80 DoubleVect surf;
81
82 if (mot != "{")
83 {
84 Cerr << "Porosites : { expected after porosites instead of " << mot << finl;
86 }
87 for (is >> mot; mot != "}"; is >> mot)
88 {
89 // 1er truc a lire : nom sous-domaine
90 les_sous_domaines.push_back(mot);
91 // 2eme truc a lire : accolade
92 is >> mot;
93 if (mot != "{")
94 {
95 Cerr << "Porosites : { expected after the sous domaine instead of " << mot << finl;
97 }
98 for (is >> motcle; motcle != "}"; is >> motcle)
99 {
100 if (motcle == "VOLUMIQUE")
101 {
102 is >> vol;
103 porosites_volu.push_back(vol);
104 }
105 else if (motcle == "SURFACIQUE")
106 {
107 is >> surf;
108 porosites_surf.push_back(surf);
109 }
110 else
111 {
112 Cerr << "Porosites : " << motcle << " is not known !! Use either VOLUMIQUE or SURFACIQUE" << finl;
114 }
115 }
116 }
117 assert(les_sous_domaines.size() == porosites_volu.size() && les_sous_domaines.size() == porosites_surf.size());
118
119 // quelques tests !
120 for (const auto &sz : les_sous_domaines)
121 if (!sub_type(Sous_Domaine, Interprete::objet(sz)))
122 {
123 Cerr << sz << " is of type " << Interprete::objet(sz).que_suis_je() << ". We waited an object of type Sous_Domaine" << finl;
125 }
126
127 for (const auto &val : porosites_surf)
128 if (val.local_min_vect() <= 0)
129 {
130 Cerr << "You entered a negative surfacic porosity ! " << finl;
132 }
133
134 return is;
135}
136
137void Porosites::remplir_champ(const Domaine_VF& zvf, DoubleVect& porosite_elem, DoubleVect& porosite_face)
138{
139 if (zvf.que_suis_je().debute_par("Domaine_VEF"))
140 {
141 Cerr << "Porosites should no longer be used in VEF. Porosites_champ should be used instead." << finl;
143 }
144
145 const IntTab& elem_faces = zvf.elem_faces();
146 const int sz = (int)les_sous_domaines.size();
147 int nb_faces_elem = zvf.domaine().nb_faces_elem();
148
149 for (int ind = 0; ind < sz; ind++)
150 {
151 Sous_Domaine& ssz = ref_cast(Sous_Domaine, Interprete::objet(les_sous_domaines[ind]));
152 const double porsurfmin = porosites_surf[ind].local_min_vect();
153
154 if ((porosites_volu[ind] != 1) && (porsurfmin != 1))
155 {
156 for (int i = 0; i < ssz.nb_elem_tot(); i++)
157 {
158 const int elem = ssz(i);
159 porosite_elem(elem) = porosites_volu[ind];
160 for (int j = 0; j < nb_faces_elem; j++)
161 {
162 double norme_normale = 0;
163 for (int iii = 0; iii < dimension; iii++)
164 norme_normale += zvf.face_normales(elem_faces(elem, j), iii) * zvf.face_normales(elem_faces(elem, j), iii);
165
166 porosite_face(elem_faces(elem, j)) = 0.;
167 for (int iii = 0; iii < dimension; iii++)
168 porosite_face(elem_faces(elem, j)) += porosites_surf[ind](iii) * std::fabs(zvf.face_normales(elem_faces(elem, j), iii))
169 * std::fabs(zvf.face_normales(elem_faces(elem, j), iii)) / norme_normale;
170 }
171 }
172 }
173 else if (porosites_volu[ind] != 1)
174 {
175 Cerr << " The volumic porosities are used to calculate the surfacic porosities " << finl;
176 for (int i = 0; i < ssz.nb_elem_tot(); i++)
177 {
178 const int elem = ssz(i);
179 porosite_elem(elem) = porosites_volu[ind];
180 }
181
182 const int nb_elem_tot = zvf.domaine().nb_elem_tot();
183 for (int i = 0; i < nb_elem_tot; i++)
184 {
185 for (int j = 0; j < nb_faces_elem; j++)
186 {
187 int face_glob = elem_faces(i, j), num_poly_vois = zvf.face_voisins(face_glob, 1), num_poly_vois1 = zvf.face_voisins(face_glob, 0);
188
189 if ((num_poly_vois != -1) && (num_poly_vois1 != -1))
190 porosite_face(face_glob) = (porosite_elem(num_poly_vois1) + porosite_elem(num_poly_vois)) / 2.;
191 else
192 porosite_face(face_glob) = porosite_elem(i);
193
194 }
195 }
196 }
197 else if (porsurfmin != 1)
198 {
199 Cerr << " The surfacic porosities are used to calculate the volumic porosities " << finl;
200 for (int i = 0; i < ssz.nb_elem_tot(); i++)
201 {
202 const int elem = ssz(i);
203 for (int j = 0; j < nb_faces_elem; j++)
204 {
205 double norme_normale = 0.;
206 for (int iii = 0; iii < dimension; iii++)
207 norme_normale += zvf.face_normales(elem_faces(elem, j), iii) * zvf.face_normales(elem_faces(elem, j), iii);
208
209 porosite_face(elem_faces(elem, j)) = 0.;
210 for (int iii = 0; iii < dimension; iii++)
211 porosite_face(elem_faces(elem, j)) += porosites_surf[ind](iii) * zvf.face_normales(elem_faces(elem, j), iii) * zvf.face_normales(elem_faces(elem, j), iii) / norme_normale;
212 }
213 }
214 }
215 }
216
217 porosites_surf.clear();
218 les_sous_domaines.clear();
219 porosites_volu.clear();
220}
int_t nb_elem_tot() const
Definition Domaine.h:132
int nb_faces_elem(int=0) const
Renvoie le nombre de face de type i des elements geometriques constituants le domaine.
Definition Domaine.h:484
class Domaine_VF
Definition Domaine_VF.h:44
virtual double face_normales(int face, int comp) const
Definition Domaine_VF.h:47
int elem_faces(int i, int j) const
renvoie le numero de le ieme face de la maille num_elem la facon dont ces faces sont numerotees est
Definition Domaine_VF.h:543
int face_voisins(int num_face, int i) const
renvoie l'element voisin de numface dans la direction i.
Definition Domaine_VF.h:418
const Domaine & domaine() const
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
Classe de base des objets "interprete".
Definition Interprete.h:38
static Objet_U & objet(const Nom &)
Voir Interprete_bloc::objet_global() BM: la classe Interprete n'est pas le meilleur endroit pour cett...
virtual int debute_par(const char *const n) const
Definition Nom.cpp:319
classe Objet_U Cette classe est la classe de base des Objets de TRUST
Definition Objet_U.h:73
friend class Entree
Definition Objet_U.h:76
static int dimension
Definition Objet_U.h:99
const Nom & que_suis_je() const
renvoie la chaine identifiant la classe.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
Definition Objet_U.cpp:293
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
Porosites_champ nom_pb champ affecte le champ champ a la porosite volumique du domaine du probleme de...
Entree & interpreter(Entree &) override
void remplir_champ(const Domaine_VF &zvf, DoubleVect &, DoubleVect &)
std::vector< DoubleVect > porosites_surf
std::vector< double > porosites_volu
std::vector< Nom > les_sous_domaines
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
Classe de base des flux de sortie.
Definition Sortie.h:52
int_t nb_elem_tot() const
virtual void ref(const TRUSTTab &)
Definition TRUSTTab.tpp:308
_SIZE_ dimension_tot(int) const override
Definition TRUSTTab.tpp:160
_SIZE_ size_totale() const
Definition TRUSTVect.tpp:61