Skip to content

Commit db91a1f

Browse files
committed
Refactor to use forward declarations and revert periodic neighbor logic
- Moved new MeshBase functions out of the header to use forward declarations, reducing unnecessary includes. - Reverted the PeriodicBoundaries::neighbor() logic to allow self-matching, since the existing boundary ID check already prevents unintended self-detections in periodic boundary cases.
1 parent 120b7c1 commit db91a1f

File tree

6 files changed

+70
-47
lines changed

6 files changed

+70
-47
lines changed

include/base/periodic_boundaries.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ class PeriodicBoundaries : public std::map<boundary_id_type, std::unique_ptr<Per
6868
const PointLocatorBase & point_locator,
6969
const Elem * e,
7070
unsigned int side,
71-
unsigned int * neigh_side = nullptr,
72-
bool skip_found_check = false) const;
71+
unsigned int * neigh_side = nullptr) const;
7372
};
7473

7574
} // namespace libMesh

include/mesh/mesh_base.h

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@
3737
#include <memory>
3838

3939
// periodic boundary condition support
40-
#include "libmesh/periodic_boundaries.h"
41-
#include "libmesh/periodic_boundary.h"
40+
// Use forward declarations inside the libMesh namespace
41+
namespace libMesh
42+
{
43+
class PeriodicBoundary;
44+
class PeriodicBoundaries;
45+
}
4246

4347
namespace libMesh
4448
{
@@ -1829,35 +1833,11 @@ class MeshBase : public ParallelObject
18291833
* Register a pair of boundaries as disconnected boundaries.
18301834
*/
18311835
void add_disconnected_boundaries(const boundary_id_type b1,
1832-
const boundary_id_type b2)
1833-
{
1834-
// Lazily allocate the container the first time it’s needed
1835-
if (!_disconnected_boundary_pairs)
1836-
_disconnected_boundary_pairs = std::make_unique<PeriodicBoundaries>();
1837-
1838-
// Create forward and inverse boundary mappings
1839-
PeriodicBoundary forward(RealVectorValue(0., 0., 0.));
1840-
PeriodicBoundary inverse(RealVectorValue(0., 0., 0.));
1841-
1842-
forward.myboundary = b1;
1843-
forward.pairedboundary = b2;
1844-
inverse.myboundary = b2;
1845-
inverse.pairedboundary = b1;
1846-
1847-
// Add both directions into the container
1848-
_disconnected_boundary_pairs->emplace(b1, forward.clone());
1849-
_disconnected_boundary_pairs->emplace(b2, inverse.clone());
1850-
}
1851-
1852-
PeriodicBoundaries * get_disconnected_boundaries()
1853-
{
1854-
return _disconnected_boundary_pairs.get();
1855-
}
1856-
1857-
const PeriodicBoundaries * get_disconnected_boundaries() const
1858-
{
1859-
return _disconnected_boundary_pairs.get();
1860-
}
1836+
const boundary_id_type b2);
1837+
1838+
PeriodicBoundaries * get_disconnected_boundaries();
1839+
1840+
const PeriodicBoundaries * get_disconnected_boundaries() const;
18611841
#endif
18621842

18631843

