Merge branch 'master' into chem_snap

This commit is contained in:
Axel Kohlmeyer
2020-06-16 05:06:11 -04:00
55 changed files with 2075 additions and 1719 deletions

View File

@ -684,6 +684,7 @@ endif()
include(Testing) include(Testing)
include(CodeCoverage) include(CodeCoverage)
include(CodingStandard)
############################################################################### ###############################################################################
# Print package summary # Print package summary

View File

@ -0,0 +1,34 @@
if(CMAKE_VERSION VERSION_LESS 3.12)
find_package(PythonInterp 3.5 QUIET) # Deprecated since version 3.12
if(PYTHONINTERP_FOUND)
set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE})
set(Python3_VERSION ${PYTHON_VERSION_STRING})
endif()
else()
find_package(Python3 COMPONENTS Interpreter QUIET)
endif()
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(
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/permissions.py -f .
WORKING_DIRECTORY ${LAMMPS_DIR}
COMMENT "Fix permission errors")
endif()
endif()

View File

@ -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)

View File

@ -1,4 +1,4 @@
.TH LAMMPS "2 June 2020" "2020-06-02" .TH LAMMPS "15 June 2020" "2020-06-15"
.SH NAME .SH NAME
.B LAMMPS .B LAMMPS
\- Molecular Dynamics Simulator. \- Molecular Dynamics Simulator.

0
examples/USER/atc/elastic/in.no_atoms Executable file → Normal file
View File

0
examples/USER/atc/elastic/in.no_atoms_cb Executable file → Normal file
View File

0
examples/USER/atc/elastic/in.no_atoms_cb_linear Executable file → Normal file
View File

0
examples/USER/atc/molecule/in.polarize Executable file → Normal file
View File

0
examples/USER/dpd/dpdrx-shardlow/in.dpdrx-shardlow Executable file → Normal file
View File

0
examples/USER/lb/confined_colloid/in.confined_colloids Executable file → Normal file
View File

0
examples/USER/lb/dragforce/in.defaultgamma_drag Executable file → Normal file
View File

0
examples/USER/lb/dragforce/in.setgamma_drag Executable file → Normal file
View File

View File

0
examples/USER/lb/fourspheres/in.fourspheres_set_gamma Executable file → Normal file
View File

View File

View File

0
examples/USER/lb/planewall/in.planewall_default_gamma Executable file → Normal file
View File

0
examples/USER/lb/planewall/in.planewall_set_gamma Executable file → Normal file
View File

View File

View File

View File

View File

@ -1 +1 @@
#define LAMMPS_VERSION "2 Jun 2020" #define LAMMPS_VERSION "15 Jun 2020"

View File

@ -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()

View File

