Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
Euclidian3Geometry.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7#include <arcane/geometry/euclidian/Euclidian3Geometry.h>
8/* Author : havep at Wed Nov 14 14:23:21 2007
9 * Generated by createNew
10 */
11using namespace Arcane;
12#include <arcane/utils/FatalErrorException.h>
13#include <arcane/utils/NotImplementedException.h>
14
15ARCANE_BEGIN_NAMESPACE
16NUMERICS_BEGIN_NAMESPACE
17
19Euclidian3Geometry::
20computeCenter(const ItemWithNodes & item)
21{
22 Real3 orientation, center;
23 Real measure;
24
25 switch (item.type()) {
26 case IT_Line2:
27 ComputeLine2(this).computeOrientedMeasureAndCenter(item,orientation,center);
28 return center;
29 case IT_Triangle3:
30 ComputeTriangle3(this).computeOrientedMeasureAndCenter(item,orientation,center);
31 return center;
32 case IT_Quad4:
33 ComputeQuad4(this).computeOrientedMeasureAndCenter(item,orientation,center);
34 return center;
35 case IT_Pentagon5:
36 ComputePentagon5(this).computeOrientedMeasureAndCenter(item,orientation,center);
37 return center;
38 case IT_Hexagon6:
39 ComputeHexagon6(this).computeOrientedMeasureAndCenter(item,orientation,center);
40 return center;
41 case IT_Tetraedron4:
42 ComputeTetraedron4(this).computeOrientedMeasureAndCenter(item,measure,center);
43 return center;
44 case IT_Pyramid5:
45 ComputePyramid5(this).computeOrientedMeasureAndCenter(item,measure,center);
46 return center;
47 case IT_Pentaedron6:
48 ComputePentaedron6(this).computeOrientedMeasureAndCenter(item,measure,center);
49 return center;
50 case IT_Hexaedron8:
51 ComputeHexaedron8(this).computeOrientedMeasureAndCenter(item,measure,center);
52 return center;
53 case IT_Heptaedron10:
54 ComputeHeptaedron10(this).computeOrientedMeasureAndCenter(item,measure,center);
55 return center;
56 case IT_Octaedron12:
57 ComputeOctaedron12(this).computeOrientedMeasureAndCenter(item,measure,center);
58 return center;
59 default:
60 throw FatalErrorException(A_FUNCINFO,"Not supported Item Type");
61 }
62}
63
65Euclidian3Geometry::
66computeOrientedMeasure(const ItemWithNodes & item)
67{
68 Real3 orientation, center;
69 Real measure;
70 switch (item.type()) {
71 case IT_Line2:
72 ComputeLine2(this).computeOrientedMeasureAndCenter(item,orientation,center);
73 return orientation;
74 case IT_Triangle3:
75 ComputeTriangle3(this).computeOrientedMeasureAndCenter(item,orientation,center);
76 return orientation;
77 case IT_Quad4:
78 ComputeQuad4(this).computeOrientedMeasureAndCenter(item,orientation,center);
79 return orientation;
80 case IT_Pentagon5:
81 ComputePentagon5(this).computeOrientedMeasureAndCenter(item,orientation,center);
82 return orientation;
83 case IT_Hexagon6:
84 ComputeHexagon6(this).computeOrientedMeasureAndCenter(item,orientation,center);
85 return orientation;
86 case IT_Tetraedron4:
87 ComputeTetraedron4(this).computeOrientedMeasureAndCenter(item,measure,center);
88 return Real3(0,0,measure);
89 case IT_Pyramid5:
90 ComputePyramid5(this).computeOrientedMeasureAndCenter(item,measure,center);
91 return Real3(0,0,measure);
92 case IT_Pentaedron6:
93 ComputePentaedron6(this).computeOrientedMeasureAndCenter(item,measure,center);
94 return Real3(0,0,measure);
95 case IT_Hexaedron8:
96 ComputeHexaedron8(this).computeOrientedMeasureAndCenter(item,measure,center);
97 return Real3(0,0,measure);
98 case IT_Heptaedron10:
99 ComputeHeptaedron10(this).computeOrientedMeasureAndCenter(item,measure,center);
100 return Real3(0,0,measure);
101 case IT_Octaedron12:
102 ComputeOctaedron12(this).computeOrientedMeasureAndCenter(item,measure,center);
103 return Real3(0,0,measure);
104 default:
105 throw FatalErrorException(A_FUNCINFO,"Not supported Item Type");
106 }
107}
108
109Real
110Euclidian3Geometry::
111computeMeasure(const ItemWithNodes & item)
112{
113 Real3 orientation, center;
114 Real measure;
115
116 switch (item.type()) {
117 case IT_Line2:
118 ComputeLine2(this).computeOrientedMeasureAndCenter(item,orientation,center);
119 return math::normeR3(orientation);
120 case IT_Triangle3:
121 ComputeTriangle3(this).computeOrientedMeasureAndCenter(item,orientation,center);
122 return math::normeR3(orientation);
123 case IT_Quad4:
124 ComputeQuad4(this).computeOrientedMeasureAndCenter(item,orientation,center);
125 return math::normeR3(orientation);
126 case IT_Pentagon5:
127 ComputePentagon5(this).computeOrientedMeasureAndCenter(item,orientation,center);
128 return math::normeR3(orientation);
129 case IT_Hexagon6:
130 ComputeHexagon6(this).computeOrientedMeasureAndCenter(item,orientation,center);
131 return math::normeR3(orientation);
132 case IT_Tetraedron4:
133 ComputeTetraedron4(this).computeOrientedMeasureAndCenter(item,measure,center);
134 return measure;
135 case IT_Pyramid5:
136 ComputePyramid5(this).computeOrientedMeasureAndCenter(item,measure,center);
137 return measure;
138 case IT_Pentaedron6:
139 ComputePentaedron6(this).computeOrientedMeasureAndCenter(item,measure,center);
140 return measure;
141 case IT_Hexaedron8:
142 ComputeHexaedron8(this).computeOrientedMeasureAndCenter(item,measure,center);
143 return measure;
144 case IT_Heptaedron10:
145 ComputeHeptaedron10(this).computeOrientedMeasureAndCenter(item,measure,center);
146 return measure;
147 case IT_Octaedron12:
148 ComputeOctaedron12(this).computeOrientedMeasureAndCenter(item,measure,center);
149 return measure;
150 default:
151 ARCANE_THROW(NotSupportedException,"Not supported Item Type {0}",item.type());
152 }
153}
154
155Real Euclidian3Geometry::
156computeLength(const ItemWithNodes & item)
157{
158 ARCANE_UNUSED(item);
160}
161
162Real Euclidian3Geometry::
163computeArea(const ItemWithNodes & item)
164{
165 Real3 orientation, center;
166
167 switch (item.type()) {
168 case IT_Line2:
169 return 0.;
170 case IT_Triangle3:
171 ComputeTriangle3(this).computeOrientedMeasureAndCenter(item,orientation,center);
172 return math::normeR3(orientation);
173 case IT_Quad4:
174 ComputeQuad4(this).computeOrientedMeasureAndCenter(item,orientation,center);
175 return math::normeR3(orientation);
176 case IT_Pentagon5:
177 ComputePentagon5(this).computeOrientedMeasureAndCenter(item,orientation,center);
178 return math::normeR3(orientation);
179 case IT_Hexagon6:
180 ComputeHexagon6(this).computeOrientedMeasureAndCenter(item,orientation,center);
181 return math::normeR3(orientation);
182 case IT_Tetraedron4:
183 case IT_Pyramid5:
184 case IT_Pentaedron6:
185 case IT_Hexaedron8:
186 case IT_Heptaedron10:
187 case IT_Octaedron12:
188 case IT_HemiHexa7:
189 case IT_HemiHexa6:
190 case IT_HemiHexa5:
191 case IT_AntiWedgeLeft6:
192 case IT_AntiWedgeRight6:
193 case IT_DiTetra5:
194 return 0.;
195 default:
196 throw FatalErrorException(A_FUNCINFO,"Not supported Item Type");
197 }
198}
199
200Real
201Euclidian3Geometry::
202computeVolume(const ItemWithNodes & item)
203{
204 Real3 center;
205 Real measure;
206
207 switch (item.type()) {
208 case IT_Line2:
209 return 0.;
210 break;
211 case IT_Triangle3:
212 case IT_Quad4:
213 case IT_Pentagon5:
214 case IT_Hexagon6:
215 return 0.;
216 case IT_Tetraedron4:
217 ComputeTetraedron4(this).computeOrientedMeasureAndCenter(item,measure,center);
218 return measure;
219 case IT_Pyramid5:
220 ComputePyramid5(this).computeOrientedMeasureAndCenter(item,measure,center);
221 return measure;
222 case IT_Pentaedron6:
223 ComputePentaedron6(this).computeOrientedMeasureAndCenter(item,measure,center);
224 return measure;
225 case IT_Hexaedron8:
226 ComputeHexaedron8(this).computeOrientedMeasureAndCenter(item,measure,center);
227 return measure;
228 case IT_Heptaedron10:
229 ComputeHeptaedron10(this).computeOrientedMeasureAndCenter(item,measure,center);
230 return measure;
231 case IT_Octaedron12:
232 ComputeOctaedron12(this).computeOrientedMeasureAndCenter(item,measure,center);
233 return measure;
234 case IT_HemiHexa7:
235 ComputeHemiHexa7(this).computeOrientedMeasureAndCenter(item,measure,center);
236 return measure;
237 case IT_HemiHexa6:
238 ComputeHemiHexa6(this).computeOrientedMeasureAndCenter(item,measure,center);
239 return measure;
240 case IT_HemiHexa5:
241 ComputeHemiHexa5(this).computeOrientedMeasureAndCenter(item,measure,center);
242 return measure;
243 case IT_AntiWedgeLeft6:
244 ComputeAntiWedgeLeft6(this).computeOrientedMeasureAndCenter(item,measure,center);
245 return measure;
246 case IT_AntiWedgeRight6:
247 ComputeAntiWedgeRight6(this).computeOrientedMeasureAndCenter(item,measure,center);
248 return measure;
249 case IT_DiTetra5:
250 ComputeDiTetra5(this).computeOrientedMeasureAndCenter(item,measure,center);
251 return measure;
252 default:
253 throw FatalErrorException(A_FUNCINFO,"Not supported Item Type");
254 }
255}
256
257Real3
258Euclidian3Geometry::
259computeSurfaceCenter(Integer n, const Real3 * coords)
260{
261 if (n == 3)
262 return computeTriangleCenter(coords[0],coords[1],coords[2]);
263
264 Real3 center(0,0,0);
265 Real area = 0;
266 for(Integer i=1;i<n-1;++i)
267 {
268 Real local_area = math::normeR3(computeTriangleNormal(coords[0],coords[i],coords[i+1]));
269 center += local_area * computeTriangleCenter(coords[0],coords[i],coords[i+1]);
270 area += local_area;
271 }
272 return center/area;
273}
274
275Real3
276Euclidian3Geometry::
277computeOrientedArea(Integer n, const Real3 * coords)
278{
279 Real3 normal(0.,0.,0.);
280 for(Integer i=1;i<n-1;++i)
281 normal += computeTriangleNormal(coords[0],coords[i],coords[i+1]);
282 return normal;
283}
284
285Real
286Euclidian3Geometry::
287computeLength(const Real3& m, const Real3& n)
288{
289 const Real3 d = m-n ;
290 return math::sqrt(math::scaMul(d,d)) ;
291}
292
293/*---------------------------------------------------------------------------*/
294
295void
296Euclidian3Geometry::ComputeLine2::
297computeOrientedMeasureAndCenter(const ItemWithNodes & item, Real3 & orientation, Real3 & center)
298{
299 orientation = m_coords[item.node(1)] - m_coords[item.node(0)];
300 center = 0.5 * (m_coords[item.node(1)] + m_coords[item.node(0)]);
301}
302
303void
304Euclidian3Geometry::ComputeTriangle3::
305computeOrientedMeasureAndCenter(const ItemWithNodes & item, Real3 & orientation, Real3 & center)
306{
307 orientation =
308 computeTriangleNormal(m_coords[item.node(0)],
309 m_coords[item.node(1)],
310 m_coords[item.node(2)]);
311
312 center =
313 computeTriangleCenter(m_coords[item.node(0)],
314 m_coords[item.node(1)],
315 m_coords[item.node(2)]);
316}
317
318void
319Euclidian3Geometry::ComputeQuad4::
320computeOrientedMeasureAndCenter(const ItemWithNodes & item, Real3 & orientation, Real3 & center)
321{
322 orientation =
323 computeTriangleNormal(m_coords[item.node(0)],
324 m_coords[item.node(1)],
325 m_coords[item.node(2)]) +
326 computeTriangleNormal(m_coords[item.node(0)],
327 m_coords[item.node(2)],
328 m_coords[item.node(3)]);
329
330 center =
331 computeQuadrilateralCenter(m_coords[item.node(0)],
332 m_coords[item.node(1)],
333 m_coords[item.node(2)],
334 m_coords[item.node(3)]);
335}
336
337void
338Euclidian3Geometry::ComputePentagon5::
339computeOrientedMeasureAndCenter(const ItemWithNodes & item, Real3 & orientation, Real3 & center)
340{
341 orientation =
342 computeTriangleNormal(m_coords[item.node(0)],
343 m_coords[item.node(1)],
344 m_coords[item.node(2)]) +
345 computeTriangleNormal(m_coords[item.node(0)],
346 m_coords[item.node(2)],
347 m_coords[item.node(3)]) +
348 computeTriangleNormal(m_coords[item.node(0)],
349 m_coords[item.node(3)],
350 m_coords[item.node(4)]);
351
352 center =
353 computePentagonalCenter(m_coords[item.node(0)],
354 m_coords[item.node(1)],
355 m_coords[item.node(2)],
356 m_coords[item.node(3)],
357 m_coords[item.node(4)]);
358}
359
360
361void
362Euclidian3Geometry::ComputeHexagon6::
363computeOrientedMeasureAndCenter(const ItemWithNodes & item, Real3 & orientation, Real3 & center)
364{
365 orientation =
366 computeTriangleNormal(m_coords[item.node(0)],
367 m_coords[item.node(1)],
368 m_coords[item.node(2)]) +
369 computeTriangleNormal(m_coords[item.node(0)],
370 m_coords[item.node(2)],
371 m_coords[item.node(3)]) +
372 computeTriangleNormal(m_coords[item.node(0)],
373 m_coords[item.node(3)],
374 m_coords[item.node(4)]) +
375 computeTriangleNormal(m_coords[item.node(0)],
376 m_coords[item.node(4)],
377 m_coords[item.node(5)]);
378
379 center =
380 computeHexagonalCenter(m_coords[item.node(0)],
381 m_coords[item.node(1)],
382 m_coords[item.node(2)],
383 m_coords[item.node(3)],
384 m_coords[item.node(4)],
385 m_coords[item.node(5)]);
386}
387
388
389void
390Euclidian3Geometry::ComputeTetraedron4::
391computeOrientedMeasureAndCenter(const ItemWithNodes & item, Real & measure, Real3 & center)
392{
393 ARCANE_ASSERT((item.type() == IT_Tetraedron4),("Bad item type: %d vs %d (Tetra4)",item.type(),IT_Tetraedron4));
394 measure = computeTetraedronVolume(m_coords[item.node(0)],
395 m_coords[item.node(1)],
396 m_coords[item.node(2)],
397 m_coords[item.node(3)]);
398 center = computeTetraedronCenter(m_coords[item.node(0)],
399 m_coords[item.node(1)],
400 m_coords[item.node(2)],
401 m_coords[item.node(3)]);
402}
403
404void
405Euclidian3Geometry::ComputeTetraedron4::
406computeVolumeArea(const ItemWithNodes & item, Real & area)
407{
408 ARCANE_ASSERT((item.type() == IT_Tetraedron4),("Bad item type: %d vs %d (Tetra4)",item.type(),IT_Tetraedron4));
409 const Cell cell = item.toCell();
410 for(Integer i=0;i<4;++i)
411 {
412 const Face face = cell.face(i);
413 area += math::abs(computeTriangleSurface(m_coords[face.node(0)],
414 m_coords[face.node(1)],
415 m_coords[face.node(2)]));
416 }
417}
418
419/*---------------------------------------------------------------------------*/
420
421void
422Euclidian3Geometry::ComputeGenericVolume::
423computeOrientedMeasureAndCenter(const ItemWithNodes & item, Real & measure, Real3 & center)
424{
425 // Choix d'un point arbitraire d'étoilement, mais "proche" du centre
426 Real3 vcenter(0,0,0);
427 for(Integer i=0;i<item.nbNode();++i) {
428 vcenter += m_coords[item.node(i)];
429 }
430 vcenter /= item.nbNode();
431
432 Real volume = 0;
433 center = Real3(0,0,0);
434
435 // Etoilement des faces puis du volume en tétraèdres
436 const Cell cell = item.toCell();
437 for(Integer i=0;i<cell.nbFace();++i)
438 {
439 const Face face = cell.face(i);
440 const Real orientation = (face.frontCell() == cell)?1:-1;
441
442 if (face.nbNode() == 3) {
443 Real v = orientation * computeTetraedronVolume(m_coords[face.node(0)],
444 m_coords[face.node(1)],
445 m_coords[face.node(2)],
446 vcenter);
447 center += v * computeTetraedronCenter(m_coords[face.node(0)],
448 m_coords[face.node(1)],
449 m_coords[face.node(2)],
450 vcenter);
451 volume += v;
452 } else if (face.nbNode() == 4) {
453 // Le tableau contient le modulo ...
454 const Real3 coords[5] = { m_coords[face.node(0)],
455 m_coords[face.node(1)],
456 m_coords[face.node(2)],
457 m_coords[face.node(3)],
458 m_coords[face.node(0)] };
459 const Real3 fcenter = computeQuadrilateralCenter(coords[0],coords[1],coords[2],coords[3]);
460 for(Integer j=0;j<4;++j) {
461 const Real v = orientation * computeTetraedronVolume(coords[j], coords[j+1], fcenter, vcenter);
462 center += v * computeTetraedronCenter(coords[j], coords[j+1], fcenter, vcenter);
463 volume += v;
464 }
465 } else {
466 throw NotImplementedException(A_FUNCINFO,"Not implemented for face with more than 4 nodes");
467 }
468 }
469
470 center /= volume;
471 measure = volume;
472}
473
474/*---------------------------------------------------------------------------*/
475
476void
477Euclidian3Geometry::ComputeGenericVolume::
478computeVolumeArea(const ItemWithNodes & item, Real & area)
479{
480 const Cell cell = item.toCell();
481 for(Integer i=0;i<cell.nbFace();++i)
482 {
483 const Face face = cell.face(i);
484 if (face.nbNode() == 3) {
485 area += math::abs(computeTriangleSurface(m_coords[face.node(0)],
486 m_coords[face.node(1)],
487 m_coords[face.node(2)]));
488 } else if (face.nbNode() == 4) {
489 area += math::abs(computeTriangleSurface(m_coords[item.node(0)],
490 m_coords[item.node(1)],
491 m_coords[item.node(2)]))
492 + math::abs(computeTriangleSurface(m_coords[item.node(0)],
493 m_coords[item.node(3)],
494 m_coords[item.node(3)]));
495 } else {
496 throw NotImplementedException(A_FUNCINFO,"Not implemented for face with more than 4 nodes");
497 }
498 }
499}
500
501/*---------------------------------------------------------------------------*/
502/*---------------------------------------------------------------------------*/
503
504NUMERICS_END_NAMESPACE
505ARCANE_END_NAMESPACE
#define ARCANE_THROW(exception_class,...)
Macro pour envoyer une exception avec formattage.
Maille d'un maillage.
Definition Item.h:1178
Face face(Int32 i) const
i-ème face de la maille
Definition Item.h:1255
Int32 nbFace() const
Nombre de faces de la maille.
Definition Item.h:1252
Face d'une maille.
Definition Item.h:932
Cell frontCell() const
Maille devant la face (maille nulle si aucune)
Definition Item.h:1604
Elément de maillage s'appuyant sur des noeuds (Edge,Face,Cell).
Definition Item.h:714
Node node(Int32 i) const
i-ème noeud de l'entité
Definition Item.h:768
Int32 nbNode() const
Nombre de noeuds de l'entité
Definition Item.h:765
Cell toCell() const
Converti l'entité en le genre Cell.
Definition Item.h:1654
Int16 type() const
Type de l'entité
Definition Item.h:232
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Classe gérant un vecteur de réel de dimension 3.
Definition Real3.h:132
Exception lorsqu'une erreur fatale est survenue.
Exception lorsqu'une fonction n'est pas implémentée.
Exception lorsqu'une opération n'est pas supportée.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-