libMesh
Loading...
Searching...
No Matches
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.
 

Public Member Functions

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

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.
 
void find_point_neighbors (std::set< const Elem * > &neighbor_set)
 This function finds all elements which touch the current patch at any point.
 

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

◆ PMF

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

Pointer to Member Function typedef.

Definition at line 104 of file patch.h.

Constructor & Destructor Documentation

◆ Patch()

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

◆ ~Patch()

libMesh::Patch::~Patch ( )
default

Destructor.

Member Function Documentation

◆ add_face_neighbors()

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

65{
66 std::set<const Elem *> new_neighbors;
67
68 this->find_face_neighbors(new_neighbors);
69
70 this->insert(new_neighbors.begin(), new_neighbors.end());
71}
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

References find_face_neighbors().

◆ add_local_face_neighbors()

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

76{
77 std::set<const Elem *> new_neighbors;
78
79 this->find_face_neighbors(new_neighbors);
80
81 // if neighbor belongs to this processor then add it to the patch
82 for (const auto & neighbor : new_neighbors)
83 if (neighbor->processor_id() == _my_procid)
84 this->insert (neighbor);
85}

References _my_procid, and find_face_neighbors().

Referenced by build_around_element().

◆ add_local_point_neighbors()

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

130{
131 std::set<const Elem *> new_neighbors;
132
133 this->find_point_neighbors(new_neighbors);
134
135 // if neighbor belongs to this processor then add it to the patch
136 for (const auto & neighbor : new_neighbors)
137 if (neighbor->processor_id() == _my_procid)
138 this->insert (neighbor);
139}
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:102

References _my_procid, and find_point_neighbors().

Referenced by build_around_element().

◆ add_point_neighbors()

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

119{
120 std::set<const Elem *> new_neighbors;
121
122 this->find_point_neighbors(new_neighbors);
123
124 this->insert(new_neighbors.begin(), new_neighbors.end());
125}

References find_point_neighbors().

◆ add_semilocal_face_neighbors()

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

90{
91 std::set<const Elem *> new_neighbors;
92
93 this->find_face_neighbors(new_neighbors);
94
95 for (const auto & neighbor : new_neighbors)
96 if (neighbor->is_semilocal(_my_procid))
97 this->insert (neighbor);
98}

References _my_procid, and find_face_neighbors().

◆ add_semilocal_point_neighbors()

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

144{
145 std::set<const Elem *> new_neighbors;
146
147 this->find_point_neighbors(new_neighbors);
148
149 for (const auto & neighbor : new_neighbors)
150 if (neighbor->is_semilocal(_my_procid))
151 this->insert (neighbor);
152}

References _my_procid, and find_point_neighbors().

◆ build_around_element()

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

159{
160
161 // Make sure we are building a patch for an active element.
162 libmesh_assert(e0);
163 libmesh_assert (e0->active());
164 // Make sure we are either starting with a local element or
165 // requesting a nonlocal patch
167 patchtype != &Patch::add_local_point_neighbors) ||
168 e0->processor_id() == _my_procid);
169
170 // First clear the current set, then add the element of interest.
171 this->clear();
172 this->insert (e0);
173
174 // Repeatedly add the neighbors of the elements in the patch until
175 // the target patch size is met
176 while (this->size() < target_patch_size)
177 {
178 // It is possible that the target patch size is larger than the number
179 // of elements that can be added to the patch. Since we don't
180 // have access to the Mesh object here, the only way we can
181 // detect this case is by detecting a "stagnant patch," i.e. a
182 // patch whose size does not increase after adding face neighbors
183 const std::size_t old_patch_size = this->size();
184
185 // We profile the patch-extending functions separately
186 (this->*patchtype)();
187
188 // Check for a "stagnant" patch
189 if (this->size() == old_patch_size)
190 {
191 libmesh_do_once(libMesh::err <<
192 "WARNING: stagnant patch of " << this->size() << " elements."
193 << std::endl <<
194 "Does the target patch size exceed the number of local elements?"
195 << std::endl;
196 libmesh_here(););
197 break;
198 }
199 } // end while loop
200
201
202 // make sure all the elements in the patch are active and local
203 // if we are in debug mode
204#ifdef DEBUG
205 for (const auto & elem : *this)
206 {
207 libmesh_assert (elem->active());
208 if ((patchtype == &Patch::add_local_face_neighbors ||
210 libmesh_assert_equal_to (elem->processor_id(), _my_procid);
211 }
212#endif
213
214}
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:75
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:129
OStreamProxy err
libmesh_assert(ctx)

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

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

◆ find_face_neighbors()

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.

38{
39 // Loop over all the elements in the patch
40 for (const auto & elem : *this)
41 for (auto neighbor : elem->neighbor_ptr_range())
42 if (neighbor != nullptr) // we have a neighbor on this side
43 {
44#ifdef LIBMESH_ENABLE_AMR
45 if (!neighbor->active()) // the neighbor is *not* active,
46 { // so add *all* neighboring
47 // active children to the patch
48 std::vector<const Elem *> active_neighbor_children;
49
50 neighbor->active_family_tree_by_neighbor
51 (active_neighbor_children, elem);
52
53 for (const auto & child : active_neighbor_children)
54 new_neighbors.insert(child);
55 }
56 else
57#endif // #ifdef LIBMESH_ENABLE_AMR
58 new_neighbors.insert (neighbor); // add active neighbors
59 }
60}

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

◆ find_point_neighbors()

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

103{
104 // Loop over all the elements in the patch
105 for (const auto & elem : *this)
106 {
107 std::set<const Elem *> elem_point_neighbors;
108
109 elem->find_point_neighbors(elem_point_neighbors);
110
111 new_neighbors.insert(elem_point_neighbors.begin(),
112 elem_point_neighbors.end());
113 }
114}

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

Member Data Documentation

◆ _my_procid

const processor_id_type libMesh::Patch::_my_procid
protected

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