node.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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"
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  ~Node ();
90 
94  Node & operator= (const Point & p);
95 
103 #ifdef LIBMESH_ENABLE_DEPRECATED
104  static std::unique_ptr<Node> build (const Node & n);
105 #endif
106 
110  static std::unique_ptr<Node> build (const Point & p,
111  const dof_id_type id);
112 
117  static std::unique_ptr<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 
186 
187 private:
188 
193  friend class MeshRefinement;
194  friend class Elem;
195 
196 #ifdef LIBMESH_ENABLE_NODE_VALENCE
197 
200  typedef unsigned char valence_idx_t;
201 
208 #endif
209 };
210 
211 
212 
213 // ------------------------------------------------------------
214 // Global Node functions
215 
216 inline
217 std::ostream & operator << (std::ostream & os, const Node & n)
218 {
219  n.print_info(os);
220  return os;
221 }
222 
223 
224 
225 //------------------------------------------------------
226 // Inline functions
227 inline
228 Node::Node (const Real x,
229  const Real y,
230  const Real z,
231  const dof_id_type dofid) :
232  Point(x,y,z)
233 #ifdef LIBMESH_ENABLE_NODE_VALENCE
234  ,
235  _valence(0)
236 #endif
237 {
238  this->set_id() = dofid;
239 }
240 
241 
242 
243 #ifdef LIBMESH_ENABLE_DEPRECATED
244 inline
245 Node::Node (const Node & n) :
246  Point(n),
247  DofObject(n),
249 #ifdef LIBMESH_ENABLE_NODE_VALENCE
250  ,
251  _valence(n._valence)
252 #endif
253 {
254  libmesh_deprecated();
255 }
256 #endif
257 
258 
259 
260 inline
261 Node::Node (const Point & p,
262  const dof_id_type dofid) :
263  Point(p)
264 #ifdef LIBMESH_ENABLE_NODE_VALENCE
265  ,
266  _valence(0)
267 #endif
268 {
269  // optionally assign the id. We have
270  // to do it like this otherwise
271  // Node n = Point p would erase
272  // the id!
273  if (dofid != invalid_id)
274  this->set_id() = dofid;
275 }
276 
277 
278 
279 inline
280 Node::~Node ()
281 {
282 }
283 
284 
285 
286 inline
288 {
289  (*this)(0) = p(0);
290 #if LIBMESH_DIM > 1
291  (*this)(1) = p(1);
292 #endif
293 #if LIBMESH_DIM > 2
294  (*this)(2) = p(2);
295 #endif
296 
297  return *this;
298 }
299 
300 
301 
302 #ifdef LIBMESH_ENABLE_DEPRECATED
303 inline
304 std::unique_ptr<Node> Node::build(const Node & n)
305 {
306  libmesh_deprecated();
307  return libmesh_make_unique<Node>(n);
308 }
309 #endif
310 
311 
312 
313 inline
314 std::unique_ptr<Node> Node::build(const Point & p,
315  const dof_id_type id)
316 {
317  return libmesh_make_unique<Node>(p,id);
318 }
319 
320 
321 
322 inline
323 std::unique_ptr<Node> Node::build(const Real x,
324  const Real y,
325  const Real z,
326  const dof_id_type id)
327 {
328  return libmesh_make_unique<Node>(x,y,z,id);
329 }
330 
331 
332 
333 inline
334 bool Node::active () const
335 {
336  return (this->id() != Node::invalid_id);
337 }
338 
339 
340 
341 #ifdef LIBMESH_ENABLE_NODE_VALENCE
342 
343 inline
344 void Node::set_valence (unsigned int val)
345 {
346  _valence = cast_int<valence_idx_t>(val);
347 }
348 
349 #else
350 
351 inline
352 void Node::set_valence (unsigned int)
353 {
354  libmesh_not_implemented();
355 }
356 
357 #endif // #ifdef LIBMESH_ENABLE_NODE_VALENCE
358 
359 } // namespace libMesh
360 
361 
362 #endif // LIBMESH_NODE_H
A geometric point in (x,y,z) space associated with a DOF.
Definition: node.h:52
const unsigned int invalid_uint
Definition: libmesh.h:245
unsigned int packed_size() const
Definition: node.h:147
Node & operator=(const Point &p)
Definition: node.h:287
valence_idx_t _valence
Definition: node.h:207
bool active() const
Definition: node.h:334
void set_valence(unsigned int val)
Definition: node.h:344
The base class for all geometric element types.
Definition: elem.h:100
uint64_t largest_id_type
Definition: id_types.h:139
uint8_t processor_id_type
Definition: id_types.h:99
processor_id_type choose_processor_id(processor_id_type pid1, processor_id_type pid2) const
Definition: node.C:78
dof_id_type & set_id()
Definition: dof_object.h:664
unsigned char valence_idx_t
Definition: node.h:200
Node(const Real x=0, const Real y=0, const Real z=0, const dof_id_type id=invalid_id)
Definition: node.h:228
void print_info(std::ostream &os=libMesh::out) const
Definition: node.C:45
Responsible for mesh refinement algorithms and data.
dof_id_type id() const
Definition: dof_object.h:655
bool operator==(const Node &rhs) const
Definition: node.C:37
static const dof_id_type invalid_id
Definition: dof_object.h:347
unsigned int valence() const
Definition: node.h:166
static std::unique_ptr< Node > build(const Node &n)
Definition: node.h:304
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
unsigned int packed_indexing_size() const
Definition: dof_object.C:445
OStreamProxy out(std::cout)
std::ostream & operator<<(std::ostream &os, const FEAbstract &fe)
Definition: fe_abstract.C:809
A geometric point in (x,y,z) space.
Definition: point.h:38
uint8_t dof_id_type
Definition: id_types.h:64
std::string get_info() const
Definition: node.C:53