TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Redresser_hexaedres_vdf.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 <Redresser_hexaedres_vdf.h>
17#include <Octree_Double.h>
18#include <Domaine.h>
19#include <Rectangle.h>
20#include <Hexaedre.h>
21#include <Quadrangle_VEF.h>
22#include <Hexaedre_VEF.h>
23
24Implemente_instanciable(Redresser_hexaedres_vdf,"Redresser_hexaedres_vdf",Interprete_geometrique_base);
25// XD redresser_hexaedres_vdf interprete redresser_hexaedres_vdf INHERITS_BRACE Keyword to convert a domain (named
26// XD_CONT domain_name) with quadrilaterals/VEF hexaedras which looks like rectangles/VDF hexaedras into a domain with
27// XD_CONT real rectangles/VDF hexaedras.
28// XD attr domain_name ref_domaine domain_name REQ Name of domain to resequence.
29
31{
32 return Interprete::printOn(os);
33}
34
36{
37 return Interprete::readOn(is);
38}
39
41{
43 {
44 Cerr << "Redresser_hexaedres_vdf can't be used during a parallel calculation." << finl;
45 exit();
46 }
48 DoubleTab& les_sommets = domaine().les_sommets();
49 int nb_sommets = les_sommets.dimension(0);
50 double epsilon = Objet_U::precision_geom;
51 int ok=0;
52 // On type en rectangle ou hexaedre
53 const Elem_geom_base& elem=domaine().type_elem().valeur();
54 Cerr << "Attempt on the mesh ";
55 if (sub_type(Rectangle,elem)) Cerr << "to correct rectangles..." << finl;
56 else if (sub_type(Quadrangle_VEF,elem)) Cerr << "to correct VEF quadrangles into rectangles..." << finl;
57 else if (sub_type(Hexaedre,elem)) Cerr << "to correct hexahedra..." << finl;
58 else if (sub_type(Hexaedre_VEF,elem)) Cerr << "to correct VEF hexahedra into regular hexahedra..." << finl;
59 else
60 {
61 Cerr << "This type of element ("<<elem.que_suis_je()<<") is not supported by Redresser_hexaedres_vdf" << finl;
62 exit();
63 }
64 if (dimension==2) domaine().typer("Rectangle");
65 if (dimension==3) domaine().typer("Hexaedre");
66 Elem_geom_base& new_elem=domaine().type_elem().valeur();
67 do
68 {
69 double correction_max = 0;
70 Octree_Double octree;
71 octree.build_nodes(les_sommets, 0 /* do not include virtual nodes */);
72 // direction indique la coordonnee qu'on va corriger
73 for (int direction = 0; direction < dimension; direction++)
74 {
75 ArrOfInt marqueurs(nb_sommets); // initialise a zero
76 ArrOfInt liste_sommets;
77
78 int prochain_sommet = 0;
79 while (prochain_sommet < nb_sommets)
80 {
81 // Cherche le prochain sommet non marque:
82 for (; prochain_sommet < nb_sommets; prochain_sommet++)
83 if (! marqueurs[prochain_sommet])
84 break;
85 if (prochain_sommet == nb_sommets)
86 break;
87 // Trouver tous les sommets qui sont dans une boite tres grande
88 // en dehors de la direction dir:
89 double x = les_sommets(prochain_sommet, 0);
90 double y = les_sommets(prochain_sommet, 1);
91 double z = (dimension == 3) ? les_sommets(prochain_sommet, 2) : 0.;
92 double xmin = (direction==0) ? (x-epsilon) : (-DMAXFLOAT);
93 double xmax = (direction==0) ? (x+epsilon) : (+DMAXFLOAT);
94 double ymin = (direction==1) ? (y-epsilon) : (-DMAXFLOAT);
95 double ymax = (direction==1) ? (y+epsilon) : (+DMAXFLOAT);
96 double zmin = (direction==2) ? (z-epsilon) : (-DMAXFLOAT);
97 double zmax = (direction==2) ? (z+epsilon) : (+DMAXFLOAT);
98 octree.search_elements_box(xmin, ymin, zmin, xmax, ymax, zmax, liste_sommets);
99 // Pour chaque sommet, corriger deux des coordonnees
100 // (on met les coordonnees du point trouve)
101 const int n = liste_sommets.size_array();
102 for (int i = 0; i < n; i++)
103 {
104 const int j = liste_sommets[i];
105 // le premier sommet sert de reference, ne pas le corriger:
106 if (j == prochain_sommet)
107 continue;
108 // coordonnee de reference (on aligne tous les autres points du
109 // plan de maillage sur celui-la:
110 const double coord_ref = les_sommets(prochain_sommet, direction);
111
112 // verifier que le sommet est bien dans la boite (l'octree
113 // renvoie les sommets "potentiellement" a l'interieur
114 const double coord = les_sommets(j, direction);
115 if (std::fabs(coord-coord_ref) > epsilon)
116 continue;
117
118 correction_max=std::max(correction_max,std::fabs(coord_ref-les_sommets(j, direction)));
119 // Corriger:
120 les_sommets(j, direction) = coord_ref;
121 marqueurs[j] = 1; // sommet traite !
122 }
123 marqueurs[prochain_sommet] = 1;
124 }
125 }
126 epsilon*=10;
127 Cerr << "Redresser_hexaedres_vdf, epsilon=" << epsilon << " maximum_correction=" << correction_max << finl;
128 if (epsilon>1)
129 {
130 Cerr << "Redresser_hexaedres_vdf failed" << finl;
131 Cerr << "it has failed to make regular hexahedra on the mesh." << finl;
132 exit();
133 }
134 if (dimension==2)
135 ok=ref_cast(Rectangle,new_elem).reordonner_elem();
136 else if (dimension==3)
137 ok=ref_cast(Hexaedre,new_elem).reordonner_elem();
138 }
139 while (ok==-1);
140 Cerr << "End and success of Redresser_hexaedres_vdf" << finl;
141 return is;
142}
DoubleTab_t & les_sommets()
Definition Domaine.h:113
void typer(const Nom &)
Type les elements du domaine avec le nom passe en parametre.
Definition Domaine.h:457
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
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
static double precision_geom
Definition Objet_U.h:86
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
void build_nodes(const DoubleTab_t &coords, const bool include_virtual, const double epsilon=0.)
construit un octree contenant les points de coordonnees coords.
int_t search_elements_box(double xmin, double ymin, double zmin, double xmax, double ymax, double zmax, ArrOfInt_t &elements) const
cherche tous les elements ou points ayant potentiellement une intersection non vide avec la boite don...
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
class Redresser_hexaedres_vdf Realise un maillage en decoupant chaque tetraedre en 4 nouveaux tetraed...
Entree & interpreter_(Entree &) override
Classe de base des flux de sortie.
Definition Sortie.h:52
_SIZE_ size_array() const
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133