Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
90 changes: 52 additions & 38 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,49 +1,63 @@
---
Language: Cpp
BasedOnStyle: Microsoft
BasedOnStyle: LLVM

AlwaysBreakTemplateDeclarations: Yes
ColumnLimit: 120

AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
#AlwaysBreakTemplateDeclarations: Yes
#
#AllowAllArgumentsOnNextLine: false
#AllowAllParametersOfDeclarationOnNextLine: false
BinPackArguments: false
BinPackParameters: false

BreakBeforeBinaryOperators: All
BreakBeforeTernaryOperators: true

Cpp11BracedListStyle: true
FixNamespaceComments: true

# InsertBraces: true # only for clang-format version15.0.0 or later

# About include
IncludeBlocks: Regroup
IncludeIsMainRegex: '([-_](test|unittest))?$'
IncludeIsMainSourceRegex: ''

PackArguments:
BinPack: UseBreakAfter
BreakAfter: 3
PackParameters:
BinPack: UseBreakAfter
BreakAfter: 3
#
#BreakBeforeBinaryOperators: None
#BreakBeforeTernaryOperators: true
BreakBeforeBraces: Allman
BreakAfterOpenBracketFunction: true
AlignAfterOpenBracket: DontAlign
#
#Cpp11BracedListStyle: true
#FixNamespaceComments: true
#
InsertBraces: true # only for clang-format version15.0.0 or later
#
## About include
#IncludeBlocks: Regroup
#IncludeIsMainRegex: '([-_](test|unittest))?$'
#IncludeIsMainSourceRegex: ''
#
IndentWidth: 4
IndentWrappedFunctionNames: true

# About Point
DerivePointerAlignment: false
PointerAlignment: Left

ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true

# About space
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceBeforeRangeBasedForLoopColon: false
SpaceInEmptyParentheses: false
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
#IndentWrappedFunctionNames: true
#
## About Point
#DerivePointerAlignment: false
#PointerAlignment: Left
PenaltyBreakBeforeMemberAccess: 1000
PenaltyBreakScopeResolution: 1000

#
#ReflowComments: true
#SortIncludes: true
#SortUsingDeclarations: true
#
## About space
#SpaceAfterCStyleCast: false
#SpaceAfterLogicalNot: false
#SpaceBeforeRangeBasedForLoopColon: false
#SpaceInEmptyParentheses: false
#SpacesInAngles: false
#SpacesInCStyleCastParentheses: false
#SpacesInContainerLiterals: false
#SpacesInParentheses: false
#SpacesInSquareBrackets: false
#
Standard: c++11
TabWidth: 4
UseTab: Never
Expand Down
139 changes: 98 additions & 41 deletions source/source_md/fire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
#endif
#include "source_base/timer.h"

