libMesh
node.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 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 #include "libmesh/auto_ptr.h" // libmesh_make_unique
28 
29 // C++ includes
30 #include <iostream>
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 #endif
79 
83  explicit Node (const Point & p,
84  const dof_id_type id = invalid_id);
85 
89  template <typename T,
90  typename = typename
92  Node (const T x) :
93  Point (x,0,0)
94  { this->set_id() = invalid_id; }
95 
99  ~Node ();
100 
104  Node & operator= (const Point & p);
105 
113 #ifdef LIBMESH_ENABLE_DEPRECATED
114  static std::unique_ptr<Node> build (const Node & n);
115 #endif
116 
120  static std::unique_ptr<Node> build (const Point & p,
121  const dof_id_type id);
122 
127  static std::unique_ptr<Node> build (const Real x,
128  const Real y,
129  const Real z,
130  const dof_id_type id);
131 
138  bool active () const;
139 
140 
144  bool operator ==(const Node & rhs) const;
145 
149  void print_info (std::ostream & os=libMesh::out) const;
150 
154  std::string get_info () const;
155 
156 #ifdef LIBMESH_HAVE_MPI
157  unsigned int packed_size() const
158  {
159  const unsigned int header_size = 2;
160 
161  // use "(a+b-1)/b" trick to get a/b to round up
162  static const unsigned int idtypes_per_Real =
163  (sizeof(Real) + sizeof(largest_id_type) - 1) / sizeof(largest_id_type);
164 
165  return header_size + LIBMESH_DIM*idtypes_per_Real +
166  this->packed_indexing_size();
167  }
168 
169 #endif // #ifdef LIBMESH_HAVE_MPI
170 
176  unsigned int valence() const
177  {
178 #ifdef LIBMESH_ENABLE_NODE_VALENCE
179  return _valence;
180 #else
181  libmesh_not_implemented();
182  return libMesh::invalid_uint;
183 #endif
184  }
185 
189  void set_valence(unsigned int val);
190 
196 
197 private:
198 
203  friend class MeshRefinement;
204  friend class Elem;
205 
206 #ifdef LIBMESH_ENABLE_NODE_VALENCE
207 
210  typedef unsigned char valence_idx_t;
211 
218 #endif
219 };
220 
221 
222 
223 // ------------------------------------------------------------
224 // Global Node functions
225 
226 inline
227 std::ostream & operator << (std::ostream & os, const Node & n)
228 {
229  n.print_info(os);
230  return os;
231 }
232 
233 
234 
235 //------------------------------------------------------
236 // Inline functions
237 inline
238 Node::Node (const Real x,
239  const Real y,
240  const Real z,
241  const dof_id_type dofid) :
242  Point(x,y,z)
243 #ifdef LIBMESH_ENABLE_NODE_VALENCE
244  ,
245  _valence(0)
246 #endif
247 {
248  this->set_id() = dofid;
249 }
250 
251 
252 
253 #ifdef LIBMESH_ENABLE_DEPRECATED
254 inline
255 Node::Node (const Node & n) :
256  Point(n),
257  DofObject(n),
259 #ifdef LIBMESH_ENABLE_NODE_VALENCE
260  ,
261  _valence(n._valence)
262 #endif
263 {
264  libmesh_deprecated();
265 }
266 #endif
267 
268 
269 
270 inline
271 Node::Node (const Point & p,
272  const dof_id_type dofid) :
273  Point(p)
274 #ifdef LIBMESH_ENABLE_NODE_VALENCE
275  ,
276  _valence(0)
277 #endif
278 {
279  // optionally assign the id. We have
280  // to do it like this otherwise
281  // Node n = Point p would erase
282  // the id!
283  if (dofid != invalid_id)
284  this->set_id() = dofid;
285 }
286 
287 
288 
289 inline
290 Node::~Node ()
291 {
292 }
293 
294 
295 
296 inline
298 {
299  (*this)(0) = p(0);
300 #if LIBMESH_DIM > 1
301  (*this)(1) = p(1);
302 #endif
303 #if LIBMESH_DIM > 2
304  (*this)(2) = p(2);
305 #endif
306 
307  return *this;
308 }
309 
310 
311 
312 #ifdef LIBMESH_ENABLE_DEPRECATED
313 inline
314 std::unique_ptr<Node> Node::build(const Node & n)
315 {
316  libmesh_deprecated();
317  return libmesh_make_unique<Node>(n);
318 }
319 #endif
320 
321 
322 
323 inline
324 std::unique_ptr<Node> Node::build(const Point & p,
325  const dof_id_type id)
326 {
327  return libmesh_make_unique<Node>(p,id);
328 }
329 
330 
331 
332 inline
333 std::unique_ptr<Node> Node::build(const Real x,
334  const Real y,
335  const Real z,
336  const dof_id_type id)
337 {
338  return libmesh_make_unique<Node>(x,y,z,id);
339 }
340 
341 
342 
343 inline
344 bool Node::active () const
345 {
346  return (this->id() != Node::invalid_id);
347 }
348 
349 
350 
351 #ifdef LIBMESH_ENABLE_NODE_VALENCE
352 
353 inline
354 void Node::set_valence (unsigned int val)
355 {
356  _valence = cast_int<valence_idx_t>(val);
357 }
358 
359 #else
360 
361 inline
362 void Node::set_valence (unsigned int)
363 {
364  libmesh_not_implemented();
365 }
366 
367 #endif // #ifdef LIBMESH_ENABLE_NODE_VALENCE
368 
369 } // namespace libMesh
370 
371 
372 #endif // LIBMESH_NODE_H
libMesh::dof_id_type
uint8_t dof_id_type
Definition: id_types.h:67
libMesh::invalid_uint
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value.
Definition: libmesh.h:249
libMesh::Node::active
bool active() const
Definition: node.h:344
libMesh::Node::~Node
~Node()
Destructor.
libMesh::DofObject::set_id
dof_id_type & set_id()
Definition: dof_object.h:776
libMesh::ReferenceCountedObject
This class implements reference counting.
Definition: reference_counted_object.h:65
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::operator<<
std::ostream & operator<<(std::ostream &os, const OrderWrapper &order)
Overload stream operators.
Definition: fe_type.h:164
libMesh::Node::operator==
bool operator==(const Node &rhs) const
Definition: node.C:37
libMesh::boostcopy::enable_if_c
Definition: compare_types.h:38
libMesh::largest_id_type
uint64_t largest_id_type
Definition: id_types.h:148
libMesh::DofObject
The DofObject defines an abstract base class for objects that have degrees of freedom associated with...
Definition: dof_object.h:53
libMesh::DofObject::packed_indexing_size
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:554
libMesh::Node::valence_idx_t
unsigned char valence_idx_t
Type used to store node valence.
Definition: node.h:210
libMesh::MeshRefinement
Implements (adaptive) mesh refinement algorithms for a MeshBase.
Definition: mesh_refinement.h:61
libMesh::DofObject::invalid_id
static const dof_id_type invalid_id
An invalid id to distinguish an uninitialized DofObject.
Definition: dof_object.h:421
libMesh::Point
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
libMesh::processor_id_type
uint8_t processor_id_type
Definition: id_types.h:104
libMesh::Node::choose_processor_id
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
libMesh::Node::build
static std::unique_ptr< Node > build(const Node &n)
Definition: node.h:314
libMesh::Node
A Node is like a Point, but with more information.
Definition: node.h:52
libMesh::Node::_valence
valence_idx_t _valence
The number of nodes connected with this node.
Definition: node.h:217
libMesh::Node::print_info
void print_info(std::ostream &os=libMesh::out) const
Prints relevant information about the node.
Definition: node.C:45
libMesh::Node::valence
unsigned int valence() const
Definition: node.h:176
libMesh::Node::packed_size
unsigned int packed_size() const
Definition: node.h:157
libMesh::Node::operator=
Node & operator=(const Point &p)
Assign to a node from a point.
Definition: node.h:297
libMesh::Elem
This is the base class from which all geometric element types are derived.
Definition: elem.h:100
libMesh::Node::get_info
std::string get_info() const
Prints relevant information about the node to a string.
Definition: node.C:53
libMesh::Node::Node
Node(const T x)
Disambiguate constructing from non-Real scalars.
Definition: node.h:92
libMesh::Node::Node
Node(const Real x=0, const Real y=0, const Real z=0, const dof_id_type id=invalid_id)
Constructor.
Definition: node.h:238
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::out
OStreamProxy out
libMesh::Node::set_valence
void set_valence(unsigned int val)
Sets the number of nodes connected with this node.
Definition: node.h:354