BELFEM 0.9.0
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 "typedefs.hpp"
16#include "cl_Vector.hpp"
17#include "Mesh_Enums.hpp"
18
19namespace belfem
20{
22 {
23
24 const uint mOrder ;
25 const uint mDimension ;
26 const Vector< index_t > mNumNodesPerDim ;
27 const Vector< real > mNodeSteps ;
28 const Vector< real > mOrigin ;
29 const Vector< index_t > mNumElementsPerDim ;
30 const Vector< index_t > mNumControlPointsPerDim ;
31
32 const Vector< real > mLimit ;
33 const Vector< real > mElementSteps ;
34 const Vector< real > mInvElementSteps ;
35 const uint mNumNodes ;
36 const uint mNumElements ;
37 const uint mNumControlPoints ;
38
39 const ElementType mElementType ;
40 public:
41
43 const uint aOrder,
44 const Vector< index_t > & aNumNodes,
45 const Vector< real > & aStep,
46 const Vector< real > aOrigin = {} );
47
48 ~TensorMeshConfig() = default;
49
50 uint order() const
51 {
52 return mOrder ;
53 }
54
56 {
57 return mDimension ;
58 }
59
61 {
62 return mNumNodesPerDim ;
63 }
64
66 {
67 return mNumElementsPerDim ;
68 }
69
70 const Vector< real > & step() const
71 {
72 return mNodeSteps ;
73 }
74
75 const Vector< real > & origin() const
76 {
77 return mOrigin ;
78 }
79
80 const Vector< real > & limit() const
81 {
82 return mLimit ;
83 }
84
85 uint
86 num_elements( const uint aDimension = BELFEM_UINT_MAX ) const
87 {
88 switch ( aDimension )
89 {
90 case 0 : return mNumElementsPerDim( 0 ) ;
91 case 1 : return mNumElementsPerDim( 1 ) ;
92 case 2 :
93 {
94 BELFEM_ERROR( mDimension == 3, "Invalid dimension : %u", ( unsigned int ) aDimension );
95 return mNumElementsPerDim( 2 ) ;
96 }
97 default : return mNumElements ;
98 }
99 }
100
101 uint
102 num_nodes( const uint aDimension = BELFEM_UINT_MAX ) const
103 {
104 switch ( aDimension )
105 {
106 case 0 : return mNumNodesPerDim( 0 ) ;
107 case 1 : return mNumNodesPerDim( 1 ) ;
108 case 2 :
109 {
110 BELFEM_ERROR( mDimension == 3,
111 "Invalid dimension : %u", ( unsigned int ) aDimension );
112 return mNumNodesPerDim( 2 ) ;
113 }
114 default : return mNumNodes ;
115 }
116 }
117
119 {
120 return mElementType ;
121 }
122
123 uint
124 num_control_points( const uint aDimension = BELFEM_UINT_MAX ) const
125 {
126 switch ( aDimension )
127 {
128 case 0 : return mNumControlPointsPerDim( 0 ) ;
129 case 1 : return mNumControlPointsPerDim( 1 ) ;
130 case 2 :
131 {
132 BELFEM_ERROR( mDimension == 3,
133 "Invalid dimension : %u", ( unsigned int ) aDimension );
134 return mNumControlPointsPerDim( 2 ) ;
135 }
136 default : return mNumControlPoints ;
137 }
138 }
139
140 real
141 min( const uint aDimension ) const
142 {
143 BELFEM_ASSERT( aDimension < mDimension, "Invalid dimension : %u", ( unsigned int ) aDimension );
144 return mOrigin( aDimension );
145 }
146
147 real
148 max( const uint aDimension ) const
149 {
150 BELFEM_ASSERT( aDimension < mDimension, "Invalid dimension : %u", ( unsigned int ) aDimension );
151 return mLimit( aDimension );
152 }
153
154 index_t
155 node_index( const index_t i, const index_t j ) const
156 {
157 BELFEM_ASSERT( mDimension == 2, "Invalid dimension : %u", ( unsigned int ) mDimension );
158
159 BELFEM_ASSERT( i < mNumNodesPerDim( 0 ), "Invalid i : %u", ( unsigned int ) i );
160 BELFEM_ASSERT( j < mNumNodesPerDim( 1 ), "Invalid j : %u", ( unsigned int ) j );
161 return mNumNodesPerDim( 1 ) * i + j ;
162 }
163
164 index_t
165 node_index( const index_t i, const index_t j, const index_t k ) const
166 {
167 BELFEM_ASSERT( mDimension == 3, "Invalid dimension : %u", ( unsigned int ) mDimension );
168 BELFEM_ASSERT( i < mNumNodesPerDim( 0 ), "Invalid i : %u", ( unsigned int ) i );
169 BELFEM_ASSERT( j < mNumNodesPerDim( 1 ), "Invalid j : %u", ( unsigned int ) j );
170 BELFEM_ASSERT( k < mNumNodesPerDim( 2 ), "Invalid k : %u", ( unsigned int ) k );
171 return mNumNodesPerDim( 2 ) * ( mNumNodesPerDim( 1 )*i + j ) + k ;
172 }
173
174 index_t
175 element_index( const index_t i, const index_t j ) const
176 {
177 BELFEM_ASSERT( mDimension == 2, "Invalid dimension : %u", ( unsigned int ) mDimension );
178 BELFEM_ASSERT( i < mNumElementsPerDim( 0 ), "Invalid i : %u", ( unsigned int ) i );
179 BELFEM_ASSERT( j < mNumElementsPerDim( 1 ), "Invalid j : %u", ( unsigned int ) j );
180 return mNumElementsPerDim( 1 ) * i + j ;
181 }
182
183 index_t
184 element_index( const index_t i, const index_t j, const index_t k ) const
185 {
186 BELFEM_ASSERT( mDimension == 3, "Invalid dimension : %u", ( unsigned int ) mDimension );
187 BELFEM_ASSERT( i < mNumElementsPerDim( 0 ), "Invalid i : %u", ( unsigned int ) i );
188 BELFEM_ASSERT( j < mNumElementsPerDim( 1 ), "Invalid j : %u", ( unsigned int ) j );
189 BELFEM_ASSERT( k < mNumElementsPerDim( 2 ), "Invalid k : %u", ( unsigned int ) k );
190 return mNumElementsPerDim( 2 ) * ( mNumElementsPerDim( 1 ) * i + j ) + k ;
191 }
192
193 real
194 element_step( const uint aDimension ) const
195 {
196 BELFEM_ASSERT( aDimension < mDimension, "Invalid dimension : %u", ( unsigned int ) aDimension );
197 return mElementSteps( aDimension );
198 }
199
200 real
201 inv_element_step( const uint aDimension ) const
202 {
203 BELFEM_ASSERT( aDimension < mDimension, "Invalid dimension : %u", ( unsigned int ) aDimension );
204 return mInvElementSteps( aDimension );
205 }
206
207 index_t
208 element_ijk( const index_t i, const real x )
209 {
210 BELFEM_ASSERT( i < mDimension, "Invalid dimension : %u", ( unsigned int ) i );
211
212 return std::clamp( ( index_t ) ( ( x - mOrigin( i ) ) * mInvElementSteps( i ) ),
213 ( index_t ) 0, mNumElementsPerDim( i ) -1);
214 }
215 private:
216
218 compute_num_elements_per_dim() const ;
219
221 compute_num_control_points_per_dim() const ;
222
224 compute_limit() const ;
225
226 index_t
227 compute_num_nodes() const ;
228
229 index_t
230 compute_num_elements() const ;
231
232 index_t
233 compute_num_control_point() const ;
234
236 determine_element_type() const ;
237
239 compute_element_steps() const ;
240
242 compute_inv_element_steps() const ;
243 };
244
245}
246#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:118
real element_step(const uint aDimension) const
Definition cl_TensorMeshConfig.hpp:194
uint num_control_points(const uint aDimension=BELFEM_UINT_MAX) const
Definition cl_TensorMeshConfig.hpp:124
const Vector< index_t > & num_elements_vector() const
Definition cl_TensorMeshConfig.hpp:65
index_t node_index(const index_t i, const index_t j) const
Definition cl_TensorMeshConfig.hpp:155
real inv_element_step(const uint aDimension) const
Definition cl_TensorMeshConfig.hpp:201
real min(const uint aDimension) const
Definition cl_TensorMeshConfig.hpp:141
uint num_elements(const uint aDimension=BELFEM_UINT_MAX) const
Definition cl_TensorMeshConfig.hpp:86
real max(const uint aDimension) const
Definition cl_TensorMeshConfig.hpp:148
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:50
const Vector< real > & origin() const
Definition cl_TensorMeshConfig.hpp:75
const Vector< index_t > & num_nodes_vector() const
Definition cl_TensorMeshConfig.hpp:60
index_t element_ijk(const index_t i, const real x)
Definition cl_TensorMeshConfig.hpp:208
index_t element_index(const index_t i, const index_t j, const index_t k) const
Definition cl_TensorMeshConfig.hpp:184
index_t node_index(const index_t i, const index_t j, const index_t k) const
Definition cl_TensorMeshConfig.hpp:165
uint num_nodes(const uint aDimension=BELFEM_UINT_MAX) const
Definition cl_TensorMeshConfig.hpp:102
const Vector< real > & step() const
Definition cl_TensorMeshConfig.hpp:70
const Vector< real > & limit() const
Definition cl_TensorMeshConfig.hpp:80
index_t element_index(const index_t i, const index_t j) const
Definition cl_TensorMeshConfig.hpp:175
uint dimension() const
Definition cl_TensorMeshConfig.hpp:55
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:80