BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
cl_Mesh_Periodicity.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, through
4 * 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_MESH_PERIODICITY_HPP
13#define BELFEM_CL_MESH_PERIODICITY_HPP
14
15#include "cl_Cell.hpp"
16#include "cl_Node.hpp"
17#include "cl_Edge.hpp"
18#include "cl_Face.hpp"
19#include "cl_SideSet.hpp"
20#include "cl_Bitset.hpp"
21
22namespace belfem
23{
24 class Mesh;
25
26
27 namespace mesh
28 {
29 class PeriodicityFactory ;
30
39 {
40 Mesh * mMesh;
41
42 // matched node pairs
43 Cell< Node * > mMasterNodes ;
44 Cell< Node * > mSlaveNodes ;
45
46 // matched edge pairs
47 Cell< Edge * > mMasterEdges ;
48 Cell< Edge * > mSlaveEdges ;
49
50 // matched face pairs
51 Cell< Face * > mMasterFaces ;
52 Cell< Face * > mSlaveFaces ;
53
54 // matched facet pairs
55 Cell< Facet * > mMasterFacets ;
56 Cell< Facet * > mSlaveFacets ;
57
58 // the three nodes that define the source plane
59 Cell< Node * > mMasterPlane ;
60
61 // the three nodes that define the target plane
62 Cell< Node * > mSlavePlane ;
63
64 // the hesse forms
65 Vector< real > mMasterHesse ;
66 Vector< real > mSlaveHesse ;
67
68 Bitset< 8 > mPopulated ;
69
70 Cell< std::pair< Node * , Node * > > mNodePairBackup ;
71
75 bool mNodePairsRestored = false ;
76 real mMaxTolerance = BELFEM_MESH_EPSILON ;
77
78 friend class PeriodicityFactory;
79
80 public:
81
82 Periodicity( Mesh * aMesh );
83
85
88
91
94
97
100
102 slave_faces();
103
106
108 slave_facets();
109
111 master_plane();
112
114 slave_plane();
115
123 void
124 update();
125
126 void
128
129 void
130 reset_nodes();
131
132 void
133 reset_edges();
134
135 void
136 reset_faces();
137
138 void
139 reset_facets();
140
141 bool
142 is_flagged( const EntityType aType ) const ;
143
144 void
146
147 void
149
150 void
152
153 void
155 Node * aNodeA,
156 Node * aNodeB,
157 const real aTolerance = BELFEM_MESH_EPSILON );
158
159 const Vector< real > &
160 master_hesse() const ;
161
162 const Vector< real > &
163 slave_hesse() const ;
164
165 bool
166 has_node_pair_backup() const;
167
168 bool
169 node_pairs_restored() const;
170
171 protected:
172
173 void
174 flag( const EntityType aType );
175
176 void
177 unflag( const EntityType aType );
178
180 master_hesse() ;
181
183 slave_hesse() ;
184
185 int
186 pair_orientation( Node * aNodeA, Node * aNodeB, const real aTolerance = BELFEM_MESH_EPSILON ) const;
187
188 };
189
190 inline Cell< Node * > &
192 {
193 return mMasterNodes ;
194 }
195
196 inline Cell< Node * > &
198 {
199 return mSlaveNodes ;
200 }
201
202 inline Cell< Edge * > &
204 {
205 return mMasterEdges ;
206 }
207
208 inline Cell< Edge * > &
210 {
211 return mSlaveEdges ;
212 }
213
214 inline Cell< Face * > &
216 {
217 return mMasterFaces ;
218 }
219
220 inline Cell< Face * > &
222 {
223 return mSlaveFaces ;
224 }
225
226 inline Cell< Facet * > &
228 {
229 return mMasterFacets ;
230 }
231
232 inline Cell< Facet * > &
234 {
235 return mSlaveFacets ;
236 }
237
238 inline Cell< Node * > &
240 {
241 return mMasterPlane ;
242 }
243
244 inline Cell< Node * > &
246 {
247 return mSlavePlane ;
248 }
249
250 inline bool
252 {
253 return mPopulated.test( static_cast< uint >( aType ) );
254 }
255
256 inline void
258 {
259 mPopulated.set( static_cast< uint >( aType ) );
260 }
261
262 inline void
264 {
265 mPopulated.reset( static_cast< uint >( aType ) );
266 }
267
268 inline Vector< real > &
270 {
271 return mMasterHesse ;
272 }
273
274 inline Vector< real > &
276 {
277 return mSlaveHesse ;
278 }
279
280 inline const Vector< real > &
282 {
283 return mMasterHesse ;
284 }
285
286 inline const Vector< real > &
288 {
289 return mSlaveHesse ;
290 }
291
292 inline
293 int
294 Periodicity::pair_orientation( Node * aNodeA, Node * aNodeB, const real aTolerance ) const
295 {
296 real tAM = std::abs( aNodeA->x() * mMasterHesse( 0 )
297 + aNodeA->y() * mMasterHesse( 1 )
298 + aNodeA->z() * mMasterHesse( 2 )
299 - mMasterHesse( 3 ) );
300
301 real tBM = std::abs( aNodeB->x() * mMasterHesse( 0 )
302 + aNodeB->y() * mMasterHesse( 1 )
303 + aNodeB->z() * mMasterHesse( 2 )
304 - mMasterHesse( 3 ) );
305
306 real tAS = std::abs( aNodeA->x() * mSlaveHesse( 0 )
307 + aNodeA->y() * mSlaveHesse( 1 )
308 + aNodeA->z() * mSlaveHesse( 2 )
309 - mSlaveHesse( 3 ) );
310
311 real tBS = std::abs( aNodeB->x() * mSlaveHesse( 0 )
312 + aNodeB->y() * mSlaveHesse( 1 )
313 + aNodeB->z() * mSlaveHesse( 2 )
314 - mSlaveHesse( 3 ) );
315
316
317 if ( tAM < aTolerance && tBS < aTolerance )
318 {
319 return 1 ;
320 }
321 if ( tAS < aTolerance && tBM < aTolerance )
322 {
323 return -1 ;
324 }
325 return 0 ;
326 }
327
328 inline bool
330 {
331 return mNodePairBackup.size() > 0 ;
332 }
333
334 inline bool
336 {
337 return mNodePairsRestored ;
338 }
339
340 }
341}
342#endif //BELFEM_CL_MESH_PERIODICITY_HPP
Cell is a wrapper around the standard vector.
Definition cl_Cell.hpp:42
Top-level container for all mesh entities.
Definition cl_Mesh.hpp:60
Definition cl_Node.hpp:30
real y() const
Definition cl_Node.hpp:191
real x() const
Definition cl_Node.hpp:183
real z() const
Definition cl_Node.hpp:199
Creates a Periodicity object by matching nodes on two periodic boundary planes.
Definition cl_Mesh_PeriodicityFactory.hpp:34
Cell< Node * > & master_nodes()
Definition cl_Mesh_Periodicity.hpp:191
bool has_node_pair_backup() const
Definition cl_Mesh_Periodicity.hpp:329
Cell< Face * > & master_faces()
Definition cl_Mesh_Periodicity.hpp:215
int pair_orientation(Node *aNodeA, Node *aNodeB, const real aTolerance=BELFEM_MESH_EPSILON) const
Definition cl_Mesh_Periodicity.hpp:294
void flag(const EntityType aType)
Definition cl_Mesh_Periodicity.hpp:257
Cell< Node * > & master_plane()
Definition cl_Mesh_Periodicity.hpp:239
Cell< Edge * > & master_edges()
Definition cl_Mesh_Periodicity.hpp:203
bool is_flagged(const EntityType aType) const
Definition cl_Mesh_Periodicity.hpp:251
Cell< Edge * > & slave_edges()
Definition cl_Mesh_Periodicity.hpp:209
const Vector< real > & master_hesse() const
Definition cl_Mesh_Periodicity.hpp:281
friend class PeriodicityFactory
Definition cl_Mesh_Periodicity.hpp:78
void reset_nodes()
Definition cl_Mesh_Periodicity.cpp:173
Cell< Facet * > & slave_facets()
Definition cl_Mesh_Periodicity.hpp:233
void unflag(const EntityType aType)
Definition cl_Mesh_Periodicity.hpp:263
void reset_facets()
Definition cl_Mesh_Periodicity.cpp:237
Cell< Facet * > & master_facets()
Definition cl_Mesh_Periodicity.hpp:227
Cell< Node * > & slave_nodes()
Definition cl_Mesh_Periodicity.hpp:197
bool node_pairs_restored() const
Definition cl_Mesh_Periodicity.hpp:335
Periodicity(Mesh *aMesh)
Definition cl_Mesh_Periodicity.cpp:22
Cell< Node * > & slave_plane()
Definition cl_Mesh_Periodicity.hpp:245
void restore_node_pairs()
Definition cl_Mesh_Periodicity.cpp:276
void clear_node_pair_backup()
Definition cl_Mesh_Periodicity.cpp:304
const Vector< real > & slave_hesse() const
Definition cl_Mesh_Periodicity.hpp:287
void reset_faces()
Definition cl_Mesh_Periodicity.cpp:216
void backup_node_pairs()
Definition cl_Mesh_Periodicity.cpp:258
Cell< Face * > & slave_faces()
Definition cl_Mesh_Periodicity.hpp:221
void update()
Re-runs the factory on this object: resets all pairs, re-collects facets and nodes,...
Definition cl_Mesh_Periodicity.cpp:38
void add_node_pair_to_backup(Node *aNodeA, Node *aNodeB, const real aTolerance=BELFEM_MESH_EPSILON)
Definition cl_Mesh_Periodicity.cpp:311
void reset_edges()
Definition cl_Mesh_Periodicity.cpp:194
void set_entity_dependencies()
Definition cl_Mesh_Periodicity.cpp:49
Definition cl_EF_EdgeFunction.hpp:17
USER GUIDES:
Definition cl_Capacitor.cpp:16
unsigned int uint
Definition typedefs.hpp:30
constexpr real BELFEM_MESH_EPSILON
Definition typedefs.hpp:92
EntityType
Definition Mesh_Enums.hpp:116
double real
Definition typedefs.hpp:36