IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 42390d8f authored by Antonio Augusto Alves Junior's avatar Antonio Augusto Alves Junior Committed by ralfulrich
Browse files

[refactory-2020] fixes for address review comments.

parent e9be64c2
No related branches found
No related tags found
No related merge requests found
...@@ -13,56 +13,57 @@ n/* ...@@ -13,56 +13,57 @@ n/*
namespace corsika { namespace corsika {
template <class TQuantity> template <typename Quantity>
class ExponentialDistribution { class ExponentialDistribution {
using RealType = typename TQuantity::value_type; typedef typename Quantity::value_type real_type;
typedef std::exponential_distribution<RealType> distribution_type; typedef std::exponential_distribution<real_type> distribution_type;
typedef TQuantity quantity_type;
public: public:
typedef Quantity value_type;
ExponentialDistribution()=delete; ExponentialDistribution()=delete;
ExponentialDistribution(quantity_type vBeta) ExponentialDistribution(value_type const& beta)
: beta_(vBeta) {} : beta_(beta) {}
ExponentialDistribution(ExponentialDistribution<quantity_type>const& other): ExponentialDistribution(ExponentialDistribution<value_type>const& other):
beta_(other.getBeta()) beta_(other.getBeta())
{} {}
ExponentialDistribution<quantity_type>& ExponentialDistribution<value_type>&
operator=(ExponentialDistribution<quantity_type>const& other){ operator=(ExponentialDistribution<value_type>const& other){
if( this == &other) return *this; if( this == &other) return *this;
beta_ = other.getBeta(); beta_ = other.getBeta();
return *this; return *this;
} }
/** /**
* @fn quantity_type getBeta()const * @fn value_type getBeta()const
* @brief Get parameter of exponential distribution \f[ \beta e^{-X}\f] * @brief Get parameter of exponential distribution \f[ \beta e^{-X}\f]
* @pre * @pre
* @post * @post
* @return quantity_type * @return value_type
*/ */
quantity_type getBeta() const { value_type getBeta() const {
return beta_; return beta_;
} }
/** /**
* @fn void setBeta(quantity_type) * @fn void setBeta(value_type)
* @brief Set parameter of exponential distribution \f[ \beta e^{-X}\f] * @brief Set parameter of exponential distribution \f[ \beta e^{-X}\f]
* *
* @pre * @pre
* @post * @post
* @param vBeta * @param vBeta
*/ */
void setBeta(quantity_type vBeta) { void setBeta(value_type const& beta) {
beta_ = vBeta; beta_ = beta;
} }
/** /**
* @fn quantity_type operator ()(Generator&) * @fn value_type operator ()(Generator&)
* @brief Generate a random number distributed like \f[ \beta e^{-X}\f] * @brief Generate a random number distributed like \f[ \beta e^{-X}\f]
* *
* @pre * @pre
...@@ -72,14 +73,14 @@ namespace corsika { ...@@ -72,14 +73,14 @@ namespace corsika {
* @return * @return
*/ */
template <class Generator> template <class Generator>
quantity_type operator()(Generator& g) { value_type operator()(Generator& g) {
return beta_ * dist_(g); return beta_ * dist_(g);
} }
private: private:
distribution_type dist_{1.}; distribution_type dist_{1.};
quantity_type beta_; value_type beta_;
}; };
} // namespace corsika } // namespace corsika
...@@ -46,18 +46,18 @@ namespace corsika { ...@@ -46,18 +46,18 @@ namespace corsika {
* *
* \throws sth. when stream \a pModuleName is already registered * \throws sth. when stream \a pModuleName is already registered
*/ */
inline void registerRandomStream(string_type const& vStreamName); inline void registerRandomStream(string_type const& streamName);
/*! /*!
* returns the pre-stored stream of given name \a pStreamName if * returns the pre-stored stream of given name \a pStreamName if
* available * available
*/ */
inline prng_type& getRandomStream(string_type const& vStreamName); inline prng_type& getRandomStream(string_type const& streamName);
/*! /*!
* Check whether a stream has been registered. * Check whether a stream has been registered.
*/ */
inline bool isRegistered(string_type const& vStreamName) const; inline bool isRegistered(string_type const& streamName) const;
/*! /*!
* dumps the names and states of all registered random-number streams * dumps the names and states of all registered random-number streams
...@@ -69,7 +69,7 @@ namespace corsika { ...@@ -69,7 +69,7 @@ namespace corsika {
* Set explicit seeds for all currently registered streams. The actual seed values * Set explicit seeds for all currently registered streams. The actual seed values
* are incremented from \a vSeed. * are incremented from \a vSeed.
*/ */
inline void seedAll(seed_type vSeed); inline void seedAll(seed_type seed);
/** /**
* Set seeds for all currently registered streams. * Set seeds for all currently registered streams.
......
...@@ -14,32 +14,33 @@ ...@@ -14,32 +14,33 @@
namespace corsika { namespace corsika {
template <class TQuantity> template <typename Quantity>
class UniformRealDistribution { class UniformRealDistribution {
using RealType = typename TQuantity::value_type;
typedef std::uniform_real_distribution<RealType> distribution_type; typedef typename Quantity::value_type real_type;
typedef std::uniform_real_distribution<real_type> distribution_type;
public: public:
typedef TQuantity quantity_type; typedef Quantity value_type;
UniformRealDistribution() = delete; UniformRealDistribution() = delete;
UniformRealDistribution(TQuantity b) UniformRealDistribution(Quantity const& b)
: min_{quantity_type(phys::units::detail::magnitude_tag, 0)} : min_{value_type(phys::units::detail::magnitude_tag, 0)}
, max_(b) {} , max_(b) {}
UniformRealDistribution(quantity_type vMin, quantity_type vMax) UniformRealDistribution(value_type const& pmin, value_type const& pmax)
: min_(vMin) : min_(pmin)
, max_(vMax) {} , max_(pmax) {}
UniformRealDistribution(UniformRealDistribution<quantity_type> const& other): UniformRealDistribution(UniformRealDistribution<value_type> const& other):
min_(other.getMin()) min_(other.getMin())
, max_(other.getMax()) , max_(other.getMax())
{} {}
inline UniformRealDistribution<quantity_type>& inline UniformRealDistribution<value_type>&
operator=(UniformRealDistribution<quantity_type> const& other){ operator=(UniformRealDistribution<value_type> const& other){
if( this == &other) return *this; if( this == &other) return *this;
min_ = other.getMin(); min_ = other.getMin();
max_ = other.getMax(); max_ = other.getMax();
...@@ -54,7 +55,7 @@ namespace corsika { ...@@ -54,7 +55,7 @@ namespace corsika {
* @post * @post
* @return quantity_type * @return quantity_type
*/ */
inline quantity_type getMax() const { inline value_type getMax() const {
return max_; return max_;
} }
...@@ -66,8 +67,8 @@ namespace corsika { ...@@ -66,8 +67,8 @@ namespace corsika {
* @post * @post
* @param vMax * @param vMax
*/ */
inline void setMax(quantity_type vMax) { inline void setMax(value_type const& pmax) {
max_ = vMax; max_ = pmax;
} }
/** /**
...@@ -78,7 +79,7 @@ namespace corsika { ...@@ -78,7 +79,7 @@ namespace corsika {
* @post * @post
* @return * @return
*/ */
inline quantity_type getMin() const { inline value_type getMin() const {
return min_; return min_;
} }
...@@ -90,8 +91,8 @@ namespace corsika { ...@@ -90,8 +91,8 @@ namespace corsika {
* @post * @post
* @param vMin * @param vMin
*/ */
inline void setMin(quantity_type vMin) { inline void setMin(value_type const& pmin) {
min_ = vMin; min_ = pmin;
} }
/** /**
...@@ -105,16 +106,16 @@ namespace corsika { ...@@ -105,16 +106,16 @@ namespace corsika {
* @return quantity_type * @return quantity_type
*/ */
template <class Generator> template <class Generator>
inline quantity_type operator()(Generator& g) { inline value_type operator()(Generator& g) {
return min_ + dist_(g) * (max_ - min_); return min_ + dist_(g) * (max_ - min_);
} }
private: private:
distribution_type dist_{RealType(0.), RealType(1.)}; distribution_type dist_{real_type(0.), real_type(1.)};
quantity_type min_; value_type min_;
quantity_type max_; value_type max_;
}; };
} // namespace corsika } // namespace corsika
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment