IAP GITLAB

Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • AirShowerPhysics/corsika
  • rulrich/corsika
  • AAAlvesJr/corsika
  • Andre/corsika
  • arrabito/corsika
  • Nikos/corsika
  • olheiser73/corsika
  • AirShowerPhysics/papers/corsika
  • pranav/corsika
9 results
Show changes
Showing
with 654 additions and 157 deletions
/*
* (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
#pragma once
namespace corsika {
inline Box::Box(CoordinateSystemPtr cs, LengthType const x, LengthType const y,
LengthType const z)
: center_(Point(cs, {0_m, 0_m, 0_m}))
, cs_(cs)
, x_(x)
, y_(y)
, z_(z) {}
inline Box::Box(CoordinateSystemPtr cs, LengthType const side)
: center_(Point(cs, {0_m, 0_m, 0_m}))
, cs_(cs)
, x_(side / 2)
, y_(side / 2)
, z_(side / 2) {}
inline bool Box::contains(Point const& p) const {
if ((abs(p.getX(cs_)) < x_) && (abs(p.getY(cs_)) < y_) && (abs(p.getZ(cs_)) < z_))
return true;
else
return false;
}
inline std::string Box::asString() const {
std::ostringstream txt;
txt << "center=" << center_ << ", x-axis=" << DirectionVector{cs_, {1, 0, 0}}
<< ", y-axis: " << DirectionVector{cs_, {0, 1, 0}}
<< ", z-axis: " << DirectionVector{cs_, {0, 0, 1}};
return txt.str();
}
template <typename TDim>
inline void Box::rotate(QuantityVector<TDim> const& axis, double const angle) {
cs_ = make_rotation(cs_, axis, angle);
}
} // namespace corsika
\ No newline at end of file
/*
* (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
#pragma once
......@@ -19,9 +18,11 @@
namespace corsika {
CoordinateSystemPtr CoordinateSystem::getReferenceCS() const { return referenceCS_; }
inline CoordinateSystemPtr CoordinateSystem::getReferenceCS() const {
return referenceCS_;
}
EigenTransform const& CoordinateSystem::getTransform() const { return transf_; }
inline EigenTransform const& CoordinateSystem::getTransform() const { return transf_; }
inline bool CoordinateSystem::operator==(CoordinateSystem const& cs) const {
return referenceCS_ == cs.referenceCS_ && transf_.matrix() == cs.transf_.matrix();
......@@ -73,13 +74,19 @@ namespace corsika {
inline CoordinateSystemPtr make_translation(CoordinateSystemPtr const& cs,
QuantityVector<length_d> const& vector) {
EigenTransform const translation{EigenTranslation(vector.getEigenVector())};
return std::make_shared<CoordinateSystem const>(CoordinateSystem(cs, translation));
return CoordinateSystemPtr{new CoordinateSystem(cs, translation)};
}
template <typename TDim>
inline CoordinateSystemPtr make_rotationToZ(CoordinateSystemPtr const& cs,
Vector<TDim> const& vVec) {
auto const a = vVec.normalized().getComponents(cs).getEigenVector();
auto const vVecComp = vVec.getComponents(cs);
if (vVecComp.getX().magnitude() == 0 && vVecComp.getY().magnitude() == 0 &&
vVecComp.getZ().magnitude() == 0) {
return cs;
}
auto const a = vVecComp.normalized().getEigenVector();
auto const a1 = a(0), a2 = a(1), a3 = a(2);
Eigen::Matrix3d A, B;
......@@ -103,8 +110,7 @@ namespace corsika {
0, 0, (a1 * a1 + a2 * a2) * c; // .
}
return std::make_shared<CoordinateSystem const>(
CoordinateSystem(cs, EigenTransform(A + B)));
return CoordinateSystemPtr{new CoordinateSystem{cs, EigenTransform{A + B}}};
}
template <typename TDim>
......@@ -118,7 +124,7 @@ namespace corsika {
EigenTransform const rotation{
Eigen::AngleAxisd(angle, axis.getEigenVector().normalized())};
return std::make_shared<CoordinateSystem const>(CoordinateSystem(cs, rotation));
return CoordinateSystemPtr{new CoordinateSystem{cs, rotation}};
}
template <typename TDim>
......@@ -133,7 +139,7 @@ namespace corsika {
Eigen::AngleAxisd(angle, axis.getEigenVector().normalized()) *
EigenTranslation(translation.getEigenVector())};
return std::make_shared<CoordinateSystem const>(CoordinateSystem(cs, transf));
return CoordinateSystemPtr{new CoordinateSystem{cs, transf}};
}
} // namespace corsika
/*
* (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
#pragma once
......@@ -15,47 +14,47 @@
namespace corsika {
template <typename TTimeType, typename TSpaceVecType>
TTimeType FourVector<TTimeType, TSpaceVecType>::getTimeLikeComponent() const {
inline TTimeType FourVector<TTimeType, TSpaceVecType>::getTimeLikeComponent() const {
return timeLike_;
}
template <typename TTimeType, typename TSpaceVecType>
TSpaceVecType& FourVector<TTimeType, TSpaceVecType>::getSpaceLikeComponents() {
inline TSpaceVecType& FourVector<TTimeType, TSpaceVecType>::getSpaceLikeComponents() {
return spaceLike_;
}
template <typename TTimeType, typename TSpaceVecType>
TSpaceVecType const& FourVector<TTimeType, TSpaceVecType>::getSpaceLikeComponents()
const {
inline TSpaceVecType const&
FourVector<TTimeType, TSpaceVecType>::getSpaceLikeComponents() const {
return spaceLike_;
}
template <typename TTimeType, typename TSpaceVecType>
typename FourVector<TTimeType, TSpaceVecType>::norm_square_type
inline typename FourVector<TTimeType, TSpaceVecType>::norm_square_type
FourVector<TTimeType, TSpaceVecType>::getNormSqr() const {
return getTimeSquared() - spaceLike_.getSquaredNorm();
}
template <typename TTimeType, typename TSpaceVecType>
typename FourVector<TTimeType, TSpaceVecType>::norm_type
inline typename FourVector<TTimeType, TSpaceVecType>::norm_type
FourVector<TTimeType, TSpaceVecType>::getNorm() const {
return sqrt(abs(getNormSqr()));
}
template <typename TTimeType, typename TSpaceVecType>
bool FourVector<TTimeType, TSpaceVecType>::isTimelike() const {
inline bool FourVector<TTimeType, TSpaceVecType>::isTimelike() const {
return getTimeSquared() < spaceLike_.getSquaredNorm();
}
template <typename TTimeType, typename TSpaceVecType>
bool FourVector<TTimeType, TSpaceVecType>::isSpacelike() const {
inline bool FourVector<TTimeType, TSpaceVecType>::isSpacelike() const {
return getTimeSquared() > spaceLike_.getSquaredNorm();
}
template <typename TTimeType, typename TSpaceVecType>
FourVector<TTimeType, TSpaceVecType>& FourVector<TTimeType, TSpaceVecType>::operator+=(
FourVector const& b) {
inline FourVector<TTimeType, TSpaceVecType>& FourVector<TTimeType, TSpaceVecType>::
operator+=(FourVector const& b) {
timeLike_ += b.timeLike_;
spaceLike_ += b.spaceLike_;
......@@ -63,38 +62,38 @@ namespace corsika {
}
template <typename TTimeType, typename TSpaceVecType>
FourVector<TTimeType, TSpaceVecType>& FourVector<TTimeType, TSpaceVecType>::operator-=(
FourVector const& b) {
inline FourVector<TTimeType, TSpaceVecType>& FourVector<TTimeType, TSpaceVecType>::
operator-=(FourVector const& b) {
timeLike_ -= b.timeLike_;
spaceLike_ -= b.spaceLike_;
return *this;
}
template <typename TTimeType, typename TSpaceVecType>
FourVector<TTimeType, TSpaceVecType>& FourVector<TTimeType, TSpaceVecType>::operator*=(
double const b) {
inline FourVector<TTimeType, TSpaceVecType>& FourVector<TTimeType, TSpaceVecType>::
operator*=(double const b) {
timeLike_ *= b;
spaceLike_ *= b;
return *this;
}
template <typename TTimeType, typename TSpaceVecType>
FourVector<TTimeType, TSpaceVecType>& FourVector<TTimeType, TSpaceVecType>::operator/=(
double const b) {
inline FourVector<TTimeType, TSpaceVecType>& FourVector<TTimeType, TSpaceVecType>::
operator/=(double const b) {
timeLike_ /= b;
spaceLike_.getComponents() /= b;
return *this;
}
template <typename TTimeType, typename TSpaceVecType>
FourVector<TTimeType, TSpaceVecType>& FourVector<TTimeType, TSpaceVecType>::operator/(
double const b) {
inline FourVector<TTimeType, TSpaceVecType>& FourVector<TTimeType, TSpaceVecType>::
operator/(double const b) {
*this /= b;
return *this;
}
template <typename TTimeType, typename TSpaceVecType>
typename FourVector<TTimeType, TSpaceVecType>::norm_type
inline typename FourVector<TTimeType, TSpaceVecType>::norm_type
FourVector<TTimeType, TSpaceVecType>::operator*(FourVector const& b) {
if constexpr (std::is_same<time_type, decltype(std::declval<space_type>() / meter *
second)>::value)
......@@ -104,7 +103,7 @@ namespace corsika {
}
template <typename TTimeType, typename TSpaceVecType>
typename FourVector<TTimeType, TSpaceVecType>::norm_square_type
inline typename FourVector<TTimeType, TSpaceVecType>::norm_square_type
FourVector<TTimeType, TSpaceVecType>::getTimeSquared() const {
if constexpr (std::is_same<time_type, decltype(std::declval<space_type>() / meter *
second)>::value)
......
/*
* (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
#pragma once
......@@ -15,23 +14,23 @@
namespace corsika {
LengthType Helix::getRadius() const { return radius_; }
inline LengthType Helix::getRadius() const { return radius_; }
Point Helix::getPosition(TimeType const t) const {
inline Point Helix::getPosition(TimeType const t) const {
return r0_ + vPar_ * t +
(vPerp_ * (std::cos(omegaC_ * t) - 1) + uPerp_ * std::sin(omegaC_ * t)) /
omegaC_;
}
Point Helix::getPositionFromArclength(LengthType const l) const {
inline Point Helix::getPositionFromArclength(LengthType const l) const {
return getPosition(getTimeFromArclength(l));
}
LengthType Helix::getArcLength(TimeType const t1, TimeType const t2) const {
inline LengthType Helix::getArcLength(TimeType const t1, TimeType const t2) const {
return (vPar_ + vPerp_).getNorm() * (t2 - t1);
}
TimeType Helix::getTimeFromArclength(LengthType const l) const {
inline TimeType Helix::getTimeFromArclength(LengthType const l) const {
return l / (vPar_ + vPerp_).getNorm();
}
......
/*
* (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
#pragma once
......@@ -12,6 +11,7 @@
#include <corsika/framework/geometry/Line.hpp>
#include <corsika/framework/geometry/Point.hpp>
#include <corsika/framework/geometry/PhysicalGeometry.hpp>
#include <corsika/framework/utility/QuarticSolver.hpp>
namespace corsika {
......@@ -28,34 +28,65 @@ namespace corsika {
}
inline Point LeapFrogTrajectory::getPosition(double const u) const {
Point position = initialPosition_ + initialVelocity_ * timeStep_ * u / 2;
VelocityVector velocity =
if (u == 0) return initialPosition_;
Point const position = initialPosition_ + initialVelocity_ * timeStep_ * u / 2;
VelocityVector const velocity =
initialVelocity_ + initialVelocity_.cross(magneticfield_) * timeStep_ * u * k_;
return position + velocity * timeStep_ * u / 2;
}
inline VelocityVector LeapFrogTrajectory::getVelocity(double const u) const {
return initialVelocity_ + initialVelocity_.cross(magneticfield_) * timeStep_ * u * k_;
return getDirection(u) * initialVelocity_.getNorm();
}
inline DirectionVector LeapFrogTrajectory::getDirection(double const u) const {
return getVelocity(u).normalized();
if (u == 0) return initialDirection_;
return (initialDirection_ +
initialDirection_.cross(magneticfield_) * timeStep_ * u * k_)
.normalized();
}
inline TimeType LeapFrogTrajectory::getDuration(double const u) const {
return u * timeStep_ *
(double(getVelocity(u).getNorm() / initialVelocity_.getNorm()) + 1.0) / 2;
TimeType const step = timeStep_ * u;
double const correction = 1;
// the eventual (delta-L to L) correction factor is:
// (initialDirection_ + initialDirection_.cross(magneticfield_) * step *
// k_).getNorm();
return step / 2 * (correction + 1);
}
template <typename Particle>
inline TimeType LeapFrogTrajectory::getTime(Particle const& particle,
double const u) const {
return particle.getTime() + getDuration(u);
}
inline LengthType LeapFrogTrajectory::getLength(double const u) const {
return timeStep_ * initialVelocity_.getNorm() * u;
return getDuration(u) * initialVelocity_.getNorm();
}
inline void LeapFrogTrajectory::setLength(LengthType const limit) {
if (initialVelocity_.getNorm() == 0_m / 1_s) setDuration(0_s);
if (initialVelocity_.getNorm() == SpeedType::zero()) setDuration(0_s);
setDuration(limit / initialVelocity_.getNorm());
}
inline void LeapFrogTrajectory::setDuration(TimeType const limit) { timeStep_ = limit; }
inline void LeapFrogTrajectory::setDuration(TimeType const limit) {
/*
initial attempt to calculate delta-L from assumed full-leap-frog-length L:
Note: often return 0. Not good enough yet.
LengthType const L = initialVelocity_.getNorm() * limit; // distance
double const a = (initialVelocity_.cross(magneticfield_) * k_).getSquaredNorm() / 4 /
square(1_m) * static_pow<4>(1_s);
double const d = L * initialVelocity_.getNorm() / square(1_m) * 1_s;
double const e = -square(L) / square(1_m);
std::vector<double> solutions = solve_quartic_real(a, 0, 0, d, e);
CORSIKA_LOG_DEBUG("setDuration limit={} L={} solution={}", limit, L,
fmt::join(solutions, ", "));
*/
timeStep_ = limit;
}
} // namespace corsika
/*
* (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
#pragma once
......
/*
* (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
#pragma once
#include <deque>
namespace corsika {
inline Path::Path(Point const& point) { points_.push_front(point); }
inline Path::Path(std::deque<Point> const& points)
: points_(points) {
int dequesize_ = points.size();
if (dequesize_ == 0 || dequesize_ == 1) {
length_ = LengthType::zero();
} else if (dequesize_ == 2) {
length_ = (points.back() - points.front()).getNorm();
} else {
for (auto point = points.begin(); point != points.end() - 1; ++point) {
auto point_next = *(point + 1);
auto point_now = *(point);
length_ += (point_next - point_now).getNorm();
}
}
}
inline void Path::addToEnd(Point const& point) {
length_ += (point - points_.back()).getNorm();
points_.push_back(point);
}
inline void Path::removeFromEnd() {
auto lastpoint_ = points_.back();
points_.pop_back();
int dequesize_ = points_.size();
if (dequesize_ == 0 || dequesize_ == 1) {
length_ = LengthType::zero();
} else if (dequesize_ == 2) {
length_ = (points_.back() - points_.front()).getNorm();
} else {
length_ -= (lastpoint_ - points_.back()).getNorm();
}
}
inline LengthType Path::getLength() const { return length_; }
inline Point const& Path::getStart() const { return points_.front(); }
inline Point const& Path::getEnd() const { return points_.back(); }
inline Point const& Path::getPoint(std::size_t const index) const {
return points_.at(index);
}
inline Path::const_iterator Path::begin() const { return points_.cbegin(); }
inline Path::const_iterator Path::end() const { return points_.cend(); }
inline Path::iterator Path::begin() { return points_.begin(); }
inline Path::iterator Path::end() { return points_.end(); }
inline int Path::getNSegments() const { return points_.size() - 1; }
} // namespace corsika
\ No newline at end of file
/*
* (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
#pragma once
......@@ -12,6 +11,8 @@
#include <corsika/framework/geometry/Point.hpp>
#include <corsika/framework/geometry/Vector.hpp>
#include <sstream>
namespace corsika {
inline bool Plane::isAbove(Point const& vP) const {
......@@ -24,6 +25,12 @@ namespace corsika {
inline Point const& Plane::getCenter() const { return center_; }
inline Plane::DimLessVec const& Plane::getNormal() const { return normal_; }
inline DirectionVector const& Plane::getNormal() const { return normal_; }
inline std::string Plane::asString() const {
std::ostringstream txt;
txt << "center=" << center_ << ", normal=" << normal_;
return txt.str();
}
} // namespace corsika
/*
* (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
#pragma once
......@@ -15,54 +14,31 @@
namespace corsika {
QuantityVector<length_d> const& Point::getCoordinates() const {
inline QuantityVector<length_d> const& Point::getCoordinates() const {
return BaseVector<length_d>::getQuantityVector();
}
QuantityVector<length_d>& Point::getCoordinates() {
inline QuantityVector<length_d>& Point::getCoordinates() {
return BaseVector<length_d>::getQuantityVector();
}
inline LengthType Point::getX(CoordinateSystemPtr const& pCS) const {
CoordinateSystemPtr const& cs = BaseVector<length_d>::getCoordinateSystem();
if (*pCS == *cs) {
return BaseVector<length_d>::getQuantityVector().getX();
} else {
return QuantityVector<length_d>(
get_transformation(*cs.get(), *pCS.get()) *
BaseVector<length_d>::getQuantityVector().eigenVector_)
.getX();
}
return getCoordinates(pCS).getX();
}
inline LengthType Point::getY(CoordinateSystemPtr const& pCS) const {
CoordinateSystemPtr const& cs = BaseVector<length_d>::getCoordinateSystem();
if (*pCS == *cs) {
return BaseVector<length_d>::getQuantityVector().getY();
} else {
return QuantityVector<length_d>(
get_transformation(*cs.get(), *pCS.get()) *
BaseVector<length_d>::getQuantityVector().eigenVector_)
.getY();
}
return getCoordinates(pCS).getY();
}
inline LengthType Point::getZ(CoordinateSystemPtr const& pCS) const {
CoordinateSystemPtr const& cs = BaseVector<length_d>::getCoordinateSystem();
if (*pCS == *cs) {
return BaseVector<length_d>::getQuantityVector().getZ();
} else {
return QuantityVector<length_d>(
get_transformation(*cs.get(), *pCS.get()) *
BaseVector<length_d>::getQuantityVector().eigenVector_)
.getZ();
}
return getCoordinates(pCS).getZ();
}
/// this always returns a QuantityVector as triple
QuantityVector<length_d> Point::getCoordinates(CoordinateSystemPtr const& pCS) const {
inline QuantityVector<length_d> Point::getCoordinates(
CoordinateSystemPtr const& pCS) const {
CoordinateSystemPtr const& cs = BaseVector<length_d>::getCoordinateSystem();
if (*pCS == *cs) {
if (pCS == cs) {
return BaseVector<length_d>::getQuantityVector();
} else {
return QuantityVector<length_d>(
......@@ -72,12 +48,12 @@ namespace corsika {
}
/// this always returns a QuantityVector as triple
QuantityVector<length_d>& Point::getCoordinates(CoordinateSystemPtr const& pCS) {
if (*pCS != *BaseVector<length_d>::getCoordinateSystem()) { rebase(pCS); }
inline QuantityVector<length_d>& Point::getCoordinates(CoordinateSystemPtr const& pCS) {
if (pCS != BaseVector<length_d>::getCoordinateSystem()) { rebase(pCS); }
return BaseVector<length_d>::getQuantityVector();
}
void Point::rebase(CoordinateSystemPtr const& pCS) {
inline void Point::rebase(CoordinateSystemPtr const& pCS) {
BaseVector<length_d>::setQuantityVector(QuantityVector<length_d>(
get_transformation(*BaseVector<length_d>::getCoordinateSystem().get(),
*pCS.get()) *
......@@ -85,14 +61,28 @@ namespace corsika {
BaseVector<length_d>::setCoordinateSystem(pCS);
}
Point Point::operator+(Vector<length_d> const& pVec) const {
inline Point Point::operator+(Vector<length_d> const& pVec) const {
CoordinateSystemPtr const& cs = BaseVector<length_d>::getCoordinateSystem();
return Point(cs, getCoordinates() + pVec.getComponents(cs));
}
Vector<length_d> Point::operator-(Point const& pB) const {
inline Point Point::operator-(Vector<length_d> const& pVec) const {
CoordinateSystemPtr const& cs = BaseVector<length_d>::getCoordinateSystem();
return Point(cs, getCoordinates() - pVec.getComponents(cs));
}
inline Vector<length_d> Point::operator-(Point const& pB) const {
CoordinateSystemPtr const& cs = BaseVector<length_d>::getCoordinateSystem();
return Vector<length_d>(cs, getCoordinates() - pB.getCoordinates(cs));
}
inline std::ostream& operator<<(std::ostream& os, corsika::Point const& p) {
auto const& qv = p.getCoordinates();
os << qv << " (ref:" << fmt::ptr(p.getCoordinateSystem()) << ")";
return os;
}
inline LengthType distance(Point const& p1, Point const& p2) {
return (p1 - p2).getNorm();
}
} // namespace corsika
/*
* (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
#pragma once
......@@ -128,7 +127,7 @@ namespace corsika {
}
template <typename TDimension>
inline auto& QuantityVector<TDimension>::operator-() const {
inline auto QuantityVector<TDimension>::operator-() const {
return QuantityVector<TDimension>(-eigenVector_);
}
......@@ -145,7 +144,7 @@ namespace corsika {
template <typename TDimension>
inline std::ostream& operator<<(std::ostream& os,
corsika::QuantityVector<TDimension> const qv) {
corsika::QuantityVector<TDimension> const& qv) {
using quantity_type = phys::units::quantity<TDimension, double>;
os << '(' << qv.eigenVector_(0) << ' ' << qv.eigenVector_(1) << ' '
......
/*
* (c) Copyright 2023 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
#pragma once
namespace corsika {
inline SeparationPlane::SeparationPlane(Plane const& plane)
: plane_(plane) {}
inline bool SeparationPlane::contains(Point const& p) const {
return !plane_.isAbove(p);
}
inline std::string SeparationPlane::asString() const { return plane_.asString(); }
} // namespace corsika
\ No newline at end of file
/*
* (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
#pragma once
......@@ -25,4 +24,14 @@ namespace corsika {
inline void Sphere::setRadius(LengthType const r) { radius_ = r; }
inline CoordinateSystemPtr const Sphere::getCoordinateSystem() const {
return center_.getCoordinateSystem();
}
inline std::string Sphere::asString() const {
std::ostringstream txt;
txt << "center=" << center_ << ", radius=" << radius_;
return txt.str();
}
} // namespace corsika
/*
* (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
#pragma once
......@@ -23,6 +22,12 @@ namespace corsika {
return u * timeStep_;
}
template <typename Particle>
inline TimeType StraightTrajectory::getTime(Particle const& particle,
double const u) const {
return particle.getTime() + getDuration(u); // timeStep_ * u;
}
inline LengthType StraightTrajectory::getLength(double const u) const {
if (timeLength_ == 0_s) return 0_m;
if (timeStep_ == std::numeric_limits<TimeType::value_type>::infinity() * 1_s)
......
/*
* (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
#pragma once
......@@ -27,7 +26,7 @@ namespace corsika {
template <typename TDimension>
inline QuantityVector<TDimension> Vector<TDimension>::getComponents(
CoordinateSystemPtr const& pCS) const {
if (*pCS == *BaseVector<TDimension>::getCoordinateSystem()) {
if (pCS == BaseVector<TDimension>::getCoordinateSystem()) {
return BaseVector<TDimension>::getQuantityVector();
} else {
return QuantityVector<TDimension>(
......@@ -88,7 +87,7 @@ namespace corsika {
}
template <typename TDimension>
void Vector<TDimension>::rebase(CoordinateSystemPtr const& pCS) {
inline void Vector<TDimension>::rebase(CoordinateSystemPtr const& pCS) {
BaseVector<TDimension>::setQuantityVector(QuantityVector<TDimension>(
get_transformation(*BaseVector<TDimension>::getCoordinateSystem().get(),
*pCS.get())
......@@ -110,7 +109,7 @@ namespace corsika {
template <typename TDimension>
template <typename TDimension2>
auto Vector<TDimension>::getParallelProjectionOnto(
inline auto Vector<TDimension>::getParallelProjectionOnto(
Vector<TDimension2> const& pVec, CoordinateSystemPtr const& pCS) const {
auto const ourCompVec = getComponents(pCS);
auto const otherCompVec = pVec.getComponents(pCS);
......@@ -123,34 +122,36 @@ namespace corsika {
template <typename TDimension>
template <typename TDimension2>
auto Vector<TDimension>::getParallelProjectionOnto(
inline auto Vector<TDimension>::getParallelProjectionOnto(
Vector<TDimension2> const& pVec) const {
return getParallelProjectionOnto<TDimension2>(
pVec, BaseVector<TDimension>::getCoordinateSystem());
}
template <typename TDimension>
Vector<TDimension> Vector<TDimension>::operator+(Vector<TDimension> const& pVec) const {
inline Vector<TDimension> Vector<TDimension>::operator+(
Vector<TDimension> const& pVec) const {
CoordinateSystemPtr const& cs = BaseVector<TDimension>::getCoordinateSystem();
auto const components = getComponents(cs) + pVec.getComponents(cs);
return Vector<TDimension>(BaseVector<TDimension>::getCoordinateSystem(), components);
}
template <typename TDimension>
Vector<TDimension> Vector<TDimension>::operator-(Vector<TDimension> const& pVec) const {
inline Vector<TDimension> Vector<TDimension>::operator-(
Vector<TDimension> const& pVec) const {
CoordinateSystemPtr const& cs = BaseVector<TDimension>::getCoordinateSystem();
return Vector<TDimension>(cs, getComponents() - pVec.getComponents(cs));
}
template <typename TDimension>
auto& Vector<TDimension>::operator*=(double const p) {
inline auto& Vector<TDimension>::operator*=(double const p) {
BaseVector<TDimension>::getQuantityVector() *= p;
return *this;
}
template <typename TDimension>
template <typename TScalarDim>
auto Vector<TDimension>::operator*(
inline auto Vector<TDimension>::operator*(
phys::units::quantity<TScalarDim, double> const p) const {
using ProdDim = phys::units::detail::product_d<TDimension, TScalarDim>;
......@@ -160,51 +161,51 @@ namespace corsika {
template <typename TDimension>
template <typename TScalarDim>
auto Vector<TDimension>::operator/(
inline auto Vector<TDimension>::operator/(
phys::units::quantity<TScalarDim, double> const p) const {
return (*this) * (1 / p);
}
template <typename TDimension>
auto Vector<TDimension>::operator*(double const p) const {
inline auto Vector<TDimension>::operator*(double const p) const {
return Vector<TDimension>(BaseVector<TDimension>::getCoordinateSystem(),
BaseVector<TDimension>::getQuantityVector() * p);
}
template <typename TDimension>
auto Vector<TDimension>::operator/(double const p) const {
inline auto Vector<TDimension>::operator/(double const p) const {
return Vector<TDimension>(BaseVector<TDimension>::getCoordinateSystem(),
BaseVector<TDimension>::getQuantityVector() / p);
}
template <typename TDimension>
auto& Vector<TDimension>::operator+=(Vector<TDimension> const& pVec) {
inline auto& Vector<TDimension>::operator+=(Vector<TDimension> const& pVec) {
BaseVector<TDimension>::getQuantityVector() +=
pVec.getComponents(BaseVector<TDimension>::getCoordinateSystem());
return *this;
}
template <typename TDimension>
auto& Vector<TDimension>::operator-=(Vector<TDimension> const& pVec) {
inline auto& Vector<TDimension>::operator-=(Vector<TDimension> const& pVec) {
BaseVector<TDimension>::getQuantityVector() -=
pVec.getComponents(BaseVector<TDimension>::getCoordinateSystem());
return *this;
}
template <typename TDimension>
auto& Vector<TDimension>::operator-() const {
inline auto Vector<TDimension>::operator-() const {
return Vector<TDimension>(BaseVector<TDimension>::getCoordinateSystem(),
-BaseVector<TDimension>::getQuantityVector());
}
template <typename TDimension>
auto Vector<TDimension>::normalized() const {
inline auto Vector<TDimension>::normalized() const {
return (*this) * (1 / getNorm());
}
template <typename TDimension>
template <typename TDimension2>
auto Vector<TDimension>::cross(Vector<TDimension2> const& pV) const {
inline auto Vector<TDimension>::cross(Vector<TDimension2> const& pV) const {
auto const c1 = getComponents().eigenVector_;
auto const c2 =
pV.getComponents(BaseVector<TDimension>::getCoordinateSystem()).eigenVector_;
......@@ -216,7 +217,7 @@ namespace corsika {
template <typename TDimension>
template <typename TDimension2>
auto Vector<TDimension>::dot(Vector<TDimension2> const& pV) const {
inline auto Vector<TDimension>::dot(Vector<TDimension2> const& pV) const {
auto const c1 = getComponents().eigenVector_;
auto const c2 =
pV.getComponents(BaseVector<TDimension>::getCoordinateSystem()).eigenVector_;
......@@ -228,4 +229,25 @@ namespace corsika {
bareResult);
}
template <typename TDimension>
inline std::ostream& operator<<(std::ostream& os,
corsika::Vector<TDimension> const& v) {
auto const& qv = v.getComponents();
os << qv << " (ref:" << fmt::ptr(v.getCoordinateSystem()) << ")";
return os;
}
/*
* scalar * vector multiplication
*/
template <typename TDimension, typename UDimension>
inline Vector<phys::units::detail::product_d<TDimension, UDimension>> operator*(
quantity<UDimension> const n, Vector<TDimension> const& vec) {
return vec * n;
}
template <typename TDimension>
inline Vector<TDimension> operator*(double const n, Vector<TDimension> const& vec) {
return vec * n;
}
} // namespace corsika
/*
* (c) Copyright 2021 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
#pragma once
#include <corsika/framework/process/ProcessTraits.hpp>
#include <corsika/framework/utility/HasMethodSignature.hpp>
namespace corsika {
/**
traits test for BoundaryCrossingProcess::doBoundaryCrossing method
*/
template <class TProcess, typename TReturn, typename TParticle>
struct has_method_doBoundaryCrossing
: public detail::has_method_signature<TReturn, TParticle&,
typename TParticle::node_type const&,
typename TParticle::node_type const&> {
///! method signature
using detail::has_method_signature<
TReturn, TParticle&, typename TParticle::node_type const&,
typename TParticle::node_type const&>::testSignature;
//! the default value
template <class T>
static std::false_type test(...);
//! templated parameter option
template <class T>
static decltype(testSignature(&T::template doBoundaryCrossing<TParticle>)) test(
std::nullptr_t);
//! non templated parameter option
template <class T>
static decltype(testSignature(&T::doBoundaryCrossing)) test(std::nullptr_t);
public:
/**
@name traits results
@{
*/
using type = decltype(test<std::decay_t<TProcess>>(nullptr));
static const bool value = type::value;
//! @}
};
//! @file BoundaryCrossingProcess.hpp
//! value traits type
template <class TProcess, typename TReturn, typename TParticle>
bool constexpr has_method_doBoundaryCrossing_v =
has_method_doBoundaryCrossing<TProcess, TReturn, TParticle>::value;
} // namespace corsika
/*
* (c) Copyright 2021 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
#pragma once
#include <corsika/framework/process/ProcessTraits.hpp>
#include <corsika/framework/utility/HasMethodSignature.hpp>
/**
* @file CascadeEquationsProcess.hpp
*/
namespace corsika {
/**
* traits test for CascadeEquationsProcess::doCascadeEquations method.
*/
template <class TProcess, typename TReturn, typename... TArg>
struct has_method_doCascadeEquations
: public detail::has_method_signature<TReturn, TArg...> {
//! method signature
using detail::has_method_signature<TReturn, TArg...>::testSignature;
//! the default value
template <class T>
static std::false_type test(...);
//! templated parameter option
template <class T>
static decltype(testSignature(&T::template doCascadeEquations<TArg...>)) test(
std::nullptr_t);
//! non templated parameter option
template <class T>
static decltype(testSignature(&T::doCascadeEquations)) test(std::nullptr_t);
public:
/**
* @name traits results
* @{
*/
using type = decltype(test<std::decay_t<TProcess>>(nullptr));
static const bool value = type::value;
//! @}
};
/**
* value traits type.
*/
template <class TProcess, typename TReturn, typename... TArg>
bool constexpr has_method_doCascadeEquations_v =
has_method_doCascadeEquations<TProcess, TReturn, TArg...>::value;
} // namespace corsika
/*
* (c) Copyright 2021 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
#pragma once
#include <corsika/framework/process/ProcessTraits.hpp>
#include <corsika/framework/utility/HasMethodSignature.hpp>
namespace corsika {
/**
traits test for ContinuousProcess::doContinuous method
*/
template <class TProcess, typename TReturn, typename TArg1, typename TArg2>
struct has_method_doContinuous
: public detail::has_method_signature<TReturn, TArg1, TArg2, bool> {
//! method signature
using detail::has_method_signature<TReturn, TArg1, TArg2, bool>::testSignature;
//! the default value
template <class T>
static std::false_type test(...);
//! templated parameter option
template <class T>
static decltype(testSignature(&T::template doContinuous<TArg1, TArg2>)) test(
std::nullptr_t);
//! non templated parameter option
template <class T>
static decltype(testSignature(&T::doContinuous)) test(std::nullptr_t);
public:
/**
@name traits results
@{
*/
using type = decltype(test<std::decay_t<TProcess>>(nullptr));
static const bool value = type::value;
//! @}
};
//! @file ContinuousProcess.hpp
//! value traits type
template <class TProcess, typename TReturn, typename TArg1, typename TArg2>
bool constexpr has_method_doContinuous_v =
has_method_doContinuous<TProcess, TReturn, TArg1, TArg2>::value;
/**
traits test for ContinuousProcess::getMaxStepLength method
*/
template <class TProcess, typename TReturn, typename... TArgs>
struct has_method_getMaxStepLength
: public detail::has_method_signature<TReturn, TArgs...> {
//! method signature
using detail::has_method_signature<TReturn, TArgs...>::testSignature;
//! the default value
template <class T>
static std::false_type test(...);
//! templated option
template <class T>
static decltype(testSignature(&T::template getMaxStepLength<TArgs...>)) test(
std::nullptr_t);
//! non templated option
template <class T>
static decltype(testSignature(&T::getMaxStepLength)) test(std::nullptr_t);
public:
/**
@name traits results
@{
*/
using type = decltype(test<std::decay_t<TProcess>>(nullptr));
static const bool value = type::value;
//! @}
};
//! value traits type
template <class TProcess, typename TReturn, typename... TArgs>
bool constexpr has_method_getMaxStepLength_v =
has_method_getMaxStepLength<TProcess, TReturn, TArgs...>::value;
} // namespace corsika
/*
* (c) Copyright 2021 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
#pragma once
#include <corsika/framework/process/ProcessTraits.hpp>
#include <corsika/framework/utility/HasMethodSignature.hpp>
namespace corsika {
/**
traits test for DecayProcess::doDecay method
*/
template <class TProcess, typename TReturn, typename... TArgs>
struct has_method_doDecay : public detail::has_method_signature<TReturn, TArgs...> {
//! type of process to be studied
typedef std::decay_t<TProcess> process_type;
///! method signature
using detail::has_method_signature<TReturn, TArgs...>::testSignature;
//! the default value
template <class T>
static std::false_type test(...);
//! signature of templated method
template <class T>
static decltype(testSignature(&T::template doDecay<TArgs...>)) test(std::nullptr_t);
//! signature of non-templated method
template <class T>
static decltype(testSignature(&T::doDecay)) test(std::nullptr_t);
public:
/**
@name traits results
@{
*/
using type = decltype(test<process_type>(nullptr));
static const bool value = type::value;
//! @}
};
//! @file DecayProcess.hpp
//! value traits type
template <class TProcess, typename TReturn, typename... TArgs>
bool constexpr has_method_doDecay_v =
has_method_doDecay<TProcess, TReturn, TArgs...>::value;
/**
traits test for DecayProcess::getLifetime method
*/
template <class TProcess, typename TReturn, typename... TArgs>
struct has_method_getLifetime : public detail::has_method_signature<TReturn, TArgs...> {
//! the moethod signature
using detail::has_method_signature<TReturn, TArgs...>::testSignature;
//! the default value
template <class T>
static std::false_type test(...);
//! signature of templated method
template <class T>
static decltype(testSignature(&T::template getLifetime<TArgs...>)) test(
std::nullptr_t);
//! signature of non-templated method
template <class T>
static decltype(testSignature(&T::getLifetime)) test(std::nullptr_t);
public:
/**
@name traits results
@{
*/
using type = decltype(test<std::decay_t<TProcess>>(nullptr));
static const bool value = type::value;
//! @}
};
//! value traits type
template <class TProcess, typename TReturn, typename... TArgs>
bool constexpr has_method_getLifetime_v =
has_method_getLifetime<TProcess, TReturn, TArgs...>::value;
} // namespace corsika
/*
* (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
#pragma once
......@@ -13,34 +12,25 @@
namespace corsika {
template <class TCountedProcess>
InteractionCounter<TCountedProcess>::InteractionCounter(TCountedProcess& process)
inline InteractionCounter<TCountedProcess>::InteractionCounter(TCountedProcess& process)
: process_(process) {}
template <class TCountedProcess>
template <typename TSecondaryView>
inline void InteractionCounter<TCountedProcess>::doInteraction(TSecondaryView& view) {
auto const projectile = view.getProjectile();
auto const massNumber = projectile.getNode()
->getModelProperties()
.getNuclearComposition()
.getAverageMassNumber();
inline void InteractionCounter<TCountedProcess>::doInteraction(
TSecondaryView& view, Code const projectileId, Code const targetId,
FourMomentum const& projectileP4, FourMomentum const& targetP4) {
size_t const massNumber = is_nucleus(targetId) ? get_nucleus_A(targetId) : 1;
auto const massTarget = massNumber * constants::nucleonMass;
if (auto const projectile_id = projectile.getPID(); projectile_id == Code::Nucleus) {
auto const A = projectile.getNuclearA();
auto const Z = projectile.getNuclearZ();
histogram_.fill(projectile_id, projectile.getEnergy(), massTarget, A, Z);
} else {
histogram_.fill(projectile_id, projectile.getEnergy(), massTarget);
}
process_.doInteraction(view);
histogram_.fill(projectileId, projectileP4.getTimeLikeComponent(), massTarget);
process_.doInteraction(view, projectileId, targetId, projectileP4, targetP4);
}
template <class TCountedProcess>
template <typename TParticle>
inline GrammageType InteractionCounter<TCountedProcess>::getInteractionLength(
TParticle const& particle) const {
return process_.getInteractionLength(particle);
inline CrossSectionType InteractionCounter<TCountedProcess>::getCrossSection(
Code const projectileId, Code const targetId, FourMomentum const& projectileP4,
FourMomentum const& targetP4) const {
return process_.getCrossSection(projectileId, targetId, projectileP4, targetP4);
}
template <class TCountedProcess>
......
/*
* (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
#pragma once
......