TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Rectify_Mesh.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 <Rectify_Mesh.h>
17#include <Domaine.h>
18#include <Scatter.h>
19#include <Synonyme_info.h>
20
21
22Implemente_instanciable(Rectify_Mesh,"Rectify_Mesh",Interprete_geometrique_base) ;
23Add_synonym(Rectify_Mesh,"Orienter_Simplexes");
24// XD rectify_mesh interprete rectify_mesh INHERITS_BRACE Keyword to raffine a mesh
25// XD attr domain_name ref_domaine domain_name REQ Name of domain.
26
28{
30 return os;
31}
32
34{
36 return is;
37}
38
40{
42 apply();
43 return is;
44}
45
47{
48 Cerr << "Rectifying domain " << domaine().le_nom() << finl;
49
52
53 if ( Objet_U::dimension == 2 )
54 {
55 apply_2D();
56 }
57 else
58 {
59 apply_3D();
60 }
61
62 Cerr << "Rectification... OK" << finl;
63}
64
66{
67 if ( ! ( (Objet_U::dimension == 2) || (Objet_U::dimension == 3) ) )
68 {
69 Cerr << "Error in 'Rectify_Mesh::check_dimension()':" << finl;
70 Cerr << " Invalid dimension: " << Objet_U::dimension << finl;
71 Cerr << " Rectify_Mesh can only deal 2D or 3D domains" << finl;
73 }
74}
75
77{
78 const Nom& cell_type = domaine().type_elem()->que_suis_je();
79
80 if ( ! ( (cell_type == Motcle("Triangle")) || (cell_type == Motcle("Tetraedre")) ) )
81 {
82 Cerr << "Error in 'Rectify_Mesh::check_cell_type()':" << finl;
83 Cerr << " Invalid cell type: " << cell_type << finl;
84 Cerr << " Rectify_Mesh can only deal with triangles and tetrahedrons" << finl;
86 }
87}
88
90{
91 Domaine& domain = domaine();
93
94 assert( domain.type_elem()->que_suis_je() == Motcle("Triangle") );
95
97
99}
100
101
103{
104 Domaine& domain = domaine();
106
107 assert( domain.type_elem()->que_suis_je() == Motcle("Tetraedre") );
108
111
113}
114
116{
117 const DoubleTab& nodes = domaine().les_sommets();
118 IntTab& cells = domaine().les_elems();
119
120 const int nb_cells = cells.dimension(0);
121
122 int nb_swaps = 0;
123
124 for (int c=0; c<nb_cells; ++c)
125 {
126 const int n0 = cells(c,0);
127 const int n1 = cells(c,1);
128 const int n2 = cells(c,2);
129
130 const double x0 = nodes(n0,0);
131 const double x1 = nodes(n1,0);
132 const double x2 = nodes(n2,0);
133
134 const double y0 = nodes(n0,1);
135 const double y1 = nodes(n1,1);
136 const double y2 = nodes(n2,1);
137
138 const double area = (x1-x0)*(y2-y0) - (x2-x0)*(y1-y0);
139 if ( area < 0.)
140 {
141 swap_nodes(cells,c,1,2);
142 ++nb_swaps;
143 }
144 }
145
146 Cerr << "************************************************" << finl;
147 Cerr << "Rectify_Mesh::check_cell_orientation_2D report :" << finl;
148 Cerr << " " << nb_swaps << " swap" << ((nb_swaps ==1) ? "" : "s") << " were performed" << finl;
149 Cerr << "************************************************" << finl;
150}
151
153{
154 const DoubleTab& nodes = domaine().les_sommets();
155 IntTab& cells = domaine().les_elems();
156
157 const int nb_cells = cells.dimension(0);
158
159 int nb_swaps = 0;
160
161 for (int c=0; c<nb_cells; ++c)
162 {
163 const int n0 = cells(c,0);
164 const int n1 = cells(c,1);
165 const int n2 = cells(c,2);
166 const int n3 = cells(c,3);
167
168 const double x0 = nodes(n0,0);
169 const double x1 = nodes(n1,0);
170 const double x2 = nodes(n2,0);
171 const double x3 = nodes(n3,0);
172
173 const double y0 = nodes(n0,1);
174 const double y1 = nodes(n1,1);
175 const double y2 = nodes(n2,1);
176 const double y3 = nodes(n3,1);
177
178 const double z0 = nodes(n0,2);
179 const double z1 = nodes(n1,2);
180 const double z2 = nodes(n2,2);
181 const double z3 = nodes(n3,2);
182
183 const double volume = (x1-x0) * (y2-y0) * (z3-z0)
184 + (x2-x0) * (y3-y0) * (z1-z0)
185 + (x3-x0) * (y1-y0) * (z2-z0)
186 - (z1-z0) * (y2-y0) * (x3-x0)
187 - (x2-x0) * (z3-z0) * (y1-y0)
188 - (y3-y0) * (x1-x0) * (z2-z0);
189 if (volume < 0.)
190 {
191 swap_nodes(cells,c,2,3);
192 ++nb_swaps;
193 }
194 }
195
196 Cerr << "************************************************" << finl;
197 Cerr << "Rectify_Mesh::check_cell_orientation_3D report :" << finl;
198 Cerr << " " << nb_swaps << " swap" << ((nb_swaps ==1) ? "" : "s") << " were performed" << finl;
199 Cerr << "************************************************" << finl;
200
201}
202
204{
205 const DoubleTab& nodes = domaine().les_sommets();
206 IntTab& cells = domaine().les_elems();
207
208 const int nb_cells = cells.dimension(0);
209
210 ArrOfDouble lengths(3);
211
212 int nb_swaps = 0;
213
214 for (int c=0; c<nb_cells; ++c)
215 {
216 const int n0 = cells(c,0);
217 const int n1 = cells(c,1);
218 const int n2 = cells(c,2);
219 const int n3 = cells(c,3);
220
221 const double x0 = nodes(n0,0);
222 const double x1 = nodes(n1,0);
223 const double x2 = nodes(n2,0);
224 const double x3 = nodes(n3,0);
225
226 const double y0 = nodes(n0,1);
227 const double y1 = nodes(n1,1);
228 const double y2 = nodes(n2,1);
229 const double y3 = nodes(n3,1);
230
231 const double z0 = nodes(n0,2);
232 const double z1 = nodes(n1,2);
233 const double z2 = nodes(n2,2);
234 const double z3 = nodes(n3,2);
235
236 lengths[0] = ((x0+x1)-(x2+x3))*((x0+x1)-(x2+x3))
237 + ((y0+y1)-(y2+y3))*((y0+y1)-(y2+y3))
238 + ((z0+z1)-(z2+z3))*((z0+z1)-(z2+z3));
239
240 lengths[1] = ((x0+x2)-(x1+x3))*((x0+x2)-(x1+x3))
241 + ((y0+y2)-(y1+y3))*((y0+y2)-(y1+y3))
242 + ((z0+z2)-(z1+z3))*((z0+z2)-(z1+z3));
243
244 lengths[2] = ((x0+x3)-(x1+x2))*((x0+x3)-(x1+x2))
245 + ((y0+y3)-(y1+y2))*((y0+y3)-(y1+y2))
246 + ((z0+z3)-(z1+z2))*((z0+z3)-(z1+z2));
247
248 const int id = imin_array(lengths);
249 // const int id = imax_array(lengths);
250
251 if ( (id == 0) && (lengths[0] < lengths[1]) )
252 {
253 swap_nodes(cells,c,1,2);
254 swap_nodes(cells,c,1,3);
255 ++nb_swaps;
256 }
257
258 if (id == 1)
259 {
260 // nothing to do
261 }
262
263 if ( (id == 2) && (lengths[2] < lengths[1]) )
264 {
265 swap_nodes(cells,c,2,3);
266 swap_nodes(cells,c,1,3);
267 ++nb_swaps;
268 }
269 }
270
271 Cerr << "************************************************" << finl;
272 Cerr << "Rectify_Mesh::check_cell_enumeration_3D report :" << finl;
273 Cerr << " " << nb_swaps << " swap" << ((nb_swaps ==1) ? "" : "s") << " were performed" << finl;
274 Cerr << "************************************************" << finl;
275
276}
277
278void Rectify_Mesh::swap_nodes(IntTab& cells, int cell, int node0, int node1)
279{
280 const int tmp = cells(cell,node0);
281 cells(cell,node0) = cells(cell,node1);
282 cells(cell,node1) = tmp;
283}
DoubleTab_t & les_sommets()
Definition Domaine.h:113
IntTab_t & les_elems()
Definition Domaine.h:129
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
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
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
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
: class Rectify_Mesh
void check_cell_type() const
void check_cell_orientation_2D()
void check_dimension() const
Entree & interpreter_(Entree &is) override
void swap_nodes(IntTab &cells, int cell, int node0, int node1)
void check_cell_orientation_3D()
void check_cell_enumeration_3D()
static void init_sequential_domain(Domaine_32_64< _SIZE_ > &dom)
Create parallel descriptors for the vertex and element arrays of the domain (necessary because Scatte...
Definition Scatter.cpp:2742
static void uninit_sequential_domain(Domaine_32_64< _SIZE_ > &dom)
methode utilisee par les interpretes qui modifient le domaine (sequentiel), detruit les descripteurs ...
Definition Scatter.cpp:2757
Classe de base des flux de sortie.
Definition Sortie.h:52
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133