Skip to content

Commit

Permalink
Fix test units; Update operator bools; Fix ScintillationParams bug
Browse files Browse the repository at this point in the history
  • Loading branch information
stognini committed Mar 20, 2024
1 parent c55c8f9 commit 5d2fa13
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/celeritas/io/ImportOpticalMaterial.hh
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ struct ImportScintData
//! Whether all data are assigned and valid
explicit operator bool() const
{
return static_cast<bool>(material) && resolution_scale >= 0;
return (static_cast<bool>(material) || !particles.empty())
&& resolution_scale >= 0;
}
};

Expand Down
15 changes: 7 additions & 8 deletions src/celeritas/optical/ScintillationData.hh
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ struct ScintillationData
//! Components for either material or particle items
Items<ScintillationComponent> components;

size_type num_materials{};
size_type num_particles{};
size_type num_opt_materials{};
size_type num_opt_particles{};

//// MEMBER FUNCTIONS ////

Expand All @@ -147,8 +147,7 @@ struct ScintillationData
{
return !matid_to_optmatid.empty() && !pid_to_scintpid.empty()
&& (!materials.empty() || !particles.empty())
&& num_materials == matid_to_optmatid.size()
&& num_particles == pid_to_scintpid.size();
&& num_opt_materials > 0 && num_opt_particles > 0;
}

//! Whether sampling must happen by particle type
Expand All @@ -161,8 +160,8 @@ struct ScintillationData
ParticleScintSpectrumId
spectrum_index(ScintillationParticleId pid, OpticalMaterialId mat_id) const
{
CELER_EXPECT(mat_id < num_materials && pid < num_particles);
return ParticleScintSpectrumId{num_materials * pid.get()
CELER_EXPECT(mat_id < num_opt_materials && pid < num_opt_particles);
return ParticleScintSpectrumId{num_opt_materials * pid.get()
+ mat_id.get()};
}

Expand All @@ -178,8 +177,8 @@ struct ScintillationData
particles = other.particles;
grid_data = other.grid_data;
components = other.components;
num_materials = other.num_materials;
num_particles = other.num_particles;
num_opt_materials = other.num_opt_materials;
num_opt_particles = other.num_opt_particles;
return *this;
}
};
Expand Down
14 changes: 10 additions & 4 deletions src/celeritas/optical/ScintillationParams.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,28 @@ ScintillationParams::ScintillationParams(Input const& input,

auto const num_mat = input.matid_to_optmatid.size();
auto const num_part = input.pid_to_scintpid.size();
host_data.num_materials = num_mat;
host_data.num_particles = num_part;

// Store material ids
for (auto const id : input.matid_to_optmatid)
{
build_optmatid.push_back(id);
if (id)
{
host_data.num_opt_materials++;
}
}
CELER_ENSURE(build_optmatid.size() == num_mat);
CELER_ENSURE(host_data.num_opt_materials > 0);

// Store particle ids
for (auto const id : input.pid_to_scintpid)
{
build_scintpid.push_back(id);
if (id)
{
host_data.num_opt_particles++;
}
}
CELER_ENSURE(build_scintpid.size() == num_part);
CELER_ENSURE(host_data.num_opt_particles > 0);

// Store resolution scale
for (auto const& inp : input.data)
Expand Down
18 changes: 15 additions & 3 deletions test/celeritas/optical/Scintillation.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "corecel/data/Collection.hh"
#include "corecel/data/CollectionBuilder.hh"
#include "corecel/data/CollectionMirror.hh"
#include "geocel/UnitUtils.hh"
#include "celeritas/Quantities.hh"
#include "celeritas/Types.hh"
#include "celeritas/optical/OpticalDistributionData.hh"
Expand Down Expand Up @@ -124,7 +125,7 @@ class ScintillationTest : public OpticalTestBase
pregen_data.points[StepPoint::pre].speed = LightSpeed(0.99);
pregen_data.points[StepPoint::post].speed = LightSpeed(0.99 * 0.9);
pregen_data.points[StepPoint::pre].pos = {0, 0, 0};
pregen_data.points[StepPoint::post].pos = {0, 0, 1};
pregen_data.points[StepPoint::post].pos = {0, 0, from_cm(1)};
return pregen_data;
}

Expand All @@ -144,8 +145,8 @@ TEST_F(ScintillationTest, material_scint_params)

auto const opt_matid = data.matid_to_optmatid[MaterialId{0}];

EXPECT_EQ(1, data.num_materials);
EXPECT_EQ(1, data.num_particles);
EXPECT_EQ(1, data.num_opt_materials);
EXPECT_EQ(1, data.num_opt_particles);
EXPECT_EQ(1, data.materials.size());
EXPECT_EQ(0, opt_matid.get());

Expand Down Expand Up @@ -353,6 +354,17 @@ TEST_F(ScintillationTest, basic)
-0.57457399792055};
static double const expected_cos_polar[] = {0, 0, 0, 0};

/* CI gpu (clhep, vecgeom, debug) log
Expected: expected_time
4 of 4 elements differ
by 9.9999999999999998e-13 relative error or 1e-14 absolute error
i expected_time time Difference
0 3.2080893159083e-08 3.20580539320367e-08 -0.000711926159069127
1 6.136381528505e-09 6.11117967007341e-09 -0.00410695754729784
2 1.7964298529751e-06 1.79642453445081e-06 -2.96060783146328e-06
3 8.0854850049769e-07 8.08544680544845e-07 -4.72445727405664e-06
*/

EXPECT_VEC_SOFT_EQ(expected_energy, energy);
EXPECT_VEC_SOFT_EQ(expected_time, time);
EXPECT_VEC_SOFT_EQ(expected_cos_theta, cos_theta);
Expand Down

0 comments on commit 5d2fa13

Please sign in to comment.