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 a new command #861

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 11 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
4 changes: 4 additions & 0 deletions src/main_gpumd/run.cu
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,10 @@ void Run::parse_one_keyword(std::vector<std::string>& tokens)
add_efield.parse(param, num_param, group);
} else if (strcmp(param[0], "mc") == 0) {
mc.parse_mc(param, num_param, group, atom);
} else if (strcmp(param[0], "mc_minimize") == 0) {
MC_Minimize mc_minimize;
mc_minimize.parse_mc_minimize(param, num_param, group, atom, box, force);
mc_minimize.compute(force, atom, box, group);
} else if (strcmp(param[0], "dftd3") == 0) {
// nothing here; will be handled elsewhere
} else if (strcmp(param[0], "compute_lsqt") == 0) {
Expand Down
1 change: 1 addition & 0 deletions src/main_gpumd/run.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Measure;
#include "force/force.cuh"
#include "integrate/integrate.cuh"
#include "mc/mc.cuh"
#include "mc_minimize/mc_minimize.cuh"
#include "measure/measure.cuh"
#include "model/atom.cuh"
#include "model/box.cuh"
Expand Down
6 changes: 6 additions & 0 deletions src/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ SOURCES_GPUMD = \
$(wildcard phonon/*.cu) \
$(wildcard integrate/*.cu) \
$(wildcard mc/*.cu) \
$(wildcard mc_minimize/*.cu) \
$(wildcard force/*.cu) \
$(wildcard measure/*.cu) \
$(wildcard model/*.cu) \
Expand Down Expand Up @@ -66,6 +67,7 @@ HEADERS = \
$(wildcard main_gpumd/*.cuh) \
$(wildcard integrate/*.cuh) \
$(wildcard mc/*.cuh) \
$(wildcard mc_minimize/*.cuh) \
$(wildcard minimize/*.cuh) \
$(wildcard force/*.cuh) \
$(wildcard measure/*.cuh) \
Expand Down Expand Up @@ -98,6 +100,8 @@ integrate/%.obj: integrate/%.cu $(HEADERS)
$(CC) $(CFLAGS) $(INC) -c $< -o $@
mc/%.obj: mc/%.cu $(HEADERS)
$(CC) $(CFLAGS) $(INC) -c $< -o $@
mc_minimize/%.obj: mc_minimize/%.cu $(HEADERS)
$(CC) $(CFLAGS) $(INC) -c $< -o $@
minimize/%.obj: minimize/%.cu $(HEADERS)
$(CC) $(CFLAGS) $(INC) -c $< -o $@
force/%.obj: force/%.cu $(HEADERS)
Expand All @@ -119,6 +123,8 @@ integrate/%.o: integrate/%.cu $(HEADERS)
$(CC) $(CFLAGS) $(INC) -c $< -o $@
mc/%.o: mc/%.cu $(HEADERS)
$(CC) $(CFLAGS) $(INC) -c $< -o $@
mc_minimize/%.o: mc_minimize/%.cu $(HEADERS)
$(CC) $(CFLAGS) $(INC) -c $< -o $@
minimize/%.o: minimize/%.cu $(HEADERS)
$(CC) $(CFLAGS) $(INC) -c $< -o $@
force/%.o: force/%.cu $(HEADERS)
Expand Down
4 changes: 4 additions & 0 deletions src/makefile.hip
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ SOURCES_GPUMD = \
$(wildcard phonon/*.cu) \
$(wildcard integrate/*.cu) \
$(wildcard mc/*.cu) \
$(wildcard mc_minimize/*.cu) \
$(wildcard force/*.cu) \
$(wildcard measure/*.cu) \
$(wildcard model/*.cu) \
Expand All @@ -53,6 +54,7 @@ HEADERS = \
$(wildcard main_gpumd/*.cuh) \
$(wildcard integrate/*.cuh) \
$(wildcard mc/*.cuh) \
$(wildcard mc_minimize/*.cuh) \
$(wildcard minimize/*.cuh) \
$(wildcard force/*.cuh) \
$(wildcard measure/*.cuh) \
Expand Down Expand Up @@ -84,6 +86,8 @@ integrate/%.o: integrate/%.cu $(HEADERS)
$(CC) $(CFLAGS) $(INC) -c $< -o $@
mc/%.o: mc/%.cu $(HEADERS)
$(CC) $(CFLAGS) $(INC) -c $< -o $@
mc_minimize/%.o: mc_minimize/%.cu $(HEADERS)
$(CC) $(CFLAGS) $(INC) -c $< -o $@
minimize/%.o: minimize/%.cu $(HEADERS)
$(CC) $(CFLAGS) $(INC) -c $< -o $@
force/%.o: force/%.cu $(HEADERS)
Expand Down
155 changes: 155 additions & 0 deletions src/mc_minimize/mc_minimize.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/*
Copyright 2017 Zheyong Fan and GPUMD development team
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_minimize.cuh"
#include "utilities/read_file.cuh"
#include "mc_minimizer_local.cuh"
#include "mc_minimizer_global.cuh"

void MC_Minimize::parse_group(
const char** param, int num_param, std::vector<Group>& groups, int num_param_before_group)
{
if (strcmp(param[num_param_before_group], "group") != 0) {
PRINT_INPUT_ERROR("invalid option for mc.\n");
}
if (!is_valid_int(param[num_param_before_group + 1], &grouping_method)) {
PRINT_INPUT_ERROR("grouping method of MC_Minimize should be an integer.\n");
}
if (grouping_method < 0) {
PRINT_INPUT_ERROR("grouping method of MC_Minimize should >= 0.\n");
}
if (grouping_method >= groups.size()) {
PRINT_INPUT_ERROR("Grouping method should < number of grouping methods.");
}
if (!is_valid_int(param[num_param_before_group + 2], &group_id)) {
PRINT_INPUT_ERROR("group ID of MC_Minimize should be an integer.\n");
}
if (group_id < 0) {
PRINT_INPUT_ERROR("group ID of MC_Minimize should >= 0.\n");
}
if (group_id >= groups[grouping_method].number) {
PRINT_INPUT_ERROR("Group ID should < number of groups.");
}
}


void MC_Minimize::compute(
Force& force,
Atom& atom,
Box& box,
std::vector<Group>& group)
{
mc_minimizer->compute(
num_trials_mc,
force,
atom,
box,
group,
grouping_method,
group_id);
}

void MC_Minimize::parse_mc_minimize(const char** param, int num_param, std::vector<Group>& group, Atom& atom, Box& box, Force& force)
{
if (num_param < 6) {
PRINT_INPUT_ERROR("mc_minimize should have at least 5 parameters.\n");
}

//0 for local, 1 for global
int mc_minimizer_type = 0;
if (strcmp(param[1], "local") == 0) {
printf("Perform simple MC with local relaxation:\n");
mc_minimizer_type = 0;
} else if (strcmp(param[1], "global") == 0) {
printf("Perform simple MC with global relaxation:\n");
mc_minimizer_type = 1;
} else {
PRINT_INPUT_ERROR("invalid MC Minimizer type for MC.\n");
}
if (mc_minimizer_type == 0) {
if (num_param < 7) {
PRINT_INPUT_ERROR("reading error for local relaxation, missing parameter\n");
}
}

//check if num_trials_mc reasonable
if (!is_valid_int(param[2], &num_trials_mc)) {
PRINT_INPUT_ERROR("number of MC trials for MC Minimize should be an integer.\n");
}
if (num_trials_mc <= 0) {
PRINT_INPUT_ERROR("number of MC trials for MC Minimize should be positive.\n");
}

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

//check if force_tolerance reasonable
if (!is_valid_real(param[4], &force_tolerance)) {
PRINT_INPUT_ERROR("force tolerance for MC Minimize should be a number.\n");
}
if (force_tolerance <= 0) {
PRINT_INPUT_ERROR("force tolerance for MC Minimize should be positive.\n");
}

//check if max nmber of relax reasonable
if (!is_valid_int(param[5], &max_relax_steps)) {
PRINT_INPUT_ERROR("max relaxation steps for MC Minimize should be an integer.\n");
}
if (max_relax_steps <= 0) {
PRINT_INPUT_ERROR("max relaxation steps for MC Minimize should be positive.\n");
}

//check if scale factor reasonable
if (mc_minimizer_type == 0)
{
if (!is_valid_real(param[6], &scale_factor)) {
PRINT_INPUT_ERROR("scale factor for MC Minimize should be a number.\n");
}
if (max_relax_steps <= 0) {
PRINT_INPUT_ERROR("scale factor for MC Minimize should be positive.\n");
}
}

int num_param_before_group;
if (mc_minimizer_type == 0)
{
num_param_before_group = 7;
}
if (mc_minimizer_type == 1)
{
num_param_before_group = 6;
}

if (num_param > num_param_before_group)
{
parse_group(param, num_param, group, num_param_before_group);
printf(" only for atoms in group %d of grouping method %d.\n", group_id, grouping_method);
}

if (mc_minimizer_type == 0)
{
mc_minimizer.reset(new MC_Minimizer_Local(param, num_param, scale_factor, temperature, force_tolerance, max_relax_steps));
}
if (mc_minimizer_type == 1)
{
mc_minimizer.reset(new MC_Minimizer_Global(param, num_param, temperature, force_tolerance, max_relax_steps));
}
}
52 changes: 52 additions & 0 deletions src/mc_minimize/mc_minimize.cuh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
Copyright 2017 Zheyong Fan and GPUMD development team
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_minimizer.cuh"
#include "force/force.cuh"
#include "model/atom.cuh"
#include "model/box.cuh"
#include "model/group.cuh"
#include <memory>
#include <vector>

class MC_Minimize
{
private:

void parse_group(const char** param, int num_param, std::vector<Group>& groups, int num_param_before_group);
int grouping_method = -1;
int group_id = -1;

//parameters
int num_trials_mc = 0;
double temperature = 0;
double force_tolerance = 0;
int max_relax_steps = 0;
double scale_factor = 0;


public:
void parse_mc_minimize(const char** param, int num_param, std::vector<Group>& group, Atom& atom, Box& box, Force& force);

void compute(
Force& force,
Atom& atom,
Box& box,
std::vector<Group>& group);

std::unique_ptr<MC_Minimizer> mc_minimizer;
};

49 changes: 49 additions & 0 deletions src/mc_minimize/mc_minimizer.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
Copyright 2017 Zheyong Fan and GPUMD development team
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_minimizer.cuh"
#include <iostream>
#include <fstream>
#include <chrono>

MC_Minimizer::MC_Minimizer(const char** param, int num_param)
{
mc_output.open("mc_minimize.out", std::ios::app);
mc_output << "# ";
for (int n = 0; n < num_param; ++n) {
mc_output << param[n] << " ";
}
mc_output << "\n";
if (strcmp(param[1], "local") == 0) {
mc_output << "Step" << "\t" << "Maximum displacement" << "\t" << "Average displacement"
<< "\t" << "Energy before" << "\t" << "Energy after" << "\t" << "Accept ratio" << std::endl;
} else if (strcmp(param[1], "global") == 0) {
mc_output << "Step" << "\t" << "Energy before" << "\t" << "Energy after" << "\t" << "Accept ratio" << std::endl;
}



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

MC_Minimizer::~MC_Minimizer()
{
//default destructor
}
44 changes: 44 additions & 0 deletions src/mc_minimize/mc_minimizer.cuh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright 2017 Zheyong Fan and GPUMD development team
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 "force/force.cuh"
#include <random>
#include "minimize/minimizer_fire.cuh"

class MC_Minimizer
{
private:

public:
MC_Minimizer(const char** param, int num_param);
virtual ~MC_Minimizer();

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

protected:
std::mt19937 rng;
std::ofstream mc_output;
};

Loading
Loading