libMesh
node.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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"
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  ~Node ();
90 
94  Node & operator= (const Point & p);
95 
103 #ifdef LIBMESH_ENABLE_DEPRECATED
104  static UniquePtr<Node> build (const Node & n);
105 #endif
106 
110  static UniquePtr<Node> build (const Point & p,
111  const dof_id_type id);
112 
117  static UniquePtr<Node> build (const Real x,
118  const Real y,
119  const Real z,
120  const dof_id_type id);
121 
128  bool active () const;
129 
130 
134  bool operator ==(const Node & rhs) const;
135 
139  void print_info (std::ostream & os=libMesh::out) const;
140 
144  std::string get_info () const;
145 
146 #ifdef LIBMESH_HAVE_MPI
147  unsigned int packed_size() const
148  {
149  const unsigned int header_size = 2;
150 
151  // use "(a+b-1)/b" trick to get a/b to round up
152  static const unsigned int idtypes_per_Real =
153  (sizeof(Real) + sizeof(largest_id_type) - 1) / sizeof(largest_id_type);
154 
155  return header_size + LIBMESH_DIM*idtypes_per_Real +
156  this->packed_indexing_size();
157  }
158 
159 #endif // #ifdef LIBMESH_HAVE_MPI
160 
166  unsigned int valence() const
167  {
168 #ifdef LIBMESH_ENABLE_NODE_VALENCE
169  return _valence;
170 #else
171  libmesh_not_implemented();
172  return libMesh::invalid_uint;
173 #endif
174  }
175 
179  void set_valence(unsigned int val);
180 
181 private:
182 
187  friend class MeshRefinement;
188  friend class Elem;
189 
190 #ifdef LIBMESH_ENABLE_NODE_VALENCE
191 
194  typedef unsigned char valence_idx_t;
195 
201  valence_idx_t _valence;
202 #endif
203 };
204 
205 
206 
207 // ------------------------------------------------------------
208 // Global Node functions
209 
210 inline
211 std::ostream & operator << (std::ostream & os, const Node & n)
212 {
213  n.print_info(os);
214  return os;
215 }
216 
217 
218 
219 //------------------------------------------------------
220 // Inline functions
221 inline
223  const Real y,
224  const Real z,
225  const dof_id_type dofid) :
226  Point(x,y,z)
227 #ifdef LIBMESH_ENABLE_NODE_VALENCE
228  ,
229  _valence(0)
230 #endif
231 {
232  this->set_id() = dofid;
233 }
234 
235 
236 
237 #ifdef LIBMESH_ENABLE_DEPRECATED
238 inline
239 Node::Node (const Node & n) :
240  Point(n),
241  DofObject(n),
243 #ifdef LIBMESH_ENABLE_NODE_VALENCE
244  ,
245  _valence(n._valence)
246 #endif
247 {
248  libmesh_deprecated();
249 }
250 #endif
251 
252 
253 
254 inline
255 Node::Node (const Point & p,
256  const dof_id_type dofid) :
257  Point(p)
258 #ifdef LIBMESH_ENABLE_NODE_VALENCE
259  ,
260  _valence(0)
261 #endif
262 {
263  // optionally assign the id. We have
264  // to do it like this otherwise
265  // Node n = Point p would erase
266  // the id!
267  if (dofid != invalid_id)
268  this->set_id() = dofid;
269 }
270 
271 
272 
273 inline
274 Node::~Node ()
275 {
276 }
277 
278 
279 
280 inline
282 {
283  (*this)(0) = p(0);
284 #if LIBMESH_DIM > 1
285  (*this)(1) = p(1);
286 #endif
287 #if LIBMESH_DIM > 2
288  (*this)(2) = p(2);
289 #endif
290 
291  return *this;
292 }
293 
294 
295 
296 #ifdef LIBMESH_ENABLE_DEPRECATED
297 inline
299 {
300  libmesh_deprecated();
301  return UniquePtr<Node>(new Node(n));
302 }
303 #endif
304 
305 
306 
307 inline
309  const dof_id_type id)
310 {
311  return UniquePtr<Node>(new Node(p,id));
312 }
313 
314 
315 
316 inline
318  const Real y,
319  const Real z,
320  const dof_id_type id)
321 {
322  return UniquePtr<Node>(new Node(x,y,z,id));
323 }
324 
325 
326 
327 inline
328 bool Node::active () const
329 {
330  return (this->id() != Node::invalid_id);
331 }
332 
333 
334 
335 #ifdef LIBMESH_ENABLE_NODE_VALENCE
336 
337 inline
338 void Node::set_valence (unsigned int val)
339 {
340  _valence = cast_int<valence_idx_t>(val);
341 }
342 
343 #else
344 
345 inline
346 void Node::set_valence (unsigned int)
347 {
348  libmesh_not_implemented();
349 }
350 
351 #endif // #ifdef LIBMESH_ENABLE_NODE_VALENCE
352 
353 
354 
355 
356 } // namespace libMesh
357 
358 
359 #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.
Definition: libmesh.h:184
std::string get_info() const
Prints relevant information about the node to a string.
Definition: node.C:53
Node & operator=(const Point &p)
Assign to a node from a point.
Definition: node.h:281
bool active() const
Definition: node.h:328
valence_idx_t _valence
The number of nodes connected with this node.
Definition: node.h:201
void print_info(std::ostream &os=libMesh::out) const
Prints relevant information about the node.
Definition: node.C:45
void set_valence(unsigned int val)
Sets the number of nodes connected with this node.
Definition: node.h:338
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
uint64_t largest_id_type
Definition: id_types.h:139
static UniquePtr< Node > build(const Node &n)
Definition: node.h:298
The libMesh namespace provides an interface to certain functionality in the library.
dof_id_type & set_id()
Definition: dof_object.h:641
unsigned char valence_idx_t
Type used to store node valence.
Definition: node.h:194
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
Node(const Real x=0, const Real y=0, const Real z=0, const dof_id_type id=invalid_id)
Constructor.
Definition: node.h:222
DofObject()
Constructor.
Definition: dof_object.h:522
Point(const Real x=0., const Real y=0., const Real z=0.)
Constructor.
Definition: point.h:46
PetscErrorCode Vec x
This is the MeshRefinement class.
static const dof_id_type invalid_id
An invalid id to distinguish an uninitialized DofObject.
Definition: dof_object.h:324
unsigned int valence() const
Definition: node.h:166
This class implements reference counting.
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:457
friend std::ostream & operator<<(std::ostream &os, const TypeVector< Real > &t)
Formatted print as above but supports the syntax:
Definition: type_vector.h:387
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
OStreamProxy out
~Node()
Destructor.
The DofObject defines an abstract base class for objects that have degrees of freedom associated with...
Definition: dof_object.h:51
unsigned int packed_size() const
Definition: node.h:147
bool operator==(const Node &rhs) const
Definition: node.C:37
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
uint8_t dof_id_type
Definition: id_types.h:64