From d7575433862973ba093fe193046d89b0c9e685fc Mon Sep 17 00:00:00 2001 From: Tobias Reiter Date: Fri, 19 Apr 2024 15:47:55 +0200 Subject: [PATCH 1/4] Add scatter probability in trajectory --- include/viennaray/rayGeometry.hpp | 12 +++--- include/viennaray/rayTrace.hpp | 17 ++++---- include/viennaray/rayTraceKernel.hpp | 60 +++++++++++++++++++++++++--- include/viennaray/rayUtil.hpp | 3 +- tests/diskAreas/diskAreas.cpp | 2 +- 5 files changed, 74 insertions(+), 20 deletions(-) diff --git a/include/viennaray/rayGeometry.hpp b/include/viennaray/rayGeometry.hpp index d228fd5..302b9b8 100644 --- a/include/viennaray/rayGeometry.hpp +++ b/include/viennaray/rayGeometry.hpp @@ -8,9 +8,9 @@ template class rayGeometry { public: template void initGeometry(RTCDevice &device, - std::vector> &points, - std::vector> &normals, - NumericType discRadii) { + std::vector> const &points, + std::vector> const &normals, + NumericType const discRadii) { static_assert(!(D == 3 && Dim == 2) && "Setting 2D geometry in 3D trace object"); @@ -98,7 +98,7 @@ template class rayGeometry { } template - void setMaterialIds(std::vector &pMaterialIds) { + void setMaterialIds(std::vector const &pMaterialIds) { assert(pMaterialIds.size() == numPoints_ && "rayGeometry: Material IDs size mismatch"); materialIds_.clear(); @@ -179,8 +179,8 @@ template class rayGeometry { private: template - void - initPointNeighborhood(std::vector> &points) { + void initPointNeighborhood( + std::vector> const &points) { pointNeighborhood_.clear(); pointNeighborhood_.resize(numPoints_, std::vector{}); diff --git a/include/viennaray/rayTrace.hpp b/include/viennaray/rayTrace.hpp index 9fd4ea7..f73df3a 100644 --- a/include/viennaray/rayTrace.hpp +++ b/include/viennaray/rayTrace.hpp @@ -54,8 +54,8 @@ template class rayTrace { rayTraceKernel tracer(device_, geometry_, boundary, raySource, pParticle_, dataLog_, numberOfRaysPerPoint_, numberOfRaysFixed_, - useRandomSeeds_, calcFlux_, runNumber_++, hitCounter_, - RTInfo_); + useRandomSeeds_, calcFlux_, lambda_, runNumber_++, + hitCounter_, RTInfo_); tracer.setTracingData(&localData_, pGlobalData_); tracer.apply(); @@ -80,8 +80,8 @@ template class rayTrace { /// It is possible to set a 2D geometry with 3D points. /// In this case the last dimension is ignored. template - void setGeometry(std::vector> &points, - std::vector> &normals, + void setGeometry(std::vector> const &points, + std::vector> const &normals, const NumericType gridDelta) { static_assert((D != 3 || Dim != 2) && "Setting 2D geometry in 3D trace object"); @@ -94,8 +94,8 @@ template class rayTrace { /// Set the ray tracing geometry /// Specify the disk radius manually. template - void setGeometry(std::vector> &points, - std::vector> &normals, + void setGeometry(std::vector> const &points, + std::vector> const &normals, const NumericType gridDelta, const NumericType diskRadii) { static_assert((D != 3 || Dim != 2) && "Setting 2D geometry in 3D trace object"); @@ -107,7 +107,7 @@ template class rayTrace { /// Set material ID's for each geometry point. /// If not set, all material ID's are default 0. - template void setMaterialIds(std::vector &materialIds) { + template void setMaterialIds(std::vector const &materialIds) { geometry_.setMaterialIds(materialIds); } @@ -151,6 +151,8 @@ template class rayTrace { usePrimaryDirection_ = true; } + void setMeanFreePath(const NumericType lambda) { lambda_ = lambda; } + /// Set whether random seeds for the internal random number generators /// should be used. void setUseRandomSeeds(const bool useRand) { useRandomSeeds_ = useRand; } @@ -374,6 +376,7 @@ template class rayTrace { size_t runNumber_ = 0; bool calcFlux_ = true; bool checkError_ = true; + NumericType lambda_ = -1.; rayHitCounter hitCounter_; rayTracingData localData_; rayTracingData *pGlobalData_ = nullptr; diff --git a/include/viennaray/rayTraceKernel.hpp b/include/viennaray/rayTraceKernel.hpp index eb1a535..1e9f9b4 100644 --- a/include/viennaray/rayTraceKernel.hpp +++ b/include/viennaray/rayTraceKernel.hpp @@ -18,16 +18,16 @@ class rayTraceKernel { std::unique_ptr> &particle, rayDataLog &dataLog, const size_t numRaysPerPoint, const size_t numRaysFixed, const bool useRandomSeed, - const bool calcFlux, const size_t runNumber, - rayHitCounter &hitCounter, + const bool calcFlux, const NumericType lambda, + const size_t runNumber, rayHitCounter &hitCounter, rayTraceInfo &traceInfo) : device_(device), geometry_(rtcGeometry), boundary_(rtcBoundary), source_(source), pParticle_(particle->clone()), numRays_(numRaysFixed == 0 ? source.getNumPoints() * numRaysPerPoint : numRaysFixed), useRandomSeeds_(useRandomSeed), runNumber_(runNumber), - calcFlux_(calcFlux), hitCounter_(hitCounter), traceInfo_(traceInfo), - dataLog_(dataLog) { + calcFlux_(calcFlux), lambda_(lambda), hitCounter_(hitCounter), + traceInfo_(traceInfo), dataLog_(dataLog) { assert(rtcGetDeviceProperty(device_, RTC_DEVICE_PROPERTY_VERSION) >= 30601 && "Error: The minimum version of Embree is 3.6.1"); @@ -55,6 +55,7 @@ class rayTraceKernel { size_t geohitc = 0; size_t nongeohitc = 0; size_t totaltraces = 0; + size_t particlehitc = 0; // thread local data storage const int numThreads = omp_get_max_threads(); @@ -85,7 +86,7 @@ class rayTraceKernel { auto time = rayInternal::timeStampNow(); -#pragma omp parallel reduction(+ : geohitc, nongeohitc, totaltraces) \ +#pragma omp parallel reduction(+ : geohitc, nongeohitc, totaltraces, particlehitc) \ shared(threadLocalData, threadLocalHitCounter) { rtcJoinCommitScene(rtcScene); @@ -163,6 +164,49 @@ class rayTraceKernel { break; } + if (lambda_ > 0.) { + std::uniform_real_distribution dist(0., 1.); + NumericType scatterProbability = + 1 - std::exp(-rayHit.ray.tfar / lambda_); + auto rndm = dist(RngState); + if (rndm < scatterProbability) { + + const auto &ray = rayHit.ray; + const rayInternal::rtcNumericType xx = + ray.org_x + ray.dir_x * ray.tfar * rndm; + const rayInternal::rtcNumericType yy = + ray.org_y + ray.dir_y * ray.tfar * rndm; + const rayInternal::rtcNumericType zz = + ray.org_z + ray.dir_z * ray.tfar * rndm; + + std::array direction{0, 0, 0}; + for (int i = 0; i < D; ++i) { + direction[i] = 2.f * dist(RngState) - 1.f; + } + + // Update ray direction and origin +#ifdef ARCH_X86 + reinterpret_cast<__m128 &>(rayHit.ray) = + _mm_set_ps(1e-4f, zz, yy, xx); + reinterpret_cast<__m128 &>(rayHit.ray.dir_x) = + _mm_set_ps(0.0f, direction[2], direction[1], direction[0]); +#else + rayHit.ray.org_x = xx; + rayHit.ray.org_y = yy; + rayHit.ray.org_z = zz; + rayHit.ray.tnear = 1e-4f; + + rayHit.ray.dir_x = direction[0]; + rayHit.ray.dir_y = direction[1]; + rayHit.ray.dir_z = direction[2]; + rayHit.ray.time = 0.0f; +#endif + particlehitc++; + reflect = true; + continue; + } + } + /* -------- Boundary hit -------- */ if (rayHit.hit.geomID == boundaryID) { boundary_.processHit(rayHit, reflect); @@ -393,6 +437,7 @@ class rayTraceKernel { traceInfo_.totalDiskHits = hitCounter_.getTotalCounts(); traceInfo_.nonGeometryHits = nongeohitc; traceInfo_.geometryHits = geohitc; + traceInfo_.particleHits = particlehitc; traceInfo_.time = (endTime - time) * 1e-3; rtcReleaseScene(rtcScene); @@ -587,14 +632,19 @@ class rayTraceKernel { private: RTCDevice &device_; + rayGeometry &geometry_; rayBoundary const &boundary_; raySource const &source_; + std::unique_ptr> const pParticle_ = nullptr; + const long long numRays_; const bool useRandomSeeds_; const size_t runNumber_; const bool calcFlux_; + const NumericType lambda_; + rayTracingData *pLocalData_ = nullptr; rayTracingData const *pGlobalData_ = nullptr; rayHitCounter &hitCounter_; diff --git a/include/viennaray/rayUtil.hpp b/include/viennaray/rayUtil.hpp index 5b76052..3a20bc9 100644 --- a/include/viennaray/rayUtil.hpp +++ b/include/viennaray/rayUtil.hpp @@ -69,6 +69,7 @@ struct rayTraceInfo { size_t totalDiskHits; size_t nonGeometryHits; size_t geometryHits; + size_t particleHits; double time; bool warning = false; bool error = false; @@ -240,7 +241,7 @@ void adjustBoundingBox(rayPair> &bdBox, } } -std::array getTraceSettings(rayTraceDirection sourceDir) { +inline std::array getTraceSettings(rayTraceDirection sourceDir) { // Trace Settings: sourceDir, boundaryDir1, boundaryDir2, minMax bdBox source, // posNeg dir std::array set{0, 0, 0, 0, 0}; diff --git a/tests/diskAreas/diskAreas.cpp b/tests/diskAreas/diskAreas.cpp index 53314e1..178e44d 100644 --- a/tests/diskAreas/diskAreas.cpp +++ b/tests/diskAreas/diskAreas.cpp @@ -49,7 +49,7 @@ int main() { rayDataLog log; rayTraceInfo info; auto tracer = rayTraceKernel(device, geometry, boundary, raySource, cp, log, - 1, 0, false, true, 0, hitCounter, info); + 1, 0, false, true, 0.f, 0, hitCounter, info); tracer.setTracingData(&localData, &globalData); tracer.apply(); auto diskAreas = hitCounter.getDiskAreas(); From ce84e73901a31eac1e12fa2a0a0ffd422054ed6a Mon Sep 17 00:00:00 2001 From: Tobias Reiter Date: Tue, 23 Apr 2024 19:52:51 +0200 Subject: [PATCH 2/4] Normalize direction after gas scatter --- include/viennaray/rayTraceKernel.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/viennaray/rayTraceKernel.hpp b/include/viennaray/rayTraceKernel.hpp index 1e9f9b4..251e32b 100644 --- a/include/viennaray/rayTraceKernel.hpp +++ b/include/viennaray/rayTraceKernel.hpp @@ -183,6 +183,7 @@ class rayTraceKernel { for (int i = 0; i < D; ++i) { direction[i] = 2.f * dist(RngState) - 1.f; } + rayInternal::Normalize(direction); // Update ray direction and origin #ifdef ARCH_X86 From 61036860f25d57cea38aa3aecfa28dc1c05aaacc Mon Sep 17 00:00:00 2001 From: Tobias Reiter Date: Tue, 23 Apr 2024 19:58:07 +0200 Subject: [PATCH 3/4] Add nodiscard in util functions --- include/viennaray/rayUtil.hpp | 57 +++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/include/viennaray/rayUtil.hpp b/include/viennaray/rayUtil.hpp index 3a20bc9..c1e8918 100644 --- a/include/viennaray/rayUtil.hpp +++ b/include/viennaray/rayUtil.hpp @@ -86,40 +86,41 @@ constexpr double DiskFactor = 0.5 * (D == 3 ? 1.7320508 : 1.41421356237) * /* ------------- Vector operation functions ------------- */ template -rayTriple Sum(const rayTriple &pVecA, - const rayTriple &pVecB) { +[[nodiscard]] rayTriple Sum(const rayTriple &pVecA, + const rayTriple &pVecB) { return {pVecA[0] + pVecB[0], pVecA[1] + pVecB[1], pVecA[2] + pVecB[2]}; } template -rayTriple Sum(const rayTriple &pVecA, - const rayTriple &pVecB, - const rayTriple &pT) { +[[nodiscard]] rayTriple Sum(const rayTriple &pVecA, + const rayTriple &pVecB, + const rayTriple &pT) { return {pVecA[0] + pVecB[0] + pT[0], pVecA[1] + pVecB[1] + pT[1], pVecA[2] + pVecB[2] + pT[2]}; } template -rayTriple Diff(const rayTriple &pVecA, - const rayTriple &pVecB) { +[[nodiscard]] rayTriple Diff(const rayTriple &pVecA, + const rayTriple &pVecB) { return {pVecA[0] - pVecB[0], pVecA[1] - pVecB[1], pVecA[2] - pVecB[2]}; } template -rayPair Diff(const rayPair &pVecA, - const rayPair &pVecB) { +[[nodiscard]] rayPair Diff(const rayPair &pVecA, + const rayPair &pVecB) { return {pVecA[0] - pVecB[0], pVecA[1] - pVecB[1]}; } template -NumericType DotProduct(const rayTriple &pVecA, - const rayTriple &pVecB) { +[[nodiscard]] NumericType DotProduct(const rayTriple &pVecA, + const rayTriple &pVecB) { return pVecA[0] * pVecB[0] + pVecA[1] * pVecB[1] + pVecA[2] * pVecB[2]; } template -rayTriple CrossProduct(const rayTriple &pVecA, - const rayTriple &pVecB) { +[[nodiscard]] rayTriple +CrossProduct(const rayTriple &pVecA, + const rayTriple &pVecB) { rayTriple rr; rr[0] = pVecA[1] * pVecB[2] - pVecA[2] * pVecB[1]; rr[1] = pVecA[2] * pVecB[0] - pVecA[0] * pVecB[2]; @@ -128,7 +129,7 @@ rayTriple CrossProduct(const rayTriple &pVecA, } template -NumericType Norm(const std::array &vec) { +[[nodiscard]] NumericType Norm(const std::array &vec) { NumericType norm = 0; std::for_each(vec.begin(), vec.end(), [&norm](NumericType entry) { norm += entry * entry; }); @@ -145,7 +146,8 @@ void Normalize(std::array &vec) { } template -std::array Normalize(const std::array &vec) { +[[nodiscard]] std::array +Normalize(const std::array &vec) { std::array normedVec = vec; auto norm = 1. / Norm(normedVec); if (norm == 1.) @@ -157,12 +159,13 @@ std::array Normalize(const std::array &vec) { } template -rayTriple Inv(const rayTriple &vec) { +[[nodiscard]] rayTriple Inv(const rayTriple &vec) { return {-vec[0], -vec[1], -vec[2]}; } template -rayTriple Scale(const NumericType pF, rayTriple &pT) { +[[nodiscard]] rayTriple Scale(const NumericType pF, + rayTriple &pT) { pT[0] *= pF; pT[1] *= pF; pT[2] *= pF; @@ -170,20 +173,20 @@ rayTriple Scale(const NumericType pF, rayTriple &pT) { } template -rayTriple Scale(const NumericType pF, - const rayTriple &pT) { +[[nodiscard]] rayTriple Scale(const NumericType pF, + const rayTriple &pT) { return {pF * pT[0], pF * pT[1], pF * pT[2]}; } template -NumericType Distance(const std::array &pVecA, - const std::array &pVecB) { +[[nodiscard]] NumericType Distance(const std::array &pVecA, + const std::array &pVecB) { auto diff = Diff(pVecA, pVecB); return Norm(diff); } template -rayTriple +[[nodiscard]] rayTriple ComputeNormal(const rayTriple> &planeCoords) { auto uu = Diff(planeCoords[1], planeCoords[0]); auto vv = Diff(planeCoords[2], planeCoords[0]); @@ -241,7 +244,8 @@ void adjustBoundingBox(rayPair> &bdBox, } } -inline std::array getTraceSettings(rayTraceDirection sourceDir) { +[[nodiscard]] inline std::array +getTraceSettings(rayTraceDirection sourceDir) { // Trace Settings: sourceDir, boundaryDir1, boundaryDir2, minMax bdBox source, // posNeg dir std::array set{0, 0, 0, 0, 0}; @@ -301,7 +305,8 @@ inline std::array getTraceSettings(rayTraceDirection sourceDir) { /* ------------------------------------------------------ */ template -static rayTriple pickRandomPointOnUnitSphere(rayRNG &RNG) { +[[nodiscard]] static rayTriple +pickRandomPointOnUnitSphere(rayRNG &RNG) { std::uniform_real_distribution uniDist; NumericType x, y, z, x2, y2, x2py2; do { @@ -323,7 +328,7 @@ static rayTriple pickRandomPointOnUnitSphere(rayRNG &RNG) { // This function is deterministic, i.e., for one input it will return always // the same result. template -rayTriple> +[[nodiscard]] rayTriple> getOrthonormalBasis(const rayTriple &vec) { rayTriple> rr; rr[0] = vec; @@ -453,7 +458,7 @@ void writeVTK(std::string filename, /* -------------------------------------------------------------- */ template -std::vector> +[[nodiscard]] std::vector> createSourceGrid(const rayPair> &pBdBox, const size_t pNumPoints, const NumericType pGridDelta, const std::array &pTraceSettings) { From 1364966b57942a3453c3175721f19676b0b38522 Mon Sep 17 00:00:00 2001 From: Tobias Reiter Date: Tue, 23 Apr 2024 20:09:50 +0200 Subject: [PATCH 4/4] Add nodiscard on API getters --- include/viennaray/rayGeometry.hpp | 28 +++++++++++-------- include/viennaray/rayHitCounter.hpp | 12 ++++---- include/viennaray/rayReflection.hpp | 10 +++---- include/viennaray/rayTrace.hpp | 29 ++++++++++++------- include/viennaray/rayTracingData.hpp | 42 +++++++++++++++++----------- include/viennaray/rayUtil.hpp | 4 +-- 6 files changed, 75 insertions(+), 50 deletions(-) diff --git a/include/viennaray/rayGeometry.hpp b/include/viennaray/rayGeometry.hpp index 302b9b8..4a8ad50 100644 --- a/include/viennaray/rayGeometry.hpp +++ b/include/viennaray/rayGeometry.hpp @@ -108,53 +108,59 @@ template class rayGeometry { } } - rayPair> getBoundingBox() const { + [[nodiscard]] rayPair> getBoundingBox() const { return {minCoords_, maxCoords_}; } - rayTriple getPoint(const unsigned int primID) const { + [[nodiscard]] rayTriple + getPoint(const unsigned int primID) const { assert(primID < numPoints_ && "rayGeometry: Prim ID out of bounds"); auto const &pnt = pPointBuffer_[primID]; return {(NumericType)pnt.xx, (NumericType)pnt.yy, (NumericType)pnt.zz}; } - std::vector const & + [[nodiscard]] std::vector const & getNeighborIndicies(const unsigned int idx) const { assert(idx < numPoints_ && "rayGeometry: Index out of bounds"); return pointNeighborhood_[idx]; } - size_t getNumPoints() const { return numPoints_; } + [[nodiscard]] size_t getNumPoints() const { return numPoints_; } - NumericType getDiscRadius() const { return discRadii_; } + [[nodiscard]] NumericType getDiscRadius() const { return discRadii_; } - RTCGeometry const &getRTCGeometry() const { return pRtcGeometry_; } + [[nodiscard]] RTCGeometry const &getRTCGeometry() const { + return pRtcGeometry_; + } - rayTriple getPrimNormal(const unsigned int primID) const { + [[nodiscard]] rayTriple + getPrimNormal(const unsigned int primID) const { assert(primID < numPoints_ && "rayGeometry: Prim ID out of bounds"); auto const &normal = pNormalVecBuffer_[primID]; return {(NumericType)normal.xx, (NumericType)normal.yy, (NumericType)normal.zz}; } - rayQuadruple &getPrimRef(unsigned int primID) { + [[nodiscard]] rayQuadruple & + getPrimRef(unsigned int primID) { assert(primID < numPoints_ && "rayGeometry: Prim ID out of bounds"); return *reinterpret_cast *>( &pPointBuffer_[primID]); } - rayTriple &getNormalRef(unsigned int primID) { + [[nodiscard]] rayTriple & + getNormalRef(unsigned int primID) { assert(primID < numPoints_ && "rayGeometry: Prim ID out of bounds"); return *reinterpret_cast *>( &pNormalVecBuffer_[primID]); } - int getMaterialId(const unsigned int primID) const { + [[nodiscard]] int getMaterialId(const unsigned int primID) const { assert(primID < numPoints_ && "rayGeometry Prim ID out of bounds"); return materialIds_[primID]; } - bool checkGeometryEmpty() const { + [[nodiscard]] bool checkGeometryEmpty() const { if (pPointBuffer_ == nullptr || pNormalVecBuffer_ == nullptr || pRtcGeometry_ == nullptr) { return true; diff --git a/include/viennaray/rayHitCounter.hpp b/include/viennaray/rayHitCounter.hpp index 30dad25..6b82a2a 100644 --- a/include/viennaray/rayHitCounter.hpp +++ b/include/viennaray/rayHitCounter.hpp @@ -117,15 +117,17 @@ template class rayHitCounter { S2s_.clear(); } - std::vector getValues() const { return S1s_; } + [[nodiscard]] std::vector getValues() const { return S1s_; } - std::vector getCounts() const { return counts_; } + [[nodiscard]] std::vector getCounts() const { return counts_; } - size_t getTotalCounts() const { return totalCounts_; } + [[nodiscard]] size_t getTotalCounts() const { return totalCounts_; } - const std::vector &getDiskAreas() const { return diskAreas_; } + [[nodiscard]] const std::vector &getDiskAreas() const { + return diskAreas_; + } - std::vector getRelativeError() { + [[nodiscard]] std::vector getRelativeError() { auto result = std::vector( S1s_.size(), std::numeric_limits::max()); // size, initial values diff --git a/include/viennaray/rayReflection.hpp b/include/viennaray/rayReflection.hpp index defb7bb..e3dd1ce 100644 --- a/include/viennaray/rayReflection.hpp +++ b/include/viennaray/rayReflection.hpp @@ -5,7 +5,7 @@ // Specular reflection template -static rayTriple +[[nodiscard]] rayTriple rayReflectionSpecular(const rayTriple &rayDir, const rayTriple &geomNormal) { assert(rayInternal::IsNormalized(geomNormal) && @@ -26,7 +26,7 @@ rayReflectionSpecular(const rayTriple &rayDir, // Diffuse reflection template -static rayTriple +[[nodiscard]] rayTriple rayReflectionDiffuse(const rayTriple &geomNormal, rayRNG &RNG) { assert(rayInternal::IsNormalized(geomNormal) && "rayReflectionDiffuse: Surface normal is not normalized"); @@ -48,7 +48,7 @@ rayReflectionDiffuse(const rayTriple &geomNormal, rayRNG &RNG) { // Coned specular reflection template -static rayTriple rayReflectionConedCosine( +[[nodiscard]] rayTriple rayReflectionConedCosine( const rayTriple &rayDir, const rayTriple &geomNormal, rayRNG &RNG, const NumericType maxConeAngle /*max opening angle of the cone*/) { @@ -104,7 +104,7 @@ namespace rayInternal { // Coned cosine reflection (deprecated) template -static rayTriple rayReflectionConedCosineOld( +[[nodiscard]] rayTriple rayReflectionConedCosineOld( NumericType avgReflAngle, const rayTriple &rayDir, const rayTriple &geomNormal, rayRNG &RNG) { @@ -193,7 +193,7 @@ static rayTriple rayReflectionConedCosineOld( } template -static rayTriple +[[nodiscard]] rayTriple rayReflectionConedCosineOld2(const rayTriple &rayDir, const rayTriple &geomNormal, rayRNG &RNG, NumericType &minAvgConeAngle = 0.) { diff --git a/include/viennaray/rayTrace.hpp b/include/viennaray/rayTrace.hpp index f73df3a..84019bf 100644 --- a/include/viennaray/rayTrace.hpp +++ b/include/viennaray/rayTrace.hpp @@ -173,13 +173,14 @@ template class rayTrace { } /// Returns the total flux on each disk. - std::vector getTotalFlux() const { + [[nodiscard]] std::vector getTotalFlux() const { return hitCounter_.getValues(); } /// Returns the normalized flux on each disk. - std::vector getNormalizedFlux(rayNormalizationType normalization, - bool averageNeighborhood = false) { + [[nodiscard]] std::vector + getNormalizedFlux(rayNormalizationType normalization, + bool averageNeighborhood = false) { auto flux = hitCounter_.getValues(); normalizeFlux(flux, normalization); if (averageNeighborhood) { @@ -244,27 +245,35 @@ template class rayTrace { } /// Returns the total number of hits for each geometry point. - std::vector getHitCounts() const { return hitCounter_.getCounts(); } + [[nodiscard]] std::vector getHitCounts() const { + return hitCounter_.getCounts(); + } /// Returns the relative error of the flux for each geometry point - std::vector getRelativeError() { + [[nodiscard]] std::vector getRelativeError() { return hitCounter_.getRelativeError(); } /// Returns the disk area for each geometry point - std::vector getDiskAreas() { return hitCounter_.getDiskAreas(); } + [[nodiscard]] std::vector getDiskAreas() { + return hitCounter_.getDiskAreas(); + } - rayTracingData &getLocalData() { return localData_; } + [[nodiscard]] rayTracingData &getLocalData() { + return localData_; + } - rayTracingData *getGlobalData() { return pGlobalData_; } + [[nodiscard]] rayTracingData *getGlobalData() { + return pGlobalData_; + } void setGlobalData(rayTracingData &data) { pGlobalData_ = &data; } - rayTraceInfo getRayTraceInfo() { return RTInfo_; } + [[nodiscard]] rayTraceInfo getRayTraceInfo() { return RTInfo_; } - rayDataLog &getDataLog() { return dataLog_; } + [[nodiscard]] rayDataLog &getDataLog() { return dataLog_; } private: NumericType getSourceArea() { diff --git a/include/viennaray/rayTracingData.hpp b/include/viennaray/rayTracingData.hpp index e56e04a..9021a8f 100644 --- a/include/viennaray/rayTracingData.hpp +++ b/include/viennaray/rayTracingData.hpp @@ -156,37 +156,45 @@ template class rayTracingData { scalarDataMerge_[num] = mergeType; } - vectorDataType &getVectorData(int i) { return vectorData_[i]; } + [[nodiscard]] vectorDataType &getVectorData(int i) { return vectorData_[i]; } - const vectorDataType &getVectorData(int i) const { return vectorData_[i]; } + [[nodiscard]] const vectorDataType &getVectorData(int i) const { + return vectorData_[i]; + } - vectorDataType &getVectorData(std::string label) { + [[nodiscard]] vectorDataType &getVectorData(std::string label) { int idx = getVectorDataIndex(label); return vectorData_[idx]; } - std::vector &getVectorData() { return vectorData_; } + [[nodiscard]] std::vector &getVectorData() { + return vectorData_; + } - const std::vector &getVectorData() const { + [[nodiscard]] const std::vector &getVectorData() const { return vectorData_; } - scalarDataType &getScalarData(int i) { return scalarData_[i]; } + [[nodiscard]] scalarDataType &getScalarData(int i) { return scalarData_[i]; } - const scalarDataType &getScalarData(int i) const { return scalarData_[i]; } + [[nodiscard]] const scalarDataType &getScalarData(int i) const { + return scalarData_[i]; + } - scalarDataType &getScalarData(std::string label) { + [[nodiscard]] scalarDataType &getScalarData(std::string label) { int idx = getScalarDataIndex(label); return scalarData_[idx]; } - std::vector &getScalarData() { return scalarData_; } + [[nodiscard]] std::vector &getScalarData() { + return scalarData_; + } - const std::vector &getScalarData() const { + [[nodiscard]] const std::vector &getScalarData() const { return scalarData_; } - std::string getVectorDataLabel(int i) const { + [[nodiscard]] std::string getVectorDataLabel(int i) const { if (i >= vectorDataLabels_.size()) rayMessage::getInstance() .addError("Getting vector data label in rayTracingData out of range.") @@ -194,7 +202,7 @@ template class rayTracingData { return vectorDataLabels_[i]; } - std::string getScalarDataLabel(int i) const { + [[nodiscard]] std::string getScalarDataLabel(int i) const { if (i >= scalarDataLabels_.size()) rayMessage::getInstance() .addError("Getting scalar data label in rayTracingData out of range.") @@ -202,7 +210,7 @@ template class rayTracingData { return scalarDataLabels_[i]; } - int getVectorDataIndex(std::string label) const { + [[nodiscard]] int getVectorDataIndex(std::string label) const { for (int i = 0; i < vectorDataLabels_.size(); ++i) { if (vectorDataLabels_[i] == label) { return i; @@ -214,7 +222,7 @@ template class rayTracingData { return -1; } - int getScalarDataIndex(std::string label) const { + [[nodiscard]] int getScalarDataIndex(std::string label) const { for (int i = 0; i < scalarDataLabels_.size(); ++i) { if (scalarDataLabels_[i] == label) { return i; @@ -226,11 +234,13 @@ template class rayTracingData { return -1; } - const rayTracingDataMergeEnum getVectorMergeType(int num) const { + [[nodiscard]] const rayTracingDataMergeEnum + getVectorMergeType(int num) const { return vectorDataMerge_[num]; } - const rayTracingDataMergeEnum getScalarMergeType(int num) const { + [[nodiscard]] const rayTracingDataMergeEnum + getScalarMergeType(int num) const { return scalarDataMerge_[num]; } }; diff --git a/include/viennaray/rayUtil.hpp b/include/viennaray/rayUtil.hpp index c1e8918..53ee9ec 100644 --- a/include/viennaray/rayUtil.hpp +++ b/include/viennaray/rayUtil.hpp @@ -164,12 +164,10 @@ template } template -[[nodiscard]] rayTriple Scale(const NumericType pF, - rayTriple &pT) { +void Scale(const NumericType pF, rayTriple &pT) { pT[0] *= pF; pT[1] *= pF; pT[2] *= pF; - return pT; } template