From 03c803c656d396f0da7a5ae0909055d1cef5895b Mon Sep 17 00:00:00 2001 From: ralfulrich <ralf.ulrich@kit.edu> Date: Sat, 1 Dec 2018 03:39:50 +0100 Subject: [PATCH] reworked Trajectory interface --- Framework/Cascade/Cascade.h | 15 +++++----- Framework/Cascade/testCascade.cc | 1 - Framework/Geometry/BaseTrajectory.h | 26 +++++++++++++++-- Framework/Geometry/CMakeLists.txt | 4 +-- Framework/Geometry/Helix.h | 8 +++--- .../Geometry/{LineTrajectory.h => Line.h} | 12 ++++---- Framework/Geometry/Trajectory.h | 28 +++++++++++-------- Framework/Geometry/testGeometry.cc | 20 ++++++------- Setup/SetupTrajectory.h | 5 ++-- 9 files changed, 72 insertions(+), 47 deletions(-) rename Framework/Geometry/{LineTrajectory.h => Line.h} (79%) diff --git a/Framework/Cascade/Cascade.h b/Framework/Cascade/Cascade.h index f5d88b33f..0e920cc4b 100644 --- a/Framework/Cascade/Cascade.h +++ b/Framework/Cascade/Cascade.h @@ -12,11 +12,11 @@ #ifndef _include_Cascade_h_ #define _include_Cascade_h_ -#include <corsika/geometry/LineTrajectory.h> // to be removed. for dummy trajectory only -#include <corsika/geometry/Point.h> // to be removed. for dummy trajectory only #include <corsika/process/ProcessReturn.h> #include <corsika/units/PhysicalUnits.h> +#include <corsika/setup/SetupTrajectory.h> + using namespace corsika::units::si; namespace corsika::cascade { @@ -62,16 +62,17 @@ namespace corsika::cascade { // DoCascadeEquations(); // } } - + void Step(Particle& particle) { [[maybe_unused]] double nextStep = fProcesseList.MinStepLength(particle); // corsika::utls::ignore(nextStep); auto const root = corsika::geometry::CoordinateSystem::CreateRootCS(); - corsika::geometry::LineTrajectory + corsika::geometry::Trajectory<corsika::geometry::Line> trajectory( // trajectory is not yet used. this is a dummy. - corsika::geometry::Point(root, {0_m, 0_m, 0_m}), - corsika::geometry::Vector<corsika::units::si::SpeedType::dimension_type>( - root, 0 * 1_m / second, 0 * 1_m / second, 1 * 1_m / second)); + corsika::geometry::Line(corsika::geometry::Point(root, {0_m, 0_m, 0_m}), + corsika::geometry::Vector<corsika::units::si::SpeedType::dimension_type>( + root, 0 * 1_m / second, 0 * 1_m / second, 1 * 1_m / second)), + 0_s, 1_s); corsika::process::EProcessReturn status = fProcesseList.DoContinuous(particle, trajectory, fStack); if (status == corsika::process::EProcessReturn::eParticleAbsorbed) { diff --git a/Framework/Cascade/testCascade.cc b/Framework/Cascade/testCascade.cc index f14a7a315..edb825bc7 100644 --- a/Framework/Cascade/testCascade.cc +++ b/Framework/Cascade/testCascade.cc @@ -10,7 +10,6 @@ */ #include <corsika/cascade/Cascade.h> -#include <corsika/geometry/LineTrajectory.h> #include <corsika/process/ProcessSequence.h> #include <corsika/process/stack_inspector/StackInspector.h> diff --git a/Framework/Geometry/BaseTrajectory.h b/Framework/Geometry/BaseTrajectory.h index b39335c8c..8289e0dca 100644 --- a/Framework/Geometry/BaseTrajectory.h +++ b/Framework/Geometry/BaseTrajectory.h @@ -24,17 +24,37 @@ namespace corsika::geometry { */ class BaseTrajectory { + BaseTrajectory() = delete; + public: + BaseTrajectory(corsika::units::si::TimeType start, corsika::units::si::TimeType end) + : fTStart(start) + , fTEnd(end) {} + //!< for \f$ t = 0 \f$, the starting Point shall be returned. virtual Point GetPosition(corsika::units::si::TimeType) const = 0; + //!< the Point is return from u=0 (start) to u=1 (end) + virtual Point GetPosition(double u) const = 0; + /*! - * returns the arc length between two points of the trajectory + * returns the length between two points of the trajectory * parameterized by \arg t1 and \arg t2. Requires \arg t2 > \arg t1. */ - virtual LengthType DistanceBetween(corsika::units::si::TimeType t1, - corsika::units::si::TimeType t2) const = 0; + virtual LengthType GetDistance(corsika::units::si::TimeType t1, + corsika::units::si::TimeType t2) const = 0; + + virtual corsika::units::si::TimeType GetDuration( + corsika::units::si::TimeType t1, corsika::units::si::TimeType t2) const { + return t2 - t1; + } + + virtual Point GetEndpoint() const { return GetPosition(fTEnd); } + virtual Point GetStartpoint() const { return GetPosition(fTStart); } + + protected: + corsika::units::si::TimeType const fTStart, fTEnd; }; } // namespace corsika::geometry diff --git a/Framework/Geometry/CMakeLists.txt b/Framework/Geometry/CMakeLists.txt index 60992f427..580066ae0 100644 --- a/Framework/Geometry/CMakeLists.txt +++ b/Framework/Geometry/CMakeLists.txt @@ -8,14 +8,14 @@ set ( GEOMETRY_HEADERS Vector.h Point.h + Line.h Sphere.h CoordinateSystem.h Helix.h BaseVector.h QuantityVector.h - BaseTrajectory.h - LineTrajectory.h Trajectory.h + BaseTrajectory.h ) set ( diff --git a/Framework/Geometry/Helix.h b/Framework/Geometry/Helix.h index 018299bcf..b647688d4 100644 --- a/Framework/Geometry/Helix.h +++ b/Framework/Geometry/Helix.h @@ -12,7 +12,6 @@ #ifndef _include_HELIX_H_ #define _include_HELIX_H_ -#include <corsika/geometry/BaseTrajectory.h> #include <corsika/geometry/Point.h> #include <corsika/geometry/Vector.h> #include <corsika/units/PhysicalUnits.h> @@ -31,7 +30,8 @@ namespace corsika::geometry { \f} */ - class Helix : public BaseTrajectory { + class Helix { + using VelocityVec = Vector<corsika::units::si::SpeedType::dimension_type>; Point const r0; @@ -51,7 +51,7 @@ namespace corsika::geometry { , uPerp(vPerp.cross(vPar.normalized())) , radius(pvPar.norm() / abs(pOmegaC)) {} - Point GetPosition(corsika::units::si::TimeType t) const override { + Point GetPosition(corsika::units::si::TimeType t) const { return r0 + vPar * t + (vPerp * (cos(omegaC * t) - 1) + uPerp * sin(omegaC * t)) / omegaC; } @@ -59,7 +59,7 @@ namespace corsika::geometry { auto GetRadius() const { return radius; } LengthType DistanceBetween(corsika::units::si::TimeType t1, - corsika::units::si::TimeType t2) const override { + corsika::units::si::TimeType t2) const { return (vPar + vPerp).norm() * (t2 - t1); } }; diff --git a/Framework/Geometry/LineTrajectory.h b/Framework/Geometry/Line.h similarity index 79% rename from Framework/Geometry/LineTrajectory.h rename to Framework/Geometry/Line.h index f13f8d822..829c16044 100644 --- a/Framework/Geometry/LineTrajectory.h +++ b/Framework/Geometry/Line.h @@ -12,30 +12,30 @@ #ifndef _include_LINETRAJECTORY_H #define _include_LINETRAJECTORY_H -#include <corsika/geometry/BaseTrajectory.h> #include <corsika/geometry/Point.h> #include <corsika/geometry/Vector.h> #include <corsika/units/PhysicalUnits.h> namespace corsika::geometry { - class LineTrajectory : public BaseTrajectory { + class Line { + using VelocityVec = Vector<corsika::units::si::SpeedType::dimension_type>; Point const r0; VelocityVec const v0; public: - LineTrajectory(Point const& pR0, VelocityVec const& pV0) + Line(Point const& pR0, VelocityVec const& pV0) : r0(pR0) , v0(pV0) {} - Point GetPosition(corsika::units::si::TimeType t) const override { + Point GetPosition(corsika::units::si::TimeType t) const { return r0 + v0 * t; } - + LengthType DistanceBetween(corsika::units::si::TimeType t1, - corsika::units::si::TimeType t2) const override { + corsika::units::si::TimeType t2) const { assert(t2 >= t1); return v0.norm() * (t2 - t1); } diff --git a/Framework/Geometry/Trajectory.h b/Framework/Geometry/Trajectory.h index 237f37931..97adfdd3b 100644 --- a/Framework/Geometry/Trajectory.h +++ b/Framework/Geometry/Trajectory.h @@ -17,28 +17,32 @@ namespace corsika::geometry { - class Trajectory { - corsika::units::si::TimeType const fTStart, fTEnd; - BaseTrajectory const& fTrajectory; + template <typename T> + class Trajectory : public BaseTrajectory { + + T fTraj; public: - Trajectory(corsika::units::si::TimeType pTStart, corsika::units::si::TimeType pTEnd, - BaseTrajectory const& pTrajectory) - : fTStart(pTStart) - , fTEnd(pTEnd) - , fTrajectory(pTrajectory) {} + Trajectory(T const& theT, corsika::units::si::TimeType pTStart, + corsika::units::si::TimeType pTEnd) + //: T(theT), fTStart(pTStart), fTEnd(pTEnd) {} + : BaseTrajectory(pTStart, pTEnd) + , fTraj(theT) {} Point GetPosition(corsika::units::si::TimeType t) const { - return fTrajectory.GetPosition(t + fTStart); + return fTraj.GetPosition(t + fTStart); } Point GetPosition(double u) const { return GetPosition(fTEnd * u + fTStart * (1 - u)); } + + LengthType GetDistance(corsika::units::si::TimeType t1, + corsika::units::si::TimeType t2) const { + return fTraj.DistanceBetween(t1, t2); + } + - auto GetEndpoint() const { return GetPosition(fTEnd); } - - auto GetStartpoint() const { return GetPosition(fTStart); } }; } // namespace corsika::geometry diff --git a/Framework/Geometry/testGeometry.cc b/Framework/Geometry/testGeometry.cc index 98527c0c1..742938ffe 100644 --- a/Framework/Geometry/testGeometry.cc +++ b/Framework/Geometry/testGeometry.cc @@ -15,7 +15,7 @@ #include <corsika/geometry/CoordinateSystem.h> #include <corsika/geometry/Helix.h> -#include <corsika/geometry/LineTrajectory.h> +#include <corsika/geometry/Line.h> #include <corsika/geometry/Point.h> #include <corsika/geometry/Sphere.h> #include <corsika/geometry/Trajectory.h> @@ -144,17 +144,17 @@ TEST_CASE("Trajectories") { Vector<SpeedType::dimension_type> v0(rootCS, {1_m / second, 0_m / second, 0_m / second}); - LineTrajectory const lineTrajectory(r0, v0); - CHECK((lineTrajectory.GetPosition(2_s).GetCoordinates() - + Line const line(r0, v0); + CHECK((line.GetPosition(2_s).GetCoordinates() - QuantityVector<length_d>(2_m, 0_m, 0_m)) .norm() .magnitude() == Approx(0).margin(absMargin)); - BaseTrajectory const* base = &lineTrajectory; - CHECK(lineTrajectory.GetPosition(2_s).GetCoordinates() == - base->GetPosition(2_s).GetCoordinates()); + Trajectory<Line> base(line, 0_s, 1_s); + CHECK(line.GetPosition(2_s).GetCoordinates() == + base.GetPosition(2_s).GetCoordinates()); - CHECK(base->DistanceBetween(1_s, 2_s) / 1_m == Approx(1)); + CHECK(base.GetDistance(1_s, 2_s) / 1_m == Approx(1)); } SECTION("Helix") { @@ -178,10 +178,10 @@ TEST_CASE("Trajectories") { .norm() .magnitude() == Approx(0).margin(absMargin)); - BaseTrajectory const* base = &helix; + Trajectory<Helix> const base(helix, 0_s, 1_s); CHECK(helix.GetPosition(1234_s).GetCoordinates() == - base->GetPosition(1234_s).GetCoordinates()); + base.GetPosition(1234_s).GetCoordinates()); - CHECK(base->DistanceBetween(1_s, 2_s) / 1_m == Approx(5)); + CHECK(base.GetDistance(1_s, 2_s) / 1_m == Approx(5)); } } diff --git a/Setup/SetupTrajectory.h b/Setup/SetupTrajectory.h index ab95732be..d7f5c482d 100644 --- a/Setup/SetupTrajectory.h +++ b/Setup/SetupTrajectory.h @@ -12,11 +12,12 @@ #ifndef _corsika_setup_setuptrajectory_h_ #define _corsika_setup_setuptrajectory_h_ -#include <corsika/geometry/LineTrajectory.h> +#include <corsika/geometry/Line.h> +#include <corsika/geometry/Trajectory.h> namespace corsika::setup { - typedef corsika::geometry::LineTrajectory Trajectory; + typedef corsika::geometry::Trajectory<corsika::geometry::Line> Trajectory; } #endif -- GitLab