TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Verifier_Simplexes.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 <Verifier_Simplexes.h>
17#include <Domaine.h>
18#include <Motcle.h>
19
20Implemente_instanciable_32_64(Verifier_Simplexes_32_64,"Verifier_Simplexes",Interprete_geometrique_base_32_64<_T_>) ;
21// XD verifier_simplexes interprete verifier_simplexes INHERITS_BRACE Keyword to raffine a simplexes
22// XD attr domain_name ref_domaine domain_name REQ Name of domain.
23
24template <typename _SIZE_>
26{
28 return os;
29}
30
31template <typename _SIZE_>
33{
35 return is;
36}
37
38// Helper implementation class that will only live in this file:
39template <typename _SIZE_>
40class Impl_32_64
41{
42public:
43 using int_t = _SIZE_;
44 using IntTab_t = IntTab_T<_SIZE_>;
45 using DoubleTab_t = DoubleTab_T<_SIZE_>;
46
48
51 static void check_internal_diagonal(Domaine_t& domain);
54 static void check_positive_volumes(Domaine_t& domain);
55};
56
57
58template <typename _SIZE_>
60{
61 const DoubleTab_t& nodes = domain.les_sommets();
62 IntTab_t& cells = domain.les_elems();
63
64 ArrOfDouble lengths(3);
65
66 const int_t nb_cells = cells.dimension(0);
67 int_t err_count = 0;
68 for (int_t cell=0; cell<nb_cells; ++cell)
69 {
70 const int_t s0 = cells(cell,0),
71 s1 = cells(cell,1),
72 s2 = cells(cell,2),
73 s3 = cells(cell,3);
74
75 const double x0 = nodes(s0,0);
76 const double x1 = nodes(s1,0);
77 const double x2 = nodes(s2,0);
78 const double x3 = nodes(s3,0);
79
80 const double y0 = nodes(s0,1);
81 const double y1 = nodes(s1,1);
82 const double y2 = nodes(s2,1);
83 const double y3 = nodes(s3,1);
84
85 const double z0 = nodes(s0,2);
86 const double z1 = nodes(s1,2);
87 const double z2 = nodes(s2,2);
88 const double z3 = nodes(s3,2);
89
90 const double x01 = 0.5 * (x0+x1);
91 const double x02 = 0.5 * (x0+x2);
92 const double x03 = 0.5 * (x0+x3);
93 const double x12 = 0.5 * (x1+x2);
94 const double x13 = 0.5 * (x1+x3);
95 const double x23 = 0.5 * (x2+x3);
96
97 const double y01 = 0.5 * (y0+y1);
98 const double y02 = 0.5 * (y0+y2);
99 const double y03 = 0.5 * (y0+y3);
100 const double y12 = 0.5 * (y1+y2);
101 const double y13 = 0.5 * (y1+y3);
102 const double y23 = 0.5 * (y2+y3);
103
104 const double z01 = 0.5 * (z0+z1);
105 const double z02 = 0.5 * (z0+z2);
106 const double z03 = 0.5 * (z0+z3);
107 const double z12 = 0.5 * (z1+z2);
108 const double z13 = 0.5 * (z1+z3);
109 const double z23 = 0.5 * (z2+z3);
110
111 lengths[0] = (x23-x01)*(x23-x01) + (y23-y01)*(y23-y01) + (z23-z01)*(z23-z01);
112 lengths[1] = (x13-x02)*(x13-x02) + (y13-y02)*(y13-y02) + (z13-z02)*(z13-z02);
113 lengths[2] = (x12-x03)*(x12-x03) + (y12-y03)*(y12-y03) + (z12-z03)*(z12-z03);
114
115 const int_t id = imin_array(lengths);
116
117 if (id == 0)
118 {
119 if (lengths[0] < lengths[1])
120 {
121 if (err_count == 0)
122 {
123 Cerr << "Error in Verifier_Simplexes_32_64.cpp 'check_internal_diagonal_for_tetrahedron()'" << finl;
124 Cerr << " The following cells have a bad internal diagonal :" << finl;
125 }
126 Cerr << cell << finl;
127 ++err_count;
128 }
129 }
130 else if (id == 1)
131 {
132 // rien a faire
133 }
134 else if (id == 2)
135 {
136 if (lengths[2] < lengths[1])
137 {
138 if (err_count == 0)
139 {
140 Cerr << "Error in Verifier_Simplexes_32_64.cpp 'check_internal_diagonal_for_tetrahedron()'" << finl;
141 Cerr << " The following cells have a bad internal diagonal :" << finl;
142 }
143 Cerr << cell << finl;
144 ++err_count;
145 }
146 }
147 else
148 {
149 if (err_count == 0)
150 {
151 Cerr << "Error in Verifier_Simplexes_32_64.cpp 'check_internal_diagonal_for_tetrahedron()'" << finl;
152 Cerr << " The following cells have a bad internal diagonal :" << finl;
153 }
154 Cerr << cell << finl;
155 ++err_count;
156 }
157 }
158
159 if (err_count>0)
161}
162
163template <typename _SIZE_>
165{
166 const Nom& cell_type = domain.type_elem()->que_suis_je();
167
168 Motcles understood_keywords(2);
169 understood_keywords[0] = "Triangle";
170 understood_keywords[1] = "Tetraedre";
171
172 int rank = understood_keywords.search(cell_type);
173 switch(rank)
174 {
175 case 0 :
177 break;
178 case 1 :
180 break;
181 default :
182 Cerr << "Error in Verifier_Simplexes_32_64.cpp 'check_internal_diagonal()'" << finl;
183 Cerr << " Unknown cell type : " << cell_type << finl;
184 Cerr << " Verifier_Simplexes_32_64 can only check Triangles and Tetrahedrons" << finl;
186 }
187}
188
189template <typename _SIZE_>
191{
192 const DoubleTab_t& nodes = domain.les_sommets();
193 IntTab_t& cells = domain.les_elems();
194
195 const int_t nb_cells = cells.dimension(0);
196 int_t err_count = 0;
197 for (int_t cell=0; cell<nb_cells; ++cell)
198 {
199 const int_t s0 = cells(cell,0),
200 s1 = cells(cell,1),
201 s2 = cells(cell,2);
202
203 const double x0 = nodes(s0,0);
204 const double x1 = nodes(s1,0);
205 const double x2 = nodes(s2,0);
206
207 const double y0 = nodes(s0,1);
208 const double y1 = nodes(s1,1);
209 const double y2 = nodes(s2,1);
210
211 const double area = 0.5 * ((x1-x0)*(y2-y0) - (x2-x0)*(y1-y0));
212 if ( area < 0.)
213 {
214 if (err_count == 0)
215 {
216 Cerr << "Error in Verifier_Simplexes_32_64.cpp 'check_positive_volumes_for_triangle()'" << finl;
217 Cerr << " The following cells have a negative orientation :" << finl;
218 }
219 Cerr << cell << finl;
220 ++err_count;
221 }
222 }
223 if (err_count>0)
225}
226
227template <typename _SIZE_>
229{
230 const DoubleTab_t& nodes = domain.les_sommets();
231 IntTab_t& cells = domain.les_elems();
232
233 const int_t nb_cells = cells.dimension(0);
234 int_t err_count = 0;
235 for (int_t cell=0; cell<nb_cells; ++cell)
236 {
237 const int_t s0 = cells(cell,0),
238 s1 = cells(cell,1),
239 s2 = cells(cell,2),
240 s3 = cells(cell,3);
241
242 const double x0 = nodes(s0,0);
243 const double x1 = nodes(s1,0);
244 const double x2 = nodes(s2,0);
245 const double x3 = nodes(s3,0);
246
247 const double y0 = nodes(s0,1);
248 const double y1 = nodes(s1,1);
249 const double y2 = nodes(s2,1);
250 const double y3 = nodes(s3,1);
251
252 const double z0 = nodes(s0,2);
253 const double z1 = nodes(s1,2);
254 const double z2 = nodes(s2,2);
255 const double z3 = nodes(s3,2);
256
257 const double volume = (1./6.) * ( (x1-x0) * (y2-y0) * (z3-z0) +
258 (x2-x0) * (y3-y0) * (z1-z0) +
259 (x3-x0) * (y1-y0) * (z2-z0) -
260 (z1-z0) * (y2-y0) * (x3-x0) -
261 (x2-x0) * (z3-z0) * (y1-y0) -
262 (y3-y0) * (x1-x0) * (z2-z0) );
263
264 if (volume < 0.)
265 {
266 if (err_count == 0)
267 {
268 Cerr << "Error in Verifier_Simplexes_32_64.cpp 'check_positive_volumes_for_tetrahedron()'" << finl;
269 Cerr << " The following cells have a negative orientation :" << finl;
270 }
271 Cerr << cell << finl;
272 ++err_count;
273 }
274 }
275 if (err_count>0)
277}
278
279template <typename _SIZE_>
281{
282 const Nom& cell_type = domain.type_elem()->que_suis_je();
283
284 Motcles understood_keywords(2);
285 understood_keywords[0] = "Triangle";
286 understood_keywords[1] = "Tetraedre";
287
288 int rank = understood_keywords.search(cell_type);
289 switch(rank)
290 {
291 case 0 :
293 break;
294 case 1 :
296 break;
297 default :
298 Cerr << "Error in Verifier_Simplexes_32_64.cpp 'check_positive_volumes()'" << finl;
299 Cerr << " Unknown cell type : " << cell_type << finl;
300 Cerr << " Verifier_Simplexes_32_64 can only check Triangles and Tetrahedrons" << finl;
302 }
303}
304
305template <typename _SIZE_>
307{
308 using Impl_ = Impl_32_64<_SIZE_>;
309
310 Impl_::check_internal_diagonal(domain);
311 Impl_::check_positive_volumes(domain);
312}
313
314template <typename _SIZE_>
316{
317 this->associer_domaine(is);
318
319 Domaine_t& domain = this->domaine();
320 check_domain(domain);
321
322 return is;
323}
324
325
326template class Verifier_Simplexes_32_64<int>;
327#if INT_is_64_ == 2
329#endif
330
classe Domaine_32_64 un Domaine est un maillage compose d'un ensemble d'elements geometriques de meme...
Definition Domaine.h:62
DoubleTab_t & les_sommets()
Definition Domaine.h:113
IntTab_t & les_elems()
Definition Domaine.h:129
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
static void check_internal_diagonal_for_triangle(Domaine_t &domain)
static void check_positive_volumes_for_tetrahedron(Domaine_t &domain)
Domaine_32_64< _SIZE_ > Domaine_t
DoubleTab_T< _SIZE_ > DoubleTab_t
static void check_positive_volumes(Domaine_t &domain)
static void check_internal_diagonal(Domaine_t &domain)
IntTab_T< _SIZE_ > IntTab_t
static void check_internal_diagonal_for_tetrahedron(Domaine_t &domain)
static void check_positive_volumes_for_triangle(Domaine_t &domain)
classe Interprete_geometrique_base .
Un tableau d'objets de la classe Motcle.
Definition Motcle.h:63
int search(const Motcle &t) const
Definition Motcle.cpp:321
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
friend class Entree
Definition Objet_U.h:76
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
Classe de base des flux de sortie.
Definition Sortie.h:52
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
: class Verifier_Simplexes
Entree & interpreter_(Entree &is) override
static void check_domain(Domaine_t &domain)
Domaine_32_64< _SIZE_ > Domaine_t