Skip to content

Commit 30efee2

Browse files
committed
Add topological neighbor method with return of neighbor side
1 parent d9b13e4 commit 30efee2

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
@@ -335,6 +335,18 @@ class Elem : public ReferenceCountedObject<Elem>,
335335
MeshBase & mesh,
336336
const PointLocatorBase & point_locator,
337337
const PeriodicBoundaries * pb);
338+
339+
/**
340+
* \returns A pointer to the \f$ i^{th} \f$ neighbor of this element
341+
* for interior elements. If an element is on a periodic
342+
* boundary, it will return a corresponding element on the opposite
343+
* side, along with the side neigh_side.
344+
*/
345+
const Elem * topological_neighbor_side(const unsigned int i,
346+
const MeshBase & mesh,
347+
const PointLocatorBase & point_locator,
348+
const PeriodicBoundaries * pb,
349+
unsigned int * neigh_side) const;
338350

339351
/**
340352
* \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
@@ -1153,6 +1153,45 @@ const Elem * Elem::topological_neighbor (const unsigned int i,
11531153
}
11541154

11551155

1156+
const Elem *
1157+
Elem::topological_neighbor_side(const unsigned int i,
1158+
const MeshBase & mesh,
1159+
const PointLocatorBase & point_locator,
1160+
const PeriodicBoundaries * pb,
1161+
unsigned int * neigh_side) const
1162+
{
1163+
libmesh_assert_less (i, this->n_neighbors());
1164+
1165+
const Elem * neighbor_i = this->neighbor_ptr(i);
1166+
if (neighbor_i != nullptr)
1167+
return neighbor_i;
1168+
1169+
if (pb)
1170+
{
1171+
// Since the neighbor is nullptr it must be on a boundary. We need
1172+
// see if this is a periodic boundary in which case it will have a
1173+
// topological neighbor
1174+
std::vector<boundary_id_type> bc_ids;
1175+
mesh.get_boundary_info().boundary_ids(this, cast_int<unsigned short>(i), bc_ids);
1176+
for (const auto & id : bc_ids)
1177+
if (pb->boundary(id))
1178+
{
1179+
neighbor_i = pb->neighbor(id, point_locator, this, i, neigh_side);
1180+
1181+
// Since coarse elements do not have more refined
1182+
// neighbors we need to make sure that we don't return one
1183+
// of these types of neighbors.
1184+
if (neighbor_i)
1185+
while (level() < neighbor_i->level())
1186+
neighbor_i = neighbor_i->parent();
1187+
return neighbor_i;
1188+
}
1189+
}
1190+
1191+
return nullptr;
1192+
}
1193+
1194+
11561195
bool Elem::has_topological_neighbor (const Elem * elem,
11571196
const MeshBase & mesh,
11581197
const PointLocatorBase & point_locator,

0 commit comments

Comments
 (0)