From 38cc3be704518b12308e70da22494ddb1e7a2b2a Mon Sep 17 00:00:00 2001 From: anagainaru Date: Wed, 6 Nov 2024 12:08:03 -0500 Subject: [PATCH 1/2] Check for empty data entry for variables that are part of a derived variable --- source/adios2/engine/bp5/BP5Writer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/adios2/engine/bp5/BP5Writer.cpp b/source/adios2/engine/bp5/BP5Writer.cpp index 590c891a63..17d4df28e9 100644 --- a/source/adios2/engine/bp5/BP5Writer.cpp +++ b/source/adios2/engine/bp5/BP5Writer.cpp @@ -585,7 +585,7 @@ void BP5Writer::ComputeDerivedVariables() // extract the dimensions and data for each variable VariableBase *varBase = itVariable->second.get(); auto mvi = WriterMinBlocksInfo(*varBase); - if (mvi->BlocksInfo.size() == 0) + if (!mvi || mvi->BlocksInfo.size() == 0) { computeDerived = false; break; From 7eccd3bfa036c20137a64a3b7a5a0a2479a9fd29 Mon Sep 17 00:00:00 2001 From: anagainaru Date: Wed, 6 Nov 2024 12:58:33 -0500 Subject: [PATCH 2/2] Update the derived variable testing for when the component variables are not written --- .../derived/TestBPDerivedCorrectness.cpp | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/testing/adios2/derived/TestBPDerivedCorrectness.cpp b/testing/adios2/derived/TestBPDerivedCorrectness.cpp index 4c3fadbb3b..f31c91234e 100644 --- a/testing/adios2/derived/TestBPDerivedCorrectness.cpp +++ b/testing/adios2/derived/TestBPDerivedCorrectness.cpp @@ -25,6 +25,42 @@ class DerivedCorrectnessP : public DerivedCorrectness, adios2::DerivedVarType GetThreads() { return GetParam(); }; }; +TEST_P(DerivedCorrectnessP, BasicCorrectnessTest) +{ + adios2::DerivedVarType mode = GetParam(); + adios2::ADIOS adios; + adios2::IO bpOut = adios.DeclareIO("BPNoData"); + EXPECT_THROW(bpOut.DefineDerivedVariable("derived", "x= var1 \n sqrt(x)", mode), + std::invalid_argument); + + const size_t N = 10; + std::default_random_engine generator; + std::uniform_real_distribution distribution(0.0, 10.0); + std::vector simArray1(N); + std::vector simArray2(N); + for (size_t i = 0; i < N; ++i) + simArray1[i] = distribution(generator); + + auto U = bpOut.DefineVariable("var1", {N}, {0}, {N}); + auto V = bpOut.DefineVariable("var2", {N}, {0}, {N}); + bpOut.DefineDerivedVariable("derived", "x= var1 \n sqrt(x)", mode); + adios2::Engine bpFileWriter = bpOut.Open("BPNoData.bp", adios2::Mode::Write); + + bpFileWriter.BeginStep(); + bpFileWriter.Put(V, simArray1.data()); + bpFileWriter.EndStep(); + bpFileWriter.Close(); + + // check that no derived data was written + adios2::IO bpIn = adios.DeclareIO("BPReadExpression"); + adios2::Engine bpFileReader = bpIn.Open("BPNoData.bp", adios2::Mode::Read); + bpFileReader.BeginStep(); + auto derVar = bpIn.InquireVariable("derived"); + EXPECT_FALSE(derVar); + bpFileReader.EndStep(); + bpFileReader.Close(); +} + TEST_P(DerivedCorrectnessP, ScalarFunctionsCorrectnessTest) { const size_t Nx = 10, Ny = 3, Nz = 6;