libMesh::Patch Class Reference

#include <patch.h>

Inheritance diagram for libMesh::Patch:

Public Types

typedef void(Patch::* PMF) ()
 

Public Member Functions

 Patch (const processor_id_type my_procid=static_cast< processor_id_type >(-1))
 
 ~Patch ()
 
void add_face_neighbors ()
 
void add_local_face_neighbors ()
 
void add_semilocal_face_neighbors ()
 
void add_point_neighbors ()
 
void add_local_point_neighbors ()
 
void add_semilocal_point_neighbors ()
 
void build_around_element (const Elem *elem, const unsigned int target_patch_size=10, PMF patchtype=&Patch::add_local_face_neighbors)
 

Protected Member Functions

void find_face_neighbors (std::set< const Elem * > &neighbor_set)
 
void find_point_neighbors (std::set< const Elem * > &neighbor_set)
 

Protected Attributes

const processor_id_type _my_procid
 

Detailed Description

This class implements useful utility functions for a patch of elements

Author
Varis Carey
Benjamin S. Kirk
Date
2004
Author
Roy H. Stogner
Date
2007

Definition at line 47 of file patch.h.

Member Typedef Documentation

typedef void(Patch::* libMesh::Patch::PMF) ()

Pointer to Member Function typedef

Definition at line 104 of file patch.h.

Constructor & Destructor Documentation

libMesh::Patch::Patch ( const processor_id_type  my_procid = static_cast<processor_id_type>(-1))
inline

Constructor. Requires the processor ID to be interpreted as "local".

Definition at line 54 of file patch.h.

54  :
55  _my_procid(my_procid)
56  {}
const processor_id_type _my_procid
Definition: patch.h:131
libMesh::Patch::~Patch ( )
inline

Member Function Documentation

void libMesh::Patch::add_face_neighbors ( )

This function finds all elements which touch the current patch at a face, and adds them to the patch.

Definition at line 76 of file patch.C.

References find_face_neighbors().

Referenced by ~Patch().

77 {
78  std::set<const Elem *> new_neighbors;
79 
80  this->find_face_neighbors(new_neighbors);
81 
82  this->insert(new_neighbors.begin(), new_neighbors.end());
83 }
void find_face_neighbors(std::set< const Elem * > &neighbor_set)
Definition: patch.C:37
void libMesh::Patch::add_local_face_neighbors ( )

This function finds all elements on the current processor which touch the current patch at a face, and adds them to the patch.

Definition at line 87 of file patch.C.

References _my_procid, find_face_neighbors(), and libMesh::DofObject::processor_id().

Referenced by build_around_element(), and ~Patch().

88 {
89  std::set<const Elem *> new_neighbors;
90 
91  this->find_face_neighbors(new_neighbors);
92 
93  std::set<const Elem *>::const_iterator it = new_neighbors.begin();
94  const std::set<const Elem *>::const_iterator end_it = new_neighbors.end();
95 
96  for (; it != end_it; ++it)
97  {
98  const Elem * neighbor = *it;
99  if (neighbor->processor_id() ==
100  _my_procid) // ... if the neighbor belongs to this processor
101  this->insert (neighbor); // ... then add it to the patch
102  }
103 }
void find_face_neighbors(std::set< const Elem * > &neighbor_set)
Definition: patch.C:37
const processor_id_type _my_procid
Definition: patch.h:131
void libMesh::Patch::add_local_point_neighbors ( )

This function finds all elements on the current processor which touch the current patch at any point, and adds them to the patch.

Definition at line 157 of file patch.C.

References _my_procid, find_point_neighbors(), and libMesh::DofObject::processor_id().

Referenced by build_around_element(), and ~Patch().

158 {
159  std::set<const Elem *> new_neighbors;
160 
161  this->find_point_neighbors(new_neighbors);
162 
163  std::set<const Elem *>::const_iterator it = new_neighbors.begin();
164  const std::set<const Elem *>::const_iterator end_it = new_neighbors.end();
165 
166  for (; it != end_it; ++it)
167  {
168  const Elem * neighbor = *it;
169  if (neighbor->processor_id() ==
170  _my_procid) // ... if the neighbor belongs to this processor
171  this->insert (neighbor); // ... then add it to the patch
172  }
173 }
const processor_id_type _my_procid
Definition: patch.h:131
void find_point_neighbors(std::set< const Elem * > &neighbor_set)
Definition: patch.C:126
void libMesh::Patch::add_point_neighbors ( )

