Skip to content

Commit

Permalink
Use shared pointer for custom source (#56)
Browse files Browse the repository at this point in the history
* Use shared pointer for setting source

* Add const in setParticleType arg

* Bump version
  • Loading branch information
tobre1 authored May 13, 2024
1 parent 504066d commit 5e526c1
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
project(
ViennaRay
LANGUAGES CXX
VERSION 2.1.0)
VERSION 2.1.1)

# --------------------------------------------------------------------------------------------------------
# Library switches
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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@2.1.0")
CPMAddPackage("gh:viennatools/viennaray@2.1.1")
```

* With a local installation
Expand Down
2 changes: 1 addition & 1 deletion include/viennaray/raySource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <rayRNG.hpp>
#include <rayUtil.hpp>

template <typename NumericType, int D> class raySource {
template <typename NumericType> class raySource {
public:
virtual ~raySource() = default;

Expand Down
2 changes: 1 addition & 1 deletion include/viennaray/raySourceGrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <raySource.hpp>

template <typename NumericType, int D>
class raySourceGrid : public raySource<NumericType, D> {
class raySourceGrid : public raySource<NumericType> {
public:
raySourceGrid(std::vector<rayTriple<NumericType>> &sourceGrid,
NumericType cosinePower,
Expand Down
2 changes: 1 addition & 1 deletion include/viennaray/raySourceRandom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <raySource.hpp>

template <typename NumericType, int D>
class raySourceRandom : public raySource<NumericType, D> {
class raySourceRandom : public raySource<NumericType> {
using boundingBoxType = rayPair<rayTriple<NumericType>>;

public:
Expand Down
8 changes: 4 additions & 4 deletions include/viennaray/rayTrace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ template <class NumericType, int D> class rayTrace {
std::enable_if_t<std::is_base_of_v<rayAbstractParticle<NumericType>,
ParticleType>,
bool> = true>
void setParticleType(std::unique_ptr<ParticleType> &particle) {
void setParticleType(std::unique_ptr<ParticleType> const &particle) {
pParticle_ = particle->clone();
}

Expand Down Expand Up @@ -125,8 +125,8 @@ template <class NumericType, int D> class rayTrace {
/// Set a custom source for the ray tracing. Per default a random source is
/// set up. The source has to be a user defined object that has to interface
/// the raySource class.
void setSource(std::unique_ptr<raySource<NumericType, D>> source) {
pSource_ = std::move(source);
void setSource(std::shared_ptr<raySource<NumericType>> source) {
pSource_ = source;
}

/// Reset the source to the default random source.
Expand Down Expand Up @@ -383,7 +383,7 @@ template <class NumericType, int D> class rayTrace {

rayGeometry<NumericType, D> geometry_;
std::unique_ptr<rayAbstractParticle<NumericType>> pParticle_ = nullptr;
std::unique_ptr<raySource<NumericType, D>> pSource_ = nullptr;
std::shared_ptr<raySource<NumericType>> pSource_ = nullptr;

size_t numberOfRaysPerPoint_ = 1000;
size_t numberOfRaysFixed_ = 0;
Expand Down
9 changes: 5 additions & 4 deletions include/viennaray/rayTraceKernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ template <typename NumericType, int D> class rayTraceKernel {
public:
rayTraceKernel(RTCDevice &device, rayGeometry<NumericType, D> &geometry,
rayBoundary<NumericType, D> &boundary,
std::unique_ptr<raySource<NumericType, D>> source,
std::shared_ptr<raySource<NumericType>> source,
std::unique_ptr<rayAbstractParticle<NumericType>> &particle,
rayDataLog<NumericType> &dataLog, const size_t numRaysPerPoint,
const size_t numRaysFixed, const bool useRandomSeed,
const bool calcFlux, const size_t runNumber,
rayHitCounter<NumericType> &hitCounter,
rayTraceInfo &traceInfo)
: device_(device), geometry_(geometry), boundary_(boundary),
pSource_(std::move(source)), pParticle_(particle->clone()),
pSource_(source), pParticle_(particle->clone()),
numRays_(numRaysFixed == 0 ? pSource_->getNumPoints() * numRaysPerPoint
: numRaysFixed),
useRandomSeeds_(useRandomSeed), runNumber_(runNumber),
Expand Down Expand Up @@ -85,7 +85,8 @@ template <typename NumericType, int D> class rayTraceKernel {

auto time = rayInternal::timeStampNow<std::chrono::milliseconds>();

#pragma omp parallel reduction(+ : geohitc, nongeohitc, totaltraces, particlehitc) \
#pragma omp parallel reduction(+ : geohitc, nongeohitc, totaltraces, \
particlehitc) \
shared(threadLocalData, threadLocalHitCounter)
{
rtcJoinCommitScene(rtcScene);
Expand Down Expand Up @@ -600,7 +601,7 @@ template <typename NumericType, int D> class rayTraceKernel {

rayGeometry<NumericType, D> &geometry_;
rayBoundary<NumericType, D> const &boundary_;
std::unique_ptr<raySource<NumericType, D>> const pSource_;
std::shared_ptr<raySource<NumericType>> const pSource_;
std::unique_ptr<rayAbstractParticle<NumericType>> const pParticle_;

const long long numRays_;
Expand Down
6 changes: 3 additions & 3 deletions tests/traceInterface/traceInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <rayTrace.hpp>

template <typename NumericType, int D>
class MySource : public raySource<NumericType, D> {
class MySource : public raySource<NumericType> {
public:
MySource() {}

Expand Down Expand Up @@ -45,8 +45,8 @@ int main() {
rayTracer.setUseRandomSeeds(false);
rayTracer.setMaterialIds(matIds);

auto mySource = std::make_unique<MySource<NumericType, D>>();
rayTracer.setSource(std::move(mySource));
auto mySource = std::make_shared<MySource<NumericType, D>>();
rayTracer.setSource(mySource);
rayTracer.resetSource();

rayTracer.apply();
Expand Down

0 comments on commit 5e526c1

Please sign in to comment.