From 62eccecd11e5187e832cd00e4f8aae744590948f Mon Sep 17 00:00:00 2001 From: mushroomfire <934313174@qq.com> Date: Wed, 22 May 2024 18:42:51 +0800 Subject: [PATCH] Add separated parameter --- doc/gpumd/input_parameters/dump_exyz.rst | 3 +++ src/measure/dump_exyz.cu | 34 +++++++++++++++++++++--- src/measure/dump_exyz.cuh | 1 + 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/doc/gpumd/input_parameters/dump_exyz.rst b/doc/gpumd/input_parameters/dump_exyz.rst index fa4138d83..fe8d0418f 100644 --- a/doc/gpumd/input_parameters/dump_exyz.rst +++ b/doc/gpumd/input_parameters/dump_exyz.rst @@ -15,12 +15,14 @@ Syntax dump_exyz dump_exyz dump_exyz + dump_exyz Here, the :attr:`interval` parameter is the output interval (number of steps) of the data. :attr:`has_velocity` can be 1 or 0, which means the velocities will or will not be included in the output. :attr:`has_force` can be 1 or 0, which means the forces will or will not be included in the output. :attr:`has_potential` can be 1 or 0, which means the atomic potential energies will or will not be included in the output. The atomic positions will always be included in the output. +:attr:`separated` can be 1 or 0, which means the output will or will not be separated into individual frames. Examples -------- @@ -32,6 +34,7 @@ Examples dump_exyz 1000 1 1 # dump positions, velocities, and forces dump_exyz 1000 1 1 1 # dump positions, velocities, forces, and potentials dump_exyz 1000 0 1 1 # dump positions, forces and potentials + dump_exyz 100 0 1 1 1 # dump positions, forces and potentials into dump.100.xyz, dump.200.xyz and so on Caveats ------- diff --git a/src/measure/dump_exyz.cu b/src/measure/dump_exyz.cu index 4471f3d11..db536dc9d 100644 --- a/src/measure/dump_exyz.cu +++ b/src/measure/dump_exyz.cu @@ -69,6 +69,7 @@ void Dump_EXYZ::parse(const char** param, int num_param) has_velocity_ = 0; has_force_ = 0; has_potential_ = 0; + separated_ = 0; if (num_param >= 3) { if (!is_valid_int(param[2], &has_velocity_)) { @@ -102,12 +103,26 @@ void Dump_EXYZ::parse(const char** param, int num_param) printf(" with potential data.\n"); } } + + if (num_param >= 6) { + if (!is_valid_int(param[5], &separated_)) { + PRINT_INPUT_ERROR("separated should be an integer."); + } + if (separated_ == 0) { + printf(" dump_exyz into dump.xyz.\n"); + } else { + printf(" dump_exyz into separated dump.*.xyz.\n"); + } + } } void Dump_EXYZ::preprocess(const int number_of_atoms) { if (dump_) { - fid_ = my_fopen("dump.xyz", "a"); + if (separated_ == 0) { + fid_ = my_fopen("dump.xyz", "a"); + } + gpu_total_virial_.resize(6); cpu_total_virial_.resize(6); if (has_force_) { @@ -235,6 +250,11 @@ void Dump_EXYZ::process( if (has_potential_) { atom.potential_per_atom.copy_to_host(cpu_potential_per_atom_.data()); } + + if (separated_) { + std::string filename = "dump."+std::to_string(step+1)+".xyz"; + fid_ = my_fopen(filename.data(), "w"); + } // line 1 fprintf(fid_, "%d\n", num_atoms_total); @@ -265,14 +285,20 @@ void Dump_EXYZ::process( } fprintf(fid_, "\n"); } - - fflush(fid_); + if (separated_ == 0) { + fflush(fid_); + } else { + fclose(fid_); + } + } void Dump_EXYZ::postprocess() { if (dump_) { - fclose(fid_); + if (separated_ == 0) { + fclose(fid_); + } dump_ = false; } } diff --git a/src/measure/dump_exyz.cuh b/src/measure/dump_exyz.cuh index f6f1ce2d6..2350fe02d 100644 --- a/src/measure/dump_exyz.cuh +++ b/src/measure/dump_exyz.cuh @@ -40,6 +40,7 @@ private: int has_velocity_ = 0; int has_force_ = 0; int has_potential_ = 0; + int separated_ = 0; FILE* fid_; char filename_[200]; void output_line2(