fixed problem in spherical_to_xyz

This commit is contained in:
Dominik Demuth
2024-08-20 17:51:49 +02:00
parent 4b2d0da295
commit 1b721978be
10 changed files with 228 additions and 140 deletions

View File

@ -9,6 +9,9 @@
#include "base.h"
#include <iostream>
#include <ostream>
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.);
@ -22,7 +25,7 @@ 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 * std::cos(2.*phi));
return M_PI * m_delta * (3. * cos_theta_square - 1. - m_eta * sin_theta_square * std::cos(2.*phi));
}
std::pair<double, double> Motion::draw_position() {

View File

@ -4,51 +4,50 @@
#include <random>
#include "tetrahedral.h"
#include <iostream>
#include <ostream>
#include "../functions.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) {}
void TetrahedralJump::initialize() {
// const auto [cos_theta, phi] = draw_position();
//
// m_corners[0] = omega_q(cos_theta, phi);
//
// const double alpha = 2. * M_PI * m_uni_dist(m_rng);
// std::cout << alpha << std::endl;
const auto [cos_theta, phi] = draw_position();
m_corners[0] = omega_q(cos_theta, phi);
const double alpha = 2. * M_PI * m_uni_dist(m_rng);
// v1[0] = sin(phi0)*sin(teta0);
// v2[0] = cos(phi0)*sin(teta0);
// v3[0] = cos(teta0);
//
// abs = v1[0]*v1[0]+v2[0]*v2[0]+v3[0]*v3[0]; // Normalization
// v1[0] = v1[0]/abs;
// v2[0] = v2[0]/abs;
// v3[0] = v3[0]/abs;
//
// /*Calculating the components of the other orientationts. Compare Master Thesis M. Sattig,corrected Version (Share/Abschlussarbeiten)*/
// norm = sqrt(1 - v3[0]*v3[0])+1E-12;
// normI = 1.0/(norm);
//
// cosgama = cos(delta0);
// singama = sin(delta0);
// v1[1] = v1[0]*cosBETA + sinBETA*normI*(-v1[0]*v3[0]*singama - v2[0]*cosgama);
// v2[1] = v2[0]*cosBETA + sinBETA*normI*(-v2[0]*v3[0]*singama + v1[0]*cosgama);
// v3[1] = v3[0]*cosBETA + sinBETA*norm*singama;
//
// cosgama = cos(gama + delta0);
// singama = sin(gama + delta0);
// v1[2] = v1[0]*cosBETA + sinBETA*normI*(-v1[0]*v3[0]*singama - v2[0]*cosgama);
// v2[2] = v2[0]*cosBETA + sinBETA*normI*(-v2[0]*v3[0]*singama + v1[0]*cosgama);
// v3[2] = v3[0]*cosBETA + sinBETA*norm*singama;
//
// cosgama = cos(2.0*gama + delta0);
// singama = sin(2.0*gama + delta0);
// v1[3] = v1[0]*cosBETA + sinBETA*normI*(-v1[0]*v3[0]*singama - v2[0]*cosgama);
// v2[3] = v2[0]*cosBETA + sinBETA*normI*(-v2[0]*v3[0]*singama + v1[0]*cosgama);
// v3[3] = v3[0]*cosBETA + sinBETA*norm*singama;
const auto vec = spherical_to_xyz(cos_theta, phi);
const double norm = std::sqrt(1 - cos_theta * cos_theta) + 1e-15;
for (int i = 1; i<4; i++) {
const double cos_alpha = std::cos(alpha + (i-1) * 2*M_PI / 3.);
const double sin_alpha = std::sin(alpha + (i-1) * 2*M_PI / 3.);
std::array<double, 3> rotated_position{};
if (cos_theta != 1 && cos_theta != -1) {
// std::cout << cos_theta << std::endl;
rotated_position = {
0*m_cos_beta * vec[0] + m_sin_beta * (-vec[0] * vec[2] * sin_alpha - vec[1] * cos_alpha) / norm,
0*m_cos_beta * vec[1] + m_sin_beta * (-vec[1] * vec[2] * sin_alpha + vec[0] * cos_alpha) / norm,
m_cos_beta * vec[2] + m_sin_beta * norm * sin_alpha
};
} else {
rotated_position = {
m_sin_beta * cos_alpha,
m_sin_beta * sin_alpha,
m_cos_beta * cos_theta
};
}
auto [new_cos_theta, new_phi] = xyz_to_spherical(rotated_position);
m_corners[i] = omega_q(new_cos_theta, new_phi);
}
}
double TetrahedralJump::jump() {
return 0.;
m_corner_idx += m_chooser(m_rng);
m_corner_idx %= 4;
return m_corners[m_corner_idx];
}

View File

@ -20,7 +20,14 @@ public:
private:
const double m_beta{std::acos(-1/3.)};
const double m_cos_beta{-1./3.};
const double m_sin_beta{ 2. * std::sqrt(2.)/3. };
std::array<double, 4> m_corners{};
int m_corner_idx{0};
std::uniform_int_distribution<> m_chooser{1, 3};
};