Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
Euclidian3Geometry.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 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/*---------------------------------------------------------------------------*/
8/* Euclidian3Geometry.h (C) 2000-2020 */
9/* */
10/* Euclidean geometric calculations in 3D. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13#ifndef ARCANE_GEOMETRY_EUCLIDIAN_EUCLIDIAN3GEOMETRY_H
14#define ARCANE_GEOMETRY_EUCLIDIAN_EUCLIDIAN3GEOMETRY_H
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/geometry/IGeometry.h"
19#include "arcane/core/MeshVariable.h"
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26namespace Arcane::Numerics
27{
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32class Euclidian3Geometry
33: public IGeometry
34{
35 public:
36
37 Euclidian3Geometry(const VariableNodeReal3& coords)
38 : m_coords(coords)
39 {}
40
41 virtual ~Euclidian3Geometry() {}
42
44
47
49
55
58
60
61 Real computeLength(const ItemWithNodes& item);
62
64
65 Real computeArea(const ItemWithNodes& item);
66
68
69 Real computeVolume(const ItemWithNodes& item);
70
72 Real3 computeSurfaceCenter(Integer n, const Real3* coords);
73
75 Real3 computeOrientedArea(Integer n, const Real3* coords);
76
78 Real computeLength(const Real3& m, const Real3& n);
79
81
82 public:
83
85 struct IComputeLine
86 {
87 IComputeLine(Euclidian3Geometry* geom)
88 : m_geom(geom)
89 , m_coords(geom->m_coords)
90 {}
91 virtual ~IComputeLine() {}
92 virtual void computeOrientedMeasureAndCenter(const ItemWithNodes& item, Real3& orientation, Real3& center) = 0;
93 Euclidian3Geometry* m_geom;
94 const VariableNodeReal3& m_coords;
95 };
96
97 struct ComputeLine2 : public IComputeLine
98 {
99 ComputeLine2(Euclidian3Geometry* geom)
100 : IComputeLine(geom)
101 {}
102 void computeOrientedMeasureAndCenter(const ItemWithNodes& item, Real3& orientation, Real3& center);
103 };
104
105 struct IComputeSurface
106 {
107 IComputeSurface(Euclidian3Geometry* geom)
108 : m_geom(geom)
109 , m_coords(geom->m_coords)
110 {}
111 virtual ~IComputeSurface() {}
112 virtual void computeOrientedMeasureAndCenter(const ItemWithNodes& item, Real3& orientation, Real3& center) = 0;
113 Euclidian3Geometry* m_geom;
114 const VariableNodeReal3& m_coords;
115 };
116
117 struct ComputeTriangle3
118 : public IComputeSurface
119 {
120 ComputeTriangle3(Euclidian3Geometry* geom)
121 : IComputeSurface(geom)
122 {}
123 void computeOrientedMeasureAndCenter(const ItemWithNodes& item, Real3& orientation, Real3& center);
124 };
125
126 struct ComputeQuad4 : public IComputeSurface
127 {
128 ComputeQuad4(Euclidian3Geometry* geom)
129 : IComputeSurface(geom)
130 {}
131 void computeOrientedMeasureAndCenter(const ItemWithNodes& item, Real3& orientation, Real3& center);
132 };
133
134 struct ComputePentagon5 : public IComputeSurface
135 {
136 ComputePentagon5(Euclidian3Geometry* geom)
137 : IComputeSurface(geom)
138 {}
139 void computeOrientedMeasureAndCenter(const ItemWithNodes& item, Real3& orientation, Real3& center);
140 };
141
142 struct ComputeHexagon6 : public IComputeSurface
143 {
144 ComputeHexagon6(Euclidian3Geometry* geom)
145 : IComputeSurface(geom)
146 {}
147 void computeOrientedMeasureAndCenter(const ItemWithNodes& item, Real3& orientation, Real3& center);
148 };
149
150 struct IComputeVolume
151 {
152 IComputeVolume(Euclidian3Geometry* geom)
153 : m_geom(geom)
154 , m_coords(geom->m_coords)
155 {}
156 virtual ~IComputeVolume() {}
157 virtual void computeOrientedMeasureAndCenter(const ItemWithNodes& item, Real& measure, Real3& center) = 0;
158 virtual void computeVolumeArea(const ItemWithNodes& item, Real& area) = 0;
159 Euclidian3Geometry* m_geom;
160 const VariableNodeReal3& m_coords;
161 };
162
163 struct ComputeTetraedron4 : public IComputeVolume
164 {
165 ComputeTetraedron4(Euclidian3Geometry* geom)
166 : IComputeVolume(geom)
167 {}
168 void computeOrientedMeasureAndCenter(const ItemWithNodes& item, Real& measure, Real3& center);
169 void computeVolumeArea(const ItemWithNodes& item, Real& area);
170 };
171
172 struct ComputeHeptaedron10 : public IComputeVolume
173 {
174 ComputeHeptaedron10(Euclidian3Geometry* geom)
175 : IComputeVolume(geom)
176 {}
177 void computeOrientedMeasureAndCenter(const ItemWithNodes& item, Real& measure, Real3& center)
178 {
179 ARCANE_UNUSED(item);
180 ARCANE_UNUSED(measure);
181 ARCANE_UNUSED(center);
183 }
184 void computeVolumeArea(const ItemWithNodes& item, Real& area)
185 {
186 ARCANE_UNUSED(item);
187 ARCANE_UNUSED(area);
189 }
190 };
191
192 struct ComputeOctaedron12
193 : public IComputeVolume
194 {
195 ComputeOctaedron12(Euclidian3Geometry* geom)
196 : IComputeVolume(geom)
197 {}
198 void computeOrientedMeasureAndCenter(const ItemWithNodes& item, Real& measure, Real3& center)
199 {
200 ARCANE_UNUSED(item);
201 ARCANE_UNUSED(measure);
202 ARCANE_UNUSED(center);
204 }
205 void computeVolumeArea(const ItemWithNodes& item, Real& area)
206 {
207 ARCANE_UNUSED(item);
208 ARCANE_UNUSED(area);
210 }
211 };
212
213 struct ComputeGenericVolume : public IComputeVolume
214 {
215 ComputeGenericVolume(Euclidian3Geometry* geom)
216 : IComputeVolume(geom)
217 {}
218 void computeOrientedMeasureAndCenter(const ItemWithNodes& item, Real& measure, Real3& center);
219 void computeVolumeArea(const ItemWithNodes& item, Real& area);
220 };
221
222 typedef ComputeGenericVolume ComputePyramid5;
223 typedef ComputeGenericVolume ComputePentaedron6;
224 typedef ComputeGenericVolume ComputeHexaedron8;
225 typedef ComputeGenericVolume ComputeHemiHexa7;
226 typedef ComputeGenericVolume ComputeHemiHexa6;
227 typedef ComputeGenericVolume ComputeHemiHexa5;
228 typedef ComputeGenericVolume ComputeAntiWedgeLeft6;
229 typedef ComputeGenericVolume ComputeAntiWedgeRight6;
230 typedef ComputeGenericVolume ComputeDiTetra5;
232
234 static inline Real3 computeTriangleNormal(const Real3& n0, const Real3& n1, const Real3& n2)
235 {
236 return math::vecMul(n1 - n0, n2 - n0) / 2.0;
237 }
238
239 static inline Real computeTriangleSurface(const Real3& n0, const Real3& n1, const Real3& n2)
240 {
241 return math::normeR3(computeTriangleNormal(n0, n1, n2));
242 }
243
244 static inline Real3 computeTriangleCenter(const Real3& n0, const Real3& n1, const Real3& n2)
245 {
246 return (n0 + n1 + n2) / 3.0;
247 }
248
249 static inline Real computeTetraedronVolume(const Real3& n0, const Real3& n1, const Real3& n2, const Real3& n3)
250 {
251 return math::mixteMul(n1 - n0, n2 - n0, n3 - n0) / 6.0;
252 }
253
254 static inline Real3 computeTetraedronCenter(const Real3& n0, const Real3& n1, const Real3& n2, const Real3& n3)
255 {
256 return 0.25 * (n0 + n1 + n2 + n3);
257 }
258
259 static inline Real3 computeQuadrilateralCenter(const Real3& n0, const Real3& n1, const Real3& n2, const Real3& n3)
260 {
261 const Real s0 = computeTriangleSurface(n0, n1, n2);
262 const Real s1 = computeTriangleSurface(n0, n2, n3);
263 const Real s2 = computeTriangleSurface(n1, n2, n3);
264 const Real s3 = computeTriangleSurface(n0, n1, n3);
265 return (s0 * computeTriangleCenter(n0, n1, n2) +
266 s1 * computeTriangleCenter(n0, n2, n3) +
267 s2 * computeTriangleCenter(n1, n2, n3) +
268 s3 * computeTriangleCenter(n0, n1, n3)) /
269 (s0 + s1 + s2 + s3);
270 }
271
272 static inline Real3 computePentagonalCenter(const Real3& n0, const Real3& n1, const Real3& n2, const Real3& n3, const Real3& n4)
273 {
274 const Real s0 = computeTriangleSurface(n4, n0, n1);
275 const Real s1 = computeTriangleSurface(n0, n1, n2);
276 const Real s2 = computeTriangleSurface(n1, n2, n3);
277 const Real s3 = computeTriangleSurface(n2, n3, n4);
278 const Real s4 = computeTriangleSurface(n3, n4, n0);
279 const Real s5 = computeTriangleSurface(n0, n2, n3);
280 const Real s6 = computeTriangleSurface(n1, n3, n4);
281 const Real s7 = computeTriangleSurface(n2, n4, n0);
282 const Real s8 = computeTriangleSurface(n3, n0, n1);
283 const Real s9 = computeTriangleSurface(n4, n1, n2);
284
285 return (2 * (s0 * computeTriangleCenter(n4, n0, n1) + s1 * computeTriangleCenter(n0, n1, n2) + s2 * computeTriangleCenter(n1, n2, n3) + s3 * computeTriangleCenter(n2, n3, n4) + s4 * computeTriangleCenter(n3, n4, n0)) +
286 s5 * computeTriangleCenter(n0, n2, n3) +
287 s6 * computeTriangleCenter(n1, n3, n4) +
288 s7 * computeTriangleCenter(n2, n4, n0) +
289 s8 * computeTriangleCenter(n3, n0, n1) +
290 s9 * computeTriangleCenter(n4, n1, n2)) /
291 (2 * (s0 + s1 + s2 + s3 + s4) + s5 + s6 + s7 + s8 + s9);
292 }
293
294 static inline Real3 computeHexagonalCenter(const Real3& n0, const Real3& n1, const Real3& n2, const Real3& n3, const Real3& n4, const Real3& n5)
295 {
296 const Real s0 = computeTriangleSurface(n0, n1, n5);
297 const Real s1 = computeTriangleSurface(n1, n2, n3);
298 const Real s2 = computeTriangleSurface(n3, n4, n5);
299 const Real s3 = computeTriangleSurface(n1, n3, n5);
300 const Real s4 = computeTriangleSurface(n0, n1, n2);
301 const Real s5 = computeTriangleSurface(n2, n3, n4);
302 const Real s6 = computeTriangleSurface(n4, n5, n0);
303 const Real s7 = computeTriangleSurface(n0, n2, n4);
304
305 return (s0 * computeTriangleCenter(n0, n1, n5) +
306 s1 * computeTriangleCenter(n1, n2, n3) +
307 s2 * computeTriangleCenter(n3, n4, n5) +
308 s3 * computeTriangleCenter(n1, n3, n5) +
309 s4 * computeTriangleCenter(n0, n1, n2) +
310 s5 * computeTriangleCenter(n2, n3, n4) +
311 s6 * computeTriangleCenter(n4, n5, n0) +
312 s7 * computeTriangleCenter(n0, n2, n4)) /
313 (s0 + s1 + s2 + s3 + s4 + s5 + s6 + s7);
314 }
316
317 protected:
318
319 const VariableNodeReal3& m_coords;
320};
321
322/*---------------------------------------------------------------------------*/
323/*---------------------------------------------------------------------------*/
324
325} // End namespace Arcane::Numerics
326
327/*---------------------------------------------------------------------------*/
328/*---------------------------------------------------------------------------*/
329
330#endif
#define ARCANE_THROW(exception_class,...)
Macro for throwing an exception with formatting.
Declarations of Arcane's general types.
Various mathematical functions.
Mesh element based on nodes (Edge,Face,Cell).
Definition Item.h:773
Real3 computeCenter(const ItemWithNodes &item)
Calculation of the center of mass.
Real computeVolume(const ItemWithNodes &item)
Calculation of the volume.
Real3 computeSurfaceCenter(Integer n, const Real3 *coords)
Calculation of the center.
Real3 computeOrientedArea(Integer n, const Real3 *coords)
Calculation of the oriented area (i.e., normal).
Real3 computeOrientedMeasure(const ItemWithNodes &item)
Calculation of the oriented measure.
Real computeArea(const ItemWithNodes &item)
Calculation of the area.
Real computeLength(const ItemWithNodes &item)
Calculation of the length.
Real computeMeasure(const ItemWithNodes &item)
Calculation of the measure (without orientation).
Class managing a 3-dimensional real vector.
Definition Real3.h:132
__host__ __device__ Real3 vecMul(Real3 u, Real3 v)
Vector cross product of u by v in .
Definition MathUtils.h:48
__host__ __device__ Real mixteMul(Real3 u, Real3 v, Real3 w)
Mixed product of u, v and w.
Definition MathUtils.h:161
MeshVariableScalarRefT< Node, Real3 > VariableNodeReal3
Coordinate type quantity at node.
Real normeR3(Real3 v1)
Norm of a vector.
Definition MathUtils.h:684
Int32 Integer
Type representing an integer.
double Real
Type representing a real number.