libMesh::Elem::PackedElem Class Reference

#include <elem.h>

List of all members.

Public Member Functions

 PackedElem (const std::vector< int >::const_iterator _buf_in)
Elemunpack (MeshBase &mesh, Elem *parent=NULL) const
unsigned int level () const
unsigned int p_level () const
Elem::RefinementState refinement_flag () const
Elem::RefinementState p_refinement_flag () const
ElemType type () const
processor_id_type processor_id () const
subdomain_id_type subdomain_id () const
dof_id_type id () const
int parent_id () const
unsigned int which_child_am_i () const
unsigned int n_nodes () const
unsigned int node (const unsigned int n) const
unsigned int n_neighbors () const
unsigned int neighbor (const unsigned int n) const
std::vector< int >::const_iterator indices () const
unsigned int packed_size () const

Static Public Member Functions

static void pack (std::vector< int > &conn, const Elem *elem)

Static Public Attributes

static const unsigned int header_size = 10

Private Attributes

const std::vector< int >
::const_iterator 
_buf_begin

Detailed Description

Convenient way to communicate elements. This class packes up an element so that it can easily be communicated through an MPI array.

Author:
Benjamin S. Kirk
Date:
2008

Definition at line 2019 of file elem.h.


Constructor & Destructor Documentation

libMesh::Elem::PackedElem::PackedElem ( const std::vector< int >::const_iterator  _buf_in  )  [inline]

Constructor. Takes an input iterator pointing to the beginning of the connectivity block for this element.

Definition at line 2034 of file elem.h.

02034                                                           :
02035     _buf_begin(_buf_in)
02036   {}


Member Function Documentation

dof_id_type libMesh::Elem::PackedElem::id (  )  const [inline]

return the id of this packed element.

Definition at line 2131 of file elem.h.

References _buf_begin.

Referenced by unpack().

02132   {
02133     return static_cast<dof_id_type>(*(_buf_begin+7));
02134   }

std::vector<int>::const_iterator libMesh::Elem::PackedElem::indices (  )  const [inline]

Definition at line 2186 of file elem.h.

References _buf_begin, header_size, n_neighbors(), and n_nodes().

Referenced by packed_size(), and unpack().

02187   {
02188     return _buf_begin + header_size + this->n_nodes() +
02189            this->n_neighbors();
02190   }

unsigned int libMesh::Elem::PackedElem::level (  )  const [inline]

return the level of this packed element.

Definition at line 2063 of file elem.h.

Referenced by unpack().

02064   {
02065     return static_cast<unsigned int>(*_buf_begin);
02066   }

unsigned int libMesh::Elem::PackedElem::n_neighbors (  )  const [inline]

return the number of neighbors of the packed element

Definition at line 2171 of file elem.h.

References type(), and libMesh::Elem::type_to_n_sides_map.

Referenced by indices(), packed_size(), and unpack().

02172   {
02173     return Elem::type_to_n_sides_map[this->type()];
02174   }

unsigned int libMesh::Elem::PackedElem::n_nodes (  )  const [inline]

return the number of nodes in this packed element

Definition at line 2155 of file elem.h.

References type(), and libMesh::Elem::type_to_n_nodes_map.

Referenced by indices(), neighbor(), packed_size(), and unpack().

02156   {
02157     return Elem::type_to_n_nodes_map[this->type()];
02158   }

unsigned int libMesh::Elem::PackedElem::neighbor ( const unsigned int  n  )  const [inline]

return the global index of the packed element's nth neighbor

Definition at line 2179 of file elem.h.

References _buf_begin, header_size, and n_nodes().

Referenced by unpack().

02180   {
02181     return static_cast<unsigned int>
02182       (*(_buf_begin + header_size + this->n_nodes() + n));
02183   }

unsigned int libMesh::Elem::PackedElem::node ( const unsigned int  n  )  const [inline]

return the global index of the packed element's nth node.

Definition at line 2163 of file elem.h.

References _buf_begin, and header_size.

Referenced by unpack().

02164   {
02165     return static_cast<unsigned int>(*(_buf_begin+header_size+n));
02166   }

unsigned int libMesh::Elem::PackedElem::p_level (  )  const [inline]

return the p-level of this packed element.

Definition at line 2071 of file elem.h.

References _buf_begin.

Referenced by unpack().

02072   {
02073     return static_cast<unsigned int>(*(_buf_begin+1));
02074   }

Elem::RefinementState libMesh::Elem::PackedElem::p_refinement_flag (  )  const [inline]

return the p-refinement state of this packed element.

Definition at line 2090 of file elem.h.

References _buf_begin, and libMesh::Elem::INVALID_REFINEMENTSTATE.