This function finds all elements which touch the current patch at any point, and adds them to the patch.

Definition at line 146 of file patch.C.

References find_point_neighbors().

Referenced by ~Patch().

147 {
148  std::set<const Elem *> new_neighbors;
149 
150  this->find_point_neighbors(new_neighbors);
151 
152  this->insert(new_neighbors.begin(), new_neighbors.end());
153 }
void find_point_neighbors(std::set< const Elem * > &neighbor_set)
Definition: patch.C:126
void libMesh::Patch::add_semilocal_face_neighbors ( )

This function finds all elements which touch the current patch at a face and which touch one of our processor's elements at any point, and it adds them to the patch.

Definition at line 107 of file patch.C.

References _my_procid, find_face_neighbors(), and libMesh::Elem::is_semilocal().

Referenced by ~Patch().

108 {
109  std::set<const Elem *> new_neighbors;
110 
111  this->find_face_neighbors(new_neighbors);
112 
113  std::set<const Elem *>::const_iterator it = new_neighbors.begin();
114  const std::set<const Elem *>::const_iterator end_it = new_neighbors.end();
115 
116  for (; it != end_it; ++it)
117  {
118  const Elem * neighbor = *it;
119  if (neighbor->is_semilocal(_my_procid))
120  this->insert (neighbor);
121  }
122 }
void find_face_neighbors(std::set< const Elem * > &neighbor_set)
Definition: patch.C:37
const processor_id_type _my_procid
Definition: patch.h:131
void libMesh::Patch::add_semilocal_point_neighbors ( )

This function finds all elements which touch the current patch at any point and which touch one of our processor's elements at any point, and it adds them to the patch.

Definition at line 177 of file patch.C.

References _my_procid, find_point_neighbors(), and libMesh::Elem::is_semilocal().

Referenced by ~Patch().

178 {
179  std::set<const Elem *> new_neighbors;
180 
181  this->find_point_neighbors(new_neighbors);
182 
183  std::set<const Elem *>::const_iterator it = new_neighbors.begin();
184  const std::set<const Elem *>::const_iterator end_it = new_neighbors.end();
185 
186  for (; it != end_it; ++it)
187  {
188  const Elem * neighbor = *it;
189  if (neighbor->is_semilocal(_my_procid))
190  this->insert (neighbor);
191  }
192 }
const processor_id_type _my_procid
Definition: patch.h:131
void find_point_neighbors(std::set< const Elem * > &neighbor_set)
Definition: patch.C:126
void libMesh::Patch::build_around_element ( const Elem elem,
const unsigned int  target_patch_size = 10,
PMF  patchtype = &Patch::add_local_face_neighbors 
)

Erases any elements in the current patch, then builds a new patch containing element elem by repeated addition of neighbors on the current processor. This procedure is repeated until the number of elements meets or exceeds target_patch_size, or until the patch has no more local neighbors.

Definition at line 196 of file patch.C.

References _my_procid, libMesh::Elem::active(), add_local_face_neighbors(), add_local_point_neighbors(), end, libMesh::err, libMesh::libmesh_assert(), and libMesh::DofObject::processor_id().

Referenced by libMesh::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), and libMesh::PatchRecoveryErrorEstimator::EstimateError::operator()().

199 {
200 
201  // Make sure we are building a patch for an active element.
202  libmesh_assert(e0);
203  libmesh_assert (e0->active());
204  // Make sure we are either starting with a local element or
205  // requesting a nonlocal patch
207  patchtype != &Patch::add_local_point_neighbors) ||
208  e0->processor_id() == _my_procid);
209 
210  // First clear the current set, then add the element of interest.
211  this->clear();
212  this->insert (e0);
213 
214  // Repeatedly add the neighbors of the elements in the patch until
215  // the target patch size is met
216  while (this->size() < target_patch_size)
217  {
218  // It is possible that the target patch size is larger than the number
219  // of elements that can be added to the patch. Since we don't
220  // have access to the Mesh object here, the only way we can
221  // detect this case is by detecting a "stagnant patch," i.e. a
222  // patch whose size does not increase after adding face neighbors
223  const std::size_t old_patch_size = this->size();
224 
225  // We profile the patch-extending functions separately
226  (this->*patchtype)();
227 
228  // Check for a "stagnant" patch
229  if (this->size() == old_patch_size)
230  {
231  libmesh_do_once(libMesh::err <<
232  "WARNING: stagnant patch of " << this->size() << " elements."
233  << std::endl <<
234  "Does the target patch size exceed the number of local elements?"
235  << std::endl;
236  libmesh_here(););
237  break;
238  }
239  } // end while loop
240 
241 
242  // make sure all the elements in the patch are active and local
243  // if we are in debug mode
244 #ifdef DEBUG
245  {
246  std::set<const Elem *>::const_iterator it = this->begin();
247  const std::set<const Elem *>::const_iterator end_it = this->end();
248 
249  for (; it != end_it; ++it)
250  {
251  // Convenience. Keep the syntax simple.
252  const Elem * elem = *it;
253 
254  libmesh_assert (elem->active());
255  if ((patchtype == &Patch::add_local_face_neighbors ||
256  patchtype == &Patch::add_local_point_neighbors))
257  libmesh_assert_equal_to (elem->processor_id(), _my_procid);
258  }
259  }
260 #endif
261 
262 }
void add_local_point_neighbors()
Definition: patch.C:157
IterBase * end
libmesh_assert(j)
OStreamProxy err(std::cerr)
void add_local_face_neighbors()
Definition: patch.C:87
const processor_id_type _my_procid
Definition: patch.h:131
void libMesh::Patch::find_face_neighbors ( std::set< const Elem * > &  neighbor_set)
protected

This function finds all elements which touch the current patch at a face

Definition at line 37 of file patch.C.

References libMesh::Elem::active(), libMesh::Elem::active_family_tree_by_neighbor(), end, libmesh_nullptr, libMesh::Elem::n_sides(), and libMesh::Elem::neighbor_ptr().

Referenced by add_face_neighbors(), add_local_face_neighbors(), and add_semilocal_face_neighbors().

38 {
39  // Loop over all the elements in the patch
40  std::set<const Elem *>::const_iterator it = this->begin();
41  const std::set<const Elem *>::const_iterator end_it = this->end();
42 
43  for (; it != end_it; ++it)
44  {
45  const Elem * elem = *it;
46  for (unsigned int s=0; s<elem->n_sides(); s++)
47  if (elem->neighbor_ptr(s) != libmesh_nullptr) // we have a neighbor on this side
48  {
49  const Elem * neighbor = elem->neighbor_ptr(s);
50 
51 #ifdef LIBMESH_ENABLE_AMR
52  if (!neighbor->active()) // the neighbor is *not* active,
53  { // so add *all* neighboring
54  // active children to the patch
55  std::vector<const Elem *> active_neighbor_children;
56 
57  neighbor->active_family_tree_by_neighbor
58  (active_neighbor_children, elem);
59 
60  std::vector<const Elem *>::const_iterator
61  child_it = active_neighbor_children.begin();
62  const std::vector<const Elem *>::const_iterator
63  child_end = active_neighbor_children.end();
64  for (; child_it != child_end; ++child_it)
65  new_neighbors.insert(*child_it);
66  }
67  else
68 #endif // #ifdef LIBMESH_ENABLE_AMR
69  new_neighbors.insert (neighbor); // add active neighbors
70  }
71  }
72 }
const class libmesh_nullptr_t libmesh_nullptr
IterBase * end
void libMesh::Patch::find_point_neighbors ( std::set< const Elem * > &  neighbor_set)
protected

This function finds all elements which touch the current patch at any point

Definition at line 126 of file patch.C.

References end, and libMesh::Elem::find_point_neighbors().

Referenced by add_local_point_neighbors(), add_point_neighbors(), and add_semilocal_point_neighbors().

127 {
128  // Loop over all the elements in the patch
129  std::set<const Elem *>::const_iterator it = this->begin();
130  const std::set<const Elem *>::const_iterator end_it = this->end();
131 
132  for (; it != end_it; ++it)
133  {
134  std::set<const Elem *> elem_point_neighbors;
135 
136  const Elem * elem = *it;
137  elem->find_point_neighbors(elem_point_neighbors);
138 
139  new_neighbors.insert(elem_point_neighbors.begin(),
140  elem_point_neighbors.end());
141  }
142 }
IterBase * end

Member Data Documentation


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