add namespaces and cmakelists for sub-dirs
This commit is contained in:
23
src/motions/CMakeLists.txt
Normal file
23
src/motions/CMakeLists.txt
Normal file
@ -0,0 +1,23 @@
|
||||
# Create a library target for motions
|
||||
add_library(
|
||||
RWMotion STATIC
|
||||
conewobble.cpp
|
||||
conewobble.h
|
||||
coordinates.cpp
|
||||
coordinates.h
|
||||
base.cpp
|
||||
base.h
|
||||
random.cpp
|
||||
random.h
|
||||
isosmallangle.cpp
|
||||
isosmallangle.h
|
||||
foursitejump.cpp
|
||||
foursitejump.h
|
||||
rjoac.cpp
|
||||
rjoac.h
|
||||
bimodalangle.cpp
|
||||
bimodalangle.h
|
||||
sixsitejump.cpp
|
||||
sixsitejump.h
|
||||
)
|
||||
|
@ -4,68 +4,74 @@
|
||||
#include "bimodalangle.h"
|
||||
#include "isosmallangle.h"
|
||||
#include "random.h"
|
||||
#include "tetrahedral.h"
|
||||
#include "foursitejump.h"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <map>
|
||||
|
||||
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.);
|
||||
}
|
||||
#include "sixsitejump.h"
|
||||
|
||||
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.);
|
||||
}
|
||||
namespace motions {
|
||||
BaseMotion::BaseMotion(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.);
|
||||
}
|
||||
|
||||
double Motion::omega_q(const double cos_theta, const double phi) const {
|
||||
const double cos_theta_square = cos_theta * cos_theta;
|
||||
const double sin_theta_square = 1. - cos_theta_square;
|
||||
BaseMotion::BaseMotion(std::string name, std::mt19937_64& rng) : m_name(std::move(name)), m_rng(rng) {
|
||||
m_uni_dist = std::uniform_real_distribution(0., 1.);
|
||||
}
|
||||
|
||||
return M_PI * m_delta * (3. * cos_theta_square - 1. - m_eta * sin_theta_square * std::cos(2.*phi));
|
||||
}
|
||||
double BaseMotion::omega_q(const double cos_theta, const double phi) const {
|
||||
const double cos_theta_square = cos_theta * cos_theta;
|
||||
const double sin_theta_square = 1. - cos_theta_square;
|
||||
|
||||
double Motion::omega_q(const SphericalPos& pos) const {
|
||||
auto [cos_theta, phi] = pos;
|
||||
return M_PI * m_delta * (3. * cos_theta_square - 1. - m_eta * sin_theta_square * std::cos(2.*phi));
|
||||
}
|
||||
|
||||
return omega_q(cos_theta, phi);
|
||||
}
|
||||
double BaseMotion::omega_q(const coordinates::SphericalPos& pos) const {
|
||||
auto [cos_theta, phi] = pos;
|
||||
|
||||
SphericalPos Motion::draw_position() {
|
||||
const double cos_theta = 1 - 2 * m_uni_dist(m_rng);
|
||||
const double phi = 2.0 * M_PI * m_uni_dist(m_rng);
|
||||
return omega_q(cos_theta, phi);
|
||||
}
|
||||
|
||||
return {cos_theta, phi};
|
||||
}
|
||||
coordinates::SphericalPos BaseMotion::draw_position() {
|
||||
const double cos_theta = 1 - 2 * m_uni_dist(m_rng);
|
||||
const double phi = 2.0 * M_PI * m_uni_dist(m_rng);
|
||||
|
||||
Motion* Motion::createFromInput(const std::string& input, std::mt19937_64& rng) {
|
||||
if (input == "TetrahedralJump")
|
||||
return new TetrahedralJump(rng);
|
||||
return {cos_theta, phi};
|
||||
}
|
||||
|
||||
if (input == "IsotropicAngle")
|
||||
return new SmallAngle(rng);
|
||||
BaseMotion* BaseMotion::createFromInput(const std::string& input, std::mt19937_64& rng) {
|
||||
if (input == "FourSiteTetrahedral")
|
||||
return new FourSiteTetrahedron(rng);
|
||||
|
||||
if (input == "RandomJump")
|
||||
return new RandomJump(rng);
|
||||
if (input == "SixSiteOctahedral")
|
||||
return new SixSiteOctahedron(rng);
|
||||
|
||||
if (input == "BimodalAngle")
|
||||
return new BimodalAngle(rng);
|
||||
if (input == "IsotropicAngle")
|
||||
return new SmallAngle(rng);
|
||||
|
||||
throw std::invalid_argument("Invalid input " + input);
|
||||
}
|
||||
if (input == "RandomJump")
|
||||
return new RandomJump(rng);
|
||||
|
||||
void Motion::setParameters(const std::unordered_map<std::string, double> ¶meters) {
|
||||
m_delta = parameters.at("delta");
|
||||
m_eta = parameters.at("eta");
|
||||
}
|
||||
if (input == "BimodalAngle")
|
||||
return new BimodalAngle(rng);
|
||||
|
||||
std::unordered_map<std::string, double> Motion::getParameters() const {
|
||||
return std::unordered_map<std::string, double>{
|
||||
{"delta", m_delta},
|
||||
{"eta", m_eta}
|
||||
};
|
||||
}
|
||||
throw std::invalid_argument("Invalid input " + input);
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Motion& m) {
|
||||
os << m.getName();
|
||||
return os;
|
||||
void BaseMotion::setParameters(const std::unordered_map<std::string, double> ¶meters) {
|
||||
m_delta = parameters.at("delta");
|
||||
m_eta = parameters.at("eta");
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, double> BaseMotion::getParameters() const {
|
||||
return std::unordered_map<std::string, double>{
|
||||
{"delta", m_delta},
|
||||
{"eta", m_eta}
|
||||
};
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const BaseMotion& m) {
|
||||
os << m.getName();
|
||||
return os;
|
||||
}
|
||||
}
|
@ -6,42 +6,43 @@
|
||||
#include <random>
|
||||
#include <unordered_map>
|
||||
|
||||
class Motion {
|
||||
public:
|
||||
virtual ~Motion() = default;
|
||||
namespace motions {
|
||||
class BaseMotion {
|
||||
public:
|
||||
virtual ~BaseMotion() = default;
|
||||
|
||||
Motion(std::string, double, double, std::mt19937_64&);
|
||||
explicit Motion(std::string, std::mt19937_64&);
|
||||
BaseMotion(std::string, double, double, std::mt19937_64&);
|
||||
explicit BaseMotion(std::string, std::mt19937_64&);
|
||||
|
||||
SphericalPos draw_position();
|
||||
[[nodiscard]] double omega_q(double, double) const;
|
||||
[[nodiscard]] double omega_q(const SphericalPos&) const;
|
||||
coordinates::SphericalPos draw_position();
|
||||
[[nodiscard]] double omega_q(double, double) const;
|
||||
[[nodiscard]] double omega_q(const coordinates::SphericalPos&) const;
|
||||
|
||||
virtual void initialize() = 0;
|
||||
virtual double jump() = 0;
|
||||
virtual void initialize() = 0;
|
||||
virtual double jump() = 0;
|
||||
|
||||
virtual void setParameters(const std::unordered_map<std::string, double>&);
|
||||
[[nodiscard]] virtual std::unordered_map<std::string, double> getParameters() const;
|
||||
[[nodiscard]] double getDelta() const { return m_delta; }
|
||||
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; }
|
||||
[[nodiscard]] double getInitOmega() const { return m_initial_omega; };
|
||||
virtual void setParameters(const std::unordered_map<std::string, double>&);
|
||||
[[nodiscard]] virtual std::unordered_map<std::string, double> getParameters() const;
|
||||
[[nodiscard]] double getDelta() const { return m_delta; }
|
||||
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; }
|
||||
[[nodiscard]] double getInitOmega() const { return m_initial_omega; };
|
||||
|
||||
[[nodiscard]] virtual std::string toString() const = 0;
|
||||
[[nodiscard]] virtual std::string toString() const = 0;
|
||||
|
||||
static Motion* createFromInput(const std::string& input, std::mt19937_64& rng);
|
||||
static BaseMotion* createFromInput(const std::string& input, std::mt19937_64& rng);
|
||||
|
||||
protected:
|
||||
std::string m_name{"BaseMotion"};
|
||||
double m_delta{1.};
|
||||
double m_eta{0.};
|
||||
std::mt19937_64& m_rng;
|
||||
std::uniform_real_distribution<> m_uni_dist;
|
||||
double m_initial_omega{0.};
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Motion& m);
|
||||
protected:
|
||||
std::string m_name{"BaseMotion"};
|
||||
double m_delta{1.};
|
||||
double m_eta{0.};
|
||||
std::mt19937_64& m_rng;
|
||||
std::uniform_real_distribution<> m_uni_dist;
|
||||
double m_initial_omega{0.};
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const BaseMotion& m);
|
||||
}
|
||||
#endif //RWSIM_MOTIONBASE_H
|
||||
|
@ -1,43 +1,46 @@
|
||||
|
||||
#include "bimodalangle.h"
|
||||
#include "base.h"
|
||||
#include "coordinates.h"
|
||||
|
||||
BimodalAngle::BimodalAngle(const double delta, const double eta, const double angle1, const double angle2, const double prob, std::mt19937_64 &rng) :
|
||||
Motion(std::string("BimodalAngle"), 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(std::string("BimodalAngle"), rng) {}
|
||||
namespace motions {
|
||||
BimodalAngle::BimodalAngle(const double delta, const double eta, const double angle1, const double angle2, const double prob, std::mt19937_64 &rng) :
|
||||
BaseMotion(std::string("BimodalAngle"), 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) : BaseMotion(std::string("BimodalAngle"), rng) {}
|
||||
|
||||
void BimodalAngle::initialize() {
|
||||
m_prev_pos = draw_position();
|
||||
m_initial_omega = omega_q(m_prev_pos);
|
||||
};
|
||||
void BimodalAngle::initialize() {
|
||||
m_prev_pos = draw_position();
|
||||
m_initial_omega = omega_q(m_prev_pos);
|
||||
};
|
||||
|
||||
double BimodalAngle::jump() {
|
||||
const double angle = m_uni_dist(m_rng) < m_prob ? m_angle1 : m_angle2;
|
||||
const double gamma{2 * M_PI * m_uni_dist(m_rng)};
|
||||
m_prev_pos = rotate(m_prev_pos, angle, gamma);
|
||||
double BimodalAngle::jump() {
|
||||
const double angle = m_uni_dist(m_rng) < m_prob ? m_angle1 : m_angle2;
|
||||
const double gamma{2 * M_PI * m_uni_dist(m_rng)};
|
||||
m_prev_pos = coordinates::rotate(m_prev_pos, angle, gamma);
|
||||
|
||||
return omega_q(m_prev_pos);
|
||||
}
|
||||
|
||||
void BimodalAngle::setParameters(const std::unordered_map<std::string, double> ¶meter) {
|
||||
Motion::setParameters(parameter);
|
||||
|
||||
m_angle1 = parameter.at("angle1") * M_PI / 180.;
|
||||
m_angle2 = parameter.at("angle2") * M_PI / 180.;
|
||||
m_prob = parameter.at("probability1");
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, double> BimodalAngle::getParameters() const {
|
||||
auto parameter = Motion::getParameters();
|
||||
parameter["angle1"] = m_angle1 * 180 / M_PI;
|
||||
parameter["angle2"] = m_angle2 * 180 / M_PI;
|
||||
parameter["probality1"] = m_prob;
|
||||
return parameter;
|
||||
}
|
||||
|
||||
std::string BimodalAngle::toString() const {
|
||||
return std::string{"BimodalAngle/angle1=" + std::to_string(m_angle1 * 180 / M_PI) + "/angle2=" + std::to_string(m_angle2 * 180 / M_PI) + "/probability1=" + std::to_string(m_prob)};
|
||||
return omega_q(m_prev_pos);
|
||||
}
|
||||
|
||||
void BimodalAngle::setParameters(const std::unordered_map<std::string, double> ¶meter) {
|
||||
BaseMotion::setParameters(parameter);
|
||||
|
||||
m_angle1 = parameter.at("angle1") * M_PI / 180.;
|
||||
m_angle2 = parameter.at("angle2") * M_PI / 180.;
|
||||
m_prob = parameter.at("probability1");
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, double> BimodalAngle::getParameters() const {
|
||||
auto parameter = BaseMotion::getParameters();
|
||||
parameter["angle1"] = m_angle1 * 180 / M_PI;
|
||||
parameter["angle2"] = m_angle2 * 180 / M_PI;
|
||||
parameter["probality1"] = m_prob;
|
||||
return parameter;
|
||||
}
|
||||
|
||||
std::string BimodalAngle::toString() const {
|
||||
return std::string{"BimodalAngle/angle1=" + std::to_string(m_angle1 * 180 / M_PI) + "/angle2=" + std::to_string(m_angle2 * 180 / M_PI) + "/probability1=" + std::to_string(m_prob)};
|
||||
}
|
||||
}
|
||||
|
@ -3,23 +3,25 @@
|
||||
#define BIMODALANGLE_H
|
||||
|
||||
#include "base.h"
|
||||
#include "coordinates.h"
|
||||
|
||||
class BimodalAngle : public Motion {
|
||||
public:
|
||||
BimodalAngle(double, double, double, double, double, std::mt19937_64& );
|
||||
explicit BimodalAngle(std::mt19937_64&);
|
||||
namespace motions {
|
||||
class BimodalAngle : public BaseMotion {
|
||||
public:
|
||||
BimodalAngle(double, double, double, double, double, std::mt19937_64& );
|
||||
explicit BimodalAngle(std::mt19937_64&);
|
||||
|
||||
void initialize() override;
|
||||
double jump() override;
|
||||
void setParameters(const std::unordered_map<std::string, double> &) override;
|
||||
[[nodiscard]] std::unordered_map<std::string, double> getParameters() const override;
|
||||
[[nodiscard]] std::string toString() const override;
|
||||
|
||||
protected:
|
||||
double m_angle1{0};
|
||||
double m_angle2{0};
|
||||
double m_prob{0};
|
||||
SphericalPos m_prev_pos{0., 0.};
|
||||
};
|
||||
void initialize() override;
|
||||
double jump() override;
|
||||
void setParameters(const std::unordered_map<std::string, double> &) override;
|
||||
[[nodiscard]] std::unordered_map<std::string, double> getParameters() const override;
|
||||
[[nodiscard]] std::string toString() const override;
|
||||
|
||||
protected:
|
||||
double m_angle1{0};
|
||||
double m_angle2{0};
|
||||
double m_prob{0};
|
||||
coordinates::SphericalPos m_prev_pos{0., 0.};
|
||||
};
|
||||
}
|
||||
#endif //BIMODALANGLE_H
|
||||
|
@ -3,37 +3,39 @@
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
||||
SphericalPos rotate(const SphericalPos& old_pos, const double alpha, const double beta) {
|
||||
const double sin_alpha{std::sin(alpha)};
|
||||
const double cos_alpha{std::cos(alpha)};
|
||||
namespace coordinates {
|
||||
SphericalPos rotate(const SphericalPos& old_pos, const double alpha, const double beta) {
|
||||
const double sin_alpha{std::sin(alpha)};
|
||||
const double cos_alpha{std::cos(alpha)};
|
||||
|
||||
const double sin_beta{std::sin(beta)};
|
||||
const double cos_beta{std::cos(beta)};
|
||||
const double sin_beta{std::sin(beta)};
|
||||
const double cos_beta{std::cos(beta)};
|
||||
|
||||
const double cos_theta{old_pos.cos_theta};
|
||||
const double cos_theta{old_pos.cos_theta};
|
||||
|
||||
if (std::abs(cos_theta) == 1) {
|
||||
return xyz_to_spherical(CartesianPos{cos_alpha * cos_beta, cos_alpha * sin_beta, cos_alpha * cos_theta});
|
||||
if (std::abs(cos_theta) == 1) {
|
||||
return xyz_to_spherical(CartesianPos{cos_alpha * cos_beta, cos_alpha * sin_beta, cos_alpha * cos_theta});
|
||||
}
|
||||
|
||||
const double norm{std::sqrt(1 - cos_theta * cos_theta) + 1e-15};
|
||||
|
||||
auto [x, y , z] = spherical_to_xyz(old_pos);
|
||||
|
||||
const auto new_pos = CartesianPos{
|
||||
cos_alpha * x + sin_alpha * (-x * z * sin_beta - y * cos_beta) / norm,
|
||||
cos_alpha * y + sin_alpha * (-y * z * sin_beta + x * cos_beta) / norm,
|
||||
cos_alpha * z + sin_alpha * norm * sin_beta
|
||||
};
|
||||
|
||||
return xyz_to_spherical(new_pos);
|
||||
}
|
||||
|
||||
const double norm{std::sqrt(1 - cos_theta * cos_theta) + 1e-15};
|
||||
CartesianPos spherical_to_xyz(const SphericalPos& pos) {
|
||||
const double sin_theta = std::sin(std::acos(pos.cos_theta));
|
||||
return {sin_theta * std::cos(pos.phi), sin_theta * std::sin(pos.phi), pos.cos_theta};
|
||||
}
|
||||
|
||||
auto [x, y , z] = spherical_to_xyz(old_pos);
|
||||
|
||||
const auto new_pos = CartesianPos{
|
||||
cos_alpha * x + sin_alpha * (-x * z * sin_beta - y * cos_beta) / norm,
|
||||
cos_alpha * y + sin_alpha * (-y * z * sin_beta + x * cos_beta) / norm,
|
||||
cos_alpha * z + sin_alpha * norm * sin_beta
|
||||
};
|
||||
|
||||
return xyz_to_spherical(new_pos);
|
||||
}
|
||||
|
||||
CartesianPos spherical_to_xyz(const SphericalPos& pos) {
|
||||
const double sin_theta = std::sin(std::acos(pos.cos_theta));
|
||||
return {sin_theta * std::cos(pos.phi), sin_theta * std::sin(pos.phi), pos.cos_theta};
|
||||
}
|
||||
|
||||
SphericalPos xyz_to_spherical(const CartesianPos& pos) {
|
||||
return {pos.z, std::atan2(pos.y, pos.x)};
|
||||
}
|
||||
SphericalPos xyz_to_spherical(const CartesianPos& pos) {
|
||||
return {pos.z, std::atan2(pos.y, pos.x)};
|
||||
}
|
||||
}
|
@ -2,19 +2,21 @@
|
||||
#ifndef COORDINATES_H
|
||||
#define COORDINATES_H
|
||||
|
||||
struct SphericalPos {
|
||||
double cos_theta;
|
||||
double phi;
|
||||
};
|
||||
namespace coordinates {
|
||||
struct SphericalPos {
|
||||
double cos_theta;
|
||||
double phi;
|
||||
};
|
||||
|
||||
struct CartesianPos {
|
||||
double x;
|
||||
double y;
|
||||
double z;
|
||||
};
|
||||
struct CartesianPos {
|
||||
double x;
|
||||
double y;
|
||||
double z;
|
||||
};
|
||||
|
||||
SphericalPos rotate(const SphericalPos&, double, double);
|
||||
CartesianPos spherical_to_xyz(const SphericalPos&);
|
||||
SphericalPos xyz_to_spherical(const CartesianPos&);
|
||||
SphericalPos rotate(const SphericalPos&, double, double);
|
||||
CartesianPos spherical_to_xyz(const SphericalPos&);
|
||||
SphericalPos xyz_to_spherical(const CartesianPos&);
|
||||
}
|
||||
|
||||
#endif //COORDINATES_H
|
||||
|
35
src/motions/foursitejump.cpp
Normal file
35
src/motions/foursitejump.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include "foursitejump.h"
|
||||
#include "coordinates.h"
|
||||
|
||||
#include <random>
|
||||
|
||||
namespace motions {
|
||||
FourSiteTetrahedron::FourSiteTetrahedron(const double delta, const double eta, std::mt19937_64& rng) :
|
||||
BaseMotion(std::string{"FourSiteTetrahedral"}, delta, eta, rng) {}
|
||||
|
||||
FourSiteTetrahedron::FourSiteTetrahedron(std::mt19937_64& rng) : BaseMotion(std::string{"FourSiteTetrahedral"}, rng) {}
|
||||
|
||||
void FourSiteTetrahedron::initialize() {
|
||||
const auto pos = draw_position();
|
||||
m_corners[0] = omega_q(pos);
|
||||
|
||||
const double alpha = 2. * M_PI * m_uni_dist(m_rng);
|
||||
|
||||
for (int i = 1; i<4; i++) {
|
||||
auto corner_pos = coordinates::rotate(pos, m_beta, alpha + (i-1) * 2*M_PI/3.);
|
||||
m_corners[i] = omega_q(corner_pos);
|
||||
}
|
||||
m_initial_omega = FourSiteTetrahedron::jump();
|
||||
}
|
||||
|
||||
double FourSiteTetrahedron::jump() {
|
||||
m_corner_idx += m_chooser(m_rng);
|
||||
m_corner_idx %= 4;
|
||||
|
||||
return m_corners[m_corner_idx];
|
||||
}
|
||||
|
||||
std::string FourSiteTetrahedron::toString() const {
|
||||
return {"FourSiteTetrahedral"};
|
||||
}
|
||||
}
|
31
src/motions/foursitejump.h
Normal file
31
src/motions/foursitejump.h
Normal file
@ -0,0 +1,31 @@
|
||||
#ifndef RWSIM_MOTIONTETRAHEDRAL_H
|
||||
#define RWSIM_MOTIONTETRAHEDRAL_H
|
||||
|
||||
#include "base.h"
|
||||
|
||||
#include <random>
|
||||
#include <cmath>
|
||||
#include <array>
|
||||
|
||||
namespace motions {
|
||||
class FourSiteTetrahedron final : public BaseMotion {
|
||||
public:
|
||||
FourSiteTetrahedron(double, double, std::mt19937_64&);
|
||||
explicit FourSiteTetrahedron(std::mt19937_64&);
|
||||
|
||||
void initialize() override;
|
||||
double jump() override;
|
||||
|
||||
[[nodiscard]] std::string toString() const override;
|
||||
|
||||
private:
|
||||
const double m_beta{std::acos(-1/3.)};
|
||||
|
||||
std::array<double, 4> m_corners{};
|
||||
int m_corner_idx{0};
|
||||
|
||||
std::uniform_int_distribution<> m_chooser{1, 3};
|
||||
|
||||
};
|
||||
}
|
||||
#endif //RWSIM_MOTIONTETRAHEDRAL_H
|
@ -4,34 +4,35 @@
|
||||
#include <iostream>
|
||||
|
||||
|
||||
namespace motions {
|
||||
SmallAngle::SmallAngle(const double delta, const double eta, const double chi, std::mt19937_64 &rng) :
|
||||
BaseMotion(std::string("IsotropicAngle"), delta, eta, rng), m_chi(chi * M_PI / 180.0) {};
|
||||
SmallAngle::SmallAngle(std::mt19937_64 &rng) : BaseMotion(std::string("IsotropicAngle"), rng) {}
|
||||
|
||||
SmallAngle::SmallAngle(const double delta, const double eta, const double chi, std::mt19937_64 &rng) :
|
||||
Motion(std::string("IsotropicAngle"), delta, eta, rng), m_chi(chi * M_PI / 180.0) {};
|
||||
SmallAngle::SmallAngle(std::mt19937_64 &rng) : Motion(std::string("IsotropicAngle"), rng) {}
|
||||
void SmallAngle::initialize() {
|
||||
m_prev_pos = draw_position();
|
||||
m_initial_omega = omega_q(m_prev_pos);
|
||||
};
|
||||
|
||||
void SmallAngle::initialize() {
|
||||
m_prev_pos = draw_position();
|
||||
m_initial_omega = omega_q(m_prev_pos);
|
||||
};
|
||||
double SmallAngle::jump() {
|
||||
const double gamma{2 * M_PI * m_uni_dist(m_rng)};
|
||||
m_prev_pos = coordinates::rotate(m_prev_pos, m_chi, gamma);
|
||||
|
||||
double SmallAngle::jump() {
|
||||
const double gamma{2 * M_PI * m_uni_dist(m_rng)};
|
||||
m_prev_pos = rotate(m_prev_pos, m_chi, gamma);
|
||||
return omega_q(m_prev_pos);
|
||||
}
|
||||
|
||||
return omega_q(m_prev_pos);
|
||||
}
|
||||
|
||||
void SmallAngle::setParameters(const std::unordered_map<std::string, double> ¶meters) {
|
||||
m_chi = parameters.at("angle") * M_PI / 180.0;
|
||||
Motion::setParameters(parameters);
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, double> SmallAngle::getParameters() const {
|
||||
auto parameter = Motion::getParameters();
|
||||
parameter["angle"] = m_chi * 180 / M_PI;
|
||||
return parameter;
|
||||
}
|
||||
|
||||
std::string SmallAngle::toString() const {
|
||||
return std::string{"IsotropicAngle/angle=" + std::to_string(m_chi * 180 / M_PI)};
|
||||
void SmallAngle::setParameters(const std::unordered_map<std::string, double> ¶meters) {
|
||||
m_chi = parameters.at("angle") * M_PI / 180.0;
|
||||
BaseMotion::setParameters(parameters);
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, double> SmallAngle::getParameters() const {
|
||||
auto parameter = BaseMotion::getParameters();
|
||||
parameter["angle"] = m_chi * 180 / M_PI;
|
||||
return parameter;
|
||||
}
|
||||
|
||||
std::string SmallAngle::toString() const {
|
||||
return std::string{"IsotropicAngle/angle=" + std::to_string(m_chi * 180 / M_PI)};
|
||||
}
|
||||
}
|
||||
|
@ -5,20 +5,21 @@
|
||||
#include "base.h"
|
||||
#include "coordinates.h"
|
||||
|
||||
class SmallAngle final : public Motion {
|
||||
public:
|
||||
SmallAngle(double, double, double, std::mt19937_64& );
|
||||
explicit SmallAngle(std::mt19937_64&);
|
||||
namespace motions {
|
||||
class SmallAngle final : public BaseMotion {
|
||||
public:
|
||||
SmallAngle(double, double, double, std::mt19937_64& );
|
||||
explicit SmallAngle(std::mt19937_64&);
|
||||
|
||||
void initialize() override;
|
||||
double jump() override;
|
||||
void setParameters(const std::unordered_map<std::string, double> &) override;
|
||||
[[nodiscard]] std::unordered_map<std::string, double> getParameters() const override;
|
||||
[[nodiscard]] std::string toString() const override;
|
||||
|
||||
private:
|
||||
double m_chi{0};
|
||||
SphericalPos m_prev_pos{0., 0.};
|
||||
};
|
||||
void initialize() override;
|
||||
double jump() override;
|
||||
void setParameters(const std::unordered_map<std::string, double> &) override;
|
||||
[[nodiscard]] std::unordered_map<std::string, double> getParameters() const override;
|
||||
[[nodiscard]] std::string toString() const override;
|
||||
|
||||
private:
|
||||
double m_chi{0};
|
||||
coordinates::SphericalPos m_prev_pos{0., 0.};
|
||||
};
|
||||
}
|
||||
#endif //RWSIM_MOTIONISOSMALLANGLE_H
|
||||
|
@ -1,19 +1,20 @@
|
||||
|
||||
#include "random.h"
|
||||
|
||||
namespace motions {
|
||||
RandomJump::RandomJump(const double delta, const double eta, std::mt19937_64 &rng) : BaseMotion(std::string("RandomJump"), delta, eta, rng) {}
|
||||
|
||||
RandomJump::RandomJump(const double delta, const double eta, std::mt19937_64 &rng) : Motion(std::string("RandomJump"), delta, eta, rng) {}
|
||||
RandomJump::RandomJump(std::mt19937_64 &rng) : BaseMotion(std::string("RandomJump"), rng) {}
|
||||
|
||||
RandomJump::RandomJump(std::mt19937_64 &rng) : Motion(std::string("RandomJump"), rng) {}
|
||||
std::string RandomJump::toString() const {
|
||||
return {"RandomJump"};
|
||||
}
|
||||
|
||||
std::string RandomJump::toString() const {
|
||||
return {"RandomJump"};
|
||||
}
|
||||
|
||||
void RandomJump::initialize() {
|
||||
m_initial_omega = RandomJump::jump();
|
||||
}
|
||||
|
||||
double RandomJump::jump() {
|
||||
return omega_q(draw_position());
|
||||
void RandomJump::initialize() {
|
||||
m_initial_omega = RandomJump::jump();
|
||||
}
|
||||
|
||||
double RandomJump::jump() {
|
||||
return omega_q(draw_position());
|
||||
}
|
||||
}
|
||||
|
@ -5,15 +5,17 @@
|
||||
#include "base.h"
|
||||
#include <random>
|
||||
|
||||
class RandomJump final : public Motion {
|
||||
public:
|
||||
RandomJump(double, double, std::mt19937_64&);
|
||||
explicit RandomJump(std::mt19937_64&);
|
||||
namespace motions {
|
||||
class RandomJump final : public BaseMotion {
|
||||
public:
|
||||
RandomJump(double, double, std::mt19937_64&);
|
||||
explicit RandomJump(std::mt19937_64&);
|
||||
|
||||
[[nodiscard]] std::string toString() const override;
|
||||
[[nodiscard]] std::string toString() const override;
|
||||
|
||||
void initialize() override;
|
||||
double jump() override;
|
||||
};
|
||||
void initialize() override;
|
||||
double jump() override;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //RWSIM_MOTIONRANDOMJUMP_H
|
||||
|
32
src/motions/rjoac.cpp
Normal file
32
src/motions/rjoac.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
|
||||
#include "rjoac.h"
|
||||
|
||||
namespace motions {
|
||||
RandomJumpOnCone::RandomJumpOnCone(const double delta, const double eta, const double chi, std::mt19937_64 &rng) : BaseMotion("RJ on a Cone", delta, eta, rng), m_angle(chi) {}
|
||||
RandomJumpOnCone::RandomJumpOnCone(std::mt19937_64 &rng) : BaseMotion("RJ on a Cone", rng) {}
|
||||
|
||||
void RandomJumpOnCone::initialize() {
|
||||
m_axis = draw_position();
|
||||
}
|
||||
|
||||
double RandomJumpOnCone::jump() {
|
||||
const double phi = 2 * M_PI * m_uni_dist(m_rng);
|
||||
return omega_q(coordinates::rotate(m_axis, m_angle, phi));
|
||||
}
|
||||
|
||||
void RandomJumpOnCone::setParameters(const std::unordered_map<std::string, double> ¶meters) {
|
||||
BaseMotion::setParameters(parameters);
|
||||
m_angle = parameters.at("angle");
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, double> RandomJumpOnCone::getParameters() const {
|
||||
auto parameter = BaseMotion::getParameters();
|
||||
parameter["angle"] = m_angle;
|
||||
|
||||
return parameter;
|
||||
}
|
||||
|
||||
std::string RandomJumpOnCone::toString() const {
|
||||
return std::string("RandomJumpOnCone/angle=") + std::to_string(m_angle);
|
||||
}
|
||||
}
|
31
src/motions/rjoac.h
Normal file
31
src/motions/rjoac.h
Normal file
@ -0,0 +1,31 @@
|
||||
#ifndef RJOAC_H
|
||||
#define RJOAC_H
|
||||
|
||||
#include "base.h"
|
||||
#include "coordinates.h"
|
||||
|
||||
#include <random>
|
||||
|
||||
namespace motions {
|
||||
class RandomJumpOnCone: public BaseMotion {
|
||||
public:
|
||||
RandomJumpOnCone(double, double, double, std::mt19937_64&);
|
||||
explicit RandomJumpOnCone(std::mt19937_64&);
|
||||
|
||||
void initialize() override;
|
||||
|
||||
double jump() override;
|
||||
|
||||
void setParameters(const std::unordered_map<std::string, double> &) override;
|
||||
|
||||
[[nodiscard]] std::unordered_map<std::string, double> getParameters() const override;
|
||||
|
||||
[[nodiscard]] std::string toString() const override;
|
||||
|
||||
private:
|
||||
double m_angle{0};
|
||||
coordinates::SphericalPos m_axis{1, 0};
|
||||
};
|
||||
}
|
||||
|
||||
#endif //RJOAC_H
|
34
src/motions/sixsitejump.cpp
Normal file
34
src/motions/sixsitejump.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include "sixsitejump.h"
|
||||
#include "coordinates.h"
|
||||
|
||||
namespace motions {
|
||||
SixSiteOctahedron::SixSiteOctahedron(const double delta, const double eta, std::mt19937_64& rng) :
|
||||
BaseMotion(std::string{"SixSiteOctahedral"}, delta, eta, rng) {}
|
||||
|
||||
SixSiteOctahedron::SixSiteOctahedron(std::mt19937_64& rng) : BaseMotion(std::string{"SixSiteOctahedral"}, rng) {}
|
||||
|
||||
void SixSiteOctahedron::initialize() {
|
||||
const auto pos = draw_position();
|
||||
m_corners[0] = omega_q(pos);
|
||||
m_corners[1] = omega_q(rotate(pos, M_PI, 0));
|
||||
|
||||
const double alpha = 2. * M_PI * m_uni_dist(m_rng);
|
||||
|
||||
for (int i = 2; i<6; i++) {
|
||||
auto corner_pos = coordinates::rotate(pos, M_PI_2, alpha + (i-2) * M_PI_2);
|
||||
m_corners[i] = omega_q(corner_pos);
|
||||
}
|
||||
m_initial_omega = SixSiteOctahedron::jump();
|
||||
}
|
||||
|
||||
double SixSiteOctahedron::jump() {
|
||||
m_corner_idx += m_chooser(m_rng);
|
||||
m_corner_idx %= 6;
|
||||
|
||||
return m_corners[m_corner_idx];
|
||||
}
|
||||
|
||||
std::string SixSiteOctahedron::toString() const {
|
||||
return {"SixSiteOctahedral"};
|
||||
}
|
||||
}
|
32
src/motions/sixsitejump.h
Normal file
32
src/motions/sixsitejump.h
Normal file
@ -0,0 +1,32 @@
|
||||
|
||||
#ifndef SIXSITEJUMP_H
|
||||
#define SIXSITEJUMP_H
|
||||
|
||||
#include "base.h"
|
||||
|
||||
#include <random>
|
||||
#include <cmath>
|
||||
#include <array>
|
||||
|
||||
namespace motions {
|
||||
class SixSiteOctahedron final : public BaseMotion {
|
||||
public:
|
||||
SixSiteOctahedron(double, double, std::mt19937_64&);
|
||||
explicit SixSiteOctahedron(std::mt19937_64&);
|
||||
|
||||
void initialize() override;
|
||||
double jump() override;
|
||||
|
||||
[[nodiscard]] std::string toString() const override;
|
||||
|
||||
private:
|
||||
const double m_beta{std::acos(-1/3.)};
|
||||
|
||||
std::array<double, 6> m_corners{};
|
||||
int m_corner_idx{0};
|
||||
|
||||
std::uniform_int_distribution<> m_chooser{1, 5};
|
||||
|
||||
};
|
||||
}
|
||||
#endif //SIXSITEJUMP_H
|
@ -1,34 +0,0 @@
|
||||
#include "tetrahedral.h"
|
||||
|
||||
#include <random>
|
||||
|
||||
#include "tetrahedral.h"
|
||||
|
||||
TetrahedralJump::TetrahedralJump(const double delta, const double eta, std::mt19937_64& rng) :
|
||||
Motion(std::string{"FourSiteTetrahedral"}, delta, eta, rng) {}
|
||||
|
||||
TetrahedralJump::TetrahedralJump(std::mt19937_64& rng) : Motion(std::string{"FourSiteTetrahedral"}, rng) {}
|
||||
|
||||
void TetrahedralJump::initialize() {
|
||||
const auto pos = draw_position();
|
||||
m_corners[0] = omega_q(pos);
|
||||
|
||||
const double alpha = 2. * M_PI * m_uni_dist(m_rng);
|
||||
|
||||
for (int i = 1; i<4; i++) {
|
||||
auto corner_pos = rotate(pos, m_beta, alpha + (i-1) * 2*M_PI/3.);
|
||||
m_corners[i] = omega_q(corner_pos);
|
||||
}
|
||||
m_initial_omega = TetrahedralJump::jump();
|
||||
}
|
||||
|
||||
double TetrahedralJump::jump() {
|
||||
m_corner_idx += m_chooser(m_rng);
|
||||
m_corner_idx %= 4;
|
||||
|
||||
return m_corners[m_corner_idx];
|
||||
}
|
||||
|
||||
std::string TetrahedralJump::toString() const {
|
||||
return {"FourSiteTetrahedral"};
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
#ifndef RWSIM_MOTIONTETRAHEDRAL_H
|
||||
#define RWSIM_MOTIONTETRAHEDRAL_H
|
||||
|
||||
#include "base.h"
|
||||
#include <random>
|
||||
#include <cmath>
|
||||
#include <array>
|
||||
|
||||
class TetrahedralJump final : public Motion {
|
||||
public:
|
||||
TetrahedralJump(double, double, std::mt19937_64&);
|
||||
explicit TetrahedralJump(std::mt19937_64&);
|
||||
|
||||
void initialize() override;
|
||||
double jump() override;
|
||||
|
||||
[[nodiscard]] std::string toString() const override;
|
||||
|
||||
private:
|
||||
const double m_beta{std::acos(-1/3.)};
|
||||
|
||||
std::array<double, 4> m_corners{};
|
||||
int m_corner_idx{0};
|
||||
|
||||
std::uniform_int_distribution<> m_chooser{1, 3};
|
||||
|
||||
};
|
||||
|
||||
#endif //RWSIM_MOTIONTETRAHEDRAL_H
|
Reference in New Issue
Block a user