Skip to content

Commit

Permalink
Merge pull request #472 from brucefan1983/mcmd
Browse files Browse the repository at this point in the history
mcmd
  • Loading branch information
brucefan1983 authored Aug 25, 2023
2 parents 004d621 + 0b2e890 commit c9a16ef
Show file tree
Hide file tree
Showing 11 changed files with 1,446 additions and 4 deletions.
16 changes: 14 additions & 2 deletions src/main_gpumd/run.cu
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ void Run::execute_run_in()
void Run::perform_a_run()
{
integrate.initialize(N, time_step, group, atom);
mc.initialize();
measure.initialize(number_of_steps, time_step, integrate, group, atom, force);

#ifdef USE_PLUMED
Expand Down Expand Up @@ -214,6 +215,8 @@ void Run::perform_a_run()

integrate.compute2(time_step, double(step) / number_of_steps, group, box, atom, thermo);

mc.compute(step, number_of_steps, atom, box, group);

measure.process(
number_of_steps,
step,
Expand Down Expand Up @@ -252,10 +255,17 @@ void Run::perform_a_run()
printf("Speed of this run = %g atom*step/second.\n", run_speed);
print_line_2();

measure.finalize(integrate, number_of_steps, time_step, integrate.temperature2, box.get_volume(),atom.number_of_beads);
measure.finalize(
integrate,
number_of_steps,
time_step,
integrate.temperature2,
box.get_volume(),
atom.number_of_beads);

electron_stop.finalize();
integrate.finalize();
mc.finalize();
velocity.finalize();
max_distance_per_step = 0.0;
}
Expand Down Expand Up @@ -366,7 +376,7 @@ void Run::parse_one_keyword(std::vector<std::string>& tokens)
measure.sdc.parse(param, num_param, group);
} else if (strcmp(param[0], "compute_msd") == 0) {
measure.msd.parse(param, num_param, group);
} else if (strcmp(param[0], "compute_rdf") == 0) {
} else if (strcmp(param[0], "compute_rdf") == 0) {
measure.rdf.parse(param, num_param, box, number_of_types, number_of_steps);
} else if (strcmp(param[0], "compute_hac") == 0) {
measure.hac.parse(param, num_param);
Expand All @@ -392,6 +402,8 @@ void Run::parse_one_keyword(std::vector<std::string>& tokens)
integrate.parse_move(param, num_param, group);
} else if (strcmp(param[0], "electron_stop") == 0) {
electron_stop.parse(param, num_param, atom.number_of_atoms, number_of_types);
} else if (strcmp(param[0], "mc") == 0) {
mc.parse_mc(param, num_param, group, atom.cpu_type);
} else if (strcmp(param[0], "run") == 0) {
parse_run(param, num_param);
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/main_gpumd/run.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Measure;
#include "electron_stop.cuh"
#include "force/force.cuh"
#include "integrate/integrate.cuh"
#include "mc/mc.cuh"
#include "measure/measure.cuh"
#include "model/atom.cuh"
#include "model/box.cuh"
Expand Down Expand Up @@ -65,6 +66,7 @@ private:

Force force;
Integrate integrate;
MC mc;
Measure measure;
Electron_Stop electron_stop;
};
10 changes: 8 additions & 2 deletions src/makefile
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ LIBS = -lcublas -lcusolver
SOURCES_GPUMD = \
$(wildcard main_gpumd/*.cu) \
$(wildcard minimize/*.cu) \
$(wildcard phonon/*.cu) \
$(wildcard phonon/*.cu) \
$(wildcard integrate/*.cu) \
$(wildcard mc/*.cu) \
$(wildcard force/*.cu) \
$(wildcard measure/*.cu) \
$(wildcard model/*.cu) \
Expand Down Expand Up @@ -62,11 +63,12 @@ HEADERS = \
$(wildcard utilities/*.cuh) \
$(wildcard main_gpumd/*.cuh) \
$(wildcard integrate/*.cuh) \
$(wildcard mc/*.cuh) \
$(wildcard minimize/*.cuh) \
$(wildcard force/*.cuh) \
$(wildcard measure/*.cuh) \
$(wildcard model/*.cuh) \
$(wildcard phonon/*.cuh) \
$(wildcard phonon/*.cuh) \
$(wildcard main_nep/*.cuh)


Expand All @@ -86,6 +88,8 @@ nep: $(OBJ_NEP)
ifdef OS # for Windows
integrate/%.obj: integrate/%.cu $(HEADERS)
$(CC) $(CFLAGS) $(INC) -c $< -o $@
mc/%.obj: mc/%.cu $(HEADERS)
$(CC) $(CFLAGS) $(INC) -c $< -o $@
minimize/%.obj: minimize/%.cu $(HEADERS)
$(CC) $(CFLAGS) $(INC) -c $< -o $@
force/%.obj: force/%.cu $(HEADERS)
Expand All @@ -105,6 +109,8 @@ main_nep/%.obj: main_nep/%.cu $(HEADERS)
else # for Linux
integrate/%.o: integrate/%.cu $(HEADERS)
$(CC) $(CFLAGS) $(INC) -c $< -o $@
mc/%.o: mc/%.cu $(HEADERS)
$(CC) $(CFLAGS) $(INC) -c $< -o $@
minimize/%.o: minimize/%.cu $(HEADERS)
$(CC) $(CFLAGS) $(INC) -c $< -o $@
force/%.o: force/%.cu $(HEADERS)
Expand Down
158 changes: 158 additions & 0 deletions src/mc/mc.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/*
Copyright 2017 Zheyong Fan, Ville Vierimaa, Mikko Ervasti, and Ari Harju
This file is part of GPUMD.
GPUMD is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
GPUMD is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GPUMD. If not, see <http://www.gnu.org/licenses/>.
*/

/*----------------------------------------------------------------------------80
The driver class for the various MC ensembles.
------------------------------------------------------------------------------*/

#include "mc.cuh"
#include "mc_ensemble_canonical.cuh"
#include "model/atom.cuh"
#include "utilities/common.cuh"
#include "utilities/read_file.cuh"

void MC::initialize(void)
{
// todo
}

void MC::finalize(void) { do_mcmd = false; }

void MC::compute(int step, int num_steps, Atom& atom, Box& box, std::vector<Group>& group)
{
if (do_mcmd) {
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);
}
}
}