src/base/periodic_boundaries.C

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ const Elem * PeriodicBoundaries::neighbor(boundary_id_type boundary_id,
6060
const PointLocatorBase & point_locator,
6161
const Elem * e,
6262
unsigned int side,
63-
unsigned int * neigh_side,
64-
bool skip_found_check) const
63+
unsigned int * neigh_side) const
6564
{
6665
std::unique_ptr<const Elem> neigh_side_proxy;
6766

@@ -82,9 +81,6 @@ const Elem * PeriodicBoundaries::neighbor(boundary_id_type boundary_id,
8281
for(const Elem * elem_it : candidate_elements)
8382
{
8483

85-
if (elem_it == e) // skip self
86-
continue;
87-
8884
std::vector<unsigned int> neigh_sides =
8985
mesh.get_boundary_info().sides_with_boundary_id(elem_it, b->pairedboundary);
9086

@@ -106,13 +102,12 @@ const Elem * PeriodicBoundaries::neighbor(boundary_id_type boundary_id,
106102
}
107103
}
108104

109-
if (!skip_found_check)
110-
// If we should have found a periodic neighbor but didn't then
111-
// either we're on a ghosted element with a remote periodic neighbor
112-
// or we're on a mesh with an inconsistent periodic boundary.
113-
libmesh_error_msg_if(mesh.is_serial() ||
114-
(e->processor_id() == mesh.processor_id()),
115-
"Periodic boundary neighbor not found");
105+
// If we should have found a periodic neighbor but didn't then
106+
// either we're on a ghosted element with a remote periodic neighbor
107+
// or we're on a mesh with an inconsistent periodic boundary.
108+
libmesh_error_msg_if(mesh.is_serial() ||
109+
(e->processor_id() == mesh.processor_id()),
110+
"Periodic boundary neighbor not found");
116111

117112
if (neigh_side)
118113
*neigh_side = libMesh::invalid_uint;

src/mesh/mesh_base.C

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
#include <sstream> // for std::ostringstream
5050
#include <unordered_map>
5151

52+
#include "libmesh/periodic_boundaries.h"
53+
#include "libmesh/periodic_boundary.h"
54+
55+
5256
namespace libMesh
5357
{
5458

@@ -1953,6 +1957,44 @@ void MeshBase::detect_interior_parents()
19531957

19541958

19551959

1960+
#ifdef LIBMESH_ENABLE_PERIODIC
1961+
/**
1962+
* Register a pair of boundaries as disconnected boundaries.
1963+
*/
1964+
void MeshBase::add_disconnected_boundaries(const boundary_id_type b1,
1965+
const boundary_id_type b2)
1966+
{
1967+
// Lazily allocate the container the first time it’s needed
1968+
if (!_disconnected_boundary_pairs)
1969+
_disconnected_boundary_pairs = std::make_unique<PeriodicBoundaries>();
1970+
1971+
// Create forward and inverse boundary mappings
1972+
PeriodicBoundary forward(RealVectorValue(0., 0., 0.));
1973+
PeriodicBoundary inverse(RealVectorValue(0., 0., 0.));
1974+
1975+
forward.myboundary = b1;
1976+
forward.pairedboundary = b2;
1977+
inverse.myboundary = b2;
1978+
inverse.pairedboundary = b1;
1979+
1980+
// Add both directions into the container
1981+
_disconnected_boundary_pairs->emplace(b1, forward.clone());
1982+
_disconnected_boundary_pairs->emplace(b2, inverse.clone());
1983+
}
1984+
1985+
PeriodicBoundaries * MeshBase::get_disconnected_boundaries()
1986+
{
1987+
return _disconnected_boundary_pairs.get();
1988+
}
1989+
1990+
const PeriodicBoundaries * MeshBase::get_disconnected_boundaries() const
1991+
{
1992+
return _disconnected_boundary_pairs.get();
1993+
}
1994+
#endif
1995+
1996+
1997+
19561998
void MeshBase::set_point_locator_close_to_point_tol(Real val)
19571999
{
19582000
_point_locator_close_to_point_tol = val;

src/mesh/unstructured_mesh.C

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
#include <sstream>
4848
#include <unordered_map>
4949

50+
// for disconnected neighbors
51+
#include "libmesh/periodic_boundaries.h"
52+
#include "libmesh/periodic_boundary.h"
53+
5054
namespace {
5155

5256
using namespace libMesh;
@@ -1015,8 +1019,11 @@ void UnstructuredMesh::find_neighbors (const bool reset_remote_elements,
10151019

10161020
for (const auto & [id, boundary_ptr] : *db)
10171021
{
1022+
if (!this->get_boundary_info().has_boundary_id(element, ms, id))
1023+
continue;
1024+
10181025
unsigned int neigh_side;
1019-
const Elem * neigh = db->neighbor(id, *point_locator, element, ms, &neigh_side, true /*skip_found_check*/);
1026+
const Elem * neigh = db->neighbor(id, *point_locator, element, ms, &neigh_side);
10201027
if (neigh && neigh != remote_elem && neigh != element)
10211028
{
10221029
element->set_neighbor(ms, this->elem_ptr(neigh->id()));

tests/systems/disconnected_neighbor_test.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ private:
286286
es.init();
287287
sys.solve();
288288

289-
ExodusII_IO(mesh).write_equation_systems("temperature_jump.e", es);
289+
// ExodusII_IO(mesh).write_equation_systems("temperature_jump.e", es);
290290

291291
Parameters params;
292292

0 commit comments

Comments
 (0)