Skip to content

Commit eef3872

Browse files
authored
Merge pull request brucefan1983#1166 from brucefan1983/dump_charge
dump charge
2 parents 0d33be6 + e786d57 commit eef3872

File tree

5 files changed

+31
-26
lines changed

5 files changed

+31
-26
lines changed

src/main_gpumd/add_efield.cu

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,6 @@ Add electric field to a group of atoms.
2828
#include <vector>
2929
#include <cstring>
3030

31-
static void __global__ add_efield(
32-
const int group_size,
33-
const int group_size_sum,
34-
const int* g_group_contents,
35-
const double Ex,
36-
const double Ey,
37-
const double Ez,
38-
const double* g_charge,
39-
double* g_fx,
40-
double* g_fy,
41-
double* g_fz)
42-
{
43-
const int tid = blockIdx.x * blockDim.x + threadIdx.x;
44-
if (tid < group_size) {
45-
const int atom_id = g_group_contents[group_size_sum + tid];
46-
const double charge = g_charge[atom_id];
47-
g_fx[atom_id] += charge * Ex;
48-
g_fy[atom_id] += charge * Ey;
49-
g_fz[atom_id] += charge * Ez;
50-
}
51-
}
52-
53-
// for NEP-charge
5431
static void __global__ add_efield(
5532
const int group_size,
5633
const int group_size_sum,

src/measure/dump_xyz.cu

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Dump per-atom data to user-specified file(s) in the extended XYZ format
1818
--------------------------------------------------------------------------------------------------*/
1919

2020
#include "dump_xyz.cuh"
21+
#include "force/force.cuh"
2122
#include "model/atom.cuh"
2223
#include "model/box.cuh"
2324
#include "utilities/common.cuh"
@@ -52,6 +53,8 @@ static __global__ void gpu_sum(const int N, const double* g_data, double* g_data
5253

5354
Dump_XYZ::Dump_XYZ(const char** param, int num_param, const std::vector<Group>& groups, Atom& atom)
5455
{
56+
is_nep_charge = check_is_nep_charge();
57+
5558
parse(param, num_param, groups);
5659
if (atom.unwrapped_position.size() < atom.number_of_atoms * 3) {
5760
atom.unwrapped_position.resize(atom.number_of_atoms * 3);
@@ -139,6 +142,15 @@ void Dump_XYZ::parse(const char** param, int num_param, const std::vector<Group>
139142
quantities.has_mass_ = true;
140143
printf(" has mass.\n");
141144
}
145+
if (strcmp(param[m], "charge") == 0) {
146+
quantities.has_charge_ = true;
147+
if (is_nep_charge){
148+
printf(" has charge predicted by NEP-charge.\n");
149+
} else {
150+
printf(" has charge specified in model.xyz.\n");
151+
}
152+
153+
}
142154
if (strcmp(param[m], "virial") == 0) {
143155
quantities.has_virial_ = true;
144156
printf(" has virial.\n");
@@ -247,6 +259,9 @@ void Dump_XYZ::output_line2(
247259
if (quantities.has_mass_) {
248260
fprintf(fid_, ":mass:R:1");
249261
}
262+
if (quantities.has_charge_) {
263+
fprintf(fid_, ":charge:R:1");
264+
}
250265
if (quantities.has_velocity_) {
251266
fprintf(fid_, ":vel:R:3");
252267
}
@@ -297,6 +312,14 @@ void Dump_XYZ::process(
297312
if (quantities.has_mass_) {
298313
atom.mass.copy_to_host(atom.cpu_mass.data());
299314
}
315+
if (quantities.has_charge_) {
316+
if (is_nep_charge) {
317+
GPU_Vector<float>& nep_charge = force.potentials[0]->get_charge_reference();
318+
nep_charge.copy_to_host(atom.cpu_charge.data());
319+
} else {
320+
atom.charge.copy_to_host(atom.cpu_charge.data());
321+
}
322+
}
300323
if (quantities.has_velocity_) {
301324
atom.velocity_per_atom.copy_to_host(atom.cpu_velocity_per_atom.data());
302325
}
@@ -340,6 +363,9 @@ void Dump_XYZ::process(
340363
if (quantities.has_mass_) {
341364
fprintf(fid_, " %.8f", atom.cpu_mass[m]);
342365
}
366+
if (quantities.has_charge_) {
367+
fprintf(fid_, " %.8f", atom.cpu_charge[m]);
368+
}
343369
if (quantities.has_velocity_) {
344370
const double natural_to_A_per_fs = 1.0 / TIME_UNIT_CONVERSION;
345371
for (int d = 0; d < 3; ++d) {

src/measure/dump_xyz.cuh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,14 @@ public:
6464
bool has_potential_ = false;
6565
bool has_unwrapped_position_ = false;
6666
bool has_mass_ = false;
67+
bool has_charge_ = false;
6768
bool has_virial_ = false;
6869
bool has_group_ = false;
6970
};
7071

7172
private:
7273

74+
bool is_nep_charge = false;
7375
int grouping_method_ = -1;
7476
int group_id_ = -1;
7577
int dump_interval_ = 1;

src/model/atom.cuh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ public:
2525
std::vector<int> cpu_type;
2626
std::vector<int> cpu_type_size;
2727
std::vector<double> cpu_mass;
28-
std::vector<double> cpu_charge;
28+
std::vector<float> cpu_charge; // float is sufficient for charge
2929
std::vector<double> cpu_position_per_atom;
3030
std::vector<double> cpu_velocity_per_atom;
3131
std::vector<std::string> cpu_atom_symbol;
3232
GPU_Vector<int> type; // per-atom type (1 component)
3333
GPU_Vector<double> mass; // per-atom mass (1 component)
34-
GPU_Vector<double> charge; // per-atom charge (1 component)
34+
GPU_Vector<float> charge; // per-atom charge (1 component)
3535
GPU_Vector<double> position_per_atom; // per-atom position (3 components)
3636
GPU_Vector<double> position_temp; // used to calculated unwrapped_position
3737
GPU_Vector<double> unwrapped_position; // unwrapped per-atom position (3 components)

src/model/read_xyz.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ void read_xyz_in_line_3(
322322
std::vector<std::string>& cpu_atom_symbol,
323323
std::vector<int>& cpu_type,
324324
std::vector<double>& cpu_mass,
325-
std::vector<double>& cpu_charge,
325+
std::vector<float>& cpu_charge,
326326
std::vector<double>& cpu_position_per_atom,
327327
std::vector<double>& cpu_velocity_per_atom,
328328
std::vector<Group>& group)

0 commit comments

Comments
 (0)