Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
bb7f530
Initial implementation of the XDG mesh
pshriwise Feb 3, 2026
e722e0d
Accounting for XDGMesh when creating MeshFilters
pshriwise Feb 4, 2026
04b9573
Updating call to XDG for element connectivity
pshriwise Feb 6, 2026
b7b5924
Adding XDG unstructured mesh tallies mirroring those of the current u…
pshriwise Feb 9, 2026
752fae5
Use explicit name for kwarg for clarity
pshriwise Feb 10, 2026
0fb73d0
Report XDG availability in build info
pshriwise Mar 13, 2026
1ceba8d
Only set libmesh comms in XDG if it has libMesh enabled
pshriwise Mar 13, 2026
834701c
Adding XDG to CI builds. MOAB and libMesh should be built if XDG is e…
pshriwise Mar 13, 2026
4679ffb
Adding init files for proper test discovery with pytest
pshriwise Mar 13, 2026
c8313d6
Update submodules when cloning XDG in CI
pshriwise Mar 13, 2026
1180069
Add XDG to the OpenMC CMake config file
pshriwise Mar 15, 2026
106ea52
Adding more test scenarios for XDG meshes
pshriwise Mar 15, 2026
49f9c65
More descriptive test labels
pshriwise Mar 15, 2026
14b9890
Returning const string ref for mesh filename
pshriwise Mar 18, 2026
0638957
C++ style
pshriwise Mar 18, 2026
d15dba6
Apply suggestions from @nuclearkevin
pshriwise Mar 21, 2026
ab183b2
Fix includes in xdg.h/cpp
paulromano May 21, 2026
aceaf56
Add some Doxygen comments in xdg.h
paulromano May 21, 2026
72578de
Reorder methods
paulromano May 21, 2026
657fe94
Python imports
paulromano May 21, 2026
5ab893b
Remove extra line
paulromano May 21, 2026
a1fc3b6
Combined two #ifdefs
paulromano May 21, 2026
1797bf5
Rename local variable to center to avoid same name as method
paulromano May 22, 2026
e29b315
Test updates
paulromano May 22, 2026
4932c75
Use pathlib in test
paulromano May 22, 2026
9913cff
Fix circular import
paulromano May 22, 2026
8fcddd7
Lump unstructured mesh capabilities into one CI matrix parameter
pshriwise Jun 9, 2026
41e96ca
A start on @paulromano's PR comments
pshriwise Jun 9, 2026
5fccdd4
Adressing more comments from @paulromano
pshriwise Jun 10, 2026
74e07f5
Update XDG and unstructured mesh tests to use a distributed spherical…
pshriwise Jun 10, 2026
b4ddd48
Report error for invalid mesh library type in XDG mesh
pshriwise Jun 10, 2026
021381f
Classify XDG as its own mesh type on the C++ side
pshriwise Jun 11, 2026
da1b67f
Include Embree apt package in CI for XDG
pshriwise Jul 3, 2026
3cec4e2
C++ format
pshriwise Jul 3, 2026
d570e85
Correct test matrix attribute. Build XDG with tools enabled in CI.
pshriwise Jul 3, 2026
9910364
Update CI matrix to remove additional DAGMC/LibMesh jobs
pshriwise Jul 8, 2026
34c66dd
Additions so that XDG meshes can be postprocessed correctly
pshriwise Jul 8, 2026
2bea0b3
Run XDG tests if XDG is enabled, do not filter based on other umesn l…
pshriwise Jul 15, 2026
2d8a708
Add support for length multiplier in the XDGMesh class
pshriwise Jul 16, 2026
ba5908d
XDGMesh Python class now inheriting from UnstructuredMesh
pshriwise Jul 16, 2026
cc88d08
Fix C++ formatting
pshriwise Jul 16, 2026
b45bfdd
Using marker UnstructuredMesh.interface to enable direction to XDG me…
pshriwise Jul 17, 2026
cb4b90f
Remove xdg.py file. It is now unused
pshriwise Jul 17, 2026
644f86a
C++ formatting
pshriwise Jul 17, 2026
665b095
Remove other references to the XDGMesh Python class
pshriwise Jul 17, 2026
b057de3
Correct attr name for unstructured mesh interface
pshriwise Jul 17, 2026
d898d86
Other instances of consolidating xdg mesh support into the Unstructur…
pshriwise Aug 11, 2026
5a65353
Update regression tests to include XDG mesh type
pshriwise Aug 11, 2026
07e85e7
Including XDG hex mesh tests
pshriwise Aug 19, 2026
5cb30d8
Link XDG to libopenmc_objects target
pshriwise Aug 21, 2026
937685c
Add XDG option to the CAPI feature_enabled function
pshriwise Aug 21, 2026
07064a4
Adjust incoming position for bins_crossed if length multiplier is set
pshriwise Aug 21, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ jobs:
python-version: ["3.12"]
mpi: [n, y]
omp: [n, y]
dagmc: [n]
libmesh: [n]
event: [n]