void MC::parse_mc(
const char** param, int num_param, std::vector<Group>& groups, std::vector<int>& cpu_type)
{
if (num_param < 6) {
PRINT_INPUT_ERROR("mc should have at least 5 parameters.\n");
}

int mc_ensemble_type = 0;
if (strcmp(param[1], "canonical") == 0) {
mc_ensemble_type = 0;
} else if (strcmp(param[1], "sgc") == 0) {
PRINT_INPUT_ERROR("semi-grand canonical MCMD has not been implemented yet.\n");
} else if (strcmp(param[1], "vcsgc") == 0) {
PRINT_INPUT_ERROR(
"variance constrained semi-grand canonical MCMD has not been implemented yet.\n");
} else {
PRINT_INPUT_ERROR("invalid MC ensemble for MCMD.\n");
}

if (!is_valid_int(param[2], &num_steps_md)) {
PRINT_INPUT_ERROR("number of MD steps for MCMD should be an integer.\n");
}
if (num_steps_md <= 0) {
PRINT_INPUT_ERROR("number of MD steps for MCMD should be positive.\n");
}

if (!is_valid_int(param[3], &num_steps_mc)) {
PRINT_INPUT_ERROR("number of MC steps for MCMD should be an integer.\n");
}
if (num_steps_mc <= 0) {
PRINT_INPUT_ERROR("number of MC steps for MCMD should be positive.\n");
}

if (!is_valid_real(param[4], &temperature_initial)) {
PRINT_INPUT_ERROR("initial temperature for MCMD should be a number.\n");
}
if (temperature_initial <= 0) {
PRINT_INPUT_ERROR("initial temperature for MCMD should be positive.\n");
}

if (!is_valid_real(param[5], &temperature_final)) {
PRINT_INPUT_ERROR("final temperature for MCMD should be a number.\n");
}
if (temperature_final <= 0) {
PRINT_INPUT_ERROR("final temperature for MCMD should be positive.\n");
}

if (mc_ensemble_type == 0) {
if (num_param > 6) {
if (num_param != 9) {
PRINT_INPUT_ERROR("mc canonical must has 9 paramters when using a grouping method.\n");
}
if (strcmp(param[6], "group") != 0) {
PRINT_INPUT_ERROR("invalid option for mc.\n");
}
if (!is_valid_int(param[7], &grouping_method)) {
PRINT_INPUT_ERROR("grouping method of MCMD should be an integer.\n");
}
if (grouping_method < 0) {
PRINT_INPUT_ERROR("grouping method of MCMD should >= 0.\n");
}
if (grouping_method >= groups.size()) {
PRINT_INPUT_ERROR("Grouping method should < number of grouping methods.");
}
if (!is_valid_int(param[8], &group_id)) {
PRINT_INPUT_ERROR("group ID of MCMD should be an integer.\n");
}
if (group_id < 0) {
PRINT_INPUT_ERROR("group ID of MCMD should >= 0.\n");
}
if (group_id >= groups[grouping_method].number) {
PRINT_INPUT_ERROR("Group ID should < number of groups.");
}

bool has_multi_types = false;
int type0 = 0;
for (int k = 0; k < groups[grouping_method].cpu_size[group_id]; ++k) {
int n =
groups[grouping_method].cpu_contents[groups[grouping_method].cpu_size_sum[group_id] + k];
if (k == 0) {
type0 = cpu_type[n];
} else {
if (cpu_type[n] != type0) {
has_multi_types = true;
break;
}
}
}
if (!has_multi_types) {
PRINT_INPUT_ERROR("Must have more than one atom type in the specified group.");
}
}
}

if (mc_ensemble_type == 0) {
printf("Perform canonical MCMD:\n");
}
printf(" after every %d MD steps, do %d MC trials.\n", num_steps_md, num_steps_mc);
printf(
" with an initial temperature of %g K and a final temperature of %g K.\n",
temperature_initial,
temperature_final);

if (mc_ensemble_type == 0) {
if (num_param == 6) {
printf(" for all the atoms in the system.\n");
} else {
printf(" only for atoms in group %d of grouping method %d.\n", group_id, grouping_method);
}
}

mc_ensemble.reset(new MC_Ensemble_Canonical(num_steps_mc));

do_mcmd = true;
}
46 changes: 46 additions & 0 deletions src/mc/mc.cuh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Copyright 2017 Zheyong Fan, Ville Vierimaa, Mikko Ervasti, and Ari Harju
This file is part of GPUMD.
GPUMD is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
GPUMD is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GPUMD. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "mc_ensemble.cuh"
#include "model/box.cuh"
#include "model/group.cuh"
#include <memory>
#include <vector>

class Atom;

class MC
{
public:
std::unique_ptr<MC_Ensemble> mc_ensemble;

void initialize(void);
void finalize(void);
void compute(int step, int num_steps, Atom& atom, Box& box, std::vector<Group>& group);

void parse_mc(
const char** param, int num_param, std::vector<Group>& group, std::vector<int>& cpu_type);

private:
bool do_mcmd = false;
int num_steps_md = 0;
int num_steps_mc = 0;
int grouping_method = 0;
int group_id = 0;
double temperature_initial = 0.0;
double temperature_final = 0.0;
};
Loading

0 comments on commit c9a16ef

Please sign in to comment.