libMesh
Loading...
Searching...
No Matches
node.h
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3
4// This library is free software; you can redistribute it and/or
5// modify it under the terms of the GNU Lesser General Public
6// License as published by the Free Software Foundation; either
7// version 2.1 of the License, or (at your option) any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// Lesser General Public License for more details.
13
14// You should have received a copy of the GNU Lesser General Public
15// License along with this library; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18
19
20#ifndef LIBMESH_NODE_H
21#define LIBMESH_NODE_H
22
23// Local includes
24#include "libmesh/point.h"
25#include "libmesh/dof_object.h"
26#include "libmesh/reference_counted_object.h"
27
28// C++ includes
29#include <iostream>
30#include <memory>
31#include <vector>
32
33namespace libMesh
34{
35
36// forward declarations
37class Node;
38class MeshBase;
39class MeshRefinement;
40
52class Node : public Point,
53 public DofObject,
54 public ReferenceCountedObject<Node>
55{
56
57public:
58
63 explicit
64 Node (const Real x=0,
65 const Real y=0,
66 const Real z=0,
67 const dof_id_type id = invalid_id);
68
76#ifdef LIBMESH_ENABLE_DEPRECATED
77 Node (const Node & n);
78#else
79 Node (const Node & n) = delete;
80#endif
81
85 explicit Node (const Point & p,
86 const dof_id_type id = invalid_id);
87
91 template <typename T,
92 typename = typename
93 std::enable_if<ScalarTraits<T>::value,void>::type>
94 explicit Node (const T x) :
95 Point (x,0,0)
96 { this->set_id() = invalid_id; }
97
102
106 Node & operator= (const Point & p);
107
115#ifdef LIBMESH_ENABLE_DEPRECATED
116 static std::unique_ptr<Node> build (const Node & n);
117#endif
118
122 static std::unique_ptr<Node> build (const Point & p,
123 const dof_id_type id);
124
129 static std::unique_ptr<Node> build (const Real x,
130 const Real y,
131 const Real z,
132 const dof_id_type id);
133
140 bool active () const;
141
142
146 bool operator ==(const Node & rhs) const;
147
151 void print_info (std::ostream & os=libMesh::out) const;
152
156 std::string get_info () const;
157
158#ifdef LIBMESH_HAVE_MPI
159 unsigned int packed_size() const
160 {
161 const unsigned int header_size = 2;
162
163 // use "(a+b-1)/b" trick to get a/b to round up
164 static const unsigned int idtypes_per_Real =
165 (sizeof(Real) + sizeof(largest_id_type) - 1) / sizeof(largest_id_type);
166
167 return header_size + LIBMESH_DIM*idtypes_per_Real +
168 this->packed_indexing_size();
169 }
170
171#endif // #ifdef LIBMESH_HAVE_MPI
172
178 unsigned int valence() const
179 {
180#ifdef LIBMESH_ENABLE_NODE_VALENCE
181 return _valence;
182#else
183 libmesh_not_implemented();
185#endif
186 }
187
191 void set_valence(unsigned int val);
192
198
199private:
200
205 friend class MeshRefinement;
206 friend class Elem;
207
208#ifdef LIBMESH_ENABLE_NODE_VALENCE
212 typedef unsigned char valence_idx_t;
213
220#endif
221};
222
223
224
225// ------------------------------------------------------------
226// Global Node functions
227
228inline
229std::ostream & operator << (std::ostream & os, const Node & n)
230{
231 n.print_info(os);
232 return os;
233}
234
235
236
237//------------------------------------------------------
238// Inline functions
239inline
241 const Real y,
242 const Real z,
243 const dof_id_type dofid) :
244 Point(x,y,z)
245#ifdef LIBMESH_ENABLE_NODE_VALENCE
246 ,
247 _valence(0)
248#endif
249{
250 this->set_id() = dofid;
251}
252
253
254#ifdef LIBMESH_ENABLE_DEPRECATED
255inline
256Node::Node (const Node & n) :
257 Point(n),
258 DofObject(), // Deliberately slicing!
260#ifdef LIBMESH_ENABLE_NODE_VALENCE
261 ,
262 _valence(0)
263#endif
264{
265 libmesh_deprecated(); // Cast to Point first!
266}
267#endif // LIBMESH_ENABLE_DEPRECATED
268
269
270
271inline
272Node::Node (const Point & p,
273 const dof_id_type dofid) :
274 Point(p)
275#ifdef LIBMESH_ENABLE_NODE_VALENCE
276 ,
277 _valence(0)
278#endif
279{
280 // optionally assign the id. We have
281 // to do it like this otherwise
282 // Node n = Point p would erase
283 // the id!
284 if (dofid != invalid_id)
285 this->set_id() = dofid;
286}
287
288
289
290inline
292{
293}
294
295
296
297inline
299{
300 (*this)(0) = p(0);
301#if LIBMESH_DIM > 1
302 (*this)(1) = p(1);
303#endif
304#if LIBMESH_DIM > 2
305 (*this)(2) = p(2);
306#endif
307
308 return *this;
309}
310
311
312
313#ifdef LIBMESH_ENABLE_DEPRECATED
314inline
315std::unique_ptr<Node> Node::build(const Node & n)
316{
317 libmesh_deprecated();
318 return std::make_unique<Node>(n);
319}
320#endif
321
322
323
324inline
325std::unique_ptr<Node> Node::build(const Point & p,
326 const dof_id_type id)
327{
328 return std::make_unique<Node>(p,id);
329}
330
331
332
333inline
334std::unique_ptr<Node> Node::build(const Real x,
335 const Real y,
336 const Real z,
337 const dof_id_type id)
338{
339 return std::make_unique<Node>(x,y,z,id);
340}
341
342
343
344inline
345bool Node::active () const
346{
347 return (this->id() != Node::invalid_id);
348}
349
350
351
352#ifdef LIBMESH_ENABLE_NODE_VALENCE
353
354inline
355void Node::set_valence (unsigned int val)
356{
357 _valence = cast_int<valence_idx_t>(val);
358}
359
360#else
361
362inline
363void Node::set_valence (unsigned int)
364{
365 libmesh_not_implemented();
366}
367
368#endif // #ifdef LIBMESH_ENABLE_NODE_VALENCE
369
370} // namespace libMesh
371
372
373#endif // LIBMESH_NODE_H
The DofObject defines an abstract base class for objects that have degrees of freedom associated with...
Definition dof_object.h:55
dof_id_type & set_id()
Definition dof_object.h:827
static constexpr dof_id_type invalid_id
An invalid id to distinguish an uninitialized DofObject.
Definition dof_object.h:473
unsigned int packed_indexing_size() const
If we pack our indices into an buffer for communications, how many ints do we need?
Definition dof_object.C:552
This is the base class from which all geometric element types are derived.
Definition elem.h:96
Implements (adaptive) mesh refinement algorithms for a MeshBase.
A Node is like a Point, but with more information.
Definition node.h:55
void print_info(std::ostream &os=libMesh::out) const
Prints relevant information about the node.
Definition node.C:45
Node(const Point &p, const dof_id_type id=invalid_id)
Copy-constructor from a Point.
void set_valence(unsigned int val)
Sets the number of nodes connected with this node.
Definition node.h:355
~Node()
Destructor.
Node(const T x)
Disambiguate constructing from non-Real scalars.
Definition node.h:94
unsigned int valence() const
Definition node.h:178
Node(const Node &n)
"Copy"-constructor: deliberately slices the source Node and only copies its' Point information,...
Node & operator=(const Point &p)
Assign to a node from a point.
Definition node.h:298
static std::unique_ptr< Node > build(const Node &n)
Definition node.h:315
unsigned char valence_idx_t
Type used to store node valence.
Definition node.h:212
Node(const Node &n)=delete
bool operator==(const Node &rhs) const
Definition node.C:37
processor_id_type choose_processor_id(processor_id_type pid1, processor_id_type pid2) const
Return which of pid1 and pid2 would be preferred by the current load-balancing heuristic applied to t...
Definition node.C:78
unsigned int packed_size() const
Definition node.h:159
valence_idx_t _valence
The number of nodes connected with this node.
Definition node.h:219
std::string get_info() const
Prints relevant information about the node to a string.
Definition node.C:53
bool active() const
Definition node.h:345
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition point.h:40
friend class Node
Make the derived class a friend.
Definition point.h:90
This class implements reference counting.
The libMesh namespace provides an interface to certain functionality in the library.
std::ostream & operator<<(std::ostream &os, const OrderWrapper &order)
Overload stream operators.
Definition fe_type.h:182
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value for an unsigned int...
Definition libmesh.h:303
OStreamProxy out
uint64_t largest_id_type
Definition id_types.h:148
uint8_t dof_id_type
Definition id_types.h:67
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
uint8_t processor_id_type
Definition id_types.h:104