Skip to content

Commit

Permalink
Add specular particle and particle tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tobre1 committed Oct 28, 2024
1 parent eadc579 commit fd59fa8
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
43 changes: 43 additions & 0 deletions include/viennaray/rayParticle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,47 @@ class DiffuseParticle
}
};

template <typename NumericType, int D>
class SpecularParticle
: public Particle<SpecularParticle<NumericType, D>, NumericType> {
const NumericType stickingProbability_;
const NumericType sourcePower_;
const std::string dataLabel_;

public:
SpecularParticle(NumericType stickingProbability, NumericType sourcePower,
std::string dataLabel)
: stickingProbability_(stickingProbability), sourcePower_(sourcePower),
dataLabel_(dataLabel) {}

std::pair<NumericType, Vec3D<NumericType>>
surfaceReflection(NumericType rayWeight, const Vec3D<NumericType> &rayDir,
const Vec3D<NumericType> &geomNormal,
const unsigned int primID, const int materialId,
const TracingData<NumericType> *globalData,
RNG &rngState) override final {
auto direction = ReflectionSpecular<NumericType, D>(rayDir, geomNormal);
return std::pair<NumericType, Vec3D<NumericType>>{stickingProbability_,
direction};
}

void surfaceCollision(NumericType rayWeight, const Vec3D<NumericType> &rayDir,
const Vec3D<NumericType> &geomNormal,
const unsigned int primID, const int materialId,
TracingData<NumericType> &localData,
const TracingData<NumericType> *globalData,
RNG &rngState) override final {
// collect data for this hit
localData.getVectorData(0)[primID] += rayWeight;
}

NumericType getSourceDistributionPower() const override final {
return sourcePower_;
}

std::vector<std::string> getLocalDataLabels() const override final {
return {dataLabel_};
}
};

} // namespace viennaray
7 changes: 7 additions & 0 deletions tests/particle/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
project(particle 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 $<TARGET_FILE:${PROJECT_NAME}>)
45 changes: 45 additions & 0 deletions tests/particle/particle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <rayParticle.hpp>
#include <rayTrace.hpp>

#include <vcTestAsserts.hpp>

namespace viennacore {

using namespace viennaray;

template <class NumericType, int D> void RunTest() {

{
auto particle =
std::make_unique<DiffuseParticle<NumericType, D>>(1., "test");

NumericType sourcePower = particle->getSourceDistributionPower();
VC_TEST_ASSERT(sourcePower == 1.);

auto labels = particle->getLocalDataLabels();
VC_TEST_ASSERT(labels.size() == 1);
VC_TEST_ASSERT(labels[0] == "test");

Trace<NumericType, D> tracer;
tracer.setParticleType(particle);
}

{
auto particle =
std::make_unique<SpecularParticle<NumericType, D>>(1., 100., "test");

NumericType sourcePower = particle->getSourceDistributionPower();
VC_TEST_ASSERT(sourcePower == 100.);

auto labels = particle->getLocalDataLabels();
VC_TEST_ASSERT(labels.size() == 1);
VC_TEST_ASSERT(labels[0] == "test");

Trace<NumericType, D> tracer;
tracer.setParticleType(particle);
}
}

} // namespace viennacore

int main() { VC_RUN_ALL_TESTS }

0 comments on commit fd59fa8

Please sign in to comment.