Referenced by unpack().

02091   {
02092     libmesh_assert_greater_equal (*(_buf_begin+3), 0);
02093     libmesh_assert_less (*(_buf_begin+3), INVALID_REFINEMENTSTATE);
02094     return static_cast<Elem::RefinementState>(*(_buf_begin+3));
02095   }

void libMesh::Elem::PackedElem::pack ( std::vector< int > &  conn,
const Elem elem 
) [static]

For each element the serialization is of the form [ level p_level r_flag p_r_flag etype processor_id subdomain_id self_ID parent_ID which_child node_0 node_1 ... node_n dof_object_buffer_1 ...] We cannot use unsigned int because parent_ID can be negative

Definition at line 2162 of file elem.C.

References libMesh::DofObject::id(), libMesh::Elem::level(), libMesh::Elem::n_neighbors(), libMesh::Elem::n_nodes(), libMesh::Elem::neighbor(), libMesh::Elem::node(), libMesh::Elem::p_level(), libMesh::Elem::p_refinement_flag(), libMesh::DofObject::pack_indexing(), libMesh::Elem::packed_size(), libMesh::Elem::parent(), libMesh::DofObject::processor_id(), libMesh::Elem::refinement_flag(), libMesh::Elem::subdomain_id(), libMesh::Elem::type(), and libMesh::Elem::which_child_am_i().

02163 {
02164   libmesh_assert(elem);
02165 
02166   // we can do at least this good. note that hopefully in general
02167   // the user will already have reserved the full space, which will render
02168   // this redundant
02169   conn.reserve (conn.size() + elem->packed_size());
02170 
02171 #ifdef LIBMESH_ENABLE_AMR
02172   conn.push_back (static_cast<int>(elem->level()));
02173   conn.push_back (static_cast<int>(elem->p_level()));
02174   conn.push_back (static_cast<int>(elem->refinement_flag()));
02175   conn.push_back (static_cast<int>(elem->p_refinement_flag()));
02176 #else
02177   conn.push_back (0);
02178   conn.push_back (0);
02179   conn.push_back (0);
02180   conn.push_back (0);
02181 #endif
02182   conn.push_back (static_cast<int>(elem->type()));
02183   conn.push_back (elem->processor_id());
02184   conn.push_back (elem->subdomain_id());
02185   conn.push_back (elem->id());
02186 
02187 #ifdef LIBMESH_ENABLE_AMR
02188   // use parent_ID of -1 to indicate a level 0 element
02189   if (elem->level() == 0)
02190     {
02191       conn.push_back(-1);
02192       conn.push_back(-1);
02193     }
02194   else
02195     {
02196       conn.push_back(elem->parent()->id());
02197       conn.push_back(elem->parent()->which_child_am_i(elem));
02198     }
02199 #else
02200   conn.push_back (-1);
02201   conn.push_back (-1);
02202 #endif
02203 
02204   for (unsigned int n=0; n<elem->n_nodes(); n++)
02205     conn.push_back (elem->node(n));
02206 
02207   for (unsigned int n=0; n<elem->n_neighbors(); n++)
02208     {
02209       Elem *neigh = elem->neighbor(n);
02210       if (neigh)
02211         conn.push_back (neigh->id());
02212       else
02213         conn.push_back (-1);
02214     }
02215 
02216   elem->pack_indexing(std::back_inserter(conn));
02217 }

unsigned int libMesh::Elem::PackedElem::packed_size (  )  const [inline]

Definition at line 2192 of file elem.h.

References header_size, indices(), n_neighbors(), n_nodes(), and libMesh::DofObject::unpackable_indexing_size().

02193   {
02194     return this->header_size + this->n_nodes() +
02195            this->n_neighbors() +
02196            DofObject::unpackable_indexing_size(this->indices());
02197   }

int libMesh::Elem::PackedElem::parent_id (  )  const [inline]

return the parent id of this packed element.

Definition at line 2139 of file elem.h.

References _buf_begin.

02140   {
02141     return *(_buf_begin+8);
02142   }

processor_id_type libMesh::Elem::PackedElem::processor_id (  )  const [inline]

return the processor id of this packed element.

Definition at line 2111 of file elem.h.

References _buf_begin, libMesh::DofObject::invalid_processor_id, and libMesh::n_processors().

Referenced by unpack().

02112   {
02113     libmesh_assert_greater_equal (*(_buf_begin+5), 0);
02114     libmesh_assert_less (static_cast<unsigned int>(*(_buf_begin+5)),
02115                    libMesh::n_processors() ||
02116                    static_cast<processor_id_type>(*(_buf_begin+5)) == DofObject::invalid_processor_id);
02117     return static_cast<processor_id_type>(*(_buf_begin+5));
02118   }

