Move MeshQualityArea to its own filter

This commit is contained in:
Kenneth Moreland 2022-06-21 09:32:01 -06:00
parent ac06c00c7d
commit f307d69397
4 changed files with 194 additions and 0 deletions

@ -11,12 +11,14 @@ set(mesh_info_headers
CellMeasures.h
GhostCellClassify.h
MeshQuality.h
MeshQualityArea.h
)
set(mesh_info_sources
CellMeasures.cxx
GhostCellClassify.cxx
MeshQuality.cxx
MeshQualityArea.cxx
)
vtkm_library(

@ -20,6 +20,7 @@
#include <vtkm/cont/Algorithm.h>
#include <vtkm/cont/ErrorFilterExecution.h>
#include <vtkm/filter/mesh_info/MeshQuality.h>
#include <vtkm/filter/mesh_info/MeshQualityArea.h>
#include <vtkm/filter/mesh_info/worklet/MeshQuality.h>
namespace vtkm
@ -67,6 +68,24 @@ VTKM_CONT MeshQuality::MeshQuality(CellMetric metric)
VTKM_CONT vtkm::cont::DataSet MeshQuality::DoExecute(const vtkm::cont::DataSet& input)
{
std::unique_ptr<vtkm::filter::NewFilterField> implementation;
switch (this->MyMetric)
{
case vtkm::filter::mesh_info::CellMetric::Area:
implementation.reset(new vtkm::filter::mesh_info::MeshQualityArea);
break;
default:
implementation.reset(); // Eventually will go away
break;
}
if (implementation) // Eventually will not need this condition
{
implementation->SetOutputFieldName(this->GetOutputFieldName());
implementation->SetActiveCoordinateSystem(this->GetActiveCoordinateSystemIndex());
return implementation->Execute(input);
}
const auto& field = this->GetFieldFromDataSet(input);
if (!field.IsFieldPoint())
{

@ -0,0 +1,127 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//
// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//=========================================================================
#include <vtkm/filter/mesh_info/MeshQualityArea.h>
#include <vtkm/worklet/WorkletMapTopology.h>
#include <vtkm/ErrorCode.h>
#include <vtkm/exec/CellMeasure.h>
namespace
{
struct AreaWorklet : vtkm::worklet::WorkletVisitCellsWithPoints
{
using ControlSignature = void(CellSetIn cellset,
FieldInPoint pointCoords,
FieldOutCell metricOut);
using ExecutionSignature = void(CellShape, PointCount, _2, _3);
template <typename CellShapeType, typename PointCoordVecType, typename OutType>
VTKM_EXEC void operator()(CellShapeType shape,
const vtkm::IdComponent& numPoints,
const PointCoordVecType& pts,
OutType& metricValue) const
{
vtkm::UInt8 thisId = shape.Id;
if (shape.Id == vtkm::CELL_SHAPE_POLYGON)
{
if (numPoints == 3)
thisId = vtkm::CELL_SHAPE_TRIANGLE;
else if (numPoints == 4)
thisId = vtkm::CELL_SHAPE_QUAD;
}
switch (thisId)
{
vtkmGenericCellShapeMacro(metricValue =
this->ComputeMetric<OutType>(numPoints, pts, CellShapeTag()));
default:
this->RaiseError(vtkm::ErrorString(vtkm::ErrorCode::CellNotFound));
metricValue = OutType(0.0);
}
}
private:
template <typename OutType, typename PointCoordVecType, typename CellShapeType>
VTKM_EXEC OutType ComputeMetric(const vtkm::IdComponent& numPts,
const PointCoordVecType& pts,
CellShapeType tag) const
{
constexpr vtkm::IdComponent dims = vtkm::CellTraits<CellShapeType>::TOPOLOGICAL_DIMENSIONS;
vtkm::ErrorCode errorCode{ vtkm::ErrorCode::Success };
if (dims == 2)
{
OutType outValue = vtkm::exec::CellMeasure<OutType>(numPts, pts, tag, errorCode);
if (errorCode != vtkm::ErrorCode::Success)
{
this->RaiseError(vtkm::ErrorString(errorCode));
}
return outValue;
}
else
{
return 0;
}
}
};
} // anonymous namespace
namespace vtkm
{
namespace filter
{
namespace mesh_info
{
MeshQualityArea::MeshQualityArea()
{
this->SetUseCoordinateSystemAsField(true);
this->SetOutputFieldName("area");
}
vtkm::cont::DataSet MeshQualityArea::DoExecute(const vtkm::cont::DataSet& input)
{
const auto& field = this->GetFieldFromDataSet(input);
if (!field.IsFieldPoint())
{
throw vtkm::cont::ErrorBadValue("Active field for MeshQuality must be point coordinates. "
"But the active field is not a point field.");
}
vtkm::cont::UnknownArrayHandle outArray;
auto resolveType = [&](const auto& concrete) {
using T = typename std::decay_t<decltype(concrete)>::ValueType::ComponentType;
vtkm::cont::ArrayHandle<T> result;
this->Invoke(AreaWorklet{}, input.GetCellSet(), concrete, result);
outArray = result;
};
this->CastAndCallVecField<3>(field, resolveType);
return this->CreateResultFieldCell(input, this->GetOutputFieldName(), outArray);
}
} // namespace mesh_info
} // namespace filter
} // namespace vtkm

@ -0,0 +1,46 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//
// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtk_m_filter_mesh_info_MeshQualityArea_h
#define vtk_m_filter_mesh_info_MeshQualityArea_h
#include <vtkm/filter/NewFilterField.h>
#include <vtkm/filter/mesh_info/vtkm_filter_mesh_info_export.h>
namespace vtkm
{
namespace filter
{
namespace mesh_info
{
class VTKM_FILTER_MESH_INFO_EXPORT MeshQualityArea : public vtkm::filter::NewFilterField
{
public:
MeshQualityArea();
private:
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override;
};
} // namespace mesh_info
} // namespace filter
} // namespace vtkm
#endif //vtk_m_filter_mesh_info_MeshQualityArea_h