Skip to content

Commit

Permalink
Fix trapezoid construction for negative phi and older Geant4 (#1227)
Browse files Browse the repository at this point in the history
* Fix GPU driver test
* Add trap with negative y skew
* Fix to_polar
* Remove unnecessary validate
  • Loading branch information
sethrj committed May 8, 2024
1 parent 87a3a37 commit d8b245c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
5 changes: 3 additions & 2 deletions app/celer-sim/simple-driver.py
Expand Up @@ -146,8 +146,9 @@ def strtobool(text):
time = run_output['time'].copy()
steps = time.pop('steps')
if use_device:
assert(len(steps) == run_output['num_step_iterations'][0])
assert steps
assert len(steps[0]) == run_output['num_step_iterations'][0]
else:
# Step times disabled on CPU from input
assert(steps is None)
assert steps is None
print(json.dumps(time, indent=1))
5 changes: 2 additions & 3 deletions src/orange/g4org/SolidConverter.cc
Expand Up @@ -114,9 +114,8 @@ SolidEnclosedAngle get_polar_wedge(S const& solid)
CELER_EXPECT(
is_soft_unit_vector(Array<double, 3>{axis.x(), axis.y(), axis.z()}));

double const theta = 1 / std::cos(axis.z());
double const phi = std::atan2(axis.x() / axis.z(), axis.y() / axis.z());

double const theta = std::acos(axis.z());
double const phi = std::atan2(axis.y(), axis.x());
return {native_value_to<Turn>(theta), native_value_to<Turn>(phi)};
}

Expand Down
4 changes: 0 additions & 4 deletions src/orange/orangeinp/ConvexRegion.cc
Expand Up @@ -35,7 +35,6 @@ namespace orangeinp
{
namespace
{
using Real2 = Array<real_type, 2>;
//---------------------------------------------------------------------------//
/*!
* Create a z-aligned bounding box infinite along z and symmetric in r.
Expand Down Expand Up @@ -356,9 +355,6 @@ GenTrap GenTrap::from_trap(
CELER_VALIDATE(theta >= zero_quantity() && theta < Turn{0.25},
<< "invalid angle " << theta.value()
<< " [turns]: must be in the range [0, 0.25)");
CELER_VALIDATE(phi >= zero_quantity() && phi < Turn{1.},
<< "invalid angle " << phi.value()
<< " [turns]: must be in the range [0, 1)");

// Calculate offset of faces from z axis
auto [dxdz_hz, dydz_hz] = [&]() -> std::pair<real_type, real_type> {
Expand Down
19 changes: 19 additions & 0 deletions test/orange/g4org/SolidConverter.test.cc
Expand Up @@ -453,6 +453,25 @@ TEST_F(SolidConverterTest, trap)
{1.20, 1.94, -4.01},
{-0.81, 1.9, -4.01},
{-1.96, -2.94, 4.01}});
tan_alpha = std::tan(30 * degree);
this->build_and_test(
G4Trap("trap",
10,
10 * degree,
-15 * degree,
20,
10,
10,
tan_alpha,
30,
15,
15,
tan_alpha),
R"json({"_type":"shape","interior":{"_type":"gentrap","halfheight":1.0,"lower":[[-2.325019322917132,-1.9543632192272244],[-0.32501932291713187,-1.9543632192272244],[1.9843817538413706,2.0456367807727753],[-0.01561824615862939,2.0456367807727753]],"upper":[[-3.061732023030996,-3.0456367807727753],[-0.06173202303099612,-3.0456367807727753],[3.4023695921067576,2.9543632192272247],[0.4023695921067574,2.9543632192272247]]},"label":"trap"})json",
{{-2.33, -1.96, -1.01},
{-2.32, -1.95, -0.99},
{3.41, 2.96, 1.01},
{3.40, 2.95, 0.99}});
}

TEST_F(SolidConverterTest, trd_box)
Expand Down

0 comments on commit d8b245c

Please sign in to comment.