Skip to content

Commit

Permalink
Expand position check test and fix for other unit systems (celeritas-…
Browse files Browse the repository at this point in the history
…project#1097)

* Expand position check test and fix for other unit systems
* Try reducing energy
* Just check for displacement > 0
* Make it always move
  • Loading branch information
amandalund committed Feb 2, 2024
1 parent c472eea commit 53648ca
Showing 1 changed file with 40 additions and 19 deletions.
59 changes: 40 additions & 19 deletions test/celeritas/global/AlongStep.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -606,33 +606,54 @@ TEST_F(SimpleCmsRZFieldAlongStepTest, msc_rzfield_finegrid)
}
}

TEST_F(LeadBoxAlongStepTest, no_position_change)
TEST_F(LeadBoxAlongStepTest, position_change)
{
size_type num_tracks = 1;
Input inp;
SCOPED_TRACE("Electron with no change in position after propagation");
inp.particle_id = this->particle()->find(pdg::electron());
inp.energy = MevEnergy{1e-6};
inp.position = {1e9, 0, 0};
inp.direction = {-1, 0, 0};
inp.phys_mfp = 1;

ScopedLogStorer scoped_log{&celeritas::world_logger()};
auto result = this->run(inp, num_tracks);
if (CELERITAS_DEBUG)
{
static char const expected_log_message[]
= "Propagation of step length 5.3822833387727e-08 due to "
"post-step action 2 leading to distance 5.3822833387727e-08 "
"failed to change position at {1000000000, 0, 0} with ending "
"direction {-1, 0, 0}";
EXPECT_EQ(expected_log_message, scoped_log.messages().back());
static char const expected_log_level[] = "error";
EXPECT_EQ(expected_log_level, scoped_log.levels().back());
SCOPED_TRACE("Electron with no change in position after propagation");
inp.energy = MevEnergy{1e-6};
inp.position = {1e9, 0, 0};
ScopedLogStorer scoped_log{&celeritas::world_logger(), LogLevel::error};
auto result = this->run(inp, num_tracks);
static double const expected_step_length = 5.38228333877273e-8;
if (CELERITAS_DEBUG)
{
static double const expected_distance = 5.3822833387727e-8;
std::stringstream ss;
ss << "Propagation of step length "
<< repr(from_cm(expected_step_length))
<< " due to post-step action 2 leading to distance "
<< repr(from_cm(expected_distance))
<< " failed to change position at "
<< repr(from_cm(inp.position)) << " with ending direction "
<< repr(inp.direction);
EXPECT_EQ(ss.str(), scoped_log.messages().front());
static char const* const expected_log_levels[] = {"error"};
EXPECT_VEC_EQ(expected_log_levels, scoped_log.levels());
}
else
{
EXPECT_TRUE(scoped_log.empty()) << scoped_log;
}
EXPECT_SOFT_NEAR(expected_step_length, result.step, 1e-13);
EXPECT_EQ(0, result.displacement);
EXPECT_EQ("eloss-range", result.action);
}
{
SCOPED_TRACE("Electron changes position");
inp.energy = MevEnergy{1};
inp.position = {1, 0, 0};
ScopedLogStorer scoped_log{&celeritas::world_logger(), LogLevel::error};
auto result = this->run(inp, num_tracks);
EXPECT_TRUE(scoped_log.empty()) << scoped_log;
EXPECT_SOFT_EQ(0.072970479114469966, result.step);
EXPECT_SOFT_EQ(0.0056608379081902749, result.displacement);
EXPECT_EQ("eloss-range", result.action);
}
EXPECT_SOFT_NEAR(5.38228333877273e-8, result.step, 1e-13);
EXPECT_EQ(0, result.displacement);
EXPECT_EQ("eloss-range", result.action);
}
//---------------------------------------------------------------------------//
} // namespace test
Expand Down

0 comments on commit 53648ca

Please sign in to comment.