libMesh
node.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 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 
33 namespace libMesh
34 {
35 
36 // forward declarations
37 class Node;
38 class MeshBase;
39 class MeshRefinement;
40 
52 class Node : public Point,
53  public DofObject,
54  public ReferenceCountedObject<Node>
55 {
56 
57 public:
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
94  explicit Node (const T x) :
95  Point (x,0,0)
96  { this->set_id() = invalid_id; }
97 
101  ~Node ();
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();
184  return libMesh::invalid_uint;
185 #endif
186  }
187 
191  void set_valence(unsigned int val);
192 
198 
199 private:
200 
205  friend class MeshRefinement;
206  friend class Elem;
207 
208 #ifdef LIBMESH_ENABLE_NODE_VALENCE
209 
212  typedef unsigned char valence_idx_t;
213 
220 #endif
221 };
222 
223 
224 
225 // ------------------------------------------------------------
226 // Global Node functions
227 
228 inline
229 std::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
239 inline
240 Node::Node (const Real x,
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
255 inline
256 Node::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 
271 inline
272 Node::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 
290 inline
291 Node::~Node ()
292 {
293 }
294 
295 
296 
297 inline
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
314 inline
315 std::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 
324 inline
325 std::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 
333 inline
334 std::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 
344 inline
345 bool Node::active () const
346 {
347  return (this->id() != Node::invalid_id);
348 }
349 
350 
351 
352 #ifdef LIBMESH_ENABLE_NODE_VALENCE
353 
354 inline
355 void Node::set_valence (unsigned int val)
356 {
357  _valence = cast_int<valence_idx_t>(val);
358 }
359 
360 #else
361 
362 inline
363 void 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
A Node is like a Point, but with more information.
Definition: node.h:52
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:310
unsigned int packed_size() const
Definition: node.h:159
Node(const T x)
Disambiguate constructing from non-Real scalars.
Definition: node.h:94
Node & operator=(const Point &p)
Assign to a node from a point.
Definition: node.h:298
valence_idx_t _valence
The number of nodes connected with this node.
Definition: node.h:219
bool active() const
Definition: node.h:345
void set_valence(unsigned int val)
Sets the number of nodes connected with this node.
Definition: node.h:355
This is the base class from which all geometric element types are derived.
Definition: elem.h:94
uint64_t largest_id_type
Definition: id_types.h:148
std::ostream & operator<<(std::ostream &os, const OrderWrapper &order)
Overload stream operators.
Definition: fe_type.h:182
The libMesh namespace provides an interface to certain functionality in the library.
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
uint8_t processor_id_type
Definition: id_types.h:104
dof_id_type & set_id()
Definition: dof_object.h:836
unsigned char valence_idx_t
Type used to store node valence.
Definition: node.h:212
Node(const Real x=0, const Real y=0, const Real z=0, const dof_id_type id=invalid_id)
Constructor.
Definition: node.h:240
void print_info(std::ostream &os=libMesh::out) const
Prints relevant information about the node.
Definition: node.C:45
Implements (adaptive) mesh refinement algorithms for a MeshBase.
dof_id_type id() const
Definition: dof_object.h:828
bool operator==(const Node &rhs) const
Definition: node.C:37
static const dof_id_type invalid_id
An invalid id to distinguish an uninitialized DofObject.
Definition: dof_object.h:482
unsigned int valence() const
Definition: node.h:178
This class implements reference counting.
static std::unique_ptr< Node > build(const Node &n)
Definition: node.h:315
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
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:560
OStreamProxy out
~Node()
Destructor.
The DofObject defines an abstract base class for objects that have degrees of freedom associated with...
Definition: dof_object.h:54
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
uint8_t dof_id_type
Definition: id_types.h:67
std::string get_info() const
Prints relevant information about the node to a string.
Definition: node.C:53