From caf2ec76719270516557d8d4ee3449961d892de1 Mon Sep 17 00:00:00 2001 From: Tobias Reiter Date: Thu, 13 Feb 2025 19:51:15 +0100 Subject: [PATCH] Add smoothing flux test --- include/viennaray/rayTrace.hpp | 2 ++ tests/smoothing/CMakeLists.txt | 7 +++++ tests/smoothing/smoothing.cpp | 54 ++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 tests/smoothing/CMakeLists.txt create mode 100644 tests/smoothing/smoothing.cpp diff --git a/include/viennaray/rayTrace.hpp b/include/viennaray/rayTrace.hpp index 6ee0f9a..7291c25 100644 --- a/include/viennaray/rayTrace.hpp +++ b/include/viennaray/rayTrace.hpp @@ -323,6 +323,8 @@ template class Trace { return pGlobalData_; } + Geometry &getGeometry() { return geometry_; } + void setGlobalData(TracingData &data) { pGlobalData_ = &data; } [[nodiscard]] TraceInfo getRayTraceInfo() { return RTInfo_; } diff --git a/tests/smoothing/CMakeLists.txt b/tests/smoothing/CMakeLists.txt new file mode 100644 index 0000000..73159a8 --- /dev/null +++ b/tests/smoothing/CMakeLists.txt @@ -0,0 +1,7 @@ +project(smoothing LANGUAGES CXX) + +add_executable(${PROJECT_NAME} "${PROJECT_NAME}.cpp") +target_link_libraries(${PROJECT_NAME} PRIVATE ViennaRay) + +add_dependencies(ViennaRay_Tests ${PROJECT_NAME}) +add_test(NAME ${PROJECT_NAME} COMMAND $) diff --git a/tests/smoothing/smoothing.cpp b/tests/smoothing/smoothing.cpp new file mode 100644 index 0000000..8188968 --- /dev/null +++ b/tests/smoothing/smoothing.cpp @@ -0,0 +1,54 @@ +#include +#include + +using namespace viennaray; + +int main() { + using NumericType = float; + constexpr int D = 3; + NumericType gridDelta = 1.0; + std::vector> points; + std::vector> normals; + + points.push_back({0, 0, 0}); + points.push_back({1, 0, 0}); + points.push_back({2, 0, 0}); + + points.push_back({0, 1, 0}); + points.push_back({1, 1, 0}); + points.push_back({2, 1, 0}); + + normals.push_back({0, 0, 1}); + normals.push_back({0, 0, 1}); + normals.push_back({0, 0, 1}); + + const Vec3D direction = {0, 1, 0}; + normals.push_back(Normalize(direction)); + normals.push_back(Normalize(direction)); + normals.push_back(Normalize(direction)); + + std::vector flux = {1, 1, 1, 0, 0, 0}; + + Trace trace; + trace.setGeometry(points, normals, gridDelta); + + trace.smoothFlux(flux, 1); + + auto &geo = trace.getGeometry(); + + for (unsigned int idx = 0; idx < 3; ++idx) { + // auto neighbors = geo.getNeighborIndicies(idx); + // std::cout << "flux[" << idx << "] = " << flux[idx] << std::endl; + // std::cout << "num neighbors: " << neighbors.size() << std::endl; + VC_TEST_ASSERT_ISCLOSE(flux[idx], 1.0, 1e-6); + } + + for (unsigned int idx = 3; idx < 6; ++idx) { + // auto neighbors = geo.getNeighborIndicies(idx); + // std::cout << "flux[" << idx << "] = " << flux[idx] << std::endl; + // std::cout << "num neighbors: " << neighbors.size() << std::endl; + VC_TEST_ASSERT_ISCLOSE(flux[idx], 0.0, 1e-6); + } + + return 0; +} \ No newline at end of file