Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scatter probability with mean free path #54

Merged
merged 4 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions include/viennaray/rayGeometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ template <typename NumericType, int D> class rayGeometry {
public:
template <size_t Dim>
void initGeometry(RTCDevice &device,
std::vector<std::array<NumericType, Dim>> &points,
std::vector<std::array<NumericType, Dim>> &normals,
NumericType discRadii) {
std::vector<std::array<NumericType, Dim>> const &points,
std::vector<std::array<NumericType, Dim>> const &normals,
NumericType const discRadii) {
static_assert(!(D == 3 && Dim == 2) &&
"Setting 2D geometry in 3D trace object");

Expand Down Expand Up @@ -98,7 +98,7 @@ template <typename NumericType, int D> class rayGeometry {
}

template <typename MatIdType>
void setMaterialIds(std::vector<MatIdType> &pMaterialIds) {
void setMaterialIds(std::vector<MatIdType> const &pMaterialIds) {
assert(pMaterialIds.size() == numPoints_ &&
"rayGeometry: Material IDs size mismatch");
materialIds_.clear();
Expand All @@ -108,53 +108,59 @@ template <typename NumericType, int D> class rayGeometry {
}
}

rayPair<rayTriple<NumericType>> getBoundingBox() const {
[[nodiscard]] rayPair<rayTriple<NumericType>> getBoundingBox() const {
return {minCoords_, maxCoords_};
}

rayTriple<NumericType> getPoint(const unsigned int primID) const {
[[nodiscard]] rayTriple<NumericType>
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<unsigned int> const &
[[nodiscard]] std::vector<unsigned int> 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<NumericType> getPrimNormal(const unsigned int primID) const {
[[nodiscard]] rayTriple<NumericType>
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<rayInternal::rtcNumericType> &getPrimRef(unsigned int primID) {
[[nodiscard]] rayQuadruple<rayInternal::rtcNumericType> &
getPrimRef(unsigned int primID) {
assert(primID < numPoints_ && "rayGeometry: Prim ID out of bounds");
return *reinterpret_cast<rayQuadruple<rayInternal::rtcNumericType> *>(
&pPointBuffer_[primID]);
}

rayTriple<rayInternal::rtcNumericType> &getNormalRef(unsigned int primID) {
[[nodiscard]] rayTriple<rayInternal::rtcNumericType> &
getNormalRef(unsigned int primID) {
assert(primID < numPoints_ && "rayGeometry: Prim ID out of bounds");
return *reinterpret_cast<rayTriple<rayInternal::rtcNumericType> *>(
&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;
Expand All @@ -179,8 +185,8 @@ template <typename NumericType, int D> class rayGeometry {

private:
template <size_t Dim>
void
initPointNeighborhood(std::vector<std::array<NumericType, Dim>> &points) {
void initPointNeighborhood(
std::vector<std::array<NumericType, Dim>> const &points) {
pointNeighborhood_.clear();
pointNeighborhood_.resize(numPoints_, std::vector<unsigned int>{});

Expand Down
12 changes: 7 additions & 5 deletions include/viennaray/rayHitCounter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,17 @@ template <typename NumericType> class rayHitCounter {
S2s_.clear();
}

std::vector<NumericType> getValues() const { return S1s_; }
[[nodiscard]] std::vector<NumericType> getValues() const { return S1s_; }

std::vector<size_t> getCounts() const { return counts_; }
[[nodiscard]] std::vector<size_t> getCounts() const { return counts_; }

size_t getTotalCounts() const { return totalCounts_; }
[[nodiscard]] size_t getTotalCounts() const { return totalCounts_; }

const std::vector<NumericType> &getDiskAreas() const { return diskAreas_; }
[[nodiscard]] const std::vector<NumericType> &getDiskAreas() const {
return diskAreas_;
}

std::vector<NumericType> getRelativeError() {
[[nodiscard]] std::vector<NumericType> getRelativeError() {
auto result = std::vector<NumericType>(
S1s_.size(),
std::numeric_limits<NumericType>::max()); // size, initial values
Expand Down
10 changes: 5 additions & 5 deletions include/viennaray/rayReflection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

// Specular reflection
template <typename NumericType, int D = 3>
static rayTriple<NumericType>
[[nodiscard]] rayTriple<NumericType>
rayReflectionSpecular(const rayTriple<NumericType> &rayDir,
const rayTriple<NumericType> &geomNormal) {
assert(rayInternal::IsNormalized(geomNormal) &&
Expand All @@ -26,7 +26,7 @@ rayReflectionSpecular(const rayTriple<NumericType> &rayDir,

// Diffuse reflection
template <typename NumericType, int D>
static rayTriple<NumericType>
[[nodiscard]] rayTriple<NumericType>
rayReflectionDiffuse(const rayTriple<NumericType> &geomNormal, rayRNG &RNG) {
assert(rayInternal::IsNormalized(geomNormal) &&
"rayReflectionDiffuse: Surface normal is not normalized");
Expand All @@ -48,7 +48,7 @@ rayReflectionDiffuse(const rayTriple<NumericType> &geomNormal, rayRNG &RNG) {

// Coned specular reflection
template <typename NumericType, int D>
static rayTriple<NumericType> rayReflectionConedCosine(
[[nodiscard]] rayTriple<NumericType> rayReflectionConedCosine(
const rayTriple<NumericType> &rayDir,
const rayTriple<NumericType> &geomNormal, rayRNG &RNG,
const NumericType maxConeAngle /*max opening angle of the cone*/) {
Expand Down Expand Up @@ -104,7 +104,7 @@ namespace rayInternal {

// Coned cosine reflection (deprecated)
template <typename NumericType, int D>
static rayTriple<NumericType> rayReflectionConedCosineOld(
[[nodiscard]] rayTriple<NumericType> rayReflectionConedCosineOld(
NumericType avgReflAngle, const rayTriple<NumericType> &rayDir,
const rayTriple<NumericType> &geomNormal, rayRNG &RNG) {

Expand Down Expand Up @@ -193,7 +193,7 @@ static rayTriple<NumericType> rayReflectionConedCosineOld(
}

template <typename NumericType, int D>
static rayTriple<NumericType>
[[nodiscard]] rayTriple<NumericType>
rayReflectionConedCosineOld2(const rayTriple<NumericType> &rayDir,
const rayTriple<NumericType> &geomNormal,
rayRNG &RNG, NumericType &minAvgConeAngle = 0.) {
Expand Down
46 changes: 29 additions & 17 deletions include/viennaray/rayTrace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ template <class NumericType, int D> 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();

Expand All @@ -80,8 +80,8 @@ template <class NumericType, int D> class rayTrace {
/// It is possible to set a 2D geometry with 3D points.
/// In this case the last dimension is ignored.
template <std::size_t Dim>
void setGeometry(std::vector<std::array<NumericType, Dim>> &points,
std::vector<std::array<NumericType, Dim>> &normals,
void setGeometry(std::vector<std::array<NumericType, Dim>> const &points,
std::vector<std::array<NumericType, Dim>> const &normals,
const NumericType gridDelta) {
static_assert((D != 3 || Dim != 2) &&
"Setting 2D geometry in 3D trace object");
Expand All @@ -94,8 +94,8 @@ template <class NumericType, int D> class rayTrace {
/// Set the ray tracing geometry
/// Specify the disk radius manually.
template <std::size_t Dim>
void setGeometry(std::vector<std::array<NumericType, Dim>> &points,
std::vector<std::array<NumericType, Dim>> &normals,
void setGeometry(std::vector<std::array<NumericType, Dim>> const &points,
std::vector<std::array<NumericType, Dim>> const &normals,
const NumericType gridDelta, const NumericType diskRadii) {
static_assert((D != 3 || Dim != 2) &&
"Setting 2D geometry in 3D trace object");
Expand All @@ -107,7 +107,7 @@ template <class NumericType, int D> class rayTrace {

/// Set material ID's for each geometry point.
/// If not set, all material ID's are default 0.
template <typename T> void setMaterialIds(std::vector<T> &materialIds) {
template <typename T> void setMaterialIds(std::vector<T> const &materialIds) {
geometry_.setMaterialIds(materialIds);
}

Expand Down Expand Up @@ -151,6 +151,8 @@ template <class NumericType, int D> 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; }
Expand All @@ -171,13 +173,14 @@ template <class NumericType, int D> class rayTrace {
}

/// Returns the total flux on each disk.
std::vector<NumericType> getTotalFlux() const {
[[nodiscard]] std::vector<NumericType> getTotalFlux() const {
return hitCounter_.getValues();
}

/// Returns the normalized flux on each disk.
std::vector<NumericType> getNormalizedFlux(rayNormalizationType normalization,
bool averageNeighborhood = false) {
[[nodiscard]] std::vector<NumericType>
getNormalizedFlux(rayNormalizationType normalization,
bool averageNeighborhood = false) {
auto flux = hitCounter_.getValues();
normalizeFlux(flux, normalization);
if (averageNeighborhood) {
Expand Down Expand Up @@ -242,27 +245,35 @@ template <class NumericType, int D> class rayTrace {
}

/// Returns the total number of hits for each geometry point.
std::vector<size_t> getHitCounts() const { return hitCounter_.getCounts(); }
[[nodiscard]] std::vector<size_t> getHitCounts() const {
return hitCounter_.getCounts();
}

/// Returns the relative error of the flux for each geometry point
std::vector<NumericType> getRelativeError() {
[[nodiscard]] std::vector<NumericType> getRelativeError() {
return hitCounter_.getRelativeError();
}

/// Returns the disk area for each geometry point
std::vector<NumericType> getDiskAreas() { return hitCounter_.getDiskAreas(); }
[[nodiscard]] std::vector<NumericType> getDiskAreas() {
return hitCounter_.getDiskAreas();
}

rayTracingData<NumericType> &getLocalData() { return localData_; }
[[nodiscard]] rayTracingData<NumericType> &getLocalData() {
return localData_;
}

rayTracingData<NumericType> *getGlobalData() { return pGlobalData_; }
[[nodiscard]] rayTracingData<NumericType> *getGlobalData() {
return pGlobalData_;
}

void setGlobalData(rayTracingData<NumericType> &data) {
pGlobalData_ = &data;
}

rayTraceInfo getRayTraceInfo() { return RTInfo_; }
[[nodiscard]] rayTraceInfo getRayTraceInfo() { return RTInfo_; }

rayDataLog<NumericType> &getDataLog() { return dataLog_; }
[[nodiscard]] rayDataLog<NumericType> &getDataLog() { return dataLog_; }

private:
NumericType getSourceArea() {
Expand Down Expand Up @@ -374,6 +385,7 @@ template <class NumericType, int D> class rayTrace {
size_t runNumber_ = 0;
bool calcFlux_ = true;
bool checkError_ = true;
NumericType lambda_ = -1.;
rayHitCounter<NumericType> hitCounter_;
rayTracingData<NumericType> localData_;
rayTracingData<NumericType> *pGlobalData_ = nullptr;
Expand Down
Loading
Loading