Elem::RefinementState libMesh::Elem::PackedElem::refinement_flag (  )  const [inline]

return the refinement state of this packed element.

Definition at line 2080 of file elem.h.

References _buf_begin, and libMesh::Elem::INVALID_REFINEMENTSTATE.

Referenced by unpack().

02081   {
02082     libmesh_assert_greater_equal (*(_buf_begin+2), 0);
02083     libmesh_assert_less (*(_buf_begin+2), INVALID_REFINEMENTSTATE);
02084     return static_cast<Elem::RefinementState>(*(_buf_begin+2));
02085   }

subdomain_id_type libMesh::Elem::PackedElem::subdomain_id (  )  const [inline]

return the subdomain id of this packed element.

Definition at line 2123 of file elem.h.

References _buf_begin.

Referenced by unpack().

02124   {
02125     return static_cast<subdomain_id_type>(*(_buf_begin+6));
02126   }

ElemType libMesh::Elem::PackedElem::type (  )  const [inline]

return the element type of this packed element.

Definition at line 2101 of file elem.h.

References _buf_begin, and libMeshEnums::INVALID_ELEM.

Referenced by n_neighbors(), n_nodes(), and unpack().

02102   {
02103     libmesh_assert_greater_equal (*(_buf_begin+4), 0);
02104     libmesh_assert_less (*(_buf_begin+4), INVALID_ELEM);
02105     return static_cast<ElemType>(*(_buf_begin+4));
02106   }

Elem * libMesh::Elem::PackedElem::unpack ( MeshBase mesh,
Elem parent = NULL 
) const

Unpacks this packed element. Returns a pointer to the new element. Takes a pointer to the parent, which is required unless this packed element is at level 0.

Definition at line 2221 of file elem.C.

References libMesh::Elem::active(), libMesh::Elem::add_child(), libMesh::Elem::build(), libMesh::Elem::child(), libMesh::Elem::family_tree_by_side(), libMesh::DofObject::id(), id(), indices(), libMesh::DofObject::invalid_id, libMesh::Elem::level(), level(), libMesh::Elem::n_children(), n_neighbors(), libMesh::Elem::n_neighbors(), n_nodes(), libMesh::Elem::n_nodes(), libMesh::Elem::n_sides(), libMesh::Elem::neighbor(), neighbor(), node(), libMesh::MeshBase::node_ptr(), p_level(), p_refinement_flag(), processor_id(), libMesh::DofObject::processor_id(), libMesh::MeshBase::query_elem(), refinement_flag(), libMesh::AutoPtr< Tp >::release(), libMesh::remote_elem, libMesh::DofObject::set_id(), libMesh::Elem::set_neighbor(), libMesh::Elem::set_node(), libMesh::Elem::set_p_level(), libMesh::Elem::set_p_refinement_flag(), libMesh::Elem::set_refinement_flag(), libMesh::Elem::side(), libMesh::Elem::subactive(), subdomain_id(), libMesh::Elem::subdomain_id(), libMesh::Elem::type(), type(), libMesh::DofObject::unpack_indexing(), and which_child_am_i().

