Added statistics method for terminization channels of particles
and elastic scattering for T3+. In this version benchmark old run.
This commit is contained in:
@@ -24,11 +24,8 @@ Simulation::Simulation() {
|
||||
looper.init(calc_seed(), calc_ID_offset(), calc_outfile_path());
|
||||
init_pop_arrays();
|
||||
}
|
||||
Simulation::~Simulation() {
|
||||
deconstruct_pop_arrays();
|
||||
}
|
||||
|
||||
void Simulation::init_pop_arrays() {
|
||||
void Simulation::init_pop_arrays() { // Init C-arrays used for MPI-Allgather commands depending on Populations sizes
|
||||
Population_Manager *populations = looper.get_populations();
|
||||
|
||||
int number_pop_species = 0;
|
||||
@@ -64,26 +61,15 @@ void Simulation::init_pop_arrays() {
|
||||
}
|
||||
}
|
||||
|
||||
void Simulation::deconstruct_pop_arrays() {
|
||||
delete[] pop_species;
|
||||
delete[] pop_array_lengths;
|
||||
for (int i = 0; i<number_pop_species; i++) {
|
||||
delete[] global_cum_time_s[i];
|
||||
delete[] global_offset[i];
|
||||
}
|
||||
delete[] global_cum_time_s;
|
||||
delete[] global_offset;
|
||||
}
|
||||
|
||||
long int Simulation::calc_ID_offset() {
|
||||
long int Simulation::calc_ID_offset() { // Calc ID_offset for individual MPI process
|
||||
return numberTotalDecays * 1000 * mpi_rank;
|
||||
}
|
||||
|
||||
long int Simulation::calc_seed() {
|
||||
long int Simulation::calc_seed() { // Calc seed for individual MPI process
|
||||
return seed + mpi_rank;
|
||||
}
|
||||
|
||||
std::string Simulation::calc_outfile_path() {
|
||||
std::string Simulation::calc_outfile_path() { // Create .h5 file for individual MPI process
|
||||
int dir_number;
|
||||
std::string dirname;
|
||||
if (mpi_rank == 0) {
|
||||
@@ -102,7 +88,7 @@ std::string Simulation::calc_outfile_path() {
|
||||
return filename.str();
|
||||
}
|
||||
|
||||
int Simulation::calc_dir_number() {
|
||||
int Simulation::calc_dir_number() { // Calc directory _num for MPI World
|
||||
string parname = get_parameter_filenamepath();
|
||||
stringstream dirname;
|
||||
int i = 0;
|
||||
@@ -113,7 +99,7 @@ int Simulation::calc_dir_number() {
|
||||
return i;
|
||||
}
|
||||
|
||||
std::string Simulation::build_dirname(int dir_number) {
|
||||
std::string Simulation::build_dirname(int dir_number) { // Concatanate directory name for MPI World
|
||||
string parname = get_parameter_filenamepath();
|
||||
stringstream dirname;
|
||||
dirname.str(std::string());
|
||||
@@ -121,7 +107,7 @@ std::string Simulation::build_dirname(int dir_number) {
|
||||
return dirname.str();
|
||||
}
|
||||
|
||||
void Simulation::create_out_dir(std::string dirname) {
|
||||
void Simulation::create_out_dir(std::string dirname) { // Create directory
|
||||
if (mkdir(dirname.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) {
|
||||
stringstream ss;
|
||||
ss<<"Simulation::create_out_dir: Could not create output directiory.\n outdirName = "<<dirname<<endl;
|
||||
@@ -129,21 +115,40 @@ void Simulation::create_out_dir(std::string dirname) {
|
||||
}
|
||||
}
|
||||
|
||||
std::string Simulation::create_number_extension() {
|
||||
std::string Simulation::create_number_extension() { // Calc h5 subindex for individual MPI process
|
||||
int digits = to_string(mpi_size).length();
|
||||
std::stringstream ss;
|
||||
ss << std::setw(digits) << std::setfill('0') << mpi_rank;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void Simulation::doit() {
|
||||
|
||||
Simulation::~Simulation() {
|
||||
deconstruct_pop_arrays();
|
||||
}
|
||||
|
||||
void Simulation::deconstruct_pop_arrays() { // Deallocate memory properly
|
||||
delete[] pop_species;
|
||||
delete[] pop_array_lengths;
|
||||
for (int i = 0; i<number_pop_species; i++) {
|
||||
delete[] global_cum_time_s[i];
|
||||
delete[] global_offset[i];
|
||||
}
|
||||
delete[] global_cum_time_s;
|
||||
delete[] global_offset;
|
||||
}
|
||||
|
||||
|
||||
void Simulation::doit() { // 2 Phase: 1. calc average densities, 2. actual simulate
|
||||
do_cycle(popCalcDecays, popCalcStep, false);
|
||||
if (mpi_rank == 0) {
|
||||
cout<<"Population calculation done.\n";
|
||||
}
|
||||
do_cycle(numberTotalDecays, simulationStepWidth, true);
|
||||
print_term_stats();
|
||||
};
|
||||
|
||||
// Split up total number_total to different processes, average densities after step_size, set particle logging on off
|
||||
void Simulation::do_cycle(long int number_total, long int step_size, bool logging) {
|
||||
if (number_total == 0) {
|
||||
return;
|
||||
@@ -172,6 +177,7 @@ void Simulation::do_cycle(long int number_total, long int step_size, bool loggin
|
||||
}
|
||||
}
|
||||
|
||||
// Run a number of decays and sync populations afterwards
|
||||
void Simulation::do_decays(const long int &number_decays, const bool &logging) {
|
||||
if (logging) {
|
||||
looper.do_loops(number_decays);
|
||||
@@ -184,13 +190,13 @@ void Simulation::do_decays(const long int &number_decays, const bool &logging) {
|
||||
|
||||
}
|
||||
|
||||
void Simulation::sync_cpus() {
|
||||
void Simulation::sync_cpus() { // Sync populations among MPI World
|
||||
MPI_Allreduce(&number_local_decays, &number_global_decays, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
|
||||
looper.set_global_decays(number_global_decays - number_local_decays);
|
||||
sync_populations();
|
||||
}
|
||||
|
||||
void Simulation::sync_populations() {
|
||||
void Simulation::sync_populations() { // Sync new densities for each species and calculate new densities properly
|
||||
Population_Manager *populations = looper.get_populations();
|
||||
Population_Container *container;
|
||||
double *global_delta_cumulated_time_s;
|
||||
@@ -230,9 +236,33 @@ void Simulation::sync_populations() {
|
||||
}
|
||||
}
|
||||
|
||||
void Simulation::do_statusUpdate() {
|
||||
void Simulation::do_statusUpdate() { // Push current number of decays to std::cout
|
||||
if (mpi_rank == 0) {
|
||||
cout<<"Status: "<<number_global_decays<<"/"<<(numberTotalDecays+popCalcDecays)<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
void Simulation::print_term_stats() {
|
||||
Terminator_Manager *terminators = looper.get_terminators();
|
||||
vector<species> all_species = get_all_species_vector();
|
||||
Termination_Stats local_stats, global_stats;
|
||||
int local_array[7], global_array[7];
|
||||
for (vector<species>::iterator itr = all_species.begin(); itr!= all_species.end(); itr++) {
|
||||
if (terminators->exists(*itr)) {
|
||||
local_stats = terminators->find(*itr)->get_stats();
|
||||
local_stats.to_array(local_array);
|
||||
MPI_Allreduce(local_array, global_array, 7, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
|
||||
global_stats.from_array(global_array);
|
||||
if (mpi_rank == 0) {
|
||||
std::cout<<"# "<<*itr<<"\n";
|
||||
std::cout<<"n_total\t"<<global_stats.n_total<<"\n";
|
||||
std::cout<<"n_rw\t"<<global_stats.n_rw<<"\n";
|
||||
std::cout<<"n_dipole\t"<<global_stats.n_dipole<<"\n";
|
||||
std::cout<<"n_radial\t"<<global_stats.n_radial<<"\n";
|
||||
std::cout<<"n_max\t"<<global_stats.n_max<<"\n";
|
||||
std::cout<<"n_energy\t"<<global_stats.n_energy<<"\n";
|
||||
std::cout<<"n_reaction\t"<<global_stats.n_reaction<<"\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user