include:
Expand All @@ -60,33 +58,26 @@ jobs:
- python-version: "3.14t"
omp: n
mpi: n
- dagmc: y
python-version: "3.12"
mpi: y
omp: y
- libmesh: y
python-version: "3.12"
mpi: y
omp: y
- libmesh: y
python-version: "3.12"
- python-version: "3.12"
omp: n
mpi: n
omp: y
umesh_libs: y
- event: y
python-version: "3.12"
omp: y
mpi: n
name: "Python ${{ matrix.python-version }} (omp=${{ matrix.omp }},
mpi=${{ matrix.mpi }}, dagmc=${{ matrix.dagmc }},
libmesh=${{ matrix.libmesh }}, event=${{ matrix.event }}"
mpi=${{ matrix.mpi }}, umesh_libs=${{ matrix.umesh_libs }},
event=${{ matrix.event }}"

env:
MPI: ${{ matrix.mpi }}
PHDF5: ${{ matrix.mpi }}
OMP: ${{ matrix.omp }}
DAGMC: ${{ matrix.dagmc }}
DAGMC: ${{ matrix.umesh_libs }}
XDG: ${{ matrix.umesh_libs }}
EVENT: ${{ matrix.event }}
LIBMESH: ${{ matrix.libmesh }}
LIBMESH: ${{ matrix.umesh_libs }}
NPY_DISABLE_CPU_FEATURES: "AVX512F AVX512_SKX"
OPENBLAS_NUM_THREADS: 1
PYTEST_ADDOPTS: --cov=openmc --cov-report=lcov:coverage-python.lcov
Expand Down Expand Up @@ -146,6 +137,12 @@ jobs:
sudo update-alternatives --set mpirun /usr/bin/mpirun.mpich
sudo update-alternatives --set mpi-x86_64-linux-gnu /usr/include/x86_64-linux-gnu/mpich

- name: Optional apt dependencies for XDG
shell: bash
if: ${{ matrix.umesh_libs == 'y' }}
run: |
sudo apt install -y libembree-dev

