From 958fef396606c42e0bc361af4c5711f3280a7542 Mon Sep 17 00:00:00 2001 From: magnoxemo Date: Sat, 9 May 2026 14:18:17 -0500 Subject: [PATCH 01/11] setting build files --- CMakeLists.txt | 8 ++++++++ examples/CMakeLists.txt | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 examples/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index fb762521..edb31857 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ option(XDG_ENABLE_EMBREE "Enable support for the Embree ray tracing library" ON option(XDG_ENABLE_GPRT "Enable support for the GPRT ray tracing library" OFF) option(XDG_BUILD_TESTS "Enable C++ unit testing" ON) option(XDG_BUILD_TOOLS "Enable tools and miniapps" ON) +option(XDG_BUILD_EXAMPLES "Enable C++ examples" ON) # Set version numbers set(XDG_VERSION_MAJOR 0) @@ -26,6 +27,13 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) # Set module path set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules) +#============================================================================ +# If we want to build examples +#============================================================================ +if(XDG_BUILD_EXAMPLES) + add_subdirectory(examples) +endif () + #=============================================================================== # libMesh #=============================================================================== diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 00000000..01dc9479 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,18 @@ +# ============================================================================= +# Examples for how to use XDG C++ APIs +# ============================================================================= + +function(xdg_add_examples name source) + add_executable(${name} ${source}) + if (XDG_ENABLE_LIBMESH) + target_link_libraries(${test} PRIVATE ${LIBMESH_LINK_LIBRARIES}) + endif() + if (XDG_ENABLE_GPRT) + target_link_libraries(${test} PRIVATE $) + endif() + if (XDG_ENABLE_MOAB) + target_link_libraries(${test} PRIVATE MOAB) + endif() +endfunction() + + From b98aa8db629fd7cc88f4490dbcd45e3767a94d8d Mon Sep 17 00:00:00 2001 From: magnoxemo Date: Sat, 9 May 2026 19:40:43 -0500 Subject: [PATCH 02/11] using compiler directive to determinte which mesh manager to use to avoid creating seperate examples for different mesh managers --- examples/ray_segments.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 examples/ray_segments.cpp diff --git a/examples/ray_segments.cpp b/examples/ray_segments.cpp new file mode 100644 index 00000000..7789dd61 --- /dev/null +++ b/examples/ray_segments.cpp @@ -0,0 +1,23 @@ +#include +#include +#include +#include + +#include "xdg/xdg.h" +#include "xdg/constants.h" +#include "xdg/mesh_managers.h" + +int main(int argc, char* argv[]) +{ + +#if defined(XDG_ENABLE_MOAB) + auto mesh_manager = std::make_shared(); + mesh_manager->load_file("cube.h5m"); +#elif defined(XDG_ENABLE_LIBMESH) + auto mesh_manager = std::make_shared(); + mesh_manager->load_file("brick.exo"); +#endif + + mesh_manager->init(); + +} \ No newline at end of file From d092b43d86b347d21bc1c5eb67c5676a4f49bc58 Mon Sep 17 00:00:00 2001 From: magnoxemo Date: Sat, 9 May 2026 20:04:12 -0500 Subject: [PATCH 03/11] fix cmake build file to allow CI to compile this example --- examples/CMakeLists.txt | 1 + examples/ray_segments.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 01dc9479..40608cce 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -16,3 +16,4 @@ function(xdg_add_examples name source) endfunction() +xdg_add_examples(ray_segments_example ray_segments.cpp) \ No newline at end of file diff --git a/examples/ray_segments.cpp b/examples/ray_segments.cpp index 7789dd61..87520c0a 100644 --- a/examples/ray_segments.cpp +++ b/examples/ray_segments.cpp @@ -9,13 +9,14 @@ int main(int argc, char* argv[]) { - + // Not sure if this is the best way but based on CI matrix in the event + // where MOAB and LibMesh both defined we are gonna end up using MOAB mesh manager #if defined(XDG_ENABLE_MOAB) auto mesh_manager = std::make_shared(); - mesh_manager->load_file("cube.h5m"); + mesh_manager->load_file("tests/cube.h5m"); // using existing test files #elif defined(XDG_ENABLE_LIBMESH) auto mesh_manager = std::make_shared(); - mesh_manager->load_file("brick.exo"); + mesh_manager->load_file("tests/brick.exo"); // using existing test files #endif mesh_manager->init(); From 44a254a43824bf468c761e88485bc25cd77d09d7 Mon Sep 17 00:00:00 2001 From: magnoxemo Date: Sat, 9 May 2026 20:18:24 -0500 Subject: [PATCH 04/11] fix CMake --- examples/CMakeLists.txt | 23 +++++++++++++++++++---- examples/ray_segments.cpp | 4 ++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 40608cce..ee16843d 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -4,16 +4,31 @@ function(xdg_add_examples name source) add_executable(${name} ${source}) + target_link_libraries(${name} PRIVATE xdg fmt::fmt) if (XDG_ENABLE_LIBMESH) - target_link_libraries(${test} PRIVATE ${LIBMESH_LINK_LIBRARIES}) + target_link_libraries(${name} PRIVATE ${LIBMESH_LINK_LIBRARIES}) endif() if (XDG_ENABLE_GPRT) - target_link_libraries(${test} PRIVATE $) + target_link_libraries(${name} PRIVATE $) endif() if (XDG_ENABLE_MOAB) - target_link_libraries(${test} PRIVATE MOAB) + target_link_libraries(${name} PRIVATE MOAB) endif() + set_target_properties(${name} PROPERTIES + BUILD_RPATH "$") endfunction() -xdg_add_examples(ray_segments_example ray_segments.cpp) \ No newline at end of file +xdg_add_examples(ray_segments_example ray_segments.cpp) + +set(EXAMPLE_MESH_FILES + cube.h5m + brick.exo +) + +foreach(file ${EXAMPLE_MESH_FILES}) + ADD_CUSTOM_TARGET(example_${file} ALL + COMMAND ${CMAKE_COMMAND} -E create_symlink + "${CMAKE_SOURCE_DIR}/tests/test_files/${file}" + "${CMAKE_CURRENT_BINARY_DIR}/${file}") +endforeach() \ No newline at end of file diff --git a/examples/ray_segments.cpp b/examples/ray_segments.cpp index 87520c0a..9ed217c6 100644 --- a/examples/ray_segments.cpp +++ b/examples/ray_segments.cpp @@ -13,10 +13,10 @@ int main(int argc, char* argv[]) // where MOAB and LibMesh both defined we are gonna end up using MOAB mesh manager #if defined(XDG_ENABLE_MOAB) auto mesh_manager = std::make_shared(); - mesh_manager->load_file("tests/cube.h5m"); // using existing test files + mesh_manager->load_file("cube.h5m"); #elif defined(XDG_ENABLE_LIBMESH) auto mesh_manager = std::make_shared(); - mesh_manager->load_file("tests/brick.exo"); // using existing test files + mesh_manager->load_file("brick.exo"); #endif mesh_manager->init(); From 8b19cfb76b1b1dbb321a03d2fa1fb2fb5bbf1399 Mon Sep 17 00:00:00 2001 From: magnoxemo Date: Sat, 9 May 2026 20:51:33 -0500 Subject: [PATCH 05/11] fixing CMake (hope fully) and adding the whole example --- examples/CMakeLists.txt | 1 + examples/ray_segments.cpp | 45 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index ee16843d..fa9f7ecd 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -12,6 +12,7 @@ function(xdg_add_examples name source) target_link_libraries(${name} PRIVATE $) endif() if (XDG_ENABLE_MOAB) + target_include_directories(${name} PRIVATE $) target_link_libraries(${name} PRIVATE MOAB) endif() set_target_properties(${name} PROPERTIES diff --git a/examples/ray_segments.cpp b/examples/ray_segments.cpp index 9ed217c6..ee5bd1e5 100644 --- a/examples/ray_segments.cpp +++ b/examples/ray_segments.cpp @@ -13,12 +13,53 @@ int main(int argc, char* argv[]) // where MOAB and LibMesh both defined we are gonna end up using MOAB mesh manager #if defined(XDG_ENABLE_MOAB) auto mesh_manager = std::make_shared(); - mesh_manager->load_file("cube.h5m"); + mesh_manager->load_file("cube.h5m"); // Provide the path to your mesh file. #elif defined(XDG_ENABLE_LIBMESH) auto mesh_manager = std::make_shared(); - mesh_manager->load_file("brick.exo"); + mesh_manager->load_file("brick.exo"); // Provide the path to your mesh file. #endif mesh_manager->init(); + // by default, we are using Embree as a ray tracer + auto xdg_instance = std::make_shared(mesh_manager); + xdg_instance->prepare_raytracer(); + + xdg::BoundingBox bbox = mesh_manager->global_bounding_box(); + + std::mt19937 gen(42); + std::uniform_real_distribution x_dist(bbox.min_x, bbox.max_x); + std::uniform_real_distribution y_dist(bbox.min_y, bbox.max_y); + std::uniform_real_distribution z_dist(bbox.min_z, bbox.max_z); + + constexpr size_t number_of_rays = 10000; + + for (size_t i = 0; i < number_of_rays; ++i) + { + xdg::Position start = {x_dist(gen), y_dist(gen), z_dist(gen)}; + xdg::Position end = {x_dist(gen), y_dist(gen), z_dist(gen)}; + + // xdg returns MeshID (or the element ID) of the elements it has intersected and + // ray segments associated with element. + std::vector> track_segments = xdg_instance->segments(start, end); + + double total_length = std::accumulate(track_segments.begin(), track_segments.end(), 0.0, + [](double sum, const std::pair& seg) { + return sum + seg.second; + }); + + double ref_distance = (end - start).length(); + + double error_pct = (ref_distance > 0.0) + ? (total_length - ref_distance) * 100.0 / ref_distance + : 0.0; + + std::cout + << "Elements hit = " << std::setw(4) << track_segments.size() + << " ref dist = " << std::fixed << std::setprecision(6) << ref_distance + << " xdg dist = " << total_length + << " error = " << std::setprecision(4) << error_pct << " %\n"; + } + + return 0; } \ No newline at end of file From 16eef4bececbcbd0547edcc43887f1c4abb69eed Mon Sep 17 00:00:00 2001 From: magnoxemo Date: Sat, 9 May 2026 21:05:05 -0500 Subject: [PATCH 06/11] don't add example subdir before moab is found --- CMakeLists.txt | 13 +++++++------ examples/CMakeLists.txt | 1 - examples/ray_segments.cpp | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index edb31857..e3a86c41 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,12 +27,6 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) # Set module path set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules) -#============================================================================ -# If we want to build examples -#============================================================================ -if(XDG_BUILD_EXAMPLES) - add_subdirectory(examples) -endif () #=============================================================================== # libMesh @@ -77,6 +71,13 @@ if (XDG_ENABLE_EMBREE) message(STATUS "Found Embree ${EMBREE_VERSION} at ${EMBREE_ROOT_DIR}") endif() +#============================================================================ +# If we want to build examples +#============================================================================ +if(XDG_BUILD_EXAMPLES) + add_subdirectory(examples) +endif () + #=============================================================================== # Update git submodules as needed (borrowed from OpenMC) #=============================================================================== diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index fa9f7ecd..ee16843d 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -12,7 +12,6 @@ function(xdg_add_examples name source) target_link_libraries(${name} PRIVATE $) endif() if (XDG_ENABLE_MOAB) - target_include_directories(${name} PRIVATE $) target_link_libraries(${name} PRIVATE MOAB) endif() set_target_properties(${name} PROPERTIES diff --git a/examples/ray_segments.cpp b/examples/ray_segments.cpp index ee5bd1e5..dd24b249 100644 --- a/examples/ray_segments.cpp +++ b/examples/ray_segments.cpp @@ -41,7 +41,7 @@ int main(int argc, char* argv[]) // xdg returns MeshID (or the element ID) of the elements it has intersected and // ray segments associated with element. - std::vector> track_segments = xdg_instance->segments(start, end); + std::vector> track_segments = xdg_instance->segments(start, end); double total_length = std::accumulate(track_segments.begin(), track_segments.end(), 0.0, [](double sum, const std::pair& seg) { From 25fc1143cd2c83592daf775d206568d0663e2b7b Mon Sep 17 00:00:00 2001 From: Ebny Walid Ahammed <69362074+magnoxemo@users.noreply.github.com> Date: Mon, 11 May 2026 09:33:46 -0500 Subject: [PATCH 07/11] Update examples/ray_segments.cpp Co-authored-by: Waqar Butt <114666466+Waqar-ukaea@users.noreply.github.com> --- examples/ray_segments.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/examples/ray_segments.cpp b/examples/ray_segments.cpp index dd24b249..27008f5c 100644 --- a/examples/ray_segments.cpp +++ b/examples/ray_segments.cpp @@ -9,21 +9,21 @@ int main(int argc, char* argv[]) { - // Not sure if this is the best way but based on CI matrix in the event - // where MOAB and LibMesh both defined we are gonna end up using MOAB mesh manager -#if defined(XDG_ENABLE_MOAB) - auto mesh_manager = std::make_shared(); - mesh_manager->load_file("cube.h5m"); // Provide the path to your mesh file. -#elif defined(XDG_ENABLE_LIBMESH) - auto mesh_manager = std::make_shared(); - mesh_manager->load_file("brick.exo"); // Provide the path to your mesh file. -#endif +// Read in your mesh file +// Do whatever logic you need to decide whether you want to use xdg with MOAB or libmesh +// Use xdg factory method XDG::create() - if no libraries specified it defaults to MOAB + embree +if (use_moab) { + std::shared_ptr xdg = XDG::create(xdg::MeshLibrary::MOAB, xdg::RTLibrary::EMBREE); +else { + std::shared_ptr xdg = XDG::create(xdg::MeshLibrary::LIBMESH, xdg::RTLibrary::EMBREE); +} - mesh_manager->init(); +// Then we can recover the mesh manager object abstractly without needing to specify the derived mesh manager classes (and thus removing the need for the pre-compile guards) +const auto& mesh_manager = xdg->mesh_manager(); +mesh_manager->load_file(filename); +mesh_manager->init(); - // by default, we are using Embree as a ray tracer - auto xdg_instance = std::make_shared(mesh_manager); - xdg_instance->prepare_raytracer(); +xdg->prepare_raytracer(); xdg::BoundingBox bbox = mesh_manager->global_bounding_box(); From 77a991ff54fbcb930b1b25b0604555b703314fb0 Mon Sep 17 00:00:00 2001 From: magnoxemo Date: Mon, 11 May 2026 10:04:48 -0500 Subject: [PATCH 08/11] adding argument parser and set up CLI args to determine which mesh+RT lib to use --- examples/ray_segments.cpp | 66 ++++++++++++++++++++++++++++++--------- 1 file changed, 51 insertions(+), 15 deletions(-) diff --git a/examples/ray_segments.cpp b/examples/ray_segments.cpp index 27008f5c..330d4a42 100644 --- a/examples/ray_segments.cpp +++ b/examples/ray_segments.cpp @@ -6,24 +6,60 @@ #include "xdg/xdg.h" #include "xdg/constants.h" #include "xdg/mesh_managers.h" +#include "argparse/argparse.hpp" +#include "xdg/error.h" int main(int argc, char* argv[]) { -// Read in your mesh file -// Do whatever logic you need to decide whether you want to use xdg with MOAB or libmesh -// Use xdg factory method XDG::create() - if no libraries specified it defaults to MOAB + embree -if (use_moab) { - std::shared_ptr xdg = XDG::create(xdg::MeshLibrary::MOAB, xdg::RTLibrary::EMBREE); -else { - std::shared_ptr xdg = XDG::create(xdg::MeshLibrary::LIBMESH, xdg::RTLibrary::EMBREE); -} - -// Then we can recover the mesh manager object abstractly without needing to specify the derived mesh manager classes (and thus removing the need for the pre-compile guards) -const auto& mesh_manager = xdg->mesh_manager(); -mesh_manager->load_file(filename); -mesh_manager->init(); - -xdg->prepare_raytracer(); + + argparse::ArgumentParser args("An example of how to setup XDG's C++ API to calculate " + "Ray segments in a mesh ", "1.0", argparse::default_arguments::help); + + args.add_argument("-f","filename").help("Path to the mesh file"); + args.add_argument("-m", "--mesh-library").help("Mesh library to use. One of (MOAB, LIBMESH)").default_value("MOAB"); + args.add_argument("-r", "--rt-library").help("Ray tracing library to use. One of (EMBREE, GPRT)").default_value("EMBREE"); + + try { + args.parse_args(argc, argv); + } + catch (const std::runtime_error& err) { + std::cout << err.what() << std::endl; + std::cout << args; + exit(0); + } + + + const std::string mesh_lib_name = args.get("--mesh-library"); + const std::string rt_lib_name = args.get("--rt-library"); + const std::string mesh_file = args.get("filename"); + + xdg::RTLibrary rt_lib; + if (rt_lib_name == "EMBREE") + rt_lib = RTLibrary::EMBREE; + else if (rt_lib_name == "GPRT") + rt_lib = RTLibrary::GPRT; + else + xdg::fatal_error("Invalid ray tracing library '{}' specified", rt_str); + + xdg::MeshLibrary mesh_lib; + if (mesh_lib_name == "MOAB") + mesh_lib = MeshLibrary::MOAB; + else if (mesh_lib_name == "LIBMESH") { + mesh_lib = MeshLibrary::LIBMESH; + if (rt_lib == RTLibrary::GPRT) + xdg::fatal_error("LibMesh is not currently supported with GPRT"); + } + else + xdg::fatal_error("Invalid mesh library '{}' specified", mesh_lib_name); + + + std::shared_ptr xdg = XDG::create(mesh_lib, rt_lib ); + const auto& mesh_manager = xdg->mesh_manager(); + + mesh_manager->load_file(mesh_file); + mesh_manager->init(); + + xdg->prepare_raytracer(); xdg::BoundingBox bbox = mesh_manager->global_bounding_box(); From 029ac447761b1c2aac02dd91f8c95600eb24e5f2 Mon Sep 17 00:00:00 2001 From: magnoxemo Date: Tue, 12 May 2026 16:16:15 -0500 Subject: [PATCH 09/11] making it a volume estimation example --- examples/CMakeLists.txt | 30 +------- examples/element_volume_estimation.cpp | 53 +++++++++++++ examples/ray_segments.cpp | 101 ------------------------- 3 files changed, 55 insertions(+), 129 deletions(-) create mode 100644 examples/element_volume_estimation.cpp delete mode 100644 examples/ray_segments.cpp diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index ee16843d..3cc87d28 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -2,33 +2,7 @@ # Examples for how to use XDG C++ APIs # ============================================================================= -function(xdg_add_examples name source) - add_executable(${name} ${source}) - target_link_libraries(${name} PRIVATE xdg fmt::fmt) - if (XDG_ENABLE_LIBMESH) - target_link_libraries(${name} PRIVATE ${LIBMESH_LINK_LIBRARIES}) - endif() - if (XDG_ENABLE_GPRT) - target_link_libraries(${name} PRIVATE $) - endif() - if (XDG_ENABLE_MOAB) - target_link_libraries(${name} PRIVATE MOAB) - endif() - set_target_properties(${name} PROPERTIES - BUILD_RPATH "$") -endfunction() +add_executable(element_volume_estimation element_volume_estimation.cpp) +target_link_libraries(element_volume_estimation PRIVATE xdg) -xdg_add_examples(ray_segments_example ray_segments.cpp) - -set(EXAMPLE_MESH_FILES - cube.h5m - brick.exo -) - -foreach(file ${EXAMPLE_MESH_FILES}) - ADD_CUSTOM_TARGET(example_${file} ALL - COMMAND ${CMAKE_COMMAND} -E create_symlink - "${CMAKE_SOURCE_DIR}/tests/test_files/${file}" - "${CMAKE_CURRENT_BINARY_DIR}/${file}") -endforeach() \ No newline at end of file diff --git a/examples/element_volume_estimation.cpp b/examples/element_volume_estimation.cpp new file mode 100644 index 00000000..67ea792e --- /dev/null +++ b/examples/element_volume_estimation.cpp @@ -0,0 +1,53 @@ +#include +#include +#include + +#include "xdg/xdg.h" +#include "xdg/mesh_managers.h" + +int main(int argc, char* argv[]) +{ + if (argc < 2) { + std::cerr << "Usage: " << argv[0] << " \n"; + return 1; + } + const std::string mesh_file = argv[1]; + + std::shared_ptr xdg = xdg::XDG::create(); + const auto& mesh_manager = xdg->mesh_manager(); + mesh_manager->load_file(mesh_file); + mesh_manager->init(); + xdg->prepare_raytracer(); + + xdg::BoundingBox bbox = mesh_manager->global_bounding_box(); + double bbox_volume = (bbox.max_x - bbox.min_x) + * (bbox.max_y - bbox.min_y) + * (bbox.max_z - bbox.min_z); + + std::mt19937 gen(42); + std::uniform_real_distribution x_dist(bbox.min_x, bbox.max_x); + std::uniform_real_distribution y_dist(bbox.min_y, bbox.max_y); + std::uniform_real_distribution z_dist(bbox.min_z, bbox.max_z); + + constexpr size_t n_samples = 100000; + + std::cout << std::setw(10) << "Volume ID" + << std::setw(20) << "MC Volume Estimate" + << std::setw(20) << "Hits / Samples\n"; + std::cout << std::string(50, '-') << "\n"; + + for (xdg::MeshID volume : mesh_manager->volumes()) { + size_t hits = 0; + for (size_t i = 0; i < n_samples; ++i) { + xdg::Position sample = {x_dist(gen), y_dist(gen), z_dist(gen)}; + if (xdg->point_in_volume(volume, sample)) + hits++; + } + const double mc_volume = bbox_volume * static_cast(hits) / n_samples; + std::cout << std::setw(10) << volume + << std::setw(20) << std::fixed << std::setprecision(4) << mc_volume + << std::setw(14) << hits << " / " << n_samples << "\n"; + } + + return 0; +} \ No newline at end of file diff --git a/examples/ray_segments.cpp b/examples/ray_segments.cpp deleted file mode 100644 index 330d4a42..00000000 --- a/examples/ray_segments.cpp +++ /dev/null @@ -1,101 +0,0 @@ -#include -#include -#include -#include - -#include "xdg/xdg.h" -#include "xdg/constants.h" -#include "xdg/mesh_managers.h" -#include "argparse/argparse.hpp" -#include "xdg/error.h" - -int main(int argc, char* argv[]) -{ - - argparse::ArgumentParser args("An example of how to setup XDG's C++ API to calculate " - "Ray segments in a mesh ", "1.0", argparse::default_arguments::help); - - args.add_argument("-f","filename").help("Path to the mesh file"); - args.add_argument("-m", "--mesh-library").help("Mesh library to use. One of (MOAB, LIBMESH)").default_value("MOAB"); - args.add_argument("-r", "--rt-library").help("Ray tracing library to use. One of (EMBREE, GPRT)").default_value("EMBREE"); - - try { - args.parse_args(argc, argv); - } - catch (const std::runtime_error& err) { - std::cout << err.what() << std::endl; - std::cout << args; - exit(0); - } - - - const std::string mesh_lib_name = args.get("--mesh-library"); - const std::string rt_lib_name = args.get("--rt-library"); - const std::string mesh_file = args.get("filename"); - - xdg::RTLibrary rt_lib; - if (rt_lib_name == "EMBREE") - rt_lib = RTLibrary::EMBREE; - else if (rt_lib_name == "GPRT") - rt_lib = RTLibrary::GPRT; - else - xdg::fatal_error("Invalid ray tracing library '{}' specified", rt_str); - - xdg::MeshLibrary mesh_lib; - if (mesh_lib_name == "MOAB") - mesh_lib = MeshLibrary::MOAB; - else if (mesh_lib_name == "LIBMESH") { - mesh_lib = MeshLibrary::LIBMESH; - if (rt_lib == RTLibrary::GPRT) - xdg::fatal_error("LibMesh is not currently supported with GPRT"); - } - else - xdg::fatal_error("Invalid mesh library '{}' specified", mesh_lib_name); - - - std::shared_ptr xdg = XDG::create(mesh_lib, rt_lib ); - const auto& mesh_manager = xdg->mesh_manager(); - - mesh_manager->load_file(mesh_file); - mesh_manager->init(); - - xdg->prepare_raytracer(); - - xdg::BoundingBox bbox = mesh_manager->global_bounding_box(); - - std::mt19937 gen(42); - std::uniform_real_distribution x_dist(bbox.min_x, bbox.max_x); - std::uniform_real_distribution y_dist(bbox.min_y, bbox.max_y); - std::uniform_real_distribution z_dist(bbox.min_z, bbox.max_z); - - constexpr size_t number_of_rays = 10000; - - for (size_t i = 0; i < number_of_rays; ++i) - { - xdg::Position start = {x_dist(gen), y_dist(gen), z_dist(gen)}; - xdg::Position end = {x_dist(gen), y_dist(gen), z_dist(gen)}; - - // xdg returns MeshID (or the element ID) of the elements it has intersected and - // ray segments associated with element. - std::vector> track_segments = xdg_instance->segments(start, end); - - double total_length = std::accumulate(track_segments.begin(), track_segments.end(), 0.0, - [](double sum, const std::pair& seg) { - return sum + seg.second; - }); - - double ref_distance = (end - start).length(); - - double error_pct = (ref_distance > 0.0) - ? (total_length - ref_distance) * 100.0 / ref_distance - : 0.0; - - std::cout - << "Elements hit = " << std::setw(4) << track_segments.size() - << " ref dist = " << std::fixed << std::setprecision(6) << ref_distance - << " xdg dist = " << total_length - << " error = " << std::setprecision(4) << error_pct << " %\n"; - } - - return 0; -} \ No newline at end of file From 08d3d618b0a24a5edd0204cd107656a75f74eed9 Mon Sep 17 00:00:00 2001 From: magnoxemo Date: Tue, 12 May 2026 16:51:34 -0500 Subject: [PATCH 10/11] remove mesh_managers include --- examples/element_volume_estimation.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/element_volume_estimation.cpp b/examples/element_volume_estimation.cpp index 67ea792e..af9d1003 100644 --- a/examples/element_volume_estimation.cpp +++ b/examples/element_volume_estimation.cpp @@ -3,7 +3,6 @@ #include #include "xdg/xdg.h" -#include "xdg/mesh_managers.h" int main(int argc, char* argv[]) { From 767724e014be3f93ca6777551bfb07a5a262256e Mon Sep 17 00:00:00 2001 From: magnoxemo Date: Wed, 20 May 2026 14:56:13 -0500 Subject: [PATCH 11/11] fix fmt link error --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e3a86c41..349a9b55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -328,7 +328,7 @@ if (XDG_ENABLE_GPRT) target_link_options(xdg PRIVATE -Wl,--unresolved-symbols=ignore-in-shared-libs) endif() -target_link_libraries(xdg PRIVATE fmt::fmt) +target_link_libraries(xdg PUBLIC fmt::fmt) # ========================== # Link ray tracing libraries