first commit
This commit is contained in:
31
motions/base.cpp
Normal file
31
motions/base.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
//
|
||||
// Created by dominik on 8/12/24.
|
||||
//
|
||||
|
||||
#include <cmath>
|
||||
#include <random>
|
||||
|
||||
#include "base.h"
|
||||
|
||||
Motion::Motion(const double delta, const double eta, std::mt19937_64& rng) : 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) {
|
||||
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;
|
||||
|
||||
return M_PI * m_delta * (3 * cos_theta_square - 1 - m_eta * sin_theta_square * cos(2.*phi));
|
||||
}
|
||||
|
||||
double 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);
|
||||
}
|
||||
|
35
motions/base.h
Normal file
35
motions/base.h
Normal file
@ -0,0 +1,35 @@
|
||||
//
|
||||
// Created by dominik on 8/12/24.
|
||||
//
|
||||
|
||||
#ifndef RWSIM_MOTIONBASE_H
|
||||
#define RWSIM_MOTIONBASE_H
|
||||
|
||||
|
||||
#include <random>
|
||||
|
||||
class Motion {
|
||||
public:
|
||||
virtual ~Motion() = default;
|
||||
|
||||
Motion(double, double, std::mt19937_64&);
|
||||
explicit Motion(std::mt19937_64&);
|
||||
|
||||
double draw_position();
|
||||
[[nodiscard]] double omega_q(double, double) const;
|
||||
|
||||
virtual double jump() = 0;
|
||||
|
||||
[[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; }
|
||||
|
||||
private:
|
||||
double m_delta{1.};
|
||||
double m_eta{0.};
|
||||
std::mt19937_64& m_rng;
|
||||
std::uniform_real_distribution<double> m_uni_dist;
|
||||
};
|
||||
|
||||
#endif //RWSIM_MOTIONBASE_H
|
14
motions/random.cpp
Normal file
14
motions/random.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
//
|
||||
// Created by dominik on 8/12/24.
|
||||
//
|
||||
|
||||
#include "random.h"
|
||||
|
||||
|
||||
RandomJump::RandomJump(const double delta, const double eta, std::mt19937_64 &rng) : Motion(delta, eta, rng) {}
|
||||
|
||||
RandomJump::RandomJump(std::mt19937_64 &rng) : Motion(rng) {}
|
||||
|
||||
double RandomJump::jump() {
|
||||
return draw_position();
|
||||
}
|
19
motions/random.h
Normal file
19
motions/random.h
Normal file
@ -0,0 +1,19 @@
|
||||
//
|
||||
// Created by dominik on 8/12/24.
|
||||
//
|
||||
|
||||
#ifndef RWSIM_MOTIONRANDOMJUMP_H
|
||||
#define RWSIM_MOTIONRANDOMJUMP_H
|
||||
|
||||
|
||||
#include "base.h"
|
||||
#include <random>
|
||||
class RandomJump final : public Motion {
|
||||
public:
|
||||
RandomJump(double, double, std::mt19937_64&);
|
||||
explicit RandomJump(std::mt19937_64&);
|
||||
|
||||
double jump() override;
|
||||
};
|
||||
|
||||
#endif //RWSIM_MOTIONRANDOMJUMP_H
|
14
motions/tetrahedral.cpp
Normal file
14
motions/tetrahedral.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
//
|
||||
// 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(std::mt19937_64& rng) : Motion(rng) {}
|
||||
|
||||
double TetrahedralJump::jump() {
|
||||
return draw_position();
|
||||
}
|
20
motions/tetrahedral.h
Normal file
20
motions/tetrahedral.h
Normal file
@ -0,0 +1,20 @@
|
||||
//
|
||||
// Created by dominik on 8/16/24.
|
||||
//
|
||||
|
||||
#ifndef RWSIM_MOTIONTETRAHEDRAL_H
|
||||
#define RWSIM_MOTIONTETRAHEDRAL_H
|
||||
|
||||
#include "base.h"
|
||||
#include <random>
|
||||
|
||||
class TetrahedralJump final : public Motion {
|
||||
public:
|
||||
TetrahedralJump(double, double, std::mt19937_64&);
|
||||
explicit TetrahedralJump(std::mt19937_64&);
|
||||
|
||||
double jump() override;
|
||||
};
|
||||
|
||||
|
||||
#endif //RWSIM_MOTIONTETRAHEDRAL_H
|
Reference in New Issue
Block a user