02222 {
02223 
02224   Elem *elem = Elem::build(this->type(),parent).release();
02225   libmesh_assert (elem);
02226 
02227 #ifdef LIBMESH_ENABLE_AMR
02228   if (this->level() != 0)
02229     {
02230       libmesh_assert(parent);
02231       parent->add_child(elem, this->which_child_am_i());
02232       libmesh_assert_equal_to (parent->type(), elem->type());
02233       libmesh_assert_equal_to (parent->child(this->which_child_am_i()), elem);
02234     }
02235 #endif
02236 
02237   // Assign the refinement flags and levels
02238 #ifdef LIBMESH_ENABLE_AMR
02239   elem->set_p_level(this->p_level());
02240   elem->set_refinement_flag(this->refinement_flag());
02241   elem->set_p_refinement_flag(this->p_refinement_flag());
02242   libmesh_assert_equal_to (elem->level(), this->level());
02243 
02244   // If this element definitely should have children, assign
02245   // remote_elem for now; later unpacked elements may overwrite that.
02246   if (!elem->active())
02247     for (unsigned int c=0; c != elem->n_children(); ++c)
02248       elem->add_child(const_cast<RemoteElem*>(remote_elem), c);
02249 #endif
02250 
02251   // Assign the IDs
02252   elem->subdomain_id() = this->subdomain_id();
02253   elem->processor_id() = this->processor_id();
02254   elem->set_id()       = this->id();
02255 
02256   // Assign the connectivity
02257   libmesh_assert_equal_to (elem->n_nodes(), this->n_nodes());
02258 
02259   for (unsigned int n=0; n<elem->n_nodes(); n++)
02260     elem->set_node(n) = mesh.node_ptr (this->node(n));
02261 
02262   // Assign the connectivity
02263   libmesh_assert_equal_to (elem->n_neighbors(), this->n_neighbors());
02264 
02265   for (unsigned int n=0; n<elem->n_neighbors(); n++)
02266     {
02267       dof_id_type neighbor_id = this->neighbor(n);
02268 
02269       // We should only be unpacking elements sent by their owners,
02270       // and their owners should know all their neighbors
02271       libmesh_assert_not_equal_to (neighbor_id, remote_elem->id());
02272 
02273       if (neighbor_id == DofObject::invalid_id)
02274         continue;
02275 
02276       Elem *neigh = mesh.query_elem(neighbor_id);
02277       if (!neigh)
02278         {
02279           elem->set_neighbor(n, const_cast<RemoteElem*>(remote_elem));
02280           continue;
02281         }
02282 
02283       // We never have neighbors more refined than us
02284       libmesh_assert_less_equal (neigh->level(), elem->level());
02285 
02286       // We never have subactive neighbors of non subactive elements
02287       libmesh_assert(!neigh->subactive() || elem->subactive());
02288 
02289       // If we have a neighbor less refined than us then it must not
02290       // have any more refined active descendants we could have
02291       // pointed to instead.
02292       libmesh_assert(neigh->level() == elem->level() ||
02293                      neigh->active());
02294      
02295       elem->set_neighbor(n, neigh);
02296 
02297       // If neigh is at elem's level, then its family might have
02298       // remote_elem neighbor links which need to point to elem
02299       // instead, but if not, then we're done.
02300       if (neigh->level() != elem->level())
02301         continue;
02302       
02303       // What side of neigh is elem on?  We can't use the usual Elem
02304       // method because we haven't finished restoring topology
02305       const AutoPtr<Elem> my_side = elem->side(n);
02306       unsigned int nn = 0;
02307       for (; nn != neigh->n_sides(); ++nn)
02308         {
02309           const AutoPtr<Elem> neigh_side = neigh->side(nn);
02310           if (*my_side == *neigh_side)
02311             break;
02312         }
02313 
02314       // elem had better be on *some* side of neigh
02315       libmesh_assert_less (nn, neigh->n_sides());
02316 
02317       // Find any elements that ought to point to elem
02318       std::vector<const Elem*> neigh_family;
02319 #ifdef LIBMESH_ENABLE_AMR
02320       if (!neigh->subactive())
02321         neigh->family_tree_by_side(neigh_family, nn);
02322 #else
02323         neigh_family.push_back(neigh);
02324 #endif
02325 
02326       // And point them to elem
02327       for (unsigned int i = 0; i != neigh_family.size(); ++i)
02328         {
02329           Elem* neigh_family_member = const_cast<Elem*>(neigh_family[i]);
02330 
02331           // The neighbor link ought to either be correct already or
02332           // ought to be to remote_elem
02333           libmesh_assert(neigh_family_member->neighbor(nn) == elem ||
02334                          neigh_family_member->neighbor(nn) == remote_elem);
02335 
02336           neigh_family_member->set_neighbor(nn, elem);
02337         }
02338     }
02339 
02340   elem->unpack_indexing(this->indices());
02341 
02342   return elem;
02343 }

unsigned int libMesh::Elem::PackedElem::which_child_am_i (  )  const [inline]

return which child this packed element is.

Definition at line 2147 of file elem.h.

References _buf_begin.

Referenced by unpack().

02148   {
02149     return static_cast<unsigned int>(*(_buf_begin+9));
02150   }


Member Data Documentation

const std::vector<int>::const_iterator libMesh::Elem::PackedElem::_buf_begin [private]

Iterator pointing to the beginning of this packed element's index buffer.

Definition at line 2026 of file elem.h.

Referenced by id(), indices(), neighbor(), node(), p_level(), p_refinement_flag(), parent_id(), processor_id(), refinement_flag(), subdomain_id(), type(), and which_child_am_i().

const unsigned int libMesh::Elem::PackedElem::header_size = 10 [static]

An Elem can be packed into an integer array which is header_size + elem->n_nodes() in length.

Definition at line 2042 of file elem.h.

Referenced by indices(), neighbor(), node(), libMesh::Elem::packed_size(), and packed_size().


The documentation for this class was generated from the following files:

Site Created By: libMesh Developers
Last modified: February 05 2013 19:55:17 UTC

Hosted By:
SourceForge.net Logo