node.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2014 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"
28 
29 // C++ includes
30 #include <iostream>
31 #include <vector>
32 
33 namespace libMesh
34 {
35 
36 
37 // forward declarations
38 class Node;
39 class MeshBase;
40 class MeshRefinement;
41 
42 
54 class Node : public Point,
55  public DofObject,
56  public ReferenceCountedObject<Node>
57 {
58 
59 public:
60 
65  explicit
66  Node (const Real x=0,
67  const Real y=0,
68  const Real z=0,
69  const dof_id_type id = invalid_id);
70 
74  Node (const Node& n);
75 
79  explicit Node (const Point& p,
80  const dof_id_type id = invalid_id);
81 
85  ~Node ();
86 
90  Node& operator= (const Point& p);
91 
96  static AutoPtr<Node> build (const Node& n);
97 
102  static AutoPtr<Node> build (const Point& p,
103  const dof_id_type id);
104 
109  static AutoPtr<Node> build (const Real x,
110  const Real y,
111  const Real z,
112  const dof_id_type id);
113 
120  bool active () const;
121 
122 
126  bool operator ==(const Node& rhs) const;
127 
131  void print_info (std::ostream& os=libMesh::out) const;
132 
136  std::string get_info () const;
137 
138 #ifdef LIBMESH_HAVE_MPI
139 
147  struct PackedNode
148  {
149  static const unsigned int header_size = 2;
150 
154 // FIXME: We should drop z (and y) if libMesh is built 2D (or 1D) only
157 
159  id(0),
161  x(0.),
162  y(0.),
163  z(0.)
164  {}
165 
166  explicit
167  PackedNode (const Node &node) :
168  id(node.id()),
169  pid(node.processor_id()),
170  x(node(0)),
171 #if LIBMESH_DIM > 1
172  y(node(1)),
173 #else
174  y(0.),
175 #endif
176 #if LIBMESH_DIM > 2
177  z(node(2))
178 #else
179  z(0.)
180 #endif
181  {}
182 
183  AutoPtr<Node> build_node () const
184  {
185  AutoPtr<Node> node(new Node(x,y,z,id));
186  node->processor_id() = pid;
187  return node;
188  }
189 
191  {
192  return Point(x,y,z);
193  }
194 
195  static MPI_Datatype create_mpi_datatype ();
196 
204  static void pack (std::vector<largest_id_type> &conn, const Node* node);
205 
206  static void unpack (std::vector<largest_id_type>::const_iterator start, Node& node);
207  };
208 
209 unsigned int packed_size() const
210 {
211  // use "(a+b-1)/b" trick to get a/b to round up
212  static const unsigned int idtypes_per_Real =
213  (sizeof(Real) + sizeof(largest_id_type) - 1) / sizeof(largest_id_type);
214 
215  return PackedNode::header_size + LIBMESH_DIM*idtypes_per_Real +
216  this->packed_indexing_size();
217 }
218 
219 #endif // #ifdef LIBMESH_HAVE_MPI
220 
221 private:
222 
227  friend class MeshRefinement;
228  friend class Elem;
229 };
230 
231 
232 
233 // ------------------------------------------------------------
234 // global Node functions
235 
236 inline
237 std::ostream& operator << (std::ostream& os, const Node& n)
238 {
239  n.print_info(os);
240  return os;
241 }
242 
243 
244 
245 //------------------------------------------------------
246 // Inline functions
247 inline
248 Node::Node (const Real x,
249  const Real y,
250  const Real z,
251  const dof_id_type dofid) :
252  Point(x,y,z)
253 {
254  this->set_id() = dofid;
255 }
256 
257 
258 
259 inline
260 Node::Node (const Node& n) :
261  Point(n),
262  DofObject(n),
264 {
265 }
266 
267 
268 
269 inline
270 Node::Node (const Point& p,
271  const dof_id_type dofid) :
272  Point(p)
273 {
274  // optionally assign the id. We have
275  // to do it like this otherwise
276  // Node n = Point p would erase
277  // the id!
278  if (dofid != invalid_id)
279  this->set_id() = dofid;
280 }
281 
282 
283 
284 inline
286 {
287 }
288 
289 
290 
291 inline
293 {
294  (*this)(0) = p(0);
295 #if LIBMESH_DIM > 1
296  (*this)(1) = p(1);
297 #endif
298 #if LIBMESH_DIM > 2
299  (*this)(2) = p(2);
300 #endif
301 
302  return *this;
303 }
304 
305 
306 
307 inline
309 {
310  AutoPtr<Node> ap(new Node(n));
311  return ap;
312 }
313 
314 
315 
316 inline
318  const dof_id_type id)
319 {
320 
321  AutoPtr<Node> ap(new Node(p,id));
322  return ap;
323 }
324 
325 
326 
327 inline
329  const Real y,
330  const Real z,
331  const dof_id_type id)
332 {
333  AutoPtr<Node> ap(new Node(x,y,z,id));
334  return ap;
335 }
336 
337 
338 
339 inline
340 bool Node::active () const
341 {
342  return (this->id() != Node::invalid_id);
343 }
344 
345 
346 } // namespace libMesh
347 
348 
349 #endif // LIBMESH_NODE_H

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:06 UTC

Hosted By:
SourceForge.net Logo