From ae2a4a706099a27e1601a24f42aa805fdbe5e2de Mon Sep 17 00:00:00 2001 From: Tobias Reiter Date: Fri, 5 Dec 2025 15:12:17 +0100 Subject: [PATCH 1/3] Use better cosine sampling, add rng tests --- examples/disk3D/disk3D.cpp | 1 + gpu/pipelines/CallableWrapper.cu | 5 ++ gpu/pipelines/Particle.cuh | 8 ++ gpu/tests/rngSeed/CMakeLists.txt | 9 ++ gpu/tests/rngSeed/rngSeed.cpp | 120 ++++++++++++++++++++++++++ include/viennaray/raySourceRandom.hpp | 22 ++--- tests/rngSeed/CMakeLists.txt | 7 ++ tests/rngSeed/rngSeed.cpp | 53 ++++++++++++ 8 files changed, 215 insertions(+), 10 deletions(-) create mode 100644 gpu/tests/rngSeed/CMakeLists.txt create mode 100644 gpu/tests/rngSeed/rngSeed.cpp create mode 100644 tests/rngSeed/CMakeLists.txt create mode 100644 tests/rngSeed/rngSeed.cpp diff --git a/examples/disk3D/disk3D.cpp b/examples/disk3D/disk3D.cpp index b4bcb02..bf62e41 100644 --- a/examples/disk3D/disk3D.cpp +++ b/examples/disk3D/disk3D.cpp @@ -61,6 +61,7 @@ int main() { // Extract the normalized hit counts for each geometry point auto &flux = rayTracer.getLocalData().getVectorData("flux"); rayTracer.normalizeFlux(flux, NormalizationType::SOURCE); + rayTracer.smoothFlux(flux); rayInternal::writeVTK("trenchResult.vtk", points, flux); diff --git a/gpu/pipelines/CallableWrapper.cu b/gpu/pipelines/CallableWrapper.cu index 14bdfa2..cd23037 100644 --- a/gpu/pipelines/CallableWrapper.cu +++ b/gpu/pipelines/CallableWrapper.cu @@ -33,6 +33,11 @@ __direct_callable__particleReflection(const void *sbtData, particleReflection(sbtData, prd); } +extern "C" __device__ void __direct_callable__particleReflectionConstSticking( + const void *sbtData, viennaray::gpu::PerRayData *prd) { + particleReflectionConstSticking(sbtData, prd); +} + extern "C" __device__ void __direct_callable__particleInit(const void *sbtData, viennaray::gpu::PerRayData *prd) { diff --git a/gpu/pipelines/Particle.cuh b/gpu/pipelines/Particle.cuh index 1b6edf7..0c58da1 100644 --- a/gpu/pipelines/Particle.cuh +++ b/gpu/pipelines/Particle.cuh @@ -30,6 +30,14 @@ particleReflection(const void *sbtData, viennaray::gpu::PerRayData *prd) { viennaray::gpu::diffuseReflection(prd, geoNormal, launchParams.D); } +__forceinline__ __device__ void +particleReflectionConstSticking(const void *sbtData, + viennaray::gpu::PerRayData *prd) { + prd->rayWeight -= prd->rayWeight * launchParams.sticking; + auto geoNormal = viennaray::gpu::computeNormal(sbtData, prd->primID); + viennaray::gpu::diffuseReflection(prd, geoNormal, launchParams.D); +} + __forceinline__ __device__ void particleInit(viennaray::gpu::PerRayData *prd) { // Optional } \ No newline at end of file diff --git a/gpu/tests/rngSeed/CMakeLists.txt b/gpu/tests/rngSeed/CMakeLists.txt new file mode 100644 index 0000000..05b00f2 --- /dev/null +++ b/gpu/tests/rngSeed/CMakeLists.txt @@ -0,0 +1,9 @@ +project(GPU_rngSeed LANGUAGES CXX) + +add_gpu_executable(${PROJECT_NAME} target_name rngSeed.cpp) + +add_dependencies(ViennaRay-GPU_Tests ${PROJECT_NAME}) +add_test(NAME ${PROJECT_NAME} COMMAND $) + +configure_file(${CMAKE_SOURCE_DIR}/examples/triangle3D/trenchMesh.dat + ${CMAKE_CURRENT_BINARY_DIR}/trenchMesh.dat COPYONLY) \ No newline at end of file diff --git a/gpu/tests/rngSeed/rngSeed.cpp b/gpu/tests/rngSeed/rngSeed.cpp new file mode 100644 index 0000000..31952be --- /dev/null +++ b/gpu/tests/rngSeed/rngSeed.cpp @@ -0,0 +1,120 @@ +#include +#include +#include +#include + +using namespace viennaray; + +int main() { + constexpr int D = 3; + using NumericType = float; + + auto context = DeviceContext::createContext("../../../lib/ptx", + 0); // relative to build directory + + gpu::Particle particle; + particle.name = "Particle"; + particle.dataLabels.push_back("hitFlux"); + + std::unordered_map pMap = {{"Particle", 0}}; + std::vector cMap = { + {0, gpu::CallableSlot::COLLISION, "__direct_callable__particleCollision"}, + {0, gpu::CallableSlot::REFLECTION, + "__direct_callable__particleReflectionConstSticking"}}; + + std::vector flux1, flux2; + + { + NumericType extent = 5; + NumericType gridDelta = 0.5; + std::vector> points; + std::vector> normals; + rayInternal::createPlaneGrid(gridDelta, extent, {0, 1, 2}, points, normals); + DiskMesh mesh(points, normals, gridDelta); + + { + gpu::TraceDisk rayTracer; + rayTracer.insertNextParticle(particle); + rayTracer.setCallables("CallableWrapper", context->modulePath); + rayTracer.setParticleCallableMap({pMap, cMap}); + rayTracer.setGeometry(mesh); + rayTracer.setNumberOfRaysPerPoint(100); + rayTracer.setRngSeed(12345); + rayTracer.prepareParticlePrograms(); + + rayTracer.apply(); + + flux1 = rayTracer.getFlux(0, 0, 0); + } + + { + gpu::TraceDisk rayTracer; + rayTracer.insertNextParticle(particle); + rayTracer.setCallables("CallableWrapper", context->modulePath); + rayTracer.setParticleCallableMap({pMap, cMap}); + rayTracer.setGeometry(mesh); + rayTracer.setNumberOfRaysPerPoint(100); + rayTracer.setRngSeed(12345); + rayTracer.prepareParticlePrograms(); + + rayTracer.apply(); + + flux2 = rayTracer.getFlux(0, 0, 0); + } + + VC_TEST_ASSERT(flux1.size() == flux2.size()); + for (size_t i = 0; i < flux1.size(); ++i) { + VC_TEST_ASSERT(flux1[i] == flux2[i]); + } + } + + { + std::vector> points; + std::vector> triangles; + float gridDelta; + rayInternal::readMeshFromFile("trenchMesh.dat", gridDelta, points, + triangles); + TriangleMesh mesh(points, triangles, gridDelta); + std::vector materialIds(mesh.triangles.size(), 7); + for (int i = mesh.triangles.size() / 2; i < mesh.triangles.size(); ++i) { + materialIds[i] = 1; + } + + { + gpu::TraceTriangle rayTracer; + rayTracer.insertNextParticle(particle); + rayTracer.setCallables("CallableWrapper", context->modulePath); + rayTracer.setParticleCallableMap({pMap, cMap}); + rayTracer.setGeometry(mesh); + rayTracer.setNumberOfRaysPerPoint(100); + rayTracer.setRngSeed(12345); + rayTracer.prepareParticlePrograms(); + + rayTracer.apply(); + + flux1 = rayTracer.getFlux(0, 0, 0); + } + + { + gpu::TraceTriangle rayTracer; + rayTracer.insertNextParticle(particle); + rayTracer.setCallables("CallableWrapper", context->modulePath); + rayTracer.setParticleCallableMap({pMap, cMap}); + rayTracer.setGeometry(mesh); + rayTracer.setNumberOfRaysPerPoint(100); + rayTracer.setRngSeed(12345); + rayTracer.prepareParticlePrograms(); + + rayTracer.apply(); + + flux2 = rayTracer.getFlux(0, 0, 0); + } + + VC_TEST_ASSERT(flux1.size() == flux2.size()); + for (size_t i = 0; i < flux1.size(); ++i) { + VC_TEST_ASSERT(flux1[i] == flux2[i]); + } + } + + return 0; +} diff --git a/include/viennaray/raySourceRandom.hpp b/include/viennaray/raySourceRandom.hpp index 29a681d..2a56e8d 100644 --- a/include/viennaray/raySourceRandom.hpp +++ b/include/viennaray/raySourceRandom.hpp @@ -18,7 +18,7 @@ class SourceRandom : public Source { : bdBox_(boundingBox), rayDir_(pTraceSettings[0]), firstDir_(pTraceSettings[1]), secondDir_(pTraceSettings[2]), minMax_(pTraceSettings[3]), posNeg_(pTraceSettings[4]), - ee_(static_cast(2) / (cosinePower + 1)), + ee_(static_cast(1) / (cosinePower + 1)), numPoints_(numPoints_), customDirection_(customDirection), orthonormalBasis_(orthonormalBasis) {} @@ -73,15 +73,16 @@ class SourceRandom : public Source { auto r1 = uniDist(rngState); auto r2 = uniDist(rngState); - const NumericType tt = pow(r2, ee_); - direction[rayDir_] = posNeg_ * sqrtf(tt); - direction[firstDir_] = cosf(M_PI * 2.f * r1) * sqrtf(1 - tt); + const NumericType cosTheta = std::pow(r2, ee_); + const NumericType sinTheta = std::sqrt(1. - cosTheta * cosTheta); + direction[rayDir_] = posNeg_ * cosTheta; + direction[firstDir_] = std::cos(M_PI * 2. * r1) * sinTheta; if constexpr (D == 2) { - direction[secondDir_] = 0; + direction[secondDir_] = 0.; Normalize(direction); } else { - direction[secondDir_] = sinf(M_PI * 2.f * r1) * sqrtf(1 - tt); + direction[secondDir_] = std::sin(M_PI * 2. * r1) * sinTheta; } return direction; @@ -96,10 +97,11 @@ class SourceRandom : public Source { auto r1 = uniDist(rngState); auto r2 = uniDist(rngState); - const NumericType tt = pow(r2, ee_); - rndDirection[0] = sqrtf(tt); - rndDirection[1] = cosf(M_PI * 2.f * r1) * sqrtf(1 - tt); - rndDirection[2] = sinf(M_PI * 2.f * r1) * sqrtf(1 - tt); + const NumericType cosTheta = std::pow(r2, ee_); + const NumericType sinTheta = std::sqrt(1. - cosTheta * cosTheta); + rndDirection[0] = cosTheta; + rndDirection[1] = std::cos(M_PI * 2. * r1) * sinTheta; + rndDirection[2] = std::sin(M_PI * 2. * r1) * sinTheta; direction[0] = orthonormalBasis_[0][0] * rndDirection[0] + orthonormalBasis_[1][0] * rndDirection[1] + diff --git a/tests/rngSeed/CMakeLists.txt b/tests/rngSeed/CMakeLists.txt new file mode 100644 index 0000000..1a905f9 --- /dev/null +++ b/tests/rngSeed/CMakeLists.txt @@ -0,0 +1,7 @@ +project(rngSeed 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/rngSeed/rngSeed.cpp b/tests/rngSeed/rngSeed.cpp new file mode 100644 index 0000000..5a92919 --- /dev/null +++ b/tests/rngSeed/rngSeed.cpp @@ -0,0 +1,53 @@ +#include +#include +#include + +using namespace viennaray; + +int main() { + constexpr int D = 3; + using NumericType = float; + omp_set_num_threads(4); + + NumericType extent = 5; + NumericType gridDelta = 0.5; + std::vector> points; + std::vector> normals; + rayInternal::createPlaneGrid(gridDelta, extent, {0, 1, 2}, points, normals); + + auto particle = + std::make_unique>(1.0, "hitFlux"); + + std::vector flux1, flux2; + + { + TraceDisk rayTracer; + rayTracer.setParticleType(particle); + rayTracer.setGeometry(points, normals, gridDelta); + rayTracer.setNumberOfRaysPerPoint(10); + rayTracer.setRngSeed(12345); + + rayTracer.apply(); + + flux1 = rayTracer.getLocalData().getVectorData(0); + } + + { + TraceDisk rayTracer; + rayTracer.setParticleType(particle); + rayTracer.setGeometry(points, normals, gridDelta); + rayTracer.setNumberOfRaysPerPoint(10); + rayTracer.setRngSeed(12345); + + rayTracer.apply(); + + flux2 = rayTracer.getLocalData().getVectorData(0); + } + + VC_TEST_ASSERT(flux1.size() == flux2.size()); + for (size_t i = 0; i < flux1.size(); ++i) { + VC_TEST_ASSERT(flux1[i] == flux2[i]); + } + + return 0; +} From ea93942a29aac23e8c109b6fa2baa5913a7bcc22 Mon Sep 17 00:00:00 2001 From: Tobias Reiter Date: Fri, 5 Dec 2025 15:25:34 +0100 Subject: [PATCH 2/3] Adjust cosine sampling on GPU --- gpu/include/raygSource.hpp | 51 ++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/gpu/include/raygSource.hpp b/gpu/include/raygSource.hpp index b780496..deec5e0 100644 --- a/gpu/include/raygSource.hpp +++ b/gpu/include/raygSource.hpp @@ -29,19 +29,21 @@ __device__ __forceinline__ void initializeRayDirection(PerRayData *prd, const float power, const uint16_t D) { // source direction const float4 u = curand_uniform4(&prd->RNGstate); // (0,1] - const float tt = powf(u.w, 2.f / (power + 1.f)); - float s, c; - __sincosf(2.f * M_PIf * u.x, &s, &c); - float sqrt1mtt = sqrtf(1 - tt); - prd->dir[0] = c * sqrt1mtt; + const float cosTheta = powf(u.w, 1.f / (power + 1.f)); + const float sinTheta = sqrtf(max(0.f, 1.f - cosTheta * cosTheta)); + float sinPhi, cosPhi; + __sincosf(2.f * M_PIf * u.x, &sinPhi, &cosPhi); + + prd->dir[0] = cosPhi * sinTheta; if (D == 2) { - prd->dir[1] = -1.f * sqrtf(tt); + prd->dir[1] = -cosTheta; prd->dir[2] = 0.f; + Normalize(prd->dir); } else { - prd->dir[1] = s * sqrt1mtt; - prd->dir[2] = -1.f * sqrtf(tt); + prd->dir[1] = sinPhi * sinTheta; + prd->dir[2] = -cosTheta; + // already normalized } - Normalize(prd->dir); } __device__ __forceinline__ void @@ -50,20 +52,16 @@ initializeRayDirection(PerRayData *prd, const float power, // source direction do { const float4 u = curand_uniform4(&prd->RNGstate); // (0,1] - const float tt = powf(u.w, 2.f / (power + 1.f)); - Vec3Df rndDirection; - rndDirection[0] = sqrtf(tt); - float s, c, sqrt1mtt = sqrtf(1 - tt); - __sincosf(2.f * M_PIf * u.x, &s, &c); - rndDirection[1] = c * sqrt1mtt; - rndDirection[2] = s * sqrt1mtt; - - prd->dir[0] = basis[0][0] * rndDirection[0] + - basis[1][0] * rndDirection[1] + basis[2][0] * rndDirection[2]; - prd->dir[1] = basis[0][1] * rndDirection[0] + - basis[1][1] * rndDirection[1] + basis[2][1] * rndDirection[2]; - prd->dir[2] = basis[0][2] * rndDirection[0] + - basis[1][2] * rndDirection[1] + basis[2][2] * rndDirection[2]; + const float cosTheta = powf(u.w, 1.f / (power + 1.f)); + const float sinTheta = sqrtf(max(0.f, 1.f - cosTheta * cosTheta)); + float sinPhi, cosPhi; + __sincosf(2.f * M_PIf * u.x, &sinPhi, &cosPhi); + + float rx = cosTheta; + float ry = cosPhi * sinTheta; + float rz = sinPhi * sinTheta; + + prd->dir = basis[0] * rx + basis[1] * ry + basis[2] * rz; } while (prd->dir[2] >= 0.f); if (D == 2) @@ -102,14 +100,13 @@ initializeRayPositionAndDirection(PerRayData *prd, launchParams->source.minPoint[1]); prd->pos[2] = launchParams->source.planeHeight; - const float tt = powf(u.w, 2.f / (launchParams->cosineExponent + 1.f)); + const float tt = powf(u.w, 1.f / (launchParams->cosineExponent + 1.f)); float s, c; __sincosf(2.f * M_PIf * u.z, &s, &c); - const float sqrt1mtt = sqrtf(1 - tt); + const float sqrt1mtt = sqrtf(1.f - tt * tt); prd->dir[0] = c * sqrt1mtt; prd->dir[1] = s * sqrt1mtt; - prd->dir[2] = -1.f * sqrtf(tt); - Normalize(prd->dir); + prd->dir[2] = -tt; } } // namespace viennaray::gpu #endif From aff8ff03932e301e7bd82feab72007e31efe90f2 Mon Sep 17 00:00:00 2001 From: Tobias Reiter Date: Fri, 5 Dec 2025 18:24:35 +0100 Subject: [PATCH 3/3] Use new logger --- CMakeLists.txt | 4 +- README.md | 2 +- gpu/include/raygReflection.hpp | 6 +- gpu/include/raygTrace.hpp | 80 ++++++++--------------- gpu/include/raygTraceDisk.hpp | 4 +- include/viennaray/rayGeometryTriangle.hpp | 4 +- include/viennaray/rayTraceDisk.hpp | 21 +++--- include/viennaray/rayTraceKernel.hpp | 18 ++--- include/viennaray/rayTraceTriangle.hpp | 18 ++--- include/viennaray/rayTracingData.hpp | 38 ++++------- include/viennaray/rayUtil.hpp | 13 ++-- 11 files changed, 72 insertions(+), 136 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b8a6a8..3effc8d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.20 FATAL_ERROR) project( ViennaRay LANGUAGES CXX - VERSION 3.8.3) + VERSION 3.8.5) # -------------------------------------------------------------------------------------------------------- # Library switches @@ -92,7 +92,7 @@ include("cmake/cpm.cmake") CPMAddPackage( NAME ViennaCore - VERSION 1.7.0 + VERSION 1.7.3 GIT_REPOSITORY "https://github.com/ViennaTools/ViennaCore" OPTIONS "VIENNACORE_USE_GPU ${VIENNARAY_USE_GPU}") diff --git a/README.md b/README.md index 8bbff3c..4952224 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ We recommend using [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake) to consum * Installation with CPM ```cmake - CPMAddPackage("gh:viennatools/viennaray@3.8.2") # Use the latest release version + CPMAddPackage("gh:viennatools/viennaray@3.8.5") # Use the latest release version ``` * With a local installation diff --git a/gpu/include/raygReflection.hpp b/gpu/include/raygReflection.hpp index 43f30d8..f2eebab 100644 --- a/gpu/include/raygReflection.hpp +++ b/gpu/include/raygReflection.hpp @@ -66,10 +66,10 @@ specularReflection(PerRayData *prd, const Vec3Df &geoNormal) { static __device__ Vec3Df PickRandomPointOnUnitSphere(CudaRNG *state) { const float4 u = curand_uniform4(state); // (0,1] - const float z = 1.0f - 2.0f * u.x; // uniform in [-1,1] - const float r2 = fmaxf(0.0f, 1.0f - z * z); + const float z = 1.f - 2.f * u.x; // uniform in [-1,1] + const float r2 = max(0.f, 1.f - z * z); const float r = sqrtf(r2); - const float phi = 2.0f * M_PIf * u.y; + const float phi = 2.f * M_PIf * u.y; float s, c; __sincosf(phi, &s, &c); // branch-free sin+cos return Vec3Df{r * c, r * s, z}; diff --git a/gpu/include/raygTrace.hpp b/gpu/include/raygTrace.hpp index 05d0fa2..f694238 100644 --- a/gpu/include/raygTrace.hpp +++ b/gpu/include/raygTrace.hpp @@ -39,11 +39,9 @@ template class Trace { : geometryType_(std::move(geometryType)) { context_ = DeviceContext::getContextFromRegistry(deviceID); if (!context_) { - Logger::getInstance() - .addError("No context found for device ID " + - std::to_string(deviceID) + - ". Create and register a context first.") - .print(); + VIENNACORE_LOG_ERROR("No context found for device ID " + + std::to_string(deviceID) + + ". Create and register a context first."); } initRayTracer(); } @@ -72,9 +70,7 @@ template class Trace { callableFile_ = path / finalName; if (!std::filesystem::exists(callableFile_)) { - Logger::getInstance() - .addError("Callable file " + finalName + " not found.") - .print(); + VIENNACORE_LOG_ERROR("Callable file " + finalName + " not found."); } } @@ -84,16 +80,14 @@ template class Trace { void apply() { if (particles_.empty()) { - Logger::getInstance() - .addError("No particles inserted. Use insertNextParticle first.") - .print(); + VIENNACORE_LOG_ERROR( + "No particles inserted. Use insertNextParticle first."); } if (cellDataBuffer_.sizeInBytes / sizeof(float) != numCellData * launchParams.numElements) { - Logger::getInstance() - .addError("Cell data buffer size does not match the expected size.") - .print(); + VIENNACORE_LOG_ERROR( + "Cell data buffer size does not match the expected size."); } // Resize our cuda result buffer @@ -127,26 +121,21 @@ template class Trace { numRays = numPointsPerDim * numPointsPerDim * config_.numRaysPerPoint; if (numRays > (1 << 29)) { - Logger::getInstance() - .addWarning("Too many rays for single launch: " + - util::prettyDouble(numRays)) - .print(); + VIENNACORE_LOG_WARNING("Too many rays for single launch: " + + util::prettyDouble(numRays)); config_.numRaysPerPoint = (1 << 29) / (numPointsPerDim * numPointsPerDim); numRays = numPointsPerDim * numPointsPerDim * config_.numRaysPerPoint; } - Logger::getInstance() - .addDebug("Number of rays: " + util::prettyDouble(numRays)) - .print(); + VIENNACORE_LOG_DEBUG("Number of rays: " + util::prettyDouble(numRays)); // set up material specific sticking probabilities materialStickingBuffer_.resize(particles_.size()); for (size_t i = 0; i < particles_.size(); i++) { if (!particles_[i].materialSticking.empty()) { if (uniqueMaterialIds_.empty() || materialIdsBuffer_.sizeInBytes == 0) { - Logger::getInstance() - .addError("Material IDs not set, when using material dependent " - "sticking.") - .print(); + VIENNACORE_LOG_ERROR( + "Material IDs not set, when using material dependent " + "sticking."); } std::vector materialSticking(uniqueMaterialIds_.size()); unsigned currentId = 0; @@ -169,17 +158,13 @@ template class Trace { launchParamsBuffers.resize(particles_.size()); if (particleMap_.empty()) { - Logger::getInstance() - .addError("No particle name->particleType mapping provided.") - .print(); + VIENNACORE_LOG_ERROR("No particle name->particleType mapping provided."); } for (size_t i = 0; i < particles_.size(); i++) { auto it = particleMap_.find(particles_[i].name); if (it == particleMap_.end()) { - Logger::getInstance() - .addError("Unknown particle name: " + particles_[i].name) - .print(); + VIENNACORE_LOG_ERROR("Unknown particle name: " + particles_[i].name); } launchParams.particleType = it->second; launchParams.particleIdx = static_cast(i); @@ -244,9 +229,8 @@ template class Trace { const unsigned numData) { if (passedCellDataBuffer.sizeInBytes / sizeof(float) / numData != launchParams.numElements) { - Logger::getInstance() - .addWarning("Passed cell data does not match number of elements.") - .print(); + VIENNACORE_LOG_WARNING( + "Passed cell data does not match number of elements."); } cellDataBuffer_ = passedCellDataBuffer; #ifndef NDEBUG @@ -402,7 +386,7 @@ template class Trace { unsigned int prepareParticlePrograms() { if (particles_.empty()) { - Logger::getInstance().addWarning("No particles defined.").print(); + VIENNACORE_LOG_WARNING("No particles defined."); return 0; } @@ -422,9 +406,8 @@ template class Trace { dataPerParticleBuffer_.allocUpload(dataPerParticle); launchParams.dataPerParticle = (unsigned int *)dataPerParticleBuffer_.dPointer(); - Logger::getInstance() - .addDebug("Number of flux arrays: " + std::to_string(numFluxes_)) - .print(); + VIENNACORE_LOG_DEBUG("Number of flux arrays: " + + std::to_string(numFluxes_)); return numFluxes_; } @@ -503,16 +486,14 @@ template class Trace { std::string pipelineFile = pipelineFileName + geometryType_ + ".optixir"; std::filesystem::path pipelinePath = context_->modulePath / pipelineFile; if (!std::filesystem::exists(pipelinePath)) { - Logger::getInstance() - .addError("Pipeline file " + pipelinePath.string() + " not found.") - .print(); + VIENNACORE_LOG_ERROR("Pipeline file " + pipelinePath.string() + + " not found."); } auto pipelineInput = getInputData(pipelinePath.c_str(), inputSize); if (!pipelineInput) { - Logger::getInstance() - .addError("Pipeline file " + pipelinePath.string() + " not found.") - .print(); + VIENNACORE_LOG_ERROR("Pipeline file " + pipelinePath.string() + + " not found."); } OPTIX_CHECK(optixModuleCreate(context_->optix, &moduleCompileOptions_, @@ -525,14 +506,13 @@ template class Trace { size_t sizeof_log_callable = sizeof(logCallable); if (callableFile_.empty()) { - Logger::getInstance().addWarning("No callable file set.").print(); + VIENNACORE_LOG_WARNING("No callable file set."); return; } auto callableInput = getInputData(callableFile_.c_str(), inputSize); if (!callableInput) { - Logger::getInstance() - .addError("Callable file " + callableFile_.string() + " not found.") - .print(); + VIENNACORE_LOG_ERROR("Callable file " + callableFile_.string() + + " not found."); } OPTIX_CHECK(optixModuleCreate(context_->optix, &moduleCompileOptions_, @@ -606,9 +586,7 @@ template class Trace { /// does all setup for the direct callables void createDirectCallablePrograms() { if (callableMap_.empty()) { - Logger::getInstance() - .addWarning("No particleType->callable mapping provided.") - .print(); + VIENNACORE_LOG_WARNING("No particleType->callable mapping provided."); return; } unsigned maxParticleTypeId = 0; diff --git a/gpu/include/raygTraceDisk.hpp b/gpu/include/raygTraceDisk.hpp index 4afa26a..ee2c5f1 100644 --- a/gpu/include/raygTraceDisk.hpp +++ b/gpu/include/raygTraceDisk.hpp @@ -22,9 +22,7 @@ template class TraceDisk final : public Trace { assert(context_ && "Context not initialized."); diskMesh = passedMesh; if (diskMesh.gridDelta <= 0.f) { - Logger::getInstance() - .addError("DiskMesh gridDelta must be positive and non-zero.") - .print(); + VIENNACORE_LOG_ERROR("DiskMesh gridDelta must be positive and non-zero."); } if (diskMesh.radius <= 0.f) { diskMesh.radius = rayInternal::DiskFactor<3> * diskMesh.gridDelta; diff --git a/include/viennaray/rayGeometryTriangle.hpp b/include/viennaray/rayGeometryTriangle.hpp index d18b2e7..488f81b 100644 --- a/include/viennaray/rayGeometryTriangle.hpp +++ b/include/viennaray/rayGeometryTriangle.hpp @@ -171,9 +171,7 @@ class GeometryTriangle : public Geometry { } else { normals_[i] = Vec3Df{0.f, 0.f, 0.f}; areas_[i] = 0.; - Logger::getInstance() - .addDebug("Degenerate triangle with zero area detected.") - .print(); + VIENNACORE_LOG_DEBUG("Degenerate triangle with zero area detected."); } } diff --git a/include/viennaray/rayTraceDisk.hpp b/include/viennaray/rayTraceDisk.hpp index 95cd414..cb273c7 100644 --- a/include/viennaray/rayTraceDisk.hpp +++ b/include/viennaray/rayTraceDisk.hpp @@ -120,10 +120,8 @@ class TraceDisk final : public Trace { case NormalizationType::SOURCE: { if (!this->pSource_) { - Logger::getInstance() - .addWarning( - "No source was specified in rayTrace for the normalization.") - .print(); + VIENNACORE_LOG_WARNING( + "No source was specified in rayTrace for the normalization."); break; } NumericType sourceArea = this->pSource_->getSourceArea(); @@ -193,26 +191,23 @@ class TraceDisk final : public Trace { void checkSettings() { if (this->pParticle_ == nullptr) { this->RTInfo_.error = true; - Logger::getInstance().addError( - "No particle was specified in rayTrace. Aborting."); + VIENNACORE_LOG_ERROR("No particle was specified in rayTrace. Aborting."); } if (geometry_.checkGeometryEmpty()) { this->RTInfo_.error = true; - Logger::getInstance().addError( - "No geometry was passed to rayTrace. Aborting."); + VIENNACORE_LOG_ERROR("No geometry was passed to rayTrace. Aborting."); } if ((D == 2 && this->sourceDirection_ == TraceDirection::POS_Z) || (D == 2 && this->sourceDirection_ == TraceDirection::NEG_Z)) { this->RTInfo_.error = true; - Logger::getInstance().addError( + VIENNACORE_LOG_ERROR( "Invalid source direction in 2D geometry. Aborting."); } if (diskRadius_ > this->gridDelta_) { this->RTInfo_.warning = true; - Logger::getInstance() - .addWarning("Disk radius should be smaller than grid delta. Hit " - "count normalization not correct.") - .print(); + VIENNACORE_LOG_WARNING( + "Disk radius should be smaller than grid delta. Hit " + "count normalization not correct."); } } diff --git a/include/viennaray/rayTraceKernel.hpp b/include/viennaray/rayTraceKernel.hpp index 738cef8..3111336 100644 --- a/include/viennaray/rayTraceKernel.hpp +++ b/include/viennaray/rayTraceKernel.hpp @@ -371,9 +371,7 @@ template class TraceKernel { } default: { - Logger::getInstance() - .addWarning("Invalid merge type in local vector data.") - .print(); + VIENNACORE_LOG_WARNING("Invalid merge type in local vector data."); break; } } @@ -402,9 +400,7 @@ template class TraceKernel { } default: { - Logger::getInstance() - .addWarning("Invalid merge type in local scalar data.") - .print(); + VIENNACORE_LOG_WARNING("Invalid merge type in local scalar data."); break; } } @@ -421,12 +417,10 @@ template class TraceKernel { traceInfo_.time = static_cast(timer.currentDuration) * 1e-9; if (raysTerminated > 1000) { - Logger::getInstance() - .addDebug( - "A total of " + std::to_string(raysTerminated) + - " rays were terminated early due to excessive boundary hits or " - "reflections.") - .print(); + VIENNACORE_LOG_DEBUG( + "A total of " + std::to_string(raysTerminated) + + " rays were terminated early due to excessive boundary hits or " + "reflections."); } rtcReleaseScene(rtcScene); diff --git a/include/viennaray/rayTraceTriangle.hpp b/include/viennaray/rayTraceTriangle.hpp index 4306154..56a92cf 100644 --- a/include/viennaray/rayTraceTriangle.hpp +++ b/include/viennaray/rayTraceTriangle.hpp @@ -28,9 +28,7 @@ class TraceTriangle final : public Trace { std::array, 3> orthonormalBasis; if (this->usePrimaryDirection_) { - Logger::getInstance() - .addDebug("ViennaRay: Using custom primary direction") - .print(); + VIENNACORE_LOG_DEBUG("ViennaRay: Using custom primary direction"); orthonormalBasis = rayInternal::getOrthonormalBasis(this->primaryDirection_); } @@ -40,7 +38,7 @@ class TraceTriangle final : public Trace { traceSettings, geometry_.getNumPrimitives(), this->usePrimaryDirection_, orthonormalBasis); } else { - Logger::getInstance().addDebug("ViennaRay: Using custom source").print(); + VIENNACORE_LOG_DEBUG("ViennaRay: Using custom source"); } auto localDataLabels = this->pParticle_->getLocalDataLabels(); @@ -109,10 +107,8 @@ class TraceTriangle final : public Trace { case NormalizationType::SOURCE: { if (!this->pSource_) { - Logger::getInstance() - .addWarning( - "No source was specified in rayTrace for the normalization.") - .print(); + VIENNACORE_LOG_WARNING( + "No source was specified in rayTrace for the normalization."); break; } NumericType sourceArea = this->pSource_->getSourceArea(); @@ -143,13 +139,11 @@ class TraceTriangle final : public Trace { void checkSettings() { if (this->pParticle_ == nullptr) { this->RTInfo_.error = true; - Logger::getInstance().addError( - "No particle was specified in rayTrace. Aborting."); + VIENNACORE_LOG_ERROR("No particle was specified in rayTrace. Aborting."); } if (geometry_.checkGeometryEmpty()) { this->RTInfo_.error = true; - Logger::getInstance().addError( - "No geometry was passed to rayTrace. Aborting."); + VIENNACORE_LOG_ERROR("No geometry was passed to rayTrace. Aborting."); } } diff --git a/include/viennaray/rayTracingData.hpp b/include/viennaray/rayTracingData.hpp index 5ed0524..cb1ccfa 100644 --- a/include/viennaray/rayTracingData.hpp +++ b/include/viennaray/rayTracingData.hpp @@ -76,9 +76,7 @@ template class TracingData { void setScalarData(int num, NumericType value, std::string label = "scalarData") { if (num >= vectorData_.size()) - viennacore::Logger::getInstance() - .addError("Setting scalar data in TracingData out of range.") - .print(); + VIENNACORE_LOG_ERROR("Setting scalar data in TracingData out of range."); scalarData_[num] = value; scalarDataLabels_[num] = std::move(label); } @@ -86,9 +84,7 @@ template class TracingData { void setVectorData(int num, std::vector &vector, std::string label = "vectorData") { if (num >= vectorData_.size()) - viennacore::Logger::getInstance() - .addError("Setting vector data in TracingData out of range.") - .print(); + VIENNACORE_LOG_ERROR("Setting vector data in TracingData out of range."); vectorData_[num] = vector; vectorDataLabels_[num] = std::move(label); } @@ -96,9 +92,7 @@ template class TracingData { void setVectorData(int num, std::vector &&vector, std::string label = "vectorData") { if (num >= vectorData_.size()) - viennacore::Logger::getInstance() - .addError("Setting vector data in TracingData out of range.") - .print(); + VIENNACORE_LOG_ERROR("Setting vector data in TracingData out of range."); vectorData_[num] = std::move(vector); vectorDataLabels_[num] = std::move(label); } @@ -106,9 +100,7 @@ template class TracingData { void setVectorData(int num, size_t size, NumericType value, std::string label = "vectorData") { if (num >= vectorData_.size()) - viennacore::Logger::getInstance() - .addError("Setting vector data in TracingData out of range.") - .print(); + VIENNACORE_LOG_ERROR("Setting vector data in TracingData out of range."); vectorData_[num].resize(size, value); vectorDataLabels_[num] = std::move(label); } @@ -116,9 +108,7 @@ template class TracingData { void setVectorData(int num, NumericType value, std::string label = "vectorData") { if (num >= vectorData_.size()) - viennacore::Logger::getInstance() - .addError("Setting vector data in TracingData out of range.") - .print(); + VIENNACORE_LOG_ERROR("Setting vector data in TracingData out of range."); vectorData_[num].fill(vectorData_[num].begin(), vectorData_[num].end(), value); vectorDataLabels_[num] = std::move(label); @@ -187,17 +177,15 @@ template class TracingData { [[nodiscard]] std::string getVectorDataLabel(int i) const { if (i >= vectorDataLabels_.size()) - viennacore::Logger::getInstance() - .addError("Getting vector data label in TracingData out of range.") - .print(); + VIENNACORE_LOG_ERROR( + "Getting vector data label in TracingData out of range."); return vectorDataLabels_[i]; } [[nodiscard]] std::string getScalarDataLabel(int i) const { if (i >= scalarDataLabels_.size()) - viennacore::Logger::getInstance() - .addError("Getting scalar data label in TracingData out of range.") - .print(); + VIENNACORE_LOG_ERROR( + "Getting scalar data label in TracingData out of range."); return scalarDataLabels_[i]; } @@ -207,9 +195,7 @@ template class TracingData { return i; } } - viennacore::Logger::getInstance() - .addError("Can not find vector data label in TracingData.") - .print(); + VIENNACORE_LOG_ERROR("Can not find vector data label in TracingData."); return -1; } @@ -219,9 +205,7 @@ template class TracingData { return i; } } - viennacore::Logger::getInstance() - .addError("Can not find scalar data label in TracingData.") - .print(); + VIENNACORE_LOG_ERROR("Can not find scalar data label in TracingData."); return -1; } diff --git a/include/viennaray/rayUtil.hpp b/include/viennaray/rayUtil.hpp index 53b934d..b87c9b1 100644 --- a/include/viennaray/rayUtil.hpp +++ b/include/viennaray/rayUtil.hpp @@ -111,9 +111,7 @@ void adjustBoundingBox(std::array, 2> &bdBox, if (direction == TraceDirection::POS_Z || direction == TraceDirection::NEG_Z) { - Logger::getInstance() - .addError("Ray source is set in z-direction for 2D geometry") - .print(); + VIENNACORE_LOG_ERROR("Ray source is set in z-direction for 2D geometry"); } } @@ -293,9 +291,8 @@ template Vec3D u = vec; const T len2 = Norm2(u); if (len2 == T(0)) { - Logger::getInstance() - .addError("Cannot build orthonormal basis for zero-length vector") - .print(); + VIENNACORE_LOG_ERROR( + "Cannot build orthonormal basis for zero-length vector"); return B; } const T invLen = T(1) / std::sqrt(len2); @@ -380,9 +377,7 @@ void readMeshFromFile(const std::string &fileName, NumericType &gridDelta, std::vector> &elements) { std::ifstream dataFile(fileName); if (!dataFile.is_open()) { - Logger::getInstance() - .addError("Failed to open mesh file: " + fileName) - .print(); + VIENNACORE_LOG_ERROR("Failed to open mesh file: " + fileName); } std::string id; dataFile >> id;