Use unique_ptr instead of raw pointer
This commit is contained in:
@@ -11,19 +11,16 @@
|
||||
#include "nsiteconejump.h"
|
||||
#include "sixsitejump.h"
|
||||
#include "rjoac.h"
|
||||
#include "conewobble.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
|
||||
|
||||
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.);
|
||||
}
|
||||
BaseMotion::BaseMotion(std::string name, const double delta, const double eta) : m_name(std::move(name)), m_delta(delta), m_eta(eta) {}
|
||||
|
||||
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.);
|
||||
}
|
||||
BaseMotion::BaseMotion(std::string name) : m_name(std::move(name)) {}
|
||||
|
||||
double BaseMotion::omega_q(const double cos_theta, const double phi) const {
|
||||
const double cos_theta_square = cos_theta * cos_theta;
|
||||
@@ -38,34 +35,37 @@ namespace motions {
|
||||
return omega_q(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);
|
||||
coordinates::SphericalPos BaseMotion::draw_position(std::mt19937_64& rng) {
|
||||
const double cos_theta = 1 - 2 * m_uni_dist(rng);
|
||||
const double phi = 2.0 * M_PI * m_uni_dist(rng);
|
||||
|
||||
return {cos_theta, phi};
|
||||
}
|
||||
|
||||
BaseMotion* BaseMotion::createFromInput(const std::string& input, std::mt19937_64& rng) {
|
||||
std::unique_ptr<BaseMotion> BaseMotion::createFromInput(const std::string& input) {
|
||||
if (input == "FourSiteTetrahedral")
|
||||
return new FourSiteTetrahedron(rng);
|
||||
return std::make_unique<FourSiteTetrahedron>();
|
||||
|
||||
if (input == "SixSiteOctahedralC3")
|
||||
return new SixSiteOctahedronC3(rng);
|
||||
return std::make_unique<SixSiteOctahedronC3>();
|
||||
|
||||
if (input == "IsotropicAngle")
|
||||
return new SmallAngle(rng);
|
||||
return std::make_unique<SmallAngle>();
|
||||
|
||||
if (input == "RandomJump")
|
||||
return new RandomJump(rng);
|
||||
return std::make_unique<RandomJump>();
|
||||
|
||||
if (input == "BimodalAngle")
|
||||
return new BimodalAngle(rng);
|
||||
return std::make_unique<BimodalAngle>();
|
||||
|
||||
if (input == "NSiteConeJump")
|
||||
return new NSiteJumpOnCone(rng);
|
||||
return std::make_unique<NSiteJumpOnCone>();
|
||||
|
||||
if (input == "RandomJumpOnCone")
|
||||
return new RandomJumpOnCone(rng);
|
||||
return std::make_unique<RandomJumpOnCone>();
|
||||
|
||||
if (input == "ConeWobble")
|
||||
return std::make_unique<WobbleCone>();
|
||||
|
||||
throw std::invalid_argument("Invalid input " + input);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "coordinates.h"
|
||||
|
||||
#include <memory>
|
||||
#include <random>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -11,15 +12,16 @@ namespace motions {
|
||||
public:
|
||||
virtual ~BaseMotion() = default;
|
||||
|
||||
BaseMotion(std::string, double, double, std::mt19937_64&);
|
||||
explicit BaseMotion(std::string, std::mt19937_64&);
|
||||
BaseMotion(std::string, double, double);
|
||||
explicit BaseMotion(std::string);
|
||||
|
||||
coordinates::SphericalPos draw_position();
|
||||
coordinates::SphericalPos draw_position(std::mt19937_64& rng);
|
||||
[[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(std::mt19937_64& rng) = 0;
|
||||
virtual double jump(std::mt19937_64& rng) = 0;
|
||||
[[nodiscard]] virtual std::unique_ptr<BaseMotion> clone() const = 0;
|
||||
|
||||
virtual void setParameters(const std::unordered_map<std::string, double>&);
|
||||
[[nodiscard]] virtual std::unordered_map<std::string, double> getParameters() const;
|
||||
@@ -32,14 +34,13 @@ namespace motions {
|
||||
|
||||
[[nodiscard]] virtual std::string toString() const = 0;
|
||||
|
||||
static BaseMotion* createFromInput(const std::string& input, std::mt19937_64& rng);
|
||||
static std::unique_ptr<BaseMotion> createFromInput(const std::string& input);
|
||||
|
||||
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;
|
||||
std::uniform_real_distribution<> m_uni_dist{0., 1.};
|
||||
double m_initial_omega{0.};
|
||||
};
|
||||
|
||||
|
||||
@@ -4,26 +4,30 @@
|
||||
#include "coordinates.h"
|
||||
|
||||
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),
|
||||
BimodalAngle::BimodalAngle(const double delta, const double eta, const double angle1, const double angle2, const double prob) :
|
||||
BaseMotion(std::string("BimodalAngle"), delta, eta),
|
||||
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) {}
|
||||
BimodalAngle::BimodalAngle() : BaseMotion(std::string("BimodalAngle")) {}
|
||||
|
||||
void BimodalAngle::initialize() {
|
||||
m_prev_pos = draw_position();
|
||||
void BimodalAngle::initialize(std::mt19937_64& rng) {
|
||||
m_prev_pos = draw_position(rng);
|
||||
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)};
|
||||
double BimodalAngle::jump(std::mt19937_64& rng) {
|
||||
const double angle = m_uni_dist(rng) < m_prob ? m_angle1 : m_angle2;
|
||||
const double gamma{2 * M_PI * m_uni_dist(rng)};
|
||||
m_prev_pos = rotate(m_prev_pos, angle, gamma);
|
||||
|
||||
return omega_q(m_prev_pos);
|
||||
}
|
||||
|
||||
std::unique_ptr<BaseMotion> BimodalAngle::clone() const {
|
||||
return std::make_unique<BimodalAngle>(*this);
|
||||
}
|
||||
|
||||
void BimodalAngle::setParameters(const std::unordered_map<std::string, double> ¶meter) {
|
||||
BaseMotion::setParameters(parameter);
|
||||
|
||||
|
||||
@@ -8,11 +8,12 @@
|
||||
namespace motions {
|
||||
class BimodalAngle final : public BaseMotion {
|
||||
public:
|
||||
BimodalAngle(double, double, double, double, double, std::mt19937_64& );
|
||||
explicit BimodalAngle(std::mt19937_64&);
|
||||
BimodalAngle(double, double, double, double, double);
|
||||
BimodalAngle();
|
||||
|
||||
void initialize() override;
|
||||
double jump() override;
|
||||
void initialize(std::mt19937_64& rng) override;
|
||||
double jump(std::mt19937_64& rng) override;
|
||||
[[nodiscard]] std::unique_ptr<BaseMotion> clone() const 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;
|
||||
|
||||
@@ -2,23 +2,24 @@
|
||||
#include "conewobble.h"
|
||||
#include "coordinates.h"
|
||||
|
||||
#include <random>
|
||||
#include <string>
|
||||
|
||||
namespace motions {
|
||||
WobbleCone::WobbleCone(const double delta, const double eta, const double chi, std::mt19937_64 &rng) : BaseMotion("Wobble in Cone", delta, eta, rng), m_angle(chi) {}
|
||||
WobbleCone::WobbleCone(std::mt19937_64 &rng) : BaseMotion("Wobble in Cone", rng) {}
|
||||
WobbleCone::WobbleCone(const double delta, const double eta, const double chi) : BaseMotion("Wobble in Cone", delta, eta), m_angle(chi) {}
|
||||
WobbleCone::WobbleCone() : BaseMotion("Wobble in Cone") {}
|
||||
|
||||
void WobbleCone::initialize() {
|
||||
m_axis = draw_position();
|
||||
void WobbleCone::initialize(std::mt19937_64& rng) {
|
||||
m_axis = draw_position(rng);
|
||||
}
|
||||
|
||||
double WobbleCone::jump() {
|
||||
const double real_angle = m_uni_dist(m_rng) * m_angle;
|
||||
const double phi = 2 * M_PI * m_uni_dist(m_rng);
|
||||
double WobbleCone::jump(std::mt19937_64& rng) {
|
||||
const double real_angle = m_uni_dist(rng) * m_angle;
|
||||
const double phi = 2 * M_PI * m_uni_dist(rng);
|
||||
return omega_q(rotate(m_axis, real_angle, phi));
|
||||
}
|
||||
|
||||
std::unique_ptr<BaseMotion> WobbleCone::clone() const {
|
||||
return std::make_unique<WobbleCone>(*this);
|
||||
}
|
||||
|
||||
void WobbleCone::setParameters(const std::unordered_map<std::string, double> ¶meters) {
|
||||
BaseMotion::setParameters(parameters);
|
||||
m_angle = parameters.at("angle");
|
||||
@@ -34,4 +35,4 @@ namespace motions {
|
||||
std::string WobbleCone::toString() const {
|
||||
return std::string("ConeWobble/angle=") + std::to_string(m_angle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,22 +4,18 @@
|
||||
#include "base.h"
|
||||
#include "coordinates.h"
|
||||
|
||||
#include <random>
|
||||
|
||||
namespace motions {
|
||||
class WobbleCone final: public BaseMotion {
|
||||
public:
|
||||
WobbleCone(double, double, double, std::mt19937_64&);
|
||||
explicit WobbleCone(std::mt19937_64&);
|
||||
WobbleCone(double, double, double);
|
||||
WobbleCone();
|
||||
|
||||
void initialize() override;
|
||||
|
||||
double jump() override;
|
||||
void initialize(std::mt19937_64& rng) override;
|
||||
double jump(std::mt19937_64& rng) override;
|
||||
[[nodiscard]] std::unique_ptr<BaseMotion> clone() const 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:
|
||||
|
||||
@@ -1,35 +1,37 @@
|
||||
#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(const double delta, const double eta) :
|
||||
BaseMotion(std::string{"FourSiteTetrahedral"}, delta, eta) {}
|
||||
|
||||
FourSiteTetrahedron::FourSiteTetrahedron(std::mt19937_64& rng) : BaseMotion(std::string{"FourSiteTetrahedral"}, rng) {}
|
||||
FourSiteTetrahedron::FourSiteTetrahedron() : BaseMotion(std::string{"FourSiteTetrahedral"}) {}
|
||||
|
||||
void FourSiteTetrahedron::initialize() {
|
||||
const auto pos = draw_position();
|
||||
void FourSiteTetrahedron::initialize(std::mt19937_64& rng) {
|
||||
const auto pos = draw_position(rng);
|
||||
m_corners[0] = omega_q(pos);
|
||||
|
||||
const double alpha = 2. * M_PI * m_uni_dist(m_rng);
|
||||
const double alpha = 2. * M_PI * m_uni_dist(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 = FourSiteTetrahedron::jump();
|
||||
m_initial_omega = FourSiteTetrahedron::jump(rng);
|
||||
}
|
||||
|
||||
double FourSiteTetrahedron::jump() {
|
||||
m_corner_idx += m_chooser(m_rng);
|
||||
double FourSiteTetrahedron::jump(std::mt19937_64& rng) {
|
||||
m_corner_idx += m_chooser(rng);
|
||||
m_corner_idx %= 4;
|
||||
|
||||
return m_corners[m_corner_idx];
|
||||
}
|
||||
|
||||
std::unique_ptr<BaseMotion> FourSiteTetrahedron::clone() const {
|
||||
return std::make_unique<FourSiteTetrahedron>(*this);
|
||||
}
|
||||
|
||||
std::string FourSiteTetrahedron::toString() const {
|
||||
return {"FourSiteTetrahedral"};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,18 +3,18 @@
|
||||
|
||||
#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&);
|
||||
FourSiteTetrahedron(double, double);
|
||||
FourSiteTetrahedron();
|
||||
|
||||
void initialize() override;
|
||||
double jump() override;
|
||||
void initialize(std::mt19937_64& rng) override;
|
||||
double jump(std::mt19937_64& rng) override;
|
||||
[[nodiscard]] std::unique_ptr<BaseMotion> clone() const override;
|
||||
|
||||
[[nodiscard]] std::string toString() const override;
|
||||
|
||||
|
||||
@@ -1,26 +1,28 @@
|
||||
#include "isosmallangle.h"
|
||||
#include "coordinates.h"
|
||||
|
||||
#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) :
|
||||
BaseMotion(std::string("IsotropicAngle"), delta, eta), m_chi(chi * M_PI / 180.0) {}
|
||||
SmallAngle::SmallAngle() : BaseMotion(std::string("IsotropicAngle")) {}
|
||||
|
||||
void SmallAngle::initialize() {
|
||||
m_prev_pos = draw_position();
|
||||
void SmallAngle::initialize(std::mt19937_64& rng) {
|
||||
m_prev_pos = draw_position(rng);
|
||||
m_initial_omega = omega_q(m_prev_pos);
|
||||
}
|
||||
|
||||
double SmallAngle::jump() {
|
||||
const double gamma{2 * M_PI * m_uni_dist(m_rng)};
|
||||
double SmallAngle::jump(std::mt19937_64& rng) {
|
||||
const double gamma{2 * M_PI * m_uni_dist(rng)};
|
||||
m_prev_pos = rotate(m_prev_pos, m_chi, gamma);
|
||||
|
||||
return omega_q(m_prev_pos);
|
||||
}
|
||||
|
||||
std::unique_ptr<BaseMotion> SmallAngle::clone() const {
|
||||
return std::make_unique<SmallAngle>(*this);
|
||||
}
|
||||
|
||||
void SmallAngle::setParameters(const std::unordered_map<std::string, double> ¶meters) {
|
||||
m_chi = parameters.at("angle") * M_PI / 180.0;
|
||||
BaseMotion::setParameters(parameters);
|
||||
|
||||
@@ -8,11 +8,12 @@
|
||||
namespace motions {
|
||||
class SmallAngle final : public BaseMotion {
|
||||
public:
|
||||
SmallAngle(double, double, double, std::mt19937_64& );
|
||||
explicit SmallAngle(std::mt19937_64&);
|
||||
SmallAngle(double, double, double);
|
||||
SmallAngle();
|
||||
|
||||
void initialize() override;
|
||||
double jump() override;
|
||||
void initialize(std::mt19937_64& rng) override;
|
||||
double jump(std::mt19937_64& rng) override;
|
||||
[[nodiscard]] std::unique_ptr<BaseMotion> clone() const 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;
|
||||
|
||||
@@ -1,43 +1,42 @@
|
||||
//
|
||||
// Created by dominik on 12/14/24.
|
||||
//
|
||||
|
||||
#include "nsiteconejump.h"
|
||||
#include "coordinates.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
|
||||
namespace motions {
|
||||
NSiteJumpOnCone::NSiteJumpOnCone(const double delta, const double eta, const int num_sites, const double chi, std::mt19937_64 &rng) :
|
||||
BaseMotion("NSiteJumpOnCone", delta, eta, rng),
|
||||
NSiteJumpOnCone::NSiteJumpOnCone(const double delta, const double eta, const int num_sites, const double chi) :
|
||||
BaseMotion("NSiteJumpOnCone", delta, eta),
|
||||
m_num_sites(num_sites),
|
||||
m_chi(chi*M_PI/180.) {}
|
||||
|
||||
NSiteJumpOnCone::NSiteJumpOnCone(std::mt19937_64 &rng) : BaseMotion("NSiteJumpOnCone", rng) { }
|
||||
NSiteJumpOnCone::NSiteJumpOnCone() : BaseMotion("NSiteJumpOnCone") { }
|
||||
|
||||
void NSiteJumpOnCone::initialize() {
|
||||
void NSiteJumpOnCone::initialize(std::mt19937_64& rng) {
|
||||
m_sites = std::vector<double>(m_num_sites);
|
||||
m_chooser = std::uniform_int_distribution<>{1, m_num_sites - 1};
|
||||
|
||||
m_axis = draw_position();
|
||||
m_axis = draw_position(rng);
|
||||
|
||||
const double alpha = m_uni_dist(m_rng) * 2 * M_PI;
|
||||
const double alpha = m_uni_dist(rng) * 2 * M_PI;
|
||||
const double steps = 2*M_PI / m_num_sites;
|
||||
for (int i = 0; i < m_num_sites; i++) {
|
||||
m_sites[i] = omega_q(rotate(m_axis, m_chi, i * steps + alpha));
|
||||
}
|
||||
}
|
||||
|
||||
double NSiteJumpOnCone::jump() {
|
||||
m_cone_idx += m_chooser(m_rng);
|
||||
double NSiteJumpOnCone::jump(std::mt19937_64& rng) {
|
||||
m_cone_idx += m_chooser(rng);
|
||||
m_cone_idx %= m_num_sites;
|
||||
|
||||
return m_sites[m_cone_idx];
|
||||
}
|
||||
|
||||
std::unique_ptr<BaseMotion> NSiteJumpOnCone::clone() const {
|
||||
return std::make_unique<NSiteJumpOnCone>(*this);
|
||||
}
|
||||
|
||||
void NSiteJumpOnCone::setParameters(const std::unordered_map<std::string, double> ¶meters) {
|
||||
BaseMotion::setParameters(parameters);
|
||||
m_num_sites = static_cast<int>(parameters.at("num_sites"));
|
||||
@@ -56,4 +55,4 @@ namespace motions {
|
||||
return std::to_string(m_num_sites) + "SiteJumpOnCone/angle=" + std::to_string(m_chi*180/M_PI);
|
||||
}
|
||||
|
||||
} // motions
|
||||
} // motions
|
||||
|
||||
@@ -3,17 +3,17 @@
|
||||
|
||||
#include "base.h"
|
||||
|
||||
#include <random>
|
||||
#include <vector>
|
||||
|
||||
namespace motions {
|
||||
class NSiteJumpOnCone final : public BaseMotion {
|
||||
public:
|
||||
NSiteJumpOnCone(double, double, int, double, std::mt19937_64&);
|
||||
explicit NSiteJumpOnCone(std::mt19937_64&);
|
||||
NSiteJumpOnCone(double, double, int, double);
|
||||
NSiteJumpOnCone();
|
||||
|
||||
void initialize() override;
|
||||
double jump() override;
|
||||
void initialize(std::mt19937_64& rng) override;
|
||||
double jump(std::mt19937_64& rng) override;
|
||||
[[nodiscard]] std::unique_ptr<BaseMotion> clone() const override;
|
||||
|
||||
[[nodiscard]] std::string toString() const override;
|
||||
|
||||
|
||||
@@ -2,19 +2,23 @@
|
||||
#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) : BaseMotion(std::string("RandomJump"), delta, eta) {}
|
||||
|
||||
RandomJump::RandomJump(std::mt19937_64 &rng) : BaseMotion(std::string("RandomJump"), rng) {}
|
||||
RandomJump::RandomJump() : BaseMotion(std::string("RandomJump")) {}
|
||||
|
||||
std::string RandomJump::toString() const {
|
||||
return {"RandomJump"};
|
||||
}
|
||||
|
||||
void RandomJump::initialize() {
|
||||
m_initial_omega = RandomJump::jump();
|
||||
std::unique_ptr<BaseMotion> RandomJump::clone() const {
|
||||
return std::make_unique<RandomJump>(*this);
|
||||
}
|
||||
|
||||
double RandomJump::jump() {
|
||||
return omega_q(draw_position());
|
||||
void RandomJump::initialize(std::mt19937_64& rng) {
|
||||
m_initial_omega = RandomJump::jump(rng);
|
||||
}
|
||||
|
||||
double RandomJump::jump(std::mt19937_64& rng) {
|
||||
return omega_q(draw_position(rng));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,18 +3,18 @@
|
||||
|
||||
|
||||
#include "base.h"
|
||||
#include <random>
|
||||
|
||||
namespace motions {
|
||||
class RandomJump final : public BaseMotion {
|
||||
public:
|
||||
RandomJump(double, double, std::mt19937_64&);
|
||||
explicit RandomJump(std::mt19937_64&);
|
||||
RandomJump(double, double);
|
||||
RandomJump();
|
||||
|
||||
[[nodiscard]] std::string toString() const override;
|
||||
[[nodiscard]] std::unique_ptr<BaseMotion> clone() const override;
|
||||
|
||||
void initialize() override;
|
||||
double jump() override;
|
||||
void initialize(std::mt19937_64& rng) override;
|
||||
double jump(std::mt19937_64& rng) override;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -2,18 +2,22 @@
|
||||
#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) {}
|
||||
RandomJumpOnCone::RandomJumpOnCone(const double delta, const double eta, const double chi) : BaseMotion("RJ on a Cone", delta, eta), m_angle(chi) {}
|
||||
RandomJumpOnCone::RandomJumpOnCone() : BaseMotion("RJ on a Cone") {}
|
||||
|
||||
void RandomJumpOnCone::initialize() {
|
||||
m_axis = draw_position();
|
||||
void RandomJumpOnCone::initialize(std::mt19937_64& rng) {
|
||||
m_axis = draw_position(rng);
|
||||
}
|
||||
|
||||
double RandomJumpOnCone::jump() {
|
||||
const double phi = 2 * M_PI * m_uni_dist(m_rng);
|
||||
double RandomJumpOnCone::jump(std::mt19937_64& rng) {
|
||||
const double phi = 2 * M_PI * m_uni_dist(rng);
|
||||
return omega_q(rotate(m_axis, m_angle, phi));
|
||||
}
|
||||
|
||||
std::unique_ptr<BaseMotion> RandomJumpOnCone::clone() const {
|
||||
return std::make_unique<RandomJumpOnCone>(*this);
|
||||
}
|
||||
|
||||
void RandomJumpOnCone::setParameters(const std::unordered_map<std::string, double> ¶meters) {
|
||||
BaseMotion::setParameters(parameters);
|
||||
m_angle = parameters.at("angle");
|
||||
@@ -29,4 +33,4 @@ namespace motions {
|
||||
std::string RandomJumpOnCone::toString() const {
|
||||
return std::string("RandomJumpOnCone/angle=") + std::to_string(m_angle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,22 +4,18 @@
|
||||
#include "base.h"
|
||||
#include "coordinates.h"
|
||||
|
||||
#include <random>
|
||||
|
||||
namespace motions {
|
||||
class RandomJumpOnCone final: public BaseMotion {
|
||||
public:
|
||||
RandomJumpOnCone(double, double, double, std::mt19937_64&);
|
||||
explicit RandomJumpOnCone(std::mt19937_64&);
|
||||
RandomJumpOnCone(double, double, double);
|
||||
RandomJumpOnCone();
|
||||
|
||||
void initialize() override;
|
||||
|
||||
double jump() override;
|
||||
void initialize(std::mt19937_64& rng) override;
|
||||
double jump(std::mt19937_64& rng) override;
|
||||
[[nodiscard]] std::unique_ptr<BaseMotion> clone() const 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:
|
||||
|
||||
@@ -1,21 +1,17 @@
|
||||
#include "sixsitejump.h"
|
||||
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
||||
#include "coordinates.h"
|
||||
|
||||
namespace motions {
|
||||
SixSiteOctahedronC3::SixSiteOctahedronC3(const double delta, const double eta, const double chi, std::mt19937_64& rng) :
|
||||
m_chi{chi*M_PI/180.},
|
||||
BaseMotion(std::string{"SixSiteOctahedral"}, delta, eta, rng) {}
|
||||
SixSiteOctahedronC3::SixSiteOctahedronC3(const double delta, const double eta, const double chi) :
|
||||
BaseMotion(std::string{"SixSiteOctahedral"}, delta, eta),
|
||||
m_chi{chi*M_PI/180.} {}
|
||||
|
||||
SixSiteOctahedronC3::SixSiteOctahedronC3(std::mt19937_64& rng) : BaseMotion(std::string{"SixSiteOctahedralC3"}, rng) {}
|
||||
SixSiteOctahedronC3::SixSiteOctahedronC3() : BaseMotion(std::string{"SixSiteOctahedralC3"}) {}
|
||||
|
||||
void SixSiteOctahedronC3::initialize() {
|
||||
const coordinates::SphericalPos c3_axis = draw_position();
|
||||
const auto [x, y, z] = spherical_to_xyz(c3_axis);
|
||||
const double alpha = 2. * M_PI * m_uni_dist(m_rng);
|
||||
void SixSiteOctahedronC3::initialize(std::mt19937_64& rng) {
|
||||
const coordinates::SphericalPos c3_axis = draw_position(rng);
|
||||
const double alpha = 2. * M_PI * m_uni_dist(rng);
|
||||
|
||||
const double m_chi_opposite = M_PI - m_chi;
|
||||
|
||||
@@ -24,17 +20,21 @@ namespace motions {
|
||||
m_corners[2*i+1] = omega_q(rotate(c3_axis, m_chi_opposite, alpha + i * 2./3.*M_PI + M_PI/3.));
|
||||
}
|
||||
|
||||
m_initial_omega = SixSiteOctahedronC3::jump();
|
||||
m_initial_omega = SixSiteOctahedronC3::jump(rng);
|
||||
}
|
||||
|
||||
|
||||
double SixSiteOctahedronC3::jump() {
|
||||
m_corner_idx += m_chooser(m_rng);
|
||||
double SixSiteOctahedronC3::jump(std::mt19937_64& rng) {
|
||||
m_corner_idx += m_chooser(rng);
|
||||
m_corner_idx %= 6;
|
||||
|
||||
return m_corners[m_corner_idx];
|
||||
}
|
||||
|
||||
std::unique_ptr<BaseMotion> SixSiteOctahedronC3::clone() const {
|
||||
return std::make_unique<SixSiteOctahedronC3>(*this);
|
||||
}
|
||||
|
||||
std::string SixSiteOctahedronC3::toString() const {
|
||||
return {"SixSiteOctahedral/angle=" + std::to_string(m_chi / M_PI * 180.)};
|
||||
}
|
||||
|
||||
@@ -4,23 +4,23 @@
|
||||
|
||||
#include "base.h"
|
||||
|
||||
#include <random>
|
||||
#include <cmath>
|
||||
#include <array>
|
||||
|
||||
namespace motions {
|
||||
class SixSiteOctahedronC3 final : public BaseMotion {
|
||||
public:
|
||||
SixSiteOctahedronC3(double, double, double, std::mt19937_64&);
|
||||
explicit SixSiteOctahedronC3(std::mt19937_64&);
|
||||
SixSiteOctahedronC3(double, double, double);
|
||||
SixSiteOctahedronC3();
|
||||
|
||||
void initialize() override;
|
||||
double jump() override;
|
||||
void initialize(std::mt19937_64& rng) override;
|
||||
double jump(std::mt19937_64& rng) override;
|
||||
[[nodiscard]] std::unique_ptr<BaseMotion> clone() const override;
|
||||
|
||||
[[nodiscard]] std::string toString() const override;
|
||||
|
||||
private:
|
||||
const double m_chi{0.95531661812450927816385710251575775424341469501000549095969812932191204590}; // 54.74 deg
|
||||
double m_chi{0.95531661812450927816385710251575775424341469501000549095969812932191204590}; // 54.74 deg
|
||||
|
||||
std::array<double, 6> m_corners{};
|
||||
int m_corner_idx{0};
|
||||
|
||||
Reference in New Issue
Block a user