node.h
Go to the documentation of this file.00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2012 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 00054 class Node : public Point, 00055 public DofObject, 00056 public ReferenceCountedObject<Node> 00057 { 00058 00059 public: 00060 00065 explicit 00066 Node (const Real x=0, 00067 const Real y=0, 00068 const Real z=0, 00069 const dof_id_type id = invalid_id); 00070 00074 Node (const Node& n); 00075 00079 explicit Node (const Point& p, 00080 const dof_id_type id = invalid_id); 00081 00085 ~Node (); 00086 00090 Node& operator= (const Point& p); 00091 00096 static AutoPtr<Node> build (const Node& n); 00097 00102 static AutoPtr<Node> build (const Point& p, 00103 const dof_id_type id); 00104 00109 static AutoPtr<Node> build (const Real x, 00110 const Real y, 00111 const Real z, 00112 const dof_id_type id); 00113 00120 bool active () const; 00121 00122 00126 bool operator ==(const Node& rhs) const; 00127 00131 void print_info (std::ostream& os=libMesh::out) const; 00132 00136 std::string get_info () const; 00137 00138 #ifdef LIBMESH_HAVE_MPI 00139 00147 struct PackedNode 00148 { 00149 static const unsigned int header_size = 2; 00150 00151 dof_id_type id; 00152 processor_id_type pid; 00153 Real x; 00154 // FIXME: We should drop z (and y) if libMesh is built 2D (or 1D) only 00155 Real y; 00156 Real z; 00157 00158 PackedNode () : 00159 id(0), 00160 pid(DofObject::invalid_processor_id), 00161 x(0.), 00162 y(0.), 00163 z(0.) 00164 {} 00165 00166 explicit 00167 PackedNode (const Node &node) : 00168 id(node.id()), 00169 pid(node.processor_id()), 00170 x(node(0)), 00171 #if LIBMESH_DIM > 1 00172 y(node(1)), 00173 #else 00174 y(0.), 00175 #endif 00176 #if LIBMESH_DIM > 2 00177 z(node(2)) 00178 #else 00179 z(0.) 00180 #endif 00181 {} 00182 00183 AutoPtr<Node> build_node () const 00184 { 00185 AutoPtr<Node> node(new Node(x,y,z,id)); 00186 node->processor_id() = pid; 00187 return node; 00188 } 00189 00190 Point build_point () const 00191 { 00192 return Point(x,y,z); 00193 } 00194 00195 static MPI_Datatype create_mpi_datatype (); 00196 00204 static void pack (std::vector<int> &conn, const Node* node); 00205 00206 static void unpack (std::vector<int>::const_iterator start, Node& node); 00207 }; 00208 00209 unsigned int packed_size() const 00210 { 00211 // use "(a+b-1)/b" trick to get a/b to round up 00212 static const unsigned int ints_per_Real = 00213 (sizeof(Real) + sizeof(int) - 1) / sizeof(int); 00214 00215 return PackedNode::header_size + LIBMESH_DIM*ints_per_Real + 00216 this->packed_indexing_size(); 00217 } 00218 00219 #endif // #ifdef LIBMESH_HAVE_MPI 00220 00221 private: 00222 00227 friend class MeshRefinement; 00228 friend class Elem; 00229 }; 00230 00231 00232 00233 // ------------------------------------------------------------ 00234 // global Node functions 00235 00236 inline 00237 std::ostream& operator << (std::ostream& os, const Node& n) 00238 { 00239 n.print_info(os); 00240 return os; 00241 } 00242 00243 00244 00245 //------------------------------------------------------ 00246 // Inline functions 00247 inline 00248 Node::Node (const Real x, 00249 const Real y, 00250 const Real z, 00251 const dof_id_type dofid) : 00252 Point(x,y,z) 00253 { 00254 this->set_id() = dofid; 00255 } 00256 00257 00258 00259 inline 00260 Node::Node (const Node& n) : 00261 Point(n), 00262 DofObject(n), 00263 ReferenceCountedObject<Node>() 00264 { 00265 } 00266 00267 00268 00269 inline 00270 Node::Node (const Point& p, 00271 const dof_id_type dofid) : 00272 Point(p) 00273 { 00274 // optionally assign the id. We have 00275 // to do it like this otherwise 00276 // Node n = Point p would erase 00277 // the id! 00278 if (dofid != invalid_id) 00279 this->set_id() = dofid; 00280 } 00281 00282 00283 00284 inline 00285 Node::~Node () 00286 { 00287 } 00288 00289 00290 00291 inline 00292 Node & Node::operator= (const Point& p) 00293 { 00294 (*this)(0) = p(0); 00295 #if LIBMESH_DIM > 1 00296 (*this)(1) = p(1); 00297 #endif 00298 #if LIBMESH_DIM > 2 00299 (*this)(2) = p(2); 00300 #endif 00301 00302 return *this; 00303 } 00304 00305 00306 00307 inline 00308 AutoPtr<Node> Node::build(const Node& n) 00309 { 00310 AutoPtr<Node> ap(new Node(n)); 00311 return ap; 00312 } 00313 00314 00315 00316 inline 00317 AutoPtr<Node> Node::build(const Point& p, 00318 const dof_id_type id) 00319 { 00320 00321 AutoPtr<Node> ap(new Node(p,id)); 00322 return ap; 00323 } 00324 00325 00326 00327 inline 00328 AutoPtr<Node> Node::build(const Real x, 00329 const Real y, 00330 const Real z, 00331 const dof_id_type id) 00332 { 00333 AutoPtr<Node> ap(new Node(x,y,z,id)); 00334 return ap; 00335 } 00336 00337 00338 00339 inline 00340 bool Node::active () const 00341 { 00342 return (this->id() != Node::invalid_id); 00343 } 00344 00345 00346 } // namespace libMesh 00347 00348 00349 #endif // LIBMESH_NODE_H
Site Created By: libMesh Developers
Last modified: February 05 2013 19:54:48 UTC
Hosted By: