diff --git a/vtkm/filter/Gradient.hxx b/vtkm/filter/Gradient.hxx index 0e2967908..8b80ad610 100644 --- a/vtkm/filter/Gradient.hxx +++ b/vtkm/filter/Gradient.hxx @@ -52,6 +52,19 @@ inline vtkm::cont::DataSet Gradient::DoExecute( throw vtkm::cont::ErrorFilterExecution("Point field expected."); } + constexpr bool isVector = std::is_same::HasMultipleComponents, + vtkm::VecTraitsTagMultipleComponents>::value; + + if (GetComputeQCriterion() && !isVector) + { + throw vtkm::cont::ErrorFilterExecution("scalar gradients can't generate qcriterion"); + } + + if (GetComputeVorticity() && !isVector) + { + throw vtkm::cont::ErrorFilterExecution("scalar gradients can't generate vorticity"); + } + const vtkm::cont::DynamicCellSet& cells = input.GetCellSet(); const vtkm::cont::CoordinateSystem& coords = input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()); @@ -86,9 +99,6 @@ inline vtkm::cont::DataSet Gradient::DoExecute( transpose_3x3(outArray); } - constexpr bool isVector = std::is_same::HasMultipleComponents, - vtkm::VecTraitsTagMultipleComponents>::value; - vtkm::cont::Field::Association fieldAssociation(this->ComputePointGradient ? vtkm::cont::Field::Association::POINTS : vtkm::cont::Field::Association::CELL_SET); diff --git a/vtkm/filter/testing/UnitTestGradient.cxx b/vtkm/filter/testing/UnitTestGradient.cxx index f5e98239e..5a9c03408 100644 --- a/vtkm/filter/testing/UnitTestGradient.cxx +++ b/vtkm/filter/testing/UnitTestGradient.cxx @@ -31,28 +31,17 @@ void TestCellGradientUniform3D() gradient.SetActiveField("pointvar"); - vtkm::cont::DataSet result = gradient.Execute(dataSet); + vtkm::cont::DataSet result; - VTKM_TEST_ASSERT(result.HasCellField("Gradient"), "Field missing."); - - //verify that the vorticity and qcriterion fields don't exist - VTKM_TEST_ASSERT(result.HasField("Vorticity") == false, - "scalar gradients can't generate vorticity"); - VTKM_TEST_ASSERT(result.HasField("QCriterion") == false, - "scalar gradients can't generate qcriterion"); - - vtkm::cont::ArrayHandle resultArrayHandle; - result.GetField("Gradient").GetData().CopyTo(resultArrayHandle); - vtkm::Vec3f_64 expected[4] = { - { 10.025, 30.075, 60.125 }, - { 10.025, 30.075, 60.125 }, - { 10.025, 30.075, 60.175 }, - { 10.025, 30.075, 60.175 }, - }; - for (int i = 0; i < 4; ++i) + // We provocate this exception + try { - VTKM_TEST_ASSERT(test_equal(resultArrayHandle.ReadPortal().Get(i), expected[i]), - "Wrong result for CellGradient filter on 3D uniform data"); + result = gradient.Execute(dataSet); + VTKM_TEST_FAIL("Gradient attempted to compute Vorticity or QCriterion with scalars"); + } + catch (vtkm::cont::ErrorFilterExecution&) + { + // We should exit in this catch } }