From d8b245cf811b74884928d7b02b57f29181fbe200 Mon Sep 17 00:00:00 2001 From: "Seth R. Johnson" Date: Wed, 8 May 2024 16:13:51 -0400 Subject: [PATCH] Fix trapezoid construction for negative phi and older Geant4 (#1227) * Fix GPU driver test * Add trap with negative y skew * Fix to_polar * Remove unnecessary validate --- app/celer-sim/simple-driver.py | 5 +++-- src/orange/g4org/SolidConverter.cc | 5 ++--- src/orange/orangeinp/ConvexRegion.cc | 4 ---- test/orange/g4org/SolidConverter.test.cc | 19 +++++++++++++++++++ 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/app/celer-sim/simple-driver.py b/app/celer-sim/simple-driver.py index f2b91658eb..9620848fce 100755 --- a/app/celer-sim/simple-driver.py +++ b/app/celer-sim/simple-driver.py @@ -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)) diff --git a/src/orange/g4org/SolidConverter.cc b/src/orange/g4org/SolidConverter.cc index f8202de71c..6b4b1f8964 100644 --- a/src/orange/g4org/SolidConverter.cc +++ b/src/orange/g4org/SolidConverter.cc @@ -114,9 +114,8 @@ SolidEnclosedAngle get_polar_wedge(S const& solid) CELER_EXPECT( is_soft_unit_vector(Array{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(theta), native_value_to(phi)}; } diff --git a/src/orange/orangeinp/ConvexRegion.cc b/src/orange/orangeinp/ConvexRegion.cc index b60a542d8e..0b67bc21ce 100644 --- a/src/orange/orangeinp/ConvexRegion.cc +++ b/src/orange/orangeinp/ConvexRegion.cc @@ -35,7 +35,6 @@ namespace orangeinp { namespace { -using Real2 = Array; //---------------------------------------------------------------------------// /*! * Create a z-aligned bounding box infinite along z and symmetric in r. @@ -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 { diff --git a/test/orange/g4org/SolidConverter.test.cc b/test/orange/g4org/SolidConverter.test.cc index 36dba343d4..b689488ac8 100644 --- a/test/orange/g4org/SolidConverter.test.cc +++ b/test/orange/g4org/SolidConverter.test.cc @@ -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)