MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
GeometryElement< nDim > Class Template Reference

#include <geometryelement.h>

Public Member Functions

void boundingBox ()
 
void writeElement () const
 
void calcNormal (const MFloat *const vertices, MFloat *normal) const
 Calculates the normal vector from the geometry element vertices. More...
 
void calcCentroid (const MFloat *const vertices, MFloat *centroid) const
 Calculate the centroid of the geometry element vertices. More...
 
void getVertices (MFloat *vertices) const
 Return the vertices of the geometry element. More...
 
void allocateElements (void *, void *, MInt &)
 

Static Public Member Functions

static void init (MInt NotUsed(dimensions), MInt, MInt)
 
static MInt staticElementSize ()
 

Public Attributes

MInt m_segmentId
 
MInt m_bndCndId
 
MInt m_originalId
 
MFloat ** m_vertices
 
MFloatm_normal
 
MFloatm_minMax
 

Detailed Description

template<MInt nDim>
class GeometryElement< nDim >

Representation of the geometrical concept of an element

Collector class! In 2D an element consists of two vertices and is part of a segment. In 3D an element consists of at least 3 vertices and is part of a segment.

Definition at line 20 of file geometryelement.h.

Member Function Documentation

◆ allocateElements()

template<MInt nDim>
void GeometryElement< nDim >::allocateElements ( void *  tmpPointer,
void *  ,
MInt  
)

Definition at line 24 of file geometryelement.cpp.

24 {
25 // TRACE();
26
27 m_vertices = (MFloat**)tmpPointer;
28 // Jump memory for pointers to pointers
29 for(MInt i = 0; i < nDim; i++) {
30 tmpPointer = (void*)((MFloat**)tmpPointer + 1);
31 }
32
33 for(MInt i = 0; i < nDim; i++) {
34 // Set pointers to pointers
35 m_vertices[i] = (MFloat*)tmpPointer;
36 // Jump memory for values
37 tmpPointer = (void*)((MFloat*)tmpPointer + nDim);
38 }
39 m_normal = (MFloat*)tmpPointer;
40 tmpPointer = (void*)((MFloat*)tmpPointer + nDim);
41 m_minMax = (MFloat*)tmpPointer;
42}
MFloat ** m_vertices
int32_t MInt
Definition: maiatypes.h:62
double MFloat
Definition: maiatypes.h:52

◆ boundingBox()

template<MInt nDim>
void GeometryElement< nDim >::boundingBox

Definition at line 45 of file geometryelement.cpp.

45 {
46 // TRACE();
47
48 for(MInt j = 0; j < nDim; j++) {
49 m_minMax[j] = m_vertices[0][j];
50 m_minMax[j + nDim] = m_vertices[0][j];
51 }
52 for(MInt i = 0; i < nDim; i++) {
53 for(MInt j = 0; j < nDim; j++) {
54 // Find maximum
55 m_minMax[j + nDim] = (m_minMax[j + nDim] < m_vertices[i][j]) ? m_vertices[i][j] : m_minMax[j + nDim];
56 // Find minimum
57 m_minMax[j] = (m_minMax[j] > m_vertices[i][j]) ? m_vertices[i][j] : m_minMax[j];
58 }
59 }
60}

◆ calcCentroid()

template<MInt nDim>
void GeometryElement< nDim >::calcCentroid ( const MFloat *const  vertices,
MFloat centroid 
) const
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de, Rodrigo Miguez
Date
2014-03-19, 2019-10-31
Parameters
[in]verticesGeometry element vertices
[out]centroidAfter a call to calcCentroid(), centroid holds the centroid of the element. Must point to storage of at least size nDim.

Definition at line 159 of file geometryelement.cpp.

159 {
160 TRACE();
161
162 // Calculate sums over vertices and divide by dimensions (works for 2D and 3D)
163 // Example 2D:
164 // vertices: (x0, y0), (x1, y1)
165 // centroid: ((x0 + x1)/2, (y0 + y1)/2)
166 for(MInt dim = 0; dim < nDim; dim++) {
167 centroid[dim] = 0.0;
168 for(MInt vertexId = 0; vertexId < nDim; vertexId++) {
169 centroid[dim] += vertices[(vertexId * nDim) + dim];
170 }
171 centroid[dim] /= static_cast<MFloat>(nDim);
172 }
173}

◆ calcNormal()

template<MInt nDim>
void GeometryElement< nDim >::calcNormal ( const MFloat *const  vertices,
MFloat normal 
) const
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de, Rodrigo Miguez
Date
2014-03-18, 2019-10-31
Parameters
[in]verticesGeometry element vertices
[out]normalAfter a call to calcNormal(), normal holds the normalized normal vector. Must point to storage of at least size nDim.

Definition at line 103 of file geometryelement.cpp.

