Prepared to analyze multiple subhalos
This commit is contained in:
parent
b86625ea13
commit
3f4025d9fb
8 changed files with 537 additions and 479 deletions
|
|
@ -69,16 +69,13 @@ public:
|
|||
double vd = (w[0]*w[3] + w[1]*w[4])/d;
|
||||
double vt = (w[0]*w[4] - w[1]*w[3])/d;
|
||||
double vz = w[5];
|
||||
|
||||
if (((z<0)&&(target_z>0)) || ((z>0)&&(target_z<0))) { // Flip up-down
|
||||
z = -z;
|
||||
vz = -vz;
|
||||
}
|
||||
|
||||
if (((vt<0)&&(target_vt>0)) || ((vt>0)&&(target_vt<0))) { // Flip left-right
|
||||
vt = -vt;
|
||||
}
|
||||
|
||||
return (abs(d - target_d) < pos_tol)
|
||||
&& (abs(z - target_z) < pos_tol)
|
||||
&& (abs(vd - target_vd) < vel_tol)
|
||||
|
|
@ -103,6 +100,19 @@ private:
|
|||
double target_d, target_z, target_vd, target_vt, target_vz;
|
||||
};
|
||||
|
||||
class Accept_all : public Acceptor {
|
||||
public:
|
||||
Accept_all() = default;
|
||||
bool operator()(const double w[6]) const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
void output_information(std::ostream& stream) const override
|
||||
{
|
||||
stream << "# Acceptor type: accept all\n";
|
||||
}
|
||||
};
|
||||
|
||||
class Initial_conditions {
|
||||
public:
|
||||
virtual std::array<double,6> operator()(Generator& generator) const = 0;
|
||||
|
|
@ -188,46 +198,49 @@ class Scattering_experiment {
|
|||
public:
|
||||
Scattering_experiment(const std::string& file_name, const double t_max, const unsigned long long n_experiments, const Initial_conditions& initial_conditions, const Acceptor& accept)
|
||||
: n_experiments(n_experiments),
|
||||
bunch_size(256),
|
||||
report_interval_seconds(300),
|
||||
t_max(t_max),
|
||||
accept(accept),
|
||||
initial_conditions(initial_conditions)
|
||||
initial_conditions(initial_conditions),
|
||||
start_time(std::chrono::system_clock::now()),
|
||||
file(std::ofstream(file_name)),
|
||||
n_threads(std::thread::hardware_concurrency())
|
||||
{
|
||||
const unsigned long time_count = start_time.time_since_epoch().count();
|
||||
const unsigned long big_prime = 840580612873L;
|
||||
unique_id = time_count + big_prime*getpid(); // TODO hash it
|
||||
file.setf(std::ios::scientific | std::ios::right);
|
||||
file.precision(16);
|
||||
}
|
||||
~Scattering_experiment() {
|
||||
file.close();
|
||||
}
|
||||
void set_concurrency(int n_threads)
|
||||
{
|
||||
this->n_threads = n_threads;
|
||||
}
|
||||
void write_header()
|
||||
{
|
||||
auto time = std::chrono::system_clock::now();
|
||||
file = std::ofstream(file_name/*, std::ofstream::app*/);
|
||||
file << "#############################################\n";
|
||||
file << "# Cosmological replay scattering experiment #\n";
|
||||
file << "#############################################\n";
|
||||
file << "# Time: " << iso_time(time) << '\n';
|
||||
file << "# Time: " << iso_time(start_time) << '\n';
|
||||
file << "# Last Git commit: " << git_version() << '\n';
|
||||
char hostname[256];
|
||||
gethostname(hostname, 256);
|
||||
file << "# Hostname: " << hostname << '\n';
|
||||
const auto pid = getpid();
|
||||
file << "# PID: " << pid << '\n';
|
||||
const unsigned long time_count = time.time_since_epoch().count();
|
||||
const unsigned long big_prime = 840580612873L;
|
||||
unique_id = time_count + big_prime*pid; // TODO hash it
|
||||
file << "# PID: " << getpid() << '\n';
|
||||
file << "# Unique identifier: " << unique_id << '\n';
|
||||
n_threads = std::thread::hardware_concurrency();
|
||||
file << "# Concurrency: " << n_threads << '\n';
|
||||
initial_conditions.output_information(file);
|
||||
accept.output_information(file);
|
||||
file.flush();
|
||||
file.setf(std::ios::scientific | std::ios::right);
|
||||
file.precision(16);
|
||||
// TODO information about galaxy model
|
||||
}
|
||||
~Scattering_experiment() {
|
||||
file.close();
|
||||
}
|
||||
void thread_task(int tid)
|
||||
{
|
||||
auto thread_begin_time = std::chrono::system_clock::now();
|
||||
auto report_interval = std::chrono::seconds(report_interval_seconds);
|
||||
auto next_report_time = thread_begin_time + report_interval;
|
||||
|
||||
std::default_random_engine generator(unique_id + tid);
|
||||
|
||||
while (counter < n_experiments) {
|
||||
|
|
@ -265,15 +278,16 @@ public:
|
|||
}
|
||||
std::cout << counter << '\n';
|
||||
}
|
||||
int n_threads = 1;
|
||||
int bunch_size = 256;
|
||||
int report_interval_seconds = 300;
|
||||
std::chrono::system_clock::time_point start_time;
|
||||
std::ofstream file;
|
||||
std::mutex mtx;
|
||||
int n_threads;
|
||||
std::vector<std::thread> threads;
|
||||
std::atomic<unsigned long long> counter;
|
||||
unsigned long long n_experiments;
|
||||
unsigned long unique_id;
|
||||
int bunch_size;
|
||||
int report_interval_seconds;
|
||||
double t_max;
|
||||
const Acceptor& accept;
|
||||
const Initial_conditions& initial_conditions;
|
||||
|
|
@ -293,7 +307,9 @@ int main()
|
|||
In_box_cyl accept(5, 50, target_pos, target_vel);
|
||||
Uniform_sphere_escape_velocity_cutoff uniform_sphere_escape_velocity_cutoff(75, 1.82777387E+07, 9.86242602E+00);
|
||||
|
||||
Scattering_experiment scattering_experiment("results.dat", t_max, 1000000000L, uniform_sphere_escape_velocity_cutoff, accept);
|
||||
Scattering_experiment scattering_experiment("results.dat", t_max, 1024*256, uniform_sphere_escape_velocity_cutoff, Accept_all());
|
||||
//scattering_experiment.set_concurrency(1);
|
||||
scattering_experiment.write_header();
|
||||
scattering_experiment.launch();
|
||||
|
||||
std::cout << "Bye\n";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue