Merge branch 'test-compute-chunk' into collected-small-changes
This commit is contained in:
@ -906,7 +906,11 @@ void ComputeChunkAtom::assign_chunk_ids()
|
||||
|
||||
// update region if necessary
|
||||
|
||||
if (regionflag) region->prematch();
|
||||
if (regionflag) {
|
||||
region = domain->get_region_by_id(idregion);
|
||||
if (!region) error->all(FLERR, "Region {} for compute chunk/atom does not exist", idregion);
|
||||
region->prematch();
|
||||
}
|
||||
|
||||
// exclude = 1 if atom is not assigned to a chunk
|
||||
// exclude atoms not in group or not in optional region
|
||||
|
||||
@ -32,8 +32,7 @@ using namespace LAMMPS_NS;
|
||||
|
||||
ComputeChunkSpreadAtom::
|
||||
ComputeChunkSpreadAtom(LAMMPS *lmp, int narg, char **arg) :
|
||||
Compute(lmp, narg, arg),
|
||||
idchunk(nullptr), ids(nullptr), which(nullptr), argindex(nullptr), value2index(nullptr)
|
||||
Compute(lmp, narg, arg), idchunk(nullptr)
|
||||
{
|
||||
if (narg < 5) error->all(FLERR,"Illegal compute chunk/spread/atom command");
|
||||
|
||||
@ -54,32 +53,27 @@ ComputeChunkSpreadAtom(LAMMPS *lmp, int narg, char **arg) :
|
||||
|
||||
// parse values
|
||||
|
||||
which = new int[nargnew];
|
||||
argindex = new int[nargnew];
|
||||
ids = new char*[nargnew];
|
||||
value2index = new int[nargnew];
|
||||
nvalues = 0;
|
||||
|
||||
for (iarg = 0; iarg < nargnew; iarg++) {
|
||||
ids[nvalues] = nullptr;
|
||||
|
||||
values.clear();
|
||||
for (iarg = 0; iarg < nargnew; ++iarg) {
|
||||
ArgInfo argi(arg[iarg], ArgInfo::COMPUTE|ArgInfo::FIX);
|
||||
|
||||
which[nvalues] = argi.get_type();
|
||||
argindex[nvalues] = argi.get_index1();
|
||||
ids[nvalues] = argi.copy_name();
|
||||
value_t val;
|
||||
val.which = argi.get_type();
|
||||
val.argindex = argi.get_index1();
|
||||
val.id = argi.get_name();
|
||||
val.val.c = nullptr;
|
||||
|
||||
if ((which[nvalues] == ArgInfo::UNKNOWN) || (which[nvalues] == ArgInfo::NONE)
|
||||
if ((val.which == ArgInfo::UNKNOWN) || (val.which == ArgInfo::NONE)
|
||||
|| (argi.get_dim() > 1))
|
||||
error->all(FLERR,"Illegal compute chunk/spread/atom command");
|
||||
error->all(FLERR,"Illegal compute chunk/spread/atom argument: {}", arg[iarg]);
|
||||
|
||||
nvalues++;
|
||||
values.push_back(val);
|
||||
}
|
||||
|
||||
// if wildcard expansion occurred, free earg memory from expand_args()
|
||||
|
||||
if (expand) {
|
||||
for (int i = 0; i < nargnew; i++) delete [] earg[i];
|
||||
for (int i = 0; i < nargnew; i++) delete[] earg[i];
|
||||
memory->sfree(earg);
|
||||
}
|
||||
|
||||
@ -87,38 +81,45 @@ ComputeChunkSpreadAtom(LAMMPS *lmp, int narg, char **arg) :
|
||||
// for compute, must calculate per-chunk values, i.e. style ends in "/chunk"
|
||||
// for fix, assume a global vector or array is per-chunk data
|
||||
|
||||
for (int i = 0; i < nvalues; i++) {
|
||||
if (which[i] == ArgInfo::COMPUTE) {
|
||||
auto icompute = modify->get_compute_by_id(ids[i]);
|
||||
for (auto &val : values) {
|
||||
if (val.which == ArgInfo::COMPUTE) {
|
||||
auto icompute = modify->get_compute_by_id(val.id);
|
||||
if (!icompute)
|
||||
error->all(FLERR,"Compute ID {} for compute chunk/spread/atom does not exist", ids[i]);
|
||||
error->all(FLERR,"Compute ID {} for compute chunk/spread/atom does not exist", val.id);
|
||||
|
||||
if (!utils::strmatch(icompute->style,"/chunk$"))
|
||||
error->all(FLERR,"Compute for compute chunk/spread/atom "
|
||||
"does not calculate per-chunk values");
|
||||
error->all(FLERR,"Compute chunk/spread/atom compute {} does not calculate per-chunk values",
|
||||
val.id);
|
||||
|
||||
if (argindex[i] == 0) {
|
||||
if (val.argindex == 0) {
|
||||
if (!icompute->vector_flag)
|
||||
error->all(FLERR,"Compute chunk/spread/atom compute does not calculate global vector");
|
||||
error->all(FLERR,"Compute chunk/spread/atom compute {} does not calculate global vector",
|
||||
val.id);
|
||||
} else {
|
||||
if (!icompute->array_flag)
|
||||
error->all(FLERR,"Compute chunk/spread/atom compute does not calculate global array");
|
||||
if (argindex[i] > icompute->size_array_cols)
|
||||
error->all(FLERR,"Compute chunk/spread/atom compute array is accessed out-of-range");
|
||||
error->all(FLERR,"Compute chunk/spread/atom compute {} does not calculate global array",
|
||||
val.id);
|
||||
if (val.argindex > icompute->size_array_cols)
|
||||
error->all(FLERR,"Compute chunk/spread/atom compute {} array is accessed out-of-range",
|
||||
val.id);
|
||||
}
|
||||
val.val.c = icompute;
|
||||
|
||||
} else if (which[i] == ArgInfo::FIX) {
|
||||
auto ifix = modify->get_fix_by_id(ids[i]);
|
||||
} else if (val.which == ArgInfo::FIX) {
|
||||
auto ifix = modify->get_fix_by_id(val.id);
|
||||
if (ifix)
|
||||
error->all(FLERR,"Fix ID {} for compute chunk/spread/atom does not exist", ids[i]);
|
||||
if (argindex[i] == 0) {
|
||||
error->all(FLERR,"Fix ID {} for compute chunk/spread/atom does not exist", val.id);
|
||||
if (val.argindex == 0) {
|
||||
if (!ifix->vector_flag)
|
||||
error->all(FLERR,"Compute chunk/spread/atom fix does not calculate global vector");
|
||||
error->all(FLERR,"Compute chunk/spread/atom {} fix does not calculate global vector",
|
||||
val.id);
|
||||
} else {
|
||||
if (!ifix->array_flag)
|
||||
error->all(FLERR,"Compute chunk/spread/atom fix does not calculate global array");
|
||||
if (argindex[i] > ifix->size_array_cols)
|
||||
error->all(FLERR,"Compute chunk/spread/atom fix array is accessed out-of-range");
|
||||
error->all(FLERR,"Compute chunk/spread/atom {} fix does not calculate global array",
|
||||
val.id);
|
||||
if (val.argindex > ifix->size_array_cols)
|
||||
error->all(FLERR,"Compute chunk/spread/atom fix {} array is accessed out-of-range",
|
||||
val.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -126,8 +127,8 @@ ComputeChunkSpreadAtom(LAMMPS *lmp, int narg, char **arg) :
|
||||
// this compute produces a peratom vector or array
|
||||
|
||||
peratom_flag = 1;
|
||||
if (nvalues == 1) size_peratom_cols = 0;
|
||||
else size_peratom_cols = nvalues;
|
||||
if (values.size() == 1) size_peratom_cols = 0;
|
||||
else size_peratom_cols = values.size();
|
||||
|
||||
// per-atom vector or array
|
||||
|
||||
@ -140,13 +141,7 @@ ComputeChunkSpreadAtom(LAMMPS *lmp, int narg, char **arg) :
|
||||
|
||||
ComputeChunkSpreadAtom::~ComputeChunkSpreadAtom()
|
||||
{
|
||||
delete [] idchunk;
|
||||
|
||||
delete [] which;
|
||||
delete [] argindex;
|
||||
for (int i = 0; i < nvalues; i++) delete [] ids[i];
|
||||
delete [] ids;
|
||||
delete [] value2index;
|
||||
delete[] idchunk;
|
||||
|
||||
memory->destroy(vector_atom);
|
||||
memory->destroy(array_atom);
|
||||
@ -160,18 +155,16 @@ void ComputeChunkSpreadAtom::init()
|
||||
|
||||
// set indices of all computes,fixes,variables
|
||||
|
||||
for (int m = 0; m < nvalues; m++) {
|
||||
if (which[m] == ArgInfo::COMPUTE) {
|
||||
int icompute = modify->find_compute(ids[m]);
|
||||
if (icompute < 0)
|
||||
error->all(FLERR,"Compute ID {} for compute chunk/spread/atom does not exist", ids[m]);
|
||||
value2index[m] = icompute;
|
||||
for (auto &val : values) {
|
||||
if (val.which == ArgInfo::COMPUTE) {
|
||||
val.val.c = modify->get_compute_by_id(val.id);
|
||||
if (!val.val.c)
|
||||
error->all(FLERR,"Compute ID {} for compute chunk/spread/atom does not exist", val.id);
|
||||
|
||||
} else if (which[m] == ArgInfo::FIX) {
|
||||
int ifix = modify->find_fix(ids[m]);
|
||||
if (ifix < 0)
|
||||
error->all(FLERR,"Fix ID {} for compute chunk/spread/atom does not exist", ids[m]);
|
||||
value2index[m] = ifix;
|
||||
} else if (val.which == ArgInfo::FIX) {
|
||||
val.val.f = modify->get_fix_by_id(val.id);
|
||||
if (!val.val.f)
|
||||
error->all(FLERR,"Fix ID {} for compute chunk/spread/atom does not exist", val.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -182,7 +175,8 @@ void ComputeChunkSpreadAtom::init_chunk()
|
||||
{
|
||||
cchunk = dynamic_cast<ComputeChunkAtom *>(modify->get_compute_by_id(idchunk));
|
||||
if (!cchunk)
|
||||
error->all(FLERR,"Chunk/atom compute does not exist for compute chunk/spread/atom {}", idchunk);
|
||||
error->all(FLERR,"Chunk/atom compute {} does not exist for compute chunk/spread/atom "
|
||||
"or is of invalid style", idchunk);
|
||||
if (strcmp(cchunk->style,"chunk/atom") != 0)
|
||||
error->all(FLERR,"Compute chunk/spread/atom {} does not use chunk/atom compute", idchunk);
|
||||
}
|
||||
@ -196,14 +190,14 @@ void ComputeChunkSpreadAtom::compute_peratom()
|
||||
// grow local vector_atom or array_atom if necessary
|
||||
|
||||
if (atom->nmax > nmax) {
|
||||
if (nvalues == 1) {
|
||||
if (values.size() == 1) {
|
||||
memory->destroy(vector_atom);
|
||||
nmax = atom->nmax;
|
||||
memory->create(vector_atom,nmax,"chunk/spread/atom:vector_atom");
|
||||
} else {
|
||||
memory->destroy(array_atom);
|
||||
nmax = atom->nmax;
|
||||
memory->create(array_atom,nmax,nvalues,"chunk/spread/atom:array_atom");
|
||||
memory->create(array_atom,nmax,values.size(),"chunk/spread/atom:array_atom");
|
||||
}
|
||||
}
|
||||
|
||||
@ -221,35 +215,35 @@ void ComputeChunkSpreadAtom::compute_peratom()
|
||||
int *mask = atom->mask;
|
||||
int nlocal = atom->nlocal;
|
||||
|
||||
int i,m,n,index,nstride;
|
||||
int index,nstride;
|
||||
double *ptr;
|
||||
|
||||
for (m = 0; m < nvalues; m++) {
|
||||
n = value2index[m];
|
||||
int m = 0;
|
||||
for (auto &val : values) {
|
||||
|
||||
// copy compute/fix values into vector_atom or array_atom
|
||||
// nstride between values for each atom
|
||||
|
||||
if (nvalues == 1) {
|
||||
if (values.size() == 1) {
|
||||
ptr = vector_atom;
|
||||
nstride = 1;
|
||||
} else {
|
||||
ptr = &array_atom[0][m];
|
||||
nstride = nvalues;
|
||||
nstride = values.size();
|
||||
}
|
||||
|
||||
// invoke compute if not previously invoked
|
||||
|
||||
if (which[m] == ArgInfo::COMPUTE) {
|
||||
Compute *compute = modify->compute[n];
|
||||
if (val.which == ArgInfo::COMPUTE) {
|
||||
Compute *compute = val.val.c;
|
||||
|
||||
if (argindex[m] == 0) {
|
||||
if (val.argindex == 0) {
|
||||
if (!(compute->invoked_flag & Compute::INVOKED_VECTOR)) {
|
||||
compute->compute_vector();
|
||||
compute->invoked_flag |= Compute::INVOKED_VECTOR;
|
||||
}
|
||||
double *cvector = compute->vector;
|
||||
for (i = 0; i < nlocal; i++, ptr += nstride) {
|
||||
for (int i = 0; i < nlocal; i++, ptr += nstride) {
|
||||
*ptr = 0.0;
|
||||
if (!(mask[i] & groupbit)) continue;
|
||||
index = ichunk[i]-1;
|
||||
@ -262,9 +256,9 @@ void ComputeChunkSpreadAtom::compute_peratom()
|
||||
compute->compute_array();
|
||||
compute->invoked_flag |= Compute::INVOKED_ARRAY;
|
||||
}
|
||||
int icol = argindex[m]-1;
|
||||
int icol = val.argindex-1;
|
||||
double **carray = compute->array;
|
||||
for (i = 0; i < nlocal; i++, ptr += nstride) {
|
||||
for (int i = 0; i < nlocal; i++, ptr += nstride) {
|
||||
*ptr = 0.0;
|
||||
if (!(mask[i] & groupbit)) continue;
|
||||
index = ichunk[i]-1;
|
||||
@ -277,15 +271,15 @@ void ComputeChunkSpreadAtom::compute_peratom()
|
||||
// are assuming the fix global vector/array is per-chunk data
|
||||
// check if index exceeds fix output length/rows
|
||||
|
||||
} else if (which[m] == ArgInfo::FIX) {
|
||||
auto &fix = modify->get_fix_list()[n];
|
||||
} else if (val.which == ArgInfo::FIX) {
|
||||
Fix *fix = val.val.f;
|
||||
if (update->ntimestep % fix->global_freq)
|
||||
error->all(FLERR,"Fix used in compute chunk/spread/atom not "
|
||||
"computed at compatible time");
|
||||
error->all(FLERR,"Fix {} used in compute chunk/spread/atom not computed at compatible time",
|
||||
val.id);
|
||||
|
||||
if (argindex[m] == 0) {
|
||||
if (val.argindex == 0) {
|
||||
int nfix = fix->size_vector;
|
||||
for (i = 0; i < nlocal; i++, ptr += nstride) {
|
||||
for (int i = 0; i < nlocal; i++, ptr += nstride) {
|
||||
*ptr = 0.0;
|
||||
if (!(mask[i] & groupbit)) continue;
|
||||
index = ichunk[i]-1;
|
||||
@ -294,9 +288,9 @@ void ComputeChunkSpreadAtom::compute_peratom()
|
||||
}
|
||||
|
||||
} else {
|
||||
int icol = argindex[m]-1;
|
||||
int icol = val.argindex-1;
|
||||
int nfix = fix->size_array_rows;
|
||||
for (i = 0; i < nlocal; i++, ptr += nstride) {
|
||||
for (int i = 0; i < nlocal; i++, ptr += nstride) {
|
||||
*ptr = 0.0;
|
||||
if (!(mask[i] & groupbit)) continue;
|
||||
index = ichunk[i]-1;
|
||||
@ -305,6 +299,7 @@ void ComputeChunkSpreadAtom::compute_peratom()
|
||||
}
|
||||
}
|
||||
}
|
||||
++m;
|
||||
}
|
||||
}
|
||||
|
||||
@ -314,6 +309,7 @@ void ComputeChunkSpreadAtom::compute_peratom()
|
||||
|
||||
double ComputeChunkSpreadAtom::memory_usage()
|
||||
{
|
||||
double bytes = (double)nmax*nvalues * sizeof(double);
|
||||
double bytes = (double)nmax*values.size() * sizeof(double);
|
||||
bytes += values.size() * sizeof(value_t);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@ -33,13 +33,20 @@ class ComputeChunkSpreadAtom : public Compute {
|
||||
double memory_usage() override;
|
||||
|
||||
protected:
|
||||
int mode, nvalues;
|
||||
char *idchunk;
|
||||
char **ids;
|
||||
int *which, *argindex, *value2index;
|
||||
struct value_t {
|
||||
int which;
|
||||
int argindex;
|
||||
std::string id;
|
||||
union {
|
||||
class Compute *c;
|
||||
class Fix *f;
|
||||
} val;
|
||||
};
|
||||
std::vector<value_t> values;
|
||||
|
||||
int nmax;
|
||||
char *idchunk;
|
||||
class ComputeChunkAtom *cchunk;
|
||||
int nmax;
|
||||
|
||||
void init_chunk();
|
||||
};
|
||||
|
||||
@ -38,6 +38,8 @@ FixVector::FixVector(LAMMPS *lmp, int narg, char **arg) :
|
||||
nevery = utils::inumeric(FLERR, arg[3], false, lmp);
|
||||
if (nevery <= 0) error->all(FLERR, "Invalid fix vector every argument: {}", nevery);
|
||||
|
||||
// parse values
|
||||
|
||||
values.clear();
|
||||
for (int iarg = 4; iarg < narg; iarg++) {
|
||||
ArgInfo argi(arg[iarg]);
|
||||
@ -48,7 +50,7 @@ FixVector::FixVector(LAMMPS *lmp, int narg, char **arg) :
|
||||
val.id = argi.get_name();
|
||||
val.val.c = nullptr;
|
||||
|
||||
if ((argi.get_type() == ArgInfo::UNKNOWN) || (argi.get_type() == ArgInfo::NONE) ||
|
||||
if ((val.which == ArgInfo::UNKNOWN) || (val.which == ArgInfo::NONE) ||
|
||||
(argi.get_dim() > 1))
|
||||
error->all(FLERR, "Invalid fix vector argument: {}", arg[iarg]);
|
||||
|
||||
|
||||
@ -58,10 +58,17 @@ target_compile_definitions(test_reset_ids PRIVATE -DTEST_INPUT_FOLDER=${CMAKE_CU
|
||||
target_link_libraries(test_reset_ids PRIVATE lammps GTest::GMock)
|
||||
add_test(NAME ResetIDs COMMAND test_reset_ids)
|
||||
|
||||
add_executable(test_compute_global test_compute_global.cpp)
|
||||
target_compile_definitions(test_compute_global PRIVATE -DTEST_INPUT_FOLDER=${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_link_libraries(test_compute_global PRIVATE lammps GTest::GMock)
|
||||
add_test(NAME ComputeGlobal COMMAND test_compute_global)
|
||||
if(PKG_MOLECULE)
|
||||
add_executable(test_compute_global test_compute_global.cpp)
|
||||
target_compile_definitions(test_compute_global PRIVATE -DTEST_INPUT_FOLDER=${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_link_libraries(test_compute_global PRIVATE lammps GTest::GMock)
|
||||
add_test(NAME ComputeGlobal COMMAND test_compute_global)
|
||||
|
||||
add_executable(test_compute_chunk test_compute_chunk.cpp)
|
||||
target_compile_definitions(test_compute_chunk PRIVATE -DTEST_INPUT_FOLDER=${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_link_libraries(test_compute_chunk PRIVATE lammps GTest::GMock)
|
||||
add_test(NAME ComputeChunk COMMAND test_compute_chunk)
|
||||
endif()
|
||||
|
||||
add_executable(test_mpi_load_balancing test_mpi_load_balancing.cpp)
|
||||
target_link_libraries(test_mpi_load_balancing PRIVATE lammps GTest::GMock)
|
||||
|
||||
290
unittest/commands/test_compute_chunk.cpp
Normal file
290
unittest/commands/test_compute_chunk.cpp
Normal file
@ -0,0 +1,290 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
certain rights in this software. This software is distributed under
|
||||
the GNU General Public License.
|
||||
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "../testing/core.h"
|
||||
#include "info.h"
|
||||
#include "lammps.h"
|
||||
#include "library.h"
|
||||
#include "utils.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <mpi.h>
|
||||
|
||||
// whether to print verbose output (i.e. not capturing LAMMPS screen output).
|
||||
bool verbose = false;
|
||||
static constexpr double EPSILON = 1.0e-6;
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
#define STRINGIFY(val) XSTR(val)
|
||||
#define XSTR(val) #val
|
||||
|
||||
class ComputeChunkTest : public LAMMPSTest {
|
||||
protected:
|
||||
void SetUp() override
|
||||
{
|
||||
testbinary = "ComputeChunkTest";
|
||||
LAMMPSTest::SetUp();
|
||||
if (info->has_style("atom", "full")) {
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("variable input_dir index \"" STRINGIFY(TEST_INPUT_FOLDER) "\"");
|
||||
command("include \"${input_dir}/in.fourmol\"");
|
||||
command("group allwater molecule 3:6");
|
||||
command("region half block 0.0 INF INF INF INF INF");
|
||||
command("compute tags all property/atom id");
|
||||
command("compute bin1d all chunk/atom bin/1d x lower 3.0 units box");
|
||||
command("compute bin2d all chunk/atom bin/2d x lower 3.0 y lower 3.0 units box");
|
||||
command("compute bin3d all chunk/atom bin/3d x lower 3.0 y lower 3.0 z lower 3.0 units "
|
||||
"box");
|
||||
command("compute binsph all chunk/atom bin/sphere 0.0 0.0 0.0 0.01 6.01 6 units box");
|
||||
command("compute bincyl all chunk/atom bin/cylinder z lower 3.0 1.0 1.0 0.01 6.01 6 "
|
||||
"units box");
|
||||
command("compute mols all chunk/atom molecule");
|
||||
command("compute types all chunk/atom type");
|
||||
END_HIDE_OUTPUT();
|
||||
}
|
||||
}
|
||||
|
||||
double get_scalar(const char *id)
|
||||
{
|
||||
return *(double *)lammps_extract_compute(lmp, id, LMP_STYLE_GLOBAL, LMP_TYPE_SCALAR);
|
||||
}
|
||||
|
||||
double *get_vector(const char *id)
|
||||
{
|
||||
return (double *)lammps_extract_compute(lmp, id, LMP_STYLE_GLOBAL, LMP_TYPE_VECTOR);
|
||||
}
|
||||
|
||||
double **get_array(const char *id)
|
||||
{
|
||||
return (double **)lammps_extract_compute(lmp, id, LMP_STYLE_GLOBAL, LMP_TYPE_ARRAY);
|
||||
}
|
||||
|
||||
double *get_peratom(const char *id)
|
||||
{
|
||||
return (double *)lammps_extract_compute(lmp, id, LMP_STYLE_ATOM, LMP_TYPE_VECTOR);
|
||||
}
|
||||
};
|
||||
|
||||
static constexpr int chunk1d[] = {0, 2, 3, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 3,
|
||||
4, 3, 3, 3, 3, 3, 4, 4, 4, 3, 3, 3, 2, 2, 2};
|
||||
static constexpr int chalf1d[] = {0, 0, 3, 0, 0, 0, 3, 3, 3, 3, 3, 3, 4, 4, 3,
|
||||
4, 3, 3, 3, 3, 3, 4, 4, 4, 3, 3, 3, 0, 0, 0};
|
||||
static constexpr int chunk2d[] = {0, 9, 14, 8, 9, 8, 13, 13, 13, 13, 13, 12, 18, 18, 13,
|
||||
18, 12, 12, 14, 14, 14, 17, 17, 17, 14, 14, 14, 7, 7, 7};
|
||||
static constexpr int chunk3d[] = {0, 43, 68, 38, 43, 38, 63, 62, 63, 63, 63, 58, 88, 88, 62,
|
||||
88, 58, 59, 67, 67, 67, 82, 82, 82, 69, 69, 69, 34, 34, 34};
|
||||
static constexpr int chunksph[] = {0, 3, 4, 2, 3, 2, 2, 3, 2, 2, 3, 4, 4, 5, 4,
|
||||
4, 4, 4, 6, 6, 6, 6, 6, 6, 5, 5, 6, 6, 6, 5};
|
||||
static constexpr int chunkcyl[] = {0, 8, 13, 8, 13, 8, 8, 7, 8, 8, 13, 18, 13, 18, 12,
|
||||
13, 18, 19, 12, 7, 17, 27, 27, 27, 14, 14, 19, 29, 29, 29};
|
||||
static constexpr int chunkmol[] = {0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6};
|
||||
static constexpr int chunktyp[] = {0, 3, 2, 1, 2, 2, 1, 4, 3, 2, 1, 2, 1, 2, 2,
|
||||
2, 1, 4, 4, 2, 2, 5, 2, 2, 5, 2, 2, 5, 2, 2};
|
||||
|
||||
TEST_F(ComputeChunkTest, ChunkAtom)
|
||||
{
|
||||
if (lammps_get_natoms(lmp) == 0.0) GTEST_SKIP();
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("pair_style lj/cut/coul/cut 10.0");
|
||||
command("pair_coeff * * 0.01 3.0");
|
||||
command("bond_style harmonic");
|
||||
command("bond_coeff * 100.0 1.5");
|
||||
command("dump 1 all custom 1 compute_chunk_atom.lammpstrj "
|
||||
"id c_bin1d c_bin2d c_bin3d c_binsph c_bincyl c_mols c_types c_tags");
|
||||
command("run 0 post no");
|
||||
END_HIDE_OUTPUT();
|
||||
|
||||
const int natoms = lammps_get_natoms(lmp);
|
||||
EXPECT_EQ(get_scalar("bin1d"), 5);
|
||||
EXPECT_EQ(get_scalar("bin2d"), 25);
|
||||
EXPECT_EQ(get_scalar("bin3d"), 125);
|
||||
EXPECT_EQ(get_scalar("binsph"), 6);
|
||||
EXPECT_EQ(get_scalar("bincyl"), 30);
|
||||
EXPECT_EQ(get_scalar("mols"), 6);
|
||||
EXPECT_EQ(get_scalar("types"), 5);
|
||||
|
||||
auto cbin1d = get_peratom("bin1d");
|
||||
auto cbin2d = get_peratom("bin2d");
|
||||
auto cbin3d = get_peratom("bin3d");
|
||||
auto cbinsph = get_peratom("binsph");
|
||||
auto cbincyl = get_peratom("bincyl");
|
||||
auto cmols = get_peratom("mols");
|
||||
auto ctypes = get_peratom("types");
|
||||
auto tag = get_peratom("tags");
|
||||
|
||||
for (int i = 0; i < natoms; ++i) {
|
||||
EXPECT_EQ(cbin1d[i], chunk1d[(int)tag[i]]);
|
||||
EXPECT_EQ(cbin2d[i], chunk2d[(int)tag[i]]);
|
||||
EXPECT_EQ(cbin3d[i], chunk3d[(int)tag[i]]);
|
||||
EXPECT_EQ(cbinsph[i], chunksph[(int)tag[i]]);
|
||||
EXPECT_EQ(cbincyl[i], chunkcyl[(int)tag[i]]);
|
||||
EXPECT_EQ(cmols[i], chunkmol[(int)tag[i]]);
|
||||
EXPECT_EQ(ctypes[i], chunktyp[(int)tag[i]]);
|
||||
}
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("uncompute bin1d");
|
||||
command("compute bin1d all chunk/atom bin/1d x lower 0.2 units reduced region half");
|
||||
command("uncompute bin3d");
|
||||
command("compute bin3d all chunk/atom bin/3d x lower 3.0 y lower 3.0 z lower 3.0 "
|
||||
"compress yes units box");
|
||||
END_HIDE_OUTPUT();
|
||||
EXPECT_EQ(get_scalar("bin1d"), 5);
|
||||
EXPECT_EQ(get_scalar("bin3d"), 12);
|
||||
|
||||
cbin1d = get_peratom("bin1d");
|
||||
tag = get_peratom("tags");
|
||||
for (int i = 0; i < natoms; ++i) {
|
||||
EXPECT_EQ(cbin1d[i], chalf1d[(int)tag[i]]);
|
||||
}
|
||||
|
||||
// cleanup
|
||||
platform::unlink("compute_chunk_atom.lammpstrj");
|
||||
}
|
||||
|
||||
TEST_F(ComputeChunkTest, PropertyChunk)
|
||||
{
|
||||
if (lammps_get_natoms(lmp) == 0.0) GTEST_SKIP();
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("pair_style lj/cut/coul/cut 10.0");
|
||||
command("pair_coeff * * 0.01 3.0");
|
||||
command("bond_style harmonic");
|
||||
command("bond_coeff * 100.0 1.5");
|
||||
command("uncompute bin3d");
|
||||
command("compute bin3d all chunk/atom bin/3d x lower 3.0 y lower 3.0 z lower 3.0 "
|
||||
"compress yes units box");
|
||||
command("compute prop1 all property/chunk bin1d count");
|
||||
command("compute prop2 all property/chunk bin2d count");
|
||||
command("compute prop3 all property/chunk bin3d id count");
|
||||
command("fix hist1 all ave/time 1 1 1 c_prop1 mode vector");
|
||||
command("fix hist2 all ave/time 1 1 1 c_prop2 mode vector");
|
||||
command("fix hist3 all ave/time 1 1 1 c_prop3[*] mode vector");
|
||||
command("run 0 post no");
|
||||
END_HIDE_OUTPUT();
|
||||
|
||||
auto cprop1 = get_vector("prop1");
|
||||
EXPECT_EQ(cprop1[0], 0);
|
||||
EXPECT_EQ(cprop1[1], 7);
|
||||
EXPECT_EQ(cprop1[2], 16);
|
||||
EXPECT_EQ(cprop1[3], 6);
|
||||
EXPECT_EQ(cprop1[4], 0);
|
||||
|
||||
auto cprop2 = get_vector("prop2");
|
||||
int nempty = 0;
|
||||
int ncount = 0;
|
||||
for (int i = 0; i < 25; ++i) {
|
||||
if (cprop2[i] == 0)
|
||||
++nempty;
|
||||
else
|
||||
ncount += cprop2[i];
|
||||
}
|
||||
EXPECT_EQ(nempty, 17);
|
||||
EXPECT_EQ(ncount, 29);
|
||||
|
||||
auto cprop3 = get_array("prop3");
|
||||
EXPECT_EQ(cprop3[0][0], 34);
|
||||
EXPECT_EQ(cprop3[1][0], 38);
|
||||
EXPECT_EQ(cprop3[2][0], 43);
|
||||
EXPECT_EQ(cprop3[3][0], 58);
|
||||
EXPECT_EQ(cprop3[4][0], 59);
|
||||
EXPECT_EQ(cprop3[5][0], 62);
|
||||
EXPECT_EQ(cprop3[6][0], 63);
|
||||
EXPECT_EQ(cprop3[7][0], 67);
|
||||
EXPECT_EQ(cprop3[8][0], 68);
|
||||
EXPECT_EQ(cprop3[9][0], 69);
|
||||
EXPECT_EQ(cprop3[10][0], 82);
|
||||
EXPECT_EQ(cprop3[11][0], 88);
|
||||
|
||||
EXPECT_EQ(cprop3[0][1], 3);
|
||||
EXPECT_EQ(cprop3[1][1], 2);
|
||||
EXPECT_EQ(cprop3[2][1], 2);
|
||||
EXPECT_EQ(cprop3[3][1], 2);
|
||||
EXPECT_EQ(cprop3[4][1], 1);
|
||||
EXPECT_EQ(cprop3[5][1], 2);
|
||||
EXPECT_EQ(cprop3[6][1], 4);
|
||||
EXPECT_EQ(cprop3[7][1], 3);
|
||||
EXPECT_EQ(cprop3[8][1], 1);
|
||||
EXPECT_EQ(cprop3[9][1], 3);
|
||||
EXPECT_EQ(cprop3[10][1], 3);
|
||||
EXPECT_EQ(cprop3[11][1], 3);
|
||||
}
|
||||
|
||||
TEST_F(ComputeChunkTest, ChunkComputes)
|
||||
{
|
||||
if (lammps_get_natoms(lmp) == 0.0) GTEST_SKIP();
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("pair_style lj/cut/coul/cut 10.0");
|
||||
command("pair_coeff * * 0.01 3.0");
|
||||
command("bond_style harmonic");
|
||||
command("bond_coeff * 100.0 1.5");
|
||||
command("compute ang all angmom/chunk mols");
|
||||
command("compute com all com/chunk mols");
|
||||
command("compute dip all dipole/chunk mols geometry");
|
||||
command("fix hist1 all ave/time 1 1 1 c_ang[*] c_com[*] c_dip[*] mode vector");
|
||||
command("run 0 post no");
|
||||
END_HIDE_OUTPUT();
|
||||
auto cang = get_array("ang");
|
||||
auto ccom = get_array("com");
|
||||
auto cdip = get_array("dip");
|
||||
EXPECT_NEAR(cang[0][0], -0.0190698, EPSILON);
|
||||
EXPECT_NEAR(cang[0][1], -0.0281453, EPSILON);
|
||||
EXPECT_NEAR(cang[0][2], -0.0335739, EPSILON);
|
||||
EXPECT_NEAR(cang[5][0], 0.00767837, EPSILON);
|
||||
EXPECT_NEAR(cang[5][1], -0.00303138, EPSILON);
|
||||
EXPECT_NEAR(cang[5][2], 0.00740977, EPSILON);
|
||||
EXPECT_NEAR(ccom[1][0], 2.2705137, EPSILON);
|
||||
EXPECT_NEAR(ccom[1][1], -1.2103888, EPSILON);
|
||||
EXPECT_NEAR(ccom[1][2], -0.585817, EPSILON);
|
||||
EXPECT_NEAR(ccom[5][0], -1.9828469, EPSILON);
|
||||
EXPECT_NEAR(ccom[5][1], -4.1735122, EPSILON);
|
||||
EXPECT_NEAR(ccom[5][2], 2.0485, EPSILON);
|
||||
EXPECT_NEAR(cdip[0][3], 0.359122, EPSILON);
|
||||
EXPECT_NEAR(cdip[1][3], 0.684537, EPSILON);
|
||||
EXPECT_NEAR(cdip[2][3], 0.502726, EPSILON);
|
||||
EXPECT_NEAR(cdip[3][3], 0.508459, EPSILON);
|
||||
EXPECT_NEAR(cdip[4][3], 0.497574, EPSILON);
|
||||
EXPECT_NEAR(cdip[5][3], 0.49105, EPSILON);
|
||||
}
|
||||
} // namespace LAMMPS_NS
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
MPI_Init(&argc, &argv);
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions())
|
||||
std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n";
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = LAMMPS_NS::utils::split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true;
|
||||
|
||||
int rv = RUN_ALL_TESTS();
|
||||
MPI_Finalize();
|
||||
return rv;
|
||||
}
|
||||
Reference in New Issue
Block a user