Version 2, position dependent E/B, kinetic ions, boris mover, terminator
This commit is contained in:
Executable
+169
@@ -0,0 +1,169 @@
|
||||
#include "simulation/kinematic.h"
|
||||
#include "blitz/array.h"
|
||||
#include "constants/physical_constants.h"
|
||||
|
||||
namespace kinematic {
|
||||
|
||||
blitz::TinyVector<double, 3> velocityOfCenterOfMass(
|
||||
const blitz::TinyVector<double, 3>& velocity_1,
|
||||
const blitz::TinyVector<double, 3>& velocity_2,
|
||||
double mass_1,
|
||||
double mass_2) {
|
||||
return blitz::TinyVector<double, 3>(
|
||||
(mass_1 * velocity_1 + mass_2 * velocity_2) / (mass_1 + mass_2));
|
||||
}
|
||||
|
||||
blitz::TinyVector<double, 3> velocityTargetFixed(
|
||||
const blitz::TinyVector<double, 3>& velocity_1,
|
||||
const blitz::TinyVector<double, 3>& velocity_2,
|
||||
double mass_1,
|
||||
double mass_2) {
|
||||
return blitz::TinyVector<double, 3>(velocity_1 - velocity_2);
|
||||
};
|
||||
|
||||
blitz::TinyVector<double, 3> rotateVector(const blitz::TinyVector<double, 3>& v,
|
||||
double theta,
|
||||
double phi) {
|
||||
const double norm_value(norm(v));
|
||||
if (norm_value == 0) {
|
||||
return v;
|
||||
}
|
||||
const blitz::TinyVector<double, 3> n = v / norm_value;
|
||||
const double s = std::sqrt(1 - n(2) * n(2));
|
||||
if (s != 0) {
|
||||
const double vx =
|
||||
-(n(0) * n(2) / s * std::cos(phi) - n(1) / s * std::sin(phi)) *
|
||||
std::sin(theta) +
|
||||
n(0) * std::cos(theta);
|
||||
const double vy =
|
||||
-(n(1) * n(2) / s * std::cos(phi) + n(0) / s * std::sin(phi)) *
|
||||
std::sin(theta) +
|
||||
n(1) * std::cos(theta);
|
||||
const double vz =
|
||||
s * (std::sin(theta) * std::cos(phi)) + n(2) * std::cos(theta);
|
||||
return blitz::TinyVector<double, 3>(vx, vy, vz) * norm_value;
|
||||
} else {
|
||||
const double vx = std::sin(theta) * std::cos(phi);
|
||||
const double vy = std::sin(theta) * std::sin(phi);
|
||||
const double vz = std::cos(theta);
|
||||
return blitz::TinyVector<double, 3>(vx, vy, vz) * norm_value;
|
||||
}
|
||||
}
|
||||
|
||||
blitz::TinyVector<double, 3> rotateVelocityInCenterOfMassFrame(
|
||||
const blitz::TinyVector<double, 3>& velocity_1,
|
||||
const blitz::TinyVector<double, 3>& velocity_2,
|
||||
double mass_1,
|
||||
double mass_2,
|
||||
double theta,
|
||||
double phi) {
|
||||
const blitz::TinyVector<double, 3> v_center_of_mass =
|
||||
velocityOfCenterOfMass(velocity_1, velocity_2, mass_1, mass_2);
|
||||
const blitz::TinyVector<double, 3> v1_in_center_of_mass_frame =
|
||||
velocity_1 - v_center_of_mass;
|
||||
const blitz::TinyVector<double, 3> v1_rot_in_center_of_mass_frame =
|
||||
rotateVector(v1_in_center_of_mass_frame, theta, phi);
|
||||
return v1_rot_in_center_of_mass_frame + v_center_of_mass;
|
||||
}
|
||||
|
||||
double norm(const blitz::TinyVector<double, 3>& vector) {
|
||||
return std::sqrt(blitz::dot(vector, vector));
|
||||
}
|
||||
|
||||
double distanceInCylinder(const blitz::TinyVector<double, 3>& position_1,
|
||||
const blitz::TinyVector<double, 3>& position_2) {
|
||||
return std::sqrt(std::pow(position_1(0), 2) + std::pow(position_2(0), 2) -
|
||||
2 * position_1(0) * position_2(0) *
|
||||
std::cos(position_1(1) - position_2(1)) +
|
||||
std::pow(position_1(2) - position_2(2), 2));
|
||||
}
|
||||
|
||||
double kineticEnergy(const blitz::TinyVector<double, 3>& velocity,
|
||||
double mass) {
|
||||
return blitz::dot(velocity, velocity) * mass / 2.;
|
||||
}
|
||||
|
||||
double thermalEnergy(double temperature_K) {
|
||||
return temperature_K * UnitConversion::KToeV;
|
||||
}
|
||||
|
||||
double velocity(double energy_eV, double mass_kg) {
|
||||
return std::sqrt(2 * energy_eV / (UnitConversion::JouleToeV * mass_kg));
|
||||
}
|
||||
|
||||
double relativisticGamma(const blitz::TinyVector<double, 3>& velocity) {
|
||||
return std::sqrt(1. + blitz::dot(velocity, velocity) / std::pow(SI::c, 2));
|
||||
}
|
||||
|
||||
double relativisticGamma(double kin_energy_eV, double mass_eV) {
|
||||
return 1 + kin_energy_eV / mass_eV;
|
||||
}
|
||||
|
||||
double relativisticBeta(double velocity_ms) {
|
||||
return velocity_ms / SI::c;
|
||||
}
|
||||
|
||||
double relativisticBeta(double kin_energy_eV, double mass_eV) {
|
||||
const double gamma = relativisticGamma(kin_energy_eV, mass_eV);
|
||||
return std::sqrt(1 - std::pow(1 / gamma, 2));
|
||||
}
|
||||
|
||||
double relativisticMomentum(double energy_eV, double mass_eV) {
|
||||
return std::sqrt(energy_eV * energy_eV + 2.0 * energy_eV * mass_eV);
|
||||
}
|
||||
|
||||
blitz::TinyVector<double, 3> velocityVector(
|
||||
double energy_eV,
|
||||
const blitz::TinyVector<double, 3>& random_unit_vector,
|
||||
double mass_kg) {
|
||||
if (energy_eV <= 0.) {
|
||||
return blitz::TinyVector<double, 3>(0., 0., 0.);
|
||||
} else {
|
||||
return random_unit_vector * kinematic::velocity(energy_eV, mass_kg);
|
||||
}
|
||||
}
|
||||
|
||||
blitz::TinyVector<double, 3> relativisticBoost(
|
||||
const blitz::TinyVector<double, 3>& v1,
|
||||
const blitz::TinyVector<double, 3>& v2) {
|
||||
const blitz::TinyVector<double, 3> v1_rel = v1 / SI::c;
|
||||
const blitz::TinyVector<double, 3> v2_rel = v2 / SI::c;
|
||||
|
||||
const double udotv = blitz::dot(v1_rel, v2_rel);
|
||||
const double vsqr = blitz::dot(v2_rel, v2_rel);
|
||||
|
||||
if (vsqr == 0) {
|
||||
return v1;
|
||||
}
|
||||
|
||||
const blitz::TinyVector<double, 3> u_parallel = udotv / vsqr * v2_rel;
|
||||
const blitz::TinyVector<double, 3> u_perpendicular = v1_rel - u_parallel;
|
||||
|
||||
return SI::c * (v2_rel + u_parallel + std::sqrt(1 - vsqr) * u_perpendicular) /
|
||||
(1 + udotv);
|
||||
}
|
||||
|
||||
blitz::TinyVector<double, 3> perpendicularVector(
|
||||
const blitz::TinyVector<double, 3>& vector,
|
||||
const blitz::TinyVector<double, 3>& direction) {
|
||||
return vector - parallelVector(vector, direction);
|
||||
}
|
||||
|
||||
blitz::TinyVector<double, 3> parallelVector(
|
||||
const blitz::TinyVector<double, 3>& vector,
|
||||
const blitz::TinyVector<double, 3>& direction) {
|
||||
return blitz::dot(vector, direction) * direction /
|
||||
blitz::dot(direction, direction);
|
||||
}
|
||||
|
||||
blitz::TinyVector<double, 3> rotateVector(
|
||||
const blitz::TinyVector<double, 3>& vector,
|
||||
const blitz::TinyVector<double, 3>& rotation_axis,
|
||||
double angle) {
|
||||
const blitz::TinyVector<double, 3> n = rotation_axis / norm(rotation_axis);
|
||||
const blitz::TinyVector<double, 3> cross = blitz::cross(n, vector);
|
||||
return n * blitz::dot(n, vector) + std::cos(angle) * blitz::cross(cross, n) +
|
||||
std::sin(angle) * cross;
|
||||
}
|
||||
|
||||
}; // namespace kinematic
|
||||
Reference in New Issue
Block a user