From 9d3dda930718e8ef5e6fa4f0183bf290dbe3cd18 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 8 Jun 2020 19:57:07 -0400 Subject: [PATCH 01/18] step version strings for next patch release --- doc/lammps.1 | 2 +- src/version.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/lammps.1 b/doc/lammps.1 index d9af339e0a..ace2ee2dce 100644 --- a/doc/lammps.1 +++ b/doc/lammps.1 @@ -1,4 +1,4 @@ -.TH LAMMPS "2 June 2020" "2020-06-02" +.TH LAMMPS "9 June 2020" "2020-06-09" .SH NAME .B LAMMPS \- Molecular Dynamics Simulator. diff --git a/src/version.h b/src/version.h index 301c39539e..07a6f4ee00 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define LAMMPS_VERSION "2 Jun 2020" +#define LAMMPS_VERSION "9 Jun 2020" From 59353513e08953997ecbf919b17a0fc1ef9c083f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 9 Jun 2020 19:02:27 -0400 Subject: [PATCH 02/18] move date --- doc/lammps.1 | 2 +- src/version.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/lammps.1 b/doc/lammps.1 index ace2ee2dce..1cd579fa7a 100644 --- a/doc/lammps.1 +++ b/doc/lammps.1 @@ -1,4 +1,4 @@ -.TH LAMMPS "9 June 2020" "2020-06-09" +.TH LAMMPS "10 June 2020" "2020-06-10" .SH NAME .B LAMMPS \- Molecular Dynamics Simulator. diff --git a/src/version.h b/src/version.h index 07a6f4ee00..58e96152f7 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define LAMMPS_VERSION "9 Jun 2020" +#define LAMMPS_VERSION "10 Jun 2020" From 554905ba369f727d7906d05af22aa912986ca2c4 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 11 Jun 2020 23:11:44 -0400 Subject: [PATCH 03/18] move version date one more time --- doc/lammps.1 | 2 +- src/version.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/lammps.1 b/doc/lammps.1 index 1cd579fa7a..0bdb8d9666 100644 --- a/doc/lammps.1 +++ b/doc/lammps.1 @@ -1,4 +1,4 @@ -.TH LAMMPS "10 June 2020" "2020-06-10" +.TH LAMMPS "12 June 2020" "2020-06-12" .SH NAME .B LAMMPS \- Molecular Dynamics Simulator. diff --git a/src/version.h b/src/version.h index 58e96152f7..698dc76be2 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define LAMMPS_VERSION "10 Jun 2020" +#define LAMMPS_VERSION "12 Jun 2020" From cf5fa3959cf33425a6495d137c0f793fb21dfcd8 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 12 Jun 2020 21:42:17 -0400 Subject: [PATCH 04/18] Add first version of whitespace utility --- cmake/CMakeLists.txt | 1 + cmake/Modules/CodingStandard.cmake | 21 +++++ tools/coding_standard/whitespace.py | 132 ++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+) create mode 100644 cmake/Modules/CodingStandard.cmake create mode 100644 tools/coding_standard/whitespace.py diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 2407d03a80..c0563565e0 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -676,6 +676,7 @@ endif() include(Testing) include(CodeCoverage) +include(CodingStandard) ############################################################################### # Print package summary diff --git a/cmake/Modules/CodingStandard.cmake b/cmake/Modules/CodingStandard.cmake new file mode 100644 index 0000000000..d7440fba9d --- /dev/null +++ b/cmake/Modules/CodingStandard.cmake @@ -0,0 +1,21 @@ +if(CMAKE_VERSION VERSION_LESS 3.12) + find_package(PythonInterp) # Deprecated since version 3.12 + if(PYTHONINTERP_FOUND) + set(Python_EXECUTABLE ${PYTHON_EXECUTABLE}) + endif() +else() + find_package(Python COMPONENTS Interpreter) +endif() + +if (Python_EXECUTABLE) + add_custom_target( + check-whitespace + ${Python_EXECUTABLE} ${LAMMPS_TOOLS_DIR}/coding_standard/whitespace.py . + WORKING_DIRECTORY ${LAMMPS_DIR} + COMMENT "Check for whitespace errors") + add_custom_target( + fix-whitespace + ${Python_EXECUTABLE} ${LAMMPS_TOOLS_DIR}/coding_standard/whitespace.py -f . + WORKING_DIRECTORY ${LAMMPS_DIR} + COMMENT "Fix whitespace errors") +endif() diff --git a/tools/coding_standard/whitespace.py b/tools/coding_standard/whitespace.py new file mode 100644 index 0000000000..f9923893a0 --- /dev/null +++ b/tools/coding_standard/whitespace.py @@ -0,0 +1,132 @@ +#!/usr/bin/env python3 +# Utility for detecting and fixing whitespace issues in LAMMPS +# +# Written by Richard Berger (Temple University) +import os +import glob +import re +import yaml +import argparse +import shutil + +DEFAULT_CONFIG = """ +recursive: true +include: + - cmake/** + - doc + - doc/src/** + - python + - src/** +patterns: + - ".gitignore" + - "README" + - "requirements.txt" + - "*.c" + - "*.cpp" + - "*.h" + - "*.sh" + - "*.py" + - "*.md" + - "*.rst" + - "*.cmake" +""" + +def check_trailing_whitespace(f): + pattern = re.compile(r'\s+\n$') + last_line = "\n" + lineno = 1 + errors = set() + + for line in f: + if pattern.match(line): + errors.add(lineno) + last_line = line + lineno += 1 + + return errors, last_line + +def check_file(path): + encoding = 'UTF-8' + last_line = "\n" + whitespace_errors = set() + try: + with open(path, 'r') as f: + whitespace_errors, last_line = check_trailing_whitespace(f) + except UnicodeDecodeError: + encoding = 'ISO-8859-1' + try: + with open(path, 'r', encoding=encoding) as f: + whitespace_errors, last_line = check_trailing_whitespace(f) + except Exception: + encoding = 'unknown' + + return { + 'whitespace_errors': whitespace_errors, + 'encoding': encoding, + 'eof_error': not last_line.endswith('\n') + } + +def fix_file(path, check_result): + newfile = path + ".modified" + with open(newfile, 'w', encoding='UTF-8') as out: + with open(path, 'r', encoding=check_result['encoding']) as src: + for line in src: + print(line.rstrip(), file=out) + shutil.move(newfile, path) + +def check_folder(directory, config, fix=False, verbose=False): + files = [] + + for base_path in config['include']: + for pattern in config['patterns']: + path = os.path.join(directory, base_path, pattern) + files += glob.glob(path, recursive=config['recursive']) + + for f in files: + path = os.path.normpath(f) + + if verbose: + print("Checking file:", path) + + result = check_file(path) + + has_resolvable_errors = False + + for lineno in result['whitespace_errors']: + print("[Error] Trailing whitespace @ {}:{}".format(path, lineno)) + has_resolvable_errors = True + + if result['eof_error']: + print("[Error] Missing newline at end of file @ {}".format(path)) + has_resolvable_errors = True + + if result['encoding'] == 'unknown': + print("[Error] Unknown text encoding @ {}".format(path)) + has_resolvable_errors = False + elif result['encoding'] == 'ISO-8859-1': + print("[Error] Found ISO-8859-1 encoding instead of UTF-8 @ {}".format(path)) + has_resolvable_errors = True + + if has_resolvable_errors and fix: + print("Applying automatic fixes to file:", path) + fix_file(path, result) + + +def main(): + parser = argparse.ArgumentParser(description='Utility for detecting and fixing whitespace issues in LAMMPS') + parser.add_argument('-c', '--config', metavar='CONFIG_FILE', help='location of a optional configuration file') + parser.add_argument('-f', '--fix', action='store_true', help='automatically fix common issues') + parser.add_argument('-v', '--verbose', action='store_true', help='verbose output') + parser.add_argument('DIRECTORY', help='directory that should be checked') + args = parser.parse_args() + + if args.config: + with open(args.config, 'r') as cfile: + config = yaml.load(cfile, Loader=yaml.FullLoader) + else: + config = yaml.load(DEFAULT_CONFIG, Loader=yaml.FullLoader) + + check_folder(args.DIRECTORY, config, args.fix, args.verbose) + +if __name__ == "__main__": + main() From dfc250339ea0559c2e048fac47f91a08f1f78cf3 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 12 Jun 2020 23:49:47 -0400 Subject: [PATCH 05/18] move release date (again) --- doc/lammps.1 | 2 +- src/version.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/lammps.1 b/doc/lammps.1 index 0bdb8d9666..4624403a67 100644 --- a/doc/lammps.1 +++ b/doc/lammps.1 @@ -1,4 +1,4 @@ -.TH LAMMPS "12 June 2020" "2020-06-12" +.TH LAMMPS "15 June 2020" "2020-06-15" .SH NAME .B LAMMPS \- Molecular Dynamics Simulator. diff --git a/src/version.h b/src/version.h index 698dc76be2..f444ce25be 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define LAMMPS_VERSION "12 Jun 2020" +#define LAMMPS_VERSION "15 Jun 2020" From 4d62ea98cfbf382df8116146a72810b83bf6d2a9 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 13 Jun 2020 01:51:16 -0400 Subject: [PATCH 06/18] add clang-format configuration file for the unittest tree --- unittest/.clang-format | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 unittest/.clang-format diff --git a/unittest/.clang-format b/unittest/.clang-format new file mode 100644 index 0000000000..91df2e925e --- /dev/null +++ b/unittest/.clang-format @@ -0,0 +1,22 @@ +--- +Language: Cpp +BasedOnStyle: LLVM +AccessModifierOffset: -4 +AlignEscapedNewlines: Left +AllowShortFunctionsOnASingleLine: Inline +AllowShortLambdasOnASingleLine: None +AllowShortIfStatementsOnASingleLine: WithoutElse +BraceWrapping: + AfterFunction: true +BreakBeforeBraces: Custom +BreakInheritanceList: AfterColon +BreakConstructorInitializers: AfterColon +ColumnLimit: 100 +IndentCaseLabels: true +IndentWidth: 4 +ObjCBlockIndentWidth: 4 +PenaltyBreakAssignment: 4 +Standard: Cpp11 +TabWidth: 4 +UseTab: Never +... From 3db944deccad66ad5a75b1ae3c39843e5ce65541 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 13 Jun 2020 01:54:58 -0400 Subject: [PATCH 07/18] apply clang-format settings to the c++ sources in the unittest tree --- unittest/force-styles/angle_style.cpp | 436 +++++------ unittest/force-styles/bond_style.cpp | 577 +++++++------- unittest/force-styles/error_stats.cpp | 27 +- unittest/force-styles/error_stats.h | 8 +- unittest/force-styles/pair_style.cpp | 741 ++++++++---------- unittest/force-styles/test_config.h | 39 +- unittest/force-styles/test_config_reader.cpp | 171 ++-- unittest/force-styles/test_config_reader.h | 56 +- unittest/force-styles/test_main.cpp | 29 +- unittest/force-styles/test_main.h | 14 +- unittest/force-styles/yaml_reader.h | 151 ++-- unittest/force-styles/yaml_writer.cpp | 94 +-- unittest/force-styles/yaml_writer.h | 8 +- .../test_eim_potential_file_reader.cpp | 80 +- .../formats/test_potential_file_reader.cpp | 66 +- unittest/utils/test_fmtlib.cpp | 73 +- unittest/utils/test_tokenizer.cpp | 55 +- unittest/utils/test_utils.cpp | 204 +++-- 18 files changed, 1400 insertions(+), 1429 deletions(-) diff --git a/unittest/force-styles/angle_style.cpp b/unittest/force-styles/angle_style.cpp index f1825d5a57..a1a618bbca 100644 --- a/unittest/force-styles/angle_style.cpp +++ b/unittest/force-styles/angle_style.cpp @@ -13,32 +13,32 @@ // unit tests for angle styles intended for molecular systems -#include "yaml_reader.h" -#include "yaml_writer.h" #include "error_stats.h" #include "test_config.h" #include "test_config_reader.h" #include "test_main.h" +#include "yaml_reader.h" +#include "yaml_writer.h" -#include "gtest/gtest.h" #include "gmock/gmock.h" +#include "gtest/gtest.h" -#include "lammps.h" +#include "angle.h" #include "atom.h" -#include "modify.h" #include "compute.h" #include "force.h" -#include "angle.h" #include "info.h" #include "input.h" +#include "lammps.h" +#include "modify.h" #include "universe.h" -#include -#include -#include -#include #include +#include +#include +#include #include +#include #include #include @@ -46,12 +46,13 @@ #include #include -using ::testing::StartsWith; using ::testing::HasSubstr; +using ::testing::StartsWith; using namespace LAMMPS_NS; -static void delete_file(const std::string & filename) { +static void delete_file(const std::string &filename) +{ remove(filename.c_str()); }; @@ -63,9 +64,7 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) delete lmp; } -LAMMPS *init_lammps(int argc, char **argv, - const TestConfig &cfg, - const bool newton=true) +LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool newton = true) { LAMMPS *lmp; @@ -74,7 +73,7 @@ LAMMPS *init_lammps(int argc, char **argv, // check if prerequisite styles are available Info *info = new Info(lmp); int nfail = 0; - for (auto& prerequisite : cfg.prerequisites) { + for (auto &prerequisite : cfg.prerequisites) { std::string style = prerequisite.second; // this is a test for angle styles, so if the suffixed @@ -86,19 +85,19 @@ LAMMPS *init_lammps(int argc, char **argv, } } - if (!info->has_style(prerequisite.first,style)) ++nfail; + if (!info->has_style(prerequisite.first, style)) ++nfail; } if (nfail > 0) { delete info; - cleanup_lammps(lmp,cfg); + cleanup_lammps(lmp, cfg); return nullptr; } // utility lambdas to improve readability - auto command = [&](const std::string & line) { + auto command = [&](const std::string &line) { lmp->input->one(line.c_str()); }; - auto parse_input_script = [&](const std::string & filename) { + auto parse_input_script = [&](const std::string &filename) { lmp->input->file(filename.c_str()); }; @@ -110,7 +109,7 @@ LAMMPS *init_lammps(int argc, char **argv, command("variable input_dir index " + INPUT_FOLDER); - for (auto& pre_command : cfg.pre_commands) { + for (auto &pre_command : cfg.pre_commands) { command(pre_command); } @@ -119,11 +118,11 @@ LAMMPS *init_lammps(int argc, char **argv, command("angle_style " + cfg.angle_style); - for (auto& angle_coeff : cfg.angle_coeff) { + for (auto &angle_coeff : cfg.angle_coeff) { command("angle_coeff " + angle_coeff); } - for (auto& post_command : cfg.post_commands) { + for (auto &post_command : cfg.post_commands) { command(post_command); } @@ -138,7 +137,7 @@ LAMMPS *init_lammps(int argc, char **argv, void run_lammps(LAMMPS *lmp) { // utility lambda to improve readability - auto command = [&](const std::string & line) { + auto command = [&](const std::string &line) { lmp->input->one(line.c_str()); }; @@ -153,7 +152,7 @@ void run_lammps(LAMMPS *lmp) void restart_lammps(LAMMPS *lmp, const TestConfig &cfg) { // utility lambda to improve readability - auto command = [&](const std::string & line) { + auto command = [&](const std::string &line) { lmp->input->one(line.c_str()); }; @@ -164,14 +163,13 @@ void restart_lammps(LAMMPS *lmp, const TestConfig &cfg) command("angle_style " + cfg.angle_style); } - if ((cfg.angle_style.substr(0,6) == "hybrid") - || !lmp->force->angle->writedata) { - for (auto& angle_coeff : cfg.angle_coeff) { + if ((cfg.angle_style.substr(0, 6) == "hybrid") || !lmp->force->angle->writedata) { + for (auto &angle_coeff : cfg.angle_coeff) { command("angle_coeff " + angle_coeff); } } - for (auto& post_command : cfg.post_commands) { + for (auto &post_command : cfg.post_commands) { command(post_command); } @@ -181,10 +179,10 @@ void restart_lammps(LAMMPS *lmp, const TestConfig &cfg) void data_lammps(LAMMPS *lmp, const TestConfig &cfg) { // utility lambdas to improve readability - auto command = [&](const std::string & line) { + auto command = [&](const std::string &line) { lmp->input->one(line.c_str()); }; - auto parse_input_script = [&](const std::string & filename) { + auto parse_input_script = [&](const std::string &filename) { lmp->input->file(filename.c_str()); }; @@ -194,7 +192,7 @@ void data_lammps(LAMMPS *lmp, const TestConfig &cfg) command("variable newton_bond delete"); command("variable newton_bond index on"); - for (auto& pre_command : cfg.pre_commands) { + for (auto &pre_command : cfg.pre_commands) { command(pre_command); } @@ -204,10 +202,10 @@ void data_lammps(LAMMPS *lmp, const TestConfig &cfg) std::string input_file = INPUT_FOLDER + PATH_SEP + cfg.input_file; parse_input_script(input_file); - for (auto& angle_coeff : cfg.angle_coeff) { + for (auto &angle_coeff : cfg.angle_coeff) { command("angle_coeff " + angle_coeff); } - for (auto& post_command : cfg.post_commands) { + for (auto &post_command : cfg.post_commands) { command(post_command); } command("run 0 post no"); @@ -218,16 +216,15 @@ void data_lammps(LAMMPS *lmp, const TestConfig &cfg) void generate_yaml_file(const char *outfile, const TestConfig &config) { // initialize system geometry - const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite" }; + const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"}; char **argv = (char **)args; - int argc = sizeof(args)/sizeof(char *); - LAMMPS *lmp = init_lammps(argc,argv,config); + int argc = sizeof(args) / sizeof(char *); + LAMMPS *lmp = init_lammps(argc, argv, config); if (!lmp) { std::cerr << "One or more prerequisite styles are not available " - "in this LAMMPS configuration:\n"; - for (auto& prerequisite : config.prerequisites) { - std::cerr << prerequisite.first << "_style " - << prerequisite.second << "\n"; + "in this LAMMPS configuration:\n"; + for (auto &prerequisite : config.prerequisites) { + std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n"; } return; } @@ -245,7 +242,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // date_generated std::time_t now = time(NULL); block = ctime(&now); - block = block.substr(0,block.find("\n")-1); + block = block.substr(0, block.find("\n") - 1); writer.emit("date_generated", block); // epsilon @@ -253,21 +250,21 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // prerequisites block.clear(); - for (auto& prerequisite : config.prerequisites) { + for (auto &prerequisite : config.prerequisites) { block += prerequisite.first + " " + prerequisite.second + "\n"; } writer.emit_block("prerequisites", block); // pre_commands block.clear(); - for (auto& command : config.pre_commands) { + for (auto &command : config.pre_commands) { block += command + "\n"; } writer.emit_block("pre_commands", block); // post_commands block.clear(); - for (auto& command : config.post_commands) { + for (auto &command : config.post_commands) { block += command + "\n"; } writer.emit_block("post_commands", block); @@ -280,7 +277,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // angle_coeff block.clear(); - for (auto& angle_coeff : config.angle_coeff) { + for (auto &angle_coeff : config.angle_coeff) { block += angle_coeff + "\n"; } writer.emit_block("angle_coeff", block); @@ -288,15 +285,15 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // equilibrium angle std::stringstream eqstr; eqstr << lmp->atom->nangletypes; - for (int i=0; i < lmp->atom->nangletypes; ++i) { - eqstr << " " << lmp->force->angle->equilibrium_angle(i+1); + for (int i = 0; i < lmp->atom->nangletypes; ++i) { + eqstr << " " << lmp->force->angle->equilibrium_angle(i + 1); } writer.emit("equilibrium", eqstr.str()); // extract block.clear(); std::stringstream outstr; - for (auto& data : config.extract) { + for (auto &data : config.extract) { outstr << data.first << " " << data.second << std::endl; } writer.emit_block("extract", outstr.str()); @@ -309,17 +306,17 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // init_stress double *stress = lmp->force->angle->virial; - snprintf(buf,bufsize,"% 23.16e % 23.16e % 23.16e % 23.16e % 23.16e % 23.16e", - stress[0],stress[1],stress[2],stress[3],stress[4],stress[5]); + snprintf(buf, bufsize, "% 23.16e % 23.16e % 23.16e % 23.16e % 23.16e % 23.16e", stress[0], + stress[1], stress[2], stress[3], stress[4], stress[5]); writer.emit_block("init_stress", buf); // init_forces block.clear(); double **f = lmp->atom->f; tagint *tag = lmp->atom->tag; - for (int i=0; i < natoms; ++i) { - snprintf(buf,bufsize,"% 3d % 23.16e % 23.16e % 23.16e\n", - (int)tag[i], f[i][0], f[i][1], f[i][2]); + for (int i = 0; i < natoms; ++i) { + snprintf(buf, bufsize, "% 3d % 23.16e % 23.16e % 23.16e\n", (int)tag[i], f[i][0], f[i][1], + f[i][2]); block += buf; } writer.emit_block("init_forces", block); @@ -332,40 +329,40 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // run_stress stress = lmp->force->angle->virial; - snprintf(buf,bufsize,"% 23.16e % 23.16e % 23.16e % 23.16e % 23.16e % 23.16e", - stress[0],stress[1],stress[2],stress[3],stress[4],stress[5]); + snprintf(buf, bufsize, "% 23.16e % 23.16e % 23.16e % 23.16e % 23.16e % 23.16e", stress[0], + stress[1], stress[2], stress[3], stress[4], stress[5]); writer.emit_block("run_stress", buf); block.clear(); f = lmp->atom->f; tag = lmp->atom->tag; - for (int i=0; i < natoms; ++i) { - snprintf(buf,bufsize,"% 3d % 23.16e % 23.16e % 23.16e\n", - (int)tag[i], f[i][0], f[i][1], f[i][2]); + for (int i = 0; i < natoms; ++i) { + snprintf(buf, bufsize, "% 3d % 23.16e % 23.16e % 23.16e\n", (int)tag[i], f[i][0], f[i][1], + f[i][2]); block += buf; } writer.emit_block("run_forces", block); - cleanup_lammps(lmp,config); + cleanup_lammps(lmp, config); return; } -TEST(AngleStyle, plain) { - const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite" }; +TEST(AngleStyle, plain) +{ + const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"}; char **argv = (char **)args; - int argc = sizeof(args)/sizeof(char *); + int argc = sizeof(args) / sizeof(char *); ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc,argv,test_config,true); + LAMMPS *lmp = init_lammps(argc, argv, test_config, true); std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; if (!lmp) { std::cerr << "One or more prerequisite styles are not available " - "in this LAMMPS configuration:\n"; - for (auto& prerequisite : test_config.prerequisites) { - std::cerr << prerequisite.first << "_style " - << prerequisite.second << "\n"; + "in this LAMMPS configuration:\n"; + for (auto &prerequisite : test_config.prerequisites) { + std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n"; } GTEST_SKIP(); } @@ -375,22 +372,21 @@ TEST(AngleStyle, plain) { // abort if running in parallel and not all atoms are local const int nlocal = lmp->atom->nlocal; - ASSERT_EQ(lmp->atom->natoms,nlocal); + ASSERT_EQ(lmp->atom->natoms, nlocal); double epsilon = test_config.epsilon; - double **f=lmp->atom->f; - tagint *tag=lmp->atom->tag; + double **f = lmp->atom->f; + tagint *tag = lmp->atom->tag; ErrorStats stats; stats.reset(); const std::vector &f_ref = test_config.init_forces; - ASSERT_EQ(nlocal+1,f_ref.size()); - for (int i=0; i < nlocal; ++i) { + ASSERT_EQ(nlocal + 1, f_ref.size()); + for (int i = 0; i < nlocal; ++i) { EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); } - if (print_stats) - std::cerr << "init_forces stats, newton on: " << stats << std::endl; + if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; Angle *angle = lmp->force->angle; double *stress = angle->virial; @@ -401,13 +397,11 @@ TEST(AngleStyle, plain) { EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) - std::cerr << "init_stress stats, newton on: " << stats << std::endl; + if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl; stats.reset(); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon); - if (print_stats) - std::cerr << "init_energy stats, newton on: " << stats << std::endl; + if (print_stats) std::cerr << "init_energy stats, newton on: " << stats << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); run_lammps(lmp); @@ -416,15 +410,14 @@ TEST(AngleStyle, plain) { f = lmp->atom->f; stress = angle->virial; const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal+1,f_run.size()); + ASSERT_EQ(nlocal + 1, f_run.size()); stats.reset(); - for (int i=0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10*epsilon); + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); } - if (print_stats) - std::cerr << "run_forces stats, newton on: " << stats << std::endl; + if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; stress = angle->virial; stats.reset(); @@ -434,52 +427,47 @@ TEST(AngleStyle, plain) { EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) - std::cerr << "run_stress stats, newton on: " << stats << std::endl; + if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; stats.reset(); int id = lmp->modify->find_compute("sum"); double energy = lmp->modify->compute[id]->compute_scalar(); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.run_energy, epsilon); EXPECT_FP_LE_WITH_EPS(angle->energy, energy, epsilon); - if (print_stats) - std::cerr << "run_energy stats, newton on: " << stats << std::endl; + if (print_stats) std::cerr << "run_energy stats, newton on: " << stats << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); - cleanup_lammps(lmp,test_config); - lmp = init_lammps(argc,argv,test_config,false); + cleanup_lammps(lmp, test_config); + lmp = init_lammps(argc, argv, test_config, false); if (!verbose) ::testing::internal::GetCapturedStdout(); // skip over these tests if newton bond is forced to be on if (lmp->force->newton_bond == 0) { - f=lmp->atom->f; - tag=lmp->atom->tag; + f = lmp->atom->f; + tag = lmp->atom->tag; stats.reset(); - for (int i=0; i < nlocal; ++i) { + for (int i = 0; i < nlocal; ++i) { EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); } - if (print_stats) - std::cerr << "init_forces stats, newton off:" << stats << std::endl; + if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; angle = lmp->force->angle; stress = angle->virial; stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 2*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 2*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 2*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 2*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 2*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 2*epsilon); - if (print_stats) - std::cerr << "init_stress stats, newton off:" << stats << std::endl; + EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 2 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 2 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 2 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 2 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 2 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 2 * epsilon); + if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; stats.reset(); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon); - if (print_stats) - std::cerr << "init_energy stats, newton off:" << stats << std::endl; + if (print_stats) std::cerr << "init_energy stats, newton off:" << stats << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); run_lammps(lmp); @@ -488,13 +476,12 @@ TEST(AngleStyle, plain) { f = lmp->atom->f; stress = angle->virial; stats.reset(); - for (int i=0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10*epsilon); + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); } - if (print_stats) - std::cerr << "run_forces stats, newton off:" << stats << std::endl; + if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; stress = angle->virial; stats.reset(); @@ -504,33 +491,30 @@ TEST(AngleStyle, plain) { EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) - std::cerr << "run_stress stats, newton off:" << stats << std::endl; + if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; stats.reset(); id = lmp->modify->find_compute("sum"); energy = lmp->modify->compute[id]->compute_scalar(); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.run_energy, epsilon); EXPECT_FP_LE_WITH_EPS(angle->energy, energy, epsilon); - if (print_stats) - std::cerr << "run_energy stats, newton off:" << stats << std::endl; + if (print_stats) std::cerr << "run_energy stats, newton off:" << stats << std::endl; } if (!verbose) ::testing::internal::CaptureStdout(); restart_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f=lmp->atom->f; - tag=lmp->atom->tag; + f = lmp->atom->f; + tag = lmp->atom->tag; stats.reset(); - ASSERT_EQ(nlocal+1,f_ref.size()); - for (int i=0; i < nlocal; ++i) { + ASSERT_EQ(nlocal + 1, f_ref.size()); + for (int i = 0; i < nlocal; ++i) { EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); } - if (print_stats) - std::cerr << "restart_forces stats:" << stats << std::endl; + if (print_stats) std::cerr << "restart_forces stats:" << stats << std::endl; angle = lmp->force->angle; stress = angle->virial; @@ -541,29 +525,26 @@ TEST(AngleStyle, plain) { EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) - std::cerr << "restart_stress stats:" << stats << std::endl; + if (print_stats) std::cerr << "restart_stress stats:" << stats << std::endl; stats.reset(); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon); - if (print_stats) - std::cerr << "restart_energy stats:" << stats << std::endl; + if (print_stats) std::cerr << "restart_energy stats:" << stats << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); data_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f=lmp->atom->f; - tag=lmp->atom->tag; + f = lmp->atom->f; + tag = lmp->atom->tag; stats.reset(); - ASSERT_EQ(nlocal+1,f_ref.size()); - for (int i=0; i < nlocal; ++i) { + ASSERT_EQ(nlocal + 1, f_ref.size()); + for (int i = 0; i < nlocal; ++i) { EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); } - if (print_stats) - std::cerr << "data_forces stats:" << stats << std::endl; + if (print_stats) std::cerr << "data_forces stats:" << stats << std::endl; angle = lmp->force->angle; stress = angle->virial; @@ -574,37 +555,35 @@ TEST(AngleStyle, plain) { EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) - std::cerr << "data_stress stats:" << stats << std::endl; + if (print_stats) std::cerr << "data_stress stats:" << stats << std::endl; stats.reset(); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon); - if (print_stats) - std::cerr << "data_energy stats:" << stats << std::endl; + if (print_stats) std::cerr << "data_energy stats:" << stats << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); - cleanup_lammps(lmp,test_config); + cleanup_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); }; -TEST(AngleStyle, omp) { +TEST(AngleStyle, omp) +{ if (!LAMMPS::is_installed_pkg("USER-OMP")) GTEST_SKIP(); - const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", - "-nocite", "-pk", "omp", "4", "-sf", "omp"}; + const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite", + "-pk", "omp", "4", "-sf", "omp"}; char **argv = (char **)args; - int argc = sizeof(args)/sizeof(char *); + int argc = sizeof(args) / sizeof(char *); ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc,argv,test_config,true); + LAMMPS *lmp = init_lammps(argc, argv, test_config, true); std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; if (!lmp) { std::cerr << "One or more prerequisite styles with /omp suffix\n" - "are not available in this LAMMPS configuration:\n"; - for (auto& prerequisite : test_config.prerequisites) { - std::cerr << prerequisite.first << "_style " - << prerequisite.second << "\n"; + "are not available in this LAMMPS configuration:\n"; + for (auto &prerequisite : test_config.prerequisites) { + std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n"; } GTEST_SKIP(); } @@ -614,40 +593,37 @@ TEST(AngleStyle, omp) { // abort if running in parallel and not all atoms are local const int nlocal = lmp->atom->nlocal; - ASSERT_EQ(lmp->atom->natoms,nlocal); + ASSERT_EQ(lmp->atom->natoms, nlocal); // relax error a bit for USER-OMP package - double epsilon = 5.0*test_config.epsilon; - double **f=lmp->atom->f; - tagint *tag=lmp->atom->tag; + double epsilon = 5.0 * test_config.epsilon; + double **f = lmp->atom->f; + tagint *tag = lmp->atom->tag; const std::vector &f_ref = test_config.init_forces; ErrorStats stats; stats.reset(); - for (int i=0; i < nlocal; ++i) { + for (int i = 0; i < nlocal; ++i) { EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); } - if (print_stats) - std::cerr << "init_forces stats, newton on: " << stats << std::endl; + if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; Angle *angle = lmp->force->angle; double *stress = angle->virial; stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10*epsilon); - if (print_stats) - std::cerr << "init_stress stats, newton on: " << stats << std::endl; + EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); + if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl; stats.reset(); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon); - if (print_stats) - std::cerr << "init_energy stats, newton on: " << stats << std::endl; + if (print_stats) std::cerr << "init_energy stats, newton on: " << stats << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); run_lammps(lmp); @@ -656,26 +632,24 @@ TEST(AngleStyle, omp) { f = lmp->atom->f; stress = angle->virial; const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal+1,f_run.size()); + ASSERT_EQ(nlocal + 1, f_run.size()); stats.reset(); - for (int i=0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10*epsilon); + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); } - if (print_stats) - std::cerr << "run_forces stats, newton on: " << stats << std::endl; + if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; stress = angle->virial; stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10*epsilon); - if (print_stats) - std::cerr << "run_stress stats, newton on: " << stats << std::endl; + EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); + if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; stats.reset(); int id = lmp->modify->find_compute("sum"); @@ -683,46 +657,42 @@ TEST(AngleStyle, omp) { EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.run_energy, epsilon); // TODO: this is currently broken for USER-OMP with angle style hybrid // needs to be fixed in the main code somewhere. Not sure where, though. - if (test_config.angle_style.substr(0,6) != "hybrid") + if (test_config.angle_style.substr(0, 6) != "hybrid") EXPECT_FP_LE_WITH_EPS(angle->energy, energy, epsilon); - if (print_stats) - std::cerr << "run_energy stats, newton on: " << stats << std::endl; + if (print_stats) std::cerr << "run_energy stats, newton on: " << stats << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); - cleanup_lammps(lmp,test_config); - lmp = init_lammps(argc,argv,test_config,false); + cleanup_lammps(lmp, test_config); + lmp = init_lammps(argc, argv, test_config, false); if (!verbose) ::testing::internal::GetCapturedStdout(); // skip over these tests if newton bond is forced to be on if (lmp->force->newton_bond == 0) { - f=lmp->atom->f; - tag=lmp->atom->tag; + f = lmp->atom->f; + tag = lmp->atom->tag; stats.reset(); - for (int i=0; i < nlocal; ++i) { + for (int i = 0; i < nlocal; ++i) { EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); } - if (print_stats) - std::cerr << "init_forces stats, newton off:" << stats << std::endl; + if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; angle = lmp->force->angle; stress = angle->virial; stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10*epsilon); - if (print_stats) - std::cerr << "init_stress stats, newton off:" << stats << std::endl; + EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); + if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; stats.reset(); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon); - if (print_stats) - std::cerr << "init_energy stats, newton off:" << stats << std::endl; + if (print_stats) std::cerr << "init_energy stats, newton off:" << stats << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); run_lammps(lmp); @@ -730,24 +700,22 @@ TEST(AngleStyle, omp) { f = lmp->atom->f; stats.reset(); - for (int i=0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10*epsilon); + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); } - if (print_stats) - std::cerr << "run_forces stats, newton off:" << stats << std::endl; + if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; stress = angle->virial; stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10*epsilon); - if (print_stats) - std::cerr << "run_stress stats, newton off:" << stats << std::endl; + EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); + if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; stats.reset(); id = lmp->modify->find_compute("sum"); @@ -755,33 +723,32 @@ TEST(AngleStyle, omp) { EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.run_energy, epsilon); // TODO: this is currently broken for USER-OMP with angle style hybrid // needs to be fixed in the main code somewhere. Not sure where, though. - if (test_config.angle_style.substr(0,6) != "hybrid") + if (test_config.angle_style.substr(0, 6) != "hybrid") EXPECT_FP_LE_WITH_EPS(angle->energy, energy, epsilon); - if (print_stats) - std::cerr << "run_energy stats, newton off:" << stats << std::endl; + if (print_stats) std::cerr << "run_energy stats, newton off:" << stats << std::endl; } if (!verbose) ::testing::internal::CaptureStdout(); - cleanup_lammps(lmp,test_config); + cleanup_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); }; -TEST(AngleStyle, single) { - const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite" }; +TEST(AngleStyle, single) +{ + const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"}; char **argv = (char **)args; - int argc = sizeof(args)/sizeof(char *); + int argc = sizeof(args) / sizeof(char *); // create a LAMMPS instance with standard settings to detect the number of atom types if (!verbose) ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc,argv,test_config); + LAMMPS *lmp = init_lammps(argc, argv, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); if (!lmp) { std::cerr << "One or more prerequisite styles are not available " - "in this LAMMPS configuration:\n"; - for (auto& prerequisite : test_config.prerequisites) { - std::cerr << prerequisite.first << "_style " - << prerequisite.second << "\n"; + "in this LAMMPS configuration:\n"; + for (auto &prerequisite : test_config.prerequisites) { + std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n"; } GTEST_SKIP(); } @@ -792,13 +759,13 @@ TEST(AngleStyle, single) { if (molecular != 1) { std::cerr << "Only simple molecular atom styles are supported\n"; if (!verbose) ::testing::internal::CaptureStdout(); - cleanup_lammps(lmp,test_config); + cleanup_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); GTEST_SKIP(); } // utility lambda to improve readability - auto command = [&](const std::string & line) { + auto command = [&](const std::string &line) { lmp->input->one(line.c_str()); }; @@ -810,7 +777,7 @@ TEST(AngleStyle, single) { command("variable input_dir index " + INPUT_FOLDER); - for (auto& pre_command : test_config.pre_commands) { + for (auto &pre_command : test_config.pre_commands) { command(pre_command); } @@ -827,7 +794,7 @@ TEST(AngleStyle, single) { char buf[10]; std::string cmd("create_box 1 box"); cmd += " angle/types "; - snprintf(buf,10,"%d",nangletypes); + snprintf(buf, 10, "%d", nangletypes); cmd += buf; cmd += " extra/angle/per/atom 2"; cmd += " extra/special/per/atom 2"; @@ -839,7 +806,7 @@ TEST(AngleStyle, single) { command("angle_style " + test_config.angle_style); Angle *angle = lmp->force->angle; - for (auto& angle_coeff : test_config.angle_coeff) { + for (auto &angle_coeff : test_config.angle_coeff) { command("angle_coeff " + angle_coeff); } @@ -850,7 +817,7 @@ TEST(AngleStyle, single) { command("create_atoms 1 single 5.0 0.75 0.4 units box"); command("create_bonds single/angle 1 1 2 3"); - for (auto& post_command : test_config.post_commands) { + for (auto &post_command : test_config.post_commands) { command(post_command); } @@ -904,14 +871,13 @@ TEST(AngleStyle, single) { EXPECT_FP_LE_WITH_EPS(eangle[1], esingle[1], epsilon); EXPECT_FP_LE_WITH_EPS(eangle[2], esingle[2], epsilon); EXPECT_FP_LE_WITH_EPS(eangle[3], esingle[3], epsilon); - if (print_stats) - std::cerr << "single_energy stats:" << stats << std::endl; + if (print_stats) std::cerr << "single_energy stats:" << stats << std::endl; int i = 0; for (auto &dist : test_config.equilibrium) - EXPECT_NEAR(dist,angle->equilibrium_angle(++i),0.00001); + EXPECT_NEAR(dist, angle->equilibrium_angle(++i), 0.00001); if (!verbose) ::testing::internal::CaptureStdout(); - cleanup_lammps(lmp,test_config); + cleanup_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); } diff --git a/unittest/force-styles/bond_style.cpp b/unittest/force-styles/bond_style.cpp index b87804ef4a..2ffd756fb7 100644 --- a/unittest/force-styles/bond_style.cpp +++ b/unittest/force-styles/bond_style.cpp @@ -13,32 +13,32 @@ // unit tests for bond styles intended for molecular systems -#include "yaml_reader.h" -#include "yaml_writer.h" #include "error_stats.h" #include "test_config.h" #include "test_config_reader.h" #include "test_main.h" +#include "yaml_reader.h" +#include "yaml_writer.h" -#include "gtest/gtest.h" #include "gmock/gmock.h" +#include "gtest/gtest.h" -#include "lammps.h" #include "atom.h" -#include "modify.h" +#include "bond.h" #include "compute.h" #include "force.h" -#include "bond.h" #include "info.h" #include "input.h" +#include "lammps.h" +#include "modify.h" #include "universe.h" -#include -#include -#include -#include #include +#include +#include +#include #include +#include #include #include @@ -46,12 +46,13 @@ #include #include -using ::testing::StartsWith; using ::testing::HasSubstr; +using ::testing::StartsWith; using namespace LAMMPS_NS; -static void delete_file(const std::string & filename) { +static void delete_file(const std::string &filename) +{ remove(filename.c_str()); }; @@ -63,9 +64,7 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) delete lmp; } -LAMMPS *init_lammps(int argc, char **argv, - const TestConfig &cfg, - const bool newton=true) +LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool newton = true) { LAMMPS *lmp; @@ -74,7 +73,7 @@ LAMMPS *init_lammps(int argc, char **argv, // check if prerequisite styles are available Info *info = new Info(lmp); int nfail = 0; - for (auto& prerequisite : cfg.prerequisites) { + for (auto &prerequisite : cfg.prerequisites) { std::string style = prerequisite.second; // this is a test for bond styles, so if the suffixed @@ -86,19 +85,19 @@ LAMMPS *init_lammps(int argc, char **argv, } } - if (!info->has_style(prerequisite.first,style)) ++nfail; + if (!info->has_style(prerequisite.first, style)) ++nfail; } if (nfail > 0) { delete info; - cleanup_lammps(lmp,cfg); + cleanup_lammps(lmp, cfg); return nullptr; } // utility lambdas to improve readability - auto command = [&](const std::string & line) { + auto command = [&](const std::string &line) { lmp->input->one(line.c_str()); }; - auto parse_input_script = [&](const std::string & filename) { + auto parse_input_script = [&](const std::string &filename) { lmp->input->file(filename.c_str()); }; @@ -110,7 +109,7 @@ LAMMPS *init_lammps(int argc, char **argv, command("variable input_dir index " + INPUT_FOLDER); - for (auto& pre_command : cfg.pre_commands) { + for (auto &pre_command : cfg.pre_commands) { command(pre_command); } @@ -119,11 +118,11 @@ LAMMPS *init_lammps(int argc, char **argv, command("bond_style " + cfg.bond_style); - for (auto& bond_coeff : cfg.bond_coeff) { + for (auto &bond_coeff : cfg.bond_coeff) { command("bond_coeff " + bond_coeff); } - for (auto& post_command : cfg.post_commands) { + for (auto &post_command : cfg.post_commands) { command(post_command); } @@ -138,7 +137,7 @@ LAMMPS *init_lammps(int argc, char **argv, void run_lammps(LAMMPS *lmp) { // utility lambda to improve readability - auto command = [&](const std::string & line) { + auto command = [&](const std::string &line) { lmp->input->one(line.c_str()); }; @@ -153,7 +152,7 @@ void run_lammps(LAMMPS *lmp) void restart_lammps(LAMMPS *lmp, const TestConfig &cfg) { // utility lambda to improve readability - auto command = [&](const std::string & line) { + auto command = [&](const std::string &line) { lmp->input->one(line.c_str()); }; @@ -164,14 +163,13 @@ void restart_lammps(LAMMPS *lmp, const TestConfig &cfg) command("bond_style " + cfg.bond_style); } - if ((cfg.bond_style.substr(0,6) == "hybrid") - || !lmp->force->bond->writedata) { - for (auto& bond_coeff : cfg.bond_coeff) { + if ((cfg.bond_style.substr(0, 6) == "hybrid") || !lmp->force->bond->writedata) { + for (auto &bond_coeff : cfg.bond_coeff) { command("bond_coeff " + bond_coeff); } } - for (auto& post_command : cfg.post_commands) { + for (auto &post_command : cfg.post_commands) { command(post_command); } @@ -181,10 +179,10 @@ void restart_lammps(LAMMPS *lmp, const TestConfig &cfg) void data_lammps(LAMMPS *lmp, const TestConfig &cfg) { // utility lambdas to improve readability - auto command = [&](const std::string & line) { + auto command = [&](const std::string &line) { lmp->input->one(line.c_str()); }; - auto parse_input_script = [&](const std::string & filename) { + auto parse_input_script = [&](const std::string &filename) { lmp->input->file(filename.c_str()); }; @@ -194,7 +192,7 @@ void data_lammps(LAMMPS *lmp, const TestConfig &cfg) command("variable newton_bond delete"); command("variable newton_bond index on"); - for (auto& pre_command : cfg.pre_commands) { + for (auto &pre_command : cfg.pre_commands) { command(pre_command); } @@ -204,10 +202,10 @@ void data_lammps(LAMMPS *lmp, const TestConfig &cfg) std::string input_file = INPUT_FOLDER + PATH_SEP + cfg.input_file; parse_input_script(input_file); - for (auto& bond_coeff : cfg.bond_coeff) { + for (auto &bond_coeff : cfg.bond_coeff) { command("bond_coeff " + bond_coeff); } - for (auto& post_command : cfg.post_commands) { + for (auto &post_command : cfg.post_commands) { command(post_command); } command("run 0 post no"); @@ -218,16 +216,15 @@ void data_lammps(LAMMPS *lmp, const TestConfig &cfg) void generate_yaml_file(const char *outfile, const TestConfig &config) { // initialize system geometry - const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite" }; + const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"}; char **argv = (char **)args; - int argc = sizeof(args)/sizeof(char *); - LAMMPS *lmp = init_lammps(argc,argv,config); + int argc = sizeof(args) / sizeof(char *); + LAMMPS *lmp = init_lammps(argc, argv, config); if (!lmp) { std::cerr << "One or more prerequisite styles are not available " - "in this LAMMPS configuration:\n"; - for (auto& prerequisite : config.prerequisites) { - std::cerr << prerequisite.first << "_style " - << prerequisite.second << "\n"; + "in this LAMMPS configuration:\n"; + for (auto &prerequisite : config.prerequisites) { + std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n"; } return; } @@ -245,7 +242,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // date_generated std::time_t now = time(NULL); block = ctime(&now); - block = block.substr(0,block.find("\n")-1); + block = block.substr(0, block.find("\n") - 1); writer.emit("date_generated", block); // epsilon @@ -253,21 +250,21 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // prerequisites block.clear(); - for (auto& prerequisite : config.prerequisites) { + for (auto &prerequisite : config.prerequisites) { block += prerequisite.first + " " + prerequisite.second + "\n"; } writer.emit_block("prerequisites", block); // pre_commands block.clear(); - for (auto& command : config.pre_commands) { + for (auto &command : config.pre_commands) { block += command + "\n"; } writer.emit_block("pre_commands", block); // post_commands block.clear(); - for (auto& command : config.post_commands) { + for (auto &command : config.post_commands) { block += command + "\n"; } writer.emit_block("post_commands", block); @@ -280,7 +277,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // bond_coeff block.clear(); - for (auto& bond_coeff : config.bond_coeff) { + for (auto &bond_coeff : config.bond_coeff) { block += bond_coeff + "\n"; } writer.emit_block("bond_coeff", block); @@ -288,15 +285,15 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // equilibrium distance std::stringstream eqstr; eqstr << lmp->atom->nbondtypes; - for (int i=0; i < lmp->atom->nbondtypes; ++i) { - eqstr << " " << lmp->force->bond->equilibrium_distance(i+1); + for (int i = 0; i < lmp->atom->nbondtypes; ++i) { + eqstr << " " << lmp->force->bond->equilibrium_distance(i + 1); } writer.emit("equilibrium", eqstr.str()); // extract block.clear(); std::stringstream outstr; - for (auto& data : config.extract) { + for (auto &data : config.extract) { outstr << data.first << " " << data.second << std::endl; } writer.emit_block("extract", outstr.str()); @@ -309,17 +306,17 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // init_stress double *stress = lmp->force->bond->virial; - snprintf(buf,bufsize,"% 23.16e % 23.16e % 23.16e % 23.16e % 23.16e % 23.16e", - stress[0],stress[1],stress[2],stress[3],stress[4],stress[5]); + snprintf(buf, bufsize, "% 23.16e % 23.16e % 23.16e % 23.16e % 23.16e % 23.16e", stress[0], + stress[1], stress[2], stress[3], stress[4], stress[5]); writer.emit_block("init_stress", buf); // init_forces block.clear(); double **f = lmp->atom->f; tagint *tag = lmp->atom->tag; - for (int i=0; i < natoms; ++i) { - snprintf(buf,bufsize,"% 3d % 23.16e % 23.16e % 23.16e\n", - (int)tag[i], f[i][0], f[i][1], f[i][2]); + for (int i = 0; i < natoms; ++i) { + snprintf(buf, bufsize, "% 3d % 23.16e % 23.16e % 23.16e\n", (int)tag[i], f[i][0], f[i][1], + f[i][2]); block += buf; } writer.emit_block("init_forces", block); @@ -332,40 +329,40 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // run_stress stress = lmp->force->bond->virial; - snprintf(buf,bufsize,"% 23.16e % 23.16e % 23.16e % 23.16e % 23.16e % 23.16e", - stress[0],stress[1],stress[2],stress[3],stress[4],stress[5]); + snprintf(buf, bufsize, "% 23.16e % 23.16e % 23.16e % 23.16e % 23.16e % 23.16e", stress[0], + stress[1], stress[2], stress[3], stress[4], stress[5]); writer.emit_block("run_stress", buf); block.clear(); f = lmp->atom->f; tag = lmp->atom->tag; - for (int i=0; i < natoms; ++i) { - snprintf(buf,bufsize,"% 3d % 23.16e % 23.16e % 23.16e\n", - (int)tag[i], f[i][0], f[i][1], f[i][2]); + for (int i = 0; i < natoms; ++i) { + snprintf(buf, bufsize, "% 3d % 23.16e % 23.16e % 23.16e\n", (int)tag[i], f[i][0], f[i][1], + f[i][2]); block += buf; } writer.emit_block("run_forces", block); - cleanup_lammps(lmp,config); + cleanup_lammps(lmp, config); return; } -TEST(BondStyle, plain) { - const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite" }; +TEST(BondStyle, plain) +{ + const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"}; char **argv = (char **)args; - int argc = sizeof(args)/sizeof(char *); + int argc = sizeof(args) / sizeof(char *); ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc,argv,test_config,true); + LAMMPS *lmp = init_lammps(argc, argv, test_config, true); std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; if (!lmp) { std::cerr << "One or more prerequisite styles are not available " - "in this LAMMPS configuration:\n"; - for (auto& prerequisite : test_config.prerequisites) { - std::cerr << prerequisite.first << "_style " - << prerequisite.second << "\n"; + "in this LAMMPS configuration:\n"; + for (auto &prerequisite : test_config.prerequisites) { + std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n"; } GTEST_SKIP(); } @@ -375,22 +372,21 @@ TEST(BondStyle, plain) { // abort if running in parallel and not all atoms are local const int nlocal = lmp->atom->nlocal; - ASSERT_EQ(lmp->atom->natoms,nlocal); + ASSERT_EQ(lmp->atom->natoms, nlocal); double epsilon = test_config.epsilon; - double **f=lmp->atom->f; - tagint *tag=lmp->atom->tag; + double **f = lmp->atom->f; + tagint *tag = lmp->atom->tag; ErrorStats stats; stats.reset(); const std::vector &f_ref = test_config.init_forces; - ASSERT_EQ(nlocal+1,f_ref.size()); - for (int i=0; i < nlocal; ++i) { + ASSERT_EQ(nlocal + 1, f_ref.size()); + for (int i = 0; i < nlocal; ++i) { EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); } - if (print_stats) - std::cerr << "init_forces stats, newton on: " << stats << std::endl; + if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; Bond *bond = lmp->force->bond; double *stress = bond->virial; @@ -401,13 +397,11 @@ TEST(BondStyle, plain) { EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) - std::cerr << "init_stress stats, newton on: " << stats << std::endl; + if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl; stats.reset(); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon); - if (print_stats) - std::cerr << "init_energy stats, newton on: " << stats << std::endl; + if (print_stats) std::cerr << "init_energy stats, newton on: " << stats << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); run_lammps(lmp); @@ -416,15 +410,14 @@ TEST(BondStyle, plain) { f = lmp->atom->f; stress = bond->virial; const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal+1,f_run.size()); + ASSERT_EQ(nlocal + 1, f_run.size()); stats.reset(); - for (int i=0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10*epsilon); + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); } - if (print_stats) - std::cerr << "run_forces stats, newton on: " << stats << std::endl; + if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; stress = bond->virial; stats.reset(); @@ -434,52 +427,47 @@ TEST(BondStyle, plain) { EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) - std::cerr << "run_stress stats, newton on: " << stats << std::endl; + if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; stats.reset(); int id = lmp->modify->find_compute("sum"); double energy = lmp->modify->compute[id]->compute_scalar(); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.run_energy, epsilon); EXPECT_FP_LE_WITH_EPS(bond->energy, energy, epsilon); - if (print_stats) - std::cerr << "run_energy stats, newton on: " << stats << std::endl; + if (print_stats) std::cerr << "run_energy stats, newton on: " << stats << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); - cleanup_lammps(lmp,test_config); - lmp = init_lammps(argc,argv,test_config,false); + cleanup_lammps(lmp, test_config); + lmp = init_lammps(argc, argv, test_config, false); if (!verbose) ::testing::internal::GetCapturedStdout(); // skip over these tests if newton bond is forced to be on if (lmp->force->newton_bond == 0) { - f=lmp->atom->f; - tag=lmp->atom->tag; + f = lmp->atom->f; + tag = lmp->atom->tag; stats.reset(); - for (int i=0; i < nlocal; ++i) { + for (int i = 0; i < nlocal; ++i) { EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); } - if (print_stats) - std::cerr << "init_forces stats, newton off:" << stats << std::endl; + if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; bond = lmp->force->bond; stress = bond->virial; stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 2*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 2*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 2*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 2*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 2*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 2*epsilon); - if (print_stats) - std::cerr << "init_stress stats, newton off:" << stats << std::endl; + EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 2 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 2 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 2 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 2 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 2 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 2 * epsilon); + if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; stats.reset(); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon); - if (print_stats) - std::cerr << "init_energy stats, newton off:" << stats << std::endl; + if (print_stats) std::cerr << "init_energy stats, newton off:" << stats << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); run_lammps(lmp); @@ -488,13 +476,12 @@ TEST(BondStyle, plain) { f = lmp->atom->f; stress = bond->virial; stats.reset(); - for (int i=0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10*epsilon); + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); } - if (print_stats) - std::cerr << "run_forces stats, newton off:" << stats << std::endl; + if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; stress = bond->virial; stats.reset(); @@ -504,33 +491,30 @@ TEST(BondStyle, plain) { EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) - std::cerr << "run_stress stats, newton off:" << stats << std::endl; + if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; stats.reset(); id = lmp->modify->find_compute("sum"); energy = lmp->modify->compute[id]->compute_scalar(); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.run_energy, epsilon); EXPECT_FP_LE_WITH_EPS(bond->energy, energy, epsilon); - if (print_stats) - std::cerr << "run_energy stats, newton off:" << stats << std::endl; + if (print_stats) std::cerr << "run_energy stats, newton off:" << stats << std::endl; } if (!verbose) ::testing::internal::CaptureStdout(); restart_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f=lmp->atom->f; - tag=lmp->atom->tag; + f = lmp->atom->f; + tag = lmp->atom->tag; stats.reset(); - ASSERT_EQ(nlocal+1,f_ref.size()); - for (int i=0; i < nlocal; ++i) { + ASSERT_EQ(nlocal + 1, f_ref.size()); + for (int i = 0; i < nlocal; ++i) { EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); } - if (print_stats) - std::cerr << "restart_forces stats:" << stats << std::endl; + if (print_stats) std::cerr << "restart_forces stats:" << stats << std::endl; bond = lmp->force->bond; stress = bond->virial; @@ -541,29 +525,26 @@ TEST(BondStyle, plain) { EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) - std::cerr << "restart_stress stats:" << stats << std::endl; + if (print_stats) std::cerr << "restart_stress stats:" << stats << std::endl; stats.reset(); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon); - if (print_stats) - std::cerr << "restart_energy stats:" << stats << std::endl; + if (print_stats) std::cerr << "restart_energy stats:" << stats << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); data_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f=lmp->atom->f; - tag=lmp->atom->tag; + f = lmp->atom->f; + tag = lmp->atom->tag; stats.reset(); - ASSERT_EQ(nlocal+1,f_ref.size()); - for (int i=0; i < nlocal; ++i) { + ASSERT_EQ(nlocal + 1, f_ref.size()); + for (int i = 0; i < nlocal; ++i) { EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); } - if (print_stats) - std::cerr << "data_forces stats:" << stats << std::endl; + if (print_stats) std::cerr << "data_forces stats:" << stats << std::endl; bond = lmp->force->bond; stress = bond->virial; @@ -574,37 +555,35 @@ TEST(BondStyle, plain) { EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) - std::cerr << "data_stress stats:" << stats << std::endl; + if (print_stats) std::cerr << "data_stress stats:" << stats << std::endl; stats.reset(); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon); - if (print_stats) - std::cerr << "data_energy stats:" << stats << std::endl; + if (print_stats) std::cerr << "data_energy stats:" << stats << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); - cleanup_lammps(lmp,test_config); + cleanup_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); }; -TEST(BondStyle, omp) { +TEST(BondStyle, omp) +{ if (!LAMMPS::is_installed_pkg("USER-OMP")) GTEST_SKIP(); - const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", - "-nocite", "-pk", "omp", "4", "-sf", "omp"}; + const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite", + "-pk", "omp", "4", "-sf", "omp"}; char **argv = (char **)args; - int argc = sizeof(args)/sizeof(char *); + int argc = sizeof(args) / sizeof(char *); ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc,argv,test_config,true); + LAMMPS *lmp = init_lammps(argc, argv, test_config, true); std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; if (!lmp) { std::cerr << "One or more prerequisite styles with /omp suffix\n" - "are not available in this LAMMPS configuration:\n"; - for (auto& prerequisite : test_config.prerequisites) { - std::cerr << prerequisite.first << "_style " - << prerequisite.second << "\n"; + "are not available in this LAMMPS configuration:\n"; + for (auto &prerequisite : test_config.prerequisites) { + std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n"; } GTEST_SKIP(); } @@ -614,39 +593,36 @@ TEST(BondStyle, omp) { // abort if running in parallel and not all atoms are local const int nlocal = lmp->atom->nlocal; - ASSERT_EQ(lmp->atom->natoms,nlocal); + ASSERT_EQ(lmp->atom->natoms, nlocal); // relax error a bit for USER-OMP package - double epsilon = 5.0*test_config.epsilon; - double **f=lmp->atom->f; - tagint *tag=lmp->atom->tag; + double epsilon = 5.0 * test_config.epsilon; + double **f = lmp->atom->f; + tagint *tag = lmp->atom->tag; const std::vector &f_ref = test_config.init_forces; ErrorStats stats; stats.reset(); - for (int i=0; i < nlocal; ++i) { + for (int i = 0; i < nlocal; ++i) { EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); } - if (print_stats) - std::cerr << "init_forces stats, newton on: " << stats << std::endl; + if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; Bond *bond = lmp->force->bond; double *stress = bond->virial; stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10*epsilon); - if (print_stats) - std::cerr << "init_stress stats, newton on: " << stats << std::endl; + EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); + if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl; stats.reset(); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon); - if (print_stats) - std::cerr << "init_energy stats, newton on: " << stats << std::endl; + if (print_stats) std::cerr << "init_energy stats, newton on: " << stats << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); run_lammps(lmp); @@ -655,26 +631,24 @@ TEST(BondStyle, omp) { f = lmp->atom->f; stress = bond->virial; const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal+1,f_run.size()); + ASSERT_EQ(nlocal + 1, f_run.size()); stats.reset(); - for (int i=0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10*epsilon); + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); } - if (print_stats) - std::cerr << "run_forces stats, newton on: " << stats << std::endl; + if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; stress = bond->virial; stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10*epsilon); - if (print_stats) - std::cerr << "run_stress stats, newton on: " << stats << std::endl; + EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); + if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; stats.reset(); int id = lmp->modify->find_compute("sum"); @@ -682,46 +656,42 @@ TEST(BondStyle, omp) { EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.run_energy, epsilon); // TODO: this is currently broken for USER-OMP with bond style hybrid // needs to be fixed in the main code somewhere. Not sure where, though. - if (test_config.bond_style.substr(0,6) != "hybrid") + if (test_config.bond_style.substr(0, 6) != "hybrid") EXPECT_FP_LE_WITH_EPS(bond->energy, energy, epsilon); - if (print_stats) - std::cerr << "run_energy stats, newton on: " << stats << std::endl; + if (print_stats) std::cerr << "run_energy stats, newton on: " << stats << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); - cleanup_lammps(lmp,test_config); - lmp = init_lammps(argc,argv,test_config,false); + cleanup_lammps(lmp, test_config); + lmp = init_lammps(argc, argv, test_config, false); if (!verbose) ::testing::internal::GetCapturedStdout(); // skip over these tests if newton bond is forced to be on if (lmp->force->newton_bond == 0) { - f=lmp->atom->f; - tag=lmp->atom->tag; + f = lmp->atom->f; + tag = lmp->atom->tag; stats.reset(); - for (int i=0; i < nlocal; ++i) { + for (int i = 0; i < nlocal; ++i) { EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); } - if (print_stats) - std::cerr << "init_forces stats, newton off:" << stats << std::endl; + if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; bond = lmp->force->bond; stress = bond->virial; stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10*epsilon); - if (print_stats) - std::cerr << "init_stress stats, newton off:" << stats << std::endl; + EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); + if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; stats.reset(); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon); - if (print_stats) - std::cerr << "init_energy stats, newton off:" << stats << std::endl; + if (print_stats) std::cerr << "init_energy stats, newton off:" << stats << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); run_lammps(lmp); @@ -729,24 +699,22 @@ TEST(BondStyle, omp) { f = lmp->atom->f; stats.reset(); - for (int i=0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10*epsilon); + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); } - if (print_stats) - std::cerr << "run_forces stats, newton off:" << stats << std::endl; + if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; stress = bond->virial; stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10*epsilon); - if (print_stats) - std::cerr << "run_stress stats, newton off:" << stats << std::endl; + EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); + if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; stats.reset(); id = lmp->modify->find_compute("sum"); @@ -754,33 +722,32 @@ TEST(BondStyle, omp) { EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.run_energy, epsilon); // TODO: this is currently broken for USER-OMP with bond style hybrid // needs to be fixed in the main code somewhere. Not sure where, though. - if (test_config.bond_style.substr(0,6) != "hybrid") + if (test_config.bond_style.substr(0, 6) != "hybrid") EXPECT_FP_LE_WITH_EPS(bond->energy, energy, epsilon); - if (print_stats) - std::cerr << "run_energy stats, newton off:" << stats << std::endl; + if (print_stats) std::cerr << "run_energy stats, newton off:" << stats << std::endl; } if (!verbose) ::testing::internal::CaptureStdout(); - cleanup_lammps(lmp,test_config); + cleanup_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); }; -TEST(BondStyle, single) { - const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite" }; +TEST(BondStyle, single) +{ + const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"}; char **argv = (char **)args; - int argc = sizeof(args)/sizeof(char *); + int argc = sizeof(args) / sizeof(char *); // create a LAMMPS instance with standard settings to detect the number of atom types if (!verbose) ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc,argv,test_config); + LAMMPS *lmp = init_lammps(argc, argv, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); if (!lmp) { std::cerr << "One or more prerequisite styles are not available " - "in this LAMMPS configuration:\n"; - for (auto& prerequisite : test_config.prerequisites) { - std::cerr << prerequisite.first << "_style " - << prerequisite.second << "\n"; + "in this LAMMPS configuration:\n"; + for (auto &prerequisite : test_config.prerequisites) { + std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n"; } GTEST_SKIP(); } @@ -791,13 +758,13 @@ TEST(BondStyle, single) { if (molecular != 1) { std::cerr << "Only simple molecular atom styles are supported\n"; if (!verbose) ::testing::internal::CaptureStdout(); - cleanup_lammps(lmp,test_config); + cleanup_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); GTEST_SKIP(); } // utility lambda to improve readability - auto command = [&](const std::string & line) { + auto command = [&](const std::string &line) { lmp->input->one(line.c_str()); }; @@ -809,7 +776,7 @@ TEST(BondStyle, single) { command("variable input_dir index " + INPUT_FOLDER); - for (auto& pre_command : test_config.pre_commands) { + for (auto &pre_command : test_config.pre_commands) { command(pre_command); } @@ -826,7 +793,7 @@ TEST(BondStyle, single) { char buf[10]; std::string cmd("create_box 1 box"); cmd += " bond/types "; - snprintf(buf,10,"%d",nbondtypes); + snprintf(buf, 10, "%d", nbondtypes); cmd += buf; cmd += " extra/bond/per/atom 2"; cmd += " extra/special/per/atom 2"; @@ -838,7 +805,7 @@ TEST(BondStyle, single) { command("bond_style " + test_config.bond_style); Bond *bond = lmp->force->bond; - for (auto& bond_coeff : test_config.bond_coeff) { + for (auto &bond_coeff : test_config.bond_coeff) { command("bond_coeff " + bond_coeff); } @@ -851,7 +818,7 @@ TEST(BondStyle, single) { command("create_bonds single/bond 1 1 2"); command("create_bonds single/bond 2 3 4"); - for (auto& post_command : test_config.post_commands) { + for (auto &post_command : test_config.post_commands) { command(post_command); } @@ -863,36 +830,36 @@ TEST(BondStyle, single) { int idx3 = lmp->atom->map(3); int idx4 = lmp->atom->map(4); double epsilon = test_config.epsilon; - double **f=lmp->atom->f; - double **x=lmp->atom->x; + double **f = lmp->atom->f; + double **x = lmp->atom->x; double delx1 = x[idx2][0] - x[idx1][0]; double dely1 = x[idx2][1] - x[idx1][1]; double delz1 = x[idx2][2] - x[idx1][2]; - double rsq1 = delx1*delx1+dely1*dely1+delz1*delz1; + double rsq1 = delx1 * delx1 + dely1 * dely1 + delz1 * delz1; double delx2 = x[idx4][0] - x[idx3][0]; double dely2 = x[idx4][1] - x[idx3][1]; double delz2 = x[idx4][2] - x[idx3][2]; - double rsq2 = delx2*delx2+dely2*dely2+delz2*delz2; + double rsq2 = delx2 * delx2 + dely2 * dely2 + delz2 * delz2; double fsingle = 0.0; double ebond[4], esngl[4]; ErrorStats stats; ebond[0] = bond->energy; esngl[0] = bond->single(1, rsq1, idx1, idx2, fsingle); - EXPECT_FP_LE_WITH_EPS(f[idx1][0],-fsingle*delx1, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx1][1],-fsingle*dely1, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx1][2],-fsingle*delz1, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx2][0], fsingle*delx1, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx2][1], fsingle*dely1, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx2][2], fsingle*delz1, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx1][0], -fsingle * delx1, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx1][1], -fsingle * dely1, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx1][2], -fsingle * delz1, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx2][0], fsingle * delx1, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx2][1], fsingle * dely1, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx2][2], fsingle * delz1, epsilon); esngl[0] += bond->single(2, rsq2, idx3, idx4, fsingle); - EXPECT_FP_LE_WITH_EPS(f[idx3][0],-fsingle*delx2, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx3][1],-fsingle*dely2, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx3][2],-fsingle*delz2, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx4][0], fsingle*delx2, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx4][1], fsingle*dely2, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx4][2], fsingle*delz2, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx3][0], -fsingle * delx2, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx3][1], -fsingle * dely2, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx3][2], -fsingle * delz2, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx4][0], fsingle * delx2, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx4][1], fsingle * dely2, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx4][2], fsingle * delz2, epsilon); if (!verbose) ::testing::internal::CaptureStdout(); command("displace_atoms all random 0.5 0.5 0.5 23456"); @@ -908,29 +875,29 @@ TEST(BondStyle, single) { delx1 = x[idx2][0] - x[idx1][0]; dely1 = x[idx2][1] - x[idx1][1]; delz1 = x[idx2][2] - x[idx1][2]; - rsq1 = delx1*delx1+dely1*dely1+delz1*delz1; + rsq1 = delx1 * delx1 + dely1 * dely1 + delz1 * delz1; delx2 = x[idx4][0] - x[idx3][0]; dely2 = x[idx4][1] - x[idx3][1]; delz2 = x[idx4][2] - x[idx3][2]; - rsq2 = delx2*delx2+dely2*dely2+delz2*delz2; + rsq2 = delx2 * delx2 + dely2 * dely2 + delz2 * delz2; fsingle = 0.0; ebond[1] = bond->energy; esngl[1] = bond->single(1, rsq1, idx1, idx2, fsingle); - EXPECT_FP_LE_WITH_EPS(f[idx1][0],-fsingle*delx1, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx1][1],-fsingle*dely1, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx1][2],-fsingle*delz1, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx2][0], fsingle*delx1, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx2][1], fsingle*dely1, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx2][2], fsingle*delz1, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx1][0], -fsingle * delx1, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx1][1], -fsingle * dely1, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx1][2], -fsingle * delz1, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx2][0], fsingle * delx1, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx2][1], fsingle * dely1, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx2][2], fsingle * delz1, epsilon); esngl[1] += bond->single(2, rsq2, idx3, idx4, fsingle); - EXPECT_FP_LE_WITH_EPS(f[idx3][0],-fsingle*delx2, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx3][1],-fsingle*dely2, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx3][2],-fsingle*delz2, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx4][0], fsingle*delx2, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx4][1], fsingle*dely2, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx4][2], fsingle*delz2, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx3][0], -fsingle * delx2, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx3][1], -fsingle * dely2, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx3][2], -fsingle * delz2, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx4][0], fsingle * delx2, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx4][1], fsingle * dely2, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx4][2], fsingle * delz2, epsilon); if (!verbose) ::testing::internal::CaptureStdout(); command("displace_atoms all random 0.5 0.5 0.5 456963"); @@ -946,29 +913,29 @@ TEST(BondStyle, single) { delx1 = x[idx2][0] - x[idx1][0]; dely1 = x[idx2][1] - x[idx1][1]; delz1 = x[idx2][2] - x[idx1][2]; - rsq1 = delx1*delx1+dely1*dely1+delz1*delz1; + rsq1 = delx1 * delx1 + dely1 * dely1 + delz1 * delz1; delx2 = x[idx4][0] - x[idx3][0]; dely2 = x[idx4][1] - x[idx3][1]; delz2 = x[idx4][2] - x[idx3][2]; - rsq2 = delx2*delx2+dely2*dely2+delz2*delz2; + rsq2 = delx2 * delx2 + dely2 * dely2 + delz2 * delz2; fsingle = 0.0; ebond[2] = bond->energy; esngl[2] = bond->single(1, rsq1, idx1, idx2, fsingle); - EXPECT_FP_LE_WITH_EPS(f[idx1][0],-fsingle*delx1, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx1][1],-fsingle*dely1, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx1][2],-fsingle*delz1, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx2][0], fsingle*delx1, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx2][1], fsingle*dely1, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx2][2], fsingle*delz1, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx1][0], -fsingle * delx1, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx1][1], -fsingle * dely1, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx1][2], -fsingle * delz1, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx2][0], fsingle * delx1, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx2][1], fsingle * dely1, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx2][2], fsingle * delz1, epsilon); esngl[2] += bond->single(2, rsq2, idx3, idx4, fsingle); - EXPECT_FP_LE_WITH_EPS(f[idx3][0],-fsingle*delx2, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx3][1],-fsingle*dely2, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx3][2],-fsingle*delz2, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx4][0], fsingle*delx2, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx4][1], fsingle*dely2, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx4][2], fsingle*delz2, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx3][0], -fsingle * delx2, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx3][1], -fsingle * dely2, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx3][2], -fsingle * delz2, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx4][0], fsingle * delx2, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx4][1], fsingle * dely2, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx4][2], fsingle * delz2, epsilon); if (!verbose) ::testing::internal::CaptureStdout(); command("displace_atoms all random 0.5 0.5 0.5 9726532"); @@ -984,64 +951,62 @@ TEST(BondStyle, single) { delx1 = x[idx2][0] - x[idx1][0]; dely1 = x[idx2][1] - x[idx1][1]; delz1 = x[idx2][2] - x[idx1][2]; - rsq1 = delx1*delx1+dely1*dely1+delz1*delz1; + rsq1 = delx1 * delx1 + dely1 * dely1 + delz1 * delz1; delx2 = x[idx4][0] - x[idx3][0]; dely2 = x[idx4][1] - x[idx3][1]; delz2 = x[idx4][2] - x[idx3][2]; - rsq2 = delx2*delx2+dely2*dely2+delz2*delz2; + rsq2 = delx2 * delx2 + dely2 * dely2 + delz2 * delz2; fsingle = 0.0; ebond[3] = bond->energy; esngl[3] = bond->single(1, rsq1, idx1, idx2, fsingle); - EXPECT_FP_LE_WITH_EPS(f[idx1][0],-fsingle*delx1, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx1][1],-fsingle*dely1, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx1][2],-fsingle*delz1, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx2][0], fsingle*delx1, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx2][1], fsingle*dely1, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx2][2], fsingle*delz1, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx1][0], -fsingle * delx1, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx1][1], -fsingle * dely1, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx1][2], -fsingle * delz1, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx2][0], fsingle * delx1, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx2][1], fsingle * dely1, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx2][2], fsingle * delz1, epsilon); esngl[3] += bond->single(2, rsq2, idx3, idx4, fsingle); - EXPECT_FP_LE_WITH_EPS(f[idx3][0],-fsingle*delx2, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx3][1],-fsingle*dely2, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx3][2],-fsingle*delz2, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx4][0], fsingle*delx2, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx4][1], fsingle*dely2, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx4][2], fsingle*delz2, epsilon); - if (print_stats) - std::cerr << "single_force stats:" << stats << std::endl; + EXPECT_FP_LE_WITH_EPS(f[idx3][0], -fsingle * delx2, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx3][1], -fsingle * dely2, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx3][2], -fsingle * delz2, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx4][0], fsingle * delx2, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx4][1], fsingle * dely2, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx4][2], fsingle * delz2, epsilon); + if (print_stats) std::cerr << "single_force stats:" << stats << std::endl; stats.reset(); EXPECT_FP_LE_WITH_EPS(ebond[0], esngl[0], epsilon); EXPECT_FP_LE_WITH_EPS(ebond[1], esngl[1], epsilon); EXPECT_FP_LE_WITH_EPS(ebond[2], esngl[2], epsilon); EXPECT_FP_LE_WITH_EPS(ebond[3], esngl[3], epsilon); - if (print_stats) - std::cerr << "single_energy stats:" << stats << std::endl; + if (print_stats) std::cerr << "single_energy stats:" << stats << std::endl; int i = 0; for (auto &dist : test_config.equilibrium) - EXPECT_NEAR(dist,bond->equilibrium_distance(++i),0.00001); + EXPECT_NEAR(dist, bond->equilibrium_distance(++i), 0.00001); if (!verbose) ::testing::internal::CaptureStdout(); - cleanup_lammps(lmp,test_config); + cleanup_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); } -TEST(BondStyle, extract) { - const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite" }; +TEST(BondStyle, extract) +{ + const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"}; char **argv = (char **)args; - int argc = sizeof(args)/sizeof(char *); + int argc = sizeof(args) / sizeof(char *); if (!verbose) ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc,argv,test_config,true); + LAMMPS *lmp = init_lammps(argc, argv, test_config, true); if (!verbose) ::testing::internal::GetCapturedStdout(); if (!lmp) { std::cerr << "One or more prerequisite styles are not available " - "in this LAMMPS configuration:\n"; + "in this LAMMPS configuration:\n"; for (auto prerequisite : test_config.prerequisites) { - std::cerr << prerequisite.first << "_style " - << prerequisite.second << "\n"; + std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n"; } GTEST_SKIP(); } @@ -1049,17 +1014,17 @@ TEST(BondStyle, extract) { void *ptr = nullptr; int dim = 0; for (auto extract : test_config.extract) { - ptr = bond->extract(extract.first.c_str(),dim); + ptr = bond->extract(extract.first.c_str(), dim); EXPECT_NE(ptr, nullptr); EXPECT_EQ(dim, extract.second); } - ptr = bond->extract("does_not_exist",dim); + ptr = bond->extract("does_not_exist", dim); EXPECT_EQ(ptr, nullptr); - for (int i=1; i <= lmp->atom->nbondtypes; ++i) + for (int i = 1; i <= lmp->atom->nbondtypes; ++i) EXPECT_GE(bond->equilibrium_distance(i), 0.0); if (!verbose) ::testing::internal::CaptureStdout(); - cleanup_lammps(lmp,test_config); + cleanup_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); } diff --git a/unittest/force-styles/error_stats.cpp b/unittest/force-styles/error_stats.cpp index 9b4f538099..8ab8c5a627 100644 --- a/unittest/force-styles/error_stats.cpp +++ b/unittest/force-styles/error_stats.cpp @@ -12,32 +12,36 @@ ------------------------------------------------------------------------- */ #include "error_stats.h" +#include #include #include -#include -void ErrorStats::reset() { +void ErrorStats::reset() +{ num = 0; maxidx = -1; - sum = sumsq = maxerr =0.0; + sum = sumsq = maxerr = 0.0; } -void ErrorStats::add(const double &val) { +void ErrorStats::add(const double &val) +{ ++num; if (val > maxerr) { maxidx = num; maxerr = val; } sum += val; - sumsq += val*val; + sumsq += val * val; } -double ErrorStats::avg() const { - return (num > 0) ? sum/num : 0.0; +double ErrorStats::avg() const +{ + return (num > 0) ? sum / num : 0.0; } -double ErrorStats::dev() const { - return (num > 0) ? sqrt(sumsq/num - sum/num*sum/num) : 0.0; +double ErrorStats::dev() const +{ + return (num > 0) ? sqrt(sumsq / num - sum / num * sum / num) : 0.0; } std::ostream &operator<<(std::ostream &out, const ErrorStats &stats) @@ -46,9 +50,7 @@ std::ostream &operator<<(std::ostream &out, const ErrorStats &stats) const std::streamsize width = out.width(10); const std::streamsize prec = out.precision(3); - out << std::scientific - << "Average: " << stats.avg() - << " StdDev: " << stats.dev() + out << std::scientific << "Average: " << stats.avg() << " StdDev: " << stats.dev() << " MaxErr: " << stats.max(); out.precision(prec); @@ -57,4 +59,3 @@ std::ostream &operator<<(std::ostream &out, const ErrorStats &stats) return out << " @ item: " << stats.idx(); } - diff --git a/unittest/force-styles/error_stats.h b/unittest/force-styles/error_stats.h index 1304c07130..664a987907 100644 --- a/unittest/force-styles/error_stats.h +++ b/unittest/force-styles/error_stats.h @@ -20,9 +20,7 @@ class ErrorStats { public: friend std::ostream &operator<<(std::ostream &out, const ErrorStats &stats); - ErrorStats() { - reset(); - } + ErrorStats() { reset(); } virtual ~ErrorStats() {} void reset(); @@ -33,8 +31,8 @@ public: double idx() const { return maxidx; } private: - double sum,sumsq,maxerr; - int num,maxidx; + double sum, sumsq, maxerr; + int num, maxidx; }; extern std::ostream &operator<<(std::ostream &out, const ErrorStats &stats); diff --git a/unittest/force-styles/pair_style.cpp b/unittest/force-styles/pair_style.cpp index 0ef67de959..62e1181dab 100644 --- a/unittest/force-styles/pair_style.cpp +++ b/unittest/force-styles/pair_style.cpp @@ -13,32 +13,32 @@ // unit tests for pair styles intended for molecular systems -#include "yaml_reader.h" -#include "yaml_writer.h" #include "error_stats.h" #include "test_config.h" #include "test_config_reader.h" #include "test_main.h" +#include "yaml_reader.h" +#include "yaml_writer.h" -#include "gtest/gtest.h" #include "gmock/gmock.h" +#include "gtest/gtest.h" -#include "lammps.h" #include "atom.h" -#include "modify.h" #include "compute.h" #include "force.h" -#include "pair.h" #include "info.h" #include "input.h" +#include "lammps.h" +#include "modify.h" +#include "pair.h" #include "universe.h" -#include -#include -#include -#include #include +#include +#include +#include #include +#include #include #include @@ -46,12 +46,13 @@ #include #include -using ::testing::StartsWith; using ::testing::HasSubstr; +using ::testing::StartsWith; using namespace LAMMPS_NS; -static void delete_file(const std::string & filename) { +static void delete_file(const std::string &filename) +{ remove(filename.c_str()); }; @@ -63,9 +64,7 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) delete lmp; } -LAMMPS *init_lammps(int argc, char **argv, - const TestConfig &cfg, - const bool newton=true) +LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool newton = true) { LAMMPS *lmp; @@ -74,7 +73,7 @@ LAMMPS *init_lammps(int argc, char **argv, // check if prerequisite styles are available Info *info = new Info(lmp); int nfail = 0; - for (auto& prerequisite : cfg.prerequisites) { + for (auto &prerequisite : cfg.prerequisites) { std::string style = prerequisite.second; // this is a test for pair styles, so if the suffixed @@ -86,19 +85,19 @@ LAMMPS *init_lammps(int argc, char **argv, } } - if (!info->has_style(prerequisite.first,style)) ++nfail; + if (!info->has_style(prerequisite.first, style)) ++nfail; } if (nfail > 0) { delete info; - cleanup_lammps(lmp,cfg); + cleanup_lammps(lmp, cfg); return nullptr; } // utility lambdas to improve readability - auto command = [&](const std::string & line) { + auto command = [&](const std::string &line) { lmp->input->one(line.c_str()); }; - auto parse_input_script = [&](const std::string & filename) { + auto parse_input_script = [&](const std::string &filename) { lmp->input->file(filename.c_str()); }; @@ -110,7 +109,7 @@ LAMMPS *init_lammps(int argc, char **argv, command("variable input_dir index " + INPUT_FOLDER); - for (auto& pre_command : cfg.pre_commands) { + for (auto &pre_command : cfg.pre_commands) { command(pre_command); } @@ -119,11 +118,11 @@ LAMMPS *init_lammps(int argc, char **argv, command("pair_style " + cfg.pair_style); - for (auto& pair_coeff : cfg.pair_coeff) { + for (auto &pair_coeff : cfg.pair_coeff) { command("pair_coeff " + pair_coeff); } - for (auto& post_command : cfg.post_commands) { + for (auto &post_command : cfg.post_commands) { command(post_command); } @@ -138,7 +137,7 @@ LAMMPS *init_lammps(int argc, char **argv, void run_lammps(LAMMPS *lmp) { // utility lambda to improve readability - auto command = [&](const std::string & line) { + auto command = [&](const std::string &line) { lmp->input->one(line.c_str()); }; @@ -153,7 +152,7 @@ void run_lammps(LAMMPS *lmp) void restart_lammps(LAMMPS *lmp, const TestConfig &cfg) { // utility lambda to improve readability - auto command = [&](const std::string & line) { + auto command = [&](const std::string &line) { lmp->input->one(line.c_str()); }; @@ -163,14 +162,13 @@ void restart_lammps(LAMMPS *lmp, const TestConfig &cfg) if (!lmp->force->pair) { command("pair_style " + cfg.pair_style); } - if (!lmp->force->pair->restartinfo - || !lmp->force->pair->writedata) { - for (auto& pair_coeff : cfg.pair_coeff) { + if (!lmp->force->pair->restartinfo || !lmp->force->pair->writedata) { + for (auto &pair_coeff : cfg.pair_coeff) { command("pair_coeff " + pair_coeff); } } - for (auto& post_command : cfg.post_commands) { + for (auto &post_command : cfg.post_commands) { command(post_command); } @@ -180,10 +178,10 @@ void restart_lammps(LAMMPS *lmp, const TestConfig &cfg) void data_lammps(LAMMPS *lmp, const TestConfig &cfg) { // utility lambdas to improve readability - auto command = [&](const std::string & line) { + auto command = [&](const std::string &line) { lmp->input->one(line.c_str()); }; - auto parse_input_script = [&](const std::string & filename) { + auto parse_input_script = [&](const std::string &filename) { lmp->input->file(filename.c_str()); }; @@ -193,7 +191,7 @@ void data_lammps(LAMMPS *lmp, const TestConfig &cfg) command("variable newton_pair delete"); command("variable newton_pair index on"); - for (auto& pre_command : cfg.pre_commands) { + for (auto &pre_command : cfg.pre_commands) { command(pre_command); } @@ -203,10 +201,10 @@ void data_lammps(LAMMPS *lmp, const TestConfig &cfg) std::string input_file = INPUT_FOLDER + PATH_SEP + cfg.input_file; parse_input_script(input_file); - for (auto& pair_coeff : cfg.pair_coeff) { + for (auto &pair_coeff : cfg.pair_coeff) { command("pair_coeff " + pair_coeff); } - for (auto& post_command : cfg.post_commands) { + for (auto &post_command : cfg.post_commands) { command(post_command); } command("run 0 post no"); @@ -217,16 +215,15 @@ void data_lammps(LAMMPS *lmp, const TestConfig &cfg) void generate_yaml_file(const char *outfile, const TestConfig &config) { // initialize system geometry - const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite" }; + const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"}; char **argv = (char **)args; - int argc = sizeof(args)/sizeof(char *); - LAMMPS *lmp = init_lammps(argc,argv,config); + int argc = sizeof(args) / sizeof(char *); + LAMMPS *lmp = init_lammps(argc, argv, config); if (!lmp) { std::cerr << "One or more prerequisite styles are not available " - "in this LAMMPS configuration:\n"; + "in this LAMMPS configuration:\n"; for (auto prerequisite : config.prerequisites) { - std::cerr << prerequisite.first << "_style " - << prerequisite.second << "\n"; + std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n"; } return; } @@ -244,7 +241,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // date_generated std::time_t now = time(NULL); block = ctime(&now); - block = block.substr(0,block.find("\n")-1); + block = block.substr(0, block.find("\n") - 1); writer.emit("date_generated", block); // epsilon @@ -252,14 +249,14 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // prerequisites block.clear(); - for (auto prerequisite : config.prerequisites) { + for (auto prerequisite : config.prerequisites) { block += prerequisite.first + " " + prerequisite.second + "\n"; } writer.emit_block("prerequisites", block); // pre_commands block.clear(); - for (auto command : config.pre_commands) { + for (auto command : config.pre_commands) { block += command + "\n"; } writer.emit_block("pre_commands", block); @@ -303,17 +300,17 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // init_stress double *stress = lmp->force->pair->virial; - snprintf(buf,bufsize,"% 23.16e % 23.16e % 23.16e % 23.16e % 23.16e % 23.16e", - stress[0],stress[1],stress[2],stress[3],stress[4],stress[5]); + snprintf(buf, bufsize, "% 23.16e % 23.16e % 23.16e % 23.16e % 23.16e % 23.16e", stress[0], + stress[1], stress[2], stress[3], stress[4], stress[5]); writer.emit_block("init_stress", buf); // init_forces block.clear(); double **f = lmp->atom->f; tagint *tag = lmp->atom->tag; - for (int i=0; i < natoms; ++i) { - snprintf(buf,bufsize,"% 3d % 23.16e % 23.16e % 23.16e\n", - (int)tag[i], f[i][0], f[i][1], f[i][2]); + for (int i = 0; i < natoms; ++i) { + snprintf(buf, bufsize, "% 3d % 23.16e % 23.16e % 23.16e\n", (int)tag[i], f[i][0], f[i][1], + f[i][2]); block += buf; } writer.emit_block("init_forces", block); @@ -329,40 +326,40 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // run_stress stress = lmp->force->pair->virial; - snprintf(buf,bufsize,"% 23.16e % 23.16e % 23.16e % 23.16e % 23.16e % 23.16e", - stress[0],stress[1],stress[2],stress[3],stress[4],stress[5]); + snprintf(buf, bufsize, "% 23.16e % 23.16e % 23.16e % 23.16e % 23.16e % 23.16e", stress[0], + stress[1], stress[2], stress[3], stress[4], stress[5]); writer.emit_block("run_stress", buf); block.clear(); f = lmp->atom->f; tag = lmp->atom->tag; - for (int i=0; i < natoms; ++i) { - snprintf(buf,bufsize,"% 3d % 23.16e % 23.16e % 23.16e\n", - (int)tag[i], f[i][0], f[i][1], f[i][2]); + for (int i = 0; i < natoms; ++i) { + snprintf(buf, bufsize, "% 3d % 23.16e % 23.16e % 23.16e\n", (int)tag[i], f[i][0], f[i][1], + f[i][2]); block += buf; } writer.emit_block("run_forces", block); - cleanup_lammps(lmp,config); + cleanup_lammps(lmp, config); return; } -TEST(PairStyle, plain) { - const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite" }; +TEST(PairStyle, plain) +{ + const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"}; char **argv = (char **)args; - int argc = sizeof(args)/sizeof(char *); + int argc = sizeof(args) / sizeof(char *); ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc,argv,test_config,true); + LAMMPS *lmp = init_lammps(argc, argv, test_config, true); std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; if (!lmp) { std::cerr << "One or more prerequisite styles are not available " - "in this LAMMPS configuration:\n"; + "in this LAMMPS configuration:\n"; for (auto prerequisite : test_config.prerequisites) { - std::cerr << prerequisite.first << "_style " - << prerequisite.second << "\n"; + std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n"; } GTEST_SKIP(); } @@ -372,22 +369,21 @@ TEST(PairStyle, plain) { // abort if running in parallel and not all atoms are local const int nlocal = lmp->atom->nlocal; - ASSERT_EQ(lmp->atom->natoms,nlocal); + ASSERT_EQ(lmp->atom->natoms, nlocal); double epsilon = test_config.epsilon; - double **f=lmp->atom->f; - tagint *tag=lmp->atom->tag; + double **f = lmp->atom->f; + tagint *tag = lmp->atom->tag; ErrorStats stats; stats.reset(); const std::vector &f_ref = test_config.init_forces; - ASSERT_EQ(nlocal+1,f_ref.size()); - for (int i=0; i < nlocal; ++i) { + ASSERT_EQ(nlocal + 1, f_ref.size()); + for (int i = 0; i < nlocal; ++i) { EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); } - if (print_stats) - std::cerr << "init_forces stats, newton on: " << stats << std::endl; + if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; Pair *pair = lmp->force->pair; double *stress = pair->virial; @@ -398,14 +394,12 @@ TEST(PairStyle, plain) { EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) - std::cerr << "init_stress stats, newton on: " << stats << std::endl; + if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl; stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.init_coul, epsilon); - if (print_stats) - std::cerr << "init_energy stats, newton on: " << stats << std::endl; + if (print_stats) std::cerr << "init_energy stats, newton on: " << stats << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); run_lammps(lmp); @@ -414,15 +408,14 @@ TEST(PairStyle, plain) { f = lmp->atom->f; stress = pair->virial; const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal+1,f_run.size()); + ASSERT_EQ(nlocal + 1, f_run.size()); stats.reset(); - for (int i=0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5*epsilon); + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon); } - if (print_stats) - std::cerr << "run_forces stats, newton on: " << stats << std::endl; + if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; stress = pair->virial; stats.reset(); @@ -432,54 +425,49 @@ TEST(PairStyle, plain) { EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) - std::cerr << "run_stress stats, newton on: " << stats << std::endl; + if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; stats.reset(); int id = lmp->modify->find_compute("sum"); double energy = lmp->modify->compute[id]->compute_scalar(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.run_vdwl, epsilon); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.run_coul, epsilon); - EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl+pair->eng_coul),energy, epsilon); - if (print_stats) - std::cerr << "run_energy stats, newton on: " << stats << std::endl; + EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl + pair->eng_coul), energy, epsilon); + if (print_stats) std::cerr << "run_energy stats, newton on: " << stats << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); - cleanup_lammps(lmp,test_config); - lmp = init_lammps(argc,argv,test_config,false); + cleanup_lammps(lmp, test_config); + lmp = init_lammps(argc, argv, test_config, false); if (!verbose) ::testing::internal::GetCapturedStdout(); // skip over these tests if newton pair is forced to be on if (lmp->force->newton_pair == 0) { - f=lmp->atom->f; - tag=lmp->atom->tag; + f = lmp->atom->f; + tag = lmp->atom->tag; stats.reset(); - for (int i=0; i < nlocal; ++i) { + for (int i = 0; i < nlocal; ++i) { EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); } - if (print_stats) - std::cerr << "init_forces stats, newton off:" << stats << std::endl; + if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; pair = lmp->force->pair; stress = pair->virial; stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 3*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 3*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 3*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 3*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 3*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 3*epsilon); - if (print_stats) - std::cerr << "init_stress stats, newton off:" << stats << std::endl; + EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 3 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 3 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 3 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 3 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 3 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 3 * epsilon); + if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.init_coul, epsilon); - if (print_stats) - std::cerr << "init_energy stats, newton off:" << stats << std::endl; + if (print_stats) std::cerr << "init_energy stats, newton off:" << stats << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); run_lammps(lmp); @@ -488,13 +476,12 @@ TEST(PairStyle, plain) { f = lmp->atom->f; stress = pair->virial; stats.reset(); - for (int i=0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5*epsilon); + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon); } - if (print_stats) - std::cerr << "run_forces stats, newton off:" << stats << std::endl; + if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; stress = pair->virial; stats.reset(); @@ -504,34 +491,31 @@ TEST(PairStyle, plain) { EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) - std::cerr << "run_stress stats, newton off:" << stats << std::endl; + if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; stats.reset(); id = lmp->modify->find_compute("sum"); energy = lmp->modify->compute[id]->compute_scalar(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.run_vdwl, epsilon); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.run_coul, epsilon); - EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl+pair->eng_coul),energy, epsilon); - if (print_stats) - std::cerr << "run_energy stats, newton off:" << stats << std::endl; + EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl + pair->eng_coul), energy, epsilon); + if (print_stats) std::cerr << "run_energy stats, newton off:" << stats << std::endl; } if (!verbose) ::testing::internal::CaptureStdout(); restart_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f=lmp->atom->f; - tag=lmp->atom->tag; + f = lmp->atom->f; + tag = lmp->atom->tag; stats.reset(); - ASSERT_EQ(nlocal+1,f_ref.size()); - for (int i=0; i < nlocal; ++i) { + ASSERT_EQ(nlocal + 1, f_ref.size()); + for (int i = 0; i < nlocal; ++i) { EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); } - if (print_stats) - std::cerr << "restart_forces stats:" << stats << std::endl; + if (print_stats) std::cerr << "restart_forces stats:" << stats << std::endl; pair = lmp->force->pair; stress = pair->virial; @@ -542,30 +526,27 @@ TEST(PairStyle, plain) { EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) - std::cerr << "restart_stress stats:" << stats << std::endl; + if (print_stats) std::cerr << "restart_stress stats:" << stats << std::endl; stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.init_coul, epsilon); - if (print_stats) - std::cerr << "restart_energy stats:" << stats << std::endl; + if (print_stats) std::cerr << "restart_energy stats:" << stats << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); data_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f=lmp->atom->f; - tag=lmp->atom->tag; + f = lmp->atom->f; + tag = lmp->atom->tag; stats.reset(); - ASSERT_EQ(nlocal+1,f_ref.size()); - for (int i=0; i < nlocal; ++i) { + ASSERT_EQ(nlocal + 1, f_ref.size()); + for (int i = 0; i < nlocal; ++i) { EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); } - if (print_stats) - std::cerr << "data_forces stats:" << stats << std::endl; + if (print_stats) std::cerr << "data_forces stats:" << stats << std::endl; pair = lmp->force->pair; stress = pair->virial; @@ -576,19 +557,17 @@ TEST(PairStyle, plain) { EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) - std::cerr << "data_stress stats:" << stats << std::endl; + if (print_stats) std::cerr << "data_stress stats:" << stats << std::endl; stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.init_coul, epsilon); - if (print_stats) - std::cerr << "data_energy stats:" << stats << std::endl; + if (print_stats) std::cerr << "data_energy stats:" << stats << std::endl; if (pair->respa_enable) { if (!verbose) ::testing::internal::CaptureStdout(); - cleanup_lammps(lmp,test_config); - lmp = init_lammps(argc,argv,test_config,false); + cleanup_lammps(lmp, test_config); + lmp = init_lammps(argc, argv, test_config, false); lmp->input->one("run_style respa 2 1 inner 1 4.0 5.0 outer 2"); run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); @@ -599,16 +578,15 @@ TEST(PairStyle, plain) { if (pair->ncoultablebits) epsilon *= 1.0e6; f = lmp->atom->f; - tag=lmp->atom->tag; + tag = lmp->atom->tag; pair = lmp->force->pair; stats.reset(); - for (int i=0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5*epsilon); + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon); } - if (print_stats) - std::cerr << "run_forces stats, r-RESPA:" << stats << std::endl; + if (print_stats) std::cerr << "run_forces stats, r-RESPA:" << stats << std::endl; stress = pair->virial; stats.reset(); @@ -618,41 +596,39 @@ TEST(PairStyle, plain) { EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) - std::cerr << "run_stress stats, r-RESPA:" << stats << std::endl; + if (print_stats) std::cerr << "run_stress stats, r-RESPA:" << stats << std::endl; stats.reset(); id = lmp->modify->find_compute("sum"); energy = lmp->modify->compute[id]->compute_scalar(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.run_vdwl, epsilon); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.run_coul, epsilon); - EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl+pair->eng_coul),energy, epsilon); - if (print_stats) - std::cerr << "run_energy stats, r-RESPA:" << stats << std::endl; + EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl + pair->eng_coul), energy, epsilon); + if (print_stats) std::cerr << "run_energy stats, r-RESPA:" << stats << std::endl; } if (!verbose) ::testing::internal::CaptureStdout(); - cleanup_lammps(lmp,test_config); + cleanup_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); }; -TEST(PairStyle, omp) { +TEST(PairStyle, omp) +{ if (!LAMMPS::is_installed_pkg("USER-OMP")) GTEST_SKIP(); - const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", - "-nocite", "-pk", "omp", "4", "-sf", "omp"}; + const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", + "-pk", "omp", "4", "-sf", "omp"}; char **argv = (char **)args; - int argc = sizeof(args)/sizeof(char *); + int argc = sizeof(args) / sizeof(char *); ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc,argv,test_config,true); + LAMMPS *lmp = init_lammps(argc, argv, test_config, true); std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; if (!lmp) { std::cerr << "One or more prerequisite styles with /omp suffix\n" - "are not available in this LAMMPS configuration:\n"; + "are not available in this LAMMPS configuration:\n"; for (auto prerequisite : test_config.prerequisites) { - std::cerr << prerequisite.first << "_style " - << prerequisite.second << "\n"; + std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n"; } GTEST_SKIP(); } @@ -662,40 +638,37 @@ TEST(PairStyle, omp) { // abort if running in parallel and not all atoms are local const int nlocal = lmp->atom->nlocal; - ASSERT_EQ(lmp->atom->natoms,nlocal); + ASSERT_EQ(lmp->atom->natoms, nlocal); // relax error a bit for USER-OMP package - double epsilon = 5.0*test_config.epsilon; - double **f=lmp->atom->f; - tagint *tag=lmp->atom->tag; + double epsilon = 5.0 * test_config.epsilon; + double **f = lmp->atom->f; + tagint *tag = lmp->atom->tag; const std::vector &f_ref = test_config.init_forces; ErrorStats stats; stats.reset(); - for (int i=0; i < nlocal; ++i) { + for (int i = 0; i < nlocal; ++i) { EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); } - if (print_stats) - std::cerr << "init_forces stats, newton on: " << stats << std::endl; + if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; Pair *pair = lmp->force->pair; double *stress = pair->virial; stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10*epsilon); - if (print_stats) - std::cerr << "init_stress stats, newton on: " << stats << std::endl; + EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); + if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl; stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.init_coul, epsilon); - if (print_stats) - std::cerr << "init_energy stats, newton on: " << stats << std::endl; + if (print_stats) std::cerr << "init_energy stats, newton on: " << stats << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); run_lammps(lmp); @@ -704,72 +677,66 @@ TEST(PairStyle, omp) { f = lmp->atom->f; stress = pair->virial; const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal+1,f_run.size()); + ASSERT_EQ(nlocal + 1, f_run.size()); stats.reset(); - for (int i=0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5*epsilon); + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon); } - if (print_stats) - std::cerr << "run_forces stats, newton on: " << stats << std::endl; + if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; stress = pair->virial; stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10*epsilon); - if (print_stats) - std::cerr << "run_stress stats, newton on: " << stats << std::endl; + EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); + if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; stats.reset(); int id = lmp->modify->find_compute("sum"); double energy = lmp->modify->compute[id]->compute_scalar(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.run_vdwl, epsilon); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.run_coul, epsilon); - EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl+pair->eng_coul),energy, epsilon); - if (print_stats) - std::cerr << "run_energy stats, newton on: " << stats << std::endl; + EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl + pair->eng_coul), energy, epsilon); + if (print_stats) std::cerr << "run_energy stats, newton on: " << stats << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); - cleanup_lammps(lmp,test_config); - lmp = init_lammps(argc,argv,test_config,false); + cleanup_lammps(lmp, test_config); + lmp = init_lammps(argc, argv, test_config, false); if (!verbose) ::testing::internal::GetCapturedStdout(); // skip over these tests if newton pair is forced to be on if (lmp->force->newton_pair == 0) { - f=lmp->atom->f; - tag=lmp->atom->tag; + f = lmp->atom->f; + tag = lmp->atom->tag; stats.reset(); - for (int i=0; i < nlocal; ++i) { + for (int i = 0; i < nlocal; ++i) { EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); } - if (print_stats) - std::cerr << "init_forces stats, newton off:" << stats << std::endl; + if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; pair = lmp->force->pair; stress = pair->virial; stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10*epsilon); - if (print_stats) - std::cerr << "init_stress stats, newton off:" << stats << std::endl; + EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); + if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.init_coul, epsilon); - if (print_stats) - std::cerr << "init_energy stats, newton off:" << stats << std::endl; + if (print_stats) std::cerr << "init_energy stats, newton off:" << stats << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); run_lammps(lmp); @@ -777,79 +744,75 @@ TEST(PairStyle, omp) { f = lmp->atom->f; stats.reset(); - for (int i=0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5*epsilon); + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon); } - if (print_stats) - std::cerr << "run_forces stats, newton off:" << stats << std::endl; + if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; stress = pair->virial; stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10*epsilon); - if (print_stats) - std::cerr << "run_stress stats, newton off:" << stats << std::endl; + EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); + if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; stats.reset(); id = lmp->modify->find_compute("sum"); energy = lmp->modify->compute[id]->compute_scalar(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.run_vdwl, epsilon); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.run_coul, epsilon); - EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl+pair->eng_coul),energy, epsilon); - if (print_stats) - std::cerr << "run_energy stats, newton off:" << stats << std::endl; + EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl + pair->eng_coul), energy, epsilon); + if (print_stats) std::cerr << "run_energy stats, newton off:" << stats << std::endl; } if (!verbose) ::testing::internal::CaptureStdout(); - cleanup_lammps(lmp,test_config); + cleanup_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); }; -TEST(PairStyle, intel) { +TEST(PairStyle, intel) +{ if (!LAMMPS::is_installed_pkg("USER-INTEL")) GTEST_SKIP(); - const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", - "-nocite", "-pk", "intel", "0", "mode", "double", - "omp", "4", "lrt", "no", "-sf", "intel"}; + const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", + "-pk", "intel", "0", "mode", "double", "omp", + "4", "lrt", "no", "-sf", "intel"}; char **argv = (char **)args; - int argc = sizeof(args)/sizeof(char *); + int argc = sizeof(args) / sizeof(char *); ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc,argv,test_config); + LAMMPS *lmp = init_lammps(argc, argv, test_config); std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; if (!lmp) { std::cerr << "One or more prerequisite styles with /intel suffix\n" - "are not available in this LAMMPS configuration:\n"; + "are not available in this LAMMPS configuration:\n"; for (auto prerequisite : test_config.prerequisites) { - std::cerr << prerequisite.first << "_style " - << prerequisite.second << "\n"; + std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n"; } GTEST_SKIP(); } if (test_config.pair_style == "rebo") { - if (!verbose) ::testing::internal::CaptureStdout(); - cleanup_lammps(lmp,test_config); - if (!verbose) ::testing::internal::GetCapturedStdout(); - std::cerr << "Skipping pair style rebo/intel\n"; - GTEST_SKIP(); + if (!verbose) ::testing::internal::CaptureStdout(); + cleanup_lammps(lmp, test_config); + if (!verbose) ::testing::internal::GetCapturedStdout(); + std::cerr << "Skipping pair style rebo/intel\n"; + GTEST_SKIP(); } // relax error a bit for USER-INTEL package - double epsilon = 7.5*test_config.epsilon; + double epsilon = 7.5 * test_config.epsilon; // we need to relax the epsilon a LOT for tests using long-range // coulomb with tabulation. seems more like mixed precision or a bug for (auto post_cmd : test_config.post_commands) { if (post_cmd.find("pair_modify table") != std::string::npos) { - if (post_cmd.find("pair_modify table 0") == std::string::npos) - epsilon *= 1000000.0; + if (post_cmd.find("pair_modify table 0") == std::string::npos) epsilon *= 1000000.0; } } @@ -858,38 +821,35 @@ TEST(PairStyle, intel) { // abort if running in parallel and not all atoms are local const int nlocal = lmp->atom->nlocal; - ASSERT_EQ(lmp->atom->natoms,nlocal); + ASSERT_EQ(lmp->atom->natoms, nlocal); - double **f=lmp->atom->f; - tagint *tag=lmp->atom->tag; + double **f = lmp->atom->f; + tagint *tag = lmp->atom->tag; const std::vector &f_ref = test_config.init_forces; ErrorStats stats; stats.reset(); - for (int i=0; i < nlocal; ++i) { + for (int i = 0; i < nlocal; ++i) { EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); } - if (print_stats) - std::cerr << "init_forces stats:" << stats << std::endl; + if (print_stats) std::cerr << "init_forces stats:" << stats << std::endl; Pair *pair = lmp->force->pair; double *stress = pair->virial; stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10*epsilon); - if (print_stats) - std::cerr << "init_stress stats:" << stats << std::endl; + EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); + if (print_stats) std::cerr << "init_stress stats:" << stats << std::endl; stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.init_coul, epsilon); - if (print_stats) - std::cerr << "init_energy stats:" << stats << std::endl; + if (print_stats) std::cerr << "init_energy stats:" << stats << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); run_lammps(lmp); @@ -898,26 +858,24 @@ TEST(PairStyle, intel) { f = lmp->atom->f; stress = pair->virial; const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal+1,f_run.size()); + ASSERT_EQ(nlocal + 1, f_run.size()); stats.reset(); - for (int i=0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5*epsilon); + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon); } - if (print_stats) - std::cerr << "run_forces stats:" << stats << std::endl; + if (print_stats) std::cerr << "run_forces stats:" << stats << std::endl; stress = pair->virial; stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10*epsilon); - if (print_stats) - std::cerr << "run_stress stats:" << stats << std::endl; + EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); + if (print_stats) std::cerr << "run_stress stats:" << stats << std::endl; stats.reset(); int id = lmp->modify->find_compute("sum"); @@ -926,36 +884,33 @@ TEST(PairStyle, intel) { EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.run_coul, epsilon); // rebo family of pair styles will have a large error in per-atom energy for USER-INTEL - if (test_config.pair_style.find("rebo") != std::string::npos) - epsilon *= 100000.0; + if (test_config.pair_style.find("rebo") != std::string::npos) epsilon *= 100000.0; - EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl+pair->eng_coul),energy, epsilon); - if (print_stats) - std::cerr << "run_energy stats:" << stats << std::endl; + EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl + pair->eng_coul), energy, epsilon); + if (print_stats) std::cerr << "run_energy stats:" << stats << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); - cleanup_lammps(lmp,test_config); + cleanup_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); }; -TEST(PairStyle, opt) { +TEST(PairStyle, opt) +{ if (!LAMMPS::is_installed_pkg("OPT")) GTEST_SKIP(); - const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", - "-nocite", "-sf", "opt"}; + const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", "-sf", "opt"}; char **argv = (char **)args; - int argc = sizeof(args)/sizeof(char *); + int argc = sizeof(args) / sizeof(char *); if (!verbose) ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc,argv,test_config); + LAMMPS *lmp = init_lammps(argc, argv, test_config); std::string output; if (!verbose) output = ::testing::internal::GetCapturedStdout(); if (!lmp) { std::cerr << "One or more prerequisite styles with /opt suffix\n" - "are not available in this LAMMPS configuration:\n"; + "are not available in this LAMMPS configuration:\n"; for (auto prerequisite : test_config.prerequisites) { - std::cerr << prerequisite.first << "_style " - << prerequisite.second << "\n"; + std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n"; } GTEST_SKIP(); } @@ -965,40 +920,37 @@ TEST(PairStyle, opt) { // abort if running in parallel and not all atoms are local const int nlocal = lmp->atom->nlocal; - ASSERT_EQ(lmp->atom->natoms,nlocal); + ASSERT_EQ(lmp->atom->natoms, nlocal); // relax error a bit for OPT package - double epsilon = 2.0*test_config.epsilon; - double **f=lmp->atom->f; - tagint *tag=lmp->atom->tag; + double epsilon = 2.0 * test_config.epsilon; + double **f = lmp->atom->f; + tagint *tag = lmp->atom->tag; const std::vector &f_ref = test_config.init_forces; ErrorStats stats; stats.reset(); - for (int i=0; i < nlocal; ++i) { + for (int i = 0; i < nlocal; ++i) { EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); } - if (print_stats) - std::cerr << "init_forces stats:" << stats << std::endl; + if (print_stats) std::cerr << "init_forces stats:" << stats << std::endl; Pair *pair = lmp->force->pair; double *stress = pair->virial; stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10*epsilon); - if (print_stats) - std::cerr << "init_stress stats:" << stats << std::endl; + EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); + if (print_stats) std::cerr << "init_stress stats:" << stats << std::endl; stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.init_coul, epsilon); - if (print_stats) - std::cerr << "init_energy stats:" << stats << std::endl; + if (print_stats) std::cerr << "init_energy stats:" << stats << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); run_lammps(lmp); @@ -1007,57 +959,54 @@ TEST(PairStyle, opt) { f = lmp->atom->f; stress = pair->virial; const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal+1,f_run.size()); + ASSERT_EQ(nlocal + 1, f_run.size()); stats.reset(); - for (int i=0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5*epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5*epsilon); + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5 * epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon); } - if (print_stats) - std::cerr << "run_forces stats:" << stats << std::endl; + if (print_stats) std::cerr << "run_forces stats:" << stats << std::endl; stress = pair->virial; stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10*epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10*epsilon); - if (print_stats) - std::cerr << "run_stress stats:" << stats << std::endl; + EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); + EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); + if (print_stats) std::cerr << "run_stress stats:" << stats << std::endl; stats.reset(); int id = lmp->modify->find_compute("sum"); double energy = lmp->modify->compute[id]->compute_scalar(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.run_vdwl, epsilon); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.run_coul, epsilon); - EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl+pair->eng_coul),energy, epsilon); - if (print_stats) - std::cerr << "run_energy stats:" << stats << std::endl; + EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl + pair->eng_coul), energy, epsilon); + if (print_stats) std::cerr << "run_energy stats:" << stats << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); - cleanup_lammps(lmp,test_config); + cleanup_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); }; -TEST(PairStyle, single) { - const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite" }; +TEST(PairStyle, single) +{ + const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"}; char **argv = (char **)args; - int argc = sizeof(args)/sizeof(char *); + int argc = sizeof(args) / sizeof(char *); // create a LAMMPS instance with standard settings to detect the number of atom types if (!verbose) ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc,argv,test_config); + LAMMPS *lmp = init_lammps(argc, argv, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); if (!lmp) { std::cerr << "One or more prerequisite styles are not available " - "in this LAMMPS configuration:\n"; + "in this LAMMPS configuration:\n"; for (auto prerequisite : test_config.prerequisites) { - std::cerr << prerequisite.first << "_style " - << prerequisite.second << "\n"; + std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n"; } GTEST_SKIP(); } @@ -1068,28 +1017,28 @@ TEST(PairStyle, single) { if (molecular > 1) { std::cerr << "Only atomic and simple molecular atom styles are supported\n"; if (!verbose) ::testing::internal::CaptureStdout(); - cleanup_lammps(lmp,test_config); + cleanup_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); GTEST_SKIP(); } Pair *pair = lmp->force->pair; if (!pair->single_enable) { - std::cerr << "Single method not available for pair style " - << test_config.pair_style << std::endl; + std::cerr << "Single method not available for pair style " << test_config.pair_style + << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); - cleanup_lammps(lmp,test_config); + cleanup_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); GTEST_SKIP(); } // The single function in EAM is different from what we assume // here, therefore we have to skip testing those pair styles. - if ((test_config.pair_style.substr(0,3) == "eam") - || ((test_config.pair_style.substr(0,6) == "hybrid") - && (test_config.pair_style.find("eam") != std::string::npos))) { + if ((test_config.pair_style.substr(0, 3) == "eam") || + ((test_config.pair_style.substr(0, 6) == "hybrid") && + (test_config.pair_style.find("eam") != std::string::npos))) { if (!verbose) ::testing::internal::CaptureStdout(); - cleanup_lammps(lmp,test_config); + cleanup_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); GTEST_SKIP(); } @@ -1098,7 +1047,7 @@ TEST(PairStyle, single) { if (!verbose) ::testing::internal::CaptureStdout(); // utility lambda to improve readability - auto command = [&](const std::string & line) { + auto command = [&](const std::string &line) { lmp->input->one(line.c_str()); }; @@ -1108,7 +1057,7 @@ TEST(PairStyle, single) { command("variable input_dir index " + INPUT_FOLDER); - for (auto& pre_command : test_config.pre_commands) { + for (auto &pre_command : test_config.pre_commands) { command(pre_command); } @@ -1126,7 +1075,7 @@ TEST(PairStyle, single) { command("region box block -10.0 10.0 -10.0 10.0 -10.0 10.0 units box"); char buf[10]; - snprintf(buf,10,"%d",ntypes); + snprintf(buf, 10, "%d", ntypes); std::string cmd("create_box "); cmd += buf; cmd += " box"; @@ -1141,7 +1090,7 @@ TEST(PairStyle, single) { pair = lmp->force->pair; - for (auto& pair_coeff : test_config.pair_coeff) { + for (auto &pair_coeff : test_config.pair_coeff) { command("pair_coeff " + pair_coeff); } @@ -1159,7 +1108,7 @@ TEST(PairStyle, single) { command("bond_coeff 1 2.0"); } - for (auto& post_command : test_config.post_commands) { + for (auto &post_command : test_config.post_commands) { command(post_command); } @@ -1169,12 +1118,12 @@ TEST(PairStyle, single) { int idx1 = lmp->atom->map(1); int idx2 = lmp->atom->map(2); double epsilon = test_config.epsilon; - double **f=lmp->atom->f; - double **x=lmp->atom->x; + double **f = lmp->atom->f; + double **x = lmp->atom->x; double delx = x[idx2][0] - x[idx1][0]; double dely = x[idx2][1] - x[idx1][1]; double delz = x[idx2][2] - x[idx1][2]; - double rsq = delx*delx+dely*dely+delz*delz; + double rsq = delx * delx + dely * dely + delz * delz; double fsingle = 0.0; double epair[4], esngl[4]; double splj = lmp->force->special_lj[1]; @@ -1183,12 +1132,12 @@ TEST(PairStyle, single) { epair[0] = pair->eng_vdwl + pair->eng_coul; esngl[0] = pair->single(idx1, idx2, 1, 2, rsq, spcl, splj, fsingle); - EXPECT_FP_LE_WITH_EPS(f[idx1][0],-fsingle*delx, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx1][1],-fsingle*dely, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx1][2],-fsingle*delz, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx2][0], fsingle*delx, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx2][1], fsingle*dely, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx2][2], fsingle*delz, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx1][0], -fsingle * delx, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx1][1], -fsingle * dely, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx1][2], -fsingle * delz, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx2][0], fsingle * delx, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx2][1], fsingle * dely, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx2][2], fsingle * delz, epsilon); if (!verbose) ::testing::internal::CaptureStdout(); command("displace_atoms all random 0.5 0.5 0.5 723456"); @@ -1202,17 +1151,17 @@ TEST(PairStyle, single) { delx = x[idx2][0] - x[idx1][0]; dely = x[idx2][1] - x[idx1][1]; delz = x[idx2][2] - x[idx1][2]; - rsq = delx*delx+dely*dely+delz*delz; + rsq = delx * delx + dely * dely + delz * delz; fsingle = 0.0; epair[1] = pair->eng_vdwl + pair->eng_coul; esngl[1] = pair->single(idx1, idx2, 1, 2, rsq, spcl, splj, fsingle); - EXPECT_FP_LE_WITH_EPS(f[idx1][0],-fsingle*delx, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx1][1],-fsingle*dely, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx1][2],-fsingle*delz, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx2][0], fsingle*delx, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx2][1], fsingle*dely, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx2][2], fsingle*delz, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx1][0], -fsingle * delx, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx1][1], -fsingle * dely, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx1][2], -fsingle * delz, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx2][0], fsingle * delx, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx2][1], fsingle * dely, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx2][2], fsingle * delz, epsilon); if (!verbose) ::testing::internal::CaptureStdout(); command("displace_atoms all random 0.5 0.5 0.5 3456963"); @@ -1226,17 +1175,17 @@ TEST(PairStyle, single) { delx = x[idx2][0] - x[idx1][0]; dely = x[idx2][1] - x[idx1][1]; delz = x[idx2][2] - x[idx1][2]; - rsq = delx*delx+dely*dely+delz*delz; + rsq = delx * delx + dely * dely + delz * delz; fsingle = 0.0; epair[2] = pair->eng_vdwl + pair->eng_coul; esngl[2] = pair->single(idx1, idx2, 1, 2, rsq, spcl, splj, fsingle); - EXPECT_FP_LE_WITH_EPS(f[idx1][0],-fsingle*delx, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx1][1],-fsingle*dely, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx1][2],-fsingle*delz, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx2][0], fsingle*delx, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx2][1], fsingle*dely, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx2][2], fsingle*delz, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx1][0], -fsingle * delx, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx1][1], -fsingle * dely, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx1][2], -fsingle * delz, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx2][0], fsingle * delx, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx2][1], fsingle * dely, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx2][2], fsingle * delz, epsilon); if (!verbose) ::testing::internal::CaptureStdout(); command("displace_atoms all random 0.5 0.5 0.5 9726532"); @@ -1250,78 +1199,76 @@ TEST(PairStyle, single) { delx = x[idx2][0] - x[idx1][0]; dely = x[idx2][1] - x[idx1][1]; delz = x[idx2][2] - x[idx1][2]; - rsq = delx*delx+dely*dely+delz*delz; + rsq = delx * delx + dely * dely + delz * delz; fsingle = 0.0; epair[3] = pair->eng_vdwl + pair->eng_coul; esngl[3] = pair->single(idx1, idx2, 1, 2, rsq, spcl, splj, fsingle); - EXPECT_FP_LE_WITH_EPS(f[idx1][0],-fsingle*delx, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx1][1],-fsingle*dely, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx1][2],-fsingle*delz, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx2][0], fsingle*delx, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx2][1], fsingle*dely, epsilon); - EXPECT_FP_LE_WITH_EPS(f[idx2][2], fsingle*delz, epsilon); - if (print_stats) - std::cerr << "single_force stats:" << stats << std::endl; + EXPECT_FP_LE_WITH_EPS(f[idx1][0], -fsingle * delx, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx1][1], -fsingle * dely, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx1][2], -fsingle * delz, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx2][0], fsingle * delx, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx2][1], fsingle * dely, epsilon); + EXPECT_FP_LE_WITH_EPS(f[idx2][2], fsingle * delz, epsilon); + if (print_stats) std::cerr << "single_force stats:" << stats << std::endl; - if ((test_config.pair_style.find("coul/dsf") != std::string::npos) - && (test_config.pair_style.find("coul/wolf") != std::string::npos)) { + if ((test_config.pair_style.find("coul/dsf") != std::string::npos) && + (test_config.pair_style.find("coul/wolf") != std::string::npos)) { stats.reset(); EXPECT_FP_LE_WITH_EPS(epair[0], esngl[0], epsilon); EXPECT_FP_LE_WITH_EPS(epair[1], esngl[1], epsilon); EXPECT_FP_LE_WITH_EPS(epair[2], esngl[2], epsilon); EXPECT_FP_LE_WITH_EPS(epair[3], esngl[3], epsilon); - if (print_stats) - std::cerr << "single_energy stats:" << stats << std::endl; + if (print_stats) std::cerr << "single_energy stats:" << stats << std::endl; } else if (print_stats) std::cerr << "skipping single_energy test due to self energy\n"; if (!verbose) ::testing::internal::CaptureStdout(); - cleanup_lammps(lmp,test_config); + cleanup_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); } -TEST(PairStyle, extract) { - const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite" }; +TEST(PairStyle, extract) +{ + const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"}; char **argv = (char **)args; - int argc = sizeof(args)/sizeof(char *); + int argc = sizeof(args) / sizeof(char *); if (!verbose) ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc,argv,test_config,true); + LAMMPS *lmp = init_lammps(argc, argv, test_config, true); if (!verbose) ::testing::internal::GetCapturedStdout(); if (!lmp) { std::cerr << "One or more prerequisite styles are not available " - "in this LAMMPS configuration:\n"; + "in this LAMMPS configuration:\n"; for (auto prerequisite : test_config.prerequisites) { - std::cerr << prerequisite.first << "_style " - << prerequisite.second << "\n"; + std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n"; } GTEST_SKIP(); } Pair *pair = lmp->force->pair; void *ptr = nullptr; int dim = 0; - for (auto& extract : test_config.extract) { + for (auto &extract : test_config.extract) { ptr = pair->extract(extract.first.c_str(), dim); EXPECT_NE(ptr, nullptr); EXPECT_EQ(dim, extract.second); } - ptr = pair->extract("does_not_exist",dim); + ptr = pair->extract("does_not_exist", dim); EXPECT_EQ(ptr, nullptr); // replace pair style with the same. // should just update setting, but not create new style. int ntypes = lmp->atom->ntypes; - for (int i=1; i <= ntypes; ++i) { - for (int j=1; j <= ntypes; ++j) { + for (int i = 1; i <= ntypes; ++i) { + for (int j = 1; j <= ntypes; ++j) { pair->cutsq[i][j] = -1.0; } } // utility lambda to improve readability - auto command = [&](const std::string & line) { + auto command = [&](const std::string &line) { lmp->input->one(line.c_str()); }; @@ -1329,19 +1276,19 @@ TEST(PairStyle, extract) { command("pair_style " + test_config.pair_style); EXPECT_EQ(pair, lmp->force->pair); - for (auto& pair_coeff : test_config.pair_coeff) { + for (auto &pair_coeff : test_config.pair_coeff) { command("pair_coeff " + pair_coeff); } pair->init(); if (!verbose) ::testing::internal::GetCapturedStdout(); - for (int i=1; i <= ntypes; ++i) { - for (int j=1; j <= ntypes; ++j) { - EXPECT_GE(pair->cutsq[i][j],0.0); + for (int i = 1; i <= ntypes; ++i) { + for (int j = 1; j <= ntypes; ++j) { + EXPECT_GE(pair->cutsq[i][j], 0.0); } } if (!verbose) ::testing::internal::CaptureStdout(); - cleanup_lammps(lmp,test_config); + cleanup_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); } diff --git a/unittest/force-styles/test_config.h b/unittest/force-styles/test_config.h index e808a0301c..3ac838f635 100644 --- a/unittest/force-styles/test_config.h +++ b/unittest/force-styles/test_config.h @@ -19,11 +19,11 @@ #include struct coord_t { - double x,y,z; + double x, y, z; }; struct stress_t { - double xx,yy,zz,xy,xz,yz; + double xx, yy, zz, xy, xz, yz; }; class TestConfig { @@ -32,7 +32,7 @@ public: std::string date_generated; std::string basename; double epsilon; - std::vector> prerequisites; + std::vector> prerequisites; std::vector pre_commands; std::vector post_commands; std::string input_file; @@ -48,7 +48,7 @@ public: std::vector dihedral_coeff; std::vector improper_coeff; std::vector equilibrium; - std::vector> extract; + std::vector> extract; int natoms; double init_energy; double run_energy; @@ -61,26 +61,13 @@ public: std::vector init_forces; std::vector run_forces; - TestConfig() : lammps_version(""), - date_generated(""), - basename(""), - epsilon(1.0e-14), - input_file(""), - pair_style("zero"), - bond_style("zero"), - angle_style("zero"), - dihedral_style("zero"), - improper_style("zero"), - kspace_style("none"), - natoms(0), - init_energy(0), - run_energy(0), - init_vdwl(0), - run_vdwl(0), - init_coul(0), - run_coul(0), - init_stress({0,0,0,0,0,0}), - run_stress({0,0,0,0,0,0}) { + TestConfig() : + lammps_version(""), date_generated(""), basename(""), epsilon(1.0e-14), input_file(""), + pair_style("zero"), bond_style("zero"), angle_style("zero"), dihedral_style("zero"), + improper_style("zero"), kspace_style("none"), natoms(0), init_energy(0), run_energy(0), + init_vdwl(0), run_vdwl(0), init_coul(0), run_coul(0), init_stress({0, 0, 0, 0, 0, 0}), + run_stress({0, 0, 0, 0, 0, 0}) + { prerequisites.clear(); pre_commands.clear(); post_commands.clear(); @@ -93,10 +80,10 @@ public: init_forces.clear(); run_forces.clear(); } - virtual ~TestConfig() {}; + virtual ~TestConfig(){}; private: - TestConfig(const TestConfig &) {}; + TestConfig(const TestConfig &){}; }; #endif diff --git a/unittest/force-styles/test_config_reader.cpp b/unittest/force-styles/test_config_reader.cpp index 3473782a7e..4733190aad 100644 --- a/unittest/force-styles/test_config_reader.cpp +++ b/unittest/force-styles/test_config_reader.cpp @@ -11,75 +11,78 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include "test_config.h" #include "test_config_reader.h" -#include "yaml_reader.h" +#include "test_config.h" #include "yaml.h" +#include "yaml_reader.h" -#include #include +#include -#include #include #include +#include #include #include -TestConfigReader::TestConfigReader(TestConfig & config) - : YamlReader(), config(config) { +TestConfigReader::TestConfigReader(TestConfig &config) : YamlReader(), config(config) +{ consumers["lammps_version"] = &TestConfigReader::lammps_version; consumers["date_generated"] = &TestConfigReader::date_generated; - consumers["epsilon"] = &TestConfigReader::epsilon; - consumers["prerequisites"] = &TestConfigReader::prerequisites; - consumers["pre_commands"] = &TestConfigReader::pre_commands; - consumers["post_commands"] = &TestConfigReader::post_commands; - consumers["input_file"] = &TestConfigReader::input_file; - consumers["extract"] = &TestConfigReader::extract; - consumers["natoms"] = &TestConfigReader::natoms; - consumers["init_stress"] = &TestConfigReader::init_stress; - consumers["run_stress"] = &TestConfigReader::run_stress; - consumers["init_forces"] = &TestConfigReader::init_forces; - consumers["run_forces"] = &TestConfigReader::run_forces; + consumers["epsilon"] = &TestConfigReader::epsilon; + consumers["prerequisites"] = &TestConfigReader::prerequisites; + consumers["pre_commands"] = &TestConfigReader::pre_commands; + consumers["post_commands"] = &TestConfigReader::post_commands; + consumers["input_file"] = &TestConfigReader::input_file; + consumers["extract"] = &TestConfigReader::extract; + consumers["natoms"] = &TestConfigReader::natoms; + consumers["init_stress"] = &TestConfigReader::init_stress; + consumers["run_stress"] = &TestConfigReader::run_stress; + consumers["init_forces"] = &TestConfigReader::init_forces; + consumers["run_forces"] = &TestConfigReader::run_forces; - consumers["pair_style"] = &TestConfigReader::pair_style; - consumers["pair_coeff"] = &TestConfigReader::pair_coeff; - consumers["init_vdwl"] = &TestConfigReader::init_vdwl; - consumers["init_coul"] = &TestConfigReader::init_coul; - consumers["run_vdwl"] = &TestConfigReader::run_vdwl; - consumers["run_coul"] = &TestConfigReader::run_coul; + consumers["pair_style"] = &TestConfigReader::pair_style; + consumers["pair_coeff"] = &TestConfigReader::pair_coeff; + consumers["init_vdwl"] = &TestConfigReader::init_vdwl; + consumers["init_coul"] = &TestConfigReader::init_coul; + consumers["run_vdwl"] = &TestConfigReader::run_vdwl; + consumers["run_coul"] = &TestConfigReader::run_coul; - consumers["bond_style"] = &TestConfigReader::bond_style; - consumers["bond_coeff"] = &TestConfigReader::bond_coeff; - consumers["angle_style"] = &TestConfigReader::angle_style; - consumers["angle_coeff"] = &TestConfigReader::angle_coeff; - consumers["init_energy"] = &TestConfigReader::init_energy; - consumers["run_energy"] = &TestConfigReader::run_energy; - consumers["equilibrium"] = &TestConfigReader::equilibrium; + consumers["bond_style"] = &TestConfigReader::bond_style; + consumers["bond_coeff"] = &TestConfigReader::bond_coeff; + consumers["angle_style"] = &TestConfigReader::angle_style; + consumers["angle_coeff"] = &TestConfigReader::angle_coeff; + consumers["init_energy"] = &TestConfigReader::init_energy; + consumers["run_energy"] = &TestConfigReader::run_energy; + consumers["equilibrium"] = &TestConfigReader::equilibrium; } -void TestConfigReader::prerequisites(const yaml_event_t & event) { +void TestConfigReader::prerequisites(const yaml_event_t &event) +{ config.prerequisites.clear(); std::stringstream data((char *)event.data.scalar.value); std::string key, value; - while(1) { + while (1) { data >> key >> value; if (data.eof()) break; - config.prerequisites.push_back(std::make_pair(key,value)); + config.prerequisites.push_back(std::make_pair(key, value)); } } -void TestConfigReader::pre_commands(const yaml_event_t & event) { +void TestConfigReader::pre_commands(const yaml_event_t &event) +{ config.pre_commands.clear(); std::stringstream data((char *)event.data.scalar.value); std::string line; - while(std::getline(data, line, '\n')) { + while (std::getline(data, line, '\n')) { config.pre_commands.push_back(line); } } -void TestConfigReader::post_commands(const yaml_event_t & event) { +void TestConfigReader::post_commands(const yaml_event_t &event) +{ config.post_commands.clear(); std::stringstream data((char *)event.data.scalar.value); std::string line; @@ -89,63 +92,68 @@ void TestConfigReader::post_commands(const yaml_event_t & event) { } } -void TestConfigReader::lammps_version(const yaml_event_t & event) { +void TestConfigReader::lammps_version(const yaml_event_t &event) +{ config.lammps_version = (char *)event.data.scalar.value; } -void TestConfigReader::date_generated(const yaml_event_t & event) { +void TestConfigReader::date_generated(const yaml_event_t &event) +{ config.date_generated = (char *)event.data.scalar.value; } -void TestConfigReader::epsilon(const yaml_event_t & event) { +void TestConfigReader::epsilon(const yaml_event_t &event) +{ config.epsilon = atof((char *)event.data.scalar.value); } -void TestConfigReader::input_file(const yaml_event_t & event) { +void TestConfigReader::input_file(const yaml_event_t &event) +{ config.input_file = (char *)event.data.scalar.value; } -void TestConfigReader::extract(const yaml_event_t & event) { +void TestConfigReader::extract(const yaml_event_t &event) +{ config.extract.clear(); std::stringstream data((char *)event.data.scalar.value); std::string name; int value; - while(1) { + while (1) { data >> name >> value; if (data.eof()) break; config.extract.push_back(make_pair(name, value)); } } -void TestConfigReader::natoms(const yaml_event_t & event) { +void TestConfigReader::natoms(const yaml_event_t &event) +{ config.natoms = atoi((char *)event.data.scalar.value); } -void TestConfigReader::init_stress(const yaml_event_t & event) { +void TestConfigReader::init_stress(const yaml_event_t &event) +{ stress_t stress; - sscanf((char *)event.data.scalar.value, - "%lg %lg %lg %lg %lg %lg", - &stress.xx, &stress.yy, &stress.zz, - &stress.xy, &stress.xz, &stress.yz); + sscanf((char *)event.data.scalar.value, "%lg %lg %lg %lg %lg %lg", &stress.xx, &stress.yy, + &stress.zz, &stress.xy, &stress.xz, &stress.yz); config.init_stress = stress; } -void TestConfigReader::run_stress(const yaml_event_t & event) { +void TestConfigReader::run_stress(const yaml_event_t &event) +{ stress_t stress; - sscanf((char *)event.data.scalar.value, - "%lg %lg %lg %lg %lg %lg", - &stress.xx, &stress.yy, &stress.zz, - &stress.xy, &stress.xz, &stress.yz); + sscanf((char *)event.data.scalar.value, "%lg %lg %lg %lg %lg %lg", &stress.xx, &stress.yy, + &stress.zz, &stress.xy, &stress.xz, &stress.yz); config.run_stress = stress; } -void TestConfigReader::init_forces(const yaml_event_t & event) { +void TestConfigReader::init_forces(const yaml_event_t &event) +{ config.init_forces.clear(); - config.init_forces.resize(config.natoms+1); - std::stringstream data((const char*)event.data.scalar.value); + config.init_forces.resize(config.natoms + 1); + std::stringstream data((const char *)event.data.scalar.value); std::string line; - while(std::getline(data, line, '\n')) { + while (std::getline(data, line, '\n')) { int tag = 0; coord_t xyz; sscanf(line.c_str(), "%d %lg %lg %lg", &tag, &xyz.x, &xyz.y, &xyz.z); @@ -153,13 +161,14 @@ void TestConfigReader::init_forces(const yaml_event_t & event) { } } -void TestConfigReader::run_forces(const yaml_event_t & event) { +void TestConfigReader::run_forces(const yaml_event_t &event) +{ config.run_forces.clear(); - config.run_forces.resize(config.natoms+1); + config.run_forces.resize(config.natoms + 1); std::stringstream data((char *)event.data.scalar.value); std::string line; - while(std::getline(data, line, '\n')) { + while (std::getline(data, line, '\n')) { int tag; coord_t xyz; sscanf(line.c_str(), "%d %lg %lg %lg", &tag, &xyz.x, &xyz.y, &xyz.z); @@ -167,11 +176,13 @@ void TestConfigReader::run_forces(const yaml_event_t & event) { } } -void TestConfigReader::pair_style(const yaml_event_t & event) { +void TestConfigReader::pair_style(const yaml_event_t &event) +{ config.pair_style = (char *)event.data.scalar.value; } -void TestConfigReader::pair_coeff(const yaml_event_t & event) { +void TestConfigReader::pair_coeff(const yaml_event_t &event) +{ config.pair_coeff.clear(); std::stringstream data((char *)event.data.scalar.value); std::string line; @@ -181,11 +192,13 @@ void TestConfigReader::pair_coeff(const yaml_event_t & event) { } } -void TestConfigReader::bond_style(const yaml_event_t & event) { +void TestConfigReader::bond_style(const yaml_event_t &event) +{ config.bond_style = (char *)event.data.scalar.value; } -void TestConfigReader::bond_coeff(const yaml_event_t & event) { +void TestConfigReader::bond_coeff(const yaml_event_t &event) +{ config.bond_coeff.clear(); std::stringstream data((char *)event.data.scalar.value); std::string line; @@ -195,11 +208,13 @@ void TestConfigReader::bond_coeff(const yaml_event_t & event) { } } -void TestConfigReader::angle_style(const yaml_event_t & event) { +void TestConfigReader::angle_style(const yaml_event_t &event) +{ config.angle_style = (char *)event.data.scalar.value; } -void TestConfigReader::angle_coeff(const yaml_event_t & event) { +void TestConfigReader::angle_coeff(const yaml_event_t &event) +{ config.angle_coeff.clear(); std::stringstream data((char *)event.data.scalar.value); std::string line; @@ -209,40 +224,46 @@ void TestConfigReader::angle_coeff(const yaml_event_t & event) { } } -void TestConfigReader::equilibrium(const yaml_event_t & event) { +void TestConfigReader::equilibrium(const yaml_event_t &event) +{ std::stringstream data((char *)event.data.scalar.value); config.equilibrium.clear(); double value; std::size_t num; data >> num; - for (std::size_t i=0; i < num; ++i) { + for (std::size_t i = 0; i < num; ++i) { data >> value; if (data.eof()) break; config.equilibrium.push_back(value); } } -void TestConfigReader::init_vdwl(const yaml_event_t & event) { +void TestConfigReader::init_vdwl(const yaml_event_t &event) +{ config.init_vdwl = atof((char *)event.data.scalar.value); } -void TestConfigReader::init_coul(const yaml_event_t & event) { +void TestConfigReader::init_coul(const yaml_event_t &event) +{ config.init_coul = atof((char *)event.data.scalar.value); } -void TestConfigReader::run_vdwl(const yaml_event_t & event) { +void TestConfigReader::run_vdwl(const yaml_event_t &event) +{ config.run_vdwl = atof((char *)event.data.scalar.value); } -void TestConfigReader::run_coul(const yaml_event_t & event) { +void TestConfigReader::run_coul(const yaml_event_t &event) +{ config.run_coul = atof((char *)event.data.scalar.value); } -void TestConfigReader::init_energy(const yaml_event_t & event) { +void TestConfigReader::init_energy(const yaml_event_t &event) +{ config.init_energy = atof((char *)event.data.scalar.value); } -void TestConfigReader::run_energy(const yaml_event_t & event) { +void TestConfigReader::run_energy(const yaml_event_t &event) +{ config.run_energy = atof((char *)event.data.scalar.value); } - diff --git a/unittest/force-styles/test_config_reader.h b/unittest/force-styles/test_config_reader.h index de960c81c6..1d7d9b6153 100644 --- a/unittest/force-styles/test_config_reader.h +++ b/unittest/force-styles/test_config_reader.h @@ -17,37 +17,37 @@ #include "yaml_reader.h" class TestConfigReader : public YamlReader { - TestConfig & config; + TestConfig &config; public: - TestConfigReader(TestConfig & config); + TestConfigReader(TestConfig &config); - void prerequisites(const yaml_event_t & event); - void pre_commands(const yaml_event_t & event); - void post_commands(const yaml_event_t & event); - void lammps_version(const yaml_event_t & event); - void date_generated(const yaml_event_t & event); - void epsilon(const yaml_event_t & event); - void input_file(const yaml_event_t & event); - void extract(const yaml_event_t & event); - void natoms(const yaml_event_t & event); - void init_stress(const yaml_event_t & event); - void run_stress(const yaml_event_t & event); - void init_forces(const yaml_event_t & event); - void run_forces(const yaml_event_t & event); - void pair_style(const yaml_event_t & event); - void pair_coeff(const yaml_event_t & event); - void bond_style(const yaml_event_t & event); - void bond_coeff(const yaml_event_t & event); - void angle_style(const yaml_event_t & event); - void angle_coeff(const yaml_event_t & event); - void equilibrium(const yaml_event_t & event); - void init_vdwl(const yaml_event_t & event); - void init_coul(const yaml_event_t & event); - void run_vdwl(const yaml_event_t & event); - void run_coul(const yaml_event_t & event); - void init_energy(const yaml_event_t & event); - void run_energy(const yaml_event_t & event); + void prerequisites(const yaml_event_t &event); + void pre_commands(const yaml_event_t &event); + void post_commands(const yaml_event_t &event); + void lammps_version(const yaml_event_t &event); + void date_generated(const yaml_event_t &event); + void epsilon(const yaml_event_t &event); + void input_file(const yaml_event_t &event); + void extract(const yaml_event_t &event); + void natoms(const yaml_event_t &event); + void init_stress(const yaml_event_t &event); + void run_stress(const yaml_event_t &event); + void init_forces(const yaml_event_t &event); + void run_forces(const yaml_event_t &event); + void pair_style(const yaml_event_t &event); + void pair_coeff(const yaml_event_t &event); + void bond_style(const yaml_event_t &event); + void bond_coeff(const yaml_event_t &event); + void angle_style(const yaml_event_t &event); + void angle_coeff(const yaml_event_t &event); + void equilibrium(const yaml_event_t &event); + void init_vdwl(const yaml_event_t &event); + void init_coul(const yaml_event_t &event); + void run_vdwl(const yaml_event_t &event); + void run_coul(const yaml_event_t &event); + void init_energy(const yaml_event_t &event); + void run_energy(const yaml_event_t &event); }; #endif diff --git a/unittest/force-styles/test_main.cpp b/unittest/force-styles/test_main.cpp index b7028e7d5e..fc59163a60 100644 --- a/unittest/force-styles/test_main.cpp +++ b/unittest/force-styles/test_main.cpp @@ -16,16 +16,15 @@ #include "test_config_reader.h" #include "gtest/gtest.h" -#include #include #include +#include // common read_yaml_file function bool read_yaml_file(const char *infile, TestConfig &config) { auto reader = TestConfigReader(config); - if (reader.parse_file(infile)) - return false; + if (reader.parse_file(infile)) return false; config.basename = reader.get_basename(); return true; @@ -76,32 +75,32 @@ int main(int argc, char **argv) return 2; } - int iarg=2; + int iarg = 2; while (iarg < argc) { - if (strcmp(argv[iarg],"-g") == 0) { - if (iarg+1 < argc) { - generate_yaml_file(argv[iarg+1], test_config); + if (strcmp(argv[iarg], "-g") == 0) { + if (iarg + 1 < argc) { + generate_yaml_file(argv[iarg + 1], test_config); return 0; } else { - usage(std::cerr,argv[0]); + usage(std::cerr, argv[0]); return 1; } - } else if (strcmp(argv[iarg],"-u") == 0) { + } else if (strcmp(argv[iarg], "-u") == 0) { generate_yaml_file(argv[1], test_config); return 0; - } else if (strcmp(argv[iarg],"-d") == 0) { - if (iarg+1 < argc) { - INPUT_FOLDER = argv[iarg+1]; + } else if (strcmp(argv[iarg], "-d") == 0) { + if (iarg + 1 < argc) { + INPUT_FOLDER = argv[iarg + 1]; iarg += 2; } else { - usage(std::cerr,argv[0]); + usage(std::cerr, argv[0]); return 1; } - } else if (strcmp(argv[iarg],"-s") == 0) { + } else if (strcmp(argv[iarg], "-s") == 0) { print_stats = true; ++iarg; - } else if (strcmp(argv[iarg],"-v") == 0) { + } else if (strcmp(argv[iarg], "-v") == 0) { verbose = true; ++iarg; } else { diff --git a/unittest/force-styles/test_main.h b/unittest/force-styles/test_main.h index 03ab9fc6f9..f541094122 100644 --- a/unittest/force-styles/test_main.h +++ b/unittest/force-styles/test_main.h @@ -22,13 +22,13 @@ extern bool print_stats; extern bool verbose; extern std::string INPUT_FOLDER; -#define EXPECT_FP_LE_WITH_EPS(val1,val2,eps) \ - do { \ - const double diff = fabs(val1-val2); \ - const double div = std::min(fabs(val1),fabs(val2)); \ - const double err = (div == 0.0) ? diff : diff/div; \ - stats.add(err); \ - EXPECT_PRED_FORMAT2(::testing::DoubleLE, err, eps); \ +#define EXPECT_FP_LE_WITH_EPS(val1, val2, eps) \ + do { \ + const double diff = fabs(val1 - val2); \ + const double div = std::min(fabs(val1), fabs(val2)); \ + const double err = (div == 0.0) ? diff : diff / div; \ + stats.add(err); \ + EXPECT_PRED_FORMAT2(::testing::DoubleLE, err, eps); \ } while (0); #endif diff --git a/unittest/force-styles/yaml_reader.h b/unittest/force-styles/yaml_reader.h index 90ac395055..7260a8cf9c 100644 --- a/unittest/force-styles/yaml_reader.h +++ b/unittest/force-styles/yaml_reader.h @@ -17,11 +17,11 @@ #include "yaml.h" #include +#include #include #include -#include -template class YamlReader { +template class YamlReader { private: enum StateValue { START, @@ -37,7 +37,7 @@ private: std::string basename; protected: - typedef void (ConsumerClass::*EventConsumer)(const yaml_event_t & event); + typedef void (ConsumerClass::*EventConsumer)(const yaml_event_t &event); std::map consumers; public: @@ -46,20 +46,21 @@ public: std::string get_basename() const { return basename; } - int parse_file(const std::string & infile) { + int parse_file(const std::string &infile) + { basename = infile; std::size_t found = basename.rfind(".yaml"); - if (found > 0) basename = basename.substr(0,found); + if (found > 0) basename = basename.substr(0, found); found = basename.find_last_of("/\\"); - if (found != std::string::npos) basename = basename.substr(found+1); + if (found != std::string::npos) basename = basename.substr(found + 1); - FILE *fp = fopen(infile.c_str(),"r"); + FILE *fp = fopen(infile.c_str(), "r"); yaml_parser_t parser; yaml_event_t event; if (!fp) { - std::cerr << "Cannot open yaml file '" << infile - << "': " << strerror(errno) << std::endl; + std::cerr << "Cannot open yaml file '" << infile << "': " << strerror(errno) + << std::endl; return 1; } yaml_parser_initialize(&parser); @@ -75,9 +76,9 @@ public: } if (accepted) { - if(!consume_key_value(key, event)) { - std::cerr << "Ignoring unknown key/value pair: " << key - << " = " << event.data.scalar.value << std::endl; + if (!consume_key_value(key, event)) { + std::cerr << "Ignoring unknown key/value pair: " << key << " = " + << event.data.scalar.value << std::endl; } } yaml_event_delete(&event); @@ -89,13 +90,14 @@ public: } protected: - bool consume_key_value(const std::string & key, const yaml_event_t & event) { + bool consume_key_value(const std::string &key, const yaml_event_t &event) + { auto it = consumers.find(key); - ConsumerClass *consumer = dynamic_cast(this); + ConsumerClass *consumer = dynamic_cast(this); - if(consumer) { - if(it != consumers.end()) { - //std::cerr << "Loading: " << key << std::endl; + if (consumer) { + if (it != consumers.end()) { + // std::cerr << "Loading: " << key << std::endl; (consumer->*(it->second))(event); return true; } @@ -106,69 +108,68 @@ protected: return false; } - bool consume_event(yaml_event_t & event) { + bool consume_event(yaml_event_t &event) + { accepted = false; switch (state) { - case START: - switch (event.type) { - case YAML_MAPPING_START_EVENT: - state = ACCEPT_KEY; - break; - case YAML_SCALAR_EVENT: - case YAML_SEQUENCE_START_EVENT: - state = ERROR; - break; - case YAML_STREAM_END_EVENT: - state = STOP; - break; - case YAML_STREAM_START_EVENT: - case YAML_DOCUMENT_START_EVENT: - case YAML_DOCUMENT_END_EVENT: - // ignore - break; - default: - std::cerr << "UNHANDLED YAML EVENT: " << event.type << std::endl; - state = ERROR; - break; - } - break; + case START: + switch (event.type) { + case YAML_MAPPING_START_EVENT: + state = ACCEPT_KEY; + break; + case YAML_SCALAR_EVENT: + case YAML_SEQUENCE_START_EVENT: + state = ERROR; + break; + case YAML_STREAM_END_EVENT: + state = STOP; + break; + case YAML_STREAM_START_EVENT: + case YAML_DOCUMENT_START_EVENT: + case YAML_DOCUMENT_END_EVENT: + // ignore + break; + default: + std::cerr << "UNHANDLED YAML EVENT: " << event.type << std::endl; + state = ERROR; + break; + } + break; - case ACCEPT_KEY: - switch (event.type) { - case YAML_SCALAR_EVENT: - key = (char *) event.data.scalar.value; - state = ACCEPT_VALUE; - break; - case YAML_MAPPING_END_EVENT: - state = STOP; - break; - default: - std::cerr << "UNHANDLED YAML EVENT (key): " << event.type - << "\nVALUE: " << event.data.scalar.value - << std::endl; - state = ERROR; - break; - } - break; + case ACCEPT_KEY: + switch (event.type) { + case YAML_SCALAR_EVENT: + key = (char *)event.data.scalar.value; + state = ACCEPT_VALUE; + break; + case YAML_MAPPING_END_EVENT: + state = STOP; + break; + default: + std::cerr << "UNHANDLED YAML EVENT (key): " << event.type + << "\nVALUE: " << event.data.scalar.value << std::endl; + state = ERROR; + break; + } + break; - case ACCEPT_VALUE: - switch (event.type) { - case YAML_SCALAR_EVENT: - accepted = true; - state = ACCEPT_KEY; - break; - default: - std::cerr << "UNHANDLED YAML EVENT (value): " << event.type - << "\nVALUE: " << event.data.scalar.value - << std::endl; - state = ERROR; - break; - } - break; + case ACCEPT_VALUE: + switch (event.type) { + case YAML_SCALAR_EVENT: + accepted = true; + state = ACCEPT_KEY; + break; + default: + std::cerr << "UNHANDLED YAML EVENT (value): " << event.type + << "\nVALUE: " << event.data.scalar.value << std::endl; + state = ERROR; + break; + } + break; - case ERROR: - case STOP: - break; + case ERROR: + case STOP: + break; } return (state != ERROR); } diff --git a/unittest/force-styles/yaml_writer.cpp b/unittest/force-styles/yaml_writer.cpp index 2581cd6acd..fca2ff092f 100644 --- a/unittest/force-styles/yaml_writer.cpp +++ b/unittest/force-styles/yaml_writer.cpp @@ -14,10 +14,11 @@ #include "yaml_writer.h" #include "yaml.h" -#include #include +#include -YamlWriter::YamlWriter(const char * outfile) { +YamlWriter::YamlWriter(const char *outfile) +{ yaml_emitter_initialize(&emitter); fp = fopen(outfile, "w"); if (!fp) { @@ -31,13 +32,13 @@ YamlWriter::YamlWriter(const char * outfile) { yaml_emitter_emit(&emitter, &event); yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0); yaml_emitter_emit(&emitter, &event); - yaml_mapping_start_event_initialize(&event, NULL, - (yaml_char_t *)YAML_MAP_TAG, - 1, YAML_ANY_MAPPING_STYLE); + yaml_mapping_start_event_initialize(&event, NULL, (yaml_char_t *)YAML_MAP_TAG, 1, + YAML_ANY_MAPPING_STYLE); yaml_emitter_emit(&emitter, &event); } -YamlWriter::~YamlWriter() { +YamlWriter::~YamlWriter() +{ yaml_mapping_end_event_initialize(&event); yaml_emitter_emit(&emitter, &event); yaml_document_end_event_initialize(&event, 0); @@ -48,84 +49,65 @@ YamlWriter::~YamlWriter() { fclose(fp); } -void YamlWriter::emit(const std::string &key, const double value) { - yaml_scalar_event_initialize(&event, NULL, - (yaml_char_t *)YAML_STR_TAG, - (yaml_char_t *) key.c_str(), - key.size(), 1, 0, +void YamlWriter::emit(const std::string &key, const double value) +{ + yaml_scalar_event_initialize(&event, NULL, (yaml_char_t *)YAML_STR_TAG, + (yaml_char_t *)key.c_str(), key.size(), 1, 0, YAML_PLAIN_SCALAR_STYLE); yaml_emitter_emit(&emitter, &event); char buf[256]; - snprintf(buf,256,"%.15g",value); - yaml_scalar_event_initialize(&event, NULL, - (yaml_char_t *)YAML_STR_TAG, - (yaml_char_t *)buf, - strlen(buf), 1, 0, - YAML_PLAIN_SCALAR_STYLE); + snprintf(buf, 256, "%.15g", value); + yaml_scalar_event_initialize(&event, NULL, (yaml_char_t *)YAML_STR_TAG, (yaml_char_t *)buf, + strlen(buf), 1, 0, YAML_PLAIN_SCALAR_STYLE); yaml_emitter_emit(&emitter, &event); } -void YamlWriter::emit(const std::string &key, const long value) { - yaml_scalar_event_initialize(&event, NULL, - (yaml_char_t *)YAML_STR_TAG, - (yaml_char_t *) key.c_str(), - key.size(), 1, 0, +void YamlWriter::emit(const std::string &key, const long value) +{ + yaml_scalar_event_initialize(&event, NULL, (yaml_char_t *)YAML_STR_TAG, + (yaml_char_t *)key.c_str(), key.size(), 1, 0, YAML_PLAIN_SCALAR_STYLE); yaml_emitter_emit(&emitter, &event); char buf[256]; - snprintf(buf,256,"%ld",value); - yaml_scalar_event_initialize(&event, NULL, - (yaml_char_t *)YAML_STR_TAG, - (yaml_char_t *)buf, - strlen(buf), 1, 0, - YAML_PLAIN_SCALAR_STYLE); + snprintf(buf, 256, "%ld", value); + yaml_scalar_event_initialize(&event, NULL, (yaml_char_t *)YAML_STR_TAG, (yaml_char_t *)buf, + strlen(buf), 1, 0, YAML_PLAIN_SCALAR_STYLE); yaml_emitter_emit(&emitter, &event); } -void YamlWriter::emit(const std::string &key, const int value) { - yaml_scalar_event_initialize(&event, NULL, - (yaml_char_t *)YAML_STR_TAG, - (yaml_char_t *) key.c_str(), - key.size(), 1, 0, +void YamlWriter::emit(const std::string &key, const int value) +{ + yaml_scalar_event_initialize(&event, NULL, (yaml_char_t *)YAML_STR_TAG, + (yaml_char_t *)key.c_str(), key.size(), 1, 0, YAML_PLAIN_SCALAR_STYLE); yaml_emitter_emit(&emitter, &event); char buf[256]; - snprintf(buf,256,"%d",value); - yaml_scalar_event_initialize(&event, NULL, - (yaml_char_t *)YAML_STR_TAG, - (yaml_char_t *)buf, - strlen(buf), 1, 0, - YAML_PLAIN_SCALAR_STYLE); + snprintf(buf, 256, "%d", value); + yaml_scalar_event_initialize(&event, NULL, (yaml_char_t *)YAML_STR_TAG, (yaml_char_t *)buf, + strlen(buf), 1, 0, YAML_PLAIN_SCALAR_STYLE); yaml_emitter_emit(&emitter, &event); } void YamlWriter::emit(const std::string &key, const std::string &value) { - yaml_scalar_event_initialize(&event, NULL, - (yaml_char_t *)YAML_STR_TAG, - (yaml_char_t *) key.c_str(), - key.size(), 1, 0, + yaml_scalar_event_initialize(&event, NULL, (yaml_char_t *)YAML_STR_TAG, + (yaml_char_t *)key.c_str(), key.size(), 1, 0, YAML_PLAIN_SCALAR_STYLE); yaml_emitter_emit(&emitter, &event); - yaml_scalar_event_initialize(&event, NULL, - (yaml_char_t *)YAML_STR_TAG, - (yaml_char_t *)value.c_str(), - value.size(), 1, 0, + yaml_scalar_event_initialize(&event, NULL, (yaml_char_t *)YAML_STR_TAG, + (yaml_char_t *)value.c_str(), value.size(), 1, 0, YAML_PLAIN_SCALAR_STYLE); yaml_emitter_emit(&emitter, &event); } -void YamlWriter::emit_block(const std::string &key, const std::string &value) { - yaml_scalar_event_initialize(&event, NULL, - (yaml_char_t *)YAML_STR_TAG, - (yaml_char_t *) key.c_str(), - key.size(), 1, 0, +void YamlWriter::emit_block(const std::string &key, const std::string &value) +{ + yaml_scalar_event_initialize(&event, NULL, (yaml_char_t *)YAML_STR_TAG, + (yaml_char_t *)key.c_str(), key.size(), 1, 0, YAML_PLAIN_SCALAR_STYLE); yaml_emitter_emit(&emitter, &event); - yaml_scalar_event_initialize(&event, NULL, - (yaml_char_t *)YAML_STR_TAG, - (yaml_char_t *)value.c_str(), - value.size(), 1, 0, + yaml_scalar_event_initialize(&event, NULL, (yaml_char_t *)YAML_STR_TAG, + (yaml_char_t *)value.c_str(), value.size(), 1, 0, YAML_LITERAL_SCALAR_STYLE); yaml_emitter_emit(&emitter, &event); } diff --git a/unittest/force-styles/yaml_writer.h b/unittest/force-styles/yaml_writer.h index cb2c7b97df..6cae7c2b24 100644 --- a/unittest/force-styles/yaml_writer.h +++ b/unittest/force-styles/yaml_writer.h @@ -20,7 +20,7 @@ class YamlWriter { public: - YamlWriter(const char * outfile); + YamlWriter(const char *outfile); virtual ~YamlWriter(); // emitters @@ -33,11 +33,11 @@ public: private: FILE *fp; yaml_emitter_t emitter; - yaml_event_t event; + yaml_event_t event; private: - YamlWriter() {}; - YamlWriter(const YamlWriter &) {}; + YamlWriter(){}; + YamlWriter(const YamlWriter &){}; }; #endif diff --git a/unittest/formats/test_eim_potential_file_reader.cpp b/unittest/formats/test_eim_potential_file_reader.cpp index eb13cee7cd..c8dcfd80e0 100644 --- a/unittest/formats/test_eim_potential_file_reader.cpp +++ b/unittest/formats/test_eim_potential_file_reader.cpp @@ -11,11 +11,11 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include "gmock/gmock.h" -#include "gtest/gtest.h" +#include "MANYBODY/pair_eim.h" #include "lammps.h" #include "utils.h" -#include "MANYBODY/pair_eim.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" #include @@ -23,19 +23,21 @@ using namespace LAMMPS_NS; class EIMPotentialFileReaderTest : public ::testing::Test { protected: - LAMMPS * lmp; + LAMMPS *lmp; PairEIM::Setfl setfl; static const int nelements = 9; - void SetUp() override { - const char *args[] = {"PotentialFileReaderTest", "-log", "none", "-echo", "screen", "-nocite" }; + void SetUp() override + { + const char *args[] = { + "PotentialFileReaderTest", "-log", "none", "-echo", "screen", "-nocite"}; char **argv = (char **)args; - int argc = sizeof(args)/sizeof(char *); + int argc = sizeof(args) / sizeof(char *); ::testing::internal::CaptureStdout(); lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); ::testing::internal::GetCapturedStdout(); - int npair = nelements*(nelements+1)/2; + int npair = nelements * (nelements + 1) / 2; setfl.ielement = new int[nelements]; setfl.mass = new double[nelements]; setfl.negativity = new double[nelements]; @@ -59,28 +61,29 @@ protected: setfl.tp = new int[npair]; } - void TearDown() override { - delete [] setfl.ielement; - delete [] setfl.mass; - delete [] setfl.negativity; - delete [] setfl.ra; - delete [] setfl.ri; - delete [] setfl.Ec; - delete [] setfl.q0; - delete [] setfl.rcutphiA; - delete [] setfl.rcutphiR; - delete [] setfl.Eb; - delete [] setfl.r0; - delete [] setfl.alpha; - delete [] setfl.beta; - delete [] setfl.rcutq; - delete [] setfl.Asigma; - delete [] setfl.rq; - delete [] setfl.rcutsigma; - delete [] setfl.Ac; - delete [] setfl.zeta; - delete [] setfl.rs; - delete [] setfl.tp; + void TearDown() override + { + delete[] setfl.ielement; + delete[] setfl.mass; + delete[] setfl.negativity; + delete[] setfl.ra; + delete[] setfl.ri; + delete[] setfl.Ec; + delete[] setfl.q0; + delete[] setfl.rcutphiA; + delete[] setfl.rcutphiR; + delete[] setfl.Eb; + delete[] setfl.r0; + delete[] setfl.alpha; + delete[] setfl.beta; + delete[] setfl.rcutq; + delete[] setfl.Asigma; + delete[] setfl.rq; + delete[] setfl.rcutsigma; + delete[] setfl.Ac; + delete[] setfl.zeta; + delete[] setfl.rs; + delete[] setfl.tp; ::testing::internal::CaptureStdout(); delete lmp; @@ -88,7 +91,8 @@ protected: } }; -TEST_F(EIMPotentialFileReaderTest, global_line) { +TEST_F(EIMPotentialFileReaderTest, global_line) +{ ::testing::internal::CaptureStdout(); EIMPotentialFileReader reader(lmp, "ffield.eim"); ::testing::internal::GetCapturedStdout(); @@ -99,7 +103,8 @@ TEST_F(EIMPotentialFileReaderTest, global_line) { ASSERT_DOUBLE_EQ(setfl.rsmall, 1.645); } -TEST_F(EIMPotentialFileReaderTest, element_line_sequential) { +TEST_F(EIMPotentialFileReaderTest, element_line_sequential) +{ ::testing::internal::CaptureStdout(); EIMPotentialFileReader reader(lmp, "ffield.eim"); ::testing::internal::GetCapturedStdout(); @@ -123,7 +128,8 @@ TEST_F(EIMPotentialFileReaderTest, element_line_sequential) { ASSERT_DOUBLE_EQ(setfl.q0[1], 0.0000e+00); } -TEST_F(EIMPotentialFileReaderTest, element_line_random) { +TEST_F(EIMPotentialFileReaderTest, element_line_random) +{ ::testing::internal::CaptureStdout(); EIMPotentialFileReader reader(lmp, "ffield.eim"); ::testing::internal::GetCapturedStdout(); @@ -138,7 +144,8 @@ TEST_F(EIMPotentialFileReaderTest, element_line_random) { ASSERT_DOUBLE_EQ(setfl.q0[0], 0.0000e+00); } -TEST_F(EIMPotentialFileReaderTest, pair_line) { +TEST_F(EIMPotentialFileReaderTest, pair_line) +{ ::testing::internal::CaptureStdout(); EIMPotentialFileReader reader(lmp, "ffield.eim"); ::testing::internal::GetCapturedStdout(); @@ -147,7 +154,7 @@ TEST_F(EIMPotentialFileReaderTest, pair_line) { ASSERT_DOUBLE_EQ(setfl.rcutphiA[0], 6.0490e+00); ASSERT_DOUBLE_EQ(setfl.rcutphiR[0], 6.0490e+00); ASSERT_DOUBLE_EQ(setfl.Eb[0], -2.5330e-01); - ASSERT_DOUBLE_EQ(setfl.r0[0], 3.6176e+00); + ASSERT_DOUBLE_EQ(setfl.r0[0], 3.6176e+00); ASSERT_DOUBLE_EQ(setfl.alpha[0], 7.5536e+00); ASSERT_DOUBLE_EQ(setfl.beta[0], 3.5017e+00); ASSERT_DOUBLE_EQ(setfl.rcutq[0], 0.0000e+00); @@ -160,7 +167,8 @@ TEST_F(EIMPotentialFileReaderTest, pair_line) { ASSERT_EQ(setfl.tp[0], 1); } -TEST_F(EIMPotentialFileReaderTest, pair_identical) { +TEST_F(EIMPotentialFileReaderTest, pair_identical) +{ ::testing::internal::CaptureStdout(); EIMPotentialFileReader reader(lmp, "ffield.eim"); ::testing::internal::GetCapturedStdout(); diff --git a/unittest/formats/test_potential_file_reader.cpp b/unittest/formats/test_potential_file_reader.cpp index 3447dbb73f..dde2b27353 100644 --- a/unittest/formats/test_potential_file_reader.cpp +++ b/unittest/formats/test_potential_file_reader.cpp @@ -11,23 +11,23 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include "gmock/gmock.h" -#include "gtest/gtest.h" -#include "potential_file_reader.h" -#include "lammps.h" -#include "utils.h" -#include "MANYBODY/pair_sw.h" #include "MANYBODY/pair_comb.h" #include "MANYBODY/pair_comb3.h" +#include "MANYBODY/pair_eim.h" +#include "MANYBODY/pair_gw.h" +#include "MANYBODY/pair_gw_zbl.h" +#include "MANYBODY/pair_nb3b_harmonic.h" +#include "MANYBODY/pair_sw.h" #include "MANYBODY/pair_tersoff.h" #include "MANYBODY/pair_tersoff_mod.h" #include "MANYBODY/pair_tersoff_mod_c.h" #include "MANYBODY/pair_tersoff_zbl.h" -#include "MANYBODY/pair_gw.h" -#include "MANYBODY/pair_gw_zbl.h" -#include "MANYBODY/pair_nb3b_harmonic.h" #include "MANYBODY/pair_vashishta.h" -#include "MANYBODY/pair_eim.h" +#include "lammps.h" +#include "potential_file_reader.h" +#include "utils.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" #include @@ -47,25 +47,29 @@ const int LAMMPS_NS::PairVashishta::NPARAMS_PER_LINE; class PotentialFileReaderTest : public ::testing::Test { protected: - LAMMPS * lmp; + LAMMPS *lmp; - void SetUp() override { - const char *args[] = {"PotentialFileReaderTest", "-log", "none", "-echo", "screen", "-nocite" }; + void SetUp() override + { + const char *args[] = { + "PotentialFileReaderTest", "-log", "none", "-echo", "screen", "-nocite"}; char **argv = (char **)args; - int argc = sizeof(args)/sizeof(char *); + int argc = sizeof(args) / sizeof(char *); ::testing::internal::CaptureStdout(); lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); ::testing::internal::GetCapturedStdout(); } - void TearDown() override { + void TearDown() override + { ::testing::internal::CaptureStdout(); delete lmp; ::testing::internal::GetCapturedStdout(); } }; -TEST_F(PotentialFileReaderTest, Si) { +TEST_F(PotentialFileReaderTest, Si) +{ ::testing::internal::CaptureStdout(); PotentialFileReader reader(lmp, "Si.sw", "Stillinger-Weber"); ::testing::internal::GetCapturedStdout(); @@ -74,7 +78,8 @@ TEST_F(PotentialFileReaderTest, Si) { ASSERT_EQ(utils::count_words(line), PairSW::NPARAMS_PER_LINE); } -TEST_F(PotentialFileReaderTest, Comb) { +TEST_F(PotentialFileReaderTest, Comb) +{ ::testing::internal::CaptureStdout(); PotentialFileReader reader(lmp, "ffield.comb", "COMB"); ::testing::internal::GetCapturedStdout(); @@ -83,7 +88,8 @@ TEST_F(PotentialFileReaderTest, Comb) { ASSERT_EQ(utils::count_words(line), PairComb::NPARAMS_PER_LINE); } -TEST_F(PotentialFileReaderTest, Comb3) { +TEST_F(PotentialFileReaderTest, Comb3) +{ ::testing::internal::CaptureStdout(); PotentialFileReader reader(lmp, "ffield.comb3", "COMB3"); ::testing::internal::GetCapturedStdout(); @@ -92,7 +98,8 @@ TEST_F(PotentialFileReaderTest, Comb3) { ASSERT_EQ(utils::count_words(line), PairComb3::NPARAMS_PER_LINE); } -TEST_F(PotentialFileReaderTest, Tersoff) { +TEST_F(PotentialFileReaderTest, Tersoff) +{ ::testing::internal::CaptureStdout(); PotentialFileReader reader(lmp, "Si.tersoff", "Tersoff"); ::testing::internal::GetCapturedStdout(); @@ -101,7 +108,8 @@ TEST_F(PotentialFileReaderTest, Tersoff) { ASSERT_EQ(utils::count_words(line), PairTersoff::NPARAMS_PER_LINE); } -TEST_F(PotentialFileReaderTest, TersoffMod) { +TEST_F(PotentialFileReaderTest, TersoffMod) +{ ::testing::internal::CaptureStdout(); PotentialFileReader reader(lmp, "Si.tersoff.mod", "Tersoff/Mod"); ::testing::internal::GetCapturedStdout(); @@ -110,7 +118,8 @@ TEST_F(PotentialFileReaderTest, TersoffMod) { ASSERT_EQ(utils::count_words(line), PairTersoffMOD::NPARAMS_PER_LINE); } -TEST_F(PotentialFileReaderTest, TersoffModC) { +TEST_F(PotentialFileReaderTest, TersoffModC) +{ ::testing::internal::CaptureStdout(); PotentialFileReader reader(lmp, "Si.tersoff.modc", "Tersoff/ModC"); ::testing::internal::GetCapturedStdout(); @@ -119,7 +128,8 @@ TEST_F(PotentialFileReaderTest, TersoffModC) { ASSERT_EQ(utils::count_words(line), PairTersoffMODC::NPARAMS_PER_LINE); } -TEST_F(PotentialFileReaderTest, TersoffZBL) { +TEST_F(PotentialFileReaderTest, TersoffZBL) +{ ::testing::internal::CaptureStdout(); PotentialFileReader reader(lmp, "SiC.tersoff.zbl", "Tersoff/ZBL"); ::testing::internal::GetCapturedStdout(); @@ -128,7 +138,8 @@ TEST_F(PotentialFileReaderTest, TersoffZBL) { ASSERT_EQ(utils::count_words(line), PairTersoffZBL::NPARAMS_PER_LINE); } -TEST_F(PotentialFileReaderTest, GW) { +TEST_F(PotentialFileReaderTest, GW) +{ ::testing::internal::CaptureStdout(); PotentialFileReader reader(lmp, "SiC.gw", "GW"); ::testing::internal::GetCapturedStdout(); @@ -137,7 +148,8 @@ TEST_F(PotentialFileReaderTest, GW) { ASSERT_EQ(utils::count_words(line), PairGW::NPARAMS_PER_LINE); } -TEST_F(PotentialFileReaderTest, GWZBL) { +TEST_F(PotentialFileReaderTest, GWZBL) +{ ::testing::internal::CaptureStdout(); PotentialFileReader reader(lmp, "SiC.gw.zbl", "GW/ZBL"); ::testing::internal::GetCapturedStdout(); @@ -146,7 +158,8 @@ TEST_F(PotentialFileReaderTest, GWZBL) { ASSERT_EQ(utils::count_words(line), PairGWZBL::NPARAMS_PER_LINE); } -TEST_F(PotentialFileReaderTest, Nb3bHarmonic) { +TEST_F(PotentialFileReaderTest, Nb3bHarmonic) +{ ::testing::internal::CaptureStdout(); PotentialFileReader reader(lmp, "MOH.nb3b.harmonic", "NB3B Harmonic"); ::testing::internal::GetCapturedStdout(); @@ -155,7 +168,8 @@ TEST_F(PotentialFileReaderTest, Nb3bHarmonic) { ASSERT_EQ(utils::count_words(line), PairNb3bHarmonic::NPARAMS_PER_LINE); } -TEST_F(PotentialFileReaderTest, Vashishta) { +TEST_F(PotentialFileReaderTest, Vashishta) +{ ::testing::internal::CaptureStdout(); PotentialFileReader reader(lmp, "SiC.vashishta", "Vashishta"); ::testing::internal::GetCapturedStdout(); diff --git a/unittest/utils/test_fmtlib.cpp b/unittest/utils/test_fmtlib.cpp index 0b1ec16368..6d02707c4d 100644 --- a/unittest/utils/test_fmtlib.cpp +++ b/unittest/utils/test_fmtlib.cpp @@ -11,114 +11,127 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include "lmptype.h" -#include "gtest/gtest.h" -#include "gmock/gmock.h" #include "fmt/format.h" -#include +#include "lmptype.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" #include +#include using namespace LAMMPS_NS; using ::testing::Eq; // this tests a subset of {fmt} that is most relevant to LAMMPS -TEST(FmtLib, insert_string) { +TEST(FmtLib, insert_string) +{ const char val[] = "word"; - auto text = fmt::format("word {}",val); + auto text = fmt::format("word {}", val); ASSERT_THAT(text, Eq("word word")); } -TEST(FmtLib, insert_int) { +TEST(FmtLib, insert_int) +{ const int val = 333; - auto text = fmt::format("word {}",val); + auto text = fmt::format("word {}", val); ASSERT_THAT(text, Eq("word 333")); } -TEST(FmtLib, insert_neg_int) { +TEST(FmtLib, insert_neg_int) +{ const int val = -333; - auto text = fmt::format("word {}",val); + auto text = fmt::format("word {}", val); ASSERT_THAT(text, Eq("word -333")); } -TEST(FmtLib, insert_bigint) { +TEST(FmtLib, insert_bigint) +{ #if defined(LAMMPS_BIGBIG) || defined(LAMMPS_SMALLBIG) const bigint val = 9945234592L; - auto text = fmt::format("word {}",val); + auto text = fmt::format("word {}", val); ASSERT_THAT(text, Eq("word 9945234592")); #else GTEST_SKIP(); #endif } -TEST(FmtLib, insert_neg_bigint) { +TEST(FmtLib, insert_neg_bigint) +{ #if defined(LAMMPS_BIGBIG) || defined(LAMMPS_SMALLBIG) const bigint val = -9945234592L; - auto text = fmt::format("word {}",val); + auto text = fmt::format("word {}", val); ASSERT_THAT(text, Eq("word -9945234592")); #else GTEST_SKIP(); #endif } -TEST(FmtLib, insert_tagint) { +TEST(FmtLib, insert_tagint) +{ #if defined(LAMMPS_BIGBIG) const tagint val = 9945234592L; - auto text = fmt::format("word {}",val); + auto text = fmt::format("word {}", val); ASSERT_THAT(text, Eq("word 9945234592")); #else GTEST_SKIP(); #endif } -TEST(FmtLib, insert_neg_tagint) { +TEST(FmtLib, insert_neg_tagint) +{ #if defined(LAMMPS_BIGBIG) const tagint val = -9945234592L; - auto text = fmt::format("word {}",val); + auto text = fmt::format("word {}", val); ASSERT_THAT(text, Eq("word -9945234592")); #else GTEST_SKIP(); #endif } -TEST(FmtLib, insert_imageint) { +TEST(FmtLib, insert_imageint) +{ #if defined(LAMMPS_BIGBIG) const imageint val = 9945234592L; - auto text = fmt::format("word {}",val); + auto text = fmt::format("word {}", val); ASSERT_THAT(text, Eq("word 9945234592")); #else GTEST_SKIP(); #endif } -TEST(FmtLib, insert_neg_imageint) { +TEST(FmtLib, insert_neg_imageint) +{ #if defined(LAMMPS_BIGBIG) const imageint val = -9945234592L; - auto text = fmt::format("word {}",val); + auto text = fmt::format("word {}", val); ASSERT_THAT(text, Eq("word -9945234592")); #else GTEST_SKIP(); #endif } -TEST(FmtLib, insert_double) { +TEST(FmtLib, insert_double) +{ const double val = 1.5; - auto text = fmt::format("word {}",val); + auto text = fmt::format("word {}", val); ASSERT_THAT(text, Eq("word 1.5")); } -TEST(FmtLib, insert_neg_double) { +TEST(FmtLib, insert_neg_double) +{ const double val = -1.5; - auto text = fmt::format("word {}",val); + auto text = fmt::format("word {}", val); ASSERT_THAT(text, Eq("word -1.5")); } -TEST(FmtLib, int_for_double) { +TEST(FmtLib, int_for_double) +{ const double val = -1.5; - ASSERT_THROW(fmt::format("word {:d}",val),std::exception); + ASSERT_THROW(fmt::format("word {:d}", val), std::exception); } -TEST(FmtLib, double_for_int) { +TEST(FmtLib, double_for_int) +{ const int val = 15; - ASSERT_THROW(fmt::format("word {:g}",val),std::exception); + ASSERT_THROW(fmt::format("word {:g}", val), std::exception); } diff --git a/unittest/utils/test_tokenizer.cpp b/unittest/utils/test_tokenizer.cpp index 903f660959..afe823acf8 100644 --- a/unittest/utils/test_tokenizer.cpp +++ b/unittest/utils/test_tokenizer.cpp @@ -11,100 +11,117 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include "gtest/gtest.h" -#include "gmock/gmock.h" #include "tokenizer.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" using namespace LAMMPS_NS; using ::testing::Eq; -TEST(Tokenizer, empty_string) { +TEST(Tokenizer, empty_string) +{ Tokenizer t("", " "); ASSERT_EQ(t.count(), 0); } -TEST(Tokenizer, whitespace_only) { +TEST(Tokenizer, whitespace_only) +{ Tokenizer t(" ", " "); ASSERT_EQ(t.count(), 0); } -TEST(Tokenizer, single_word) { +TEST(Tokenizer, single_word) +{ Tokenizer t("test", " "); ASSERT_EQ(t.count(), 1); } -TEST(Tokenizer, two_words) { +TEST(Tokenizer, two_words) +{ Tokenizer t("test word", " "); ASSERT_EQ(t.count(), 2); } -TEST(Tokenizer, prefix_separators) { +TEST(Tokenizer, prefix_separators) +{ Tokenizer t(" test word", " "); ASSERT_EQ(t.count(), 2); } -TEST(Tokenizer, postfix_separators) { +TEST(Tokenizer, postfix_separators) +{ Tokenizer t("test word ", " "); ASSERT_EQ(t.count(), 2); } -TEST(Tokenizer, iterate_words) { +TEST(Tokenizer, iterate_words) +{ Tokenizer t(" test word ", " "); ASSERT_THAT(t.next(), Eq("test")); ASSERT_THAT(t.next(), Eq("word")); ASSERT_EQ(t.count(), 2); } -TEST(Tokenizer, default_separators) { +TEST(Tokenizer, default_separators) +{ Tokenizer t(" \r\n test \t word \f"); ASSERT_THAT(t.next(), Eq("test")); ASSERT_THAT(t.next(), Eq("word")); ASSERT_EQ(t.count(), 2); } -TEST(Tokenizer, as_vector) { +TEST(Tokenizer, as_vector) +{ Tokenizer t(" \r\n test \t word \f"); std::vector list = t.as_vector(); ASSERT_THAT(list[0], Eq("test")); ASSERT_THAT(list[1], Eq("word")); } -TEST(ValueTokenizer, empty_string) { +TEST(ValueTokenizer, empty_string) +{ ValueTokenizer values(""); ASSERT_FALSE(values.has_next()); } -TEST(ValueTokenizer, bad_integer) { +TEST(ValueTokenizer, bad_integer) +{ ValueTokenizer values("f10"); ASSERT_THROW(values.next_int(), InvalidIntegerException); } -TEST(ValueTokenizer, bad_double) { +TEST(ValueTokenizer, bad_double) +{ ValueTokenizer values("1a.0"); ASSERT_THROW(values.next_double(), InvalidFloatException); } -TEST(ValueTokenizer, valid_int) { +TEST(ValueTokenizer, valid_int) +{ ValueTokenizer values("10"); ASSERT_EQ(values.next_int(), 10); } -TEST(ValueTokenizer, valid_tagint) { +TEST(ValueTokenizer, valid_tagint) +{ ValueTokenizer values("42"); ASSERT_EQ(values.next_tagint(), 42); } -TEST(ValueTokenizer, valid_bigint) { +TEST(ValueTokenizer, valid_bigint) +{ ValueTokenizer values("42"); ASSERT_EQ(values.next_bigint(), 42); } -TEST(ValueTokenizer, valid_double) { +TEST(ValueTokenizer, valid_double) +{ ValueTokenizer values("3.14"); ASSERT_DOUBLE_EQ(values.next_double(), 3.14); } -TEST(ValueTokenizer, valid_double_with_exponential) { +TEST(ValueTokenizer, valid_double_with_exponential) +{ ValueTokenizer values("3.14e22"); ASSERT_DOUBLE_EQ(values.next_double(), 3.14e22); } diff --git a/unittest/utils/test_utils.cpp b/unittest/utils/test_utils.cpp index 317c77cf3f..ec29b58ccb 100644 --- a/unittest/utils/test_utils.cpp +++ b/unittest/utils/test_utils.cpp @@ -11,215 +11,265 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include "gtest/gtest.h" -#include "gmock/gmock.h" #include "utils.h" -#include +#include "gmock/gmock.h" +#include "gtest/gtest.h" #include #include #include +#include using namespace LAMMPS_NS; using ::testing::Eq; -TEST(Utils, trim_comment) { +TEST(Utils, trim_comment) +{ auto trimmed = utils::trim_comment("some text # comment"); ASSERT_THAT(trimmed, Eq("some text ")); } -TEST(Utils, count_words) { +TEST(Utils, count_words) +{ ASSERT_EQ(utils::count_words("some text # comment"), 4); } -TEST(Utils, count_words_non_default) { +TEST(Utils, count_words_non_default) +{ ASSERT_EQ(utils::count_words("some text # comment", " #"), 3); } -TEST(Utils, trim_and_count_words) { +TEST(Utils, trim_and_count_words) +{ ASSERT_EQ(utils::trim_and_count_words("some text # comment"), 2); } -TEST(Utils, count_words_with_extra_spaces) { +TEST(Utils, count_words_with_extra_spaces) +{ ASSERT_EQ(utils::count_words(" some text # comment "), 4); } -TEST(Utils, valid_integer1) { +TEST(Utils, valid_integer1) +{ ASSERT_TRUE(utils::is_integer("10")); } -TEST(Utils, valid_integer2) { +TEST(Utils, valid_integer2) +{ ASSERT_TRUE(utils::is_integer("-10")); } -TEST(Utils, valid_integer3) { +TEST(Utils, valid_integer3) +{ ASSERT_TRUE(utils::is_integer("+10")); } -TEST(Utils, valid_double1) { +TEST(Utils, valid_double1) +{ ASSERT_TRUE(utils::is_double("10.0")); } -TEST(Utils, valid_double2) { +TEST(Utils, valid_double2) +{ ASSERT_TRUE(utils::is_double("1.")); } -TEST(Utils, valid_double3) { +TEST(Utils, valid_double3) +{ ASSERT_TRUE(utils::is_double(".0")); } -TEST(Utils, valid_double4) { +TEST(Utils, valid_double4) +{ ASSERT_TRUE(utils::is_double("-10.0")); } -TEST(Utils, valid_double5) { +TEST(Utils, valid_double5) +{ ASSERT_TRUE(utils::is_double("-1.")); } -TEST(Utils, valid_double6) { +TEST(Utils, valid_double6) +{ ASSERT_TRUE(utils::is_double("-.0")); } -TEST(Utils, valid_double7) { +TEST(Utils, valid_double7) +{ ASSERT_TRUE(utils::is_double("+10.0")); } -TEST(Utils, valid_double8) { +TEST(Utils, valid_double8) +{ ASSERT_TRUE(utils::is_double("+1.")); } -TEST(Utils, valid_double9) { +TEST(Utils, valid_double9) +{ ASSERT_TRUE(utils::is_double("+.0")); } -TEST(Utils, empty_not_an_integer) { +TEST(Utils, empty_not_an_integer) +{ ASSERT_FALSE(utils::is_integer("")); } -TEST(Utils, empty_not_a_double) { +TEST(Utils, empty_not_a_double) +{ ASSERT_FALSE(utils::is_double("")); } -TEST(Utils, text_not_an_integer) { +TEST(Utils, text_not_an_integer) +{ ASSERT_FALSE(utils::is_integer("one")); } -TEST(Utils, text_not_a_double) { +TEST(Utils, text_not_a_double) +{ ASSERT_FALSE(utils::is_double("half")); } -TEST(Utils, double_not_an_integer1) { +TEST(Utils, double_not_an_integer1) +{ ASSERT_FALSE(utils::is_integer("10.0")); } -TEST(Utils, double_not_an_integer2) { +TEST(Utils, double_not_an_integer2) +{ ASSERT_FALSE(utils::is_integer(".0")); } -TEST(Utils, double_not_an_integer3) { +TEST(Utils, double_not_an_integer3) +{ ASSERT_FALSE(utils::is_integer("1.")); } -TEST(Utils, integer_is_double1) { +TEST(Utils, integer_is_double1) +{ ASSERT_TRUE(utils::is_double("10")); } -TEST(Utils, integer_is_double2) { +TEST(Utils, integer_is_double2) +{ ASSERT_TRUE(utils::is_double("-10")); } -TEST(Utils, is_double_with_exponential) { +TEST(Utils, is_double_with_exponential) +{ ASSERT_TRUE(utils::is_double("+1e02")); } -TEST(Utils, is_double_with_neg_exponential) { +TEST(Utils, is_double_with_neg_exponential) +{ ASSERT_TRUE(utils::is_double("1.0e-22")); } -TEST(Utils, is_double_with_pos_exponential) { +TEST(Utils, is_double_with_pos_exponential) +{ ASSERT_TRUE(utils::is_double(".1e+22")); } -TEST(Utils, signed_double_and_exponential) { +TEST(Utils, signed_double_and_exponential) +{ ASSERT_TRUE(utils::is_double("-10E-22")); } -TEST(Utils, is_double_with_d_exponential) { +TEST(Utils, is_double_with_d_exponential) +{ ASSERT_FALSE(utils::is_double("10d22")); } -TEST(Utils, is_double_with_neg_d_exponential) { +TEST(Utils, is_double_with_neg_d_exponential) +{ ASSERT_FALSE(utils::is_double("10d-22")); } -TEST(Utils, signed_double_and_d_exponential) { +TEST(Utils, signed_double_and_d_exponential) +{ ASSERT_FALSE(utils::is_double("-10D-22")); } -TEST(Utils, strmatch_beg) { - ASSERT_TRUE(utils::strmatch("rigid/small/omp","^rigid")); +TEST(Utils, strmatch_beg) +{ + ASSERT_TRUE(utils::strmatch("rigid/small/omp", "^rigid")); } -TEST(Utils, strmatch_mid1) { - ASSERT_TRUE(utils::strmatch("rigid/small/omp","small")); +TEST(Utils, strmatch_mid1) +{ + ASSERT_TRUE(utils::strmatch("rigid/small/omp", "small")); } -TEST(Utils, strmatch_mid2) { - ASSERT_TRUE(utils::strmatch("rigid/small/omp","omp")); +TEST(Utils, strmatch_mid2) +{ + ASSERT_TRUE(utils::strmatch("rigid/small/omp", "omp")); } -TEST(Utils, strmatch_end) { - ASSERT_TRUE(utils::strmatch("rigid/small/omp","/omp$")); +TEST(Utils, strmatch_end) +{ + ASSERT_TRUE(utils::strmatch("rigid/small/omp", "/omp$")); } -TEST(Utils, no_strmatch_beg) { - ASSERT_FALSE(utils::strmatch("rigid/small/omp","^small")); +TEST(Utils, no_strmatch_beg) +{ + ASSERT_FALSE(utils::strmatch("rigid/small/omp", "^small")); } -TEST(Utils, no_strmatch_mid) { - ASSERT_FALSE(utils::strmatch("rigid/small/omp","none")); +TEST(Utils, no_strmatch_mid) +{ + ASSERT_FALSE(utils::strmatch("rigid/small/omp", "none")); } -TEST(Utils, no_strmatch_end) { - ASSERT_FALSE(utils::strmatch("rigid/small/omp","/opt$")); +TEST(Utils, no_strmatch_end) +{ + ASSERT_FALSE(utils::strmatch("rigid/small/omp", "/opt$")); } -TEST(Utils, strmatch_whole_line) { - ASSERT_TRUE(utils::strmatch("ITEM: UNITS\n","^\\s*ITEM: UNITS\\s*$")); +TEST(Utils, strmatch_whole_line) +{ + ASSERT_TRUE(utils::strmatch("ITEM: UNITS\n", "^\\s*ITEM: UNITS\\s*$")); } -TEST(Utils, no_strmatch_whole_line) { - ASSERT_FALSE(utils::strmatch("ITEM: UNITS\n","^\\s*ITEM: UNIT\\s*$")); +TEST(Utils, no_strmatch_whole_line) +{ + ASSERT_FALSE(utils::strmatch("ITEM: UNITS\n", "^\\s*ITEM: UNIT\\s*$")); } -TEST(Utils, strmatch_integer_in_line) { - ASSERT_TRUE(utils::strmatch(" 5 angles\n","^\\s*\\d+\\s+angles\\s")); +TEST(Utils, strmatch_integer_in_line) +{ + ASSERT_TRUE(utils::strmatch(" 5 angles\n", "^\\s*\\d+\\s+angles\\s")); } -TEST(Utils, strmatch_float_in_line) { - ASSERT_TRUE(utils::strmatch(" 5.0 angles\n","^\\s*\\f+\\s+angles\\s")); +TEST(Utils, strmatch_float_in_line) +{ + ASSERT_TRUE(utils::strmatch(" 5.0 angles\n", "^\\s*\\f+\\s+angles\\s")); } -TEST(Utils, strmatch_int_as_float_in_line) { - ASSERT_TRUE(utils::strmatch(" 5 angles\n","^\\s*\\f+\\s+angles\\s")); +TEST(Utils, strmatch_int_as_float_in_line) +{ + ASSERT_TRUE(utils::strmatch(" 5 angles\n", "^\\s*\\f+\\s+angles\\s")); } -TEST(Utils, strmatch_char_range) { - ASSERT_TRUE(utils::strmatch("rigid","^[ip-s]+gid")); +TEST(Utils, strmatch_char_range) +{ + ASSERT_TRUE(utils::strmatch("rigid", "^[ip-s]+gid")); } -TEST(Utils, strmatch_opt_range) { - ASSERT_TRUE(utils::strmatch("rigid","^[0-9]*[p-s]igid")); +TEST(Utils, strmatch_opt_range) +{ + ASSERT_TRUE(utils::strmatch("rigid", "^[0-9]*[p-s]igid")); } -TEST(Utils, path_join) { +TEST(Utils, path_join) +{ #if defined(_WIN32) - ASSERT_THAT(utils::path_join("c:\\parent\\folder", "filename"), Eq("c:\\parent\\folder\\filename")); + ASSERT_THAT(utils::path_join("c:\\parent\\folder", "filename"), + Eq("c:\\parent\\folder\\filename")); #else ASSERT_THAT(utils::path_join("/parent/folder", "filename"), Eq("/parent/folder/filename")); #endif } -TEST(Utils, path_basename) { +TEST(Utils, path_basename) +{ #if defined(_WIN32) ASSERT_THAT(utils::path_basename("c:\\parent\\folder\\filename"), Eq("filename")); #else @@ -227,7 +277,8 @@ TEST(Utils, path_basename) { #endif } -TEST(Utils, getsyserror) { +TEST(Utils, getsyserror) +{ #if defined(__linux__) errno = ENOENT; std::string errmesg = utils::getsyserror(); @@ -237,24 +288,25 @@ TEST(Utils, getsyserror) { #endif } -TEST(Utils, potential_file) { +TEST(Utils, potential_file) +{ FILE *fp; - fp = fopen("ctest.txt","w"); - ASSERT_NE(fp,nullptr); - fputs("# DATE: 2020-02-20 CONTRIBUTOR: Nessuno\n",fp); + fp = fopen("ctest.txt", "w"); + ASSERT_NE(fp, nullptr); + fputs("# DATE: 2020-02-20 CONTRIBUTOR: Nessuno\n", fp); fclose(fp); EXPECT_TRUE(utils::file_is_readable("ctest.txt")); EXPECT_FALSE(utils::file_is_readable("no_such_file.txt")); - EXPECT_THAT(utils::get_potential_file_path("ctest.txt"),Eq("ctest.txt")); + EXPECT_THAT(utils::get_potential_file_path("ctest.txt"), Eq("ctest.txt")); const char *folder = getenv("LAMMPS_POTENTIALS"); if (folder != nullptr) { - std::string path=utils::path_join(folder,"Cu_u3.eam"); - EXPECT_THAT(utils::get_potential_file_path("Cu_u3.eam"),Eq(path)); + std::string path = utils::path_join(folder, "Cu_u3.eam"); + EXPECT_THAT(utils::get_potential_file_path("Cu_u3.eam"), Eq(path)); } - EXPECT_THAT(utils::get_potential_date("ctest.txt","Test"),Eq("2020-02-20")); + EXPECT_THAT(utils::get_potential_date("ctest.txt", "Test"), Eq("2020-02-20")); remove("ctest.txt"); } From 9c3d108bbc5408fb32bf3fd95dd286ec7654be2e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 13 Jun 2020 02:05:13 -0400 Subject: [PATCH 08/18] enable aligning consecutive assignments --- unittest/.clang-format | 1 + unittest/force-styles/angle_style.cpp | 108 +++++----- unittest/force-styles/bond_style.cpp | 195 +++++++++--------- unittest/force-styles/error_stats.cpp | 7 +- unittest/force-styles/pair_style.cpp | 191 +++++++++-------- unittest/force-styles/test_config_reader.cpp | 36 ++-- unittest/force-styles/test_main.h | 14 +- unittest/force-styles/yaml_reader.h | 8 +- .../test_eim_potential_file_reader.cpp | 44 ++-- .../formats/test_potential_file_reader.cpp | 2 +- unittest/utils/test_fmtlib.cpp | 22 +- unittest/utils/test_utils.cpp | 2 +- 12 files changed, 328 insertions(+), 302 deletions(-) diff --git a/unittest/.clang-format b/unittest/.clang-format index 91df2e925e..cb352b37f5 100644 --- a/unittest/.clang-format +++ b/unittest/.clang-format @@ -2,6 +2,7 @@ Language: Cpp BasedOnStyle: LLVM AccessModifierOffset: -4 +AlignConsecutiveAssignments: true AlignEscapedNewlines: Left AllowShortFunctionsOnASingleLine: Inline AllowShortLambdasOnASingleLine: None diff --git a/unittest/force-styles/angle_style.cpp b/unittest/force-styles/angle_style.cpp index a1a618bbca..b38d23ce55 100644 --- a/unittest/force-styles/angle_style.cpp +++ b/unittest/force-styles/angle_style.cpp @@ -72,7 +72,7 @@ LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool new // check if prerequisite styles are available Info *info = new Info(lmp); - int nfail = 0; + int nfail = 0; for (auto &prerequisite : cfg.prerequisites) { std::string style = prerequisite.second; @@ -217,8 +217,9 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) { // initialize system geometry const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"}; + char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = sizeof(args) / sizeof(char *); LAMMPS *lmp = init_lammps(argc, argv, config); if (!lmp) { std::cerr << "One or more prerequisite styles are not available " @@ -229,7 +230,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) return; } - const int natoms = lmp->atom->natoms; + const int natoms = lmp->atom->natoms; const int bufsize = 256; char buf[bufsize]; std::string block(""); @@ -241,8 +242,8 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // date_generated std::time_t now = time(NULL); - block = ctime(&now); - block = block.substr(0, block.find("\n") - 1); + block = ctime(&now); + block = block.substr(0, block.find("\n") - 1); writer.emit("date_generated", block); // epsilon @@ -312,7 +313,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // init_forces block.clear(); - double **f = lmp->atom->f; + double **f = lmp->atom->f; tagint *tag = lmp->atom->tag; for (int i = 0; i < natoms; ++i) { snprintf(buf, bufsize, "% 3d % 23.16e % 23.16e % 23.16e\n", (int)tag[i], f[i][0], f[i][1], @@ -334,7 +335,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) writer.emit_block("run_stress", buf); block.clear(); - f = lmp->atom->f; + f = lmp->atom->f; tag = lmp->atom->tag; for (int i = 0; i < natoms; ++i) { snprintf(buf, bufsize, "% 3d % 23.16e % 23.16e % 23.16e\n", (int)tag[i], f[i][0], f[i][1], @@ -350,11 +351,13 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) TEST(AngleStyle, plain) { const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"}; + char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = sizeof(args) / sizeof(char *); ::testing::internal::CaptureStdout(); LAMMPS *lmp = init_lammps(argc, argv, test_config, true); + std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -375,8 +378,8 @@ TEST(AngleStyle, plain) ASSERT_EQ(lmp->atom->natoms, nlocal); double epsilon = test_config.epsilon; - double **f = lmp->atom->f; - tagint *tag = lmp->atom->tag; + double **f = lmp->atom->f; + tagint *tag = lmp->atom->tag; ErrorStats stats; stats.reset(); const std::vector &f_ref = test_config.init_forces; @@ -388,7 +391,7 @@ TEST(AngleStyle, plain) } if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; - Angle *angle = lmp->force->angle; + Angle *angle = lmp->force->angle; double *stress = angle->virial; stats.reset(); EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); @@ -407,8 +410,8 @@ TEST(AngleStyle, plain) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - stress = angle->virial; + f = lmp->atom->f; + stress = angle->virial; const std::vector &f_run = test_config.run_forces; ASSERT_EQ(nlocal + 1, f_run.size()); stats.reset(); @@ -430,7 +433,7 @@ TEST(AngleStyle, plain) if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; stats.reset(); - int id = lmp->modify->find_compute("sum"); + int id = lmp->modify->find_compute("sum"); double energy = lmp->modify->compute[id]->compute_scalar(); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.run_energy, epsilon); EXPECT_FP_LE_WITH_EPS(angle->energy, energy, epsilon); @@ -444,7 +447,7 @@ TEST(AngleStyle, plain) // skip over these tests if newton bond is forced to be on if (lmp->force->newton_bond == 0) { - f = lmp->atom->f; + f = lmp->atom->f; tag = lmp->atom->tag; stats.reset(); for (int i = 0; i < nlocal; ++i) { @@ -454,7 +457,7 @@ TEST(AngleStyle, plain) } if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; - angle = lmp->force->angle; + angle = lmp->force->angle; stress = angle->virial; stats.reset(); EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 2 * epsilon); @@ -473,7 +476,7 @@ TEST(AngleStyle, plain) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; + f = lmp->atom->f; stress = angle->virial; stats.reset(); for (int i = 0; i < nlocal; ++i) { @@ -494,7 +497,7 @@ TEST(AngleStyle, plain) if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; stats.reset(); - id = lmp->modify->find_compute("sum"); + id = lmp->modify->find_compute("sum"); energy = lmp->modify->compute[id]->compute_scalar(); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.run_energy, epsilon); EXPECT_FP_LE_WITH_EPS(angle->energy, energy, epsilon); @@ -505,7 +508,7 @@ TEST(AngleStyle, plain) restart_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; + f = lmp->atom->f; tag = lmp->atom->tag; stats.reset(); ASSERT_EQ(nlocal + 1, f_ref.size()); @@ -516,7 +519,7 @@ TEST(AngleStyle, plain) } if (print_stats) std::cerr << "restart_forces stats:" << stats << std::endl; - angle = lmp->force->angle; + angle = lmp->force->angle; stress = angle->virial; stats.reset(); EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); @@ -535,7 +538,7 @@ TEST(AngleStyle, plain) data_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; + f = lmp->atom->f; tag = lmp->atom->tag; stats.reset(); ASSERT_EQ(nlocal + 1, f_ref.size()); @@ -546,7 +549,7 @@ TEST(AngleStyle, plain) } if (print_stats) std::cerr << "data_forces stats:" << stats << std::endl; - angle = lmp->force->angle; + angle = lmp->force->angle; stress = angle->virial; stats.reset(); EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); @@ -571,11 +574,13 @@ TEST(AngleStyle, omp) if (!LAMMPS::is_installed_pkg("USER-OMP")) GTEST_SKIP(); const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite", "-pk", "omp", "4", "-sf", "omp"}; + char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = sizeof(args) / sizeof(char *); ::testing::internal::CaptureStdout(); LAMMPS *lmp = init_lammps(argc, argv, test_config, true); + std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -596,9 +601,9 @@ TEST(AngleStyle, omp) ASSERT_EQ(lmp->atom->natoms, nlocal); // relax error a bit for USER-OMP package - double epsilon = 5.0 * test_config.epsilon; - double **f = lmp->atom->f; - tagint *tag = lmp->atom->tag; + double epsilon = 5.0 * test_config.epsilon; + double **f = lmp->atom->f; + tagint *tag = lmp->atom->tag; const std::vector &f_ref = test_config.init_forces; ErrorStats stats; stats.reset(); @@ -609,7 +614,7 @@ TEST(AngleStyle, omp) } if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; - Angle *angle = lmp->force->angle; + Angle *angle = lmp->force->angle; double *stress = angle->virial; stats.reset(); @@ -629,8 +634,8 @@ TEST(AngleStyle, omp) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - stress = angle->virial; + f = lmp->atom->f; + stress = angle->virial; const std::vector &f_run = test_config.run_forces; ASSERT_EQ(nlocal + 1, f_run.size()); stats.reset(); @@ -652,7 +657,7 @@ TEST(AngleStyle, omp) if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; stats.reset(); - int id = lmp->modify->find_compute("sum"); + int id = lmp->modify->find_compute("sum"); double energy = lmp->modify->compute[id]->compute_scalar(); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.run_energy, epsilon); // TODO: this is currently broken for USER-OMP with angle style hybrid @@ -669,7 +674,7 @@ TEST(AngleStyle, omp) // skip over these tests if newton bond is forced to be on if (lmp->force->newton_bond == 0) { - f = lmp->atom->f; + f = lmp->atom->f; tag = lmp->atom->tag; stats.reset(); for (int i = 0; i < nlocal; ++i) { @@ -679,7 +684,7 @@ TEST(AngleStyle, omp) } if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; - angle = lmp->force->angle; + angle = lmp->force->angle; stress = angle->virial; stats.reset(); EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); @@ -718,7 +723,7 @@ TEST(AngleStyle, omp) if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; stats.reset(); - id = lmp->modify->find_compute("sum"); + id = lmp->modify->find_compute("sum"); energy = lmp->modify->compute[id]->compute_scalar(); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.run_energy, epsilon); // TODO: this is currently broken for USER-OMP with angle style hybrid @@ -736,8 +741,9 @@ TEST(AngleStyle, omp) TEST(AngleStyle, single) { const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"}; + char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = sizeof(args) / sizeof(char *); // create a LAMMPS instance with standard settings to detect the number of atom types if (!verbose) ::testing::internal::CaptureStdout(); @@ -755,7 +761,7 @@ TEST(AngleStyle, single) // gather some information and skip if unsupported int nangletypes = lmp->atom->nangletypes; - int molecular = lmp->atom->molecular; + int molecular = lmp->atom->molecular; if (molecular != 1) { std::cerr << "Only simple molecular atom styles are supported\n"; if (!verbose) ::testing::internal::CaptureStdout(); @@ -824,13 +830,13 @@ TEST(AngleStyle, single) command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); - int idx1 = lmp->atom->map(1); - int idx2 = lmp->atom->map(2); - int idx3 = lmp->atom->map(3); + int idx1 = lmp->atom->map(1); + int idx2 = lmp->atom->map(2); + int idx3 = lmp->atom->map(3); double epsilon = test_config.epsilon; double eangle[4], esingle[4]; - eangle[0] = angle->energy; + eangle[0] = angle->energy; esingle[0] = angle->single(1, idx1, idx2, idx3); if (!verbose) ::testing::internal::CaptureStdout(); @@ -838,10 +844,10 @@ TEST(AngleStyle, single) command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); - idx1 = lmp->atom->map(1); - idx2 = lmp->atom->map(2); - idx3 = lmp->atom->map(3); - eangle[1] = angle->energy; + idx1 = lmp->atom->map(1); + idx2 = lmp->atom->map(2); + idx3 = lmp->atom->map(3); + eangle[1] = angle->energy; esingle[1] = angle->single(1, idx1, idx2, idx3); if (!verbose) ::testing::internal::CaptureStdout(); @@ -849,10 +855,10 @@ TEST(AngleStyle, single) command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); - idx1 = lmp->atom->map(1); - idx2 = lmp->atom->map(2); - idx3 = lmp->atom->map(3); - eangle[2] = angle->energy; + idx1 = lmp->atom->map(1); + idx2 = lmp->atom->map(2); + idx3 = lmp->atom->map(3); + eangle[2] = angle->energy; esingle[2] = angle->single(1, idx1, idx2, idx3); if (!verbose) ::testing::internal::CaptureStdout(); @@ -860,10 +866,10 @@ TEST(AngleStyle, single) command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); - idx1 = lmp->atom->map(1); - idx2 = lmp->atom->map(2); - idx3 = lmp->atom->map(3); - eangle[3] = angle->energy; + idx1 = lmp->atom->map(1); + idx2 = lmp->atom->map(2); + idx3 = lmp->atom->map(3); + eangle[3] = angle->energy; esingle[3] = angle->single(1, idx1, idx2, idx3); ErrorStats stats; diff --git a/unittest/force-styles/bond_style.cpp b/unittest/force-styles/bond_style.cpp index 2ffd756fb7..c2db3b608b 100644 --- a/unittest/force-styles/bond_style.cpp +++ b/unittest/force-styles/bond_style.cpp @@ -72,7 +72,7 @@ LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool new // check if prerequisite styles are available Info *info = new Info(lmp); - int nfail = 0; + int nfail = 0; for (auto &prerequisite : cfg.prerequisites) { std::string style = prerequisite.second; @@ -217,8 +217,9 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) { // initialize system geometry const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"}; + char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = sizeof(args) / sizeof(char *); LAMMPS *lmp = init_lammps(argc, argv, config); if (!lmp) { std::cerr << "One or more prerequisite styles are not available " @@ -229,7 +230,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) return; } - const int natoms = lmp->atom->natoms; + const int natoms = lmp->atom->natoms; const int bufsize = 256; char buf[bufsize]; std::string block(""); @@ -241,8 +242,8 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // date_generated std::time_t now = time(NULL); - block = ctime(&now); - block = block.substr(0, block.find("\n") - 1); + block = ctime(&now); + block = block.substr(0, block.find("\n") - 1); writer.emit("date_generated", block); // epsilon @@ -312,7 +313,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // init_forces block.clear(); - double **f = lmp->atom->f; + double **f = lmp->atom->f; tagint *tag = lmp->atom->tag; for (int i = 0; i < natoms; ++i) { snprintf(buf, bufsize, "% 3d % 23.16e % 23.16e % 23.16e\n", (int)tag[i], f[i][0], f[i][1], @@ -334,7 +335,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) writer.emit_block("run_stress", buf); block.clear(); - f = lmp->atom->f; + f = lmp->atom->f; tag = lmp->atom->tag; for (int i = 0; i < natoms; ++i) { snprintf(buf, bufsize, "% 3d % 23.16e % 23.16e % 23.16e\n", (int)tag[i], f[i][0], f[i][1], @@ -350,11 +351,13 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) TEST(BondStyle, plain) { const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"}; + char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = sizeof(args) / sizeof(char *); ::testing::internal::CaptureStdout(); LAMMPS *lmp = init_lammps(argc, argv, test_config, true); + std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -375,8 +378,8 @@ TEST(BondStyle, plain) ASSERT_EQ(lmp->atom->natoms, nlocal); double epsilon = test_config.epsilon; - double **f = lmp->atom->f; - tagint *tag = lmp->atom->tag; + double **f = lmp->atom->f; + tagint *tag = lmp->atom->tag; ErrorStats stats; stats.reset(); const std::vector &f_ref = test_config.init_forces; @@ -388,7 +391,7 @@ TEST(BondStyle, plain) } if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; - Bond *bond = lmp->force->bond; + Bond *bond = lmp->force->bond; double *stress = bond->virial; stats.reset(); EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); @@ -407,8 +410,8 @@ TEST(BondStyle, plain) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - stress = bond->virial; + f = lmp->atom->f; + stress = bond->virial; const std::vector &f_run = test_config.run_forces; ASSERT_EQ(nlocal + 1, f_run.size()); stats.reset(); @@ -430,7 +433,7 @@ TEST(BondStyle, plain) if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; stats.reset(); - int id = lmp->modify->find_compute("sum"); + int id = lmp->modify->find_compute("sum"); double energy = lmp->modify->compute[id]->compute_scalar(); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.run_energy, epsilon); EXPECT_FP_LE_WITH_EPS(bond->energy, energy, epsilon); @@ -444,7 +447,7 @@ TEST(BondStyle, plain) // skip over these tests if newton bond is forced to be on if (lmp->force->newton_bond == 0) { - f = lmp->atom->f; + f = lmp->atom->f; tag = lmp->atom->tag; stats.reset(); for (int i = 0; i < nlocal; ++i) { @@ -454,7 +457,7 @@ TEST(BondStyle, plain) } if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; - bond = lmp->force->bond; + bond = lmp->force->bond; stress = bond->virial; stats.reset(); EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 2 * epsilon); @@ -473,7 +476,7 @@ TEST(BondStyle, plain) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; + f = lmp->atom->f; stress = bond->virial; stats.reset(); for (int i = 0; i < nlocal; ++i) { @@ -494,7 +497,7 @@ TEST(BondStyle, plain) if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; stats.reset(); - id = lmp->modify->find_compute("sum"); + id = lmp->modify->find_compute("sum"); energy = lmp->modify->compute[id]->compute_scalar(); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.run_energy, epsilon); EXPECT_FP_LE_WITH_EPS(bond->energy, energy, epsilon); @@ -505,7 +508,7 @@ TEST(BondStyle, plain) restart_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; + f = lmp->atom->f; tag = lmp->atom->tag; stats.reset(); ASSERT_EQ(nlocal + 1, f_ref.size()); @@ -516,7 +519,7 @@ TEST(BondStyle, plain) } if (print_stats) std::cerr << "restart_forces stats:" << stats << std::endl; - bond = lmp->force->bond; + bond = lmp->force->bond; stress = bond->virial; stats.reset(); EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); @@ -535,7 +538,7 @@ TEST(BondStyle, plain) data_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; + f = lmp->atom->f; tag = lmp->atom->tag; stats.reset(); ASSERT_EQ(nlocal + 1, f_ref.size()); @@ -546,7 +549,7 @@ TEST(BondStyle, plain) } if (print_stats) std::cerr << "data_forces stats:" << stats << std::endl; - bond = lmp->force->bond; + bond = lmp->force->bond; stress = bond->virial; stats.reset(); EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); @@ -571,11 +574,13 @@ TEST(BondStyle, omp) if (!LAMMPS::is_installed_pkg("USER-OMP")) GTEST_SKIP(); const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite", "-pk", "omp", "4", "-sf", "omp"}; + char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = sizeof(args) / sizeof(char *); ::testing::internal::CaptureStdout(); LAMMPS *lmp = init_lammps(argc, argv, test_config, true); + std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -596,9 +601,9 @@ TEST(BondStyle, omp) ASSERT_EQ(lmp->atom->natoms, nlocal); // relax error a bit for USER-OMP package - double epsilon = 5.0 * test_config.epsilon; - double **f = lmp->atom->f; - tagint *tag = lmp->atom->tag; + double epsilon = 5.0 * test_config.epsilon; + double **f = lmp->atom->f; + tagint *tag = lmp->atom->tag; const std::vector &f_ref = test_config.init_forces; ErrorStats stats; stats.reset(); @@ -609,7 +614,7 @@ TEST(BondStyle, omp) } if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; - Bond *bond = lmp->force->bond; + Bond *bond = lmp->force->bond; double *stress = bond->virial; stats.reset(); EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); @@ -628,8 +633,8 @@ TEST(BondStyle, omp) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - stress = bond->virial; + f = lmp->atom->f; + stress = bond->virial; const std::vector &f_run = test_config.run_forces; ASSERT_EQ(nlocal + 1, f_run.size()); stats.reset(); @@ -651,7 +656,7 @@ TEST(BondStyle, omp) if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; stats.reset(); - int id = lmp->modify->find_compute("sum"); + int id = lmp->modify->find_compute("sum"); double energy = lmp->modify->compute[id]->compute_scalar(); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.run_energy, epsilon); // TODO: this is currently broken for USER-OMP with bond style hybrid @@ -668,7 +673,7 @@ TEST(BondStyle, omp) // skip over these tests if newton bond is forced to be on if (lmp->force->newton_bond == 0) { - f = lmp->atom->f; + f = lmp->atom->f; tag = lmp->atom->tag; stats.reset(); for (int i = 0; i < nlocal; ++i) { @@ -678,7 +683,7 @@ TEST(BondStyle, omp) } if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; - bond = lmp->force->bond; + bond = lmp->force->bond; stress = bond->virial; stats.reset(); EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); @@ -717,7 +722,7 @@ TEST(BondStyle, omp) if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; stats.reset(); - id = lmp->modify->find_compute("sum"); + id = lmp->modify->find_compute("sum"); energy = lmp->modify->compute[id]->compute_scalar(); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.run_energy, epsilon); // TODO: this is currently broken for USER-OMP with bond style hybrid @@ -735,8 +740,9 @@ TEST(BondStyle, omp) TEST(BondStyle, single) { const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"}; + char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = sizeof(args) / sizeof(char *); // create a LAMMPS instance with standard settings to detect the number of atom types if (!verbose) ::testing::internal::CaptureStdout(); @@ -754,7 +760,7 @@ TEST(BondStyle, single) // gather some information and skip if unsupported int nbondtypes = lmp->atom->nbondtypes; - int molecular = lmp->atom->molecular; + int molecular = lmp->atom->molecular; if (molecular != 1) { std::cerr << "Only simple molecular atom styles are supported\n"; if (!verbose) ::testing::internal::CaptureStdout(); @@ -825,21 +831,21 @@ TEST(BondStyle, single) command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); - int idx1 = lmp->atom->map(1); - int idx2 = lmp->atom->map(2); - int idx3 = lmp->atom->map(3); - int idx4 = lmp->atom->map(4); + int idx1 = lmp->atom->map(1); + int idx2 = lmp->atom->map(2); + int idx3 = lmp->atom->map(3); + int idx4 = lmp->atom->map(4); double epsilon = test_config.epsilon; - double **f = lmp->atom->f; - double **x = lmp->atom->x; - double delx1 = x[idx2][0] - x[idx1][0]; - double dely1 = x[idx2][1] - x[idx1][1]; - double delz1 = x[idx2][2] - x[idx1][2]; - double rsq1 = delx1 * delx1 + dely1 * dely1 + delz1 * delz1; - double delx2 = x[idx4][0] - x[idx3][0]; - double dely2 = x[idx4][1] - x[idx3][1]; - double delz2 = x[idx4][2] - x[idx3][2]; - double rsq2 = delx2 * delx2 + dely2 * dely2 + delz2 * delz2; + double **f = lmp->atom->f; + double **x = lmp->atom->x; + double delx1 = x[idx2][0] - x[idx1][0]; + double dely1 = x[idx2][1] - x[idx1][1]; + double delz1 = x[idx2][2] - x[idx1][2]; + double rsq1 = delx1 * delx1 + dely1 * dely1 + delz1 * delz1; + double delx2 = x[idx4][0] - x[idx3][0]; + double dely2 = x[idx4][1] - x[idx3][1]; + double delz2 = x[idx4][2] - x[idx3][2]; + double rsq2 = delx2 * delx2 + dely2 * dely2 + delz2 * delz2; double fsingle = 0.0; double ebond[4], esngl[4]; ErrorStats stats; @@ -866,20 +872,20 @@ TEST(BondStyle, single) command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - x = lmp->atom->x; - idx1 = lmp->atom->map(1); - idx2 = lmp->atom->map(2); - idx3 = lmp->atom->map(3); - idx4 = lmp->atom->map(4); - delx1 = x[idx2][0] - x[idx1][0]; - dely1 = x[idx2][1] - x[idx1][1]; - delz1 = x[idx2][2] - x[idx1][2]; - rsq1 = delx1 * delx1 + dely1 * dely1 + delz1 * delz1; - delx2 = x[idx4][0] - x[idx3][0]; - dely2 = x[idx4][1] - x[idx3][1]; - delz2 = x[idx4][2] - x[idx3][2]; - rsq2 = delx2 * delx2 + dely2 * dely2 + delz2 * delz2; + f = lmp->atom->f; + x = lmp->atom->x; + idx1 = lmp->atom->map(1); + idx2 = lmp->atom->map(2); + idx3 = lmp->atom->map(3); + idx4 = lmp->atom->map(4); + delx1 = x[idx2][0] - x[idx1][0]; + dely1 = x[idx2][1] - x[idx1][1]; + delz1 = x[idx2][2] - x[idx1][2]; + rsq1 = delx1 * delx1 + dely1 * dely1 + delz1 * delz1; + delx2 = x[idx4][0] - x[idx3][0]; + dely2 = x[idx4][1] - x[idx3][1]; + delz2 = x[idx4][2] - x[idx3][2]; + rsq2 = delx2 * delx2 + dely2 * dely2 + delz2 * delz2; fsingle = 0.0; ebond[1] = bond->energy; @@ -904,20 +910,20 @@ TEST(BondStyle, single) command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - x = lmp->atom->x; - idx1 = lmp->atom->map(1); - idx2 = lmp->atom->map(2); - idx3 = lmp->atom->map(3); - idx4 = lmp->atom->map(4); - delx1 = x[idx2][0] - x[idx1][0]; - dely1 = x[idx2][1] - x[idx1][1]; - delz1 = x[idx2][2] - x[idx1][2]; - rsq1 = delx1 * delx1 + dely1 * dely1 + delz1 * delz1; - delx2 = x[idx4][0] - x[idx3][0]; - dely2 = x[idx4][1] - x[idx3][1]; - delz2 = x[idx4][2] - x[idx3][2]; - rsq2 = delx2 * delx2 + dely2 * dely2 + delz2 * delz2; + f = lmp->atom->f; + x = lmp->atom->x; + idx1 = lmp->atom->map(1); + idx2 = lmp->atom->map(2); + idx3 = lmp->atom->map(3); + idx4 = lmp->atom->map(4); + delx1 = x[idx2][0] - x[idx1][0]; + dely1 = x[idx2][1] - x[idx1][1]; + delz1 = x[idx2][2] - x[idx1][2]; + rsq1 = delx1 * delx1 + dely1 * dely1 + delz1 * delz1; + delx2 = x[idx4][0] - x[idx3][0]; + dely2 = x[idx4][1] - x[idx3][1]; + delz2 = x[idx4][2] - x[idx3][2]; + rsq2 = delx2 * delx2 + dely2 * dely2 + delz2 * delz2; fsingle = 0.0; ebond[2] = bond->energy; @@ -942,20 +948,20 @@ TEST(BondStyle, single) command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - x = lmp->atom->x; - idx1 = lmp->atom->map(1); - idx2 = lmp->atom->map(2); - idx3 = lmp->atom->map(3); - idx4 = lmp->atom->map(4); - delx1 = x[idx2][0] - x[idx1][0]; - dely1 = x[idx2][1] - x[idx1][1]; - delz1 = x[idx2][2] - x[idx1][2]; - rsq1 = delx1 * delx1 + dely1 * dely1 + delz1 * delz1; - delx2 = x[idx4][0] - x[idx3][0]; - dely2 = x[idx4][1] - x[idx3][1]; - delz2 = x[idx4][2] - x[idx3][2]; - rsq2 = delx2 * delx2 + dely2 * dely2 + delz2 * delz2; + f = lmp->atom->f; + x = lmp->atom->x; + idx1 = lmp->atom->map(1); + idx2 = lmp->atom->map(2); + idx3 = lmp->atom->map(3); + idx4 = lmp->atom->map(4); + delx1 = x[idx2][0] - x[idx1][0]; + dely1 = x[idx2][1] - x[idx1][1]; + delz1 = x[idx2][2] - x[idx1][2]; + rsq1 = delx1 * delx1 + dely1 * dely1 + delz1 * delz1; + delx2 = x[idx4][0] - x[idx3][0]; + dely2 = x[idx4][1] - x[idx3][1]; + delz2 = x[idx4][2] - x[idx3][2]; + rsq2 = delx2 * delx2 + dely2 * dely2 + delz2 * delz2; fsingle = 0.0; ebond[3] = bond->energy; @@ -995,8 +1001,9 @@ TEST(BondStyle, single) TEST(BondStyle, extract) { const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"}; + char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = sizeof(args) / sizeof(char *); if (!verbose) ::testing::internal::CaptureStdout(); LAMMPS *lmp = init_lammps(argc, argv, test_config, true); @@ -1011,8 +1018,8 @@ TEST(BondStyle, extract) GTEST_SKIP(); } Bond *bond = lmp->force->bond; - void *ptr = nullptr; - int dim = 0; + void *ptr = nullptr; + int dim = 0; for (auto extract : test_config.extract) { ptr = bond->extract(extract.first.c_str(), dim); EXPECT_NE(ptr, nullptr); diff --git a/unittest/force-styles/error_stats.cpp b/unittest/force-styles/error_stats.cpp index 8ab8c5a627..c58ff4c0ee 100644 --- a/unittest/force-styles/error_stats.cpp +++ b/unittest/force-styles/error_stats.cpp @@ -12,13 +12,14 @@ ------------------------------------------------------------------------- */ #include "error_stats.h" +#include "fmt/format.h" #include #include #include void ErrorStats::reset() { - num = 0; + num = 0; maxidx = -1; sum = sumsq = maxerr = 0.0; } @@ -47,8 +48,8 @@ double ErrorStats::dev() const std::ostream &operator<<(std::ostream &out, const ErrorStats &stats) { const std::ios_base::fmtflags flags = out.flags(); - const std::streamsize width = out.width(10); - const std::streamsize prec = out.precision(3); + const std::streamsize width = out.width(10); + const std::streamsize prec = out.precision(3); out << std::scientific << "Average: " << stats.avg() << " StdDev: " << stats.dev() << " MaxErr: " << stats.max(); diff --git a/unittest/force-styles/pair_style.cpp b/unittest/force-styles/pair_style.cpp index 62e1181dab..31c493f717 100644 --- a/unittest/force-styles/pair_style.cpp +++ b/unittest/force-styles/pair_style.cpp @@ -72,7 +72,7 @@ LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool new // check if prerequisite styles are available Info *info = new Info(lmp); - int nfail = 0; + int nfail = 0; for (auto &prerequisite : cfg.prerequisites) { std::string style = prerequisite.second; @@ -216,8 +216,9 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) { // initialize system geometry const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"}; + char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = sizeof(args) / sizeof(char *); LAMMPS *lmp = init_lammps(argc, argv, config); if (!lmp) { std::cerr << "One or more prerequisite styles are not available " @@ -228,7 +229,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) return; } - const int natoms = lmp->atom->natoms; + const int natoms = lmp->atom->natoms; const int bufsize = 256; char buf[bufsize]; std::string block(""); @@ -240,8 +241,8 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // date_generated std::time_t now = time(NULL); - block = ctime(&now); - block = block.substr(0, block.find("\n") - 1); + block = ctime(&now); + block = block.substr(0, block.find("\n") - 1); writer.emit("date_generated", block); // epsilon @@ -306,7 +307,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // init_forces block.clear(); - double **f = lmp->atom->f; + double **f = lmp->atom->f; tagint *tag = lmp->atom->tag; for (int i = 0; i < natoms; ++i) { snprintf(buf, bufsize, "% 3d % 23.16e % 23.16e % 23.16e\n", (int)tag[i], f[i][0], f[i][1], @@ -331,7 +332,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) writer.emit_block("run_stress", buf); block.clear(); - f = lmp->atom->f; + f = lmp->atom->f; tag = lmp->atom->tag; for (int i = 0; i < natoms; ++i) { snprintf(buf, bufsize, "% 3d % 23.16e % 23.16e % 23.16e\n", (int)tag[i], f[i][0], f[i][1], @@ -347,11 +348,13 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) TEST(PairStyle, plain) { const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"}; + char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = sizeof(args) / sizeof(char *); ::testing::internal::CaptureStdout(); LAMMPS *lmp = init_lammps(argc, argv, test_config, true); + std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -372,8 +375,8 @@ TEST(PairStyle, plain) ASSERT_EQ(lmp->atom->natoms, nlocal); double epsilon = test_config.epsilon; - double **f = lmp->atom->f; - tagint *tag = lmp->atom->tag; + double **f = lmp->atom->f; + tagint *tag = lmp->atom->tag; ErrorStats stats; stats.reset(); const std::vector &f_ref = test_config.init_forces; @@ -385,7 +388,7 @@ TEST(PairStyle, plain) } if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; - Pair *pair = lmp->force->pair; + Pair *pair = lmp->force->pair; double *stress = pair->virial; stats.reset(); EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); @@ -405,8 +408,8 @@ TEST(PairStyle, plain) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - stress = pair->virial; + f = lmp->atom->f; + stress = pair->virial; const std::vector &f_run = test_config.run_forces; ASSERT_EQ(nlocal + 1, f_run.size()); stats.reset(); @@ -428,7 +431,7 @@ TEST(PairStyle, plain) if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; stats.reset(); - int id = lmp->modify->find_compute("sum"); + int id = lmp->modify->find_compute("sum"); double energy = lmp->modify->compute[id]->compute_scalar(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.run_vdwl, epsilon); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.run_coul, epsilon); @@ -443,7 +446,7 @@ TEST(PairStyle, plain) // skip over these tests if newton pair is forced to be on if (lmp->force->newton_pair == 0) { - f = lmp->atom->f; + f = lmp->atom->f; tag = lmp->atom->tag; stats.reset(); for (int i = 0; i < nlocal; ++i) { @@ -453,7 +456,7 @@ TEST(PairStyle, plain) } if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; - pair = lmp->force->pair; + pair = lmp->force->pair; stress = pair->virial; stats.reset(); EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 3 * epsilon); @@ -473,7 +476,7 @@ TEST(PairStyle, plain) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; + f = lmp->atom->f; stress = pair->virial; stats.reset(); for (int i = 0; i < nlocal; ++i) { @@ -494,7 +497,7 @@ TEST(PairStyle, plain) if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; stats.reset(); - id = lmp->modify->find_compute("sum"); + id = lmp->modify->find_compute("sum"); energy = lmp->modify->compute[id]->compute_scalar(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.run_vdwl, epsilon); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.run_coul, epsilon); @@ -506,7 +509,7 @@ TEST(PairStyle, plain) restart_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; + f = lmp->atom->f; tag = lmp->atom->tag; stats.reset(); ASSERT_EQ(nlocal + 1, f_ref.size()); @@ -517,7 +520,7 @@ TEST(PairStyle, plain) } if (print_stats) std::cerr << "restart_forces stats:" << stats << std::endl; - pair = lmp->force->pair; + pair = lmp->force->pair; stress = pair->virial; stats.reset(); EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); @@ -537,7 +540,7 @@ TEST(PairStyle, plain) data_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; + f = lmp->atom->f; tag = lmp->atom->tag; stats.reset(); ASSERT_EQ(nlocal + 1, f_ref.size()); @@ -548,7 +551,7 @@ TEST(PairStyle, plain) } if (print_stats) std::cerr << "data_forces stats:" << stats << std::endl; - pair = lmp->force->pair; + pair = lmp->force->pair; stress = pair->virial; stats.reset(); EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); @@ -577,8 +580,8 @@ TEST(PairStyle, plain) // and compute_middle() so we get a significant deviation. if (pair->ncoultablebits) epsilon *= 1.0e6; - f = lmp->atom->f; - tag = lmp->atom->tag; + f = lmp->atom->f; + tag = lmp->atom->tag; pair = lmp->force->pair; stats.reset(); for (int i = 0; i < nlocal; ++i) { @@ -599,7 +602,7 @@ TEST(PairStyle, plain) if (print_stats) std::cerr << "run_stress stats, r-RESPA:" << stats << std::endl; stats.reset(); - id = lmp->modify->find_compute("sum"); + id = lmp->modify->find_compute("sum"); energy = lmp->modify->compute[id]->compute_scalar(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.run_vdwl, epsilon); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.run_coul, epsilon); @@ -616,11 +619,13 @@ TEST(PairStyle, omp) if (!LAMMPS::is_installed_pkg("USER-OMP")) GTEST_SKIP(); const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", "-pk", "omp", "4", "-sf", "omp"}; + char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = sizeof(args) / sizeof(char *); ::testing::internal::CaptureStdout(); LAMMPS *lmp = init_lammps(argc, argv, test_config, true); + std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -641,9 +646,9 @@ TEST(PairStyle, omp) ASSERT_EQ(lmp->atom->natoms, nlocal); // relax error a bit for USER-OMP package - double epsilon = 5.0 * test_config.epsilon; - double **f = lmp->atom->f; - tagint *tag = lmp->atom->tag; + double epsilon = 5.0 * test_config.epsilon; + double **f = lmp->atom->f; + tagint *tag = lmp->atom->tag; const std::vector &f_ref = test_config.init_forces; ErrorStats stats; stats.reset(); @@ -654,7 +659,7 @@ TEST(PairStyle, omp) } if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; - Pair *pair = lmp->force->pair; + Pair *pair = lmp->force->pair; double *stress = pair->virial; stats.reset(); EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); @@ -674,8 +679,8 @@ TEST(PairStyle, omp) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - stress = pair->virial; + f = lmp->atom->f; + stress = pair->virial; const std::vector &f_run = test_config.run_forces; ASSERT_EQ(nlocal + 1, f_run.size()); stats.reset(); @@ -697,7 +702,7 @@ TEST(PairStyle, omp) if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; stats.reset(); - int id = lmp->modify->find_compute("sum"); + int id = lmp->modify->find_compute("sum"); double energy = lmp->modify->compute[id]->compute_scalar(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.run_vdwl, epsilon); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.run_coul, epsilon); @@ -712,7 +717,7 @@ TEST(PairStyle, omp) // skip over these tests if newton pair is forced to be on if (lmp->force->newton_pair == 0) { - f = lmp->atom->f; + f = lmp->atom->f; tag = lmp->atom->tag; stats.reset(); for (int i = 0; i < nlocal; ++i) { @@ -722,7 +727,7 @@ TEST(PairStyle, omp) } if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; - pair = lmp->force->pair; + pair = lmp->force->pair; stress = pair->virial; stats.reset(); EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); @@ -762,7 +767,7 @@ TEST(PairStyle, omp) if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; stats.reset(); - id = lmp->modify->find_compute("sum"); + id = lmp->modify->find_compute("sum"); energy = lmp->modify->compute[id]->compute_scalar(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.run_vdwl, epsilon); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.run_coul, epsilon); @@ -780,11 +785,13 @@ TEST(PairStyle, intel) const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", "-pk", "intel", "0", "mode", "double", "omp", "4", "lrt", "no", "-sf", "intel"}; + char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = sizeof(args) / sizeof(char *); ::testing::internal::CaptureStdout(); LAMMPS *lmp = init_lammps(argc, argv, test_config); + std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -823,8 +830,8 @@ TEST(PairStyle, intel) const int nlocal = lmp->atom->nlocal; ASSERT_EQ(lmp->atom->natoms, nlocal); - double **f = lmp->atom->f; - tagint *tag = lmp->atom->tag; + double **f = lmp->atom->f; + tagint *tag = lmp->atom->tag; const std::vector &f_ref = test_config.init_forces; ErrorStats stats; stats.reset(); @@ -835,7 +842,7 @@ TEST(PairStyle, intel) } if (print_stats) std::cerr << "init_forces stats:" << stats << std::endl; - Pair *pair = lmp->force->pair; + Pair *pair = lmp->force->pair; double *stress = pair->virial; stats.reset(); EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); @@ -855,8 +862,8 @@ TEST(PairStyle, intel) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - stress = pair->virial; + f = lmp->atom->f; + stress = pair->virial; const std::vector &f_run = test_config.run_forces; ASSERT_EQ(nlocal + 1, f_run.size()); stats.reset(); @@ -878,7 +885,7 @@ TEST(PairStyle, intel) if (print_stats) std::cerr << "run_stress stats:" << stats << std::endl; stats.reset(); - int id = lmp->modify->find_compute("sum"); + int id = lmp->modify->find_compute("sum"); double energy = lmp->modify->compute[id]->compute_scalar(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.run_vdwl, epsilon); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.run_coul, epsilon); @@ -898,13 +905,15 @@ TEST(PairStyle, opt) { if (!LAMMPS::is_installed_pkg("OPT")) GTEST_SKIP(); const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", "-sf", "opt"}; + char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = sizeof(args) / sizeof(char *); if (!verbose) ::testing::internal::CaptureStdout(); LAMMPS *lmp = init_lammps(argc, argv, test_config); - std::string output; - if (!verbose) output = ::testing::internal::GetCapturedStdout(); + + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; if (!lmp) { std::cerr << "One or more prerequisite styles with /opt suffix\n" @@ -923,9 +932,9 @@ TEST(PairStyle, opt) ASSERT_EQ(lmp->atom->natoms, nlocal); // relax error a bit for OPT package - double epsilon = 2.0 * test_config.epsilon; - double **f = lmp->atom->f; - tagint *tag = lmp->atom->tag; + double epsilon = 2.0 * test_config.epsilon; + double **f = lmp->atom->f; + tagint *tag = lmp->atom->tag; const std::vector &f_ref = test_config.init_forces; ErrorStats stats; stats.reset(); @@ -936,7 +945,7 @@ TEST(PairStyle, opt) } if (print_stats) std::cerr << "init_forces stats:" << stats << std::endl; - Pair *pair = lmp->force->pair; + Pair *pair = lmp->force->pair; double *stress = pair->virial; stats.reset(); EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); @@ -956,8 +965,8 @@ TEST(PairStyle, opt) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - stress = pair->virial; + f = lmp->atom->f; + stress = pair->virial; const std::vector &f_run = test_config.run_forces; ASSERT_EQ(nlocal + 1, f_run.size()); stats.reset(); @@ -979,7 +988,7 @@ TEST(PairStyle, opt) if (print_stats) std::cerr << "run_stress stats:" << stats << std::endl; stats.reset(); - int id = lmp->modify->find_compute("sum"); + int id = lmp->modify->find_compute("sum"); double energy = lmp->modify->compute[id]->compute_scalar(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.run_vdwl, epsilon); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.run_coul, epsilon); @@ -994,8 +1003,9 @@ TEST(PairStyle, opt) TEST(PairStyle, single) { const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"}; + char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = sizeof(args) / sizeof(char *); // create a LAMMPS instance with standard settings to detect the number of atom types if (!verbose) ::testing::internal::CaptureStdout(); @@ -1012,7 +1022,7 @@ TEST(PairStyle, single) } // gather some information and skip if unsupported - int ntypes = lmp->atom->ntypes; + int ntypes = lmp->atom->ntypes; int molecular = lmp->atom->molecular; if (molecular > 1) { std::cerr << "Only atomic and simple molecular atom styles are supported\n"; @@ -1115,15 +1125,15 @@ TEST(PairStyle, single) command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); - int idx1 = lmp->atom->map(1); - int idx2 = lmp->atom->map(2); + int idx1 = lmp->atom->map(1); + int idx2 = lmp->atom->map(2); double epsilon = test_config.epsilon; - double **f = lmp->atom->f; - double **x = lmp->atom->x; - double delx = x[idx2][0] - x[idx1][0]; - double dely = x[idx2][1] - x[idx1][1]; - double delz = x[idx2][2] - x[idx1][2]; - double rsq = delx * delx + dely * dely + delz * delz; + double **f = lmp->atom->f; + double **x = lmp->atom->x; + double delx = x[idx2][0] - x[idx1][0]; + double dely = x[idx2][1] - x[idx1][1]; + double delz = x[idx2][2] - x[idx1][2]; + double rsq = delx * delx + dely * dely + delz * delz; double fsingle = 0.0; double epair[4], esngl[4]; double splj = lmp->force->special_lj[1]; @@ -1144,14 +1154,14 @@ TEST(PairStyle, single) command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - x = lmp->atom->x; - idx1 = lmp->atom->map(1); - idx2 = lmp->atom->map(2); - delx = x[idx2][0] - x[idx1][0]; - dely = x[idx2][1] - x[idx1][1]; - delz = x[idx2][2] - x[idx1][2]; - rsq = delx * delx + dely * dely + delz * delz; + f = lmp->atom->f; + x = lmp->atom->x; + idx1 = lmp->atom->map(1); + idx2 = lmp->atom->map(2); + delx = x[idx2][0] - x[idx1][0]; + dely = x[idx2][1] - x[idx1][1]; + delz = x[idx2][2] - x[idx1][2]; + rsq = delx * delx + dely * dely + delz * delz; fsingle = 0.0; epair[1] = pair->eng_vdwl + pair->eng_coul; @@ -1168,14 +1178,14 @@ TEST(PairStyle, single) command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - x = lmp->atom->x; - idx1 = lmp->atom->map(1); - idx2 = lmp->atom->map(2); - delx = x[idx2][0] - x[idx1][0]; - dely = x[idx2][1] - x[idx1][1]; - delz = x[idx2][2] - x[idx1][2]; - rsq = delx * delx + dely * dely + delz * delz; + f = lmp->atom->f; + x = lmp->atom->x; + idx1 = lmp->atom->map(1); + idx2 = lmp->atom->map(2); + delx = x[idx2][0] - x[idx1][0]; + dely = x[idx2][1] - x[idx1][1]; + delz = x[idx2][2] - x[idx1][2]; + rsq = delx * delx + dely * dely + delz * delz; fsingle = 0.0; epair[2] = pair->eng_vdwl + pair->eng_coul; @@ -1192,14 +1202,14 @@ TEST(PairStyle, single) command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - x = lmp->atom->x; - idx1 = lmp->atom->map(1); - idx2 = lmp->atom->map(2); - delx = x[idx2][0] - x[idx1][0]; - dely = x[idx2][1] - x[idx1][1]; - delz = x[idx2][2] - x[idx1][2]; - rsq = delx * delx + dely * dely + delz * delz; + f = lmp->atom->f; + x = lmp->atom->x; + idx1 = lmp->atom->map(1); + idx2 = lmp->atom->map(2); + delx = x[idx2][0] - x[idx1][0]; + dely = x[idx2][1] - x[idx1][1]; + delz = x[idx2][2] - x[idx1][2]; + rsq = delx * delx + dely * dely + delz * delz; fsingle = 0.0; epair[3] = pair->eng_vdwl + pair->eng_coul; @@ -1231,8 +1241,9 @@ TEST(PairStyle, single) TEST(PairStyle, extract) { const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"}; + char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = sizeof(args) / sizeof(char *); if (!verbose) ::testing::internal::CaptureStdout(); LAMMPS *lmp = init_lammps(argc, argv, test_config, true); @@ -1247,8 +1258,8 @@ TEST(PairStyle, extract) GTEST_SKIP(); } Pair *pair = lmp->force->pair; - void *ptr = nullptr; - int dim = 0; + void *ptr = nullptr; + int dim = 0; for (auto &extract : test_config.extract) { ptr = pair->extract(extract.first.c_str(), dim); EXPECT_NE(ptr, nullptr); diff --git a/unittest/force-styles/test_config_reader.cpp b/unittest/force-styles/test_config_reader.cpp index 4733190aad..24b08f93e9 100644 --- a/unittest/force-styles/test_config_reader.cpp +++ b/unittest/force-styles/test_config_reader.cpp @@ -29,31 +29,31 @@ TestConfigReader::TestConfigReader(TestConfig &config) : YamlReader(), config(co { consumers["lammps_version"] = &TestConfigReader::lammps_version; consumers["date_generated"] = &TestConfigReader::date_generated; - consumers["epsilon"] = &TestConfigReader::epsilon; - consumers["prerequisites"] = &TestConfigReader::prerequisites; - consumers["pre_commands"] = &TestConfigReader::pre_commands; - consumers["post_commands"] = &TestConfigReader::post_commands; - consumers["input_file"] = &TestConfigReader::input_file; - consumers["extract"] = &TestConfigReader::extract; - consumers["natoms"] = &TestConfigReader::natoms; - consumers["init_stress"] = &TestConfigReader::init_stress; - consumers["run_stress"] = &TestConfigReader::run_stress; - consumers["init_forces"] = &TestConfigReader::init_forces; - consumers["run_forces"] = &TestConfigReader::run_forces; + consumers["epsilon"] = &TestConfigReader::epsilon; + consumers["prerequisites"] = &TestConfigReader::prerequisites; + consumers["pre_commands"] = &TestConfigReader::pre_commands; + consumers["post_commands"] = &TestConfigReader::post_commands; + consumers["input_file"] = &TestConfigReader::input_file; + consumers["extract"] = &TestConfigReader::extract; + consumers["natoms"] = &TestConfigReader::natoms; + consumers["init_stress"] = &TestConfigReader::init_stress; + consumers["run_stress"] = &TestConfigReader::run_stress; + consumers["init_forces"] = &TestConfigReader::init_forces; + consumers["run_forces"] = &TestConfigReader::run_forces; consumers["pair_style"] = &TestConfigReader::pair_style; consumers["pair_coeff"] = &TestConfigReader::pair_coeff; - consumers["init_vdwl"] = &TestConfigReader::init_vdwl; - consumers["init_coul"] = &TestConfigReader::init_coul; - consumers["run_vdwl"] = &TestConfigReader::run_vdwl; - consumers["run_coul"] = &TestConfigReader::run_coul; + consumers["init_vdwl"] = &TestConfigReader::init_vdwl; + consumers["init_coul"] = &TestConfigReader::init_coul; + consumers["run_vdwl"] = &TestConfigReader::run_vdwl; + consumers["run_coul"] = &TestConfigReader::run_coul; - consumers["bond_style"] = &TestConfigReader::bond_style; - consumers["bond_coeff"] = &TestConfigReader::bond_coeff; + consumers["bond_style"] = &TestConfigReader::bond_style; + consumers["bond_coeff"] = &TestConfigReader::bond_coeff; consumers["angle_style"] = &TestConfigReader::angle_style; consumers["angle_coeff"] = &TestConfigReader::angle_coeff; consumers["init_energy"] = &TestConfigReader::init_energy; - consumers["run_energy"] = &TestConfigReader::run_energy; + consumers["run_energy"] = &TestConfigReader::run_energy; consumers["equilibrium"] = &TestConfigReader::equilibrium; } diff --git a/unittest/force-styles/test_main.h b/unittest/force-styles/test_main.h index f541094122..ee0be2a637 100644 --- a/unittest/force-styles/test_main.h +++ b/unittest/force-styles/test_main.h @@ -22,13 +22,13 @@ extern bool print_stats; extern bool verbose; extern std::string INPUT_FOLDER; -#define EXPECT_FP_LE_WITH_EPS(val1, val2, eps) \ - do { \ - const double diff = fabs(val1 - val2); \ - const double div = std::min(fabs(val1), fabs(val2)); \ - const double err = (div == 0.0) ? diff : diff / div; \ - stats.add(err); \ - EXPECT_PRED_FORMAT2(::testing::DoubleLE, err, eps); \ +#define EXPECT_FP_LE_WITH_EPS(val1, val2, eps) \ + do { \ + const double diff = fabs(val1 - val2); \ + const double div = std::min(fabs(val1), fabs(val2)); \ + const double err = (div == 0.0) ? diff : diff / div; \ + stats.add(err); \ + EXPECT_PRED_FORMAT2(::testing::DoubleLE, err, eps); \ } while (0); #endif diff --git a/unittest/force-styles/yaml_reader.h b/unittest/force-styles/yaml_reader.h index 7260a8cf9c..fc286838ca 100644 --- a/unittest/force-styles/yaml_reader.h +++ b/unittest/force-styles/yaml_reader.h @@ -48,7 +48,7 @@ public: int parse_file(const std::string &infile) { - basename = infile; + basename = infile; std::size_t found = basename.rfind(".yaml"); if (found > 0) basename = basename.substr(0, found); found = basename.find_last_of("/\\"); @@ -92,7 +92,7 @@ public: protected: bool consume_key_value(const std::string &key, const yaml_event_t &event) { - auto it = consumers.find(key); + auto it = consumers.find(key); ConsumerClass *consumer = dynamic_cast(this); if (consumer) { @@ -139,7 +139,7 @@ protected: case ACCEPT_KEY: switch (event.type) { case YAML_SCALAR_EVENT: - key = (char *)event.data.scalar.value; + key = (char *)event.data.scalar.value; state = ACCEPT_VALUE; break; case YAML_MAPPING_END_EVENT: @@ -157,7 +157,7 @@ protected: switch (event.type) { case YAML_SCALAR_EVENT: accepted = true; - state = ACCEPT_KEY; + state = ACCEPT_KEY; break; default: std::cerr << "UNHANDLED YAML EVENT (value): " << event.type diff --git a/unittest/formats/test_eim_potential_file_reader.cpp b/unittest/formats/test_eim_potential_file_reader.cpp index c8dcfd80e0..0aaa236fea 100644 --- a/unittest/formats/test_eim_potential_file_reader.cpp +++ b/unittest/formats/test_eim_potential_file_reader.cpp @@ -32,33 +32,33 @@ protected: const char *args[] = { "PotentialFileReaderTest", "-log", "none", "-echo", "screen", "-nocite"}; char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = sizeof(args) / sizeof(char *); ::testing::internal::CaptureStdout(); lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); ::testing::internal::GetCapturedStdout(); - int npair = nelements * (nelements + 1) / 2; - setfl.ielement = new int[nelements]; - setfl.mass = new double[nelements]; + int npair = nelements * (nelements + 1) / 2; + setfl.ielement = new int[nelements]; + setfl.mass = new double[nelements]; setfl.negativity = new double[nelements]; - setfl.ra = new double[nelements]; - setfl.ri = new double[nelements]; - setfl.Ec = new double[nelements]; - setfl.q0 = new double[nelements]; - setfl.rcutphiA = new double[npair]; - setfl.rcutphiR = new double[npair]; - setfl.Eb = new double[npair]; - setfl.r0 = new double[npair]; - setfl.alpha = new double[npair]; - setfl.beta = new double[npair]; - setfl.rcutq = new double[npair]; - setfl.Asigma = new double[npair]; - setfl.rq = new double[npair]; - setfl.rcutsigma = new double[npair]; - setfl.Ac = new double[npair]; - setfl.zeta = new double[npair]; - setfl.rs = new double[npair]; - setfl.tp = new int[npair]; + setfl.ra = new double[nelements]; + setfl.ri = new double[nelements]; + setfl.Ec = new double[nelements]; + setfl.q0 = new double[nelements]; + setfl.rcutphiA = new double[npair]; + setfl.rcutphiR = new double[npair]; + setfl.Eb = new double[npair]; + setfl.r0 = new double[npair]; + setfl.alpha = new double[npair]; + setfl.beta = new double[npair]; + setfl.rcutq = new double[npair]; + setfl.Asigma = new double[npair]; + setfl.rq = new double[npair]; + setfl.rcutsigma = new double[npair]; + setfl.Ac = new double[npair]; + setfl.zeta = new double[npair]; + setfl.rs = new double[npair]; + setfl.tp = new int[npair]; } void TearDown() override diff --git a/unittest/formats/test_potential_file_reader.cpp b/unittest/formats/test_potential_file_reader.cpp index dde2b27353..199a4ad329 100644 --- a/unittest/formats/test_potential_file_reader.cpp +++ b/unittest/formats/test_potential_file_reader.cpp @@ -54,7 +54,7 @@ protected: const char *args[] = { "PotentialFileReaderTest", "-log", "none", "-echo", "screen", "-nocite"}; char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = sizeof(args) / sizeof(char *); ::testing::internal::CaptureStdout(); lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); ::testing::internal::GetCapturedStdout(); diff --git a/unittest/utils/test_fmtlib.cpp b/unittest/utils/test_fmtlib.cpp index 6d02707c4d..fd9a4a06a2 100644 --- a/unittest/utils/test_fmtlib.cpp +++ b/unittest/utils/test_fmtlib.cpp @@ -26,21 +26,21 @@ using ::testing::Eq; TEST(FmtLib, insert_string) { const char val[] = "word"; - auto text = fmt::format("word {}", val); + auto text = fmt::format("word {}", val); ASSERT_THAT(text, Eq("word word")); } TEST(FmtLib, insert_int) { const int val = 333; - auto text = fmt::format("word {}", val); + auto text = fmt::format("word {}", val); ASSERT_THAT(text, Eq("word 333")); } TEST(FmtLib, insert_neg_int) { const int val = -333; - auto text = fmt::format("word {}", val); + auto text = fmt::format("word {}", val); ASSERT_THAT(text, Eq("word -333")); } @@ -48,7 +48,7 @@ TEST(FmtLib, insert_bigint) { #if defined(LAMMPS_BIGBIG) || defined(LAMMPS_SMALLBIG) const bigint val = 9945234592L; - auto text = fmt::format("word {}", val); + auto text = fmt::format("word {}", val); ASSERT_THAT(text, Eq("word 9945234592")); #else GTEST_SKIP(); @@ -59,7 +59,7 @@ TEST(FmtLib, insert_neg_bigint) { #if defined(LAMMPS_BIGBIG) || defined(LAMMPS_SMALLBIG) const bigint val = -9945234592L; - auto text = fmt::format("word {}", val); + auto text = fmt::format("word {}", val); ASSERT_THAT(text, Eq("word -9945234592")); #else GTEST_SKIP(); @@ -70,7 +70,7 @@ TEST(FmtLib, insert_tagint) { #if defined(LAMMPS_BIGBIG) const tagint val = 9945234592L; - auto text = fmt::format("word {}", val); + auto text = fmt::format("word {}", val); ASSERT_THAT(text, Eq("word 9945234592")); #else GTEST_SKIP(); @@ -81,7 +81,7 @@ TEST(FmtLib, insert_neg_tagint) { #if defined(LAMMPS_BIGBIG) const tagint val = -9945234592L; - auto text = fmt::format("word {}", val); + auto text = fmt::format("word {}", val); ASSERT_THAT(text, Eq("word -9945234592")); #else GTEST_SKIP(); @@ -92,7 +92,7 @@ TEST(FmtLib, insert_imageint) { #if defined(LAMMPS_BIGBIG) const imageint val = 9945234592L; - auto text = fmt::format("word {}", val); + auto text = fmt::format("word {}", val); ASSERT_THAT(text, Eq("word 9945234592")); #else GTEST_SKIP(); @@ -103,7 +103,7 @@ TEST(FmtLib, insert_neg_imageint) { #if defined(LAMMPS_BIGBIG) const imageint val = -9945234592L; - auto text = fmt::format("word {}", val); + auto text = fmt::format("word {}", val); ASSERT_THAT(text, Eq("word -9945234592")); #else GTEST_SKIP(); @@ -113,14 +113,14 @@ TEST(FmtLib, insert_neg_imageint) TEST(FmtLib, insert_double) { const double val = 1.5; - auto text = fmt::format("word {}", val); + auto text = fmt::format("word {}", val); ASSERT_THAT(text, Eq("word 1.5")); } TEST(FmtLib, insert_neg_double) { const double val = -1.5; - auto text = fmt::format("word {}", val); + auto text = fmt::format("word {}", val); ASSERT_THAT(text, Eq("word -1.5")); } diff --git a/unittest/utils/test_utils.cpp b/unittest/utils/test_utils.cpp index ec29b58ccb..eb91a7483c 100644 --- a/unittest/utils/test_utils.cpp +++ b/unittest/utils/test_utils.cpp @@ -280,7 +280,7 @@ TEST(Utils, path_basename) TEST(Utils, getsyserror) { #if defined(__linux__) - errno = ENOENT; + errno = ENOENT; std::string errmesg = utils::getsyserror(); ASSERT_THAT(errmesg, Eq("No such file or directory")); #else From d5d28bcbd2e9cba870f9b00021eb8ea2d80271bb Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 13 Jun 2020 02:11:21 -0400 Subject: [PATCH 09/18] use fmt::format() for error_stats output. --- unittest/force-styles/error_stats.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/unittest/force-styles/error_stats.cpp b/unittest/force-styles/error_stats.cpp index c58ff4c0ee..a22f299f55 100644 --- a/unittest/force-styles/error_stats.cpp +++ b/unittest/force-styles/error_stats.cpp @@ -47,16 +47,7 @@ double ErrorStats::dev() const std::ostream &operator<<(std::ostream &out, const ErrorStats &stats) { - const std::ios_base::fmtflags flags = out.flags(); - const std::streamsize width = out.width(10); - const std::streamsize prec = out.precision(3); - - out << std::scientific << "Average: " << stats.avg() << " StdDev: " << stats.dev() - << " MaxErr: " << stats.max(); - - out.precision(prec); - out.width(width); - out.flags(flags); - - return out << " @ item: " << stats.idx(); + out << fmt::format("Average: {:10.3e} StdDev: {:10.3e} MaxErr: {:10.3e} @ item: {}", + stats.avg(), stats.dev(), stats.max(), stats.idx()); + return out; } From fcd3e9a3f98c1a80eb12a6140670c917aa92fcaa Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Sat, 13 Jun 2020 08:28:48 -0400 Subject: [PATCH 10/18] Make quiet Python 3 check --- cmake/Modules/CodingStandard.cmake | 31 ++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/cmake/Modules/CodingStandard.cmake b/cmake/Modules/CodingStandard.cmake index d7440fba9d..467dbb2b16 100644 --- a/cmake/Modules/CodingStandard.cmake +++ b/cmake/Modules/CodingStandard.cmake @@ -1,21 +1,24 @@ if(CMAKE_VERSION VERSION_LESS 3.12) - find_package(PythonInterp) # Deprecated since version 3.12 + find_package(PythonInterp 3.5 QUIET) # Deprecated since version 3.12 if(PYTHONINTERP_FOUND) - set(Python_EXECUTABLE ${PYTHON_EXECUTABLE}) + set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE}) + set(Python3_VERSION ${PYTHON_VERSION_STRING}) endif() else() - find_package(Python COMPONENTS Interpreter) + find_package(Python3 COMPONENTS Interpreter QUIET) endif() -if (Python_EXECUTABLE) - add_custom_target( - check-whitespace - ${Python_EXECUTABLE} ${LAMMPS_TOOLS_DIR}/coding_standard/whitespace.py . - WORKING_DIRECTORY ${LAMMPS_DIR} - COMMENT "Check for whitespace errors") - add_custom_target( - fix-whitespace - ${Python_EXECUTABLE} ${LAMMPS_TOOLS_DIR}/coding_standard/whitespace.py -f . - WORKING_DIRECTORY ${LAMMPS_DIR} - COMMENT "Fix whitespace errors") +if (Python3_EXECUTABLE) + if(Python3_VERSION VERSION_GREATER_EQUAL 3.5) + add_custom_target( + check-whitespace + ${Python3_EXECUTABLE} ${LAMMPS_TOOLS_DIR}/coding_standard/whitespace.py . + WORKING_DIRECTORY ${LAMMPS_DIR} + COMMENT "Check for whitespace errors") + add_custom_target( + fix-whitespace + ${Python3_EXECUTABLE} ${LAMMPS_TOOLS_DIR}/coding_standard/whitespace.py -f . + WORKING_DIRECTORY ${LAMMPS_DIR} + COMMENT "Fix whitespace errors") + endif() endif() From 49982e22bf7044143c7bd72a596df8f5da9c334c Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Sat, 13 Jun 2020 09:54:12 -0400 Subject: [PATCH 11/18] Add check for permissions --- cmake/Modules/CodingStandard.cmake | 10 +++ tools/coding_standard/permissions.py | 118 +++++++++++++++++++++++++++ tools/coding_standard/whitespace.py | 17 ++-- 3 files changed, 137 insertions(+), 8 deletions(-) create mode 100644 tools/coding_standard/permissions.py diff --git a/cmake/Modules/CodingStandard.cmake b/cmake/Modules/CodingStandard.cmake index 467dbb2b16..5a9c0e1dda 100644 --- a/cmake/Modules/CodingStandard.cmake +++ b/cmake/Modules/CodingStandard.cmake @@ -15,10 +15,20 @@ if (Python3_EXECUTABLE) ${Python3_EXECUTABLE} ${LAMMPS_TOOLS_DIR}/coding_standard/whitespace.py . WORKING_DIRECTORY ${LAMMPS_DIR} COMMENT "Check for whitespace errors") + add_custom_target( + check-permissions + ${Python3_EXECUTABLE} ${LAMMPS_TOOLS_DIR}/coding_standard/permissions.py . + WORKING_DIRECTORY ${LAMMPS_DIR} + COMMENT "Check for permission errors") add_custom_target( fix-whitespace ${Python3_EXECUTABLE} ${LAMMPS_TOOLS_DIR}/coding_standard/whitespace.py -f . WORKING_DIRECTORY ${LAMMPS_DIR} COMMENT "Fix whitespace errors") + add_custom_target( + fix-permissions + ${Python3_EXECUTABLE} ${LAMMPS_TOOLS_DIR}/coding_standard/permission.py -f . + WORKING_DIRECTORY ${LAMMPS_DIR} + COMMENT "Fix permission errors") endif() endif() diff --git a/tools/coding_standard/permissions.py b/tools/coding_standard/permissions.py new file mode 100644 index 0000000000..d956aed58c --- /dev/null +++ b/tools/coding_standard/permissions.py @@ -0,0 +1,118 @@ +#!/usr/bin/env python3 +# Utility for detecting and fixing file permission issues in LAMMPS +# +# Written by Richard Berger (Temple University) +import os +import glob +import yaml +import argparse +import stat + +DEFAULT_CONFIG = """ +permission: "rw-r--r--" +recursive: true +include: + - cmake/** + - doc/src/** + - python + - src/** + - examples/** + - tools/coding_standard +patterns: + - "*.c" + - "*.cmake" + - "*.cpp" + - "*.h" + - "*.jpg" + - "*.md" + - "*.pdf" + - "*.png" + - "*.rst" + - "*.tex" + - ".gitignore" + - "README" + - "in.*" + - "requirements.txt" +""" + +def check_permission(path, mask): + st = os.stat(path) + return bool(stat.S_IMODE(st.st_mode) == mask) + +def generate_permission_mask(line): + assert(len(line) == 9) + mask = 0 + + # USER + if line[0] == "r": + mask |= stat.S_IRUSR + if line[1] == "w": + mask |= stat.S_IWUSR + if line[2] == "x": + mask |= stat.S_IXUSR + + # GROUP + if line[3] == "r": + mask |= stat.S_IRGRP + if line[4] == "w": + mask |= stat.S_IWGRP + if line[5] == "x": + mask |= stat.S_IXGRP + + # OTHER + if line[6] == "r": + mask |= stat.S_IROTH + if line[7] == "w": + mask |= stat.S_IWOTH + if line[8] == "x": + mask |= stat.S_IXOTH + + return mask + +def check_folder(directory, config, fix=False, verbose=False): + files = [] + + for base_path in config['include']: + for pattern in config['patterns']: + path = os.path.join(directory, base_path, pattern) + files += glob.glob(path, recursive=config['recursive']) + + mask = generate_permission_mask(config['permission']) + + for f in files: + path = os.path.normpath(f) + + if verbose: + print("Checking file:", path) + + ok = check_permission(path, mask) + + if not ok: + print("[Error] Wrong file permissions @ {}".format(path)) + + if fix: + if os.access(path, os.W_OK): + print("Changing permissions of file {} to '{}'".format(path, config['permission'])) + os.chmod(path, mask) + else: + print("[Error] Can not write permissions of file {}".format(path)) + + +def main(): + parser = argparse.ArgumentParser(description='Utility for detecting and fixing file permission issues in LAMMPS') + parser.add_argument('-c', '--config', metavar='CONFIG_FILE', help='location of a optional configuration file') + parser.add_argument('-f', '--fix', action='store_true', help='automatically fix permissions') + parser.add_argument('-v', '--verbose', action='store_true', help='verbose output') + parser.add_argument('DIRECTORY', help='directory that should be checked') + args = parser.parse_args() + + if args.config: + with open(args.config, 'r') as cfile: + config = yaml.load(cfile, Loader=yaml.FullLoader) + else: + config = yaml.load(DEFAULT_CONFIG, Loader=yaml.FullLoader) + + check_folder(args.DIRECTORY, config, args.fix, args.verbose) + +if __name__ == "__main__": + main() diff --git a/tools/coding_standard/whitespace.py b/tools/coding_standard/whitespace.py index f9923893a0..04246ec704 100644 --- a/tools/coding_standard/whitespace.py +++ b/tools/coding_standard/whitespace.py @@ -17,18 +17,19 @@ include: - doc/src/** - python - src/** + - tools/coding_standard patterns: + - "*.c" + - "*.cmake" + - "*.cpp" + - "*.h" + - "*.md" + - "*.py" + - "*.rst" + - "*.sh" - ".gitignore" - "README" - "requirements.txt" - - "*.c" - - "*.cpp" - - "*.h" - - "*.sh" - - "*.py" - - "*.md" - - "*.rst" - - "*.cmake" """ def check_trailing_whitespace(f): From e840fa23f11cca188c5e0ddc27ce8155ea2e4299 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 15 Jun 2020 11:21:43 -0400 Subject: [PATCH 12/18] Add format-tests target --- cmake/Modules/FindClangFormat.cmake | 46 +++++++++++++++++++++++++++++ unittest/CMakeLists.txt | 10 +++++++ 2 files changed, 56 insertions(+) create mode 100644 cmake/Modules/FindClangFormat.cmake diff --git a/cmake/Modules/FindClangFormat.cmake b/cmake/Modules/FindClangFormat.cmake new file mode 100644 index 0000000000..48393f0614 --- /dev/null +++ b/cmake/Modules/FindClangFormat.cmake @@ -0,0 +1,46 @@ +# Find clang-format +find_program(ClangFormat_EXECUTABLE NAMES clang-format + clang-format-10.0 + clang-format-9.0 + clang-format-8.0 + clang-format-7.0 + clang-format-6.0 + DOC "clang-format executable") +mark_as_advanced(ClangFormat_EXECUTABLE) + +if(ClangFormat_EXECUTABLE) + # find version + execute_process(COMMAND ${ClangFormat_EXECUTABLE} --version + OUTPUT_VARIABLE clang_format_version + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + + + if(clang_format_version MATCHES "^clang-format version .*") + # Arch Linux + # clang-format version 10.0.0 + + # Ubuntu 18.04 LTS Output + # clang-format version 6.0.0-1ubuntu2 (tags/RELEASE_600/final) + string(REGEX REPLACE "clang-format version ([0-9.]+).*" + "\\1" + ClangFormat_VERSION + "${clang_format_version}") + elseif(clang_format_version MATCHES ".*LLVM version .*") + # CentOS 7 Output + # LLVM (http://llvm.org/): + # LLVM version 3.4.2 + # Optimized build. + # Built Nov 1 2018 (15:06:24). + # Default target: x86_64-redhat-linux-gnu + # Host CPU: x86-64 + string(REGEX REPLACE ".*LLVM version ([0-9.]+).*" + "\\1" + ClangFormat_VERSION + "${clang_format_version}") + else() + set(ClangFormat_VERSION "0.0") + endif() +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(ClangFormat REQUIRED_VARS ClangFormat_EXECUTABLE VERSION_VAR ClangFormat_VERSION) diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index 531e943f6c..74a8b24017 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -5,3 +5,13 @@ add_subdirectory(force-styles) add_subdirectory(utils) add_subdirectory(formats) + +find_package(ClangFormat) + +if(ClangFormat_FOUND) + set(UNITTEST_SOURCES) + file(GLOB_RECURSE UNITTEST_SOURCES *.cpp *.h) + add_custom_target(format-tests + COMMAND ${ClangFormat_EXECUTABLE} --verbose -i -style=file ${UNITTEST_SOURCES} + DEPENDS ${UNITTEST_SOURCES}) +endif() From 65ff6bb617fa36cb847b541e8807b1dc1b34856c Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 15 Jun 2020 14:59:43 -0400 Subject: [PATCH 13/18] Require clang-format >= 8.0 --- unittest/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index 74a8b24017..99b5463a81 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -6,7 +6,7 @@ add_subdirectory(utils) add_subdirectory(formats) -find_package(ClangFormat) +find_package(ClangFormat 8.0) if(ClangFormat_FOUND) set(UNITTEST_SOURCES) From 05d1924d62130304bbc3f3b76ead39ef59bf62b5 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 15 Jun 2020 16:48:20 -0400 Subject: [PATCH 14/18] update for using {fmt} --- unittest/force-styles/test_error_stats.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/unittest/force-styles/test_error_stats.cpp b/unittest/force-styles/test_error_stats.cpp index ea0b36cbf7..86cf4f9df2 100644 --- a/unittest/force-styles/test_error_stats.cpp +++ b/unittest/force-styles/test_error_stats.cpp @@ -5,8 +5,9 @@ // include the implementation since ErrorStats is a standalone class // this way we don't have to link against the style_tests and lammps libs - #include "error_stats.cpp" +#include "fmtlib_format.cpp" +#include "fmtlib_os.cpp" TEST(ErrorStats, test) { @@ -25,7 +26,7 @@ TEST(ErrorStats, test) std::stringstream out; out << stats; - ASSERT_EQ(out.str(), " Average: 5.800e-01 StdDev: 7.305e-01 MaxErr: 2.000e+00 @ item: 3"); + ASSERT_EQ(out.str(), " Average: 5.800e-01 StdDev: 7.305e-01 MaxErr: 2.000e+00 @ item: 3.0"); stats.reset(); ASSERT_DOUBLE_EQ(stats.avg(), 0.0); From 05319cae66567dd0230a9b2b5b8c5e934f780c6d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 15 Jun 2020 16:51:31 -0400 Subject: [PATCH 15/18] updates for using {fmt} and reordering of include statements exposing hidden includes --- unittest/force-styles/CMakeLists.txt | 2 ++ unittest/force-styles/test_config_reader.h | 1 + unittest/force-styles/test_error_stats.cpp | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/unittest/force-styles/CMakeLists.txt b/unittest/force-styles/CMakeLists.txt index 7c69ab8087..c7937336f2 100644 --- a/unittest/force-styles/CMakeLists.txt +++ b/unittest/force-styles/CMakeLists.txt @@ -8,6 +8,7 @@ endif() set(TEST_INPUT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/tests) add_library(style_tests STATIC yaml_writer.cpp error_stats.cpp test_config_reader.cpp test_main.cpp) target_compile_definitions(style_tests PRIVATE TEST_INPUT_FOLDER=${TEST_INPUT_FOLDER}) +target_include_directories(style_tests PRIVATE ${LAMMPS_SOURCE_DIR}) target_link_libraries(style_tests PUBLIC GTest::GTest GTest::GMock Yaml::Yaml) if(BUILD_MPI) target_link_libraries(style_tests PUBLIC MPI::MPI_CXX) @@ -17,6 +18,7 @@ endif() # unit test for error stats class add_executable(test_error_stats test_error_stats.cpp) +target_include_directories(test_error_stats PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${LAMMPS_SOURCE_DIR}) target_link_libraries(test_error_stats PRIVATE GTest::GTestMain GTest::GTest) add_test(NAME ErrorStats COMMAND test_error_stats) diff --git a/unittest/force-styles/test_config_reader.h b/unittest/force-styles/test_config_reader.h index 1d7d9b6153..f39706db90 100644 --- a/unittest/force-styles/test_config_reader.h +++ b/unittest/force-styles/test_config_reader.h @@ -14,6 +14,7 @@ #ifndef TEST_CONFIG_READER_H #define TEST_CONFIG_READER_H +#include "test_config.h" #include "yaml_reader.h" class TestConfigReader : public YamlReader { diff --git a/unittest/force-styles/test_error_stats.cpp b/unittest/force-styles/test_error_stats.cpp index 86cf4f9df2..42c185db83 100644 --- a/unittest/force-styles/test_error_stats.cpp +++ b/unittest/force-styles/test_error_stats.cpp @@ -26,7 +26,7 @@ TEST(ErrorStats, test) std::stringstream out; out << stats; - ASSERT_EQ(out.str(), " Average: 5.800e-01 StdDev: 7.305e-01 MaxErr: 2.000e+00 @ item: 3.0"); + ASSERT_EQ(out.str(), "Average: 5.800e-01 StdDev: 7.305e-01 MaxErr: 2.000e+00 @ item: 3.0"); stats.reset(); ASSERT_DOUBLE_EQ(stats.avg(), 0.0); From fd8cfed86d7e92fd5933d8b488e1069711a8a5cd Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 15 Jun 2020 17:33:50 -0400 Subject: [PATCH 16/18] fix typo --- cmake/Modules/CodingStandard.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Modules/CodingStandard.cmake b/cmake/Modules/CodingStandard.cmake index 5a9c0e1dda..72b064af66 100644 --- a/cmake/Modules/CodingStandard.cmake +++ b/cmake/Modules/CodingStandard.cmake @@ -27,7 +27,7 @@ if (Python3_EXECUTABLE) COMMENT "Fix whitespace errors") add_custom_target( fix-permissions - ${Python3_EXECUTABLE} ${LAMMPS_TOOLS_DIR}/coding_standard/permission.py -f . + ${Python3_EXECUTABLE} ${LAMMPS_TOOLS_DIR}/coding_standard/permissions.py -f . WORKING_DIRECTORY ${LAMMPS_DIR} COMMENT "Fix permission errors") endif() From 3abbf57146d2664900701e71863b4b296fb0c380 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 15 Jun 2020 17:34:21 -0400 Subject: [PATCH 17/18] remove executable permissions on files that should not have them --- examples/USER/atc/elastic/in.no_atoms | 0 examples/USER/atc/elastic/in.no_atoms_cb | 0 examples/USER/atc/elastic/in.no_atoms_cb_linear | 0 examples/USER/atc/molecule/in.polarize | 0 examples/USER/dpd/dpdrx-shardlow/in.dpdrx-shardlow | 0 examples/USER/lb/confined_colloid/in.confined_colloids | 0 examples/USER/lb/dragforce/in.defaultgamma_drag | 0 examples/USER/lb/dragforce/in.setgamma_drag | 0 examples/USER/lb/fourspheres/in.fourspheres_default_gamma | 0 examples/USER/lb/fourspheres/in.fourspheres_set_gamma | 0 examples/USER/lb/microrheology/in.microrheology_default_gamma | 0 examples/USER/lb/microrheology/in.microrheology_set_gamma | 0 examples/USER/lb/planewall/in.planewall_default_gamma | 0 examples/USER/lb/planewall/in.planewall_set_gamma | 0 examples/USER/phonon/dynamical_matrix_command/Silicon/README.md | 0 examples/USER/phonon/dynamical_matrix_command/Silicon/in.silicon | 0 examples/USER/phonon/dynamical_matrix_command/python/README.md | 0 17 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 examples/USER/atc/elastic/in.no_atoms mode change 100755 => 100644 examples/USER/atc/elastic/in.no_atoms_cb mode change 100755 => 100644 examples/USER/atc/elastic/in.no_atoms_cb_linear mode change 100755 => 100644 examples/USER/atc/molecule/in.polarize mode change 100755 => 100644 examples/USER/dpd/dpdrx-shardlow/in.dpdrx-shardlow mode change 100755 => 100644 examples/USER/lb/confined_colloid/in.confined_colloids mode change 100755 => 100644 examples/USER/lb/dragforce/in.defaultgamma_drag mode change 100755 => 100644 examples/USER/lb/dragforce/in.setgamma_drag mode change 100755 => 100644 examples/USER/lb/fourspheres/in.fourspheres_default_gamma mode change 100755 => 100644 examples/USER/lb/fourspheres/in.fourspheres_set_gamma mode change 100755 => 100644 examples/USER/lb/microrheology/in.microrheology_default_gamma mode change 100755 => 100644 examples/USER/lb/microrheology/in.microrheology_set_gamma mode change 100755 => 100644 examples/USER/lb/planewall/in.planewall_default_gamma mode change 100755 => 100644 examples/USER/lb/planewall/in.planewall_set_gamma mode change 100755 => 100644 examples/USER/phonon/dynamical_matrix_command/Silicon/README.md mode change 100755 => 100644 examples/USER/phonon/dynamical_matrix_command/Silicon/in.silicon mode change 100755 => 100644 examples/USER/phonon/dynamical_matrix_command/python/README.md diff --git a/examples/USER/atc/elastic/in.no_atoms b/examples/USER/atc/elastic/in.no_atoms old mode 100755 new mode 100644 diff --git a/examples/USER/atc/elastic/in.no_atoms_cb b/examples/USER/atc/elastic/in.no_atoms_cb old mode 100755 new mode 100644 diff --git a/examples/USER/atc/elastic/in.no_atoms_cb_linear b/examples/USER/atc/elastic/in.no_atoms_cb_linear old mode 100755 new mode 100644 diff --git a/examples/USER/atc/molecule/in.polarize b/examples/USER/atc/molecule/in.polarize old mode 100755 new mode 100644 diff --git a/examples/USER/dpd/dpdrx-shardlow/in.dpdrx-shardlow b/examples/USER/dpd/dpdrx-shardlow/in.dpdrx-shardlow old mode 100755 new mode 100644 diff --git a/examples/USER/lb/confined_colloid/in.confined_colloids b/examples/USER/lb/confined_colloid/in.confined_colloids old mode 100755 new mode 100644 diff --git a/examples/USER/lb/dragforce/in.defaultgamma_drag b/examples/USER/lb/dragforce/in.defaultgamma_drag old mode 100755 new mode 100644 diff --git a/examples/USER/lb/dragforce/in.setgamma_drag b/examples/USER/lb/dragforce/in.setgamma_drag old mode 100755 new mode 100644 diff --git a/examples/USER/lb/fourspheres/in.fourspheres_default_gamma b/examples/USER/lb/fourspheres/in.fourspheres_default_gamma old mode 100755 new mode 100644 diff --git a/examples/USER/lb/fourspheres/in.fourspheres_set_gamma b/examples/USER/lb/fourspheres/in.fourspheres_set_gamma old mode 100755 new mode 100644 diff --git a/examples/USER/lb/microrheology/in.microrheology_default_gamma b/examples/USER/lb/microrheology/in.microrheology_default_gamma old mode 100755 new mode 100644 diff --git a/examples/USER/lb/microrheology/in.microrheology_set_gamma b/examples/USER/lb/microrheology/in.microrheology_set_gamma old mode 100755 new mode 100644 diff --git a/examples/USER/lb/planewall/in.planewall_default_gamma b/examples/USER/lb/planewall/in.planewall_default_gamma old mode 100755 new mode 100644 diff --git a/examples/USER/lb/planewall/in.planewall_set_gamma b/examples/USER/lb/planewall/in.planewall_set_gamma old mode 100755 new mode 100644 diff --git a/examples/USER/phonon/dynamical_matrix_command/Silicon/README.md b/examples/USER/phonon/dynamical_matrix_command/Silicon/README.md old mode 100755 new mode 100644 diff --git a/examples/USER/phonon/dynamical_matrix_command/Silicon/in.silicon b/examples/USER/phonon/dynamical_matrix_command/Silicon/in.silicon old mode 100755 new mode 100644 diff --git a/examples/USER/phonon/dynamical_matrix_command/python/README.md b/examples/USER/phonon/dynamical_matrix_command/python/README.md old mode 100755 new mode 100644 From 30100d33c61a3d0000607c756a7744be1f8dc112 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 15 Jun 2020 17:37:45 -0400 Subject: [PATCH 18/18] get rid of tabs and trailing whitespace --- doc/src/Build_development.rst | 4 +- src/USER-AWPMD/README | 2 +- src/USER-CGSDK/README | 2 +- src/USER-DRUDE/README | 6 +-- src/USER-INTEL/TEST/README | 46 +++++++++--------- src/USER-OMP/README | 2 +- src/USER-QTB/README | 88 +++++++++++++++++------------------ src/USER-REAXC/README | 8 ++-- src/USER-UEF/README | 16 +++---- 9 files changed, 87 insertions(+), 87 deletions(-) diff --git a/doc/src/Build_development.rst b/doc/src/Build_development.rst index be86037f61..cf7d8c7955 100644 --- a/doc/src/Build_development.rst +++ b/doc/src/Build_development.rst @@ -95,9 +95,9 @@ The output of this command will be looking something like this:: 25/26 Test #25: AngleStyle:harmonic ................. Passed 0.01 sec Start 26: AngleStyle:zero 26/26 Test #26: AngleStyle:zero ..................... Passed 0.01 sec - + 100% tests passed, 0 tests failed out of 26 - + Total Test time (real) = 0.27 sec diff --git a/src/USER-AWPMD/README b/src/USER-AWPMD/README index 4a853f5059..6d8e8d032d 100644 --- a/src/USER-AWPMD/README +++ b/src/USER-AWPMD/README @@ -16,7 +16,7 @@ installed. The person who created this package is Ilya Valuev at the JIHT in Russia (valuev at physik.hu-berlin.de). Contact him directly if you have questions. - + ---------------------- ACKNOWLEDGMENTS: diff --git a/src/USER-CGSDK/README b/src/USER-CGSDK/README index 535bd43ac1..3d5cae9b20 100644 --- a/src/USER-CGSDK/README +++ b/src/USER-CGSDK/README @@ -25,7 +25,7 @@ recommended over regular pppm. The person who created this package is Axel Kohlmeyer at Temple U (akohlmey at gmail.com). Contact him directly if you have questions. - + --------------------------------- Thanks for contributions, support and testing goes to diff --git a/src/USER-DRUDE/README b/src/USER-DRUDE/README index 0b4913ca5d..3aac41ec7f 100644 --- a/src/USER-DRUDE/README +++ b/src/USER-DRUDE/README @@ -3,7 +3,7 @@ polarizable systems in LAMMPS. The package provides the following features: * tagging particles as cores or Drude particles -* thermostating the Drude oscillators at a distinct temperature +* thermostating the Drude oscillators at a distinct temperature using Langevin or Nosé-Hoover thermostats * computation of the atom and dipole temperatures * damping induced dipole interactions using Thole's function @@ -15,7 +15,7 @@ There are auxiliary tools for using this package in tools/drude. There are example scripts for using this package in examples/USER/drude. The person who created this package is Alain Dequidt at the -Chemistry Institute of Clermont-Ferrand, Clermont University, France +Chemistry Institute of Clermont-Ferrand, Clermont University, France (alain.dequidt at uca.fr). Contact him directly if you have questions. Co-authors: Julien Devémy, Agilio Padua. - + diff --git a/src/USER-INTEL/TEST/README b/src/USER-INTEL/TEST/README index 62602d5920..fdc92b363d 100644 --- a/src/USER-INTEL/TEST/README +++ b/src/USER-INTEL/TEST/README @@ -1,11 +1,11 @@ ############################################################################# # Benchmarks # -# in.intel.lj - Atomic fluid (LJ Benchmark) +# in.intel.lj - Atomic fluid (LJ Benchmark) # in.intel.rhodo - Protein (Rhodopsin Benchmark) -# in.intel.lc - Liquid Crystal w/ Gay-Berne potential -# in.intel.eam - Copper benchmark with Embedded Atom Method -# in.intel.sw - Silicon benchmark with Stillinger-Weber +# in.intel.lc - Liquid Crystal w/ Gay-Berne potential +# in.intel.eam - Copper benchmark with Embedded Atom Method +# in.intel.sw - Silicon benchmark with Stillinger-Weber # in.intel.tersoff - Silicon benchmark with Tersoff # in.intel.water - Coarse-grain water benchmark using Stillinger-Weber # in.intel.airebo - Polyethelene benchmark with AIREBO @@ -18,12 +18,12 @@ # - Compiled w/ Intel Parallel Studio 2017u2 and Makefile.intel_cpu_intelmpi # # Xeon E5-2697v4 Xeon Phi 7250 Xeon Gold 6148 -# +# # in.intel.lj - 199.5 282.3 317.3 # in.intel.rhodo - 12.4 17.5 24.4 -# in.intel.lc - 19.0 25.7 26.8 -# in.intel.eam - 59.4 92.8 105.6 -# in.intel.sw - 132.4 161.9 213.8 +# in.intel.lc - 19.0 25.7 26.8 +# in.intel.eam - 59.4 92.8 105.6 +# in.intel.sw - 132.4 161.9 213.8 # in.intel.tersoff - 83.3 101.1 109.6 # in.intel.water - 53.4 90.3 105.5 # in.intel.airebo - 7.3 11.8 17.6 @@ -33,14 +33,14 @@ ############################################################################# # For Skylake server (Xeon) architectures, see notes in the USER-INTEL/README -# for build flags that should be used. +# for build flags that should be used. ############################################################################# ############################################################################# -# For Haswell (Xeon v3) architectures, depending on the compiler version, -# it may give better performance to compile for an AVX target (with -xAVX -# compiler option) instead of -xHost or -xCORE-AVX2 for some of the -# workloads. In most cases, FMA sensitive routines will still use AVX2 +# For Haswell (Xeon v3) architectures, depending on the compiler version, +# it may give better performance to compile for an AVX target (with -xAVX +# compiler option) instead of -xHost or -xCORE-AVX2 for some of the +# workloads. In most cases, FMA sensitive routines will still use AVX2 # (MKL and SVML detect the processor at runtime). For Broadwell (Xeon v4) # architectures, -xCORE-AVX2 or -xHost will work best for all. ############################################################################# @@ -50,40 +50,40 @@ # the Intel package. You can specify a multiplier for all of the benchmarks # to increase or decrease the runtime. Example commandline arguments: # -# -v m 2 # Run for twice as long -# -v m 0.5 # Run for half as long +# -v m 2 # Run for twice as long +# -v m 0.5 # Run for half as long ############################################################################# ############################################################################# # The LAMMPS newton setting can be controlled from the commandline for the # benchmarks with the N variable: # -# -v N on # newton on -# -v N off # newton off +# -v N on # newton on +# -v N off # newton off # # The default is on for all of the benchmarks except for LJ where the off # setting performs best with the USER-INTEL package ############################################################################# -# Example for running benchmarks (see run_benchmarks.sh for script): +# Example for running benchmarks (see run_benchmarks.sh for script): -# Number of physical cores per node not including hyperthreads +# Number of physical cores per node not including hyperthreads export LMP_CORES=28 # If hyperthreading is enabled, number of hyperthreads to use per core # (2 for Xeon; 2 or 4 for Xeon Phi) export OMP_NUM_THREADS=2 - + # Name of the LAMMPS binary export LMP_BIN=../../lmp_intel_cpu # LAMMPS root directory export LMP_ROOT=../../../ - + source source /opt/intel/parallel_studio_xe_2017.2.050/psxevars.sh export KMP_BLOCKTIME=0 export I_MPI_PIN_DOMAIN=core -export I_MPI_FABRICS=shm # For single node +export I_MPI_FABRICS=shm # For single node # ONLY FOR INTEL XEON PHI x200 SERIES PROCESSORS export I_MPI_SHM_LMT=shm @@ -121,7 +121,7 @@ mpirun -np $LMP_CORES $LMP_BIN -in $bench -log none -pk intel 0 -sf intel mpirun -np $LMP_CORES $LMP_BIN -in $bench -log none -pk intel 1 -sf intel ############################################################################# -# If using PPPM (e.g. in.intel.rhodo) on Intel Xeon Phi x200 series +# If using PPPM (e.g. in.intel.rhodo) on Intel Xeon Phi x200 series # or Skylake processors ############################################################################# export KMP_AFFINITY=none diff --git a/src/USER-OMP/README b/src/USER-OMP/README index 0aef853bca..e1ca2ae99b 100644 --- a/src/USER-OMP/README +++ b/src/USER-OMP/README @@ -1,7 +1,7 @@ This package provides OpenMP multi-threading support and other optimizations of various LAMMPS pair styles, dihedral styles, and fix styles. - + See this section of the manual to get started: doc/Section_accelerate.html, sub-section 5.2 diff --git a/src/USER-QTB/README b/src/USER-QTB/README index cc81a2bca5..3b2b399d49 100644 --- a/src/USER-QTB/README +++ b/src/USER-QTB/README @@ -1,56 +1,56 @@ -This package contains 2 fix commands, "fix qtb" and +This package contains 2 fix commands, "fix qtb" and "fix qbmsst" which involve quantum nuclear effects. -What is quantum nuclear effects (in molecular dynamics +What is quantum nuclear effects (in molecular dynamics simulation)? - Quantum treatment of the vibrational modes will - introduce zero point energy into the system, alter - the energy power spectrum and bias the heat capacity - from the classical limit. classical MD leaves out - these effects completely and thus need to be corrected. - -When should I consider quantum nuclear effects in -my simulation? - (1) When you want to model systems at temperatures - lower than their classical limits. This is especially - important for materials with a large population of - hydrogen atoms and thus higher classical limits. + Quantum treatment of the vibrational modes will + introduce zero point energy into the system, alter + the energy power spectrum and bias the heat capacity + from the classical limit. classical MD leaves out + these effects completely and thus need to be corrected. - (2) In MD simulations when temperatures ramp up - across (or starting from somewhere close to) the - classical limits, tiny differences between the - classical and quantum heat capacity can accumulate - and cause the final state to deviate (could be as - large as 30 %). +When should I consider quantum nuclear effects in +my simulation? + (1) When you want to model systems at temperatures + lower than their classical limits. This is especially + important for materials with a large population of + hydrogen atoms and thus higher classical limits. + + (2) In MD simulations when temperatures ramp up + across (or starting from somewhere close to) the + classical limits, tiny differences between the + classical and quantum heat capacity can accumulate + and cause the final state to deviate (could be as + large as 30 %). What command should I use regarding these two cases? - (1) "fix qtb" provides quantum nulcear correction - through a colored thermostat and can be used with - other time integration schemes like fix nve or - fix nph. In this case, you tell "fix qtb" the temperature - and the other time integration scheme either the - pressure ("fix nph") or the volume ("fix nve"). + (1) "fix qtb" provides quantum nulcear correction + through a colored thermostat and can be used with + other time integration schemes like fix nve or + fix nph. In this case, you tell "fix qtb" the temperature + and the other time integration scheme either the + pressure ("fix nph") or the volume ("fix nve"). - (2) "fix qbmsst" deals with shock MD simulations - in which cases the temperature may increase a lot. - It enables quantum nuclear correction of a multi-scale - shock technique simulation by coupling the quantum - thermal bath with the shocked system. It is an independent - command from "fix msst" and does not assume that - the SHOCK package has been installed. + (2) "fix qbmsst" deals with shock MD simulations + in which cases the temperature may increase a lot. + It enables quantum nuclear correction of a multi-scale + shock technique simulation by coupling the quantum + thermal bath with the shocked system. It is an independent + command from "fix msst" and does not assume that + the SHOCK package has been installed. - See the doc page for the fix qtb and fix qbmsst - command for detailed usage instructions. + See the doc page for the fix qtb and fix qbmsst + command for detailed usage instructions. Where can I find examples of these two commands? - There are example scripts for using this package in - examples/USER/qtb, including one "fix qtb" and one - "fix qbmsst" example for each of alpha quartz and - methane. Running the alpha quartz example requires - installation of the kspace package while the methane - example requires the REAX package for the force field. + There are example scripts for using this package in + examples/USER/qtb, including one "fix qtb" and one + "fix qbmsst" example for each of alpha quartz and + methane. Running the alpha quartz example requires + installation of the kspace package while the methane + example requires the REAX package for the force field. Authors Information and Contact - The person who created this package is Yuan Shen - (sy0302 at stanford.edu) at Stanford University. - Contact him directly if you have questions. + The person who created this package is Yuan Shen + (sy0302 at stanford.edu) at Stanford University. + Contact him directly if you have questions. diff --git a/src/USER-REAXC/README b/src/USER-REAXC/README index 86803957b8..d21fbb791d 100644 --- a/src/USER-REAXC/README +++ b/src/USER-REAXC/README @@ -53,14 +53,14 @@ The reaxc files in this directory have the following header: H. M. Aktulga, J. C. Fogarty, S. A. Pandit, A. Y. Grama, "Parallel Reactive Molecular Dynamics: Numerical Methods and Algorithmic Techniques", Parallel Computing, in press. - + This program 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 2 of + published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program 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. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details: . diff --git a/src/USER-UEF/README b/src/USER-UEF/README index 92b2cee5e3..2f2b872d3b 100644 --- a/src/USER-UEF/README +++ b/src/USER-UEF/README @@ -1,11 +1,11 @@ USER-UEF is a LAMMPS package for non-equilibrium molecular dynamics -(NEMD) under diagonal flow fields, including uniaxial and biaxial -flow. With this package, simulations under extensional flow may be +(NEMD) under diagonal flow fields, including uniaxial and biaxial +flow. With this package, simulations under extensional flow may be carried out for an indefinite amount of time. It is an implementation of the boundary conditions developed by Matthew Dobson, and also uses -numerical lattice reduction as was proposed by Thomas Hunt. The -lattice reduction algorithm is from Igor Semaev. The package is -intended for simulations of homogeneous flows, and integrates the +numerical lattice reduction as was proposed by Thomas Hunt. The +lattice reduction algorithm is from Igor Semaev. The package is +intended for simulations of homogeneous flows, and integrates the SLLOD equations of motion. -- @@ -19,7 +19,7 @@ The following commands are contained in this package: fix npt/uef and fix nvt/uef: These commands perform time-integration of the SLLOD equations of - motion under constant temperature/pressure with the proper + motion under constant temperature/pressure with the proper boundary conditions for extensional flow fields. compute pressure/uef and compute temp/uef: @@ -29,8 +29,8 @@ compute pressure/uef and compute temp/uef: dump cfg/uef: This command dumps coordinates in the reference frame corresponding to the applied flow field. - -For more information, visit the documentation page for fix nvt/uef + +For more information, visit the documentation page for fix nvt/uef and examine the example scripts in doc/USER/uef/. --