create Motion classes on runtime instead of compile
This commit is contained in:
@ -2,20 +2,25 @@
|
||||
// Created by dominik on 8/12/24.
|
||||
//
|
||||
|
||||
// #include <cmath>
|
||||
#include <random>
|
||||
#include <cmath>
|
||||
|
||||
#include "base.h"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
|
||||
#include "coordinates.h"
|
||||
#include "bimodalangle.h"
|
||||
#include "isosmallangle.h"
|
||||
#include "random.h"
|
||||
#include "tetrahedral.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
Motion::Motion(const double delta, const double eta, std::mt19937_64& rng) : m_delta(delta), m_eta(eta), m_rng(rng) {
|
||||
Motion::Motion(std::string name, const double delta, const double eta, std::mt19937_64& rng) : m_name(std::move(name)), m_delta(delta), m_eta(eta), m_rng(rng) {
|
||||
m_uni_dist = std::uniform_real_distribution(0., 1.);
|
||||
}
|
||||
|
||||
Motion::Motion(std::mt19937_64& rng) : m_rng(rng) {
|
||||
Motion::Motion(std::string name, std::mt19937_64& rng) : m_name(std::move(name)), m_rng(rng) {
|
||||
m_uni_dist = std::uniform_real_distribution(0., 1.);
|
||||
}
|
||||
|
||||
@ -27,7 +32,6 @@ double Motion::omega_q(const double cos_theta, const double phi) const {
|
||||
}
|
||||
|
||||
double Motion::omega_q(const SphericalPos& pos) const {
|
||||
// std::cout << pos.cos_theta << " " << pos.phi << std::endl;
|
||||
auto [cos_theta, phi] = pos;
|
||||
|
||||
return omega_q(cos_theta, phi);
|
||||
@ -39,3 +43,24 @@ SphericalPos Motion::draw_position() {
|
||||
|
||||
return {cos_theta, phi};
|
||||
}
|
||||
|
||||
Motion* Motion::createFromInput(const std::string& input, std::mt19937_64& rng) {
|
||||
if (input == "TetrahedralJump")
|
||||
return new TetrahedralJump(rng);
|
||||
|
||||
if (input == "IsotropicAngle")
|
||||
return new SmallAngle(rng);
|
||||
|
||||
if (input == "RandomJump")
|
||||
return new RandomJump(rng);
|
||||
|
||||
if (input == "BimodalAngle")
|
||||
return new BimodalAngle(rng);
|
||||
|
||||
throw std::invalid_argument("Invalid input " + input);
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Motion& m) {
|
||||
os << m.getName();
|
||||
return os;
|
||||
}
|
||||
|
@ -7,15 +7,13 @@
|
||||
|
||||
#include "coordinates.h"
|
||||
#include <random>
|
||||
#include <unordered_map>
|
||||
|
||||
|
||||
class Motion {
|
||||
public:
|
||||
virtual ~Motion() = default;
|
||||
|
||||
Motion(double, double, std::mt19937_64&);
|
||||
explicit Motion(std::mt19937_64&);
|
||||
Motion(std::string, double, double, std::mt19937_64&);
|
||||
explicit Motion(std::string, std::mt19937_64&);
|
||||
|
||||
SphericalPos draw_position();
|
||||
[[nodiscard]] double omega_q(double, double) const;
|
||||
@ -28,13 +26,18 @@ public:
|
||||
void setDelta(const double delta) { m_delta = delta; }
|
||||
[[nodiscard]] double getEta() const { return m_eta; }
|
||||
void setEta(const double eta) { m_eta = eta; }
|
||||
[[nodiscard]] std::string getName() const { return m_name; }
|
||||
|
||||
static Motion* createFromInput(const std::string& input, std::mt19937_64& rng);
|
||||
|
||||
protected:
|
||||
std::string m_name{"Base motion"};
|
||||
double m_delta{1.};
|
||||
double m_eta{0.};
|
||||
std::mt19937_64& m_rng;
|
||||
std::uniform_real_distribution<> m_uni_dist;
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Motion& m);
|
||||
|
||||
#endif //RWSIM_MOTIONBASE_H
|
||||
|
@ -6,11 +6,11 @@
|
||||
#include "base.h"
|
||||
|
||||
BimodalAngle::BimodalAngle(const double delta, const double eta, const double angle1, const double angle2, const double prob, std::mt19937_64 &rng) :
|
||||
Motion(delta, eta, rng),
|
||||
Motion(std::string("Bimodal Angle Jump"), delta, eta, rng),
|
||||
m_angle1(angle1 * M_PI / 180.0),
|
||||
m_angle2(angle2 * M_PI / 180.0),
|
||||
m_prob(prob) {};
|
||||
BimodalAngle::BimodalAngle(std::mt19937_64 &rng) : Motion(rng) {}
|
||||
BimodalAngle::BimodalAngle(std::mt19937_64 &rng) : Motion(std::string("Bimodal Angle Jump"), rng) {}
|
||||
|
||||
void BimodalAngle::initialize() {
|
||||
m_prev_pos = draw_position();
|
||||
|
@ -6,8 +6,9 @@
|
||||
#include "coordinates.h"
|
||||
|
||||
|
||||
SmallAngle::SmallAngle(const double delta, const double eta, const double chi, std::mt19937_64 &rng) : Motion(delta, eta, rng), m_chi(chi * M_PI / 180.0) {};
|
||||
SmallAngle::SmallAngle(std::mt19937_64 &rng) : Motion(rng) {}
|
||||
SmallAngle::SmallAngle(const double delta, const double eta, const double chi, std::mt19937_64 &rng) :
|
||||
Motion(std::string("Isotropic Angle Jump"), delta, eta, rng), m_chi(chi * M_PI / 180.0) {};
|
||||
SmallAngle::SmallAngle(std::mt19937_64 &rng) : Motion(std::string("Isotropic Angle Jump"), rng) {}
|
||||
|
||||
void SmallAngle::initialize() {
|
||||
m_prev_pos = draw_position();
|
||||
|
@ -5,9 +5,9 @@
|
||||
#include "random.h"
|
||||
|
||||
|
||||
RandomJump::RandomJump(const double delta, const double eta, std::mt19937_64 &rng) : Motion(delta, eta, rng) {}
|
||||
RandomJump::RandomJump(const double delta, const double eta, std::mt19937_64 &rng) : Motion(std::string("Random Jump"), delta, eta, rng) {}
|
||||
|
||||
RandomJump::RandomJump(std::mt19937_64 &rng) : Motion(rng) {}
|
||||
RandomJump::RandomJump(std::mt19937_64 &rng) : Motion(std::string("Random Jump"), rng) {}
|
||||
|
||||
void RandomJump::initialize() {}
|
||||
|
||||
|
@ -2,11 +2,13 @@
|
||||
// Created by dominik on 8/16/24.
|
||||
//
|
||||
#include <random>
|
||||
|
||||
#include "tetrahedral.h"
|
||||
|
||||
TetrahedralJump::TetrahedralJump(const double delta, const double eta, std::mt19937_64& rng) : Motion(delta, eta, rng) {}
|
||||
TetrahedralJump::TetrahedralJump(const double delta, const double eta, std::mt19937_64& rng) :
|
||||
Motion(std::string{"TetrahedralJump"}, delta, eta, rng) {}
|
||||
|
||||
TetrahedralJump::TetrahedralJump(std::mt19937_64& rng) : Motion(rng) {}
|
||||
TetrahedralJump::TetrahedralJump(std::mt19937_64& rng) : Motion(std::string{"TetrahedralJump"}, rng) {}
|
||||
|
||||
void TetrahedralJump::initialize() {
|
||||
const auto pos = draw_position();
|
||||
|
Reference in New Issue
Block a user