Skip to content

Commit 5fe612b

Browse files
committed
Add topological neighbor method with return of neighbor side
1 parent 24d44d5 commit 5fe612b

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

include/geom/elem.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,18 @@ class Elem : public ReferenceCountedObject<Elem>,
326326
MeshBase & mesh,
327327
const PointLocatorBase & point_locator,
328328
const PeriodicBoundaries * pb);
329+
330+
/**
331+
* \returns A pointer to the \f$ i^{th} \f$ neighbor of this element
332+
* for interior elements. If an element is on a periodic
333+
* boundary, it will return a corresponding element on the opposite
334+
* side, along with the side neigh_side.
335+
*/
336+
const Elem * topological_neighbor_side(const unsigned int i,
337+
const MeshBase & mesh,
338+
const PointLocatorBase & point_locator,
339+
const PeriodicBoundaries * pb,
340+
unsigned int * neigh_side) const;
329341

330342
/**
331343
* \returns \p true if the element \p elem in question is a neighbor or

src/geom/elem.C

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,45 @@ const Elem * Elem::topological_neighbor (const unsigned int i,
11011101
}
11021102

11031103

1104+
const Elem *
1105+
Elem::topological_neighbor_side(const unsigned int i,
1106+
const MeshBase & mesh,
1107+
const PointLocatorBase & point_locator,
1108+
const PeriodicBoundaries * pb,
1109+
unsigned int * neigh_side) const
1110+
{
1111+
libmesh_assert_less (i, this->n_neighbors());
1112+
1113+
const Elem * neighbor_i = this->neighbor_ptr(i);
1114+
if (neighbor_i != nullptr)
1115+
return neighbor_i;
1116+
1117+
if (pb)
1118+
{
1119+
// Since the neighbor is nullptr it must be on a boundary. We need
1120+
// see if this is a periodic boundary in which case it will have a
1121+
// topological neighbor
1122+
std::vector<boundary_id_type> bc_ids;
1123+
mesh.get_boundary_info().boundary_ids(this, cast_int<unsigned short>(i), bc_ids);
1124+
for (const auto & id : bc_ids)
1125+
if (pb->boundary(id))
1126+
{
1127+
neighbor_i = pb->neighbor(id, point_locator, this, i, neigh_side);
1128+
1129+
// Since coarse elements do not have more refined
1130+
// neighbors we need to make sure that we don't return one
1131+
// of these types of neighbors.
1132+
if (neighbor_i)
1133+
while (level() < neighbor_i->level())
1134+
neighbor_i = neighbor_i->parent();
1135+
return neighbor_i;
1136+
}
1137+
}
1138+
1139+
return nullptr;
1140+
}
1141+
1142+
11041143
bool Elem::has_topological_neighbor (const Elem * elem,
11051144
const MeshBase & mesh,
11061145
const PointLocatorBase & point_locator,

0 commit comments

Comments
 (0)