Skip to content

Commit 8ded62f

Browse files
committed
add support for SoftEdge SeparateEnergies
1 parent 0e08949 commit 8ded62f

File tree

6 files changed

+29
-154
lines changed

6 files changed

+29
-154
lines changed

Intern/rayx-core/src/Shader/LightSources/EnergyDistributions/DatFile.cpp

Lines changed: 0 additions & 106 deletions
This file was deleted.

Intern/rayx-core/src/Shader/LightSources/EnergyDistributions/DatFile.h

Lines changed: 0 additions & 40 deletions
This file was deleted.

Intern/rayx-core/src/Shader/LightSources/EnergyDistributions/EnergyDistribution.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,22 @@ RAYX_FN_ACC double selectEnergy(const SeparateEnergies& __restrict separateEnerg
5050
}
5151

5252
RAYX_FN_ACC double selectEnergy(const EnergyDistributionList& __restrict energyDistributionList, Rand& __restrict rand) {
53-
// TODO: implement all the other stuff from DayFile::selectEnergy
54-
// TODO: implement continous
5553
const auto r = rand.randomDouble() * energyDistributionList.weightSum;
5654
const int index = binarySearchPrefix(energyDistributionList.prefixWeights, energyDistributionList.size, r);
57-
return energyDistributionList.energies[index];
55+
56+
if (energyDistributionList.continous) {
57+
const auto centerEnergy = energyDistributionList.energies[index];
58+
if (index < energyDistributionList.size - 1)
59+
return rand.randomDoubleInRange(centerEnergy, energyDistributionList.energies[index + 1]);
60+
else
61+
return centerEnergy;
62+
} else {
63+
return energyDistributionList.energies[index];
64+
}
5865
}
5966

6067
RAYX_FN_ACC double selectEnergy(const EnergyDistributionDataVariant& __restrict energyDistribution, Rand& __restrict rand) {
61-
return std::visit([&]<typename T>(const T& __restrict value) { return selectEnergy(value, rand); }, energyDistribution);
68+
return energyDistribution.visit([&](const auto& __restrict value) { return selectEnergy(value, rand); });
6269
}
6370

6471
} // namespace rayx

Intern/rayx-core/src/Shader/LightSources/EnergyDistributions/EnergyDistribution.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "Beamline/EnergyDistribution.h"
44
#include "Core.h"
55
#include "Shader/Rand.h"
6+
#include "Variant.h"
67

78
namespace rayx {
89

@@ -14,8 +15,14 @@ struct EnergyDistributionList {
1415
bool continous;
1516
};
1617

17-
// TODO: use cuda::std::variant
18-
using EnergyDistributionDataVariant = std::variant<HardEdge, SoftEdge, SeparateEnergies, EnergyDistributionList>;
18+
struct EnergyDistributionDataBase {
19+
using HardEdge = rayx::HardEdge;
20+
using SoftEdge = rayx::SoftEdge;
21+
using SeparateEnergies = rayx::SeparateEnergies;
22+
using EnergyDistributionList = rayx::EnergyDistributionList;
23+
};
24+
25+
using EnergyDistributionDataVariant = Variant<EnergyDistributionDataBase, EnergyDistributionDataBase::HardEdge, EnergyDistributionDataBase::SoftEdge, SeparateEnergies, EnergyDistributionDataBase::EnergyDistributionList>;
1926

2027
RAYX_FN_ACC double selectEnergy(const HardEdge& __restrict hardEdge, Rand& __restrict rand);
2128
RAYX_FN_ACC double selectEnergy(const SoftEdge& __restrict softEdge, Rand& __restrict rand);

Intern/rayx-core/src/Tracer/GenRays.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ struct GenRays {
154154
weights.push_back(entry.m_weight);
155155
energies.push_back(entry.m_energy);
156156
}
157+
157158
std::vector<double> prefixWeights(weights.size());
158159
std::inclusive_scan(weights.begin(), weights.end(), prefixWeights.begin());
159160
const auto weightSum = weights.back() + prefixWeights.back();

Intern/rayx-core/tests/testRml.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,18 @@ TEST_F(TestSuite, allBeamlineObjects) {
1111
TEST_F(TestSuite, loadDatFile) {
1212
const auto rays = traceRml("loadDatFile", RayAttrMask::Energy);
1313
writeCsvUsingFilename(rays, "loadDatFile.rayx");
14-
expectEqualAny(rays.energy, {12.0, 15.0, 17.0});
14+
using namespace testing;
15+
EXPECT_THAT(rays.energy, Each(AnyOf(12, 15, 17)));
1516
}
1617

1718
TEST_F(TestSuite, loadDatFile2) {
1819
const auto rays = traceRml("loadDatFile2", RayAttrMask::Energy);
19-
expectEqualAny(rays.energy, {12.0, 15.0, 17.0});
20+
writeCsvUsingFilename(rays, "loadDatFile2.rayx");
21+
using namespace testing;
22+
EXPECT_THAT(rays.energy, Each(AllOf(Ge(12), Le(18))));
23+
EXPECT_THAT(rays.energy, Contains(AllOf(Ge(12), Le(13))));
24+
EXPECT_THAT(rays.energy, Contains(AllOf(Ge(15), Le(16))));
25+
EXPECT_THAT(rays.energy, Contains(AllOf(Ge(17), Le(18))));
2026
}
2127

2228
TEST_F(TestSuite, loadGroups) {

0 commit comments

Comments
 (0)