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

mcmd #472

Merged
merged 31 commits into from
Aug 25, 2023
Merged

mcmd #472

Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
73f6761
starting point of mcmd
brucefan1983 Aug 7, 2023
1e43629
more complete input parsing
brucefan1983 Aug 7, 2023
be947e5
find atom pairs to exchange
brucefan1983 Aug 10, 2023
afabb02
prepare data for energy calculator
brucefan1983 Aug 10, 2023
07b9add
nep energy calculator finished
brucefan1983 Aug 10, 2023
fc42c15
accept or reject
brucefan1983 Aug 10, 2023
fe1b0e7
Fixed typo in makefile
erhart1 Aug 10, 2023
4ff0af1
start to add nep energy calculator
brucefan1983 Aug 10, 2023
5ed52c2
find the local atoms for energy calculations
brucefan1983 Aug 12, 2023
88ed7b3
simplify
brucefan1983 Aug 12, 2023
1257545
speed up using locality
brucefan1983 Aug 13, 2023
717c498
only calculated zbl when it is enabled
brucefan1983 Aug 13, 2023
a431c49
small simplify
brucefan1983 Aug 13, 2023
22aa0a0
exchange in GPU
brucefan1983 Aug 13, 2023
f3c0ff8
exchange in CPU
brucefan1983 Aug 14, 2023
0183f03
simplify type
brucefan1983 Aug 14, 2023
cfe4382
get potential file name
brucefan1983 Aug 14, 2023
21edb7c
check potential name
brucefan1983 Aug 14, 2023
722b337
no eam
brucefan1983 Aug 14, 2023
e9bb98e
clean up printf
brucefan1983 Aug 14, 2023
e90c2ab
output mcmd.out
brucefan1983 Aug 14, 2023
cece1c8
change order of output
brucefan1983 Aug 14, 2023
3ad0363
exchange atom symbol (not only type)
brucefan1983 Aug 15, 2023
749ab68
output acceptance ratio
brucefan1983 Aug 15, 2023
b47083d
check number of types
brucefan1983 Aug 16, 2023
f0c2184
change syntax
brucefan1983 Aug 19, 2023
5cf0a0a
start to add group in mcmd
brucefan1983 Aug 19, 2023
d039835
parse group
brucefan1983 Aug 23, 2023
e23d295
check group for mcmd
brucefan1983 Aug 23, 2023
4799153
use group in mcmd
brucefan1983 Aug 23, 2023
0b2e890
fix bug related to group
brucefan1983 Aug 24, 2023
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
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, atom, box);

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], "cmc") == 0) {
mc.parse_cmc(param, num_param);
} 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
77 changes: 77 additions & 0 deletions src/mc/mc.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
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, Atom& atom, Box& box)
{
if (do_mcmd) {
if ((step + 1) % num_steps_md == 0) {
printf("Now do MC after %d MD steps:\n", step + 1);
mc_ensemble->compute(atom, box);
}
}
}

void MC::parse_cmc(const char** param, int num_param)
{
if (num_param != 4) {
PRINT_INPUT_ERROR("cmc should have 3 parameter.\n");
}

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

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

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

printf("Perform canonical MC:\n");
printf(" after every %d MD steps, do %d MC trials.\n", num_steps_md, num_steps_mc);
printf(" with a temperature of %g K.\n", temperature);

mc_ensemble.reset(new MC_Ensemble_Canonical(num_steps_mc, temperature));

do_mcmd = true;
}
42 changes: 42 additions & 0 deletions src/mc/mc.cuh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
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, Atom& atom, Box& box);

void parse_cmc(const char** param, int num_param);

private:
bool do_mcmd = false;
int num_steps_md = 0;
int num_steps_mc = 0;
double temperature = 0.0;
};
58 changes: 58 additions & 0 deletions src/mc/mc_ensemble.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
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 abstract base class (ABC) for the MC_Ensemble classes.
------------------------------------------------------------------------------*/

#include "mc_ensemble.cuh"
#include "utilities/common.cuh"
#include <chrono>

MC_Ensemble::MC_Ensemble(void)
{
const int n_max = 1000;
const int m_max = 1000;
NN_radial.resize(n_max);
NN_angular.resize(n_max);
local_type_before.resize(n_max);
local_type_after.resize(n_max);
t2_radial_before.resize(n_max * m_max);
t2_radial_after.resize(n_max * m_max);
t2_angular_before.resize(n_max * m_max);
t2_angular_after.resize(n_max * m_max);
x12_radial.resize(n_max * m_max);
y12_radial.resize(n_max * m_max);
z12_radial.resize(n_max * m_max);
x12_angular.resize(n_max * m_max);
y12_angular.resize(n_max * m_max);
z12_angular.resize(n_max * m_max);
pe_before.resize(n_max);
pe_after.resize(n_max);

// TODO
nep_energy.initialize("../examples/11_NEP_potential_PbTe/nep.txt");
brucefan1983 marked this conversation as resolved.
Show resolved Hide resolved

#ifdef DEBUG
rng = std::mt19937(13579);
#else
rng = std::mt19937(std::chrono::system_clock::now().time_since_epoch().count());
#endif
}

MC_Ensemble::~MC_Ensemble(void)
{
// nothing now
}
58 changes: 58 additions & 0 deletions src/mc/mc_ensemble.cuh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
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 "model/atom.cuh"
#include "model/box.cuh"
#include "model/group.cuh"
#include "nep_energy.cuh"
#include "utilities/gpu_vector.cuh"
#include <random>
#include <vector>

class MC_Ensemble
{
public:
MC_Ensemble(void);
virtual ~MC_Ensemble(void);

virtual void compute(Atom& atom, Box& box) = 0;

protected:
int num_steps_mc = 0;
double temperature = 0.0;
std::mt19937 rng;

GPU_Vector<int> NN_radial;
GPU_Vector<int> NN_angular;
GPU_Vector<int> type_before;
GPU_Vector<int> type_after;
GPU_Vector<int> local_type_before;
GPU_Vector<int> local_type_after;
GPU_Vector<int> t2_radial_before;
GPU_Vector<int> t2_radial_after;
GPU_Vector<int> t2_angular_before;
GPU_Vector<int> t2_angular_after;
GPU_Vector<float> x12_radial;
GPU_Vector<float> y12_radial;
GPU_Vector<float> z12_radial;
GPU_Vector<float> x12_angular;
GPU_Vector<float> y12_angular;
GPU_Vector<float> z12_angular;
GPU_Vector<float> pe_before;
GPU_Vector<float> pe_after;

NEP_Energy nep_energy;
};
Loading