BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
cl_Mesh_PeriodicityFactory.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_PERIODICITYFACTORY_HPP
13#define BELFEM_CL_MESH_PERIODICITYFACTORY_HPP
14
15#include "cl_Mesh.hpp"
17#include "cl_ProtoMesh.hpp"
18
19namespace belfem
20{
21 namespace mesh
22 {
34 {
35 Mesh * mMesh;
36 ProtoMesh * mProtoMesh ;
37
38 // plane equation: dot(X, N) = D, where N is row 2 of T
39 Cell< Node * > mSourcePlane ;
40 Cell< Node * > mTargetPlane ;
41
42 real mSourceDistance = BELFEM_QUIET_NAN ;
43 Matrix< real > mSourceTransform ;
44 real mTargetDistance = BELFEM_QUIET_NAN ;
45 Matrix< real > mTargetTransform ;
46
47 Vector< real > mSourceHesse ;
48 Vector< real > mTargetHesse ;
49
50 DynamicBitset * mNodeBitset = nullptr ;
51 DynamicBitset * mFaceBitset = nullptr ;
52 DynamicBitset * mEdgeBitset = nullptr ;
53
54 public:
55
56 PeriodicityFactory( Mesh * aMesh, ProtoMesh * aProtoMesh=nullptr );
57
59
60 void
61 set_master_plane( const Vector< id_t > & aPointIDs );
62
63 void
64 set_slave_plane( const Vector< id_t > & aPointIDs );
65
66 void
68
69 void
71
76 void
77 set_master_plane( const id_t A, const id_t B, const id_t C );
78
84 void
85 set_slave_plane( const id_t A, const id_t B, const id_t C );
86
89
91 to_proto( Periodicity * aPeriodicity );
92
94 from_proto( proto::PeriodicityData * aPeriodicity, const bool aCrosslinkEntities );
95
100 void
101 update_periodicity( Periodicity * aPeriodicity );
102
103 void
105
106 private:
107
108 void
109 map_facets(
110 Cell< Facet * > & aSourceFacets,
111 Cell< Facet * > & aTargetFacets );
112
113 void
114 collect_nodes(
115 Cell< Facet * > & aFacets,
116 Cell< Node * > & aNodes );
117
118 void
119 collect_edges(
120 Cell< Facet * > & aFacets,
121 Cell< Edge * > & aEdges );
122
123 bool
124 match_nodes(
125 Cell< Facet * > & aSourceFacets,
126 Cell< Facet * > & aTargetFacets,
127 Cell< Node * > & aSourceNodes,
128 Cell< Node * > & aTargetNodes );
129 bool
130 match_edges(
131 Cell< Facet * > & aSourceFacets,
132 Cell< Facet * > & aTargetFacets,
133 Cell< Node * > & aSourceNodes,
134 Cell< Edge * > & aSourceEdges,
135 Cell< Node * > & aTargetNodes,
136 Cell< Edge * > & aTargetEdges );
137
138 bool
139 match_facets_and_faces(
140 Cell< Node * > & aSourceNodes,
141 Cell< Facet * > & aSourceFacets,
142 Cell< Face * > & aSourceFaces,
143 Cell< Node * > & aTargetNodes,
144 Cell< Facet * > & aTargetFacets,
145 Cell< Face * > & aTargetFaces );
146
147 void
148 create_edge_map( Cell< Node * > & aNodes, Cell< Edge * > & aEdges, Map< key_t, Edge * > & aEdgeMap );
149
150 void
151 create_facet_map( Cell< Node * > & aNodes, Cell< Facet * > & aFaces, Map< key128_t, Facet * > & aFacetMap );
152
153 // builds orthonormal basis [P; Q; N] and plane offset D from 3 nodes
154 void
155 compute_transformation_matrix(
156 const Node * A,
157 const Node * B,
158 const Node * C,
159 real & D,
160 Matrix< real > & T,
161 Vector< real > & H );
162
163 // recursive k-d tree nearest-neighbor search (Euclidean distances)
164 Node *
165 find_closest_node( Node * aNode,
166 real aX,
167 real aY,
168 bool aFlip,
169 Node * aBest,
170 real & aBestDist );
171
172 // collects the sidesets whose nodes all sit on a given plane
173 void
174 select_sidesets(
175 const Matrix< real > & aTransform,
176 const real aDistance,
177 Cell< SideSet * > & aSideSets );
178
179 void
180 create_temporary_nodes(
181 const Matrix< real > & aTransform,
182 const real aDistance,
183 const Cell< SideSet * > & aSideSets,
184 Cell< Node * > & aNodes );
185
186 // builds 2D k-d tree from transformed node positions
187 Node *
188 create_kdtree( Cell< Node * > & aNodes );
189
190 // recursive median-based k-d tree construction, alternating x/y splits
191 Node *
192 kdsort( Cell< Node * > & aNodes, index_t aStart, index_t aEnd, const bool aFlip );
193
194 // reassigns slave faces from master to slave orientation
195 void
196 fix_face_slaves( Periodicity * aPeriodicity );
197
198 void
199 create_hesse( Cell< Node * > & aNodes , Vector< real > & aHesse );
200
201 void
202 reset_bitsets( const index_t aNumNodes, const index_t aNumEdges, const index_t aNumFaces );
203
204 void
205 crosslink( Periodicity * aPeriodicity );
206
207 template < typename T >
208 void
209 crosslink( Cell< T * > & aMaster, Cell< T * > & aSlave )
210 {
211
212 BELFEM_ASSERT( aMaster.size() == aSlave.size() , "Periodic entity sizes do not match");
213
214 index_t n = aMaster.size();
215
216 for ( index_t k=0; k<n; ++k )
217 {
218 T * A = aMaster( k );
219 T * B = aSlave( k );
220
221 if ( A != B )
222 {
223 A->set_periodic( B );
224 B->set_periodic( A );
225 }
226 }
227 }
228 };
229 }
230}
231#endif //BELFEM_CL_MESH_PeriodicityFactory_HPP
#define BELFEM_ASSERT(aCheck,...)
Definition assert.hpp:244
Cell is a wrapper around the standard vector.
Definition cl_Cell.hpp:42
size_t size() const
return the size of the Cell
Definition cl_Cell.hpp:181
Runtime-sized bitset; one bit per flag, packed into 64-bit words.
Definition cl_DynamicBitset.hpp:33
Hash map (unordered key-value).
Definition cl_Map.hpp:75
Top-level container for all mesh entities.
Definition cl_Mesh.hpp:60
Definition cl_Node.hpp:30
void tag_periodic_sidesets()
Definition cl_Mesh_PeriodicityFactory.cpp:1740
void set_master_plane(const Vector< id_t > &aPointIDs)
Definition cl_Mesh_PeriodicityFactory.cpp:46
PeriodicityFactory(Mesh *aMesh, ProtoMesh *aProtoMesh=nullptr)
Definition cl_Mesh_PeriodicityFactory.cpp:28
Periodicity * from_proto(proto::PeriodicityData *aPeriodicity, const bool aCrosslinkEntities)
Definition cl_Mesh_PeriodicityFactory.cpp:228
void update_periodicity(Periodicity *aPeriodicity)
Match nodes, then derive edge and face pairs.
Definition cl_Mesh_PeriodicityFactory.cpp:336
void set_slave_plane(const Vector< id_t > &aPointIDs)
Definition cl_Mesh_PeriodicityFactory.cpp:54
Periodicity * create_periodicity()
Definition cl_Mesh_PeriodicityFactory.cpp:126
proto::PeriodicityData * to_proto(Periodicity *aPeriodicity)
Definition cl_Mesh_PeriodicityFactory.cpp:143
Stores matched periodic boundary entity pairs (nodes, edges, faces).
Definition cl_Mesh_Periodicity.hpp:39
Definition cl_ProtoMesh.hpp:39
Definition cl_EF_EdgeFunction.hpp:17
USER GUIDES:
Definition cl_Capacitor.cpp:16
unsigned int id_t
Definition typedefs.hpp:41
uint32_t index_t
Definition typedefs.hpp:52
double real
Definition typedefs.hpp:36
Definition st_ProtoMesh.hpp:164
#define BELFEM_QUIET_NAN
Definition typedefs.hpp:87