Skip to content

Commit

Permalink
fix bug related to group
Browse files Browse the repository at this point in the history
  • Loading branch information
brucefan1983 committed Aug 24, 2023
1 parent 4799153 commit 0b2e890
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/mc/mc.cu
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void MC::compute(int step, int num_steps, Atom& atom, Box& box, std::vector<Grou
if ((step + 2) % num_steps_md == 0) {
double temperature =
temperature_initial + step * (temperature_final - temperature_initial) / num_steps;
mc_ensemble->compute(step + 2, temperature, atom, box, group[grouping_method], group_id);
mc_ensemble->compute(step + 2, temperature, atom, box, group, grouping_method, group_id);
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/mc/mc_ensemble.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ public:
MC_Ensemble(void);
virtual ~MC_Ensemble(void);

virtual void
compute(int md_step, double temperature, Atom& atom, Box& box, Group& group, int group_id) = 0;
virtual void compute(
int md_step,
double temperature,
Atom& atom,
Box& box,
std::vector<Group>& group,
int grouping_method,
int group_id) = 0;

protected:
int num_steps_mc = 0;
Expand Down
21 changes: 17 additions & 4 deletions src/mc/mc_ensemble_canonical.cu
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,13 @@ static bool check_if_small_box(const double rc, const Box& box)
}

void MC_Ensemble_Canonical::compute(
int md_step, double temperature, Atom& atom, Box& box, Group& group, int group_id)
int md_step,
double temperature,
Atom& atom,
Box& box,
std::vector<Group>& groups,
int grouping_method,
int group_id)
{
if (check_if_small_box(nep_energy.paramb.rc_radial, box)) {
printf("Cannot use small box for MCMD.\n");
Expand All @@ -233,17 +239,24 @@ void MC_Ensemble_Canonical::compute(
type_after.resize(atom.number_of_atoms);
}

int group_size = group.cpu_size[group_id];
int group_size =
groups.size() > 0 ? groups[grouping_method].cpu_size[group_id] : atom.number_of_atoms;
std::uniform_int_distribution<int> r1(0, group_size - 1);

int num_accepted = 0;
for (int step = 0; step < num_steps_mc; ++step) {

int i = group.cpu_contents[group.cpu_size_sum[group_id] + r1(rng)];
int i = groups.size() > 0
? groups[grouping_method]
.cpu_contents[groups[grouping_method].cpu_size_sum[group_id] + r1(rng)]
: r1(rng);
int type_i = atom.cpu_type[i];
int j = 0, type_j = type_i;
while (type_i == type_j) {
j = group.cpu_contents[group.cpu_size_sum[group_id] + r1(rng)];
j = groups.size() > 0
? groups[grouping_method]
.cpu_contents[groups[grouping_method].cpu_size_sum[group_id] + r1(rng)]
: r1(rng);
type_j = atom.cpu_type[j];
}

Expand Down
10 changes: 8 additions & 2 deletions src/mc/mc_ensemble_canonical.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ public:
MC_Ensemble_Canonical(int num_steps_mc);
virtual ~MC_Ensemble_Canonical(void);

virtual void
compute(int md_step, double temperature, Atom& atom, Box& box, Group& group, int group_id);
virtual void compute(
int md_step,
double temperature,
Atom& atom,
Box& box,
std::vector<Group>& group,
int grouping_method,
int group_id);

private:
GPU_Vector<int> NN_ij;
Expand Down

0 comments on commit 0b2e890

Please sign in to comment.