103 {
104 TRACE();
105
106 using Vec2D = array<MFloat, 2>;
107 using Vec3D = array<MFloat, 3>;
108
109 // Since the used algorithms depend on the dimension, we need to branch here
110 IF_CONSTEXPR(nDim == 2) {
111 Vec2D edge, norm;
112
113 // Calculate edge vector
114 edge[0] = vertices[2] - vertices[0];
115 edge[1] = vertices[3] - vertices[1];
116
117 // Calculate vector normal to edge
118 norm[0] = edge[1];
119 norm[1] = -edge[0];
120
121 // Normalize normal vector and copy to result
123 copy(norm.begin(), norm.end(), normal);
124 }
125 else IF_CONSTEXPR(nDim == 3) {
126 Vec3D edge0, edge1, norm;
127
128 // Calculate edge vectors
129 edge0[0] = vertices[3] - vertices[0];
130 edge0[1] = vertices[4] - vertices[1];
131 edge0[2] = vertices[5] - vertices[2];
132 edge1[0] = vertices[6] - vertices[0];
133 edge1[1] = vertices[7] - vertices[1];
134 edge1[2] = vertices[8] - vertices[2];
135
136 // Calculate vector normal to plane
137 norm = maia::math::cross(edge0, edge1);
138
139 // Normalize normal vector and copy to result
141 copy(norm.begin(), norm.end(), normal);
142 }
143 else {
144 TERMM(1, "Bad number of dimensions.");
145 }
146}
void cross(const T *const u, const T *const v, T *const c)
Definition: maiamath.h:101
void normalize(std::array< T, N > &u)
Definition: maiamath.h:191
MFloat norm(const std::array< T, N > &u)
Definition: maiamath.h:148

◆ getVertices()

template<MInt nDim>
void GeometryElement< nDim >::getVertices ( MFloat vertices) const
Author
Rodrigo Barros Miguez (rodrigo) rodri.nosp@m.go.m.nosp@m.iguez.nosp@m.@rwt.nosp@m.h-aac.nosp@m.hen..nosp@m.de
Date
June 2019
Parameters
[out]verticesAfter a call to getVertices(), 'vertices' holds the vertices of the geometry element.

Definition at line 184 of file geometryelement.cpp.

184 {
185 TRACE();
186
187 IF_CONSTEXPR(nDim == 2) {
188 // Copy vertices information to vectors
189 vertices[0] = m_vertices[0][0];
190 vertices[1] = m_vertices[0][1];
191 vertices[2] = m_vertices[1][0];
192 vertices[3] = m_vertices[1][1];
193 }
194 else IF_CONSTEXPR(nDim == 3) {
195 // Copy vertices information to vectors
196 vertices[0] = m_vertices[0][0];
197 vertices[1] = m_vertices[0][1];
198 vertices[2] = m_vertices[0][2];
199 vertices[3] = m_vertices[1][0];
200 vertices[4] = m_vertices[1][1];
201 vertices[5] = m_vertices[1][2];
202 vertices[6] = m_vertices[2][0];
203 vertices[7] = m_vertices[2][1];
204 vertices[8] = m_vertices[2][2];
205 }
206}

◆ init()

template<MInt nDim>
static void GeometryElement< nDim >::init ( MInt   NotUseddimensions,
MInt  ,
MInt   
)
inlinestatic

Definition at line 38 of file geometryelement.h.

38 {
39 // TRACE();
40 };

◆ staticElementSize()

template<MInt nDim>
static MInt GeometryElement< nDim >::staticElementSize ( )
inlinestatic

Definition at line 42 of file geometryelement.h.

42{ return (nDim + 3) * nDim * sizeof(MFloat) + sizeof(MFloat*) * nDim; }

◆ writeElement()

template<MInt nDim>
void GeometryElement< nDim >::writeElement

Definition at line 63 of file geometryelement.cpp.

63 {
64 TRACE();
65
66 cerr.precision(10);
67 cerr << "------------------------------" << endl;
68 // M_Normal vector only in 3D (for now)
69 IF_CONSTEXPR(nDim == 3) { cerr << "M_Normal : " << m_normal[0] << " " << m_normal[1] << " " << m_normal[2] << endl; }
70
71 for(MInt i = 0; i < nDim; i++) {
72 cerr << "Vertex " << i << ": ";
73 for(MInt j = 0; j < nDim; j++) {
74 cerr << m_vertices[i][j] << " ";
75 }
76 cerr << endl;
77 }
78 cerr << "Bounding box: " << endl << "m_min: ";
79
80 for(MInt i = 0; i < nDim; i++) {
81 cerr << m_minMax[i] << " ";
82 }
83 cerr << endl;
84 cerr << "Bounding box: " << endl << "m_max: ";
85
86 for(MInt i = 0; i < nDim; i++) {
87 cerr << m_minMax[i + nDim] << " ";
88 }
89 cerr << endl;
90}

Member Data Documentation

◆ m_bndCndId

template<MInt nDim>
MInt GeometryElement< nDim >::m_bndCndId

Definition at line 23 of file geometryelement.h.

◆ m_minMax

template<MInt nDim>
MFloat* GeometryElement< nDim >::m_minMax

Definition at line 29 of file geometryelement.h.

◆ m_normal

template<MInt nDim>
MFloat* GeometryElement< nDim >::m_normal

Definition at line 26 of file geometryelement.h.

◆ m_originalId

template<MInt nDim>
MInt GeometryElement< nDim >::m_originalId

Definition at line 24 of file geometryelement.h.

◆ m_segmentId

template<MInt nDim>
MInt GeometryElement< nDim >::m_segmentId

Definition at line 22 of file geometryelement.h.

◆ m_vertices

template<MInt nDim>
MFloat** GeometryElement< nDim >::m_vertices

Definition at line 25 of file geometryelement.h.


The documentation for this class was generated from the following files: