Skip to content

Commit

Permalink
Fix dimensions bug
Browse files Browse the repository at this point in the history
  • Loading branch information
lizdulac committed Oct 17, 2024
1 parent 10b392a commit 59c8e6b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 29 deletions.
3 changes: 2 additions & 1 deletion source/adios2/toolkit/derived/Function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,8 @@ std::tuple<Dims, Dims, Dims> CurlDimsFunc(std::vector<std::tuple<Dims, Dims, Dim

std::tuple<Dims, Dims, Dims> ScalarDimsFunc(std::vector<std::tuple<Dims, Dims, Dims>> input)
{
return {{1}, {0}, {1}};
// Start, Count, Shape
return {{0}, {1}, {1}};
}

DataType SameTypeFunc(DataType input) { return input; }
Expand Down
36 changes: 8 additions & 28 deletions testing/adios2/derived/TestBPDerivedCorrectness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ TEST_P(DerivedCorrectnessP, ScalarFunctionsCorrectnessTest)
auto Uy = bpOut.DefineVariable<float>(varname[1], {Nx, Ny, Nz}, {0, 0, 0}, {Nx, Ny, Nz});
auto Uz = bpOut.DefineVariable<float>(varname[2], {Nx, Ny, Nz}, {0, 0, 0}, {Nx, Ny, Nz});
// clang-format off
/*
bpOut.DefineDerivedVariable(derAgrAdd,
"x=" + varname[0] + "\n"
"add(x)",
Expand Down Expand Up @@ -107,12 +106,10 @@ TEST_P(DerivedCorrectnessP, ScalarFunctionsCorrectnessTest)
"x =" + varname[0] + " \n"
"sqrt(x)",
mode);
*/
bpOut.DefineDerivedVariable(derMinName,
"x =" + varname[0] + " \n"
"min(x)",
mode);
/*
bpOut.DefineDerivedVariable(derMaxName,
"x =" + varname[0] + " \n"
"max(x)",
Expand All @@ -133,7 +130,6 @@ TEST_P(DerivedCorrectnessP, ScalarFunctionsCorrectnessTest)
"x =" + varname[0] + " \n"
"stdev(x)",
mode);
*/
// clang-format on
std::string filename = "derivedScalar.bp";
adios2::Engine bpFileWriter = bpOut.Open(filename, adios2::Mode::Write);
Expand Down Expand Up @@ -173,23 +169,19 @@ TEST_P(DerivedCorrectnessP, ScalarFunctionsCorrectnessTest)
bpFileReader.Get(varname[0], readUx);
bpFileReader.Get(varname[1], readUy);
bpFileReader.Get(varname[2], readUz);
/*
bpFileReader.Get(derAddName, readAdd);
bpFileReader.Get(derAgrAdd, readAgrAdd);
bpFileReader.Get(derSubtrName, readSubtr);
bpFileReader.Get(derMultName, readMult);
bpFileReader.Get(derDivName, readDiv);
bpFileReader.Get(derPowName, readPow);
bpFileReader.Get(derSqrtName, readSqrt);
*/
bpFileReader.Get(derMinName, readMin);
/*
bpFileReader.Get(derMaxName, readMax);
bpFileReader.Get(derSumName, readSum);
bpFileReader.Get(derMeanName, readMean);
bpFileReader.Get(derVarianceName, readVariance);
bpFileReader.Get(derStdevName, readStdev);
*/
bpFileReader.EndStep();

float min = std::numeric_limits<float>::max();
Expand All @@ -198,7 +190,6 @@ TEST_P(DerivedCorrectnessP, ScalarFunctionsCorrectnessTest)

for (size_t ind = 0; ind < Nx * Ny * Nz; ++ind)
{
/*
calcFloat = readUx[ind] + readUy[ind] + readUz[ind];
EXPECT_TRUE(fabs(calcFloat - readAdd[ind]) < epsilon);

Expand All @@ -216,19 +207,16 @@ TEST_P(DerivedCorrectnessP, ScalarFunctionsCorrectnessTest)

calcDouble = std::sqrt(readUx[ind]);
EXPECT_TRUE(fabs(calcDouble - readSqrt[ind]) < epsilon);
*/
min = std::min(min, readUx[ind]);
max = std::max(max, readUx[ind]);
sum += readUx[ind];
}

float mean = sum / (Nx * Ny * Nz);
EXPECT_TRUE(fabs(min - readMin[0]) < epsilon);
/*
EXPECT_TRUE(fabs(max - readMax) < epsilon);
EXPECT_TRUE(fabs(sum - readSum) < epsilon);
EXPECT_TRUE(fabs(mean - readMean) < epsilon);
*/
EXPECT_TRUE(fabs(max - readMax[0]) < epsilon);
EXPECT_TRUE(fabs(sum - readSum[0]) < epsilon);
EXPECT_TRUE(fabs(mean - readMean[0]) < epsilon);

float variance = 0;

Expand All @@ -240,10 +228,8 @@ TEST_P(DerivedCorrectnessP, ScalarFunctionsCorrectnessTest)
variance /= (Nx * Ny * Nz);
double stdev = std::sqrt(variance);

/*
EXPECT_TRUE(fabs(variance - readVariance) < epsilon);
EXPECT_TRUE(fabs(stdev - readStdev) < epsilon);
*/
EXPECT_TRUE(fabs(variance - readVariance[0]) < epsilon);
EXPECT_TRUE(fabs(stdev - readStdev[0]) < epsilon);

for (size_t ind = 0; ind < Nx * Ny; ++ind)
{
Expand All @@ -253,12 +239,12 @@ TEST_P(DerivedCorrectnessP, ScalarFunctionsCorrectnessTest)
{
calcA += readUx[z + start];
}
//EXPECT_TRUE(fabs(calcA - readAgrAdd[ind]) < epsilon);
EXPECT_TRUE(fabs(calcA - readAgrAdd[ind]) < epsilon);
}
}
bpFileReader.Close();
}
/*

TEST_P(DerivedCorrectnessP, TrigCorrectnessTest)
{
const size_t Nx = 10, Ny = 3, Nz = 6;
Expand Down Expand Up @@ -565,7 +551,6 @@ TEST_P(DerivedCorrectnessP, CurlCorrectnessTest)
simArray2[idx] = sqrtf(z + 1) * cosf(x);
simArray3[idx] = powf(x, 2) * sinf(y) + (6 * z);
*/
/*
}
}
}
Expand Down Expand Up @@ -636,7 +621,6 @@ TEST_P(DerivedCorrectnessP, CurlCorrectnessTest)
curl_x = -(2 * x);
curl_y = 7 - (2 * y);
curl_z = (4 * z) - (6 * x);
*/
/* Less linear
curl_x = 2 * y * cosf(x);
curl_y = cosf(z) + (powf(y, 2) * sinf(x));
Expand All @@ -647,7 +631,6 @@ TEST_P(DerivedCorrectnessP, CurlCorrectnessTest)
curl_y = -2 * x * sinf(y);
curl_z = -sqrtf(z + 1) * sinf(x) - (2 * expf(2 * y) * sinf(x));
*/
/*
if (fabs(curl_x) < 1)
{
err_x = fabs(curl_x - readCurl[3 * idx]) / (1 + fabs(curl_x));
Expand Down Expand Up @@ -777,15 +760,12 @@ TEST_P(DerivedCorrectnessP, MagCurlCorrectnessTest)
bpFileReader.Close();
EXPECT_LT(err / (Nx * Ny * Nz), error_limit);
}
*/

INSTANTIATE_TEST_SUITE_P(DerivedCorrectness, DerivedCorrectnessP,
::testing::Values(adios2::DerivedVarType::ExpressionString));
/*
::testing::Values(adios2::DerivedVarType::StatsOnly,
adios2::DerivedVarType::ExpressionString,
adios2::DerivedVarType::StoreData));
*/

int main(int argc, char **argv)
{
int result;
Expand Down

0 comments on commit 59c8e6b

Please sign in to comment.