libMesh::Elem::PackedElem Class Reference

#include <elem.h>

Public Member Functions

 PackedElem (const std::vector< largest_id_type >::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< largest_id_type >
::const_iterator 
indices () const
 
unsigned int packed_size () const
 

Static Public Member Functions

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

Static Public Attributes

static const unsigned int header_size = 10
 

Private Attributes

const std::vector
< largest_id_type >
::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 2034 of file elem.h.

Constructor & Destructor Documentation

libMesh::Elem::PackedElem::PackedElem ( const std::vector< largest_id_type >::const_iterator  _buf_in)
inline

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

Definition at line 2049 of file elem.h.

2049  :
2050  _buf_begin(_buf_in)
2051  {}

Member Function Documentation

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

return the id of this packed element.

Definition at line 2146 of file elem.h.

References _buf_begin.

2147  {
2148  return static_cast<dof_id_type>(*(_buf_begin+7));
2149  }
std::vector<largest_id_type>::const_iterator libMesh::Elem::PackedElem::indices ( ) const
inline

Definition at line 2201 of file elem.h.

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

Referenced by packed_size().

2202  {
2203  return _buf_begin + header_size + this->n_nodes() +
2204  this->n_neighbors();
2205  }
unsigned int libMesh::Elem::PackedElem::level ( ) const
inline

return the level of this packed element.

Definition at line 2078 of file elem.h.

2079  {
2080  return static_cast<unsigned int>(*_buf_begin);
2081  }
unsigned int libMesh::Elem::PackedElem::n_neighbors ( ) const
inline

return the number of neighbors of the packed element

Definition at line 2186 of file elem.h.

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

Referenced by indices(), and packed_size().

2187  {
2188  return Elem::type_to_n_sides_map[this->type()];
2189  }
unsigned int libMesh::Elem::PackedElem::n_nodes ( ) const
inline

return the number of nodes in this packed element

Definition at line 2170 of file elem.h.

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

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

2171  {
2172  return Elem::type_to_n_nodes_map[this->type()];
2173  }
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 2194 of file elem.h.

References _buf_begin, header_size, and n_nodes().

2195  {
2196  return static_cast<unsigned int>
2197  (*(_buf_begin + header_size + this->n_nodes() + n));
2198  }
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 2178 of file elem.h.

References _buf_begin, and header_size.

2179  {
2180  return static_cast<unsigned int>(*(_buf_begin+header_size+n));
2181  }
unsigned int libMesh::Elem::PackedElem::p_level ( ) const
inline

return the p-level of this packed element.

Definition at line 2086 of file elem.h.

References _buf_begin.

2087  {
2088  return static_cast<unsigned int>(*(_buf_begin+1));
2089  }
Elem::RefinementState libMesh::Elem::PackedElem::p_refinement_flag ( ) const
inline

return the p-refinement state of this packed element.

Definition at line 2105 of file elem.h.

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

2106  {
2107  // libmesh_assert_greater_equal (*(_buf_begin+3), 0);
2108  libmesh_assert_less (*(_buf_begin+3), INVALID_REFINEMENTSTATE);
2109  return static_cast<Elem::RefinementState>(*(_buf_begin+3));
2110  }
void libMesh::Elem::PackedElem::pack ( std::vector< largest_id_type > &  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 2227 of file elem.C.

References libMesh::DofObject::id(), libMesh::Elem::level(), libMesh::libmesh_assert(), 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().

2228 {
2229  libmesh_assert(elem);
2230 
2231  // we can do at least this good. note that hopefully in general
2232  // the user will already have reserved the full space, which will render
2233  // this redundant
2234  conn.reserve (conn.size() + elem->packed_size());
2235 
2236 #ifdef LIBMESH_ENABLE_AMR
2237  conn.push_back (static_cast<largest_id_type>(elem->level()));
2238  conn.push_back (static_cast<largest_id_type>(elem->p_level()));
2239  conn.push_back (static_cast<largest_id_type>(elem->refinement_flag()));
2240  conn.push_back (static_cast<largest_id_type>(elem->p_refinement_flag()));
2241 #else
2242  conn.push_back (0);
2243  conn.push_back (0);
2244  conn.push_back (0);
2245  conn.push_back (0);
2246 #endif
2247  conn.push_back (static_cast<largest_id_type>(elem->type()));
2248  conn.push_back (elem->processor_id());
2249  conn.push_back (elem->subdomain_id());
2250  conn.push_back (elem->id());
2251 
2252 #ifdef LIBMESH_ENABLE_AMR
2253  // use parent_ID of -1 to indicate a level 0 element
2254  if (elem->level() == 0)
2255  {
2256  conn.push_back(-1);
2257  conn.push_back(-1);
2258  }
2259  else
2260  {
2261  conn.push_back(elem->parent()->id());
2262  conn.push_back(elem->parent()->which_child_am_i(elem));
2263  }
2264 #else
2265  conn.push_back (-1);
2266  conn.push_back (-1);
2267 #endif
2268 
2269  for (unsigned int n=0; n<elem->n_nodes(); n++)
2270  conn.push_back (elem->node(n));
2271 
2272  for (unsigned int n=0; n<elem->n_neighbors(); n++)
2273  {
2274  Elem *neigh = elem->neighbor(n);
2275  if (neigh)
2276  conn.push_back (neigh->id());
2277  else
2278  conn.push_back (-1);
2279  }
2280 
2281  elem->pack_indexing(std::back_inserter(conn));
2282 }
unsigned int libMesh::Elem::PackedElem::packed_size ( ) const
inline

Definition at line 2207 of file elem.h.

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

2208  {
2209  return this->header_size + this->n_nodes() +
2210  this->n_neighbors() +
2212  }
int libMesh::Elem::PackedElem::parent_id ( ) const
inline

return the parent id of this packed element.

Definition at line 2154 of file elem.h.

References _buf_begin.

2155  {
2156  return *(_buf_begin+8);
2157  }
processor_id_type libMesh::Elem::PackedElem::processor_id ( ) const
inline

return the processor id of this packed element.

Definition at line 2126 of file elem.h.

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

2127  {
2128  // libmesh_assert_greater_equal (*(_buf_begin+5), 0);
2129  libmesh_assert_less (static_cast<unsigned int>(*(_buf_begin+5)),
2131  static_cast<processor_id_type>(*(_buf_begin+5)) == DofObject::invalid_processor_id);
2132  return static_cast<processor_id_type>(*(_buf_begin+5));
2133  }
Elem::RefinementState libMesh::Elem::PackedElem::refinement_flag ( ) const
inline

return the refinement state of this packed element.

Definition at line 2095 of file elem.h.

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

2096  {
2097  // libmesh_assert_greater_equal (*(_buf_begin+2), 0);
2098  libmesh_assert_less (*(_buf_begin+2), INVALID_REFINEMENTSTATE);
2099  return static_cast<Elem::RefinementState>(*(_buf_begin+2));
2100  }
subdomain_id_type libMesh::Elem::PackedElem::subdomain_id ( ) const
inline

return the subdomain id of this packed element.

Definition at line 2138 of file elem.h.

References _buf_begin.

2139  {
2140  return static_cast<subdomain_id_type>(*(_buf_begin+6));
2141  }
ElemType libMesh::Elem::PackedElem::type ( ) const
inline

return the element type of this packed element.

Definition at line 2116 of file elem.h.

References _buf_begin, and libMeshEnums::INVALID_ELEM.

Referenced by n_neighbors(), and n_nodes().

2117  {
2118  // libmesh_assert_greater_equal (*(_buf_begin+4), 0);
2119  libmesh_assert_less (*(_buf_begin+4), INVALID_ELEM);
2120  return static_cast<ElemType>(*(_buf_begin+4));
2121  }
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 2286 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(), libMesh::DofObject::invalid_id, libMesh::Elem::level(), libMesh::libmesh_assert(), libMesh::Elem::n_children(), libMesh::Elem::n_neighbors(), libMesh::Elem::n_nodes(), libMesh::Elem::n_sides(), libMesh::Elem::neighbor(), libMesh::Elem::node(), libMesh::MeshBase::node_ptr(), libMesh::Elem::p_level(), libMesh::Elem::p_refinement_flag(), libMesh::DofObject::processor_id(), libMesh::MeshBase::query_elem(), libMesh::Elem::refinement_flag(), 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(), libMesh::Elem::subdomain_id(), libMesh::Elem::type(), libMesh::DofObject::unpack_indexing(), and libMesh::Elem::which_child_am_i().

2287 {
2288 
2289  Elem *elem = Elem::build(this->type(),parent).release();
2290  libmesh_assert (elem);
2291 
2292 #ifdef LIBMESH_ENABLE_AMR
2293  if (this->level() != 0)
2294  {
2296  parent->add_child(elem, this->which_child_am_i());
2297  libmesh_assert_equal_to (parent->type(), elem->type());
2298  libmesh_assert_equal_to (parent->child(this->which_child_am_i()), elem);
2299  }
2300 #endif
2301 
2302  // Assign the refinement flags and levels
2303 #ifdef LIBMESH_ENABLE_AMR
2304  elem->set_p_level(this->p_level());
2305  elem->set_refinement_flag(this->refinement_flag());
2306  elem->set_p_refinement_flag(this->p_refinement_flag());
2307  libmesh_assert_equal_to (elem->level(), this->level());
2308 
2309  // If this element definitely should have children, assign
2310  // remote_elem for now; later unpacked elements may overwrite that.
2311  if (!elem->active())
2312  for (unsigned int c=0; c != elem->n_children(); ++c)
2313  elem->add_child(const_cast<RemoteElem*>(remote_elem), c);
2314 #endif
2315 
2316  // Assign the IDs
2317  elem->subdomain_id() = this->subdomain_id();
2318  elem->processor_id() = this->processor_id();
2319  elem->set_id() = this->id();
2320 
2321  // Assign the connectivity
2322  libmesh_assert_equal_to (elem->n_nodes(), this->n_nodes());
2323 
2324  for (unsigned int n=0; n<elem->n_nodes(); n++)
2325  elem->set_node(n) = mesh.node_ptr (this->node(n));
2326 
2327  // Assign the connectivity
2328  libmesh_assert_equal_to (elem->n_neighbors(), this->n_neighbors());
2329 
2330  for (unsigned int n=0; n<elem->n_neighbors(); n++)
2331  {
2332  dof_id_type neighbor_id = this->neighbor(n);
2333 
2334  // We should only be unpacking elements sent by their owners,
2335  // and their owners should know all their neighbors
2336  libmesh_assert_not_equal_to (neighbor_id, remote_elem->id());
2337 
2338  if (neighbor_id == DofObject::invalid_id)
2339  continue;
2340 
2341  Elem *neigh = mesh.query_elem(neighbor_id);
2342  if (!neigh)
2343  {
2344  elem->set_neighbor(n, const_cast<RemoteElem*>(remote_elem));
2345  continue;
2346  }
2347 
2348  // We never have neighbors more refined than us
2349  libmesh_assert_less_equal (neigh->level(), elem->level());
2350 
2351  // We never have subactive neighbors of non subactive elements
2352  libmesh_assert(!neigh->subactive() || elem->subactive());
2353 
2354  // If we have a neighbor less refined than us then it must not
2355  // have any more refined active descendants we could have
2356  // pointed to instead.
2357  libmesh_assert(neigh->level() == elem->level() ||
2358  neigh->active());
2359 
2360  elem->set_neighbor(n, neigh);
2361 
2362  // If neigh is at elem's level, then its family might have
2363  // remote_elem neighbor links which need to point to elem
2364  // instead, but if not, then we're done.
2365  if (neigh->level() != elem->level())
2366  continue;
2367 
2368  // What side of neigh is elem on? We can't use the usual Elem
2369  // method because we haven't finished restoring topology
2370  const AutoPtr<Elem> my_side = elem->side(n);
2371  unsigned int nn = 0;
2372  for (; nn != neigh->n_sides(); ++nn)
2373  {
2374  const AutoPtr<Elem> neigh_side = neigh->side(nn);
2375  if (*my_side == *neigh_side)
2376  break;
2377  }
2378 
2379  // elem had better be on *some* side of neigh
2380  libmesh_assert_less (nn, neigh->n_sides());
2381 
2382  // Find any elements that ought to point to elem
2383  std::vector<const Elem*> neigh_family;
2384 #ifdef LIBMESH_ENABLE_AMR
2385  if (!neigh->subactive())
2386  neigh->family_tree_by_side(neigh_family, nn);
2387 #else
2388  neigh_family.push_back(neigh);
2389 #endif
2390 
2391  // And point them to elem
2392  for (unsigned int i = 0; i != neigh_family.size(); ++i)
2393  {
2394  Elem* neigh_family_member = const_cast<Elem*>(neigh_family[i]);
2395 
2396  // The neighbor link ought to either be correct already or
2397  // ought to be to remote_elem
2398  libmesh_assert(neigh_family_member->neighbor(nn) == elem ||
2399  neigh_family_member->neighbor(nn) == remote_elem);
2400 
2401  neigh_family_member->set_neighbor(nn, elem);
2402  }
2403  }
2404 
2405  elem->unpack_indexing(this->indices());
2406 
2407  return elem;
2408 }
unsigned int libMesh::Elem::PackedElem::which_child_am_i ( ) const
inline

return which child this packed element is.

Definition at line 2162 of file elem.h.

References _buf_begin.

2163  {
2164  return static_cast<unsigned int>(*(_buf_begin+9));
2165  }

Member Data Documentation

const std::vector<largest_id_type>::const_iterator libMesh::Elem::PackedElem::_buf_begin
private

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

Definition at line 2041 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 2057 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 07 2014 16:57:18 UTC

Hosted By:
SourceForge.net Logo