Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -26,6 +27,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Set module path
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)


#===============================================================================
# libMesh
#===============================================================================
Expand Down Expand Up @@ -69,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)
#===============================================================================
Expand Down Expand Up @@ -323,7 +332,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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remind me why this is necessary again?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue was that fmt was linked privately to xdg. As a result, when a library or executable linked against xdg, the fmt dependency was not propagated to it. That caused the linker error we were seeing at that time.


# ==========================
# Link ray tracing libraries
Expand Down
8 changes: 8 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# =============================================================================
# Examples for how to use XDG C++ APIs
# =============================================================================

add_executable(element_volume_estimation element_volume_estimation.cpp)
target_link_libraries(element_volume_estimation PRIVATE xdg)


52 changes: 52 additions & 0 deletions examples/element_volume_estimation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <iostream>
#include <iomanip>
#include <random>

#include "xdg/xdg.h"

int main(int argc, char* argv[])
{
if (argc < 2) {
std::cerr << "Usage: " << argv[0] << " <mesh_file>\n";
return 1;
}
const std::string mesh_file = argv[1];

std::shared_ptr<xdg::XDG> xdg = xdg::XDG::create();
const auto& mesh_manager = xdg->mesh_manager();
mesh_manager->load_file(mesh_file);
mesh_manager->init();
xdg->prepare_raytracer();
Comment thread
pshriwise marked this conversation as resolved.

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<double> x_dist(bbox.min_x, bbox.max_x);
std::uniform_real_distribution<double> y_dist(bbox.min_y, bbox.max_y);
std::uniform_real_distribution<double> 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<double>(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;
}
Loading