Skip to content

Commit

Permalink
Reduce default maximum substeps in field propagator (#1384)
Browse files Browse the repository at this point in the history
* Reduce max substeps in field propagator from 100 to 10
* Update expected looping parameters in sim test
* Update along-step test results
* Update field propagator tests
* Use 100 max substeps in vecgeom failure test
* Check diagnostic action keys with CI build
  • Loading branch information
amandalund authored Aug 30, 2024
1 parent 0e7905d commit 36b4057
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/celeritas/field/FieldDriverOptions.hh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct FieldDriverOptions
short int max_nsteps = 100;

//! Maximum number of substeps in the field propagator
short int max_substeps = 100;
short int max_substeps = 10;

//! Initial step tolerance
static constexpr inline real_type initial_step_tol = 1e-6;
Expand Down
14 changes: 13 additions & 1 deletion test/celeritas/field/FieldPropagator.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,12 @@ TEST_F(TwoBoxesTest, electron_interior)
SCOPED_TRACE("Half turn");
stepper.reset_count();
result = propagate(pi * radius);
EXPECT_SOFT_EQ(pi * radius, result.distance);
// The maximum substep limit in the field propagator was reached before
// traveling the full distance; propagate again to reach the end
real_type partial_distance = 8.7323805094658429;
EXPECT_SOFT_EQ(partial_distance, result.distance);
result = propagate(pi * radius - partial_distance);
EXPECT_SOFT_EQ(pi * radius - partial_distance, result.distance);
EXPECT_LT(distance(Real3({radius, 0, 0}), geo.pos()), 1e-5);
EXPECT_SOFT_EQ(1.0, dot_product(Real3({0, 1, 0}), geo.dir()));
EXPECT_EQ(40, stepper.count());
Expand Down Expand Up @@ -675,6 +680,8 @@ TEST_F(TwoBoxesTest, electron_cross)
{
SCOPED_TRACE("Return to start (2/3 turn)");

FieldDriverOptions driver_options;
driver_options.max_substeps = 100;
auto geo = this->make_geo_track_view();
auto propagate = make_mag_field_propagator<DormandPrinceStepper>(
field, driver_options, particle, geo);
Expand Down Expand Up @@ -730,6 +737,8 @@ TEST_F(TwoBoxesTest, electron_tangent_cross)

real_type dy = 0.9 * driver_options.delta_chord;

FieldDriverOptions driver_options;
driver_options.max_substeps = 100;
auto geo = this->make_geo_track_view({1, 4 + dy, 0}, {0, 1, 0});
auto propagate = make_mag_field_propagator<DormandPrinceStepper>(
field, driver_options, particle, geo);
Expand Down Expand Up @@ -1016,6 +1025,7 @@ TEST_F(TwoBoxesTest,
auto stepper = make_mag_field_stepper<DiagnosticDPStepper>(
field, particle.charge());
FieldDriverOptions driver_options;
driver_options.max_substeps = 100;
auto propagate
= make_field_propagator(stepper, driver_options, particle, geo);
for (int i : range(2))
Expand Down Expand Up @@ -1247,6 +1257,7 @@ TEST_F(SimpleCmsTest, TEST_IF_CELERITAS_DOUBLE(vecgeom_failure))
{
UniformZField field(1 * units::tesla);
FieldDriverOptions driver_options;
driver_options.max_substeps = 100;

auto geo = this->make_geo_track_view({1.23254142755319734e+02,
-2.08186543568394598e+01,
Expand Down Expand Up @@ -1386,6 +1397,7 @@ TEST_F(CmseTest, coarse)
FieldDriverOptions driver_options;
driver_options.delta_intersection = 0.001;
driver_options.delta_chord = 0.1;
driver_options.max_substeps = 100;

std::vector<int> num_boundary;
std::vector<int> num_step;
Expand Down
15 changes: 8 additions & 7 deletions test/celeritas/global/AlongStep.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ TEST_F(MockAlongStepFieldTest, TEST_IF_CELERITAS_DOUBLE(basic))
inp.phys_mfp = 100;
auto result = this->run(inp, num_tracks);
EXPECT_SOFT_EQ(0.001, result.eloss);
EXPECT_SOFT_NEAR(0.014775335072293276, result.displacement, 1e-10);
EXPECT_SOFT_NEAR(-0.57704594283791188, result.angle, 1e-10);
EXPECT_SOFT_EQ(5.5782056196201597e-09, result.time);
EXPECT_SOFT_EQ(7.4731670215320127, result.step);
EXPECT_SOFT_NEAR(0.0036768333578785931, result.displacement, 1e-10);
EXPECT_SOFT_NEAR(0.65590801657964626, result.angle, 1e-10);
EXPECT_SOFT_EQ(6.9431339225049422e-10, result.time);
EXPECT_SOFT_EQ(0.930177246841563, result.step);
EXPECT_SOFT_EQ(0, result.mfp);
EXPECT_SOFT_EQ(1, result.alive);
EXPECT_EQ("physics-discrete-select", result.action);
Expand Down Expand Up @@ -509,7 +509,7 @@ TEST_F(SimpleCmsAlongStepTest, msc_field)
-0.0391118941072485030};
// Step limited by distance to interaction = 2.49798914193346685e21
auto result = this->run(inp, num_tracks);
EXPECT_SOFT_EQ(27.208989423735016, result.step);
EXPECT_SOFT_EQ(2.7199323076809536, result.step);
EXPECT_EQ(0, result.eloss);
EXPECT_EQ(0, result.mfp);
EXPECT_EQ("geo-propagation-limit", result.action);
Expand Down Expand Up @@ -571,8 +571,9 @@ TEST_F(SimpleCmsRZFieldAlongStepTest, msc_rzfield)
-0.0391118941072485030};

auto result = this->run(inp, num_tracks);
EXPECT_SOFT_EQ(4.1632772063250023, result.displacement);
EXPECT_SOFT_NEAR(-0.59445532857679839, result.angle, 1e-11);
EXPECT_SOFT_EQ(0.5515596670659112, result.displacement);
EXPECT_SOFT_NEAR(0.095167236229178429, result.angle, 1e-11);
EXPECT_EQ("geo-propagation-limit", result.action);
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/celeritas/track/Sim.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ TEST_F(SimTest, looping)
{
LoopingThreshold expected;
expected.threshold_energy = MevEnergy{250};
expected.max_steps = 100;
expected.max_subthreshold_steps = 10;
expected.max_steps = 1000;
expected.max_subthreshold_steps = 100;

// Check looping threshold parameters for each particle
SimTrackView sim(this->sim()->host_ref(), sim_state_.ref(), TrackSlotId{0});
Expand Down
41 changes: 20 additions & 21 deletions test/celeritas/user/Diagnostic.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,30 +151,29 @@ TEST_F(TestEm3DiagnosticTest, host)
"stuck on some builds but not others";
}

// Check action diagnostic results
static char const* const expected_nonzero_action_keys[]
= {"annihil-2-gamma e+",
"brems-combined e+",
"brems-combined e-",
"conv-bethe-heitler gamma",
"eloss-range e+",
"eloss-range e-",
"geo-boundary e+",
"geo-boundary e-",
"geo-boundary gamma",
"ioni-moller-bhabha e+",
"ioni-moller-bhabha e-",
"msc-range e+",
"msc-range e-",
"photoel-livermore gamma",
"physics-integral-rejected e+",
"physics-integral-rejected e-",
"scat-klein-nishina gamma"};
EXPECT_VEC_EQ(expected_nonzero_action_keys, result.nonzero_action_keys);

if (this->is_ci_build()
&& std::string(celeritas_geant4_version) == "11.0.4")
{
static char const* const expected_nonzero_action_keys[]
= {"annihil-2-gamma e+",
"brems-combined e+",
"brems-combined e-",
"conv-bethe-heitler gamma",
"eloss-range e+",
"eloss-range e-",
"geo-boundary e+",
"geo-boundary e-",
"geo-boundary gamma",
"ioni-moller-bhabha e+",
"ioni-moller-bhabha e-",
"msc-range e+",
"msc-range e-",
"photoel-livermore gamma",
"physics-integral-rejected e+",
"physics-integral-rejected e-",
"scat-klein-nishina gamma"};
EXPECT_VEC_EQ(expected_nonzero_action_keys, result.nonzero_action_keys);

static size_type const expected_nonzero_action_counts[] = {
119u,
398u,
Expand Down

0 comments on commit 36b4057

Please sign in to comment.