cpp/motions/base.cpp

73 lines
1.9 KiB
C++
Raw Normal View History

2024-08-16 17:55:27 +00:00
//
// Created by dominik on 8/12/24.
//
#include <random>
2024-08-18 11:21:27 +00:00
#include <cmath>
2024-08-16 17:55:27 +00:00
#include "base.h"
#include <stdexcept>
#include <utility>
#include "coordinates.h"
#include "bimodalangle.h"
#include "isosmallangle.h"
#include "random.h"
#include "tetrahedral.h"
2024-08-18 11:21:27 +00:00
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) {
2024-08-16 17:55:27 +00:00
m_uni_dist = std::uniform_real_distribution(0., 1.);
}
Motion::Motion(std::string name, std::mt19937_64& rng) : m_name(std::move(name)), m_rng(rng) {
2024-08-16 17:55:27 +00:00
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;
2024-08-20 15:51:49 +00:00
return M_PI * m_delta * (3. * cos_theta_square - 1. - m_eta * sin_theta_square * std::cos(2.*phi));
2024-08-16 17:55:27 +00:00
}
2024-08-23 16:33:38 +00:00
double Motion::omega_q(const SphericalPos& pos) const {
auto [cos_theta, phi] = pos;
2024-08-16 17:55:27 +00:00
2024-08-23 16:33:38 +00:00
return omega_q(cos_theta, phi);
2024-08-16 17:55:27 +00:00
}
2024-08-23 16:33:38 +00:00
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 {cos_theta, phi};
2024-09-16 17:52:51 +00:00
}
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);
}
2024-11-10 14:52:54 +00:00
void Motion::setParameters(const std::unordered_map<std::string, double> &parameters) {
m_delta = parameters.at("delta");
m_eta = parameters.at("eta");
}
std::ostream& operator<<(std::ostream& os, const Motion& m) {
os << m.getName();
return os;
}