FIRE::FIRE(const MD_para& mdp_in,
const bool cal_stress_in,
const bool init_vel,
const int my_rank_in,
const double force_thr_in,
MDCell& mdcell_in)
: MD_base(mdp_in, cal_stress_in, init_vel, my_rank_in, mdcell_in)
FIRE::FIRE(
const MD_para &mdp_in,
const bool cal_stress_in,
const bool init_vel,
const int my_rank_in,
const double force_thr_in,
MDCell &mdcell_in)
: MD_base(
mdp_in,
cal_stress_in,
init_vel,
my_rank_in,
mdcell_in)
{
force_thr = force_thr_in;
dt_max = -1.0;
Expand All @@ -32,11 +38,9 @@ FIRE::FIRE(const MD_para& mdp_in,
// force_thr = 1e-3;
}

FIRE::~FIRE()
{
}
FIRE::~FIRE() {}

void FIRE::setup(ModuleESolver::ESolver* p_esolver, const std::string& global_readin_dir, DomainDecomposition& decomp)
void FIRE::setup(ModuleESolver::ESolver *p_esolver, const std::string &global_readin_dir, DomainDecomposition &decomp)
{
ModuleBase::TITLE("FIRE", "setup");
ModuleBase::timer::start("FIRE", "setup");
Expand All @@ -50,7 +54,7 @@ void FIRE::setup(ModuleESolver::ESolver* p_esolver, const std::string& global_re
return;
}

void FIRE::first_half(std::ofstream& ofs)
void FIRE::first_half(std::ofstream &ofs)
{
ModuleBase::TITLE("FIRE", "first_half");
ModuleBase::timer::start("FIRE", "first_half");
Expand All @@ -66,7 +70,6 @@ void FIRE::first_half(std::ofstream& ofs)
return;
}


void FIRE::second_half(void)
{
ModuleBase::TITLE("FIRE", "second_half");
Expand All @@ -81,8 +84,7 @@ void FIRE::second_half(void)
return;
}


void FIRE::print_md(std::ofstream& ofs, const bool& cal_stress)
void FIRE::print_md(std::ofstream &ofs, const bool &cal_stress)
{
MD_base::print_md(ofs, cal_stress);

Expand All @@ -94,8 +96,7 @@ void FIRE::print_md(std::ofstream& ofs, const bool& cal_stress)
return;
}


void FIRE::write_restart(const std::string& global_out_dir)
void FIRE::write_restart(const std::string &global_out_dir)
{
if (!my_rank)
{
Expand All @@ -118,8 +119,7 @@ void FIRE::write_restart(const std::string& global_out_dir)
return;
}


void FIRE::restart(const std::string& global_readin_dir)
void FIRE::restart(const std::string &global_readin_dir)
{
bool ok = true;

Expand All @@ -137,16 +137,21 @@ void FIRE::restart(const std::string& global_readin_dir)
if (ok)
{
file >> step_rst_ >> md_tfirst >> alpha >> negative_count >> dt_max >> md_dt;
if(!file)
if (!file)
{
ok = false;
}
}
file.close();
}
}

#ifdef __MPI
MPI_Bcast(&ok, 1, MPI_C_BOOL, 0, mdcell.communicator());
MPI_Bcast(
&ok,
1,
MPI_C_BOOL,
0,
mdcell.communicator());
#endif

if (!ok)
Expand All @@ -155,12 +160,42 @@ void FIRE::restart(const std::string& global_readin_dir)
}

#ifdef __MPI
MPI_Bcast(&step_rst_, 1, MPI_INT, 0, mdcell.communicator());
MPI_Bcast(&md_tfirst, 1, MPI_DOUBLE, 0, mdcell.communicator());
MPI_Bcast(&alpha, 1, MPI_DOUBLE, 0, mdcell.communicator());
MPI_Bcast(&negative_count, 1, MPI_INT, 0, mdcell.communicator());
MPI_Bcast(&dt_max, 1, MPI_DOUBLE, 0, mdcell.communicator());
MPI_Bcast(&md_dt, 1, MPI_DOUBLE, 0, mdcell.communicator());
MPI_Bcast(
&step_rst_,
1,
MPI_INT,
0,
mdcell.communicator());
MPI_Bcast(
&md_tfirst,
1,
MPI_DOUBLE,
0,
mdcell.communicator());
MPI_Bcast(
&alpha,
1,
MPI_DOUBLE,
0,
mdcell.communicator());
MPI_Bcast(
&negative_count,
1,
MPI_INT,
0,
mdcell.communicator());
MPI_Bcast(
&dt_max,
1,
MPI_DOUBLE,
0,
mdcell.communicator());
MPI_Bcast(
&md_dt,
1,
MPI_DOUBLE,
0,
mdcell.communicator());
#endif

return;
Expand All @@ -172,7 +207,7 @@ void FIRE::check_force(void)

std::int64_t movable_dof = 0;

for (const LocalAtom& atom : mdcell.owned_atoms())
for (const LocalAtom &atom : mdcell.owned_atoms())
{
for (int j = 0; j < 3; ++j)
{
Expand All @@ -197,13 +232,25 @@ void FIRE::check_force(void)
}
}

#ifdef __MPI
#ifdef __MPI
if (mdcell.mpi_size() > 1)
{
double global_max = 0.0;
std::int64_t global_movable_dof = 0;
MPI_Allreduce(&max, &global_max, 1, MPI_DOUBLE, MPI_MAX, mdcell.communicator());
MPI_Allreduce(&movable_dof, &global_movable_dof, 1, MPI_INT64_T, MPI_SUM, mdcell.communicator());
MPI_Allreduce(
&max,
&global_max,
1,
MPI_DOUBLE,
MPI_MAX,
mdcell.communicator());
MPI_Allreduce(
&movable_dof,
&global_movable_dof,
1,
MPI_INT64_T,
MPI_SUM,
mdcell.communicator());
max = global_max;
movable_dof = global_movable_dof;
}
Expand All @@ -224,7 +271,6 @@ void FIRE::check_force(void)
return;
}


void FIRE::check_fire(void)
{
double P = 0.0;
Expand All @@ -242,7 +288,7 @@ void FIRE::check_fire(void)
// Compute P, |F| and |v| only on movable degrees of freedom.
// Fixed atoms/directions may have non-zero raw forces, but they should not
// affect the FIRE velocity projection or adaptive time-step control.
for (LocalAtom& atom : mdcell.owned_atoms())
for (LocalAtom &atom : mdcell.owned_atoms())
{
for (int j = 0; j < 3; ++j)
{
Expand All @@ -261,14 +307,26 @@ void FIRE::check_fire(void)
}
}

#ifdef __MPI
#ifdef __MPI
if (mdcell.mpi_size() > 1)
{
double local_values[3] = {P, sumforce, normvel};
double global_values[3] = {0.0, 0.0, 0.0};
std::int64_t global_movable_dof = 0;
MPI_Allreduce(local_values, global_values, 3, MPI_DOUBLE, MPI_SUM, mdcell.communicator());
MPI_Allreduce(&movable_dof, &global_movable_dof, 1, MPI_INT64_T, MPI_SUM, mdcell.communicator());
MPI_Allreduce(
local_values,
global_values,
3,
MPI_DOUBLE,
MPI_SUM,
mdcell.communicator());
MPI_Allreduce(
&movable_dof,
&global_movable_dof,
1,
MPI_INT64_T,
MPI_SUM,
mdcell.communicator());
P = global_values[0];
sumforce = global_values[1];
normvel = global_values[2];
Expand All @@ -289,7 +347,7 @@ void FIRE::check_fire(void)
// Avoid 0/0. In a truly converged case check_force() should stop the run.
if (sumforce > 0.0 && normvel > 0.0)
{
for (LocalAtom& atom : mdcell.owned_atoms())
for (LocalAtom &atom : mdcell.owned_atoms())
{
for (int j = 0; j < 3; ++j)
{
Expand All @@ -299,8 +357,7 @@ void FIRE::check_fire(void)
continue;
}

atom.vel[j] = (1.0 - alpha) * atom.vel[j]
+ alpha * atom.force[j] / sumforce * normvel;
atom.vel[j] = (1.0 - alpha) * atom.vel[j] + alpha * atom.force[j] / sumforce * normvel;
}
}
}
Expand All @@ -319,7 +376,7 @@ void FIRE::check_fire(void)
md_dt *= fdec;
negative_count = 0;

for (LocalAtom& atom : mdcell.owned_atoms())
for (LocalAtom &atom : mdcell.owned_atoms())
{
for (int j = 0; j < 3; ++j)
{
Expand Down
Loading
Loading