- name: install
shell: bash
run: |
Expand Down
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ option(OPENMC_BUILD_TESTS "Build tests"
option(OPENMC_ENABLE_PROFILE "Compile with profiling flags" OFF)
option(OPENMC_ENABLE_COVERAGE "Compile with coverage analysis flags" OFF)
option(OPENMC_USE_DAGMC "Enable support for DAGMC (CAD) geometry" OFF)
option(OPENMC_USE_XDG "Enable support for XDG discretized CAD geometry" OFF)
option(OPENMC_USE_LIBMESH "Enable support for libMesh unstructured mesh tallies" OFF)
option(OPENMC_USE_MPI "Enable MPI" OFF)
option(OPENMC_USE_UWUW "Enable UWUW" OFF)
Expand Down Expand Up @@ -173,6 +174,15 @@ if(OPENMC_USE_DAGMC)
endif()
endif()

#===============================================================================
# XDG Mesh and Geometry Support
#===============================================================================

if(OPENMC_USE_XDG)
find_package(XDG REQUIRED PATH_SUFFIXES lib/cmake)
message(STATUS "Found XDG: ${XDG_DIR} (version ${XDG_VERSION})")
endif()

#===============================================================================
# libMesh Unstructured Mesh Support
#===============================================================================
Expand Down Expand Up @@ -445,6 +455,7 @@ list(APPEND libopenmc_SOURCES
src/string_utils.cpp
src/summary.cpp
src/surface.cpp
src/xdg.cpp
src/tallies/derivative.cpp
src/tallies/filter.cpp
src/tallies/filter_azimuthal.cpp
Expand Down Expand Up @@ -580,6 +591,11 @@ elseif(OPENMC_USE_UWUW)
message(FATAL_ERROR "DAGMC must be enabled when UWUW is enabled.")
endif()

if(OPENMC_USE_XDG)
target_compile_definitions(libopenmc_objects PRIVATE OPENMC_XDG_ENABLED)
target_link_libraries(libopenmc_objects PUBLIC xdg::xdg)
endif()

if(OPENMC_USE_LIBMESH)
target_compile_definitions(libopenmc_objects PRIVATE OPENMC_LIBMESH_ENABLED)
target_link_libraries(libopenmc_objects PUBLIC PkgConfig::LIBMESH)
Expand Down
4 changes: 4 additions & 0 deletions cmake/OpenMCConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ if("@PNG_FOUND@")
find_dependency(PNG)
endif()

if(@OPENMC_USE_XDG@)
find_dependency(XDG REQUIRED HINTS @XDG_DIR@)
endif()

if(@OPENMC_USE_MPI@)
find_dependency(MPI REQUIRED)
endif()
Expand Down
40 changes: 37 additions & 3 deletions include/openmc/mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ class Mesh {

// Factory method for creating meshes from either an XML node or HDF5 group
template<typename T>
static const std::unique_ptr<Mesh>& create(
T dataset, const std::string& mesh_type, const std::string& mesh_library);
static const std::unique_ptr<Mesh>& create(T dataset);

// Methods
//! Perform any preparation needed to support point location within the mesh
Expand Down Expand Up @@ -721,6 +720,9 @@ class SphericalMesh : public PeriodicStructuredMesh {
class UnstructuredMesh : public Mesh {

public:
template<typename T>
static std::unique_ptr<UnstructuredMesh> create(T dataset);

// Constructors
UnstructuredMesh() { n_dimension_ = 3; };
UnstructuredMesh(pugi::xml_node node);
Expand Down Expand Up @@ -782,6 +784,9 @@ class UnstructuredMesh : public Mesh {
//! Get the library used for this unstructured mesh
virtual std::string library() const = 0;

//! Get the mesh filename
virtual const std::string& filename() const { return filename_; }

// Data members
bool output_ {
true}; //!< Write tallies onto the unstructured mesh at the end of a run
Expand All @@ -808,7 +813,36 @@ class UnstructuredMesh : public Mesh {
//! \param[in] coords Coordinates of the tetrahedron
//! \param[in] seed Random number generation seed
//! \return Sampled position within the tetrahedron
Position sample_tet(std::array<Position, 4> coords, uint64_t* seed) const;
template<typename V>
Position sample_tet(span<V> coords, uint64_t* seed) const
{
// Uniform distribution
double s = prn(seed);
double t = prn(seed);
double u = prn(seed);

// From PyNE implementation of moab tet sampling C. Rocchini & P. Cignoni
// (2000) Generating Random Points in a Tetrahedron, Journal of Graphics
// Tools, 5:4, 9-12, DOI: 10.1080/10867651.2000.10487528
if (s + t > 1) {
s = 1.0 - s;
t = 1.0 - t;
}
if (s + t + u > 1) {
if (t + u > 1) {
double old_t = t;
t = 1.0 - u;
u = 1.0 - s - old_t;
} else if (t + u <= 1) {
double old_s = s;
s = 1.0 - t - u;
u = old_s + t + u - 1;
}
}
V result = s * (coords[1] - coords[0]) + t * (coords[2] - coords[0]) +
u * (coords[3] - coords[0]) + coords[0];
return {result[0], result[1], result[2]};
}

// Data members
double length_multiplier_ {
Expand Down
125 changes: 125 additions & 0 deletions include/openmc/xdg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#ifndef OPENMC_XDG_H
#define OPENMC_XDG_H

namespace openmc {
extern "C" const bool XDG_ENABLED;
}

#ifdef OPENMC_XDG_ENABLED

#include "xdg/xdg.h"

#include "openmc/mesh.h"
#include "openmc/position.h"
#include "openmc/xml_interface.h"

namespace openmc {

class XDGMesh : public UnstructuredMesh {

public:
//----------------------------------------------------------------------------
// Constructors
XDGMesh() = default;
XDGMesh(pugi::xml_node node);
XDGMesh(hid_t group);
XDGMesh(const std::string& filename, double length_multiplier = 1.0);
XDGMesh(std::shared_ptr<xdg::XDG> external_xdg);

static const std::string mesh_type;

//----------------------------------------------------------------------------
// Methods

//! Get the underlying XDG instance
//!
//! \return Shared pointer to the XDG instance
const std::shared_ptr<xdg::XDG>& xdg_instance() const { return xdg_; }

//! Check whether a bin index is valid
//!
//! \param[in] bin Bin index to check
//! \return True if the bin index is in [0, n_bins())
bool bin_is_valid(int bin) const { return bin >= 0 && bin < n_bins(); }

std::string get_mesh_type() const override { return mesh_type; }

//! Convert a mesh bin index to an XDG MeshID
//!
//! \param[in] bin Bin index to convert
//! \return XDG MeshID corresponding to the bin
xdg::MeshID bin_to_mesh_id(int bin) const;

//! Convert an XDG MeshID to a mesh bin index
//!
//! \param[in] id XDG MeshID to convert
//! \return Bin index corresponding to the MeshID, or -1 if invalid
int mesh_id_to_bin(xdg::MeshID id) const;

//! Get the name of the underlying mesh library
//!
//! \return Name of the mesh library being used in XDG
std::string library() const override;

//----------------------------------------------------------------------------
// Overridden Methods

//! Perform any preparation needed to support use in mesh filters
void prepare_for_point_location() override;

Position sample_element(int32_t bin, uint64_t* seed) const override;

void bins_crossed(Position r0, Position r1, const Direction& u,
vector<int>& bins, vector<double>& lengths) const override;

int get_bin(Position r) const override;

int n_bins() const override;

int n_surface_bins() const override;

std::pair<vector<double>, vector<double>> plot(
Position plot_ll, Position plot_ur) const override;

//! Add a score to the mesh instance
void add_score(const std::string& score) override {};

//! Remove all scores from the mesh instance
void remove_scores() override {};

//! Set data for a score
void set_score_data(const std::string& score, const vector<double>& values,
const vector<double>& std_dev) override {};

//! Write the mesh with any current tally data
void write(const std::string& base_filename) const override;

Position centroid(int bin) const override;

int n_vertices() const override;

Position vertex(int id) const override;

std::vector<int> connectivity(int id) const override;

//! Get the volume of a mesh bin
//
//! \param[in] bin Bin to return the volume for
//! \return Volume of the bin
double volume(int bin) const override;

private:
void initialize() override;

//----------------------------------------------------------------------------
// Private data members
std::shared_ptr<xdg::XDG> xdg_; //!< XDG instance
xdg::MeshLibrary mesh_library_ {
xdg::MeshLibrary::LIBMESH}; //!< Mesh library type
};

} // namespace openmc

#endif // OPENMC_XDG_ENABLED

#endif // OPENMC_XDG_H
3 changes: 3 additions & 0 deletions openmc/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def feature_enabled(feature: str) -> bool:
return enabled.value


def _xdg_enabled():
return c_bool.in_dll(_dll, "XDG_ENABLED").value

def _coord_levels():
return c_int.in_dll(_dll, "n_coord_levels").value

Expand Down
Loading
Loading