Move MeshQualityWarpage to its own filter

This commit is contained in:
Kenneth Moreland 2022-06-21 10:46:13 -06:00
parent 2702ee570d
commit af3b73777b
10 changed files with 249 additions and 23 deletions

@ -13,6 +13,7 @@ set(mesh_info_headers
MeshQuality.h
MeshQualityArea.h
MeshQualityVolume.h
MeshQualityWarpage.h
)
set(mesh_info_sources
@ -21,6 +22,7 @@ set(mesh_info_sources
MeshQuality.cxx
MeshQualityArea.cxx
MeshQualityVolume.cxx
MeshQualityWarpage.cxx
)
vtkm_library(

@ -23,6 +23,7 @@
#include <vtkm/filter/mesh_info/MeshQuality.h>
#include <vtkm/filter/mesh_info/MeshQualityArea.h>
#include <vtkm/filter/mesh_info/MeshQualityVolume.h>
#include <vtkm/filter/mesh_info/MeshQualityWarpage.h>
#include <vtkm/filter/mesh_info/worklet/MeshQuality.h>
namespace vtkm
@ -79,6 +80,9 @@ VTKM_CONT vtkm::cont::DataSet MeshQuality::DoExecute(const vtkm::cont::DataSet&
case vtkm::filter::mesh_info::CellMetric::Volume:
implementation.reset(new vtkm::filter::mesh_info::MeshQualityVolume);
break;
case vtkm::filter::mesh_info::CellMetric::Warpage:
implementation.reset(new vtkm::filter::mesh_info::MeshQualityWarpage);
break;
default:
implementation.reset(); // Eventually will go away
break;

@ -46,9 +46,13 @@ struct AreaWorklet : vtkm::worklet::WorkletVisitCellsWithPoints
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)
{

@ -0,0 +1,66 @@
//============================================================================
// 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/MeshQualityWarpage.h>
#include <vtkm/filter/mesh_info/worklet/MeshQualityWorklet.h>
#include <vtkm/filter/mesh_info/worklet/cellmetrics/CellWarpageMetric.h>
namespace
{
struct WarpageWorklet : MeshQualityWorklet<WarpageWorklet>
{
template <typename OutType, typename PointCoordVecType, typename CellShapeType>
VTKM_EXEC OutType ComputeMetric(const vtkm::IdComponent& numPts,
const PointCoordVecType& pts,
CellShapeType shape,
vtkm::ErrorCode& ec) const
{
return vtkm::worklet::cellmetrics::CellWarpageMetric<OutType>(numPts, pts, shape, ec);
}
};
} // anonymous namespace
namespace vtkm
{
namespace filter
{
namespace mesh_info
{
MeshQualityWarpage::MeshQualityWarpage()
{
this->SetUseCoordinateSystemAsField(true);
this->SetOutputFieldName("warpage");
}
vtkm::cont::DataSet MeshQualityWarpage::DoExecute(const vtkm::cont::DataSet& input)
{
vtkm::cont::UnknownArrayHandle outArray =
WarpageWorklet::Run(input, this->GetFieldFromDataSet(input));
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_MeshQualityWarpage_h
#define vtk_m_filter_mesh_info_MeshQualityWarpage_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 MeshQualityWarpage : public vtkm::filter::NewFilterField
{
public:
MeshQualityWarpage();
private:
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override;
};
} // namespace mesh_info
} // namespace filter
} // namespace vtkm
#endif //vtk_m_filter_mesh_info_MeshQualityWarpage_h

@ -11,6 +11,7 @@
set(headers
CellMeasure.h
MeshQuality.h
MeshQualityWorklet.h
)
vtkm_declare_headers(${headers})

@ -43,7 +43,6 @@
#include <vtkm/filter/mesh_info/worklet/cellmetrics/CellSkewMetric.h>
#include <vtkm/filter/mesh_info/worklet/cellmetrics/CellStretchMetric.h>
#include <vtkm/filter/mesh_info/worklet/cellmetrics/CellTaperMetric.h>
#include <vtkm/filter/mesh_info/worklet/cellmetrics/CellWarpageMetric.h>
#include <vtkm/worklet/WorkletMapTopology.h>
namespace vtkm
@ -187,10 +186,6 @@ private:
case vtkm::filter::mesh_info::CellMetric::Taper:
metricValue = vtkm::worklet::cellmetrics::CellTaperMetric<OutType>(numPts, pts, tag, ec);
break;
case vtkm::filter::mesh_info::CellMetric::Warpage:
metricValue =
vtkm::worklet::cellmetrics::CellWarpageMetric<OutType>(numPts, pts, tag, ec);
break;
case vtkm::filter::mesh_info::CellMetric::None:
break;
default:

@ -0,0 +1,110 @@
//============================================================================
// 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 2018 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
// Copyright 2018 UT-Battelle, LLC.
// Copyright 2018 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_worklet_MeshQualityWorklet_h
#define vtk_m_filter_mesh_info_worklet_MeshQualityWorklet_h
#include <vtkm/worklet/WorkletMapTopology.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/Field.h>
#include <vtkm/cont/UnknownArrayHandle.h>
#include <vtkm/ErrorCode.h>
#include <vtkm/TypeList.h>
namespace
{
/**
* Worklet that computes mesh quality metric values for each cell in
* the input mesh. A metric is specified per cell type in the calling filter,
* and this metric is invoked over all cells of that cell type. An array of
* the computed metric values (one per cell) is returned as output.
*/
template <typename Derived>
struct MeshQualityWorklet : 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;
}
const Derived* self = reinterpret_cast<const Derived*>(this);
vtkm::ErrorCode errorCode = vtkm::ErrorCode::Success;
switch (thisId)
{
vtkmGenericCellShapeMacro(metricValue = self->template ComputeMetric<OutType>(
numPoints, pts, CellShapeTag{}, errorCode));
default:
errorCode = vtkm::ErrorCode::CellNotFound;
metricValue = OutType(0.0);
}
if (errorCode != vtkm::ErrorCode::Success)
{
this->RaiseError(vtkm::ErrorString(errorCode));
}
}
VTKM_CONT static vtkm::cont::UnknownArrayHandle Run(const vtkm::cont::DataSet& input,
const vtkm::cont::Field& field)
{
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;
vtkm::cont::Invoker invoke;
auto resolveType = [&](const auto& concrete) {
using T = typename std::decay_t<decltype(concrete)>::ValueType::ComponentType;
vtkm::cont::ArrayHandle<T> result;
invoke(Derived{}, input.GetCellSet(), concrete, result);
outArray = result;
};
field.GetData()
.CastAndCallForTypesWithFloatFallback<vtkm::TypeListFieldVec3, VTKM_DEFAULT_STORAGE_LIST>(
resolveType);
return outArray;
}
};
} // anonymous namespace
#endif //vtk_m_filter_mesh_info_worklet_MeshQualityWorklet_h

@ -20,12 +20,12 @@
#ifndef vtk_m_worklet_CellWarpageMetric_h
#define vtk_m_worklet_CellWarpageMetric_h
#include "vtkm/CellShape.h"
#include "vtkm/CellTraits.h"
#include "vtkm/ErrorCode.h"
#include "vtkm/VecTraits.h"
#include "vtkm/VectorAnalysis.h"
#include "vtkm/exec/FunctorBase.h"
#include "TypeOfCellQuadrilateral.h"
#include <vtkm/CellShape.h>
#include <vtkm/CellTraits.h>
#include <vtkm/ErrorCode.h>
#include <vtkm/VecTraits.h>
#include <vtkm/VectorAnalysis.h>
namespace vtkm
{
@ -35,27 +35,21 @@ namespace cellmetrics
{
template <typename OutType, typename PointCoordVecType, typename CellShapeType>
VTKM_EXEC OutType CellWarpageMetric(const vtkm::IdComponent& numPts,
const PointCoordVecType& pts,
CellShapeType shape,
vtkm::ErrorCode& ec)
VTKM_EXEC OutType CellWarpageMetric(const vtkm::IdComponent& vtkmNotUsed(numPts),
const PointCoordVecType& vtkmNotUsed(pts),
CellShapeType vtkmNotUsed(shape),
vtkm::ErrorCode& vtkmNotUsed(ec))
{
UNUSED(numPts);
UNUSED(pts);
UNUSED(shape);
UNUSED(ec);
//ec = vtkm::ErrorCode::InvalidCellMetric;
return OutType(-1.0);
}
template <typename OutType, typename PointCoordVecType>
VTKM_EXEC OutType CellWarpageMetric(const vtkm::IdComponent& numPts,
VTKM_EXEC OutType CellWarpageMetric(const vtkm::IdComponent& vtkmNotUsed(numPts),
const PointCoordVecType& pts,
vtkm::CellShapeTagQuad,
vtkm::ErrorCode& ec)
vtkm::ErrorCode& vtkmNotUsed(ec))
{
UNUSED(numPts);
UNUSED(ec);
using Scalar = OutType;
using CollectionOfPoints = PointCoordVecType;
using Vector = typename PointCoordVecType::ComponentType;

@ -32,6 +32,10 @@
* used components for subsequent use in metrics.
*/
#include <vtkm/Math.h>
#include <vtkm/Types.h>
#include <vtkm/VectorAnalysis.h>
/**
* Returns the L0 vector, as defined by the verdict manual.
*