BELFEM 0.9.4
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
cl_TensorMeshConfig.hpp
Go to the documentation of this file.
1/*
2 * BELFEM -- The Berkeley Lab Finite Element Framework
3 * Copyright (c) 2026, The Regents of the University of California,
4 * through Lawrence Berkeley National Laboratory (subject to receipt of any required
5 * approvals from the U.S. Dept. of Energy). All rights reserved.
6 *
7 * Developers: Christian Messe, Gregory Giard
8 *
9 * See the top-level LICENSE file for the complete license and disclaimer.
10 */
11
12#ifndef BELFEM_CL_TENSORMESHCONFIG_HPP
13#define BELFEM_CL_TENSORMESHCONFIG_HPP
14
15#include <algorithm>
16#include <cmath>
17
18#include "typedefs.hpp"
19#include "cl_Vector.hpp"
20#include "Mesh_Enums.hpp"
21
22namespace belfem
23{
25 {
26
27 const uint mOrder ;
28 const uint mDimension ;
29 const Vector< index_t > mNumNodesPerDim ;
30 const Vector< real > mNodeSteps ;
31 const Vector< real > mOrigin ;
32 const Vector< index_t > mNumElementsPerDim ;
33 const Vector< index_t > mNumControlPointsPerDim ;
34
35 const Vector< real > mLimit ;
36 const Vector< real > mElementSteps ;
37 const Vector< real > mInvElementSteps ;
38 const uint mNumNodes ;
39 const uint mNumElements ;
40 const uint mNumControlPoints ;
41
42 const ElementType mElementType ;
43 public:
44
46 const uint aOrder,
47 const Vector< index_t > & aNumNodes,
48 const Vector< real > & aStep,
49 const Vector< real > aOrigin = {} );
50
51 ~TensorMeshConfig() = default;
52
53 uint order() const
54 {
55 return mOrder ;
56 }
57
59 {
60 return mDimension ;
61 }
62
64 {
65 return mNumNodesPerDim ;
66 }
67
69 {
70 return mNumElementsPerDim ;
71 }
72
73 const Vector< real > & step() const
74 {
75 return mNodeSteps ;
76 }
77
78 const Vector< real > & origin() const
79 {
80 return mOrigin ;
81 }
82
83 const Vector< real > & limit() const
84 {
85 return mLimit ;
86 }
87
88 uint
89 num_elements( const uint aDimension = BELFEM_UINT_MAX ) const
90 {
91 switch ( aDimension )
92 {
93 case 0 : return mNumElementsPerDim( 0 ) ;
94 case 1 : return mNumElementsPerDim( 1 ) ;
95 case 2 :
96 {
97 BELFEM_ERROR( mDimension == 3, "Invalid dimension : %u", ( unsigned int ) aDimension );
98 return mNumElementsPerDim( 2 ) ;
99 }
100 default : return mNumElements ;
101 }
102 }
103
104 uint
105 num_nodes( const uint aDimension = BELFEM_UINT_MAX ) const
106 {
107 switch ( aDimension )
108 {
109 case 0 : return mNumNodesPerDim( 0 ) ;
110 case 1 : return mNumNodesPerDim( 1 ) ;
111 case 2 :
112 {
113 BELFEM_ERROR( mDimension == 3,
114 "Invalid dimension : %u", ( unsigned int ) aDimension );
115 return mNumNodesPerDim( 2 ) ;
116 }
117 default : return mNumNodes ;
118 }
119 }
120
122 {
123 return mElementType ;
124 }
125
126 uint
127 num_control_points( const uint aDimension = BELFEM_UINT_MAX ) const
128 {
129 switch ( aDimension )
130 {
131 case 0 : return mNumControlPointsPerDim( 0 ) ;
132 case 1 : return mNumControlPointsPerDim( 1 ) ;
133 case 2 :
134 {
135 BELFEM_ERROR( mDimension == 3,
136 "Invalid dimension : %u", ( unsigned int ) aDimension );
137 return mNumControlPointsPerDim( 2 ) ;
138 }
139 default : return mNumControlPoints ;
140 }
141 }
142
143 real
144 min( const uint aDimension ) const
145 {
146 BELFEM_ASSERT( aDimension < mDimension, "Invalid dimension : %u", ( unsigned int ) aDimension );
147 return mOrigin( aDimension );
148 }
149
150 real
151 max( const uint aDimension ) const
152 {
153 BELFEM_ASSERT( aDimension < mDimension, "Invalid dimension : %u", ( unsigned int ) aDimension );
154 return mLimit( aDimension );
155 }
156
157 index_t
158 node_index( const index_t i, const index_t j ) const
159 {
160 BELFEM_ASSERT( mDimension == 2, "Invalid dimension : %u", ( unsigned int ) mDimension );
161
162 BELFEM_ASSERT( i < mNumNodesPerDim( 0 ), "Invalid i : %u", ( unsigned int ) i );
163 BELFEM_ASSERT( j < mNumNodesPerDim( 1 ), "Invalid j : %u", ( unsigned int ) j );
164 return mNumNodesPerDim( 1 ) * i + j ;
165 }
166
167 index_t
168 node_index( const index_t i, const index_t j, const index_t k ) const
169 {
170 BELFEM_ASSERT( mDimension == 3, "Invalid dimension : %u", ( unsigned int ) mDimension );
171 BELFEM_ASSERT( i < mNumNodesPerDim( 0 ), "Invalid i : %u", ( unsigned int ) i );
172 BELFEM_ASSERT( j < mNumNodesPerDim( 1 ), "Invalid j : %u", ( unsigned int ) j );
173 BELFEM_ASSERT( k < mNumNodesPerDim( 2 ), "Invalid k : %u", ( unsigned int ) k );
174 return mNumNodesPerDim( 2 ) * ( mNumNodesPerDim( 1 )*i + j ) + k ;
175 }
176
177 index_t
178 element_index( const index_t i, const index_t j ) const
179 {
180 BELFEM_ASSERT( mDimension == 2, "Invalid dimension : %u", ( unsigned int ) mDimension );
181 BELFEM_ASSERT( i < mNumElementsPerDim( 0 ), "Invalid i : %u", ( unsigned int ) i );
182 BELFEM_ASSERT( j < mNumElementsPerDim( 1 ), "Invalid j : %u", ( unsigned int ) j );
183 return mNumElementsPerDim( 1 ) * i + j ;
184 }
185
186 index_t
187 element_index( const index_t i, const index_t j, const index_t k ) const
188 {
189 BELFEM_ASSERT( mDimension == 3, "Invalid dimension : %u", ( unsigned int ) mDimension );
190 BELFEM_ASSERT( i < mNumElementsPerDim( 0 ), "Invalid i : %u", ( unsigned int ) i );
191 BELFEM_ASSERT( j < mNumElementsPerDim( 1 ), "Invalid j : %u", ( unsigned int ) j );
192 BELFEM_ASSERT( k < mNumElementsPerDim( 2 ), "Invalid k : %u", ( unsigned int ) k );
193 return mNumElementsPerDim( 2 ) * ( mNumElementsPerDim( 1 ) * i + j ) + k ;
194 }
195
196 real
197 element_step( const uint aDimension ) const
198 {
199 BELFEM_ASSERT( aDimension < mDimension, "Invalid dimension : %u", ( unsigned int ) aDimension );
200 return mElementSteps( aDimension );
201 }
202
203 real
204 inv_element_step( const uint aDimension ) const
205 {
206 BELFEM_ASSERT( aDimension < mDimension, "Invalid dimension : %u", ( unsigned int ) aDimension );
207 return mInvElementSteps( aDimension );
208 }
209
210 index_t
211 element_ijk( const index_t i, const real x )
212 {
213 BELFEM_ASSERT( i < mDimension, "Invalid dimension : %u", ( unsigned int ) i );
214 BELFEM_ASSERT( ! std::isnan( x ), "coordinate is NaN" );
215
216 // clamped as a real: converting a value that does not fit in
217 // index_t, such as one element or more below the origin, is
218 // undefined. The first test also sends NaN to element 0, which
219 // std::clamp would pass through
220 const real tS = std::floor( ( x - mOrigin( i ) ) * mInvElementSteps( i ) );
221 if ( ! ( tS > 0.0 ) )
222 {
223 return 0 ;
224 }
225 return ( index_t ) std::min( tS, ( real ) ( mNumElementsPerDim( i ) - 1 ) );
226 }
227 private:
228
230 compute_num_elements_per_dim() const ;
231
233 compute_num_control_points_per_dim() const ;
234
236 compute_limit() const ;
237
238 index_t
239 compute_num_nodes() const ;
240
241 index_t
242 compute_num_elements() const ;
243
244 index_t
245 compute_num_control_point() const ;
246
248 determine_element_type() const ;
249
251 compute_element_steps() const ;
252
254 compute_inv_element_steps() const ;
255 };
256
257}
258#endif //BELFEM_CL_TENSORMESHCONFIG_HPP
#define BELFEM_ERROR(aCheck,...)
Definition assert.hpp:264
#define BELFEM_ASSERT(aCheck,...)
Definition assert.hpp:244
ElementType element_type() const
Definition cl_TensorMeshConfig.hpp:121
real element_step(const uint aDimension) const
Definition cl_TensorMeshConfig.hpp:197
uint num_control_points(const uint aDimension=BELFEM_UINT_MAX) const
Definition cl_TensorMeshConfig.hpp:127
const Vector< index_t > & num_elements_vector() const
Definition cl_TensorMeshConfig.hpp:68
index_t node_index(const index_t i, const index_t j) const
Definition cl_TensorMeshConfig.hpp:158
real inv_element_step(const uint aDimension) const
Definition cl_TensorMeshConfig.hpp:204
real min(const uint aDimension) const
Definition cl_TensorMeshConfig.hpp:144
uint num_elements(const uint aDimension=BELFEM_UINT_MAX) const
Definition cl_TensorMeshConfig.hpp:89
real max(const uint aDimension) const
Definition cl_TensorMeshConfig.hpp:151
TensorMeshConfig(const uint aOrder, const Vector< index_t > &aNumNodes, const Vector< real > &aStep, const Vector< real > aOrigin={})
Definition cl_TensorMeshConfig.cpp:17
uint order() const
Definition cl_TensorMeshConfig.hpp:53
const Vector< real > & origin() const
Definition cl_TensorMeshConfig.hpp:78
const Vector< index_t > & num_nodes_vector() const
Definition cl_TensorMeshConfig.hpp:63
index_t element_ijk(const index_t i, const real x)
Definition cl_TensorMeshConfig.hpp:211
index_t element_index(const index_t i, const index_t j, const index_t k) const
Definition cl_TensorMeshConfig.hpp:187
index_t node_index(const index_t i, const index_t j, const index_t k) const
Definition cl_TensorMeshConfig.hpp:168
uint num_nodes(const uint aDimension=BELFEM_UINT_MAX) const
Definition cl_TensorMeshConfig.hpp:105
const Vector< real > & step() const
Definition cl_TensorMeshConfig.hpp:73
const Vector< real > & limit() const
Definition cl_TensorMeshConfig.hpp:83
index_t element_index(const index_t i, const index_t j) const
Definition cl_TensorMeshConfig.hpp:178
uint dimension() const
Definition cl_TensorMeshConfig.hpp:58
USER GUIDES:
Definition cl_Capacitor.cpp:16
unsigned int uint
Definition typedefs.hpp:30
ElementType
Element types.
Definition Mesh_Enums.hpp:27
uint32_t index_t
Definition typedefs.hpp:52
double real
Definition typedefs.hpp:36
#define BELFEM_UINT_MAX
Definition typedefs.hpp:79