Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add separated parameter for dump_exyz #629

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/gpumd/input_parameters/dump_exyz.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ Syntax
dump_exyz <interval> <has_velocity>
dump_exyz <interval> <has_velocity> <has_force>
dump_exyz <interval> <has_velocity> <has_force> <has_potential>
dump_exyz <interval> <has_velocity> <has_force> <has_potential> <separated>

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
--------
Expand All @@ -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
-------
Expand Down
34 changes: 30 additions & 4 deletions src/measure/dump_exyz.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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_)) {
Expand Down Expand Up @@ -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_) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions src/measure/dump_exyz.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down