TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Distanceparoi.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 <Distanceparoi.h>
17#include <SFichierBin.h>
18#include <Static_Int_Lists.h>
19#include <Connectivite_som_elem.h>
20#include <Faces_builder.h>
21#include <fstream>
22
23
24Implemente_instanciable(Distanceparoi,"Distance_paroi",Interprete_geometrique_base);
25// XD distance_paroi interprete distance_paroi NO_BRACE Class to generate external file Wall_length.xyz devoted for
26// XD_CONT instance, for mixing length modelling. In this file, are saved the coordinates of each element (center of
27// XD_CONT gravity) of dom domain and minimum distance between this point and boundaries (specified bords) that user
28// XD_CONT specifies in data file (typically, those associated to walls). A field Distance_paroi is available to post
29// XD_CONT process the distance to the wall.
30// XD attr dom ref_domaine dom REQ Name of domain.
31// XD attr bords listchaine bords REQ Boundaries.
32// XD attr format chaine(into=["binaire","formatte"]) format REQ Value for format may be binaire (a binary file
33// XD_CONT Wall_length.xyz is written) or formatte (moreover, a formatted file Wall_length_formatted.xyz is written).
34
35
37{
38 return Interprete::printOn(os);
39}
40
42{
43 return Interprete::readOn(is);
44}
45
47{
49 {
50 Cerr << " Distance_paroi : the calculation of the distance to the wall is made in sequential mode !! " << finl;
51 exit();
52 }
53
54 int nb_paroi;
55 Motcle format;
57 is >> nb_paroi;
58
59 Noms nom_paroi(nb_paroi);
60
61 for (int i=0; i< nb_paroi; i++) is >> nom_paroi[i];
62
63 is >> format;
64 if( (format != "binaire") && (format != "formatte"))
65 {
66 Cerr<<"Define the writing's format 'formatte' to write the file Wall_length.xyz"<<finl;
67 Cerr<<"both in binary and ascii format, otherwise specify 'binaire'"<<finl;
68 exit();
69 }
70
71
72 Domaine& dom=domaine();
73 Nom fichier = dom.le_nom();
74 fichier += "_Wall_length.xyz";
75
76 Cerr << "In Distanceparoi::interpreter : Generate faces" << finl;
77 Faces* les_faces_ptr=new(Faces);
78 Faces& les_faces= *les_faces_ptr;
79
80 //le_dom.creer_faces(les_faces);
81
82 {
83 // bloc a factoriser avec Domaine_VF.cpp :
84 Type_Face type_face = dom.type_elem()->type_face(0);
85 les_faces.typer(type_face);
86 les_faces.associer_domaine(dom);
87
88 Static_Int_Lists connectivite_som_elem;
89 const int nb_sommets_tot = dom.nb_som_tot();
90 const IntTab& elements = dom.les_elems();
91
92 construire_connectivite_som_elem(nb_sommets_tot,
93 elements,
94 connectivite_som_elem,
95 1 /* include virtual elements */);
96
97 Faces_builder faces_builder;
98 IntTab elem_faces; // Tableau dont on aura pas besoin
99 faces_builder.creer_faces_reeles(dom,
100 connectivite_som_elem,
101 les_faces,
102 elem_faces);
103 }
104 Cerr << "In Distanceparoi::interpreter : Generate faces finished" << finl;
105
106 DoubleTab xp; // centres de gravite des elements
107 DoubleTab xv; // centres de gravite des faces
108 const DoubleTab& xs=dom.coord_sommets(); // coordonnees des sommets
109
110 les_faces.calculer_centres_gravite(xv);
112
113 int nb_elem_tot = xp.dimension(0);
114 int dim = xv.dimension(1);
115
116 DoubleVect wall_length(nb_elem_tot);
117 wall_length=10e+15;
118 DoubleVect dist_min(wall_length);
119
120 ifstream fic1(fichier);
121 if (fic1)
122 {
123 Cerr << " file " << fichier << " already exits : to generate a new one, this file has to be deleted" << finl;
124 exit();
125 }
126 else
127 {
128 Cerr << " Generation of the external file named : " << fichier << finl;
129
130 for (int b=0; b<nb_paroi; b++)
131 {
132 int rang=dom.rang_frontiere(nom_paroi[b]);
133 const Frontiere& la_frontiere=dom.frontiere(rang);
134
135 // pas de methode const pour Frontiere::les_sommets_des_faces();
136 const IntTab& sommets_face = (ref_cast(Frontiere,la_frontiere)).les_sommets_des_faces();
137
138 int ndeb = la_frontiere.num_premiere_face();
139 int nb_faces = la_frontiere.nb_faces();
140 int nfin = ndeb + nb_faces;
141
142 int pourcent=0;
143
144 for (int face=ndeb; face<nfin; face++)
145 {
146
147 if((((face-ndeb)*100)/nb_faces)>pourcent)
148 {
149 pourcent=((face-ndeb)*100)/nb_faces;
150 Cerr <<"\r"<< pourcent << " % performs of " << nom_paroi[b] ;
151 }
152
153 if (dim==2)
154 {
155 double compx_0=(xv(face,0));
156 double compy_0=(xv(face,1));
157
158 int som1=sommets_face(face-ndeb,0);
159 int som2=sommets_face(face-ndeb,1);
160
161 double nx= xs(som1,1)-xs(som2,1);
162 double ny=-(xs(som1,0)-xs(som2,0));
163
164 double norme=sqrt(nx*nx+ny*ny);
165 if (norme==0)
166 {
167 Cerr << "Error in Distanceparoi::interpreter_" << finl;
168 Cerr << "Two nodes " << som1 << " and " << som2 << " seems to have same coordinates:" << finl;
169 Cerr << "xs(" << som1 << ")=" << xs(som1,0) <<" ys(" << som1 << ")= " << xs(som1,1) << finl;
170 Cerr << "xs(" << som2 << ")=" << xs(som2,0) <<" ys(" << som2 << ")= " << xs(som2,1) << finl;
171 Cerr << "Check your mesh and suppress same nodes or contact TRUST support." << finl;
172 exit();
173 }
174
175 if ( (dom.chercher_elements(compx_0+nx, compy_0+ny)) < 0 ) norme*=-1.;
176
177 nx/=norme;
178 ny/=norme;
179
180
181 for (int num_elem=0; num_elem<nb_elem_tot; num_elem++)
182 {
183 double min_loc=dist_min[num_elem];
184
185 double compx=(compx_0-xp(num_elem,0));
186 if (compx<min_loc)
187 {
188 double compy=(compy_0-xp(num_elem,1));
189 if (compy<min_loc)
190 {
191
192 double w_dist=sqrt(compx*compx+compy*compy);
193
194 if (w_dist<min_loc)
195 {
196 double compx_vect=compx*nx;
197 double compy_vect=compy*ny;
198 // double compz_vect=compz*nz;
199
200 double w_distproj=sqrt(compx_vect*compx_vect+compy_vect*compy_vect);
201 wall_length[num_elem]=w_distproj;
202 dist_min[num_elem]=w_dist;
203 }
204
205 }
206 }
207 }
208 }
209
210 else if (dim==3)
211 {
212 double compx_0=(xv(face,0));
213 double compy_0=(xv(face,1));
214 double compz_0=(xv(face,2));
215
216 int som1=sommets_face(face-ndeb,0);
217 int som2=sommets_face(face-ndeb,1);
218 int som3=sommets_face(face-ndeb,2);
219
220 double x1= xs(som2,0)-xs(som1,0);
221 double y1= xs(som2,1)-xs(som1,1);
222 double z1= xs(som2,2)-xs(som1,2);
223
224 double x2= xs(som3,0)-xs(som1,0);
225 double y2= xs(som3,1)-xs(som1,1);
226 double z2= xs(som3,2)-xs(som1,2);
227
228 double nx= y1*z2 - z1*y2 ;
229 double ny= z1*x2 - x1*z2 ;
230 double nz= x1*y2 - y1*x2 ;
231
232 double norme=sqrt(nx*nx+ny*ny+nz*nz);
233
234 if ( (dom.chercher_elements(compx_0+nx, compy_0+ny, compz_0+nz)) < 0 ) norme*=-1.;
235
236 nx/=norme;
237 ny/=norme;
238 nz/=norme;
239
240
241 for (int num_elem=0; num_elem<nb_elem_tot; num_elem++)
242 {
243 double min_loc=dist_min[num_elem];
244
245 double compx=(compx_0-xp(num_elem,0));
246 if (compx<min_loc)
247 {
248 double compy=(compy_0-xp(num_elem,1));
249 if (compy<min_loc)
250 {
251 double compz=(compz_0-xp(num_elem,2));
252 if (compz<min_loc)
253 {
254
255 double w_dist=sqrt(compx*compx+compy*compy+compz*compz);
256
257 if (w_dist<min_loc)
258 {
259 double compx_vect=compx*nx;
260 double compy_vect=compy*ny;
261 double compz_vect=compz*nz;
262
263 double w_distproj=sqrt(compx_vect*compx_vect+compy_vect*compy_vect+compz_vect*compz_vect);
264 wall_length[num_elem]=w_distproj;
265 dist_min[num_elem]=w_dist;
266 }
267 }
268 }
269 }
270 }
271 }
272 else
273 {
274 Cerr << "ERROR : Dimension 2 or 3 are required to calculate wall distance "<< finl;
275 exit();
276 }
277 }// fin face
278 Cerr<<finl;
279 }// fin nb_paroi
280 }//(!fic1)
281
282 Cerr<<" Max distance"<< local_max_vect(dist_min)<<" "<< local_max_vect(wall_length)<<finl;
283
284
285
286 SFichierBin fic_sauv(fichier);
287
288 fic_sauv<<nom_paroi<<finl;
289 int ntot=(nb_elem_tot*(1+Objet_U::dimension));
290 // entete pour pouvoir passer les blocs
291 // fic_sauv<<1 <<finl<<ntot << finl<< (int)1 <<ntot<<finl<<ntot<<finl;
292 fic_sauv << (int)1 <<ntot << (int)1 << ntot << finl << ntot << finl;
293 // fic_sauv << (int)1 << ntot << (int)1 << ntot << ntot;
294 for (int p=0; p<nb_elem_tot; p++)
295 {
296 fic_sauv<<xp(p,0)<<" "<<xp(p,1);
297 if (Objet_U::dimension==3) fic_sauv<<" "<<xp(p,2);
298 fic_sauv<<" "<<wall_length(p)<<finl;
299 }
300
301 fic_sauv << ntot << (int)0 << (int)0 << (int)0 << (int)1 << (int)0 << finl << ntot << finl << (int)1 << (int)0 << (int)0 <<finl;
302
303 if (format=="formatte")
304 {
305 fichier = dom.le_nom();
306 fichier += "_Wall_length_formatted.xyz";
307 SFichier fic_sauv_format(fichier);
308 fic_sauv_format<<nom_paroi<<finl;
309 int ntot2=(nb_elem_tot*(1+Objet_U::dimension));
310 // entete pour pouvoir passer les blocs
311 fic_sauv_format << (int)1 <<ntot2 << (int)1 << ntot2 << finl << ntot2 << finl;
312 for (int p=0; p<nb_elem_tot; p++)
313 {
314 fic_sauv_format<<xp(p,0)<<" "<<xp(p,1);
315 if (Objet_U::dimension==3) fic_sauv_format<<" "<<xp(p,2);
316 fic_sauv_format<<" "<<wall_length(p)<<finl;
317 }
318 fic_sauv_format << ntot2 << (int)0 << (int)0 << (int)0 << (int)1 << (int)0 << finl << ntot2 << finl << (int)1 << (int)0 << (int)0 <<finl;
319 }
320
321 delete les_faces_ptr;
322 return is;
323}
324
325/* lecture
326
327
328EFichier fic(nomfic);
329fic>>nom_paroi;
330DoubleTab walllength(nbelem);
331Ecriture_Lecture_Special:::lecture(zvf,fic,nbelem,wallelngth,0);
332*/
class Distanceparoi Realise une boite de recirculation (maillage hexa) extrudee d'un bord
Entree & interpreter_(Entree &) override
SmallArrOfTID_t & chercher_elements(const DoubleTab &pos, SmallArrOfTID_t &elem, int reel=0) const
Recherche des elements contenant les points dont les coordonnees sont specifiees.
Definition Domaine.cpp:405
void calculer_centres_gravite(DoubleTab_t &xp) const
Calcule les centres de gravites des elements du domaine.
Definition Domaine.h:503
int rang_frontiere(const Nom &) const
Definition Domaine.cpp:1052
const Frontiere_t & frontiere(int i) const
Definition Domaine.h:539
IntTab_t & les_elems()
Definition Domaine.h:129
const DoubleTab_t & coord_sommets() const
Definition Domaine.h:112
int_t nb_som_tot() const
Renvoie le nombre total de sommets du domaine i.e. le nombre de sommets reels et virtuels sur le proc...
Definition Domaine.h:123
const Nom & le_nom() const override
Donne le nom de l'Objet_U Methode a surcharger : renvoie "neant" dans cette implementation.
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
void typer(const Motcle &)
Type les faces.
Definition Faces.cpp:390
void associer_domaine(const Domaine_t &z)
Definition Faces.h:94
void calculer_centres_gravite(DoubleTab_t &xv) const
Calcule les centres de gravite de chaque face.
Definition Faces.cpp:776
void creer_faces_reeles(Domaine_t &domaine, const Static_Int_Lists_t &connect_som_elem, Faces_t &les_faces, IntTab_t &elem_faces)
A partir de la description des elements du domaine et des frontieres (bords, raccords,...
int_t num_premiere_face() const
Definition Frontiere.h:67
int_t nb_faces() const
Renvoie le nombre de faces de la frontiere.
Definition Frontiere.h:59
Une chaine de caractere (Nom) en majuscules.
Definition Motcle.h:26
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
Un tableau de chaine de caracteres (VECT(Nom)).
Definition Noms.h:26
friend class Entree
Definition Objet_U.h:76
static int dimension
Definition Objet_U.h:99
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 is_parallel()
Definition Process.cpp:110
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
Ecriture dans un fichier d'objets ecrits au format binaire.
Definition SFichierBin.h:26
Cette classe est a la classe C++ ofstream ce que la classe Sortie est a la classe C++ ostream Elle re...
Definition SFichier.h:27
Classe de base des flux de sortie.
Definition Sortie.h:52
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133