16#include <NettoieNoeuds.h>
17#include <Lire_Tgrid.h>
28inline void decompression(
Nom& nom_fichier)
31 if (tmp.prefix(
".gz")!=nom_fichier)
33 Cerr <<
"Unzipping file " << nom_fichier <<
" ..." << finl;
35 cmd+=nom_fichier+
" > "+tmp;
36 Cerr << (int)system(cmd) << finl;
40Implemente_instanciable(
Lire_Tgrid,
"Lire_Tgrid",Interprete_geometrique_base);
52 if( (0>(c-
'0')) || ((c-
'0')>9) )
59int htoi(
const char * szChaine)
64 if (szChaine ==
nullptr)
67 iLength = (int)strlen(szChaine);
70 char * szHexaString = strdup(szChaine);
72 for (
int i = iLength - 1; i >= 0; i--)
74 char cCharacter = szHexaString[i];
77 if (isdigit(cCharacter))
82 iValue = chartoint(cCharacter);
85 Cerr <<
"iValue is worth " << iValue <<
" ! " << finl;
90 else if (isalpha(cCharacter))
126 for (
int puissance=0; puissance<iLength - i - 1; puissance++)
136inline void va_a_la_parenthese_fermante(
EFichier& fic)
138 int parenthese_ouverte=1;
140 while ((parenthese_ouverte!=0)&&(fic.
good()))
143 const char* chaine = lu.
getChar();
145 size_t iLength = strlen(chaine);
146 for (
size_t i=0; i<iLength; i++)
152 parenthese_ouverte++;
155 parenthese_ouverte--;
161 if (parenthese_ouverte!=0)
163 Cerr<<
"Error in file"<<finl;
168inline void va_a_la_parenthese_ouvrante(
EFichier& fic)
175 const char* chaine = lu.
getChar();
176 size_t iLength = strlen(chaine);
177 for (
size_t i=0; i<iLength; i++)
199 Cerr <<
"Reading a mesh which comes from Tgrid" << finl;
209 int type_elements = 0;
212 ArrOfInt nb_som_lu_elem;
217 decompression(nom_fichier);
218 Cerr <<
"Reading of the file " << nom_fichier <<
" ..." << finl;
224 Cerr <<
"Problem to open the file " << nom_fichier << finl;
225 Cerr <<
"There is maybe an error in the filename." << finl;
232 while (!lecture.
eof())
243 Cerr <<
"The total number of elements to read is " << nb_elem << finl;
245 if (motlu!=
"0))") lecture >> motlu;
247 else if (motlu==
"(id") lecture >> motlu;
258 Cerr <<
"2D elements of type Triangle" << finl;
260 else if (motlu==
"3))")
264 Cerr <<
"2D elements of type Quadrangle" << finl;
266 else if (motlu==
"2))")
270 Cerr <<
"3D elements of type Tetrahedron" << finl;
272 else if (motlu==
"4))")
276 Cerr <<
"3D elements of type Hexahedron" << finl;
281 Cerr <<
"Elements unknown !" << finl;
282 Cerr <<
"It should probably crashed !!!!!" << finl;
295 Cerr <<
"Reading a comment:" << finl;
297 va_a_la_parenthese_fermante(fic);
298 Cerr << finl << finl;
300 else if (motlu==
"(1")
302 Cerr <<
"Reading a header:" << finl;
304 va_a_la_parenthese_fermante(fic);
305 Cerr << finl << finl;
307 else if (motlu==
"(2")
309 Cerr <<
"Reading of the dimension of the case:" << finl;
311 dim=atoi(motlu.prefix(
")"));
312 if (dim==3) Cerr <<
"Dimension 3." << finl;
313 else if (dim==2) Cerr <<
"Dimension 2." << finl;
316 Cerr <<
"Dimension " << dim <<
" of the mesh not provided." << finl;
321 else if (motlu==
"(10")
329 Cerr <<
"The total number of nodes to read is " << nb_som << finl;
331 coord_sommets.
resize(nb_som,dim);
335 if (tmp==motlu.
prefix(
"))"))
340 int idomaine=htoi(motlu.suffix(
"("));
342 int ideb=htoi(motlu);
344 int ifin=htoi(motlu);
345 Cerr << ifin-ideb+1 <<
" nodes are read in the area " << idomaine << finl;
347 va_a_la_parenthese_ouvrante(fic);
355 for (
int i=ideb-1; i<ifin; i++)
356 for (
int j=0; j<dim; j++)
357 fic >> coord_sommets(i,j);
362 else if (motlu==
"(12")
371 if (motlu!=
"0))") fic >> motlu;
375 int idomaine=htoi(motlu.suffix(
"("));
381 int type=htoi(motlu);
382 Cerr <<
"The type of area " << idomaine <<
" is " << type <<
" (1:fluid, 17:solid)" << finl;
387 dom.type_elem().
typer(
"Tetraedre");
389 else if (motlu==
"4))")
392 dom.type_elem().
typer(
"Hexaedre_VEF");
394 else if (motlu==
"1))")
397 dom.type_elem().
typer(
"Triangle");
399 else if (motlu==
"3))")
402 dom.type_elem().
typer(
"Quadrangle");
406 Cerr <<
"Reading the elements is not provided in this interpreter." << finl;
407 Cerr <<
"Indeed, we read faces to reconstruct the elements." << finl;
408 Cerr <<
"Contact TRUST support." << finl;
411 dom.type_elem()->associer_domaine(dom);
415 else if (motlu.debute_par(
"(13"))
425 Cerr <<
"The total number of faces to read is " << nb_face << finl;
427 if (motlu !=
"0))") fic >> motlu;
431 int idomaine=htoi(motlu.suffix(
"("));
433 int ideb=htoi(motlu);
435 int ifin=htoi(motlu);
437 int type=htoi(motlu);
441 int nb_som_face,mixte=0;
442 if (tmp!=motlu.
prefix(
")"))
446 nb_som_face=htoi(motlu);
451 nb_som_face=htoi(motlu);
455 else if (nb_som_face==4)
457 else if (nb_som_face==2 && type_elements==1)
459 else if (nb_som_face==2 && type_elements==3)
464 Cerr <<
"It seems that we try to read faces with different types..." << finl;
467 Cerr <<
"The case of faces that are not triangles or quadrangles" << finl;
468 Cerr <<
"or a mixture of several types of faces" << finl;
469 Cerr <<
"is not yet provided. Your mesh is not only composed" << finl;
470 Cerr <<
"of tetrahedra, hexahedra, triangles or quadrangles." << finl;
475 if (les_elems.
size()==0)
478 les_elems.
resize(nb_elem,nb_som_elem);
484 ArrOfInt elem(2),som(nb_som_face);
485 int nb_face_lu=ifin-ideb+1;
486 OBS_PTR(Frontiere) nouveau_bord;
488 for (
int i=0; i<nb_face_lu; i++)
493 if (htoi(motlu)!=nb_som_face)
495 Cerr <<
"We read an element to " << htoi(motlu) <<
" faces." << finl;
496 Cerr <<
"So it was planned to read elements to " << nb_som_face <<
" faces."<< finl;
500 for (
int j=0; j<nb_som_face; j++)
503 som[j]=htoi(motlu)-1;
513 elem[0]=htoi(motlu)-1;
517 if (tmp2!=motlu.
prefix(
"))"))
520 elem[1]=htoi(tmp2)-1;
525 if (tmp2!=motlu.
prefix(
")"))
528 elem[1]=htoi(motlu)-1;
533 elem[1]=htoi(motlu)-1;
543 if (elem[0]<0 || elem[1]<0)
547 Cerr << nb_face_lu <<
" faces are read from the boundary number " << idomaine << finl;
549 nouveau_bord->nommer((
Nom)idomaine);
551 nouveau_bord->faces().typer(Type_Face::triangle_3D);
552 else if (nb_som_face==4)
553 nouveau_bord->faces().typer(Type_Face::quadrangle_3D);
554 else if (nb_som_face==2)
555 nouveau_bord->faces().typer(Type_Face::segment_2D);
558 Cerr <<
"Type of boundary face not provided for nb_som_face=" << nb_som_face << finl;
561 nouveau_bord->faces().dimensionner(nb_face_lu);
566 Cerr << nb_face_lu <<
" internal faces are read in the area " << idomaine << finl;
571 for (
int j=0; j<nb_som_face; j++)
572 nouveau_bord->faces().sommet(i,j)=som[j];
575 for (
int i2=0; i2<2; i2++)
580 if (nb_som_lu_elem[elem[i2]]==0)
582 for (
int j=0; j<nb_som_face; j++)
583 les_elems(elem[i2],nb_som_lu_elem[elem[i2]]++)=som[j];
588 for (
int j=0; j<nb_som_face; j++)
592 while (k<nb_som_lu_elem[elem[i2]] && trouve==0)
594 if (les_elems(elem[i2],k)==som[j])
603 if ((trouve==0 && nb_som_face==3) || (trouve==0 && nb_som_face==2 && type_elements==1))
604 les_elems(elem[i2],nb_som_lu_elem[elem[i2]]++)=som[j];
606 assert(elem[i2]<nb_elem);
607 if (nb_som_lu_elem[elem[i2]]>nb_som_elem)
609 Cerr <<
"Problem on reading the element " << elem[i2] << finl;
610 Cerr <<
"There is more than " << nb_som_elem <<
" nodes !" << finl;
611 Cerr <<
"Check that the read file contains only tetrahedra or triangles" << finl;
612 Cerr <<
"or contact TRUST support." << finl;
617 if ((nb_som_face==4 && face_opposee==1) || (nb_som_face==2 && face_opposee==1 && type_elements==3))
619 for (
int j=0; j<nb_som_face; j++)
620 les_elems(elem[i2],nb_som_lu_elem[elem[i2]]++)=som[j];
626 if (compteur==0 || compteur==-1)
629 if (motlu==
")" && compteur==0)
635 else if ((motlu==
"(45") || (motlu==
"(39"))
637 Cerr <<
"Reading of a name:" << finl;
641 int idomaine=atoi(motlu.suffix(
"("));
645 Nom nom_domaine=Nomdomaine;
646 nom_domaine.
prefix(
")())");
647 if (nom_domaine==Nomdomaine)
654 nom_domaine=Nomdomaine;
655 nom_domaine.
prefix(
")())");
658 Cerr <<
"The area " << idomaine <<
" is called " << nom_domaine << finl;
662 if (les_bords.est_vide())
664 Cerr <<
"Reading a name before reading the boundaries..." << finl;
665 Cerr <<
"Case not provided, contact TRUST support." << finl;
669 for (
auto& itr : les_bords)
670 if (itr.le_nom()==(
Nom)idomaine) itr.nommer(nom_domaine);
676 if (motlu.debute_par(
"("))
678 Cerr <<
"Reading a tag:" << finl;
680 va_a_la_parenthese_fermante(fic);
681 Cerr << finl << finl;
683 else if ( (motlu==
" ") || (motlu==
"") )
685 Cerr <<
"End of file ?" << finl;
687 else if (motlu!=
"??")
689 Cerr <<
"Tag " << motlu <<
" unrecognized." << finl;
696 for (
int i=0; i<nb_elem; i++)
697 for (
int j=0; j<nb_som_elem; j++)
698 if (les_elems(i,j)==-1)
700 Cerr <<
"The array of connectivity elements-nodes is wrong filled in Lire_Tgrid::interpreter." << finl;
701 Cerr <<
"Contact TRUST support." << finl;
void associer_domaine(const Domaine_t &)
Associe un domaine a tous les bords de la liste.
DoubleTab_t & les_sommets()
void typer(const Nom &)
Type les elements du domaine avec le nom passe en parametre.
Fichier en lecture Cette classe est a la classe C++ ifstream ce que la classe Entree est a la.
Class defining operators and methods for all reading operation in an input flow (file,...
void associer_domaine(Nom &nom_dom)
Domaine_t & domaine(int i=0)
class Lire_Fichier Lecture d'un fichier
Entree & interpreter_(Entree &) override
Lecture d'un fichier Avec 2 arguments nom1 et nom2 , lit l'objet du fichier nom2 dans l'objet nom1.
Une chaine de caractere (Nom) en majuscules.
static void nettoie(Domaine_t &)
static int NettoiePasNoeuds
class Nom Une chaine de caractere pour nommer les objets de TRUST
const char * getChar() const
Nom & prefix(const char *const)
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
static Sortie & Journal(int message_level=0)
Renvoie un objet statique de type Sortie qui sert de journal d'evenements.
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
static bool is_sequential()
Classe de base des flux de sortie.
void resize_array(_SIZE_ new_size, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)