BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
cl_Node.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_NODE_HPP
13#define BELFEM_CL_NODE_HPP
14
15#include "typedefs.hpp"
16#include "cl_Cell.hpp"
17#include "meshtools.hpp"
18#include "Mesh_Enums.hpp"
19
20#include "cl_Vector.hpp"
21#include "cl_Vertex.hpp"
22
23namespace belfem
24{
25//------------------------------------------------------------------------------
26
27 namespace mesh
28 {
29 class Node : public Vertex
30 {
31 // coordinates of this vector
32 real mCoords[ 3 ];
33
34 // container for duplicates
35 Node ** mDuplicates = nullptr ;
36 int mNumberOfDuplicates = 0 ;
37
38 Node * mPeriodic = nullptr ;
39
40//------------------------------------------------------------------------------
41 public:
42//------------------------------------------------------------------------------
43
44 Node( const id_t & aID,
45 const real aX=0.0,
46 const real aY=0.0,
47 const real aZ=0.0 );
48
49//------------------------------------------------------------------------------
50
51 ~Node() override;
52
53//------------------------------------------------------------------------------
54
56 entity_type() const override ;
57
58//------------------------------------------------------------------------------
59
60 real
61 x() const;
62
63//------------------------------------------------------------------------------
64
65 real
66 x( const uint aDimension ) const;
67
68//------------------------------------------------------------------------------
69
70 real
71 y() const;
72
73//------------------------------------------------------------------------------
74
75 real
76 z() const;
77
78//------------------------------------------------------------------------------
79
81 coords() const ;
82
83//------------------------------------------------------------------------------
84
88 void
89 set_coords( const Vector< real > & aCoords );
90
91 void
92 get_coords( Vector< real > & aCoords );
93
94 void
95 set_coords( const real aX, const real aY );
96
97 void
98 set_coords( const real aX, const real aY, const real & aZ );
99
100 void
101 allocate_duplicate_container( const uint aSize );
102
103 void
105
106 void
107 add_duplicate( Node * aNode );
108
109//------------------------------------------------------------------------------
110
114 uint
115 number_of_duplicates() const ;
116
117//------------------------------------------------------------------------------
118
119 bool
120 is_duplicate() const ;
121
122//------------------------------------------------------------------------------
123
127 Node *
128 duplicate( const uint aIndex );
129
130//------------------------------------------------------------------------------
131
135 Node *
136 original();
137
138 const Node *
139 original() const ;
140
141//------------------------------------------------------------------------------
142
143 void
144 set_original( Node * aNode );
145
146//------------------------------------------------------------------------------
147
148 void
150
151//------------------------------------------------------------------------------
152
153 size_t
154 memory() const ;
155
156//------------------------------------------------------------------------------
157
158 void
159 set_periodic( Node * aNode ) ;
160
161 Node *
162 periodic() ;
163
164 const Node *
165 periodic() const ;
166
167 bool
168 is_periodic() const ;
169
170//------------------------------------------------------------------------------
171 };
172//------------------------------------------------------------------------------
173
174 inline EntityType
176 {
177 return EntityType::NODE ;
178 }
179
180//------------------------------------------------------------------------------
181
182 inline real
183 Node::x() const
184 {
185 return mCoords[ 0 ];
186 }
187
188//------------------------------------------------------------------------------
189
190 inline real
191 Node::y() const
192 {
193 return mCoords[ 1 ];
194 }
195
196//------------------------------------------------------------------------------
197
198 inline real
199 Node::z() const
200 {
201 return mCoords[ 2 ];
202 }
203
204//------------------------------------------------------------------------------
205
206 inline Vector<real>
208 {
209 return Vector< real >( {mCoords[0],mCoords[1], mCoords[2]} );
210 }
211
212//------------------------------------------------------------------------------
213
214 inline real
215 Node::x( const uint aDimension ) const
216 {
217 return mCoords[ aDimension ];
218 }
219
220//------------------------------------------------------------------------------
221
225 inline uint
227 {
228 return mNumberOfDuplicates == -1 ? 0 : mNumberOfDuplicates ;
229 }
230
231//------------------------------------------------------------------------------
232
233 inline bool
235 {
236 return mNumberOfDuplicates == -1 ;
237 }
238
239//------------------------------------------------------------------------------
240
244 inline Node *
245 Node::duplicate( const uint aIndex )
246 {
247 BELFEM_ASSERT( aIndex < std::abs( mNumberOfDuplicates ) ,
248 "Duplicate Index %d for node %lu out of bounds, which must be less than %d",
249 ( int ) aIndex,
250 ( long unsigned int ) this->id(),
251 ( int ) mNumberOfDuplicates );
252
253 return mDuplicates[ aIndex ];
254 }
255
256//------------------------------------------------------------------------------
257
258 inline void
260 {
261 BELFEM_ASSERT( ! this->is_duplicate(), "Duplicates of a duplicate node are forbidden (node %lu, original: %lu )",
262 ( long unsigned int ) this->id(),( long unsigned int ) this->original()->id());
263
264
265 BELFEM_ASSERT( mNumberOfDuplicates == 0, "duplicate container of node %lu already allocated", (luint) this->id() );
266
267 if ( aSize > 0 )
268 {
269 mDuplicates = new Node * [ aSize ];
270 }
271 mNumberOfDuplicates = 0;
272 }
273
274//------------------------------------------------------------------------------
275
276 inline void
278 {
279 if( mDuplicates != nullptr )
280 {
281 delete[] mDuplicates;
282 mDuplicates = nullptr;
283 mNumberOfDuplicates = 0;
284 }
285 }
286//------------------------------------------------------------------------------
287
288 inline void
290 {
291 mDuplicates[ mNumberOfDuplicates++ ] = aNode ;
292 }
293
294//------------------------------------------------------------------------------
295
296 inline void
298 {
299 BELFEM_ASSERT( mNumberOfDuplicates == 0, "can't set original if this node has duplicates" );
300
301 mNumberOfDuplicates = -1 ;
302 mDuplicates = new Node * [ 1 ];
303 mDuplicates[ 0 ] = aNode ;
304 }
305
306 inline void
308 {
309 BELFEM_ASSERT( this->is_duplicate(), "can't unlink from original if this node is not a duplicate" );
310 mNumberOfDuplicates = 0 ;
311 delete[] mDuplicates;
312 mDuplicates = nullptr ;
313 }
314
315//------------------------------------------------------------------------------
316
317 inline Node *
319 {
320 return mNumberOfDuplicates == -1 ? mDuplicates[ 0 ] : this ;
321 }
322//------------------------------------------------------------------------------
323
324 inline const Node *
326 {
327 return mNumberOfDuplicates == -1 ? mDuplicates[ 0 ] : this ;
328 }
329
330//------------------------------------------------------------------------------
331
332 inline size_t
334 {
335 // mCoords[3] is a member array, already counted in sizeof(Node).
336 // the duplicate array holds the duplicates of an original, or the
337 // one slot a duplicate keeps for its original ( counter -1 );
338 // its capacity is not stored, this is the fill count
339 return sizeof( Node ) + this->array_memory()
340 + std::abs( mNumberOfDuplicates ) * sizeof( Node * );
341 }
342
343//------------------------------------------------------------------------------
344
345 inline void
347 {
348 mPeriodic = aNode ;
349 }
350
351 inline Node *
353 {
354 return mPeriodic ;
355 }
356
357 inline const Node *
359 {
360 return mPeriodic ;
361 }
362
363 inline bool
365 {
366 return mPeriodic != nullptr ;
367 }
368
369 inline void Node::get_coords( Vector< real > & aCoords )
370 {
371 aCoords.set_size( 3 );
372 aCoords( 0 ) = mCoords[ 0 ];
373 aCoords( 1 ) = mCoords[ 1 ];
374 aCoords( 2 ) = mCoords[ 2 ];
375 }
376
377//------------------------------------------------------------------------------
378 }
379}
380#endif //BELFEM_CL_NODE_HPP
#define BELFEM_ASSERT(aCheck,...)
Definition assert.hpp:244
Column vector.
Definition cl_BZ_Vector.hpp:41
void set_size(const size_t aNumRows)
change the size of the vector
Definition cl_AR_Vector.hpp:237
Definition cl_Node.hpp:30
void set_periodic(Node *aNode)
Definition cl_Node.hpp:346
void reset_duplicate_container()
Definition cl_Node.hpp:277
void add_duplicate(Node *aNode)
Definition cl_Node.hpp:289
EntityType entity_type() const override
returns the type of this vertex
Definition cl_Node.hpp:175
void get_coords(Vector< real > &aCoords)
Definition cl_Node.hpp:369
bool is_periodic() const
Definition cl_Node.hpp:364
size_t memory() const
Definition cl_Node.hpp:333
bool is_duplicate() const
Definition cl_Node.hpp:234
void allocate_duplicate_container(const uint aSize)
Definition cl_Node.hpp:259
void unlink_from_original()
Definition cl_Node.hpp:307
Node * periodic()
Definition cl_Node.hpp:352
real y() const
Definition cl_Node.hpp:191
Node(const id_t &aID, const real aX=0.0, const real aY=0.0, const real aZ=0.0)
Definition cl_Node.cpp:21
Node * original()
returns the original of this node
Definition cl_Node.hpp:318
real x() const
Definition cl_Node.hpp:183
uint number_of_duplicates() const
returns the number of duplicates of this node
Definition cl_Node.hpp:226
Vector< real > coords() const
Definition cl_Node.hpp:207
Node * duplicate(const uint aIndex)
returns duplicates of this node
Definition cl_Node.hpp:245
void set_coords(const Vector< real > &aCoords)
change the coordinates of this node
Definition cl_Node.cpp:48
void set_original(Node *aNode)
Definition cl_Node.hpp:297
real z() const
Definition cl_Node.hpp:199
Vertex()
Definition cl_Vertex.cpp:24
size_t array_memory() const
Definition cl_Vertex.hpp:304
Definition cl_EF_EdgeFunction.hpp:17
USER GUIDES:
Definition cl_Capacitor.cpp:16
long unsigned int luint
Definition typedefs.hpp:33
unsigned int uint
Definition typedefs.hpp:30
unsigned int id_t
Definition typedefs.hpp:41
EntityType
Definition Mesh_Enums.hpp:116
@ NODE
Definition Mesh_Enums.hpp:117
double real
Definition typedefs.hpp:36