@ -0,0 +1,133 @@
#!/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/**
- tools/coding_standard
patterns:
- "*.c"
- "*.cmake"
- "*.cpp"
- "*.h"
- "*.md"
- "*.py"
- "*.rst"
- "*.sh"
- ".gitignore"
- "README"
- "requirements.txt"
"""
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()

23
unittest/.clang-format Normal file
View File

@ -0,0 +1,23 @@
---
Language: Cpp
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignConsecutiveAssignments: true
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
...

View File

@ -5,3 +5,13 @@ add_subdirectory(force-styles)
add_subdirectory(utils) add_subdirectory(utils)
add_subdirectory(formats) add_subdirectory(formats)
find_package(ClangFormat 8.0)
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()

View File

@ -8,6 +8,7 @@ endif()
set(TEST_INPUT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/tests) 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) 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_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) target_link_libraries(style_tests PUBLIC GTest::GTest GTest::GMock Yaml::Yaml)
if(BUILD_MPI) if(BUILD_MPI)
target_link_libraries(style_tests PUBLIC MPI::MPI_CXX) target_link_libraries(style_tests PUBLIC MPI::MPI_CXX)
@ -17,6 +18,7 @@ endif()
# unit test for error stats class # unit test for error stats class
add_executable(test_error_stats test_error_stats.cpp) 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) target_link_libraries(test_error_stats PRIVATE GTest::GTestMain GTest::GTest)
add_test(NAME ErrorStats COMMAND test_error_stats) add_test(NAME ErrorStats COMMAND test_error_stats)

View File

@ -13,32 +13,32 @@
// unit tests for angle styles intended for molecular systems // unit tests for angle styles intended for molecular systems
#include "yaml_reader.h"
#include "yaml_writer.h"
#include "error_stats.h" #include "error_stats.h"
#include "test_config.h" #include "test_config.h"
#include "test_config_reader.h" #include "test_config_reader.h"
#include "test_main.h" #include "test_main.h"
#include "yaml_reader.h"
#include "yaml_writer.h"
#include "gtest/gtest.h"
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "lammps.h" #include "angle.h"
#include "atom.h" #include "atom.h"
#include "modify.h"
#include "compute.h" #include "compute.h"
#include "force.h" #include "force.h"
#include "angle.h"
#include "info.h" #include "info.h"
#include "input.h" #include "input.h"
#include "lammps.h"
#include "modify.h"
#include "universe.h" #include "universe.h"
#include <mpi.h>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype> #include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime> #include <ctime>
#include <mpi.h>
#include <iostream> #include <iostream>
#include <map> #include <map>
@ -46,12 +46,13 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
using ::testing::StartsWith;
using ::testing::HasSubstr; using ::testing::HasSubstr;
using ::testing::StartsWith;
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
static void delete_file(const std::string & filename) { static void delete_file(const std::string &filename)
{
remove(filename.c_str()); remove(filename.c_str());
}; };
@ -63,9 +64,7 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg)
delete lmp; delete lmp;
} }
LAMMPS *init_lammps(int argc, char **argv, LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool newton = true)
const TestConfig &cfg,
const bool newton=true)
{ {
LAMMPS *lmp; LAMMPS *lmp;
@ -164,8 +163,7 @@ void restart_lammps(LAMMPS *lmp, const TestConfig &cfg)
command("angle_style " + cfg.angle_style); command("angle_style " + cfg.angle_style);
} }
if ((cfg.angle_style.substr(0,6) == "hybrid") if ((cfg.angle_style.substr(0, 6) == "hybrid") || !lmp->force->angle->writedata) {
|| !lmp->force->angle->writedata) {
for (auto &angle_coeff : cfg.angle_coeff) { for (auto &angle_coeff : cfg.angle_coeff) {
command("angle_coeff " + angle_coeff); command("angle_coeff " + angle_coeff);
} }
@ -219,6 +217,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
{ {
// initialize system geometry // 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; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = sizeof(args) / sizeof(char *);
LAMMPS *lmp = init_lammps(argc, argv, config); LAMMPS *lmp = init_lammps(argc, argv, config);
@ -226,8 +225,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
std::cerr << "One or more prerequisite styles are not available " 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) { for (auto &prerequisite : config.prerequisites) {
std::cerr << prerequisite.first << "_style " std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n";
<< prerequisite.second << "\n";
} }
return; return;
} }
@ -309,8 +307,8 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
// init_stress // init_stress
double *stress = lmp->force->angle->virial; double *stress = lmp->force->angle->virial;
snprintf(buf,bufsize,"% 23.16e % 23.16e % 23.16e % 23.16e % 23.16e % 23.16e", snprintf(buf, bufsize, "% 23.16e % 23.16e % 23.16e % 23.16e % 23.16e % 23.16e", stress[0],
stress[0],stress[1],stress[2],stress[3],stress[4],stress[5]); stress[1], stress[2], stress[3], stress[4], stress[5]);
writer.emit_block("init_stress", buf); writer.emit_block("init_stress", buf);
// init_forces // init_forces
@ -318,8 +316,8 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
double **f = lmp->atom->f; double **f = lmp->atom->f;
tagint *tag = lmp->atom->tag; tagint *tag = lmp->atom->tag;
for (int i = 0; i < natoms; ++i) { for (int i = 0; i < natoms; ++i) {
snprintf(buf,bufsize,"% 3d % 23.16e % 23.16e % 23.16e\n", snprintf(buf, bufsize, "% 3d % 23.16e % 23.16e % 23.16e\n", (int)tag[i], f[i][0], f[i][1],
(int)tag[i], f[i][0], f[i][1], f[i][2]); f[i][2]);
block += buf; block += buf;
} }
writer.emit_block("init_forces", block); writer.emit_block("init_forces", block);
@ -332,16 +330,16 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
// run_stress // run_stress
stress = lmp->force->angle->virial; stress = lmp->force->angle->virial;
snprintf(buf,bufsize,"% 23.16e % 23.16e % 23.16e % 23.16e % 23.16e % 23.16e", snprintf(buf, bufsize, "% 23.16e % 23.16e % 23.16e % 23.16e % 23.16e % 23.16e", stress[0],
stress[0],stress[1],stress[2],stress[3],stress[4],stress[5]); stress[1], stress[2], stress[3], stress[4], stress[5]);
writer.emit_block("run_stress", buf); writer.emit_block("run_stress", buf);
block.clear(); block.clear();
f = lmp->atom->f; f = lmp->atom->f;
tag = lmp->atom->tag; tag = lmp->atom->tag;
for (int i = 0; i < natoms; ++i) { for (int i = 0; i < natoms; ++i) {
snprintf(buf,bufsize,"% 3d % 23.16e % 23.16e % 23.16e\n", snprintf(buf, bufsize, "% 3d % 23.16e % 23.16e % 23.16e\n", (int)tag[i], f[i][0], f[i][1],
(int)tag[i], f[i][0], f[i][1], f[i][2]); f[i][2]);
block += buf; block += buf;
} }
writer.emit_block("run_forces", block); writer.emit_block("run_forces", block);
@ -350,13 +348,16 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
return; return;
} }
TEST(AngleStyle, plain) { TEST(AngleStyle, plain)
{
const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"}; const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout(); ::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(); std::string output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;
@ -364,8 +365,7 @@ TEST(AngleStyle, plain) {
std::cerr << "One or more prerequisite styles are not available " 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) { for (auto &prerequisite : test_config.prerequisites) {
std::cerr << prerequisite.first << "_style " std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n";
<< prerequisite.second << "\n";
} }
GTEST_SKIP(); GTEST_SKIP();
} }
@ -389,8 +389,7 @@ TEST(AngleStyle, plain) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl;
std::cerr << "init_forces stats, newton on: " << stats << std::endl;
Angle *angle = lmp->force->angle; Angle *angle = lmp->force->angle;
double *stress = angle->virial; double *stress = angle->virial;
@ -401,13 +400,11 @@ TEST(AngleStyle, plain) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); 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[4], test_config.init_stress.xz, epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon);
if (print_stats) if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl;
std::cerr << "init_stress stats, newton on: " << stats << std::endl;
stats.reset(); stats.reset();
EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon);
if (print_stats) if (print_stats) std::cerr << "init_energy stats, newton on: " << stats << std::endl;
std::cerr << "init_energy stats, newton on: " << stats << std::endl;
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
run_lammps(lmp); run_lammps(lmp);
@ -423,8 +420,7 @@ TEST(AngleStyle, plain) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl;
std::cerr << "run_forces stats, newton on: " << stats << std::endl;
stress = angle->virial; stress = angle->virial;
stats.reset(); stats.reset();
@ -434,16 +430,14 @@ TEST(AngleStyle, plain) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); 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[4], test_config.run_stress.xz, epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon);
if (print_stats) if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl;
std::cerr << "run_stress stats, newton on: " << stats << std::endl;
stats.reset(); stats.reset();
int id = lmp->modify->find_compute("sum"); int id = lmp->modify->find_compute("sum");
double energy = lmp->modify->compute[id]->compute_scalar(); 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, test_config.run_energy, epsilon);
EXPECT_FP_LE_WITH_EPS(angle->energy, energy, epsilon); EXPECT_FP_LE_WITH_EPS(angle->energy, energy, epsilon);
if (print_stats) if (print_stats) std::cerr << "run_energy stats, newton on: " << stats << std::endl;
std::cerr << "run_energy stats, newton on: " << stats << std::endl;
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
cleanup_lammps(lmp, test_config); cleanup_lammps(lmp, test_config);
@ -461,8 +455,7 @@ TEST(AngleStyle, plain) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl;
std::cerr << "init_forces stats, newton off:" << stats << std::endl;
angle = lmp->force->angle; angle = lmp->force->angle;
stress = angle->virial; stress = angle->virial;
@ -473,13 +466,11 @@ TEST(AngleStyle, plain) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 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[4], test_config.init_stress.xz, 2 * epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 2 * epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 2 * epsilon);
if (print_stats) if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl;
std::cerr << "init_stress stats, newton off:" << stats << std::endl;
stats.reset(); stats.reset();
EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon);
if (print_stats) if (print_stats) std::cerr << "init_energy stats, newton off:" << stats << std::endl;
std::cerr << "init_energy stats, newton off:" << stats << std::endl;
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
run_lammps(lmp); run_lammps(lmp);
@ -493,8 +484,7 @@ TEST(AngleStyle, plain) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl;
std::cerr << "run_forces stats, newton off:" << stats << std::endl;
stress = angle->virial; stress = angle->virial;
stats.reset(); stats.reset();
@ -504,16 +494,14 @@ TEST(AngleStyle, plain) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); 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[4], test_config.run_stress.xz, epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon);
if (print_stats) if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl;
std::cerr << "run_stress stats, newton off:" << stats << std::endl;
stats.reset(); stats.reset();
id = lmp->modify->find_compute("sum"); id = lmp->modify->find_compute("sum");
energy = lmp->modify->compute[id]->compute_scalar(); 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, test_config.run_energy, epsilon);
EXPECT_FP_LE_WITH_EPS(angle->energy, energy, epsilon); EXPECT_FP_LE_WITH_EPS(angle->energy, energy, epsilon);
if (print_stats) if (print_stats) std::cerr << "run_energy stats, newton off:" << stats << std::endl;
std::cerr << "run_energy stats, newton off:" << stats << std::endl;
} }
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
@ -529,8 +517,7 @@ TEST(AngleStyle, plain) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "restart_forces stats:" << stats << std::endl;
std::cerr << "restart_forces stats:" << stats << std::endl;
angle = lmp->force->angle; angle = lmp->force->angle;
stress = angle->virial; stress = angle->virial;
@ -541,13 +528,11 @@ TEST(AngleStyle, plain) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); 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[4], test_config.init_stress.xz, epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon);
if (print_stats) if (print_stats) std::cerr << "restart_stress stats:" << stats << std::endl;
std::cerr << "restart_stress stats:" << stats << std::endl;
stats.reset(); stats.reset();
EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon);
if (print_stats) if (print_stats) std::cerr << "restart_energy stats:" << stats << std::endl;
std::cerr << "restart_energy stats:" << stats << std::endl;
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
data_lammps(lmp, test_config); data_lammps(lmp, test_config);
@ -562,8 +547,7 @@ TEST(AngleStyle, plain) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "data_forces stats:" << stats << std::endl;
std::cerr << "data_forces stats:" << stats << std::endl;
angle = lmp->force->angle; angle = lmp->force->angle;
stress = angle->virial; stress = angle->virial;
@ -574,28 +558,29 @@ TEST(AngleStyle, plain) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); 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[4], test_config.init_stress.xz, epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon);
if (print_stats) if (print_stats) std::cerr << "data_stress stats:" << stats << std::endl;
std::cerr << "data_stress stats:" << stats << std::endl;
stats.reset(); stats.reset();
EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon);
if (print_stats) if (print_stats) std::cerr << "data_energy stats:" << stats << std::endl;
std::cerr << "data_energy stats:" << stats << std::endl;
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
cleanup_lammps(lmp, test_config); cleanup_lammps(lmp, test_config);
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
}; };
TEST(AngleStyle, omp) { TEST(AngleStyle, omp)
{
if (!LAMMPS::is_installed_pkg("USER-OMP")) GTEST_SKIP(); if (!LAMMPS::is_installed_pkg("USER-OMP")) GTEST_SKIP();
const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite",
"-nocite", "-pk", "omp", "4", "-sf", "omp"}; "-pk", "omp", "4", "-sf", "omp"};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout(); ::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(); std::string output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;
@ -603,8 +588,7 @@ TEST(AngleStyle, omp) {
std::cerr << "One or more prerequisite styles with /omp suffix\n" 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) { for (auto &prerequisite : test_config.prerequisites) {
std::cerr << prerequisite.first << "_style " std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n";
<< prerequisite.second << "\n";
} }
GTEST_SKIP(); GTEST_SKIP();
} }
@ -628,8 +612,7 @@ TEST(AngleStyle, omp) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl;
std::cerr << "init_forces stats, newton on: " << stats << std::endl;
Angle *angle = lmp->force->angle; Angle *angle = lmp->force->angle;
double *stress = angle->virial; double *stress = angle->virial;
@ -641,13 +624,11 @@ TEST(AngleStyle, omp) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 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[4], test_config.init_stress.xz, 10 * epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon);
if (print_stats) if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl;
std::cerr << "init_stress stats, newton on: " << stats << std::endl;
stats.reset(); stats.reset();
EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon);
if (print_stats) if (print_stats) std::cerr << "init_energy stats, newton on: " << stats << std::endl;
std::cerr << "init_energy stats, newton on: " << stats << std::endl;
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
run_lammps(lmp); run_lammps(lmp);
@ -663,8 +644,7 @@ TEST(AngleStyle, omp) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl;
std::cerr << "run_forces stats, newton on: " << stats << std::endl;
stress = angle->virial; stress = angle->virial;
stats.reset(); stats.reset();
@ -674,8 +654,7 @@ TEST(AngleStyle, omp) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 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[4], test_config.run_stress.xz, 10 * epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon);
if (print_stats) if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl;
std::cerr << "run_stress stats, newton on: " << stats << std::endl;
stats.reset(); stats.reset();
int id = lmp->modify->find_compute("sum"); int id = lmp->modify->find_compute("sum");
@ -685,8 +664,7 @@ TEST(AngleStyle, omp) {
// needs to be fixed in the main code somewhere. Not sure where, though. // 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); EXPECT_FP_LE_WITH_EPS(angle->energy, energy, epsilon);
if (print_stats) if (print_stats) std::cerr << "run_energy stats, newton on: " << stats << std::endl;
std::cerr << "run_energy stats, newton on: " << stats << std::endl;
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
cleanup_lammps(lmp, test_config); cleanup_lammps(lmp, test_config);
@ -704,8 +682,7 @@ TEST(AngleStyle, omp) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl;
std::cerr << "init_forces stats, newton off:" << stats << std::endl;
angle = lmp->force->angle; angle = lmp->force->angle;
stress = angle->virial; stress = angle->virial;
@ -716,13 +693,11 @@ TEST(AngleStyle, omp) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 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[4], test_config.init_stress.xz, 10 * epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon);
if (print_stats) if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl;
std::cerr << "init_stress stats, newton off:" << stats << std::endl;
stats.reset(); stats.reset();
EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon);
if (print_stats) if (print_stats) std::cerr << "init_energy stats, newton off:" << stats << std::endl;
std::cerr << "init_energy stats, newton off:" << stats << std::endl;
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
run_lammps(lmp); run_lammps(lmp);
@ -735,8 +710,7 @@ TEST(AngleStyle, omp) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl;
std::cerr << "run_forces stats, newton off:" << stats << std::endl;
stress = angle->virial; stress = angle->virial;
stats.reset(); stats.reset();
@ -746,8 +720,7 @@ TEST(AngleStyle, omp) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 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[4], test_config.run_stress.xz, 10 * epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon);
if (print_stats) if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl;
std::cerr << "run_stress stats, newton off:" << stats << std::endl;
stats.reset(); stats.reset();
id = lmp->modify->find_compute("sum"); id = lmp->modify->find_compute("sum");
@ -757,8 +730,7 @@ TEST(AngleStyle, omp) {
// needs to be fixed in the main code somewhere. Not sure where, though. // 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); EXPECT_FP_LE_WITH_EPS(angle->energy, energy, epsilon);
if (print_stats) if (print_stats) std::cerr << "run_energy stats, newton off:" << stats << std::endl;
std::cerr << "run_energy stats, newton off:" << stats << std::endl;
} }
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
@ -766,8 +738,10 @@ TEST(AngleStyle, omp) {
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
}; };
TEST(AngleStyle, single) { TEST(AngleStyle, single)
{
const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"}; const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = sizeof(args) / sizeof(char *);
@ -780,8 +754,7 @@ TEST(AngleStyle, single) {
std::cerr << "One or more prerequisite styles are not available " 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) { for (auto &prerequisite : test_config.prerequisites) {
std::cerr << prerequisite.first << "_style " std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n";
<< prerequisite.second << "\n";
} }
GTEST_SKIP(); GTEST_SKIP();
} }
@ -904,8 +877,7 @@ TEST(AngleStyle, single) {
EXPECT_FP_LE_WITH_EPS(eangle[1], esingle[1], epsilon); 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[2], esingle[2], epsilon);
EXPECT_FP_LE_WITH_EPS(eangle[3], esingle[3], epsilon); EXPECT_FP_LE_WITH_EPS(eangle[3], esingle[3], epsilon);
if (print_stats) if (print_stats) std::cerr << "single_energy stats:" << stats << std::endl;
std::cerr << "single_energy stats:" << stats << std::endl;
int i = 0; int i = 0;
for (auto &dist : test_config.equilibrium) for (auto &dist : test_config.equilibrium)

View File

@ -13,32 +13,32 @@
// unit tests for bond styles intended for molecular systems // unit tests for bond styles intended for molecular systems
#include "yaml_reader.h"
#include "yaml_writer.h"
#include "error_stats.h" #include "error_stats.h"
#include "test_config.h" #include "test_config.h"
#include "test_config_reader.h" #include "test_config_reader.h"
#include "test_main.h" #include "test_main.h"
#include "yaml_reader.h"
#include "yaml_writer.h"
#include "gtest/gtest.h"
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "lammps.h"
#include "atom.h" #include "atom.h"
#include "modify.h" #include "bond.h"
#include "compute.h" #include "compute.h"
#include "force.h" #include "force.h"
#include "bond.h"
#include "info.h" #include "info.h"
#include "input.h" #include "input.h"
#include "lammps.h"
#include "modify.h"
#include "universe.h" #include "universe.h"
#include <mpi.h>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype> #include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime> #include <ctime>
#include <mpi.h>
#include <iostream> #include <iostream>
#include <map> #include <map>
@ -46,12 +46,13 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
using ::testing::StartsWith;
using ::testing::HasSubstr; using ::testing::HasSubstr;
using ::testing::StartsWith;
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
static void delete_file(const std::string & filename) { static void delete_file(const std::string &filename)
{
remove(filename.c_str()); remove(filename.c_str());
}; };
@ -63,9 +64,7 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg)
delete lmp; delete lmp;
} }
LAMMPS *init_lammps(int argc, char **argv, LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool newton = true)
const TestConfig &cfg,
const bool newton=true)
{ {
LAMMPS *lmp; LAMMPS *lmp;
@ -164,8 +163,7 @@ void restart_lammps(LAMMPS *lmp, const TestConfig &cfg)
command("bond_style " + cfg.bond_style); command("bond_style " + cfg.bond_style);
} }
if ((cfg.bond_style.substr(0,6) == "hybrid") if ((cfg.bond_style.substr(0, 6) == "hybrid") || !lmp->force->bond->writedata) {
|| !lmp->force->bond->writedata) {
for (auto &bond_coeff : cfg.bond_coeff) { for (auto &bond_coeff : cfg.bond_coeff) {
command("bond_coeff " + bond_coeff); command("bond_coeff " + bond_coeff);
} }
@ -219,6 +217,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
{ {
// initialize system geometry // 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; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = sizeof(args) / sizeof(char *);
LAMMPS *lmp = init_lammps(argc, argv, config); LAMMPS *lmp = init_lammps(argc, argv, config);
@ -226,8 +225,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
std::cerr << "One or more prerequisite styles are not available " 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) { for (auto &prerequisite : config.prerequisites) {
std::cerr << prerequisite.first << "_style " std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n";
<< prerequisite.second << "\n";
} }
return; return;
} }
@ -309,8 +307,8 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
// init_stress // init_stress
double *stress = lmp->force->bond->virial; double *stress = lmp->force->bond->virial;
snprintf(buf,bufsize,"% 23.16e % 23.16e % 23.16e % 23.16e % 23.16e % 23.16e", snprintf(buf, bufsize, "% 23.16e % 23.16e % 23.16e % 23.16e % 23.16e % 23.16e", stress[0],
stress[0],stress[1],stress[2],stress[3],stress[4],stress[5]); stress[1], stress[2], stress[3], stress[4], stress[5]);
writer.emit_block("init_stress", buf); writer.emit_block("init_stress", buf);
// init_forces // init_forces
@ -318,8 +316,8 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
double **f = lmp->atom->f; double **f = lmp->atom->f;
tagint *tag = lmp->atom->tag; tagint *tag = lmp->atom->tag;
for (int i = 0; i < natoms; ++i) { for (int i = 0; i < natoms; ++i) {
snprintf(buf,bufsize,"% 3d % 23.16e % 23.16e % 23.16e\n", snprintf(buf, bufsize, "% 3d % 23.16e % 23.16e % 23.16e\n", (int)tag[i], f[i][0], f[i][1],
(int)tag[i], f[i][0], f[i][1], f[i][2]); f[i][2]);
block += buf; block += buf;
} }
writer.emit_block("init_forces", block); writer.emit_block("init_forces", block);
@ -332,16 +330,16 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
// run_stress // run_stress
stress = lmp->force->bond->virial; stress = lmp->force->bond->virial;
snprintf(buf,bufsize,"% 23.16e % 23.16e % 23.16e % 23.16e % 23.16e % 23.16e", snprintf(buf, bufsize, "% 23.16e % 23.16e % 23.16e % 23.16e % 23.16e % 23.16e", stress[0],
stress[0],stress[1],stress[2],stress[3],stress[4],stress[5]); stress[1], stress[2], stress[3], stress[4], stress[5]);
writer.emit_block("run_stress", buf); writer.emit_block("run_stress", buf);
block.clear(); block.clear();
f = lmp->atom->f; f = lmp->atom->f;
tag = lmp->atom->tag; tag = lmp->atom->tag;
for (int i = 0; i < natoms; ++i) { for (int i = 0; i < natoms; ++i) {
snprintf(buf,bufsize,"% 3d % 23.16e % 23.16e % 23.16e\n", snprintf(buf, bufsize, "% 3d % 23.16e % 23.16e % 23.16e\n", (int)tag[i], f[i][0], f[i][1],
(int)tag[i], f[i][0], f[i][1], f[i][2]); f[i][2]);
block += buf; block += buf;
} }
writer.emit_block("run_forces", block); writer.emit_block("run_forces", block);
@ -350,13 +348,16 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
return; return;
} }
TEST(BondStyle, plain) { TEST(BondStyle, plain)
{
const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"}; const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout(); ::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(); std::string output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;
@ -364,8 +365,7 @@ TEST(BondStyle, plain) {
std::cerr << "One or more prerequisite styles are not available " 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) { for (auto &prerequisite : test_config.prerequisites) {
std::cerr << prerequisite.first << "_style " std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n";
<< prerequisite.second << "\n";
} }
GTEST_SKIP(); GTEST_SKIP();
} }
@ -389,8 +389,7 @@ TEST(BondStyle, plain) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl;
std::cerr << "init_forces stats, newton on: " << stats << std::endl;
Bond *bond = lmp->force->bond; Bond *bond = lmp->force->bond;
double *stress = bond->virial; double *stress = bond->virial;
@ -401,13 +400,11 @@ TEST(BondStyle, plain) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); 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[4], test_config.init_stress.xz, epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon);
if (print_stats) if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl;
std::cerr << "init_stress stats, newton on: " << stats << std::endl;
stats.reset(); stats.reset();
EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon);
if (print_stats) if (print_stats) std::cerr << "init_energy stats, newton on: " << stats << std::endl;
std::cerr << "init_energy stats, newton on: " << stats << std::endl;
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
run_lammps(lmp); run_lammps(lmp);
@ -423,8 +420,7 @@ TEST(BondStyle, plain) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl;
std::cerr << "run_forces stats, newton on: " << stats << std::endl;
stress = bond->virial; stress = bond->virial;
stats.reset(); stats.reset();
@ -434,16 +430,14 @@ TEST(BondStyle, plain) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); 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[4], test_config.run_stress.xz, epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon);
if (print_stats) if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl;
std::cerr << "run_stress stats, newton on: " << stats << std::endl;
stats.reset(); stats.reset();
int id = lmp->modify->find_compute("sum"); int id = lmp->modify->find_compute("sum");
double energy = lmp->modify->compute[id]->compute_scalar(); 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, test_config.run_energy, epsilon);
EXPECT_FP_LE_WITH_EPS(bond->energy, energy, epsilon); EXPECT_FP_LE_WITH_EPS(bond->energy, energy, epsilon);
if (print_stats) if (print_stats) std::cerr << "run_energy stats, newton on: " << stats << std::endl;
std::cerr << "run_energy stats, newton on: " << stats << std::endl;
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
cleanup_lammps(lmp, test_config); cleanup_lammps(lmp, test_config);
@ -461,8 +455,7 @@ TEST(BondStyle, plain) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl;
std::cerr << "init_forces stats, newton off:" << stats << std::endl;
bond = lmp->force->bond; bond = lmp->force->bond;
stress = bond->virial; stress = bond->virial;
@ -473,13 +466,11 @@ TEST(BondStyle, plain) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 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[4], test_config.init_stress.xz, 2 * epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 2 * epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 2 * epsilon);
if (print_stats) if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl;
std::cerr << "init_stress stats, newton off:" << stats << std::endl;
stats.reset(); stats.reset();
EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon);
if (print_stats) if (print_stats) std::cerr << "init_energy stats, newton off:" << stats << std::endl;
std::cerr << "init_energy stats, newton off:" << stats << std::endl;
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
run_lammps(lmp); run_lammps(lmp);
@ -493,8 +484,7 @@ TEST(BondStyle, plain) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl;
std::cerr << "run_forces stats, newton off:" << stats << std::endl;
stress = bond->virial; stress = bond->virial;
stats.reset(); stats.reset();
@ -504,16 +494,14 @@ TEST(BondStyle, plain) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); 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[4], test_config.run_stress.xz, epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon);
if (print_stats) if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl;
std::cerr << "run_stress stats, newton off:" << stats << std::endl;
stats.reset(); stats.reset();
id = lmp->modify->find_compute("sum"); id = lmp->modify->find_compute("sum");
energy = lmp->modify->compute[id]->compute_scalar(); 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, test_config.run_energy, epsilon);
EXPECT_FP_LE_WITH_EPS(bond->energy, energy, epsilon); EXPECT_FP_LE_WITH_EPS(bond->energy, energy, epsilon);
if (print_stats) if (print_stats) std::cerr << "run_energy stats, newton off:" << stats << std::endl;
std::cerr << "run_energy stats, newton off:" << stats << std::endl;
} }
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
@ -529,8 +517,7 @@ TEST(BondStyle, plain) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "restart_forces stats:" << stats << std::endl;
std::cerr << "restart_forces stats:" << stats << std::endl;
bond = lmp->force->bond; bond = lmp->force->bond;
stress = bond->virial; stress = bond->virial;
@ -541,13 +528,11 @@ TEST(BondStyle, plain) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); 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[4], test_config.init_stress.xz, epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon);
if (print_stats) if (print_stats) std::cerr << "restart_stress stats:" << stats << std::endl;
std::cerr << "restart_stress stats:" << stats << std::endl;
stats.reset(); stats.reset();
EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon);
if (print_stats) if (print_stats) std::cerr << "restart_energy stats:" << stats << std::endl;
std::cerr << "restart_energy stats:" << stats << std::endl;
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
data_lammps(lmp, test_config); data_lammps(lmp, test_config);
@ -562,8 +547,7 @@ TEST(BondStyle, plain) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "data_forces stats:" << stats << std::endl;
std::cerr << "data_forces stats:" << stats << std::endl;
bond = lmp->force->bond; bond = lmp->force->bond;
stress = bond->virial; stress = bond->virial;
@ -574,28 +558,29 @@ TEST(BondStyle, plain) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); 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[4], test_config.init_stress.xz, epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon);
if (print_stats) if (print_stats) std::cerr << "data_stress stats:" << stats << std::endl;
std::cerr << "data_stress stats:" << stats << std::endl;
stats.reset(); stats.reset();
EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon);
if (print_stats) if (print_stats) std::cerr << "data_energy stats:" << stats << std::endl;
std::cerr << "data_energy stats:" << stats << std::endl;
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
cleanup_lammps(lmp, test_config); cleanup_lammps(lmp, test_config);
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
}; };
TEST(BondStyle, omp) { TEST(BondStyle, omp)
{
if (!LAMMPS::is_installed_pkg("USER-OMP")) GTEST_SKIP(); if (!LAMMPS::is_installed_pkg("USER-OMP")) GTEST_SKIP();
const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite",
"-nocite", "-pk", "omp", "4", "-sf", "omp"}; "-pk", "omp", "4", "-sf", "omp"};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout(); ::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(); std::string output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;
@ -603,8 +588,7 @@ TEST(BondStyle, omp) {
std::cerr << "One or more prerequisite styles with /omp suffix\n" 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) { for (auto &prerequisite : test_config.prerequisites) {
std::cerr << prerequisite.first << "_style " std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n";
<< prerequisite.second << "\n";
} }
GTEST_SKIP(); GTEST_SKIP();
} }
@ -628,8 +612,7 @@ TEST(BondStyle, omp) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl;
std::cerr << "init_forces stats, newton on: " << stats << std::endl;
Bond *bond = lmp->force->bond; Bond *bond = lmp->force->bond;
double *stress = bond->virial; double *stress = bond->virial;
@ -640,13 +623,11 @@ TEST(BondStyle, omp) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 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[4], test_config.init_stress.xz, 10 * epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon);
if (print_stats) if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl;
std::cerr << "init_stress stats, newton on: " << stats << std::endl;
stats.reset(); stats.reset();
EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon);
if (print_stats) if (print_stats) std::cerr << "init_energy stats, newton on: " << stats << std::endl;
std::cerr << "init_energy stats, newton on: " << stats << std::endl;
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
run_lammps(lmp); run_lammps(lmp);
@ -662,8 +643,7 @@ TEST(BondStyle, omp) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl;
std::cerr << "run_forces stats, newton on: " << stats << std::endl;
stress = bond->virial; stress = bond->virial;
stats.reset(); stats.reset();
@ -673,8 +653,7 @@ TEST(BondStyle, omp) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 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[4], test_config.run_stress.xz, 10 * epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon);
if (print_stats) if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl;
std::cerr << "run_stress stats, newton on: " << stats << std::endl;
stats.reset(); stats.reset();
int id = lmp->modify->find_compute("sum"); int id = lmp->modify->find_compute("sum");
@ -684,8 +663,7 @@ TEST(BondStyle, omp) {
// needs to be fixed in the main code somewhere. Not sure where, though. // 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); EXPECT_FP_LE_WITH_EPS(bond->energy, energy, epsilon);
if (print_stats) if (print_stats) std::cerr << "run_energy stats, newton on: " << stats << std::endl;
std::cerr << "run_energy stats, newton on: " << stats << std::endl;
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
cleanup_lammps(lmp, test_config); cleanup_lammps(lmp, test_config);
@ -703,8 +681,7 @@ TEST(BondStyle, omp) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl;
std::cerr << "init_forces stats, newton off:" << stats << std::endl;
bond = lmp->force->bond; bond = lmp->force->bond;
stress = bond->virial; stress = bond->virial;
@ -715,13 +692,11 @@ TEST(BondStyle, omp) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 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[4], test_config.init_stress.xz, 10 * epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon);
if (print_stats) if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl;
std::cerr << "init_stress stats, newton off:" << stats << std::endl;
stats.reset(); stats.reset();
EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon);
if (print_stats) if (print_stats) std::cerr << "init_energy stats, newton off:" << stats << std::endl;
std::cerr << "init_energy stats, newton off:" << stats << std::endl;
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
run_lammps(lmp); run_lammps(lmp);
@ -734,8 +709,7 @@ TEST(BondStyle, omp) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl;
std::cerr << "run_forces stats, newton off:" << stats << std::endl;
stress = bond->virial; stress = bond->virial;
stats.reset(); stats.reset();
@ -745,8 +719,7 @@ TEST(BondStyle, omp) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 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[4], test_config.run_stress.xz, 10 * epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon);
if (print_stats) if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl;
std::cerr << "run_stress stats, newton off:" << stats << std::endl;
stats.reset(); stats.reset();
id = lmp->modify->find_compute("sum"); id = lmp->modify->find_compute("sum");
@ -756,8 +729,7 @@ TEST(BondStyle, omp) {
// needs to be fixed in the main code somewhere. Not sure where, though. // 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); EXPECT_FP_LE_WITH_EPS(bond->energy, energy, epsilon);
if (print_stats) if (print_stats) std::cerr << "run_energy stats, newton off:" << stats << std::endl;
std::cerr << "run_energy stats, newton off:" << stats << std::endl;
} }
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
@ -765,8 +737,10 @@ TEST(BondStyle, omp) {
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
}; };
TEST(BondStyle, single) { TEST(BondStyle, single)
{
const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"}; const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = sizeof(args) / sizeof(char *);
@ -779,8 +753,7 @@ TEST(BondStyle, single) {
std::cerr << "One or more prerequisite styles are not available " 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) { for (auto &prerequisite : test_config.prerequisites) {
std::cerr << prerequisite.first << "_style " std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n";
<< prerequisite.second << "\n";
} }
GTEST_SKIP(); GTEST_SKIP();
} }
@ -1007,16 +980,14 @@ TEST(BondStyle, single) {
EXPECT_FP_LE_WITH_EPS(f[idx4][0], fsingle * delx2, 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][1], fsingle * dely2, epsilon);
EXPECT_FP_LE_WITH_EPS(f[idx4][2], fsingle * delz2, epsilon); EXPECT_FP_LE_WITH_EPS(f[idx4][2], fsingle * delz2, epsilon);
if (print_stats) if (print_stats) std::cerr << "single_force stats:" << stats << std::endl;
std::cerr << "single_force stats:" << stats << std::endl;
stats.reset(); stats.reset();
EXPECT_FP_LE_WITH_EPS(ebond[0], esngl[0], epsilon); 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[1], esngl[1], epsilon);
EXPECT_FP_LE_WITH_EPS(ebond[2], esngl[2], epsilon); EXPECT_FP_LE_WITH_EPS(ebond[2], esngl[2], epsilon);
EXPECT_FP_LE_WITH_EPS(ebond[3], esngl[3], epsilon); EXPECT_FP_LE_WITH_EPS(ebond[3], esngl[3], epsilon);
if (print_stats) if (print_stats) std::cerr << "single_energy stats:" << stats << std::endl;
std::cerr << "single_energy stats:" << stats << std::endl;
int i = 0; int i = 0;
for (auto &dist : test_config.equilibrium) for (auto &dist : test_config.equilibrium)
@ -1027,8 +998,10 @@ TEST(BondStyle, single) {
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }
TEST(BondStyle, extract) { TEST(BondStyle, extract)
{
const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"}; const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = sizeof(args) / sizeof(char *);
@ -1040,8 +1013,7 @@ TEST(BondStyle, extract) {
std::cerr << "One or more prerequisite styles are not available " 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) { for (auto prerequisite : test_config.prerequisites) {
std::cerr << prerequisite.first << "_style " std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n";
<< prerequisite.second << "\n";
} }
GTEST_SKIP(); GTEST_SKIP();
} }

View File

@ -12,17 +12,20 @@
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
#include "error_stats.h" #include "error_stats.h"
#include "fmt/format.h"
#include <cmath>
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <cmath>
void ErrorStats::reset() { void ErrorStats::reset()
{
num = 0; num = 0;
maxidx = -1; 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; ++num;
if (val > maxerr) { if (val > maxerr) {
maxidx = num; maxidx = num;
@ -32,29 +35,19 @@ void ErrorStats::add(const double &val) {
sumsq += val * val; sumsq += val * val;
} }
double ErrorStats::avg() const { double ErrorStats::avg() const
{
return (num > 0) ? sum / num : 0.0; return (num > 0) ? sum / num : 0.0;
} }
double ErrorStats::dev() const { double ErrorStats::dev() const
{
return (num > 0) ? sqrt(sumsq / num - sum / num * sum / num) : 0.0; return (num > 0) ? sqrt(sumsq / num - sum / num * sum / num) : 0.0;
} }
std::ostream &operator<<(std::ostream &out, const ErrorStats &stats) std::ostream &operator<<(std::ostream &out, const ErrorStats &stats)
{ {
const std::ios_base::fmtflags flags = out.flags(); out << fmt::format("Average: {:10.3e} StdDev: {:10.3e} MaxErr: {:10.3e} @ item: {}",
const std::streamsize width = out.width(10); stats.avg(), stats.dev(), stats.max(), stats.idx());
const std::streamsize prec = out.precision(3); return out;
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();
} }

View File

@ -20,9 +20,7 @@ class ErrorStats {
public: public:
friend std::ostream &operator<<(std::ostream &out, const ErrorStats &stats); friend std::ostream &operator<<(std::ostream &out, const ErrorStats &stats);
ErrorStats() { ErrorStats() { reset(); }
reset();
}
virtual ~ErrorStats() {} virtual ~ErrorStats() {}
void reset(); void reset();

View File

@ -13,32 +13,32 @@
// unit tests for pair styles intended for molecular systems // unit tests for pair styles intended for molecular systems
#include "yaml_reader.h"
#include "yaml_writer.h"
#include "error_stats.h" #include "error_stats.h"
#include "test_config.h" #include "test_config.h"
#include "test_config_reader.h" #include "test_config_reader.h"
#include "test_main.h" #include "test_main.h"
#include "yaml_reader.h"
#include "yaml_writer.h"
#include "gtest/gtest.h"
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "lammps.h"
#include "atom.h" #include "atom.h"
#include "modify.h"
#include "compute.h" #include "compute.h"
#include "force.h" #include "force.h"
#include "pair.h"
#include "info.h" #include "info.h"
#include "input.h" #include "input.h"
#include "lammps.h"
#include "modify.h"
#include "pair.h"
#include "universe.h" #include "universe.h"
#include <mpi.h>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype> #include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime> #include <ctime>
#include <mpi.h>
#include <iostream> #include <iostream>
#include <map> #include <map>
@ -46,12 +46,13 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
using ::testing::StartsWith;
using ::testing::HasSubstr; using ::testing::HasSubstr;
using ::testing::StartsWith;
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
static void delete_file(const std::string & filename) { static void delete_file(const std::string &filename)
{
remove(filename.c_str()); remove(filename.c_str());
}; };
@ -63,9 +64,7 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg)
delete lmp; delete lmp;
} }
LAMMPS *init_lammps(int argc, char **argv, LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool newton = true)
const TestConfig &cfg,
const bool newton=true)
{ {
LAMMPS *lmp; LAMMPS *lmp;
@ -163,8 +162,7 @@ void restart_lammps(LAMMPS *lmp, const TestConfig &cfg)
if (!lmp->force->pair) { if (!lmp->force->pair) {
command("pair_style " + cfg.pair_style); command("pair_style " + cfg.pair_style);
} }
if (!lmp->force->pair->restartinfo if (!lmp->force->pair->restartinfo || !lmp->force->pair->writedata) {
|| !lmp->force->pair->writedata) {
for (auto &pair_coeff : cfg.pair_coeff) { for (auto &pair_coeff : cfg.pair_coeff) {
command("pair_coeff " + pair_coeff); command("pair_coeff " + pair_coeff);
} }
@ -218,6 +216,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
{ {
// initialize system geometry // 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; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = sizeof(args) / sizeof(char *);
LAMMPS *lmp = init_lammps(argc, argv, config); LAMMPS *lmp = init_lammps(argc, argv, config);
@ -225,8 +224,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
std::cerr << "One or more prerequisite styles are not available " 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) { for (auto prerequisite : config.prerequisites) {
std::cerr << prerequisite.first << "_style " std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n";
<< prerequisite.second << "\n";
} }
return; return;
} }
@ -303,8 +301,8 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
// init_stress // init_stress
double *stress = lmp->force->pair->virial; double *stress = lmp->force->pair->virial;
snprintf(buf,bufsize,"% 23.16e % 23.16e % 23.16e % 23.16e % 23.16e % 23.16e", snprintf(buf, bufsize, "% 23.16e % 23.16e % 23.16e % 23.16e % 23.16e % 23.16e", stress[0],
stress[0],stress[1],stress[2],stress[3],stress[4],stress[5]); stress[1], stress[2], stress[3], stress[4], stress[5]);
writer.emit_block("init_stress", buf); writer.emit_block("init_stress", buf);
// init_forces // init_forces
@ -312,8 +310,8 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
double **f = lmp->atom->f; double **f = lmp->atom->f;
tagint *tag = lmp->atom->tag; tagint *tag = lmp->atom->tag;
for (int i = 0; i < natoms; ++i) { for (int i = 0; i < natoms; ++i) {
snprintf(buf,bufsize,"% 3d % 23.16e % 23.16e % 23.16e\n", snprintf(buf, bufsize, "% 3d % 23.16e % 23.16e % 23.16e\n", (int)tag[i], f[i][0], f[i][1],
(int)tag[i], f[i][0], f[i][1], f[i][2]); f[i][2]);
block += buf; block += buf;
} }
writer.emit_block("init_forces", block); writer.emit_block("init_forces", block);
@ -329,16 +327,16 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
// run_stress // run_stress
stress = lmp->force->pair->virial; stress = lmp->force->pair->virial;
snprintf(buf,bufsize,"% 23.16e % 23.16e % 23.16e % 23.16e % 23.16e % 23.16e", snprintf(buf, bufsize, "% 23.16e % 23.16e % 23.16e % 23.16e % 23.16e % 23.16e", stress[0],
stress[0],stress[1],stress[2],stress[3],stress[4],stress[5]); stress[1], stress[2], stress[3], stress[4], stress[5]);
writer.emit_block("run_stress", buf); writer.emit_block("run_stress", buf);
block.clear(); block.clear();
f = lmp->atom->f; f = lmp->atom->f;
tag = lmp->atom->tag; tag = lmp->atom->tag;
for (int i = 0; i < natoms; ++i) { for (int i = 0; i < natoms; ++i) {
snprintf(buf,bufsize,"% 3d % 23.16e % 23.16e % 23.16e\n", snprintf(buf, bufsize, "% 3d % 23.16e % 23.16e % 23.16e\n", (int)tag[i], f[i][0], f[i][1],
(int)tag[i], f[i][0], f[i][1], f[i][2]); f[i][2]);
block += buf; block += buf;
} }
writer.emit_block("run_forces", block); writer.emit_block("run_forces", block);
@ -347,13 +345,16 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
return; return;
} }
TEST(PairStyle, plain) { TEST(PairStyle, plain)
{
const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"}; const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout(); ::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(); std::string output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;
@ -361,8 +362,7 @@ TEST(PairStyle, plain) {
std::cerr << "One or more prerequisite styles are not available " 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) { for (auto prerequisite : test_config.prerequisites) {
std::cerr << prerequisite.first << "_style " std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n";
<< prerequisite.second << "\n";
} }
GTEST_SKIP(); GTEST_SKIP();
} }
@ -386,8 +386,7 @@ TEST(PairStyle, plain) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl;
std::cerr << "init_forces stats, newton on: " << stats << std::endl;
Pair *pair = lmp->force->pair; Pair *pair = lmp->force->pair;
double *stress = pair->virial; double *stress = pair->virial;
@ -398,14 +397,12 @@ TEST(PairStyle, plain) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); 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[4], test_config.init_stress.xz, epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon);
if (print_stats) if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl;
std::cerr << "init_stress stats, newton on: " << stats << std::endl;
stats.reset(); stats.reset();
EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); 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); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.init_coul, epsilon);
if (print_stats) if (print_stats) std::cerr << "init_energy stats, newton on: " << stats << std::endl;
std::cerr << "init_energy stats, newton on: " << stats << std::endl;
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
run_lammps(lmp); run_lammps(lmp);
@ -421,8 +418,7 @@ TEST(PairStyle, plain) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl;
std::cerr << "run_forces stats, newton on: " << stats << std::endl;
stress = pair->virial; stress = pair->virial;
stats.reset(); stats.reset();
@ -432,8 +428,7 @@ TEST(PairStyle, plain) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); 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[4], test_config.run_stress.xz, epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon);
if (print_stats) if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl;
std::cerr << "run_stress stats, newton on: " << stats << std::endl;
stats.reset(); stats.reset();
int id = lmp->modify->find_compute("sum"); int id = lmp->modify->find_compute("sum");
@ -441,8 +436,7 @@ TEST(PairStyle, plain) {
EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.run_vdwl, epsilon); 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_coul, test_config.run_coul, epsilon);
EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl + pair->eng_coul), energy, epsilon); EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl + pair->eng_coul), energy, epsilon);
if (print_stats) if (print_stats) std::cerr << "run_energy stats, newton on: " << stats << std::endl;
std::cerr << "run_energy stats, newton on: " << stats << std::endl;
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
cleanup_lammps(lmp, test_config); cleanup_lammps(lmp, test_config);
@ -460,8 +454,7 @@ TEST(PairStyle, plain) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl;
std::cerr << "init_forces stats, newton off:" << stats << std::endl;
pair = lmp->force->pair; pair = lmp->force->pair;
stress = pair->virial; stress = pair->virial;
@ -472,14 +465,12 @@ TEST(PairStyle, plain) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 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[4], test_config.init_stress.xz, 3 * epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 3 * epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 3 * epsilon);
if (print_stats) if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl;
std::cerr << "init_stress stats, newton off:" << stats << std::endl;
stats.reset(); stats.reset();
EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); 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); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.init_coul, epsilon);
if (print_stats) if (print_stats) std::cerr << "init_energy stats, newton off:" << stats << std::endl;
std::cerr << "init_energy stats, newton off:" << stats << std::endl;
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
run_lammps(lmp); run_lammps(lmp);
@ -493,8 +484,7 @@ TEST(PairStyle, plain) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl;
std::cerr << "run_forces stats, newton off:" << stats << std::endl;
stress = pair->virial; stress = pair->virial;
stats.reset(); stats.reset();
@ -504,8 +494,7 @@ TEST(PairStyle, plain) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); 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[4], test_config.run_stress.xz, epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon);
if (print_stats) if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl;
std::cerr << "run_stress stats, newton off:" << stats << std::endl;
stats.reset(); stats.reset();
id = lmp->modify->find_compute("sum"); id = lmp->modify->find_compute("sum");
@ -513,8 +502,7 @@ TEST(PairStyle, plain) {
EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.run_vdwl, epsilon); 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_coul, test_config.run_coul, epsilon);
EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl + pair->eng_coul), energy, epsilon); EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl + pair->eng_coul), energy, epsilon);
if (print_stats) if (print_stats) std::cerr << "run_energy stats, newton off:" << stats << std::endl;
std::cerr << "run_energy stats, newton off:" << stats << std::endl;
} }
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
@ -530,8 +518,7 @@ TEST(PairStyle, plain) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "restart_forces stats:" << stats << std::endl;
std::cerr << "restart_forces stats:" << stats << std::endl;
pair = lmp->force->pair; pair = lmp->force->pair;
stress = pair->virial; stress = pair->virial;
@ -542,14 +529,12 @@ TEST(PairStyle, plain) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); 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[4], test_config.init_stress.xz, epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon);
if (print_stats) if (print_stats) std::cerr << "restart_stress stats:" << stats << std::endl;
std::cerr << "restart_stress stats:" << stats << std::endl;
stats.reset(); stats.reset();
EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); 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); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.init_coul, epsilon);
if (print_stats) if (print_stats) std::cerr << "restart_energy stats:" << stats << std::endl;
std::cerr << "restart_energy stats:" << stats << std::endl;
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
data_lammps(lmp, test_config); data_lammps(lmp, test_config);
@ -564,8 +549,7 @@ TEST(PairStyle, plain) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "data_forces stats:" << stats << std::endl;
std::cerr << "data_forces stats:" << stats << std::endl;
pair = lmp->force->pair; pair = lmp->force->pair;
stress = pair->virial; stress = pair->virial;
@ -576,14 +560,12 @@ TEST(PairStyle, plain) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); 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[4], test_config.init_stress.xz, epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon);
if (print_stats) if (print_stats) std::cerr << "data_stress stats:" << stats << std::endl;
std::cerr << "data_stress stats:" << stats << std::endl;
stats.reset(); stats.reset();
EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); 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); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.init_coul, epsilon);
if (print_stats) if (print_stats) std::cerr << "data_energy stats:" << stats << std::endl;
std::cerr << "data_energy stats:" << stats << std::endl;
if (pair->respa_enable) { if (pair->respa_enable) {
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
@ -607,8 +589,7 @@ TEST(PairStyle, plain) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "run_forces stats, r-RESPA:" << stats << std::endl;
std::cerr << "run_forces stats, r-RESPA:" << stats << std::endl;
stress = pair->virial; stress = pair->virial;
stats.reset(); stats.reset();
@ -618,8 +599,7 @@ TEST(PairStyle, plain) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); 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[4], test_config.run_stress.xz, epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon);
if (print_stats) if (print_stats) std::cerr << "run_stress stats, r-RESPA:" << stats << std::endl;
std::cerr << "run_stress stats, r-RESPA:" << stats << std::endl;
stats.reset(); stats.reset();
id = lmp->modify->find_compute("sum"); id = lmp->modify->find_compute("sum");
@ -627,23 +607,25 @@ TEST(PairStyle, plain) {
EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.run_vdwl, epsilon); 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_coul, test_config.run_coul, epsilon);
EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl + pair->eng_coul), energy, epsilon); EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl + pair->eng_coul), energy, epsilon);
if (print_stats) if (print_stats) std::cerr << "run_energy stats, r-RESPA:" << stats << std::endl;
std::cerr << "run_energy stats, r-RESPA:" << stats << std::endl;
} }
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
cleanup_lammps(lmp, test_config); cleanup_lammps(lmp, test_config);
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
}; };
TEST(PairStyle, omp) { TEST(PairStyle, omp)
{
if (!LAMMPS::is_installed_pkg("USER-OMP")) GTEST_SKIP(); if (!LAMMPS::is_installed_pkg("USER-OMP")) GTEST_SKIP();
const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite",
"-nocite", "-pk", "omp", "4", "-sf", "omp"}; "-pk", "omp", "4", "-sf", "omp"};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout(); ::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(); std::string output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;
@ -651,8 +633,7 @@ TEST(PairStyle, omp) {
std::cerr << "One or more prerequisite styles with /omp suffix\n" 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) { for (auto prerequisite : test_config.prerequisites) {
std::cerr << prerequisite.first << "_style " std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n";
<< prerequisite.second << "\n";
} }
GTEST_SKIP(); GTEST_SKIP();
} }
@ -676,8 +657,7 @@ TEST(PairStyle, omp) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl;
std::cerr << "init_forces stats, newton on: " << stats << std::endl;
Pair *pair = lmp->force->pair; Pair *pair = lmp->force->pair;
double *stress = pair->virial; double *stress = pair->virial;
@ -688,14 +668,12 @@ TEST(PairStyle, omp) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 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[4], test_config.init_stress.xz, 10 * epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon);
if (print_stats) if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl;
std::cerr << "init_stress stats, newton on: " << stats << std::endl;
stats.reset(); stats.reset();
EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); 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); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.init_coul, epsilon);
if (print_stats) if (print_stats) std::cerr << "init_energy stats, newton on: " << stats << std::endl;
std::cerr << "init_energy stats, newton on: " << stats << std::endl;
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
run_lammps(lmp); run_lammps(lmp);
@ -711,8 +689,7 @@ TEST(PairStyle, omp) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl;
std::cerr << "run_forces stats, newton on: " << stats << std::endl;
stress = pair->virial; stress = pair->virial;
stats.reset(); stats.reset();
@ -722,8 +699,7 @@ TEST(PairStyle, omp) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 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[4], test_config.run_stress.xz, 10 * epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon);
if (print_stats) if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl;
std::cerr << "run_stress stats, newton on: " << stats << std::endl;
stats.reset(); stats.reset();
int id = lmp->modify->find_compute("sum"); int id = lmp->modify->find_compute("sum");
@ -731,8 +707,7 @@ TEST(PairStyle, omp) {
EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.run_vdwl, epsilon); 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_coul, test_config.run_coul, epsilon);
EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl + pair->eng_coul), energy, epsilon); EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl + pair->eng_coul), energy, epsilon);
if (print_stats) if (print_stats) std::cerr << "run_energy stats, newton on: " << stats << std::endl;
std::cerr << "run_energy stats, newton on: " << stats << std::endl;
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
cleanup_lammps(lmp, test_config); cleanup_lammps(lmp, test_config);
@ -750,8 +725,7 @@ TEST(PairStyle, omp) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl;
std::cerr << "init_forces stats, newton off:" << stats << std::endl;
pair = lmp->force->pair; pair = lmp->force->pair;
stress = pair->virial; stress = pair->virial;
@ -762,14 +736,12 @@ TEST(PairStyle, omp) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 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[4], test_config.init_stress.xz, 10 * epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon);
if (print_stats) if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl;
std::cerr << "init_stress stats, newton off:" << stats << std::endl;
stats.reset(); stats.reset();
EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); 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); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.init_coul, epsilon);
if (print_stats) if (print_stats) std::cerr << "init_energy stats, newton off:" << stats << std::endl;
std::cerr << "init_energy stats, newton off:" << stats << std::endl;
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
run_lammps(lmp); run_lammps(lmp);
@ -782,8 +754,7 @@ TEST(PairStyle, omp) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl;
std::cerr << "run_forces stats, newton off:" << stats << std::endl;
stress = pair->virial; stress = pair->virial;
stats.reset(); stats.reset();
@ -793,8 +764,7 @@ TEST(PairStyle, omp) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 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[4], test_config.run_stress.xz, 10 * epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon);
if (print_stats) if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl;
std::cerr << "run_stress stats, newton off:" << stats << std::endl;
stats.reset(); stats.reset();
id = lmp->modify->find_compute("sum"); id = lmp->modify->find_compute("sum");
@ -802,24 +772,26 @@ TEST(PairStyle, omp) {
EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.run_vdwl, epsilon); 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_coul, test_config.run_coul, epsilon);
EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl + pair->eng_coul), energy, epsilon); EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl + pair->eng_coul), energy, epsilon);
if (print_stats) if (print_stats) std::cerr << "run_energy stats, newton off:" << stats << std::endl;
std::cerr << "run_energy stats, newton off:" << stats << std::endl;
} }
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
cleanup_lammps(lmp, test_config); cleanup_lammps(lmp, test_config);
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
}; };
TEST(PairStyle, intel) { TEST(PairStyle, intel)
{
if (!LAMMPS::is_installed_pkg("USER-INTEL")) GTEST_SKIP(); if (!LAMMPS::is_installed_pkg("USER-INTEL")) GTEST_SKIP();
const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite",
"-nocite", "-pk", "intel", "0", "mode", "double", "-pk", "intel", "0", "mode", "double", "omp",
"omp", "4", "lrt", "no", "-sf", "intel"}; "4", "lrt", "no", "-sf", "intel"};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout(); ::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(); std::string output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;
@ -827,8 +799,7 @@ TEST(PairStyle, intel) {
std::cerr << "One or more prerequisite styles with /intel suffix\n" 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) { for (auto prerequisite : test_config.prerequisites) {
std::cerr << prerequisite.first << "_style " std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n";
<< prerequisite.second << "\n";
} }
GTEST_SKIP(); GTEST_SKIP();
} }
@ -848,8 +819,7 @@ TEST(PairStyle, intel) {
// coulomb with tabulation. seems more like mixed precision or a bug // coulomb with tabulation. seems more like mixed precision or a bug
for (auto post_cmd : test_config.post_commands) { 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") != std::string::npos) {
if (post_cmd.find("pair_modify table 0") == std::string::npos) if (post_cmd.find("pair_modify table 0") == std::string::npos) epsilon *= 1000000.0;
epsilon *= 1000000.0;
} }
} }
@ -870,8 +840,7 @@ TEST(PairStyle, intel) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "init_forces stats:" << stats << std::endl;
std::cerr << "init_forces stats:" << stats << std::endl;
Pair *pair = lmp->force->pair; Pair *pair = lmp->force->pair;
double *stress = pair->virial; double *stress = pair->virial;
@ -882,14 +851,12 @@ TEST(PairStyle, intel) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 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[4], test_config.init_stress.xz, 10 * epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon);
if (print_stats) if (print_stats) std::cerr << "init_stress stats:" << stats << std::endl;
std::cerr << "init_stress stats:" << stats << std::endl;
stats.reset(); stats.reset();
EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); 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); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.init_coul, epsilon);
if (print_stats) if (print_stats) std::cerr << "init_energy stats:" << stats << std::endl;
std::cerr << "init_energy stats:" << stats << std::endl;
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
run_lammps(lmp); run_lammps(lmp);
@ -905,8 +872,7 @@ TEST(PairStyle, intel) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "run_forces stats:" << stats << std::endl;
std::cerr << "run_forces stats:" << stats << std::endl;
stress = pair->virial; stress = pair->virial;
stats.reset(); stats.reset();
@ -916,8 +882,7 @@ TEST(PairStyle, intel) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 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[4], test_config.run_stress.xz, 10 * epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon);
if (print_stats) if (print_stats) std::cerr << "run_stress stats:" << stats << std::endl;
std::cerr << "run_stress stats:" << stats << std::endl;
stats.reset(); stats.reset();
int id = lmp->modify->find_compute("sum"); int id = lmp->modify->find_compute("sum");
@ -926,36 +891,35 @@ TEST(PairStyle, intel) {
EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.run_coul, epsilon); 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 // 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) if (test_config.pair_style.find("rebo") != std::string::npos) epsilon *= 100000.0;
epsilon *= 100000.0;
EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl + pair->eng_coul), energy, epsilon); EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl + pair->eng_coul), energy, epsilon);
if (print_stats) if (print_stats) std::cerr << "run_energy stats:" << stats << std::endl;
std::cerr << "run_energy stats:" << stats << std::endl;
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
cleanup_lammps(lmp, test_config); cleanup_lammps(lmp, test_config);
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
}; };
TEST(PairStyle, opt) { TEST(PairStyle, opt)
{
if (!LAMMPS::is_installed_pkg("OPT")) GTEST_SKIP(); if (!LAMMPS::is_installed_pkg("OPT")) GTEST_SKIP();
const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", "-sf", "opt"};
"-nocite", "-sf", "opt"};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = sizeof(args) / sizeof(char *);
if (!verbose) ::testing::internal::CaptureStdout(); 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(); std::string output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output;
if (!lmp) { if (!lmp) {
std::cerr << "One or more prerequisite styles with /opt suffix\n" 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) { for (auto prerequisite : test_config.prerequisites) {
std::cerr << prerequisite.first << "_style " std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n";
<< prerequisite.second << "\n";
} }
GTEST_SKIP(); GTEST_SKIP();
} }
@ -979,8 +943,7 @@ TEST(PairStyle, opt) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "init_forces stats:" << stats << std::endl;
std::cerr << "init_forces stats:" << stats << std::endl;
Pair *pair = lmp->force->pair; Pair *pair = lmp->force->pair;
double *stress = pair->virial; double *stress = pair->virial;
@ -991,14 +954,12 @@ TEST(PairStyle, opt) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 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[4], test_config.init_stress.xz, 10 * epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon);
if (print_stats) if (print_stats) std::cerr << "init_stress stats:" << stats << std::endl;
std::cerr << "init_stress stats:" << stats << std::endl;
stats.reset(); stats.reset();
EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); 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); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.init_coul, epsilon);
if (print_stats) if (print_stats) std::cerr << "init_energy stats:" << stats << std::endl;
std::cerr << "init_energy stats:" << stats << std::endl;
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
run_lammps(lmp); run_lammps(lmp);
@ -1014,8 +975,7 @@ TEST(PairStyle, opt) {
EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 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); EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon);
} }
if (print_stats) if (print_stats) std::cerr << "run_forces stats:" << stats << std::endl;
std::cerr << "run_forces stats:" << stats << std::endl;
stress = pair->virial; stress = pair->virial;
stats.reset(); stats.reset();
@ -1025,8 +985,7 @@ TEST(PairStyle, opt) {
EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 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[4], test_config.run_stress.xz, 10 * epsilon);
EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon);
if (print_stats) if (print_stats) std::cerr << "run_stress stats:" << stats << std::endl;
std::cerr << "run_stress stats:" << stats << std::endl;
stats.reset(); stats.reset();
int id = lmp->modify->find_compute("sum"); int id = lmp->modify->find_compute("sum");
@ -1034,16 +993,17 @@ TEST(PairStyle, opt) {
EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.run_vdwl, epsilon); 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_coul, test_config.run_coul, epsilon);
EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl + pair->eng_coul), energy, epsilon); EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl + pair->eng_coul), energy, epsilon);
if (print_stats) if (print_stats) std::cerr << "run_energy stats:" << stats << std::endl;
std::cerr << "run_energy stats:" << stats << std::endl;
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
cleanup_lammps(lmp, test_config); cleanup_lammps(lmp, test_config);
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
}; };
TEST(PairStyle, single) { TEST(PairStyle, single)
{
const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"}; const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = sizeof(args) / sizeof(char *);
@ -1056,8 +1016,7 @@ TEST(PairStyle, single) {
std::cerr << "One or more prerequisite styles are not available " 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) { for (auto prerequisite : test_config.prerequisites) {
std::cerr << prerequisite.first << "_style " std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n";
<< prerequisite.second << "\n";
} }
GTEST_SKIP(); GTEST_SKIP();
} }
@ -1075,8 +1034,8 @@ TEST(PairStyle, single) {
Pair *pair = lmp->force->pair; Pair *pair = lmp->force->pair;
if (!pair->single_enable) { if (!pair->single_enable) {
std::cerr << "Single method not available for pair style " std::cerr << "Single method not available for pair style " << test_config.pair_style
<< test_config.pair_style << std::endl; << std::endl;
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
cleanup_lammps(lmp, test_config); cleanup_lammps(lmp, test_config);
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
@ -1085,9 +1044,9 @@ TEST(PairStyle, single) {
// The single function in EAM is different from what we assume // The single function in EAM is different from what we assume
// here, therefore we have to skip testing those pair styles. // here, therefore we have to skip testing those pair styles.
if ((test_config.pair_style.substr(0,3) == "eam") if ((test_config.pair_style.substr(0, 3) == "eam") ||
|| ((test_config.pair_style.substr(0,6) == "hybrid") ((test_config.pair_style.substr(0, 6) == "hybrid") &&
&& (test_config.pair_style.find("eam") != std::string::npos))) { (test_config.pair_style.find("eam") != std::string::npos))) {
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
cleanup_lammps(lmp, test_config); cleanup_lammps(lmp, test_config);
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
@ -1261,18 +1220,16 @@ TEST(PairStyle, single) {
EXPECT_FP_LE_WITH_EPS(f[idx2][0], fsingle * delx, 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][1], fsingle * dely, epsilon);
EXPECT_FP_LE_WITH_EPS(f[idx2][2], fsingle * delz, epsilon); EXPECT_FP_LE_WITH_EPS(f[idx2][2], fsingle * delz, epsilon);
if (print_stats) if (print_stats) std::cerr << "single_force stats:" << stats << std::endl;
std::cerr << "single_force stats:" << stats << std::endl;
if ((test_config.pair_style.find("coul/dsf") != std::string::npos) if ((test_config.pair_style.find("coul/dsf") != std::string::npos) &&
&& (test_config.pair_style.find("coul/wolf") != std::string::npos)) { (test_config.pair_style.find("coul/wolf") != std::string::npos)) {
stats.reset(); stats.reset();
EXPECT_FP_LE_WITH_EPS(epair[0], esngl[0], epsilon); 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[1], esngl[1], epsilon);
EXPECT_FP_LE_WITH_EPS(epair[2], esngl[2], epsilon); EXPECT_FP_LE_WITH_EPS(epair[2], esngl[2], epsilon);
EXPECT_FP_LE_WITH_EPS(epair[3], esngl[3], epsilon); EXPECT_FP_LE_WITH_EPS(epair[3], esngl[3], epsilon);
if (print_stats) if (print_stats) std::cerr << "single_energy stats:" << stats << std::endl;
std::cerr << "single_energy stats:" << stats << std::endl;
} else if (print_stats) } else if (print_stats)
std::cerr << "skipping single_energy test due to self energy\n"; std::cerr << "skipping single_energy test due to self energy\n";
@ -1281,8 +1238,10 @@ TEST(PairStyle, single) {
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }
TEST(PairStyle, extract) { TEST(PairStyle, extract)
{
const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"}; const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = sizeof(args) / sizeof(char *);
@ -1294,8 +1253,7 @@ TEST(PairStyle, extract) {
std::cerr << "One or more prerequisite styles are not available " 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) { for (auto prerequisite : test_config.prerequisites) {
std::cerr << prerequisite.first << "_style " std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n";
<< prerequisite.second << "\n";
} }
GTEST_SKIP(); GTEST_SKIP();
} }

View File

@ -61,26 +61,13 @@ public:
std::vector<coord_t> init_forces; std::vector<coord_t> init_forces;
std::vector<coord_t> run_forces; std::vector<coord_t> run_forces;
TestConfig() : lammps_version(""), TestConfig() :
date_generated(""), lammps_version(""), date_generated(""), basename(""), epsilon(1.0e-14), input_file(""),
basename(""), pair_style("zero"), bond_style("zero"), angle_style("zero"), dihedral_style("zero"),
epsilon(1.0e-14), improper_style("zero"), kspace_style("none"), natoms(0), init_energy(0), run_energy(0),
input_file(""), init_vdwl(0), run_vdwl(0), init_coul(0), run_coul(0), init_stress({0, 0, 0, 0, 0, 0}),
pair_style("zero"), run_stress({0, 0, 0, 0, 0, 0})
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(); prerequisites.clear();
pre_commands.clear(); pre_commands.clear();
post_commands.clear(); post_commands.clear();

View File

@ -11,22 +11,22 @@
See the README file in the top-level LAMMPS directory. See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
#include "test_config.h"
#include "test_config_reader.h" #include "test_config_reader.h"
#include "yaml_reader.h" #include "test_config.h"
#include "yaml.h" #include "yaml.h"
#include "yaml_reader.h"
#include <cstring>
#include <cstdlib> #include <cstdlib>
#include <cstring>
#include <string>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <string>
#include <utility> #include <utility>
#include <vector> #include <vector>
TestConfigReader::TestConfigReader(TestConfig & config) TestConfigReader::TestConfigReader(TestConfig &config) : YamlReader(), config(config)
: YamlReader(), config(config) { {
consumers["lammps_version"] = &TestConfigReader::lammps_version; consumers["lammps_version"] = &TestConfigReader::lammps_version;
consumers["date_generated"] = &TestConfigReader::date_generated; consumers["date_generated"] = &TestConfigReader::date_generated;
consumers["epsilon"] = &TestConfigReader::epsilon; consumers["epsilon"] = &TestConfigReader::epsilon;
@ -57,7 +57,8 @@ TestConfigReader::TestConfigReader(TestConfig & config)
consumers["equilibrium"] = &TestConfigReader::equilibrium; consumers["equilibrium"] = &TestConfigReader::equilibrium;
} }
void TestConfigReader::prerequisites(const yaml_event_t & event) { void TestConfigReader::prerequisites(const yaml_event_t &event)
{
config.prerequisites.clear(); config.prerequisites.clear();
std::stringstream data((char *)event.data.scalar.value); std::stringstream data((char *)event.data.scalar.value);
std::string key, value; std::string key, value;
@ -69,7 +70,8 @@ void TestConfigReader::prerequisites(const yaml_event_t & event) {
} }
} }
void TestConfigReader::pre_commands(const yaml_event_t & event) { void TestConfigReader::pre_commands(const yaml_event_t &event)
{
config.pre_commands.clear(); config.pre_commands.clear();
std::stringstream data((char *)event.data.scalar.value); std::stringstream data((char *)event.data.scalar.value);
std::string line; std::string line;
@ -79,7 +81,8 @@ void TestConfigReader::pre_commands(const yaml_event_t & event) {
} }
} }
void TestConfigReader::post_commands(const yaml_event_t & event) { void TestConfigReader::post_commands(const yaml_event_t &event)
{
config.post_commands.clear(); config.post_commands.clear();
std::stringstream data((char *)event.data.scalar.value); std::stringstream data((char *)event.data.scalar.value);
std::string line; std::string line;
@ -89,23 +92,28 @@ 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; 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; 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); 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; 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(); config.extract.clear();
std::stringstream data((char *)event.data.scalar.value); std::stringstream data((char *)event.data.scalar.value);
std::string name; std::string name;
@ -117,29 +125,29 @@ void TestConfigReader::extract(const yaml_event_t & event) {
} }
} }
void TestConfigReader::natoms(const yaml_event_t & event) { void TestConfigReader::natoms(const yaml_event_t &event)
{
config.natoms = atoi((char *)event.data.scalar.value); 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; stress_t stress;
sscanf((char *)event.data.scalar.value, sscanf((char *)event.data.scalar.value, "%lg %lg %lg %lg %lg %lg", &stress.xx, &stress.yy,
"%lg %lg %lg %lg %lg %lg", &stress.zz, &stress.xy, &stress.xz, &stress.yz);
&stress.xx, &stress.yy, &stress.zz,
&stress.xy, &stress.xz, &stress.yz);
config.init_stress = stress; 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; stress_t stress;
sscanf((char *)event.data.scalar.value, sscanf((char *)event.data.scalar.value, "%lg %lg %lg %lg %lg %lg", &stress.xx, &stress.yy,
"%lg %lg %lg %lg %lg %lg", &stress.zz, &stress.xy, &stress.xz, &stress.yz);
&stress.xx, &stress.yy, &stress.zz,
&stress.xy, &stress.xz, &stress.yz);
config.run_stress = stress; 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.clear();
config.init_forces.resize(config.natoms + 1); config.init_forces.resize(config.natoms + 1);
std::stringstream data((const char *)event.data.scalar.value); std::stringstream data((const char *)event.data.scalar.value);
@ -153,7 +161,8 @@ 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.clear();
config.run_forces.resize(config.natoms + 1); config.run_forces.resize(config.natoms + 1);
std::stringstream data((char *)event.data.scalar.value); std::stringstream data((char *)event.data.scalar.value);
@ -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; 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(); config.pair_coeff.clear();
std::stringstream data((char *)event.data.scalar.value); std::stringstream data((char *)event.data.scalar.value);
std::string line; 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; 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(); config.bond_coeff.clear();
std::stringstream data((char *)event.data.scalar.value); std::stringstream data((char *)event.data.scalar.value);
std::string line; 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; 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(); config.angle_coeff.clear();
std::stringstream data((char *)event.data.scalar.value); std::stringstream data((char *)event.data.scalar.value);
std::string line; std::string line;
@ -209,7 +224,8 @@ 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); std::stringstream data((char *)event.data.scalar.value);
config.equilibrium.clear(); config.equilibrium.clear();
double value; double value;
@ -222,27 +238,32 @@ void TestConfigReader::equilibrium(const yaml_event_t & event) {
} }
} }
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); 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); 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); 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); 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); 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); config.run_energy = atof((char *)event.data.scalar.value);
} }

View File

@ -14,6 +14,7 @@
#ifndef TEST_CONFIG_READER_H #ifndef TEST_CONFIG_READER_H
#define TEST_CONFIG_READER_H #define TEST_CONFIG_READER_H
#include "test_config.h"
#include "yaml_reader.h" #include "yaml_reader.h"
class TestConfigReader : public YamlReader<TestConfigReader> { class TestConfigReader : public YamlReader<TestConfigReader> {

View File

@ -5,8 +5,9 @@
// include the implementation since ErrorStats is a standalone class // include the implementation since ErrorStats is a standalone class
// this way we don't have to link against the style_tests and lammps libs // this way we don't have to link against the style_tests and lammps libs
#include "error_stats.cpp" #include "error_stats.cpp"
#include "fmtlib_format.cpp"
#include "fmtlib_os.cpp"
TEST(ErrorStats, test) TEST(ErrorStats, test)
{ {
@ -25,7 +26,7 @@ TEST(ErrorStats, test)
std::stringstream out; std::stringstream out;
out << stats; 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(); stats.reset();
ASSERT_DOUBLE_EQ(stats.avg(), 0.0); ASSERT_DOUBLE_EQ(stats.avg(), 0.0);

View File

@ -16,16 +16,15 @@
#include "test_config_reader.h" #include "test_config_reader.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include <mpi.h>
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
#include <mpi.h>
// common read_yaml_file function // common read_yaml_file function
bool read_yaml_file(const char *infile, TestConfig &config) bool read_yaml_file(const char *infile, TestConfig &config)
{ {
auto reader = TestConfigReader(config); auto reader = TestConfigReader(config);
if (reader.parse_file(infile)) if (reader.parse_file(infile)) return false;
return false;
config.basename = reader.get_basename(); config.basename = reader.get_basename();
return true; return true;

View File

@ -17,9 +17,9 @@
#include "yaml.h" #include "yaml.h"
#include <cstdio> #include <cstdio>
#include <iostream>
#include <map> #include <map>
#include <string> #include <string>
#include <iostream>
template <typename ConsumerClass> class YamlReader { template <typename ConsumerClass> class YamlReader {
private: private:
@ -46,7 +46,8 @@ public:
std::string get_basename() const { return basename; } std::string get_basename() const { return basename; }
int parse_file(const std::string & infile) { int parse_file(const std::string &infile)
{
basename = infile; basename = infile;
std::size_t found = basename.rfind(".yaml"); std::size_t found = basename.rfind(".yaml");
if (found > 0) basename = basename.substr(0, found); if (found > 0) basename = basename.substr(0, found);
@ -58,8 +59,8 @@ public:
yaml_event_t event; yaml_event_t event;
if (!fp) { if (!fp) {
std::cerr << "Cannot open yaml file '" << infile std::cerr << "Cannot open yaml file '" << infile << "': " << strerror(errno)
<< "': " << strerror(errno) << std::endl; << std::endl;
return 1; return 1;
} }
yaml_parser_initialize(&parser); yaml_parser_initialize(&parser);
@ -76,8 +77,8 @@ public:
if (accepted) { if (accepted) {
if (!consume_key_value(key, event)) { if (!consume_key_value(key, event)) {
std::cerr << "Ignoring unknown key/value pair: " << key std::cerr << "Ignoring unknown key/value pair: " << key << " = "
<< " = " << event.data.scalar.value << std::endl; << event.data.scalar.value << std::endl;
} }
} }
yaml_event_delete(&event); yaml_event_delete(&event);
@ -89,7 +90,8 @@ public:
} }
protected: 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); auto it = consumers.find(key);
ConsumerClass *consumer = dynamic_cast<ConsumerClass *>(this); ConsumerClass *consumer = dynamic_cast<ConsumerClass *>(this);
@ -106,7 +108,8 @@ protected:
return false; return false;
} }
bool consume_event(yaml_event_t & event) { bool consume_event(yaml_event_t &event)
{
accepted = false; accepted = false;
switch (state) { switch (state) {
case START: case START:
@ -144,8 +147,7 @@ protected:
break; break;
default: default:
std::cerr << "UNHANDLED YAML EVENT (key): " << event.type std::cerr << "UNHANDLED YAML EVENT (key): " << event.type
<< "\nVALUE: " << event.data.scalar.value << "\nVALUE: " << event.data.scalar.value << std::endl;
<< std::endl;
state = ERROR; state = ERROR;
break; break;
} }
@ -159,8 +161,7 @@ protected:
break; break;
default: default:
std::cerr << "UNHANDLED YAML EVENT (value): " << event.type std::cerr << "UNHANDLED YAML EVENT (value): " << event.type
<< "\nVALUE: " << event.data.scalar.value << "\nVALUE: " << event.data.scalar.value << std::endl;
<< std::endl;
state = ERROR; state = ERROR;
break; break;
} }

View File

@ -14,10 +14,11 @@
#include "yaml_writer.h" #include "yaml_writer.h"
#include "yaml.h" #include "yaml.h"
#include <string>
#include <cstdio> #include <cstdio>
#include <string>
YamlWriter::YamlWriter(const char * outfile) { YamlWriter::YamlWriter(const char *outfile)
{
yaml_emitter_initialize(&emitter); yaml_emitter_initialize(&emitter);
fp = fopen(outfile, "w"); fp = fopen(outfile, "w");
if (!fp) { if (!fp) {
@ -31,13 +32,13 @@ YamlWriter::YamlWriter(const char * outfile) {
yaml_emitter_emit(&emitter, &event); yaml_emitter_emit(&emitter, &event);
yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0); yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
yaml_emitter_emit(&emitter, &event); yaml_emitter_emit(&emitter, &event);
yaml_mapping_start_event_initialize(&event, NULL, yaml_mapping_start_event_initialize(&event, NULL, (yaml_char_t *)YAML_MAP_TAG, 1,
(yaml_char_t *)YAML_MAP_TAG, YAML_ANY_MAPPING_STYLE);
1, YAML_ANY_MAPPING_STYLE);
yaml_emitter_emit(&emitter, &event); yaml_emitter_emit(&emitter, &event);
} }
YamlWriter::~YamlWriter() { YamlWriter::~YamlWriter()
{
yaml_mapping_end_event_initialize(&event); yaml_mapping_end_event_initialize(&event);
yaml_emitter_emit(&emitter, &event); yaml_emitter_emit(&emitter, &event);
yaml_document_end_event_initialize(&event, 0); yaml_document_end_event_initialize(&event, 0);
@ -48,84 +49,65 @@ YamlWriter::~YamlWriter() {
fclose(fp); fclose(fp);
} }
void YamlWriter::emit(const std::string &key, const double value) { void YamlWriter::emit(const std::string &key, const double value)
yaml_scalar_event_initialize(&event, NULL, {
(yaml_char_t *)YAML_STR_TAG, yaml_scalar_event_initialize(&event, NULL, (yaml_char_t *)YAML_STR_TAG,
(yaml_char_t *) key.c_str(), (yaml_char_t *)key.c_str(), key.size(), 1, 0,
key.size(), 1, 0,
YAML_PLAIN_SCALAR_STYLE); YAML_PLAIN_SCALAR_STYLE);
yaml_emitter_emit(&emitter, &event); yaml_emitter_emit(&emitter, &event);
char buf[256]; char buf[256];
snprintf(buf, 256, "%.15g", value); snprintf(buf, 256, "%.15g", value);
yaml_scalar_event_initialize(&event, NULL, yaml_scalar_event_initialize(&event, NULL, (yaml_char_t *)YAML_STR_TAG, (yaml_char_t *)buf,
(yaml_char_t *)YAML_STR_TAG, strlen(buf), 1, 0, YAML_PLAIN_SCALAR_STYLE);
(yaml_char_t *)buf,
strlen(buf), 1, 0,
YAML_PLAIN_SCALAR_STYLE);
yaml_emitter_emit(&emitter, &event); yaml_emitter_emit(&emitter, &event);
} }
void YamlWriter::emit(const std::string &key, const long value) { void YamlWriter::emit(const std::string &key, const long value)
yaml_scalar_event_initialize(&event, NULL, {
(yaml_char_t *)YAML_STR_TAG, yaml_scalar_event_initialize(&event, NULL, (yaml_char_t *)YAML_STR_TAG,
(yaml_char_t *) key.c_str(), (yaml_char_t *)key.c_str(), key.size(), 1, 0,
key.size(), 1, 0,
YAML_PLAIN_SCALAR_STYLE); YAML_PLAIN_SCALAR_STYLE);
yaml_emitter_emit(&emitter, &event); yaml_emitter_emit(&emitter, &event);
char buf[256]; char buf[256];
snprintf(buf, 256, "%ld", value); snprintf(buf, 256, "%ld", value);
yaml_scalar_event_initialize(&event, NULL, yaml_scalar_event_initialize(&event, NULL, (yaml_char_t *)YAML_STR_TAG, (yaml_char_t *)buf,
(yaml_char_t *)YAML_STR_TAG, strlen(buf), 1, 0, YAML_PLAIN_SCALAR_STYLE);
(yaml_char_t *)buf,
strlen(buf), 1, 0,
YAML_PLAIN_SCALAR_STYLE);
yaml_emitter_emit(&emitter, &event); yaml_emitter_emit(&emitter, &event);
} }
void YamlWriter::emit(const std::string &key, const int value) { void YamlWriter::emit(const std::string &key, const int value)
yaml_scalar_event_initialize(&event, NULL, {
(yaml_char_t *)YAML_STR_TAG, yaml_scalar_event_initialize(&event, NULL, (yaml_char_t *)YAML_STR_TAG,
(yaml_char_t *) key.c_str(), (yaml_char_t *)key.c_str(), key.size(), 1, 0,
key.size(), 1, 0,
YAML_PLAIN_SCALAR_STYLE); YAML_PLAIN_SCALAR_STYLE);
yaml_emitter_emit(&emitter, &event); yaml_emitter_emit(&emitter, &event);
char buf[256]; char buf[256];
snprintf(buf, 256, "%d", value); snprintf(buf, 256, "%d", value);
yaml_scalar_event_initialize(&event, NULL, yaml_scalar_event_initialize(&event, NULL, (yaml_char_t *)YAML_STR_TAG, (yaml_char_t *)buf,
(yaml_char_t *)YAML_STR_TAG, strlen(buf), 1, 0, YAML_PLAIN_SCALAR_STYLE);
(yaml_char_t *)buf,
strlen(buf), 1, 0,
YAML_PLAIN_SCALAR_STYLE);
yaml_emitter_emit(&emitter, &event); yaml_emitter_emit(&emitter, &event);
} }
void YamlWriter::emit(const std::string &key, const std::string &value) void YamlWriter::emit(const std::string &key, const std::string &value)
{ {
yaml_scalar_event_initialize(&event, NULL, yaml_scalar_event_initialize(&event, NULL, (yaml_char_t *)YAML_STR_TAG,
(yaml_char_t *)YAML_STR_TAG, (yaml_char_t *)key.c_str(), key.size(), 1, 0,
(yaml_char_t *) key.c_str(),
key.size(), 1, 0,
YAML_PLAIN_SCALAR_STYLE); YAML_PLAIN_SCALAR_STYLE);
yaml_emitter_emit(&emitter, &event); yaml_emitter_emit(&emitter, &event);
yaml_scalar_event_initialize(&event, NULL, yaml_scalar_event_initialize(&event, NULL, (yaml_char_t *)YAML_STR_TAG,
(yaml_char_t *)YAML_STR_TAG, (yaml_char_t *)value.c_str(), value.size(), 1, 0,
(yaml_char_t *)value.c_str(),
value.size(), 1, 0,
YAML_PLAIN_SCALAR_STYLE); YAML_PLAIN_SCALAR_STYLE);
yaml_emitter_emit(&emitter, &event); yaml_emitter_emit(&emitter, &event);
} }
void YamlWriter::emit_block(const std::string &key, const std::string &value) { 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_scalar_event_initialize(&event, NULL, (yaml_char_t *)YAML_STR_TAG,
(yaml_char_t *) key.c_str(), (yaml_char_t *)key.c_str(), key.size(), 1, 0,
key.size(), 1, 0,
YAML_PLAIN_SCALAR_STYLE); YAML_PLAIN_SCALAR_STYLE);
yaml_emitter_emit(&emitter, &event); yaml_emitter_emit(&emitter, &event);
yaml_scalar_event_initialize(&event, NULL, yaml_scalar_event_initialize(&event, NULL, (yaml_char_t *)YAML_STR_TAG,
(yaml_char_t *)YAML_STR_TAG, (yaml_char_t *)value.c_str(), value.size(), 1, 0,
(yaml_char_t *)value.c_str(),
value.size(), 1, 0,
YAML_LITERAL_SCALAR_STYLE); YAML_LITERAL_SCALAR_STYLE);
yaml_emitter_emit(&emitter, &event); yaml_emitter_emit(&emitter, &event);
} }

View File

@ -11,11 +11,11 @@
See the README file in the top-level LAMMPS directory. See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
#include "gmock/gmock.h" #include "MANYBODY/pair_eim.h"
#include "gtest/gtest.h"
#include "lammps.h" #include "lammps.h"
#include "utils.h" #include "utils.h"
#include "MANYBODY/pair_eim.h" #include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <mpi.h> #include <mpi.h>
@ -27,8 +27,10 @@ protected:
PairEIM::Setfl setfl; PairEIM::Setfl setfl;
static const int nelements = 9; static const int nelements = 9;
void SetUp() override { void SetUp() override
const char *args[] = {"PotentialFileReaderTest", "-log", "none", "-echo", "screen", "-nocite" }; {
const char *args[] = {
"PotentialFileReaderTest", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
@ -59,7 +61,8 @@ protected:
setfl.tp = new int[npair]; setfl.tp = new int[npair];
} }
void TearDown() override { void TearDown() override
{
delete[] setfl.ielement; delete[] setfl.ielement;
delete[] setfl.mass; delete[] setfl.mass;
delete[] setfl.negativity; delete[] setfl.negativity;
@ -88,7 +91,8 @@ protected:
} }
}; };
TEST_F(EIMPotentialFileReaderTest, global_line) { TEST_F(EIMPotentialFileReaderTest, global_line)
{
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
EIMPotentialFileReader reader(lmp, "ffield.eim"); EIMPotentialFileReader reader(lmp, "ffield.eim");
::testing::internal::GetCapturedStdout(); ::testing::internal::GetCapturedStdout();
@ -99,7 +103,8 @@ TEST_F(EIMPotentialFileReaderTest, global_line) {
ASSERT_DOUBLE_EQ(setfl.rsmall, 1.645); ASSERT_DOUBLE_EQ(setfl.rsmall, 1.645);
} }
TEST_F(EIMPotentialFileReaderTest, element_line_sequential) { TEST_F(EIMPotentialFileReaderTest, element_line_sequential)
{
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
EIMPotentialFileReader reader(lmp, "ffield.eim"); EIMPotentialFileReader reader(lmp, "ffield.eim");
::testing::internal::GetCapturedStdout(); ::testing::internal::GetCapturedStdout();
@ -123,7 +128,8 @@ TEST_F(EIMPotentialFileReaderTest, element_line_sequential) {
ASSERT_DOUBLE_EQ(setfl.q0[1], 0.0000e+00); ASSERT_DOUBLE_EQ(setfl.q0[1], 0.0000e+00);
} }
TEST_F(EIMPotentialFileReaderTest, element_line_random) { TEST_F(EIMPotentialFileReaderTest, element_line_random)
{
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
EIMPotentialFileReader reader(lmp, "ffield.eim"); EIMPotentialFileReader reader(lmp, "ffield.eim");
::testing::internal::GetCapturedStdout(); ::testing::internal::GetCapturedStdout();
@ -138,7 +144,8 @@ TEST_F(EIMPotentialFileReaderTest, element_line_random) {
ASSERT_DOUBLE_EQ(setfl.q0[0], 0.0000e+00); ASSERT_DOUBLE_EQ(setfl.q0[0], 0.0000e+00);
} }
TEST_F(EIMPotentialFileReaderTest, pair_line) { TEST_F(EIMPotentialFileReaderTest, pair_line)
{
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
EIMPotentialFileReader reader(lmp, "ffield.eim"); EIMPotentialFileReader reader(lmp, "ffield.eim");
::testing::internal::GetCapturedStdout(); ::testing::internal::GetCapturedStdout();
@ -160,7 +167,8 @@ TEST_F(EIMPotentialFileReaderTest, pair_line) {
ASSERT_EQ(setfl.tp[0], 1); ASSERT_EQ(setfl.tp[0], 1);
} }
TEST_F(EIMPotentialFileReaderTest, pair_identical) { TEST_F(EIMPotentialFileReaderTest, pair_identical)
{
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
EIMPotentialFileReader reader(lmp, "ffield.eim"); EIMPotentialFileReader reader(lmp, "ffield.eim");
::testing::internal::GetCapturedStdout(); ::testing::internal::GetCapturedStdout();

View File

@ -11,23 +11,23 @@
See the README file in the top-level LAMMPS directory. 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_comb.h"
#include "MANYBODY/pair_comb3.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.h"
#include "MANYBODY/pair_tersoff_mod.h" #include "MANYBODY/pair_tersoff_mod.h"
#include "MANYBODY/pair_tersoff_mod_c.h" #include "MANYBODY/pair_tersoff_mod_c.h"
#include "MANYBODY/pair_tersoff_zbl.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_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 <mpi.h> #include <mpi.h>
@ -49,8 +49,10 @@ class PotentialFileReaderTest : public ::testing::Test {
protected: protected:
LAMMPS *lmp; LAMMPS *lmp;
void SetUp() override { void SetUp() override
const char *args[] = {"PotentialFileReaderTest", "-log", "none", "-echo", "screen", "-nocite" }; {
const char *args[] = {
"PotentialFileReaderTest", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
@ -58,14 +60,16 @@ protected:
::testing::internal::GetCapturedStdout(); ::testing::internal::GetCapturedStdout();
} }
void TearDown() override { void TearDown() override
{
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
delete lmp; delete lmp;
::testing::internal::GetCapturedStdout(); ::testing::internal::GetCapturedStdout();
} }
}; };
TEST_F(PotentialFileReaderTest, Si) { TEST_F(PotentialFileReaderTest, Si)
{
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
PotentialFileReader reader(lmp, "Si.sw", "Stillinger-Weber"); PotentialFileReader reader(lmp, "Si.sw", "Stillinger-Weber");
::testing::internal::GetCapturedStdout(); ::testing::internal::GetCapturedStdout();
@ -74,7 +78,8 @@ TEST_F(PotentialFileReaderTest, Si) {
ASSERT_EQ(utils::count_words(line), PairSW::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairSW::NPARAMS_PER_LINE);
} }
TEST_F(PotentialFileReaderTest, Comb) { TEST_F(PotentialFileReaderTest, Comb)
{
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
PotentialFileReader reader(lmp, "ffield.comb", "COMB"); PotentialFileReader reader(lmp, "ffield.comb", "COMB");
::testing::internal::GetCapturedStdout(); ::testing::internal::GetCapturedStdout();
@ -83,7 +88,8 @@ TEST_F(PotentialFileReaderTest, Comb) {
ASSERT_EQ(utils::count_words(line), PairComb::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairComb::NPARAMS_PER_LINE);
} }
TEST_F(PotentialFileReaderTest, Comb3) { TEST_F(PotentialFileReaderTest, Comb3)
{
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
PotentialFileReader reader(lmp, "ffield.comb3", "COMB3"); PotentialFileReader reader(lmp, "ffield.comb3", "COMB3");
::testing::internal::GetCapturedStdout(); ::testing::internal::GetCapturedStdout();
@ -92,7 +98,8 @@ TEST_F(PotentialFileReaderTest, Comb3) {
ASSERT_EQ(utils::count_words(line), PairComb3::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairComb3::NPARAMS_PER_LINE);
} }
TEST_F(PotentialFileReaderTest, Tersoff) { TEST_F(PotentialFileReaderTest, Tersoff)
{
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
PotentialFileReader reader(lmp, "Si.tersoff", "Tersoff"); PotentialFileReader reader(lmp, "Si.tersoff", "Tersoff");
::testing::internal::GetCapturedStdout(); ::testing::internal::GetCapturedStdout();
@ -101,7 +108,8 @@ TEST_F(PotentialFileReaderTest, Tersoff) {
ASSERT_EQ(utils::count_words(line), PairTersoff::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairTersoff::NPARAMS_PER_LINE);
} }
TEST_F(PotentialFileReaderTest, TersoffMod) { TEST_F(PotentialFileReaderTest, TersoffMod)
{
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
PotentialFileReader reader(lmp, "Si.tersoff.mod", "Tersoff/Mod"); PotentialFileReader reader(lmp, "Si.tersoff.mod", "Tersoff/Mod");
::testing::internal::GetCapturedStdout(); ::testing::internal::GetCapturedStdout();
@ -110,7 +118,8 @@ TEST_F(PotentialFileReaderTest, TersoffMod) {
ASSERT_EQ(utils::count_words(line), PairTersoffMOD::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairTersoffMOD::NPARAMS_PER_LINE);
} }
TEST_F(PotentialFileReaderTest, TersoffModC) { TEST_F(PotentialFileReaderTest, TersoffModC)
{
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
PotentialFileReader reader(lmp, "Si.tersoff.modc", "Tersoff/ModC"); PotentialFileReader reader(lmp, "Si.tersoff.modc", "Tersoff/ModC");
::testing::internal::GetCapturedStdout(); ::testing::internal::GetCapturedStdout();
@ -119,7 +128,8 @@ TEST_F(PotentialFileReaderTest, TersoffModC) {
ASSERT_EQ(utils::count_words(line), PairTersoffMODC::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairTersoffMODC::NPARAMS_PER_LINE);
} }
TEST_F(PotentialFileReaderTest, TersoffZBL) { TEST_F(PotentialFileReaderTest, TersoffZBL)
{
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
PotentialFileReader reader(lmp, "SiC.tersoff.zbl", "Tersoff/ZBL"); PotentialFileReader reader(lmp, "SiC.tersoff.zbl", "Tersoff/ZBL");
::testing::internal::GetCapturedStdout(); ::testing::internal::GetCapturedStdout();
@ -128,7 +138,8 @@ TEST_F(PotentialFileReaderTest, TersoffZBL) {
ASSERT_EQ(utils::count_words(line), PairTersoffZBL::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairTersoffZBL::NPARAMS_PER_LINE);
} }
TEST_F(PotentialFileReaderTest, GW) { TEST_F(PotentialFileReaderTest, GW)
{
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
PotentialFileReader reader(lmp, "SiC.gw", "GW"); PotentialFileReader reader(lmp, "SiC.gw", "GW");
::testing::internal::GetCapturedStdout(); ::testing::internal::GetCapturedStdout();
@ -137,7 +148,8 @@ TEST_F(PotentialFileReaderTest, GW) {
ASSERT_EQ(utils::count_words(line), PairGW::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairGW::NPARAMS_PER_LINE);
} }
TEST_F(PotentialFileReaderTest, GWZBL) { TEST_F(PotentialFileReaderTest, GWZBL)
{
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
PotentialFileReader reader(lmp, "SiC.gw.zbl", "GW/ZBL"); PotentialFileReader reader(lmp, "SiC.gw.zbl", "GW/ZBL");
::testing::internal::GetCapturedStdout(); ::testing::internal::GetCapturedStdout();
@ -146,7 +158,8 @@ TEST_F(PotentialFileReaderTest, GWZBL) {
ASSERT_EQ(utils::count_words(line), PairGWZBL::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairGWZBL::NPARAMS_PER_LINE);
} }
TEST_F(PotentialFileReaderTest, Nb3bHarmonic) { TEST_F(PotentialFileReaderTest, Nb3bHarmonic)
{
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
PotentialFileReader reader(lmp, "MOH.nb3b.harmonic", "NB3B Harmonic"); PotentialFileReader reader(lmp, "MOH.nb3b.harmonic", "NB3B Harmonic");
::testing::internal::GetCapturedStdout(); ::testing::internal::GetCapturedStdout();
@ -155,7 +168,8 @@ TEST_F(PotentialFileReaderTest, Nb3bHarmonic) {
ASSERT_EQ(utils::count_words(line), PairNb3bHarmonic::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairNb3bHarmonic::NPARAMS_PER_LINE);
} }
TEST_F(PotentialFileReaderTest, Vashishta) { TEST_F(PotentialFileReaderTest, Vashishta)
{
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
PotentialFileReader reader(lmp, "SiC.vashishta", "Vashishta"); PotentialFileReader reader(lmp, "SiC.vashishta", "Vashishta");
::testing::internal::GetCapturedStdout(); ::testing::internal::GetCapturedStdout();

View File

@ -11,37 +11,41 @@
See the README file in the top-level LAMMPS directory. 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 "fmt/format.h"
#include <string> #include "lmptype.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <exception> #include <exception>
#include <string>
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
using ::testing::Eq; using ::testing::Eq;
// this tests a subset of {fmt} that is most relevant to LAMMPS // this tests a subset of {fmt} that is most relevant to LAMMPS
TEST(FmtLib, insert_string) { TEST(FmtLib, insert_string)
{
const char val[] = "word"; const char val[] = "word";
auto text = fmt::format("word {}", val); auto text = fmt::format("word {}", val);
ASSERT_THAT(text, Eq("word word")); ASSERT_THAT(text, Eq("word word"));
} }
TEST(FmtLib, insert_int) { TEST(FmtLib, insert_int)
{
const int val = 333; const int val = 333;
auto text = fmt::format("word {}", val); auto text = fmt::format("word {}", val);
ASSERT_THAT(text, Eq("word 333")); ASSERT_THAT(text, Eq("word 333"));
} }
TEST(FmtLib, insert_neg_int) { TEST(FmtLib, insert_neg_int)
{
const int val = -333; const int val = -333;
auto text = fmt::format("word {}", val); auto text = fmt::format("word {}", val);
ASSERT_THAT(text, Eq("word -333")); ASSERT_THAT(text, Eq("word -333"));
} }
TEST(FmtLib, insert_bigint) { TEST(FmtLib, insert_bigint)
{
#if defined(LAMMPS_BIGBIG) || defined(LAMMPS_SMALLBIG) #if defined(LAMMPS_BIGBIG) || defined(LAMMPS_SMALLBIG)
const bigint val = 9945234592L; const bigint val = 9945234592L;
auto text = fmt::format("word {}", val); auto text = fmt::format("word {}", val);
@ -51,7 +55,8 @@ TEST(FmtLib, insert_bigint) {
#endif #endif
} }
TEST(FmtLib, insert_neg_bigint) { TEST(FmtLib, insert_neg_bigint)
{
#if defined(LAMMPS_BIGBIG) || defined(LAMMPS_SMALLBIG) #if defined(LAMMPS_BIGBIG) || defined(LAMMPS_SMALLBIG)
const bigint val = -9945234592L; const bigint val = -9945234592L;
auto text = fmt::format("word {}", val); auto text = fmt::format("word {}", val);
@ -61,7 +66,8 @@ TEST(FmtLib, insert_neg_bigint) {
#endif #endif
} }
TEST(FmtLib, insert_tagint) { TEST(FmtLib, insert_tagint)
{
#if defined(LAMMPS_BIGBIG) #if defined(LAMMPS_BIGBIG)
const tagint val = 9945234592L; const tagint val = 9945234592L;
auto text = fmt::format("word {}", val); auto text = fmt::format("word {}", val);
@ -71,7 +77,8 @@ TEST(FmtLib, insert_tagint) {
#endif #endif
} }
TEST(FmtLib, insert_neg_tagint) { TEST(FmtLib, insert_neg_tagint)
{
#if defined(LAMMPS_BIGBIG) #if defined(LAMMPS_BIGBIG)
const tagint val = -9945234592L; const tagint val = -9945234592L;
auto text = fmt::format("word {}", val); auto text = fmt::format("word {}", val);
@ -81,7 +88,8 @@ TEST(FmtLib, insert_neg_tagint) {
#endif #endif
} }
TEST(FmtLib, insert_imageint) { TEST(FmtLib, insert_imageint)
{
#if defined(LAMMPS_BIGBIG) #if defined(LAMMPS_BIGBIG)
const imageint val = 9945234592L; const imageint val = 9945234592L;
auto text = fmt::format("word {}", val); auto text = fmt::format("word {}", val);
@ -91,7 +99,8 @@ TEST(FmtLib, insert_imageint) {
#endif #endif
} }
TEST(FmtLib, insert_neg_imageint) { TEST(FmtLib, insert_neg_imageint)
{
#if defined(LAMMPS_BIGBIG) #if defined(LAMMPS_BIGBIG)
const imageint val = -9945234592L; const imageint val = -9945234592L;
auto text = fmt::format("word {}", val); auto text = fmt::format("word {}", val);
@ -101,24 +110,28 @@ TEST(FmtLib, insert_neg_imageint) {
#endif #endif
} }
TEST(FmtLib, insert_double) { TEST(FmtLib, insert_double)
{
const double val = 1.5; const double val = 1.5;
auto text = fmt::format("word {}", val); auto text = fmt::format("word {}", val);
ASSERT_THAT(text, Eq("word 1.5")); ASSERT_THAT(text, Eq("word 1.5"));
} }
TEST(FmtLib, insert_neg_double) { TEST(FmtLib, insert_neg_double)
{
const double val = -1.5; const double val = -1.5;
auto text = fmt::format("word {}", val); auto text = fmt::format("word {}", val);
ASSERT_THAT(text, Eq("word -1.5")); ASSERT_THAT(text, Eq("word -1.5"));
} }
TEST(FmtLib, int_for_double) { TEST(FmtLib, int_for_double)
{
const double val = -1.5; 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; const int val = 15;
ASSERT_THROW(fmt::format("word {:g}", val), std::exception); ASSERT_THROW(fmt::format("word {:g}", val), std::exception);
} }

View File

@ -11,100 +11,117 @@
See the README file in the top-level LAMMPS directory. See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "tokenizer.h" #include "tokenizer.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
using ::testing::Eq; using ::testing::Eq;
TEST(Tokenizer, empty_string) { TEST(Tokenizer, empty_string)
{
Tokenizer t("", " "); Tokenizer t("", " ");
ASSERT_EQ(t.count(), 0); ASSERT_EQ(t.count(), 0);
} }
TEST(Tokenizer, whitespace_only) { TEST(Tokenizer, whitespace_only)
{
Tokenizer t(" ", " "); Tokenizer t(" ", " ");
ASSERT_EQ(t.count(), 0); ASSERT_EQ(t.count(), 0);
} }
TEST(Tokenizer, single_word) { TEST(Tokenizer, single_word)
{
Tokenizer t("test", " "); Tokenizer t("test", " ");
ASSERT_EQ(t.count(), 1); ASSERT_EQ(t.count(), 1);
} }
TEST(Tokenizer, two_words) { TEST(Tokenizer, two_words)
{
Tokenizer t("test word", " "); Tokenizer t("test word", " ");
ASSERT_EQ(t.count(), 2); ASSERT_EQ(t.count(), 2);
} }
TEST(Tokenizer, prefix_separators) { TEST(Tokenizer, prefix_separators)
{
Tokenizer t(" test word", " "); Tokenizer t(" test word", " ");
ASSERT_EQ(t.count(), 2); ASSERT_EQ(t.count(), 2);
} }
TEST(Tokenizer, postfix_separators) { TEST(Tokenizer, postfix_separators)
{
Tokenizer t("test word ", " "); Tokenizer t("test word ", " ");
ASSERT_EQ(t.count(), 2); ASSERT_EQ(t.count(), 2);
} }
TEST(Tokenizer, iterate_words) { TEST(Tokenizer, iterate_words)
{
Tokenizer t(" test word ", " "); Tokenizer t(" test word ", " ");
ASSERT_THAT(t.next(), Eq("test")); ASSERT_THAT(t.next(), Eq("test"));
ASSERT_THAT(t.next(), Eq("word")); ASSERT_THAT(t.next(), Eq("word"));
ASSERT_EQ(t.count(), 2); ASSERT_EQ(t.count(), 2);
} }
TEST(Tokenizer, default_separators) { TEST(Tokenizer, default_separators)
{
Tokenizer t(" \r\n test \t word \f"); Tokenizer t(" \r\n test \t word \f");
ASSERT_THAT(t.next(), Eq("test")); ASSERT_THAT(t.next(), Eq("test"));
ASSERT_THAT(t.next(), Eq("word")); ASSERT_THAT(t.next(), Eq("word"));
ASSERT_EQ(t.count(), 2); ASSERT_EQ(t.count(), 2);
} }
TEST(Tokenizer, as_vector) { TEST(Tokenizer, as_vector)
{
Tokenizer t(" \r\n test \t word \f"); Tokenizer t(" \r\n test \t word \f");
std::vector<std::string> list = t.as_vector(); std::vector<std::string> list = t.as_vector();
ASSERT_THAT(list[0], Eq("test")); ASSERT_THAT(list[0], Eq("test"));
ASSERT_THAT(list[1], Eq("word")); ASSERT_THAT(list[1], Eq("word"));
} }
TEST(ValueTokenizer, empty_string) { TEST(ValueTokenizer, empty_string)
{
ValueTokenizer values(""); ValueTokenizer values("");
ASSERT_FALSE(values.has_next()); ASSERT_FALSE(values.has_next());
} }
TEST(ValueTokenizer, bad_integer) { TEST(ValueTokenizer, bad_integer)
{
ValueTokenizer values("f10"); ValueTokenizer values("f10");
ASSERT_THROW(values.next_int(), InvalidIntegerException); ASSERT_THROW(values.next_int(), InvalidIntegerException);
} }
TEST(ValueTokenizer, bad_double) { TEST(ValueTokenizer, bad_double)
{
ValueTokenizer values("1a.0"); ValueTokenizer values("1a.0");
ASSERT_THROW(values.next_double(), InvalidFloatException); ASSERT_THROW(values.next_double(), InvalidFloatException);
} }
TEST(ValueTokenizer, valid_int) { TEST(ValueTokenizer, valid_int)
{
ValueTokenizer values("10"); ValueTokenizer values("10");
ASSERT_EQ(values.next_int(), 10); ASSERT_EQ(values.next_int(), 10);
} }
TEST(ValueTokenizer, valid_tagint) { TEST(ValueTokenizer, valid_tagint)
{
ValueTokenizer values("42"); ValueTokenizer values("42");
ASSERT_EQ(values.next_tagint(), 42); ASSERT_EQ(values.next_tagint(), 42);
} }
TEST(ValueTokenizer, valid_bigint) { TEST(ValueTokenizer, valid_bigint)
{
ValueTokenizer values("42"); ValueTokenizer values("42");
ASSERT_EQ(values.next_bigint(), 42); ASSERT_EQ(values.next_bigint(), 42);
} }
TEST(ValueTokenizer, valid_double) { TEST(ValueTokenizer, valid_double)
{
ValueTokenizer values("3.14"); ValueTokenizer values("3.14");
ASSERT_DOUBLE_EQ(values.next_double(), 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"); ValueTokenizer values("3.14e22");
ASSERT_DOUBLE_EQ(values.next_double(), 3.14e22); ASSERT_DOUBLE_EQ(values.next_double(), 3.14e22);
} }

View File

@ -11,215 +11,265 @@
See the README file in the top-level LAMMPS directory. See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "utils.h" #include "utils.h"
#include <string> #include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <cerrno> #include <cerrno>
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <string>
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
using ::testing::Eq; using ::testing::Eq;
TEST(Utils, trim_comment) { TEST(Utils, trim_comment)
{
auto trimmed = utils::trim_comment("some text # comment"); auto trimmed = utils::trim_comment("some text # comment");
ASSERT_THAT(trimmed, Eq("some text ")); ASSERT_THAT(trimmed, Eq("some text "));
} }
TEST(Utils, count_words) { TEST(Utils, count_words)
{
ASSERT_EQ(utils::count_words("some text # comment"), 4); 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); 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); 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); ASSERT_EQ(utils::count_words(" some text # comment "), 4);
} }
TEST(Utils, valid_integer1) { TEST(Utils, valid_integer1)
{
ASSERT_TRUE(utils::is_integer("10")); ASSERT_TRUE(utils::is_integer("10"));
} }
TEST(Utils, valid_integer2) { TEST(Utils, valid_integer2)
{
ASSERT_TRUE(utils::is_integer("-10")); ASSERT_TRUE(utils::is_integer("-10"));
} }
TEST(Utils, valid_integer3) { TEST(Utils, valid_integer3)
{
ASSERT_TRUE(utils::is_integer("+10")); ASSERT_TRUE(utils::is_integer("+10"));
} }
TEST(Utils, valid_double1) { TEST(Utils, valid_double1)
{
ASSERT_TRUE(utils::is_double("10.0")); ASSERT_TRUE(utils::is_double("10.0"));
} }
TEST(Utils, valid_double2) { TEST(Utils, valid_double2)
{
ASSERT_TRUE(utils::is_double("1.")); ASSERT_TRUE(utils::is_double("1."));
} }
TEST(Utils, valid_double3) { TEST(Utils, valid_double3)
{
ASSERT_TRUE(utils::is_double(".0")); ASSERT_TRUE(utils::is_double(".0"));
} }
TEST(Utils, valid_double4) { TEST(Utils, valid_double4)
{
ASSERT_TRUE(utils::is_double("-10.0")); ASSERT_TRUE(utils::is_double("-10.0"));
} }
TEST(Utils, valid_double5) { TEST(Utils, valid_double5)
{
ASSERT_TRUE(utils::is_double("-1.")); ASSERT_TRUE(utils::is_double("-1."));
} }
TEST(Utils, valid_double6) { TEST(Utils, valid_double6)
{
ASSERT_TRUE(utils::is_double("-.0")); ASSERT_TRUE(utils::is_double("-.0"));
} }
TEST(Utils, valid_double7) { TEST(Utils, valid_double7)
{
ASSERT_TRUE(utils::is_double("+10.0")); ASSERT_TRUE(utils::is_double("+10.0"));
} }
TEST(Utils, valid_double8) { TEST(Utils, valid_double8)
{
ASSERT_TRUE(utils::is_double("+1.")); ASSERT_TRUE(utils::is_double("+1."));
} }
TEST(Utils, valid_double9) { TEST(Utils, valid_double9)
{
ASSERT_TRUE(utils::is_double("+.0")); ASSERT_TRUE(utils::is_double("+.0"));
} }
TEST(Utils, empty_not_an_integer) { TEST(Utils, empty_not_an_integer)
{
ASSERT_FALSE(utils::is_integer("")); ASSERT_FALSE(utils::is_integer(""));
} }
TEST(Utils, empty_not_a_double) { TEST(Utils, empty_not_a_double)
{
ASSERT_FALSE(utils::is_double("")); ASSERT_FALSE(utils::is_double(""));
} }
TEST(Utils, text_not_an_integer) { TEST(Utils, text_not_an_integer)
{
ASSERT_FALSE(utils::is_integer("one")); ASSERT_FALSE(utils::is_integer("one"));
} }
TEST(Utils, text_not_a_double) { TEST(Utils, text_not_a_double)
{
ASSERT_FALSE(utils::is_double("half")); 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")); 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")); ASSERT_FALSE(utils::is_integer(".0"));
} }
TEST(Utils, double_not_an_integer3) { TEST(Utils, double_not_an_integer3)
{
ASSERT_FALSE(utils::is_integer("1.")); ASSERT_FALSE(utils::is_integer("1."));
} }
TEST(Utils, integer_is_double1) { TEST(Utils, integer_is_double1)
{
ASSERT_TRUE(utils::is_double("10")); ASSERT_TRUE(utils::is_double("10"));
} }
TEST(Utils, integer_is_double2) { TEST(Utils, integer_is_double2)
{
ASSERT_TRUE(utils::is_double("-10")); ASSERT_TRUE(utils::is_double("-10"));
} }
TEST(Utils, is_double_with_exponential) { TEST(Utils, is_double_with_exponential)
{
ASSERT_TRUE(utils::is_double("+1e02")); 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")); 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")); 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")); 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")); 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")); 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")); ASSERT_FALSE(utils::is_double("-10D-22"));
} }
TEST(Utils, strmatch_beg) { TEST(Utils, strmatch_beg)
{
ASSERT_TRUE(utils::strmatch("rigid/small/omp", "^rigid")); ASSERT_TRUE(utils::strmatch("rigid/small/omp", "^rigid"));
} }
TEST(Utils, strmatch_mid1) { TEST(Utils, strmatch_mid1)
{
ASSERT_TRUE(utils::strmatch("rigid/small/omp", "small")); ASSERT_TRUE(utils::strmatch("rigid/small/omp", "small"));
} }
TEST(Utils, strmatch_mid2) { TEST(Utils, strmatch_mid2)
{
ASSERT_TRUE(utils::strmatch("rigid/small/omp", "omp")); ASSERT_TRUE(utils::strmatch("rigid/small/omp", "omp"));
} }
TEST(Utils, strmatch_end) { TEST(Utils, strmatch_end)
{
ASSERT_TRUE(utils::strmatch("rigid/small/omp", "/omp$")); ASSERT_TRUE(utils::strmatch("rigid/small/omp", "/omp$"));
} }
TEST(Utils, no_strmatch_beg) { TEST(Utils, no_strmatch_beg)
{
ASSERT_FALSE(utils::strmatch("rigid/small/omp", "^small")); ASSERT_FALSE(utils::strmatch("rigid/small/omp", "^small"));
} }
TEST(Utils, no_strmatch_mid) { TEST(Utils, no_strmatch_mid)
{
ASSERT_FALSE(utils::strmatch("rigid/small/omp", "none")); ASSERT_FALSE(utils::strmatch("rigid/small/omp", "none"));
} }
TEST(Utils, no_strmatch_end) { TEST(Utils, no_strmatch_end)
{
ASSERT_FALSE(utils::strmatch("rigid/small/omp", "/opt$")); ASSERT_FALSE(utils::strmatch("rigid/small/omp", "/opt$"));
} }
TEST(Utils, strmatch_whole_line) { TEST(Utils, strmatch_whole_line)
{
ASSERT_TRUE(utils::strmatch("ITEM: UNITS\n", "^\\s*ITEM: UNITS\\s*$")); ASSERT_TRUE(utils::strmatch("ITEM: UNITS\n", "^\\s*ITEM: UNITS\\s*$"));
} }
TEST(Utils, no_strmatch_whole_line) { TEST(Utils, no_strmatch_whole_line)
{
ASSERT_FALSE(utils::strmatch("ITEM: UNITS\n", "^\\s*ITEM: UNIT\\s*$")); ASSERT_FALSE(utils::strmatch("ITEM: UNITS\n", "^\\s*ITEM: UNIT\\s*$"));
} }
TEST(Utils, strmatch_integer_in_line) { TEST(Utils, strmatch_integer_in_line)
{
ASSERT_TRUE(utils::strmatch(" 5 angles\n", "^\\s*\\d+\\s+angles\\s")); ASSERT_TRUE(utils::strmatch(" 5 angles\n", "^\\s*\\d+\\s+angles\\s"));
} }
TEST(Utils, strmatch_float_in_line) { TEST(Utils, strmatch_float_in_line)
{
ASSERT_TRUE(utils::strmatch(" 5.0 angles\n", "^\\s*\\f+\\s+angles\\s")); ASSERT_TRUE(utils::strmatch(" 5.0 angles\n", "^\\s*\\f+\\s+angles\\s"));
} }
TEST(Utils, strmatch_int_as_float_in_line) { TEST(Utils, strmatch_int_as_float_in_line)
{
ASSERT_TRUE(utils::strmatch(" 5 angles\n", "^\\s*\\f+\\s+angles\\s")); ASSERT_TRUE(utils::strmatch(" 5 angles\n", "^\\s*\\f+\\s+angles\\s"));
} }
TEST(Utils, strmatch_char_range) { TEST(Utils, strmatch_char_range)
{
ASSERT_TRUE(utils::strmatch("rigid", "^[ip-s]+gid")); ASSERT_TRUE(utils::strmatch("rigid", "^[ip-s]+gid"));
} }
TEST(Utils, strmatch_opt_range) { TEST(Utils, strmatch_opt_range)
{
ASSERT_TRUE(utils::strmatch("rigid", "^[0-9]*[p-s]igid")); ASSERT_TRUE(utils::strmatch("rigid", "^[0-9]*[p-s]igid"));
} }
TEST(Utils, path_join) { TEST(Utils, path_join)
{
#if defined(_WIN32) #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 #else
ASSERT_THAT(utils::path_join("/parent/folder", "filename"), Eq("/parent/folder/filename")); ASSERT_THAT(utils::path_join("/parent/folder", "filename"), Eq("/parent/folder/filename"));
#endif #endif
} }
TEST(Utils, path_basename) { TEST(Utils, path_basename)
{
#if defined(_WIN32) #if defined(_WIN32)
ASSERT_THAT(utils::path_basename("c:\\parent\\folder\\filename"), Eq("filename")); ASSERT_THAT(utils::path_basename("c:\\parent\\folder\\filename"), Eq("filename"));
#else #else
@ -227,7 +277,8 @@ TEST(Utils, path_basename) {
#endif #endif
} }
TEST(Utils, getsyserror) { TEST(Utils, getsyserror)
{
#if defined(__linux__) #if defined(__linux__)
errno = ENOENT; errno = ENOENT;
std::string errmesg = utils::getsyserror(); std::string errmesg = utils::getsyserror();
@ -237,11 +288,12 @@ TEST(Utils, getsyserror) {
#endif #endif
} }
TEST(Utils, potential_file) { TEST(Utils, potential_file)
{
FILE *fp; FILE *fp;
fp = fopen("ctest1.txt", "w"); fp = fopen("ctest1.txt", "w");
ASSERT_NE(fp, nullptr); ASSERT_NE(fp, nullptr);
fputs("# DATE: 2020-02-20 CONTRIBUTOR: Nessuno UNITS: real\n",fp); fputs("# DATE: 2020-02-20 UNITS: real CONTRIBUTOR: Nessuno\n", fp);
fclose(fp); fclose(fp);
fp = fopen("ctest2.txt", "w"); fp = fopen("ctest2.txt", "w");
ASSERT_NE(fp, nullptr); ASSERT_NE(fp, nullptr);