#pragma once #include #include #include "double3.h" class External_gravity { public: void apply(const int n_act, const std::vector &x, const std::vector &v, std::vector &pot, std::vector &a, std::vector &adot) { for (int i=0; iset_coordinates(x[i], v[i]); this->calc_gravity(); pot[i] += potential; a[i] += acceleration; adot[i] += jerk; } } virtual void calc_gravity() = 0; virtual void print_info() {} void set_name(const std::string &name) { this->name = name; } bool is_active = false; protected: double potential; double3 acceleration, jerk; double3 x, v; std::string name = "ext"; void set_coordinates(double3 x, double3 v) { this->x = x; this->v = v; } }; class Plummer : public External_gravity { public: Plummer(double m, double b) : m(m), b(b) {is_active=(m>0);} void calc_gravity() override; void print_info() override { if (!is_active) return; printf("m_%-5s = %.4E b_%-5s = %.4E\n", name.c_str(), m, name.c_str(), b); } private: double m, b; }; class Miyamoto_Nagai : public External_gravity { public: Miyamoto_Nagai(double m, double a, double b) : m(m), a(a), b(b) {is_active=(m>0); this->set_name("disk");} void calc_gravity(); void print_info() override { if (!is_active) return; printf("m_%-5s = %.4E a_%-5s = %.4E b_%-5s = %.4E\n", name.c_str(), m, name.c_str(), a, name.c_str(), b); } private: double m, a, b; }; class Logarithmic_halo : public External_gravity { public: Logarithmic_halo(double v_halo, double r_halo) : v2_halo(v_halo*v_halo), r2_halo(r_halo*r_halo) {is_active=(r_halo>0); this->set_name("halo");} void calc_gravity() override; void print_info() override { if (!is_active) return; printf("v_%-4s = %.6E r_%-4s = %.4E\n", name.c_str(), sqrt(v2_halo), name.c_str(), sqrt(r2_halo)); } private: double v2_halo, r2_halo; }; class Dehnen : public External_gravity { public: Dehnen(double m, double r, double gamma) : m(m), r(r), gamma(gamma) {is_active=(m>0);} void calc_gravity() override; void print_info() override { if (!is_active) return; printf("m_%-5s = %.4E r_%-5s = %.4E g_%-5s = %.4E\n", name.c_str(), m, name.c_str(), r, name.c_str(), gamma); } private: double m, r, gamma; };