libMesh
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
libMesh::Patch Class Reference

This class implements useful utility functions for a patch of elements. More...

#include <patch.h>

Inheritance diagram for libMesh::Patch:
[legend]

Public Types

typedef void(Patch::* PMF) ()
 Pointer to Member Function typedef. More...
 

Public Member Functions

 Patch (const processor_id_type my_procid=static_cast< processor_id_type >(-1))
 Constructor. More...
 
 ~Patch ()
 Destructor. More...
 
void add_face_neighbors ()
 This function finds all elements which touch the current patch at a face, and adds them to the patch. More...
 
void 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. More...
 
void 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. More...
 
void add_point_neighbors ()
 This function finds all elements which touch the current patch at any point, and adds them to the patch. More...
 
void 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. More...
 
void 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. More...
 
void 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. More...
 

Protected Member Functions

void find_face_neighbors (std::set< const Elem * > &neighbor_set)
 This function finds all elements which touch the current patch at a face. More...
 
void find_point_neighbors (std::set< const Elem * > &neighbor_set)
 This function finds all elements which touch the current patch at any point. More...
 

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))

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 ( )

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 74 of file patch.C.

References find_face_neighbors().

Referenced by ~Patch().

75 {
76  std::set<const Elem *> new_neighbors;
77 
78  this->find_face_neighbors(new_neighbors);
79 
80  this->insert(new_neighbors.begin(), new_neighbors.end());
81 }
void find_face_neighbors(std::set< const Elem * > &neighbor_set)
This function finds all elements which touch the current patch at a face.
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 85 of file patch.C.

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

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

86 {
87  std::set<const Elem *> new_neighbors;
88 
89  this->find_face_neighbors(new_neighbors);
90 
91  std::set<const Elem *>::const_iterator it = new_neighbors.begin();
92  const std::set<const Elem *>::const_iterator end_it = new_neighbors.end();
93 
94  for (; it != end_it; ++it)
95  {
96  const Elem * neighbor = *it;
97  if (neighbor->processor_id() ==
98  _my_procid) // ... if the neighbor belongs to this processor
99  this->insert (neighbor); // ... then add it to the patch
100  }
101 }
void find_face_neighbors(std::set< const Elem * > &neighbor_set)
This function finds all elements which touch the current patch at a face.
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 155 of file patch.C.

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

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

156 {
157  std::set<const Elem *> new_neighbors;
158 
159  this->find_point_neighbors(new_neighbors);
160 
161  std::set<const Elem *>::const_iterator it = new_neighbors.begin();
162  const std::set<const Elem *>::const_iterator end_it = new_neighbors.end();
163 
164  for (; it != end_it; ++it)
165  {
166  const Elem * neighbor = *it;
167  if (neighbor->processor_id() ==
168  _my_procid) // ... if the neighbor belongs to this processor
169  this->insert (neighbor); // ... then add it to the patch
170  }
171 }
const processor_id_type _my_procid
Definition: patch.h:131
void find_point_neighbors(std::set< const Elem * > &neighbor_set)
This function finds all elements which touch the current patch at any point.
Definition: patch.C:124
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 144 of file patch.C.

References find_point_neighbors().

Referenced by ~Patch().

145 {
146  std::set<const Elem *> new_neighbors;
147 
148  this->find_point_neighbors(new_neighbors);
149 
150  this->insert(new_neighbors.begin(), new_neighbors.end());
151 }
void find_point_neighbors(std::set< const Elem * > &neighbor_set)
This function finds all elements which touch the current patch at any point.
Definition: patch.C:124
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 105 of file patch.C.

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

Referenced by ~Patch().

106 {
107  std::set<const Elem *> new_neighbors;
108 
109  this->find_face_neighbors(new_neighbors);
110 
111  std::set<const Elem *>::const_iterator it = new_neighbors.begin();
112  const std::set<const Elem *>::const_iterator end_it = new_neighbors.end();
113 
114  for (; it != end_it; ++it)
115  {
116  const Elem * neighbor = *it;
117  if (neighbor->is_semilocal(_my_procid))
118  this->insert (neighbor);
119  }
120 }
void find_face_neighbors(std::set< const Elem * > &neighbor_set)
This function finds all elements which touch the current patch at a face.
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 175 of file patch.C.

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

Referenced by ~Patch().

176 {
177  std::set<const Elem *> new_neighbors;
178 
179  this->find_point_neighbors(new_neighbors);
180 
181  std::set<const Elem *>::const_iterator it = new_neighbors.begin();
182  const std::set<const Elem *>::const_iterator end_it = new_neighbors.end();
183 
184  for (; it != end_it; ++it)
185  {
186  const Elem * neighbor = *it;
187  if (neighbor->is_semilocal(_my_procid))
188  this->insert (neighbor);
189  }
190 }
const processor_id_type _my_procid
Definition: patch.h:131
void find_point_neighbors(std::set< const Elem * > &neighbor_set)
This function finds all elements which touch the current patch at any point.
Definition: patch.C:124
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 194 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()().

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

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 (auto neighbor : elem->neighbor_ptr_range())
47  if (neighbor != libmesh_nullptr) // we have a neighbor on this side
48  {
49 #ifdef LIBMESH_ENABLE_AMR
50  if (!neighbor->active()) // the neighbor is *not* active,
51  { // so add *all* neighboring
52  // active children to the patch
53  std::vector<const Elem *> active_neighbor_children;
54 
55  neighbor->active_family_tree_by_neighbor
56  (active_neighbor_children, elem);
57 
58  std::vector<const Elem *>::const_iterator
59  child_it = active_neighbor_children.begin();
60  const std::vector<const Elem *>::const_iterator
61  child_end = active_neighbor_children.end();
62  for (; child_it != child_end; ++child_it)
63  new_neighbors.insert(*child_it);
64  }
65  else
66 #endif // #ifdef LIBMESH_ENABLE_AMR
67  new_neighbors.insert (neighbor); // add active neighbors
68  }
69  }
70 }
const class libmesh_nullptr_t libmesh_nullptr
IterBase * end
Also have a polymorphic pointer to the end object, this prevents iterating past the 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 124 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().

125 {
126  // Loop over all the elements in the patch
127  std::set<const Elem *>::const_iterator it = this->begin();
128  const std::set<const Elem *>::const_iterator end_it = this->end();
129 
130  for (; it != end_it; ++it)
131  {
132  std::set<const Elem *> elem_point_neighbors;
133 
134  const Elem * elem = *it;
135  elem->find_point_neighbors(elem_point_neighbors);
136 
137  new_neighbors.insert(elem_point_neighbors.begin(),
138  elem_point_neighbors.end());
139  }
140 }
IterBase * end
Also have a polymorphic pointer to the end object, this prevents iterating past the end...

Member Data Documentation

const processor_id_type libMesh::Patch::_my_procid
protected

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