TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Champ_front_lu.cpp
1/****************************************************************************
2* Copyright (c) 2024, 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 <Champ_front_lu.h>
17#include <Domaine.h>
18#include <LecFicDiffuse.h>
19#include <Interprete.h>
20#include <Domaine_VF.h>
21
22Implemente_instanciable(Champ_front_lu,"Champ_front_lu",Ch_front_var_stationnaire);
23// XD champ_front_lu front_field_base champ_front_lu NO_BRACE boundary field which is given from data issued from a read
24// XD_CONT file. The format of this file has to be the same that the one generated by Ecrire_fichier_xyz_valeur NL2
25// XD_CONT Example for K and epsilon quantities to be defined for inlet condition in a boundary named \'entree\':
26// XD_CONT NL2entree frontiere_ouverte_K_Eps_impose Champ_Front_lu dom 2pb_K_EPS_PERIO_1006.306198.dat
27// XD attr domaine ref_domaine domain REQ Name of domain
28// XD attr dim entier dim REQ number of components
29// XD attr file chaine file REQ path for the read file
30
31
32/*! @brief Imprime le champ sur flot de sortie.
33 *
34 * Imprime la taille du champ et la valeur (constante) sur
35 * la frontiere.
36 *
37 * @param (Sortie& os) un flot de sortie
38 * @return (Sortie&) le flot de sortie modifie
39 */
41{
42 const DoubleTab& tab=valeurs();
43 os << tab.size() << " ";
44 for(int i=0; i<tab.size(); i++)
45 os << tab(0,i);
46 return os;
47}
48
49
50/*! @brief Lit le champ a partir d'un flot d'entree.
51 *
52 * Format:
53 * Champ_front_lu nb_compo vrel_1 ... [vrel_i]
54 *
55 * @param (Entree& is) un flot d'entree
56 * @return (Entree& is) le flot d'entree modifie
57 */
59{
60 int dim;
61 //Motcle motlu;
62 Nom nom;
63 is >> nom;
64
65 mon_domaine = ref_cast(Domaine, Interprete::objet(nom));
66
67
68
70 fixer_nb_comp(dim);
71 is >> nom_fic;
72 // Lecture des valeurs dans le fichier fic
73 return is;
74}
75
76void erreur_chfront(const Nom& nom_fic, const int dim, const Nom& nom_domaine)
77{
78 Cerr << "****************************************************************************************************************" << finl;
79 Cerr << "Error! It seems that several faces into the file " << nom_fic << " does not match any faces of the current mesh." << finl;
80 Cerr << finl;
81 Cerr << "First, check that the file " << nom_fic << " can be used to define a boundary field on the specified boundary of the current mesh." << finl;
82 Cerr << "Second, try to switch to a different algorithm in your data file (find the nearest geometric face of the mesh for each face defined in the " << nom_fic << " file):" << finl;
83 Cerr << "Replace:" <<finl;
84 Cerr << "Champ_front_lu " << nom_domaine << " " << dim << " " << nom_fic << finl;
85 Nom un((Nom)dim),zero((Nom)dim);
86 for (int i=0; i<dim; i++)
87 {
88 un+=" 1";
89 zero+=" 0";
90 }
91 Cerr << "By:"<<finl;
92 Nom chaine="moyenne_imposee connexion_approchee fichier";
93 Cerr << "Champ_front_recyclage { pb_champ_evaluateur problem_name field_name "<<dim<<finl;
94 Cerr << " "<<chaine<<" "<<nom_fic<<finl;
95 Cerr << " ampli_moyenne_imposee "<<un<<finl;
96 Cerr << " ampli_moyenne_recyclee "<<zero<<finl;
97 Cerr << " ampli_fluctuation "<<zero<<" }" <<finl;
99}
100
101int Champ_front_lu::initialiser(double temps, const Champ_Inc_base& inco)
102{
103
105 return 0;
106
107 int dim=nb_comp();
108 Domaine& domaine=mon_domaine.valeur();
109 const Frontiere_dis_base& fr_dis=frontiere_dis();
110 const Frontiere& frontiere=fr_dis.frontiere();
111 const int nb_faces=frontiere.nb_faces();
112 const int ndeb=frontiere.num_premiere_face();
113 DoubleTab& les_val=valeurs();
114
115 LecFicDiffuse fic;
116 int bin=is_bin(nom_fic);
117 fic.set_bin(bin);
118 fic.ouvrir(nom_fic);
119 Nom format;
120 if (bin)
121 fic >> format;
122 else
123 format="ascii";
124
125 Cerr << "Reading of the " << format << " file : " << nom_fic << finl;
126
127 DoubleVect point(dimension);
128 DoubleVect val_lu(dim);
129 int nb_val_lues;
130 fic >> nb_val_lues;
131
132 // Verification (il se peut que le fichier contienne PLUS de faces que la frontiere, exemple en periodique)
133 trustIdType nb_faces_tot = mp_sum(nb_faces);
134 if ((trustIdType)nb_val_lues<nb_faces_tot)
135 {
136 Cerr << "This file contains " << nb_val_lues << " faces which is not enough compare to" << finl;
137 Cerr << "the faces number (" << nb_faces_tot << ") of the boundary " << frontiere.le_nom() << finl;
138 exit();
139 }
140
141 // PQ 20/06/06 : pour permettre une recherche "rapide" des faces
142 // on s'appuie sur mon_dom.chercher_elements(x,y,z)
143 // (methode inspiree de EcritureLectureSpecial::lecture_special)
144 //
145 // Restriction --> champs aux faces
146
147 int nb_elems = domaine.nb_elem();
148 int nbfacelem=domaine.nb_faces_elem();
149 const Domaine_VF& zvf = ref_cast(Domaine_VF, domaine_dis());
150 const IntTab& elem_faces=zvf.elem_faces();
151 const DoubleTab& xv=zvf.xv();
152 IntTab compteur(nb_faces);
153 compteur=0;
154
155 int k;
156 double x,y,z=0;
157 int pourcent=0,tmp;
158
159 for (int p=0; p<nb_val_lues; p++)
160 {
161 tmp=(p*10)/nb_val_lues;
162 if (tmp>pourcent)
163 {
164 pourcent=tmp;
165 Cerr<<"\rProcess "<<Process::me()<<" has read "<<pourcent*10<<"% of values"<<flush;
166 }
167 for (k=0; k<dimension; k++)
168 fic >> point[k];
169 for (k=0; k<dim; k++)
170 fic >>val_lu[k];
171
172 x=point[0];
173 y=point[1];
174 if (Objet_U::dimension==3) z=point[2];
175 int Case=-1;
176 // Premier algorithme (le plus rapide) cherchant l'element
177 // contenant le centre de gravite de la face
178 int num_elem=domaine.chercher_elements(x,y,z);
179 if ((num_elem!=-1) && (num_elem<nb_elems))
180 {
181 // On cherche la face de l'element
182 for (int fac=0; fac<nbfacelem; fac++)
183 {
184 int face=elem_faces(num_elem,fac);
185 int ok=1;
186 for (int dir=0; dir<dimension; dir++)
187 {
188 ok=ok&&(est_egal(point[dir],xv(face,dir)));
189 }
190 if (ok)
191 {
192 Case=face;
193 break;
194 }
195 }
196 }
197 else
198 {
199 // Deuxieme algorithme (plus lent) utilise dans le cas ou le point se trouve a l'exterieur du domaine
200 // Dans ce cas la, on parcours les faces de la frontiere
201 for (int face=0; face<nb_faces; face++)
202 if (compteur[face] == 0)
203 {
204 int ok=1;
205 for (int dir=0; dir<dimension; dir++)
206 ok=ok&&(est_egal(point[dir],xv(ndeb+face,dir)));
207 if (ok)
208 {
209 Case=ndeb+face;
210 break;
211 }
212 }
213 }
214 // Face trouvee
215 if (Case!=-1)
216 {
217 int face_loc=Case-ndeb;
218 if ((face_loc<0) || (face_loc>=nb_faces))
219 {
220 Cerr << " The face " << ndeb << " found doesn't belong to the boundary sought " << finl;
221 exit();
222 }
223 compteur[face_loc] += 1;
224 for (k=0; k<dim; k++)
225 les_val(face_loc,k) = val_lu[k];
226 }
227 }
228 Cerr<<"\rProcess "<<Process::me()<<" has read 100% of values"<<finl;
229
230 // On verifie que toutes les faces de la frontiere ont ete affectees
231 bool err=false;
232 for (int face=0; face<nb_faces; face++)
233 if (compteur[face] != 1)
234 {
235 Cerr.precision(12);
236 if (compteur[face] == 0)
237 Cerr << "No value found for the face " << face << "/" << nb_faces-1 << " of the boundary " << frontiere.le_nom() << " on the processor " << Process::me() << ".";
238 else
239 Cerr << "Several values found for the face " << face << "/" << nb_faces-1 << " of the boundary " << frontiere.le_nom() << " on the processor " << Process::me() << ".";
240 Cerr << " Coordinates: " << xv(ndeb+face,0) << " " << xv(ndeb+face,1);
241 if (dimension==3) Cerr << " " << xv(ndeb+face,2);
242 Cerr << finl;
243 err=true;
244 }
245 if (Process::mp_or(err))
246 erreur_chfront(nom_fic, dim, mon_domaine->le_nom());
247 les_val.echange_espace_virtuel();
248 return 1;
249}
250
251/*! @brief Renvoie le format du fichier lu
252 *
253 * @param (Nom name) un flot d'entree
254 * @return (int)
255 */
257{
258 LecFicDiffuse fichier(name);
259 Nom format;
260 fichier >> format;
261
262#ifdef INT_is_64_
263 // In case of INT_64, first Nom can be INT64 ...
264 if(format=="INT64")
265 format="binary";
266#endif
267
268 if(format=="binary")
269 return 1;
270 else
271 return 0;
272}
classe Ch_front_var_stationnaire Cette classe abstraite represente un champ sur une frontiere,
Classe Champ_Inc_base.
int lire_dimension(Entree &, const Nom &)
Verification de la dimension du champ Renvoie la dimension du champ.
virtual int initialiser(double temps, const Champ_Inc_base &inco)
Initialisation en debut de calcul.
virtual const Frontiere_dis_base & frontiere_dis() const
Renvoie la frontiere discretisee associee au champ.
virtual const Domaine_dis_base & domaine_dis() const
virtual DoubleTab & valeurs() override
Renvoie le tableau des valeurs du champ.
classe Champ_front_lu Classe derivee de Champ_front_var qui represente les
int initialiser(double temps, const Champ_Inc_base &inco) override
Initialisation en debut de calcul.
int is_bin(Nom name)
Renvoie le format du fichier lu.
class Domaine_VF
Definition Domaine_VF.h:44
double xv(int num_face, int k) const
Definition Domaine_VF.h:76
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
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
virtual void fixer_nb_comp(int i)
Fixe le nombre de composantes du champ.
virtual int nb_comp() const
Definition Field_base.h:56
int_t num_premiere_face() const
Definition Frontiere.h:67
const Nom & le_nom() const override
Donne le nom de l'Objet_U Methode a surcharger : renvoie "neant" dans cette implementation.
Definition Frontiere.h:49
int_t nb_faces() const
Renvoie le nombre de faces de la frontiere.
Definition Frontiere.h:59
classe Frontiere_dis_base Classe representant une frontiere discretisee.
const Frontiere & frontiere() const
Renvoie la frontiere geometrique associee.
static Objet_U & objet(const Nom &)
Voir Interprete_bloc::objet_global() BM: la classe Interprete n'est pas le meilleur endroit pour cett...
Cette classe implemente les operateurs et les methodes virtuelles de la classe EFichier de la facon s...
int ouvrir(const char *name, IOS_OPEN_MODE mode=ios::in) override
Ouverture du fichier.
void set_bin(bool bin) override
appelle get_entree_master().
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
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
static bool mp_or(bool)
Definition Process.cpp:418
static double mp_sum(double)
Calcule la somme de x sur tous les processeurs du groupe courant.
Definition Process.cpp:146
static int me()
renvoie mon rang dans le groupe de communication courant.
Definition Process.cpp:125
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
_SIZE_ size() const
Definition TRUSTVect.tpp:45
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")