$extrastylesheet
node.h
Go to the documentation of this file.
00001 // The libMesh Finite Element Library.
00002 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
00003 
00004 // This library is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public
00006 // License as published by the Free Software Foundation; either
00007 // version 2.1 of the License, or (at your option) any later version.
00008 
00009 // This library is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // Lesser General Public License for more details.
00013 
00014 // You should have received a copy of the GNU Lesser General Public
00015 // License along with this library; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018 
00019 
00020 #ifndef LIBMESH_NODE_H
00021 #define LIBMESH_NODE_H
00022 
00023 // Local includes
00024 #include "libmesh/point.h"
00025 #include "libmesh/dof_object.h"
00026 #include "libmesh/reference_counted_object.h"
00027 #include "libmesh/auto_ptr.h"
00028 
00029 // C++ includes
00030 #include <iostream>
00031 #include <vector>
00032 
00033 namespace libMesh
00034 {
00035 
00036 
00037 // forward declarations
00038 class Node;
00039 class MeshBase;
00040 class MeshRefinement;
00041 
00042 
00053 class Node : public Point,
00054              public DofObject,
00055              public ReferenceCountedObject<Node>
00056 {
00057 
00058 public:
00059 
00064   explicit
00065   Node  (const Real x=0,
00066          const Real y=0,
00067          const Real z=0,
00068          const dof_id_type id = invalid_id);
00069 
00073   Node (const Node& n);
00074 
00078   explicit Node (const Point& p,
00079                  const dof_id_type id = invalid_id);
00080 
00084   ~Node ();
00085 
00089   Node& operator= (const Point& p);
00090 
00095   static UniquePtr<Node> build (const Node& n);
00096 
00101   static UniquePtr<Node> build (const Point& p,
00102                                 const dof_id_type id);
00103 
00108   static UniquePtr<Node> build (const Real x,
00109                                 const Real y,
00110                                 const Real z,
00111                                 const dof_id_type id);
00112 
00119   bool active () const;
00120 
00121 
00125   bool operator ==(const Node& rhs) const;
00126 
00130   void print_info (std::ostream& os=libMesh::out) const;
00131 
00135   std::string get_info () const;
00136 
00137 #ifdef LIBMESH_HAVE_MPI
00138   unsigned int packed_size() const
00139   {
00140     const unsigned int header_size = 2;
00141 
00142     // use "(a+b-1)/b" trick to get a/b to round up
00143     static const unsigned int idtypes_per_Real =
00144       (sizeof(Real) + sizeof(largest_id_type) - 1) / sizeof(largest_id_type);
00145 
00146     return header_size + LIBMESH_DIM*idtypes_per_Real +
00147       this->packed_indexing_size();
00148   }
00149 
00150 #endif // #ifdef LIBMESH_HAVE_MPI
00151 
00157   unsigned int valence() const
00158   {
00159 #ifdef LIBMESH_ENABLE_NODE_VALENCE
00160     return _valence;
00161 #else
00162     libmesh_not_implemented();
00163     return libMesh::invalid_uint;
00164 #endif
00165   }
00166 
00170   void set_valence(unsigned int val);
00171 
00172 private:
00173 
00178   friend class MeshRefinement;
00179   friend class Elem;
00180 
00181 #ifdef LIBMESH_ENABLE_NODE_VALENCE
00182 
00185   typedef unsigned char valence_idx_t;
00186 
00192   valence_idx_t _valence;
00193 #endif
00194 };
00195 
00196 
00197 
00198 // ------------------------------------------------------------
00199 // global Node functions
00200 
00201 inline
00202 std::ostream& operator << (std::ostream& os, const Node& n)
00203 {
00204   n.print_info(os);
00205   return os;
00206 }
00207 
00208 
00209 
00210 //------------------------------------------------------
00211 // Inline functions
00212 inline
00213 Node::Node (const Real x,
00214             const Real y,
00215             const Real z,
00216             const dof_id_type dofid) :
00217   Point(x,y,z)
00218 #ifdef LIBMESH_ENABLE_NODE_VALENCE
00219   ,
00220   _valence(0)
00221 #endif
00222 {
00223   this->set_id() = dofid;
00224 }
00225 
00226 
00227 
00228 inline
00229 Node::Node (const Node& n) :
00230   Point(n),
00231   DofObject(n),
00232   ReferenceCountedObject<Node>()
00233 #ifdef LIBMESH_ENABLE_NODE_VALENCE
00234   ,
00235   _valence(n._valence)
00236 #endif
00237 {
00238 }
00239 
00240 
00241 
00242 inline
00243 Node::Node (const Point& p,
00244             const dof_id_type dofid) :
00245   Point(p)
00246 #ifdef LIBMESH_ENABLE_NODE_VALENCE
00247   ,
00248   _valence(0)
00249 #endif
00250 {
00251   // optionally assign the id.  We have
00252   // to do it like this otherwise
00253   // Node n = Point p would erase
00254   // the id!
00255   if (dofid != invalid_id)
00256     this->set_id() = dofid;
00257 }
00258 
00259 
00260 
00261 inline
00262 Node::~Node ()
00263 {
00264 }
00265 
00266 
00267 
00268 inline
00269 Node & Node::operator= (const Point& p)
00270 {
00271   (*this)(0) = p(0);
00272 #if LIBMESH_DIM > 1
00273   (*this)(1) = p(1);
00274 #endif
00275 #if LIBMESH_DIM > 2
00276   (*this)(2) = p(2);
00277 #endif
00278 
00279   return *this;
00280 }
00281 
00282 
00283 
00284 inline
00285 UniquePtr<Node> Node::build(const Node& n)
00286 {
00287   return UniquePtr<Node>(new Node(n));
00288 }
00289 
00290 
00291 
00292 inline
00293 UniquePtr<Node> Node::build(const Point& p,
00294                             const dof_id_type id)
00295 {
00296   return UniquePtr<Node>(new Node(p,id));
00297 }
00298 
00299 
00300 
00301 inline
00302 UniquePtr<Node> Node::build(const Real x,
00303                             const Real y,
00304                             const Real z,
00305                             const dof_id_type id)
00306 {
00307   return UniquePtr<Node>(new Node(x,y,z,id));
00308 }
00309 
00310 
00311 
00312 inline
00313 bool Node::active () const
00314 {
00315   return (this->id() != Node::invalid_id);
00316 }
00317 
00318 
00319 
00320 #ifdef LIBMESH_ENABLE_NODE_VALENCE
00321 
00322 inline
00323 void Node::set_valence (unsigned int val)
00324 {
00325   _valence = cast_int<valence_idx_t>(val);
00326 }
00327 
00328 #else
00329 
00330 inline
00331 void Node::set_valence (unsigned int)
00332 {
00333   libmesh_not_implemented();
00334 }
00335 
00336 #endif // #ifdef LIBMESH_ENABLE_NODE_VALENCE
00337 
00338 
00339 
00340 
00341 } // namespace libMesh
00342 
00343 
00344 #endif // LIBMESH_NODE_H