Skip to content

Commit

Permalink
Fix position check after propagating (celeritas-project#1094)
Browse files Browse the repository at this point in the history
  • Loading branch information
amandalund committed Feb 1, 2024
1 parent 8f5849a commit c472eea
Show file tree
Hide file tree
Showing 7 changed files with 321 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ PropagationApplierBaseImpl<MP>::operator()(CoreTrackView const& track)
tracks_can_loop = propagate.tracks_can_loop();
CELER_ASSERT(p.distance > 0);
#if CELER_CHECK_POSITION
if (CELER_UNLIKELY(track.make_geo_view().pos() != orig_pos))
if (CELER_UNLIKELY(track.make_geo_view().pos() == orig_pos))
{
// This unusual case happens when the step length is less than
// machine epsilon compared to the actual position. This case seems
Expand Down
8 changes: 5 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ celeritas_add_test(celeritas/global/ActionRegistry.test.cc)
if(CELERITAS_USE_Geant4 AND CELERITAS_REAL_TYPE STREQUAL "double")
set(_along_step_filter
FILTER
"-Em3*:SimpleCms*"
"-Em3*:SimpleCms*:LeadBox*"
"Em3AlongStepTest.nofluct_nomsc"
"Em3AlongStepTest.msc_nofluct"
"Em3AlongStepTest.msc_nofluct_finegrid"
Expand All @@ -484,6 +484,7 @@ if(CELERITAS_USE_Geant4 AND CELERITAS_REAL_TYPE STREQUAL "double")
"SimpleCmsAlongStepTest.msc_field_finegrid"
"SimpleCmsRZFieldAlongStepTest.msc_rzfield"
"SimpleCmsRZFieldAlongStepTest.msc_rzfield_finegrid"
"LeadBox*"
)
set(_stepper_filter
FILTER
Expand All @@ -496,11 +497,12 @@ if(CELERITAS_USE_Geant4 AND CELERITAS_REAL_TYPE STREQUAL "double")
"OneSteelSphere.*"
)
elseif(CELERITAS_USE_Geant4)
set(_along_step_filter
set(_along_step_filter
FILTER
"-Em3*:SimpleCms*"
"-Em3*:SimpleCms*:LeadBox*"
"Em3AlongStepTest.nofluct_nomsc"
"Em3AlongStepTest.fluct_nomsc"
"LeadBox*"
)
set(_stepper_filter
FILTER
Expand Down
28 changes: 28 additions & 0 deletions test/celeritas/LeadBoxTestBase.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//----------------------------------*-C++-*----------------------------------//
// Copyright 2024 UT-Battelle, LLC, and other Celeritas developers.
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file celeritas/LeadBoxTestBase.hh
//---------------------------------------------------------------------------//
#pragma once

#include "GeantTestBase.hh"

namespace celeritas
{
namespace test
{
//---------------------------------------------------------------------------//
/*!
* Test harness for large lead box.
*/
class LeadBoxTestBase : virtual public GeantTestBase
{
protected:
std::string_view geometry_basename() const override { return "lead-box"; }
};

//---------------------------------------------------------------------------//
} // namespace test
} // namespace celeritas
72 changes: 72 additions & 0 deletions test/celeritas/data/lead-box.gdml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<gdml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://service-spi.web.cern.ch/service-spi/app/releases/GDML/schema/gdml.xsd">

<define/>

<materials>
<isotope N="204" Z="82" name="Pb204">
<atom unit="g/mole" value="203.973"/>
</isotope>
<isotope N="206" Z="82" name="Pb206">
<atom unit="g/mole" value="205.974"/>
</isotope>
<isotope N="207" Z="82" name="Pb207">
<atom unit="g/mole" value="206.976"/>
</isotope>
<isotope N="208" Z="82" name="Pb208">
<atom unit="g/mole" value="207.977"/>
</isotope>
<element name="Pb">
<fraction n="0.014" ref="Pb204"/>
<fraction n="0.241" ref="Pb206"/>
<fraction n="0.221" ref="Pb207"/>
<fraction n="0.524" ref="Pb208"/>
</element>
<material name="Pb" state="solid">
<T unit="K" value="293.15"/>
<MEE unit="eV" value="823"/>
<D unit="g/cm3" value="11.35"/>
<fraction n="1" ref="Pb"/>
</material>
<isotope N="1" Z="1" name="H1">
<atom unit="g/mole" value="1.00782503081372"/>
</isotope>
<isotope N="2" Z="1" name="H2">
<atom unit="g/mole" value="2.01410199966617"/>
</isotope>
<element name="H">
<fraction n="0.999885" ref="H1"/>
<fraction n="0.000115" ref="H2"/>
</element>
<material name="vacuum" state="gas">
<T unit="K" value="2.73"/>
<P unit="pascal" value="3e-18"/>
<MEE unit="eV" value="21.8"/>
<D unit="g/cm3" value="1e-25"/>
<fraction n="1" ref="H"/>
</material>
</materials>

<solids>
<box lunit="mm" name="box" x="1e11" y="1e11" z="1e11"/>
<box lunit="mm" name="world" x="1e11" y="1e11" z="1e11"/>
</solids>

<structure>
<volume name="box">
<materialref ref="Pb"/>
<solidref ref="box"/>
</volume>
<volume name="world">
<materialref ref="vacuum"/>
<solidref ref="world"/>
<physvol name="box">
<volumeref ref="box"/>
</physvol>
</volume>
</structure>
<setup name="Default" version="1.0">
<world ref="world"/>
</setup>

</gdml>
148 changes: 148 additions & 0 deletions test/celeritas/data/lead-box.org.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
{
"_format": "SCALE ORANGE",
"_version": 0,
"materials": {
"cell_to_mat": [
-1,
0,
1
],
"names": [
"Pb",
"vacuum"
]
},
"universes": [
{
"_type": "simple unit",
"bbox": [
[
-5000000000.0,
-5000000000.0,
-5000000000.0
],
[
5000000000.0,
5000000000.0,
5000000000.0
]
],
"cell_names": [
"[EXTERIOR]",
"box",
"world"
],
"cells": [
{
"faces": [
0,
1,
2,
3,
4,
5
],
"flags": 1,
"logic": "0 1 ~ & 2 & 3 ~ & 4 & 5 ~ & ~",
"num_intersections": 6,
"zorder": 2
},
{
"faces": [
6,
7,
8,
9,
10,
11
],
"logic": "0 1 ~ & 2 & 3 ~ & 4 & 5 ~ &",
"num_intersections": 6,
"zorder": 2
},
{
"faces": [
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11
],
"flags": 1,
"logic": "0 1 ~ & 2 & 3 ~ & 4 & 5 ~ & 6 7 ~ & 8 & 9 ~ & 10 & 11 ~ & ~ &",
"num_intersections": 12,
"zorder": 2
}
],
"md": {
"name": "global",
"provenance": ""
},
"surface_names": [
"world.mx",
"world.px",
"world.my",
"world.py",
"world.mz",
"world.pz",
"box.mx",
"box.px",
"box.my",
"box.py",
"box.mz",
"box.pz"
],
"surfaces": {
"data": [
-5000000000.0,
5000000000.0,
-5000000000.0,
5000000000.0,
-5000000000.0,
5000000000.0,
-5000000000.0,
5000000000.0,
-5000000000.0,
5000000000.0,
-5000000000.0,
5000000000.0
],
"sizes": [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
],
"types": [
"px",
"px",
"py",
"py",
"pz",
"pz",
"px",
"px",
"py",
"py",
"pz",
"pz"
]
}
}
]
}
30 changes: 30 additions & 0 deletions test/celeritas/data/lead-box.org.omn
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
! Copyright 2024 UT-Battelle, LLC and other Celeritas Developers.
! See the top-level COPYRIGHT file for details.
! SPDX-License-Identifier: (Apache-2.0 OR MIT)

[GEOMETRY]
global "global"
comp : matid
"Pb" 0
"vacuum" 1

!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!

[UNIVERSE=general global]
interior "world"

[UNIVERSE][SHAPE=box box]
widths 10000000000 10000000000 10000000000 ! note: units are in cm

[UNIVERSE][SHAPE=box world]
widths 10000000000 10000000000 10000000000

!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!

[UNIVERSE][CELL box]
comp "Pb"
shapes box

[UNIVERSE][CELL world]
comp "vacuum"
shapes world ~box
37 changes: 37 additions & 0 deletions test/celeritas/global/AlongStep.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
//---------------------------------------------------------------------------//
#include <fstream>

#include "corecel/ScopedLogStorer.hh"
#include "corecel/io/Logger.hh"
#include "celeritas/LeadBoxTestBase.hh"
#include "celeritas/SimpleCmsTestBase.hh"
#include "celeritas/TestEm3Base.hh"
#include "celeritas/UnitUtils.hh"
Expand Down Expand Up @@ -154,6 +157,11 @@ class SimpleCmsRZFieldAlongStepTest : public SimpleCmsAlongStepTest
bool fluct_{true};
};

#define LeadBoxAlongStepTest TEST_IF_CELERITAS_GEANT(LeadBoxAlongStepTest)
class LeadBoxAlongStepTest : public LeadBoxTestBase, public AlongStepTestBase
{
};

//---------------------------------------------------------------------------//
// TESTS
//---------------------------------------------------------------------------//
Expand Down Expand Up @@ -597,6 +605,35 @@ TEST_F(SimpleCmsRZFieldAlongStepTest, msc_rzfield_finegrid)
EXPECT_SOFT_EQ(0.99999999288499986, result.angle);
}
}

TEST_F(LeadBoxAlongStepTest, no_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());
}
EXPECT_SOFT_NEAR(5.38228333877273e-8, result.step, 1e-13);
EXPECT_EQ(0, result.displacement);
EXPECT_EQ("eloss-range", result.action);
}
//---------------------------------------------------------------------------//
} // namespace test
} // namespace celeritas

0 comments on commit c472eea

Please sign in to comment.