unit test for gather and scatter; char* to const char* in library.*
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
|
||||
#include "lammps.h"
|
||||
#include "library.h"
|
||||
#include "atom.h"
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <mpi.h>
|
||||
@ -26,6 +27,11 @@ void f_lammps_scatter_atoms_positions();
|
||||
void f_lammps_setup_gather_bonds();
|
||||
int f_lammps_test_gather_bonds_small();
|
||||
int f_lammps_test_gather_bonds_big();
|
||||
double f_lammps_gather_pe_atom(int);
|
||||
double f_lammps_gather_pe_atom_concat(int);
|
||||
void f_lammps_gather_pe_atom_subset(int*, double*);
|
||||
void f_lammps_scatter_compute();
|
||||
void f_lammps_scatter_subset_compute();
|
||||
}
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
@ -216,3 +222,105 @@ TEST_F(LAMMPS_gather_scatter, gather_bonds)
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
TEST_F(LAMMPS_gather_scatter, gather_compute)
|
||||
{
|
||||
#ifdef LAMMPS_BIGBIG
|
||||
GTEST_SKIP()
|
||||
#endif
|
||||
f_lammps_setup_gather_scatter();
|
||||
lammps_command(lmp, "run 0");
|
||||
int natoms = lmp->atom->natoms;
|
||||
int *tag = lmp->atom->tag;
|
||||
double *pe = (double*) lammps_extract_compute(lmp, "pe", LMP_STYLE_ATOM,
|
||||
LMP_TYPE_VECTOR);
|
||||
for (int i = 0; i < natoms; i++)
|
||||
EXPECT_DOUBLE_EQ(f_lammps_gather_pe_atom(tag[i]), pe[i]);
|
||||
};
|
||||
|
||||
TEST_F(LAMMPS_gather_scatter, gather_compute_concat)
|
||||
{
|
||||
#ifdef LAMMPS_BIGBIG
|
||||
GTEST_SKIP()
|
||||
#endif
|
||||
f_lammps_setup_gather_scatter();
|
||||
lammps_command(lmp, "run 0");
|
||||
int natoms = lmp->atom->natoms;
|
||||
int *tag = lmp->atom->tag;
|
||||
double *pe = (double*) lammps_extract_compute(lmp, "pe", LMP_STYLE_ATOM,
|
||||
LMP_TYPE_VECTOR);
|
||||
for (int i = 0; i < natoms; i++)
|
||||
EXPECT_DOUBLE_EQ(f_lammps_gather_pe_atom(tag[i]), pe[i]);
|
||||
};
|
||||
|
||||
TEST_F(LAMMPS_gather_scatter, gather_compute_subset)
|
||||
{
|
||||
f_lammps_setup_gather_scatter();
|
||||
lammps_command(lmp, "run 0");
|
||||
int ids[2] = {3, 1};
|
||||
int *tag = lmp->atom->tag;
|
||||
double pe[2] = {0.0, 0.0};
|
||||
int nlocal = lammps_extract_setting(lmp, "nlocal");
|
||||
double *pa_pe = (double*) lammps_extract_compute(lmp, "pe", LMP_STYLE_ATOM,
|
||||
LMP_TYPE_VECTOR);
|
||||
|
||||
for (int i = 0; i < nlocal; i++) {
|
||||
if(tag[i] == ids[0]) pe[0] = pa_pe[i];
|
||||
if(tag[i] == ids[1]) pe[1] = pa_pe[i];
|
||||
}
|
||||
|
||||
double ftn_pe[2];
|
||||
f_lammps_gather_pe_atom_subset(ids, ftn_pe);
|
||||
EXPECT_DOUBLE_EQ(ftn_pe[0], pe[0]);
|
||||
EXPECT_DOUBLE_EQ(ftn_pe[1], pe[1]);
|
||||
};
|
||||
|
||||
TEST_F(LAMMPS_gather_scatter, scatter_compute)
|
||||
{
|
||||
#ifdef LAMMPS_BIGBIG
|
||||
GTEST_SKIP();
|
||||
#endif
|
||||
f_lammps_setup_gather_scatter();
|
||||
int natoms = lmp->atom->natoms;
|
||||
double *pe = new double[natoms];
|
||||
lammps_command(lmp, "run 0");
|
||||
lammps_gather(lmp, "c_pe", 1, 1, pe);
|
||||
double *old_pe = new double[natoms];
|
||||
for (int i = 0; i < natoms; i++)
|
||||
old_pe[i] = pe[i];
|
||||
EXPECT_DOUBLE_EQ(pe[0], old_pe[0]);
|
||||
EXPECT_DOUBLE_EQ(pe[1], old_pe[1]);
|
||||
EXPECT_DOUBLE_EQ(pe[2], old_pe[2]);
|
||||
f_lammps_scatter_compute();
|
||||
lammps_gather(lmp, "c_pe", 1, 1, pe);
|
||||
EXPECT_DOUBLE_EQ(pe[0], old_pe[2]);
|
||||
EXPECT_DOUBLE_EQ(pe[1], old_pe[1]);
|
||||
EXPECT_DOUBLE_EQ(pe[2], old_pe[0]);
|
||||
delete[] old_pe;
|
||||
delete[] pe;
|
||||
};
|
||||
|
||||
TEST_F(LAMMPS_gather_scatter, scatter_subset_compute)
|
||||
{
|
||||
#ifdef LAMMPS_BIGBIG
|
||||
GTEST_SKIP();
|
||||
#endif
|
||||
f_lammps_setup_gather_scatter();
|
||||
int natoms = lmp->atom->natoms;
|
||||
double *pe = new double[natoms];
|
||||
lammps_command(lmp, "run 0");
|
||||
lammps_gather(lmp, "c_pe", 1, 1, pe);
|
||||
double *old_pe = new double[natoms];
|
||||
for (int i = 0; i < natoms; i++)
|
||||
old_pe[i] = pe[i];
|
||||
EXPECT_DOUBLE_EQ(pe[0], old_pe[0]);
|
||||
EXPECT_DOUBLE_EQ(pe[1], old_pe[1]);
|
||||
EXPECT_DOUBLE_EQ(pe[2], old_pe[2]);
|
||||
f_lammps_scatter_subset_compute();
|
||||
lammps_gather(lmp, "c_pe", 1, 1, pe);
|
||||
EXPECT_DOUBLE_EQ(pe[0], old_pe[2]);
|
||||
EXPECT_DOUBLE_EQ(pe[1], old_pe[1]);
|
||||
EXPECT_DOUBLE_EQ(pe[2], old_pe[0]);
|
||||
delete[] old_pe;
|
||||
delete[] pe;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user