Skip to content

Commit

Permalink
Merge pull request #195 from eschnett/eschnett/testarraygroup
Browse files Browse the repository at this point in the history
TestArrayGroup: Modernize thorn, add test case
  • Loading branch information
eschnett authored Aug 3, 2023
2 parents bf0cf9a + 4fc5ce4 commit de6e8c0
Show file tree
Hide file tree
Showing 22 changed files with 569 additions and 223 deletions.
2 changes: 1 addition & 1 deletion TestArrayGroup/interface.ccl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ CCTK_REAL test_array[4] TYPE=array DIM=2 SIZE=5,6 DISTRIB=constant
test1 test2 test3
} "Test arrays for verifying CarpetX implementation of non-distributed array data"

CCTK_REAL test_gf TYPE=gf CENTERING={CCC} "Test grid function for verifying CarpetX implementation of DynamicData"
CCTK_REAL test_gf TYPE=gf CENTERING={VVV} "Test grid function for verifying CarpetX implementation of DynamicData"

CCTK_REAL test_scalar TYPE=scalar "Test scalar for verifying CarpetX implementation of DynamicData"
92 changes: 39 additions & 53 deletions TestArrayGroup/src/TestArray.cxx
Original file line number Diff line number Diff line change
@@ -1,35 +1,24 @@
#include <cctk.h>
#include <cctk_Arguments.h>
#include <cctk_Parameters.h>
#include <util_Table.h>

#include <cassert>
#include <cmath>
#include <memory>
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <tuple>
#include <type_traits>
#include <vector>
#include <cassert>
#include <sstream>

extern "C" void TestArrayGroup_Initialize(cGH *cctkGH) {
extern "C" void TestArrayGroup_Initialize(CCTK_ARGUMENTS) {
DECLARE_CCTK_PARAMETERS;
DECLARE_CCTK_ARGUMENTS_TestArrayGroup_Initialize;

int imax = 5;
int jmax = 6;
int nmax = 4;
const int imax = 5;
const int jmax = 6;
const int nmax = 4;

// Initialize test array
for (int n = 0; n < nmax; n++) {
for (int j = 0; j < jmax; j++) {
for (int i = 0; i < imax; i++) {
int index = i + j * imax + n * imax * jmax;
const int index = i + j * imax + n * imax * jmax;
test1[index] = 1 + i * j * n;
test2[index] = 1 + 7 * i * j * n;
test3[index] = 1 + 13 * i * j * n;
Expand All @@ -42,47 +31,54 @@ extern "C" void TestArrayGroup_Initialize(cGH *cctkGH) {
cGroup group;
int ierr = CCTK_GroupData(gi, &group);
assert(!ierr);
std::vector<int> lsh(3);
std::array<int, 3> lsh;
ierr = CCTK_GrouplshGI(cctkGH, group.dim, lsh.data(), gi);
assert(!ierr);

const int i0 = cctk_lbnd[0];
const int j0 = cctk_lbnd[1];
const int k0 = cctk_lbnd[2];
for (int k = 0; k < lsh[2]; k++) {
for (int j = 0; j < lsh[1]; j++) {
for (int i = 0; i < lsh[0]; i++) {
int index = CCTK_GFINDEX3D(cctkGH, i, j, k);
test_gf[index] = i * j * k;
const int index = CCTK_GFINDEX3D(cctkGH, i, j, k);
test_gf[index] = (i0 + i) * (j0 + j) * (k0 + k);
}
}
}

*test_scalar = 1;

return;
}

extern "C" void TestArrayGroup_Compare(cGH *cctkGH) {
DECLARE_CCTK_PARAMETERS;
DECLARE_CCTK_ARGUMENTS_TestArrayGroup_Compare;

int imax = 5;
int jmax = 6;
int nmax = 4;
const int imax = 5;
const int jmax = 6;
const int nmax = 4;

int error_count[3] = {0, 0, 0};
std::string vname;

for (int n = 0; n < nmax; n++) {
vname = "TestArrayGroup::test1[" + std::to_string(n) + "]";
CCTK_REAL *var1 = (CCTK_REAL *)CCTK_VarDataPtr(cctkGH, 0, vname.c_str());
std::ostringstream vname1;
vname1 << "TestArrayGroup::test1[" << n << "]";
CCTK_REAL *const var1 =
(CCTK_REAL *)CCTK_VarDataPtr(cctkGH, 0, vname1.str().c_str());

std::ostringstream vname2;
vname2 << "TestArrayGroup::test2[" << n << "]";
CCTK_REAL *const var2 =
(CCTK_REAL *)CCTK_VarDataPtr(cctkGH, 0, vname2.str().c_str());

vname = "TestArrayGroup::test2[" + std::to_string(n) + "]";
CCTK_REAL *var2 = (CCTK_REAL *)CCTK_VarDataPtr(cctkGH, 0, vname.c_str());
std::ostringstream vname3;
vname3 << "TestArrayGroup::test3[" << n << "]";
CCTK_REAL *const var3 =
(CCTK_REAL *)CCTK_VarDataPtr(cctkGH, 0, vname3.str().c_str());

vname = "TestArrayGroup::test3[" + std::to_string(n) + "]";
CCTK_REAL *var3 = (CCTK_REAL *)CCTK_VarDataPtr(cctkGH, 0, vname.c_str());
for (int j = 0; j < jmax; j++) {
for (int i = 0; i < imax; i++) {
int index = i + j * imax;
const int index = i + j * imax;
if (var1[index] != 1 + i * j * n)
error_count[0] += 1;
if (var2[index] != 1 + 7 * i * j * n)
Expand All @@ -94,30 +90,20 @@ extern "C" void TestArrayGroup_Compare(cGH *cctkGH) {
}

if (error_count[0] > 0) {
int size = nmax * jmax * imax;
std::string msg;
msg = "TestArrayGroup: grid array test1 failed in " +
std::to_string(error_count[0]) + " of " + std::to_string(size) +
" elements.";
CCTK_ERROR(msg.c_str());
const int size = nmax * jmax * imax;
CCTK_VERROR("TestArrayGroup: grid array test1 failed in %d of %d elements",
error_count[0], size);
}

if (error_count[1] > 0) {
int size = nmax * jmax * imax;
std::string msg;
msg = "TestArrayGroup: grid array test2 failed in " +
std::to_string(error_count[1]) + " of " + std::to_string(size) +
" elements.";
CCTK_ERROR(msg.c_str());
const int size = nmax * jmax * imax;
CCTK_VERROR("TestArrayGroup: grid array test2 failed in %d of %d elements",
error_count[1], size);
}

if (error_count[2] > 0) {
int size = nmax * jmax * imax;
std::string msg;
msg = "TestArrayGroup: grid array test3 failed in " +
std::to_string(error_count[2]) + " of " + std::to_string(size) +
" elements.";
CCTK_ERROR(msg.c_str());
const int size = nmax * jmax * imax;
CCTK_VERROR("TestArrayGroup: grid array test3 failed in %d of %d elements",
error_count[2], size);
}
return;
}
Loading

0 comments on commit de6e8c0

Please sign in to comment.