From 3b0cdcec27172ffb7d27b9727e7c8647f95d13a4 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Fri, 18 Mar 2022 12:58:57 -0600 Subject: [PATCH] Add tests for divergence, vorticity, and q criterion The gradient filter has the ability to compute divergence, vorticity, and q criterion. However, none of the gradient tests were actually testing the result of these computations. At best, one of the tests was checking that the arrays were created, but never actually looking at the values. For one of the gradient tests, this change computes these 3 values and checks the results, which look reasonable compared to ParaView. --- .../testing/UnitTestGradientUniform.cxx | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/vtkm/filter/vector_analysis/testing/UnitTestGradientUniform.cxx b/vtkm/filter/vector_analysis/testing/UnitTestGradientUniform.cxx index 3430cde66..0fbc06edb 100644 --- a/vtkm/filter/vector_analysis/testing/UnitTestGradientUniform.cxx +++ b/vtkm/filter/vector_analysis/testing/UnitTestGradientUniform.cxx @@ -68,6 +68,7 @@ void TestCellGradientUniform3DWithVectorField() //we need to add Vec3 array to the dataset vtkm::filter::vector_analysis::Gradient gradient; gradient.SetOutputFieldName("vec_gradient"); + gradient.SetComputeDivergence(true); gradient.SetComputeVorticity(true); gradient.SetComputeQCriterion(true); gradient.SetActiveField("vec_pointvar"); @@ -77,30 +78,32 @@ void TestCellGradientUniform3DWithVectorField() VTKM_TEST_ASSERT(result.HasCellField("vec_gradient"), "Result field missing."); //verify that the vorticity and qcriterion fields DO exist - VTKM_TEST_ASSERT(result.HasField("Vorticity") == true, "vec gradients should generate vorticity"); - VTKM_TEST_ASSERT(result.HasField("QCriterion") == true, - "vec gradients should generate qcriterion"); + VTKM_TEST_ASSERT(result.HasField("Divergence")); + VTKM_TEST_ASSERT(result.HasField("Vorticity")); + VTKM_TEST_ASSERT(result.HasField("QCriterion")); - vtkm::cont::ArrayHandle> resultArrayHandle; - result.GetCellField("vec_gradient").GetData().AsArrayHandle(resultArrayHandle); - vtkm::Vec expected[4] = { - { { 10.025, 10.025, 10.025 }, { 30.075, 30.075, 30.075 }, { 60.125, 60.125, 60.125 } }, - { { 10.025, 10.025, 10.025 }, { 30.075, 30.075, 30.075 }, { 60.125, 60.125, 60.125 } }, - { { 10.025, 10.025, 10.025 }, { 30.075, 30.075, 30.075 }, { 60.175, 60.175, 60.175 } }, - { { 10.025, 10.025, 10.025 }, { 30.075, 30.075, 30.075 }, { 60.175, 60.175, 60.175 } } - }; - for (int i = 0; i < 4; ++i) - { - vtkm::Vec e = expected[i]; - vtkm::Vec r = resultArrayHandle.ReadPortal().Get(i); + VTKM_TEST_ASSERT(test_equal_ArrayHandles( + result.GetCellField("vec_gradient").GetData(), + vtkm::cont::make_ArrayHandle>( + { { { 10.025, 10.025, 10.025 }, { 30.075, 30.075, 30.075 }, { 60.125, 60.125, 60.125 } }, + { { 10.025, 10.025, 10.025 }, { 30.075, 30.075, 30.075 }, { 60.125, 60.125, 60.125 } }, + { { 10.025, 10.025, 10.025 }, { 30.075, 30.075, 30.075 }, { 60.175, 60.175, 60.175 } }, + { { 10.025, 10.025, 10.025 }, { 30.075, 30.075, 30.075 }, { 60.175, 60.175, 60.175 } } }))); - VTKM_TEST_ASSERT(test_equal(e[0], r[0]), - "Wrong result for vec field CellGradient filter on 3D uniform data"); - VTKM_TEST_ASSERT(test_equal(e[1], r[1]), - "Wrong result for vec field CellGradient filter on 3D uniform data"); - VTKM_TEST_ASSERT(test_equal(e[2], r[2]), - "Wrong result for vec field CellGradient filter on 3D uniform data"); - } + VTKM_TEST_ASSERT(test_equal_ArrayHandles( + result.GetCellField("Divergence").GetData(), + vtkm::cont::make_ArrayHandle({ 100.225, 100.225, 100.275, 100.275 }))); + + VTKM_TEST_ASSERT(test_equal_ArrayHandles( + result.GetCellField("Vorticity").GetData(), + vtkm::cont::make_ArrayHandle({ { -30.05, 50.1, -20.05 }, + { -30.05, 50.1, -20.05 }, + { -30.1, 50.15, -20.05 }, + { -30.1, 50.15, -20.05 } }))); + + VTKM_TEST_ASSERT(test_equal_ArrayHandles( + result.GetCellField("QCriterion").GetData(), + vtkm::cont::make_ArrayHandle({ -5022.53, -5022.53, -5027.54, -5027.54 }))); }