Removed d'Alembert force and chaned halo model to NFW
This commit is contained in:
parent
f8eae117dd
commit
8cb62ac88c
7 changed files with 316 additions and 73 deletions
53
main.cpp
53
main.cpp
|
|
@ -42,15 +42,23 @@ private:
|
|||
gsl_spline *spline;
|
||||
};
|
||||
|
||||
void plummer(double M, double b, const double3& pos, double3& acc)
|
||||
double3 plummer(const double M, const double b, const double3& pos)
|
||||
{
|
||||
double r2 = (pos[0]*pos[0] + pos[1]*pos[1] + pos[2]*pos[2] + b*b);
|
||||
double r2 = pos.squaredNorm() + b*b;
|
||||
double r = sqrt(r2);
|
||||
double r3_inv = 1/(r*r2);
|
||||
acc = -G*M*pos*r3_inv;
|
||||
return -G*M*pos*r3_inv;
|
||||
}
|
||||
|
||||
void miyamoto_nagai(double M, double a, double b, double phi, double theta, const double3& pos, double3& acc)
|
||||
double3 nfw(const double rho_0, const double b, const double3& pos)
|
||||
{
|
||||
double r2 = pos.squaredNorm();
|
||||
double r = sqrt(r2);
|
||||
double tmp = -4*M_PI*G*rho_0*b*b*b*(log(1+r/b) - r/(b+r))/(r2*r);
|
||||
return pos*tmp;
|
||||
}
|
||||
|
||||
double3 miyamoto_nagai(const double M, const double a, const double b, const double phi, const double theta, const double3& pos)
|
||||
{
|
||||
// Construct new z-axis from the angles
|
||||
double cos_theta = cos(theta);
|
||||
|
|
@ -76,47 +84,44 @@ void miyamoto_nagai(double M, double a, double b, double phi, double theta, cons
|
|||
acc_in_rotated_frame[2] = - tmp * new_pos[2] * (z_tmp + a)/z_tmp;
|
||||
|
||||
// Return to original frame
|
||||
acc = rot.inverse() * acc_in_rotated_frame;
|
||||
return rot.inverse() * acc_in_rotated_frame;
|
||||
}
|
||||
|
||||
class Galaxy {
|
||||
public:
|
||||
Galaxy(std::string file_name)
|
||||
{
|
||||
auto data = Loadtxt(file_name, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}).get_cols();
|
||||
auto data = Loadtxt(file_name, {1, 2, 3, 4, 5, 6, 7, 8}).get_cols();
|
||||
auto& t_data = data[0];
|
||||
std::transform(begin(t_data), end(t_data), begin(t_data), [t0=t_data[0]](const double& x){ return x-t0; });
|
||||
for (int i=0; i<10; i++) interp[i] = Interp(t_data, data[i+1]);
|
||||
for (int i=0; i<7; i++) interp[i] = Interp(t_data, data[i+1]);
|
||||
}
|
||||
void func(const std::array<double, 6> &y, std::array<double, 6> &f, const double t)
|
||||
{
|
||||
f[0] = y[3]; // vx -> x'
|
||||
f[1] = y[4]; // vy -> y'
|
||||
f[2] = y[5]; // vz -> z'
|
||||
double m_disk = interp[0](t);
|
||||
double phi = interp[1](t);
|
||||
double theta = interp[2](t);
|
||||
double phi = interp[0](t);
|
||||
double theta = interp[1](t);
|
||||
double m_disk = interp[2](t);
|
||||
double a_disk = interp[3](t);
|
||||
double b_disk = interp[4](t);
|
||||
double m_halo = interp[5](t);
|
||||
double b_halo = interp[6](t);
|
||||
double3 dalembert;
|
||||
// for (int i=0; i<3; i++) dalembert[i] = interp[7+i](t);
|
||||
dalembert = {0,0,0};
|
||||
double rho_0_nfw = interp[5](t);
|
||||
double b_nfw = interp[6](t);
|
||||
|
||||
double3 acc_disk, acc_halo;
|
||||
const double3 pos(y.data());
|
||||
miyamoto_nagai(m_disk, a_disk, b_disk, phi, theta, pos, acc_disk);
|
||||
plummer(m_halo, b_halo, pos, acc_halo);
|
||||
for (int i=0; i<3; i++) f[3+i] = acc_disk[i] + acc_halo[i] + dalembert[i];
|
||||
double3 pos(y.data());
|
||||
double3 acc_disk = miyamoto_nagai(m_disk, a_disk, b_disk, phi, theta, pos);
|
||||
double3 acc_halo = nfw(rho_0_nfw, b_nfw, pos);
|
||||
for (int i=0; i<3; i++) f[3+i] = acc_disk[i] + acc_halo[i];
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
Interp interp[10];
|
||||
} galaxy("subhalo_411321_parameters_processed.dat");
|
||||
|
||||
extern "C"
|
||||
int integrate(const double y0[], const double t_max, const double stride_size, double y[])
|
||||
void integrate(const double y0[], const double t_max, const double stride_size, double y[])
|
||||
{
|
||||
using namespace boost::numeric::odeint;
|
||||
using Coordinates = std::array<double, 6>;
|
||||
|
|
@ -127,7 +132,7 @@ int integrate(const double y0[], const double t_max, const double stride_size, d
|
|||
std::copy(y0, y0+6, begin(y_current));
|
||||
std::copy(y0, y0+6, y);
|
||||
double t = 0;
|
||||
const double h = 1./4096.;
|
||||
const double h = std::min(1./4096., stride_size);
|
||||
for (int i=0; i<stride_count; i++) {
|
||||
integrate_adaptive(stepper, function_wrapper, y_current, t, t+stride_size, h);
|
||||
// NOTE h here is just a recommended initial step size for the stepper,
|
||||
|
|
@ -139,10 +144,6 @@ int integrate(const double y0[], const double t_max, const double stride_size, d
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << "Hi" << std::endl;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue