TrioCFD 1.9.9_beta
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 Print the field to an output stream.
33 *
34 * Prints the field size and the (constant) value on
35 * the boundary.
36 *
37 * @param (Sortie& os) an output stream
38 * @return (Sortie&) the modified output stream
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 Read the field from an input stream.
51 *
52 * Format:
53 * Champ_front_lu nb_compo vrel_1 ... [vrel_i]
54 *
55 * @param (Entree& is) an input stream
56 * @return (Entree& is) the modified input stream
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 // Reading values from file 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 (the file may contain MORE faces than the boundary, e.g. in periodic cases)
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 : to enable a "fast" search of faces
142 // we rely on mon_dom.chercher_elements(x,y,z)
143 // (method inspired by EcritureLectureSpecial::lecture_special)
144 //
145 // Restriction --> face fields only
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 // First algorithm (the fastest) searching for the element
177 // containing the face centre of gravity
178 int num_elem=domaine.chercher_elements(x,y,z);
179 if ((num_elem!=-1) && (num_elem<nb_elems))
180 {
181 // Find the face of the 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 // Second algorithm (slower) used when the point is outside the domain
200 // In that case, we scan the faces of the boundary
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 found
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 // We verify that all faces of the boundary have been assigned
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 Returns the format of the read file
252 *
253 * @param (Nom name) an input stream
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}
class Ch_front_var_stationnaire This abstract class represents a field on a boundary,
Class Champ_Inc_base.
int lire_dimension(Entree &, const Nom &)
Verification of the field dimension Returns the dimension of the field.
virtual int initialiser(double temps, const Champ_Inc_base &inco)
Initialization at the beginning of calculation.
virtual const Frontiere_dis_base & frontiere_dis() const
Returns the discretized boundary associated with the field.
virtual const Domaine_dis_base & domaine_dis() const
virtual DoubleTab & valeurs() override
Returns the array of field values.
class Champ_front_lu Derived class of Champ_front_var representing
int initialiser(double temps, const Champ_Inc_base &inco) override
Initialization at the beginning of calculation.
int is_bin(Nom name)
Returns the format of the read file.
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
Returns the index of the i-th face of element num_elem; the face numbering convention is.
Definition Domaine_VF.h:542
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)
Sets the number of components of the field.
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
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this implementation.
Definition Frontiere.h:49
int_t nb_faces() const
Returns the number of faces of the boundary.
Definition Frontiere.h:59
class Frontiere_dis_base Class representing a discretized boundary.
const Frontiere & frontiere() const
Returns the associated geometric boundary.
static Objet_U & objet(const Nom &)
See Interprete_bloc::objet_global(). BM: the Interprete class is not the best place for this.
This class implements the operators and virtual methods of the EFichier class as follows: The file to...
int ouvrir(const char *name, IOS_OPEN_MODE mode=ios::in) override
Opens the file.
void set_bin(bool bin) override
Calls get_entree_master().
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
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
static bool mp_or(bool)
Definition Process.cpp:427
static double mp_sum(double)
Computes the sum of x over all processors in the current group.
Definition Process.cpp:145
static int me()
Returns the rank of the local processor in the current communication group. See Comm_Group::rank() an...
Definition Process.cpp:122
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
Base class for output streams.
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")