mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-19 02:25:42 +00:00
Move MeshQualityShapeAndSize to its own filter
Also added functions to MeshQualityArea and MeshQualityVolume to find the average area and volume, respectively, of a dataset. This can now be shared among metrics that need this value. Also had to make a small change to the Run method of MeshQualityWorklet to preserve state of the worklet.
This commit is contained in:
parent
553e627455
commit
05cad24592
@ -13,6 +13,7 @@ set(mesh_info_headers
|
||||
MeshQuality.h
|
||||
MeshQualityArea.h
|
||||
MeshQualityShape.h
|
||||
MeshQualityShapeAndSize.h
|
||||
MeshQualityShear.h
|
||||
MeshQualitySkew.h
|
||||
MeshQualityStretch.h
|
||||
@ -27,6 +28,7 @@ set(mesh_info_sources
|
||||
MeshQuality.cxx
|
||||
MeshQualityArea.cxx
|
||||
MeshQualityShape.cxx
|
||||
MeshQualityShapeAndSize.cxx
|
||||
MeshQualityShear.cxx
|
||||
MeshQualitySkew.cxx
|
||||
MeshQualityStretch.cxx
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <vtkm/filter/mesh_info/MeshQuality.h>
|
||||
#include <vtkm/filter/mesh_info/MeshQualityArea.h>
|
||||
#include <vtkm/filter/mesh_info/MeshQualityShape.h>
|
||||
#include <vtkm/filter/mesh_info/MeshQualityShapeAndSize.h>
|
||||
#include <vtkm/filter/mesh_info/MeshQualityShear.h>
|
||||
#include <vtkm/filter/mesh_info/MeshQualitySkew.h>
|
||||
#include <vtkm/filter/mesh_info/MeshQualityStretch.h>
|
||||
@ -85,6 +86,9 @@ VTKM_CONT vtkm::cont::DataSet MeshQuality::DoExecute(const vtkm::cont::DataSet&
|
||||
case vtkm::filter::mesh_info::CellMetric::Shape:
|
||||
implementation.reset(new vtkm::filter::mesh_info::MeshQualityShape);
|
||||
break;
|
||||
case vtkm::filter::mesh_info::CellMetric::ShapeAndSize:
|
||||
implementation.reset(new vtkm::filter::mesh_info::MeshQualityShapeAndSize);
|
||||
break;
|
||||
case vtkm::filter::mesh_info::CellMetric::Shear:
|
||||
implementation.reset(new vtkm::filter::mesh_info::MeshQualityShear);
|
||||
break;
|
||||
|
@ -22,6 +22,8 @@
|
||||
|
||||
#include <vtkm/worklet/WorkletMapTopology.h>
|
||||
|
||||
#include <vtkm/cont/Algorithm.h>
|
||||
|
||||
#include <vtkm/ErrorCode.h>
|
||||
|
||||
#include <vtkm/exec/CellMeasure.h>
|
||||
@ -104,6 +106,40 @@ MeshQualityArea::MeshQualityArea()
|
||||
this->SetOutputFieldName("area");
|
||||
}
|
||||
|
||||
vtkm::Float64 MeshQualityArea::ComputeTotalArea(const vtkm::cont::DataSet& input)
|
||||
{
|
||||
vtkm::cont::Field areaField;
|
||||
if (input.HasCellField(this->GetOutputFieldName()))
|
||||
{
|
||||
areaField = input.GetCellField(this->GetOutputFieldName());
|
||||
}
|
||||
else
|
||||
{
|
||||
vtkm::cont::DataSet areaData = this->Execute(input);
|
||||
areaField = areaData.GetCellField(this->GetOutputFieldName());
|
||||
}
|
||||
|
||||
vtkm::Float64 totalArea = 0;
|
||||
auto resolveType = [&](const auto& concrete) {
|
||||
totalArea = vtkm::cont::Algorithm::Reduce(concrete, vtkm::Float64{ 0 });
|
||||
};
|
||||
this->CastAndCallScalarField(areaField, resolveType);
|
||||
return totalArea;
|
||||
}
|
||||
|
||||
vtkm::Float64 MeshQualityArea::ComputeAverageArea(const vtkm::cont::DataSet& input)
|
||||
{
|
||||
vtkm::Id numCells = input.GetNumberOfCells();
|
||||
if (numCells > 0)
|
||||
{
|
||||
return this->ComputeTotalArea(input) / static_cast<vtkm::Float64>(numCells);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
vtkm::cont::DataSet MeshQualityArea::DoExecute(const vtkm::cont::DataSet& input)
|
||||
{
|
||||
const auto& field = this->GetFieldFromDataSet(input);
|
||||
|
@ -35,6 +35,15 @@ class VTKM_FILTER_MESH_INFO_EXPORT MeshQualityArea : public vtkm::filter::NewFil
|
||||
public:
|
||||
MeshQualityArea();
|
||||
|
||||
/// \brief Computes the area of all polygonal cells and returns the total area.
|
||||
vtkm::Float64 ComputeTotalArea(const vtkm::cont::DataSet& input);
|
||||
|
||||
/// \brief Computes the average area of cells.
|
||||
///
|
||||
/// This method first computes the total area of all cells and then divides that by the
|
||||
/// number of cells in the dataset.
|
||||
vtkm::Float64 ComputeAverageArea(const vtkm::cont::DataSet& input);
|
||||
|
||||
private:
|
||||
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override;
|
||||
};
|
||||
|
@ -56,7 +56,7 @@ MeshQualityShape::MeshQualityShape()
|
||||
vtkm::cont::DataSet MeshQualityShape::DoExecute(const vtkm::cont::DataSet& input)
|
||||
{
|
||||
vtkm::cont::UnknownArrayHandle outArray =
|
||||
ShapeWorklet::Run(input, this->GetFieldFromDataSet(input));
|
||||
ShapeWorklet{}.Run(input, this->GetFieldFromDataSet(input));
|
||||
|
||||
return this->CreateResultFieldCell(input, this->GetOutputFieldName(), outArray);
|
||||
}
|
||||
|
97
vtkm/filter/mesh_info/MeshQualityShapeAndSize.cxx
Normal file
97
vtkm/filter/mesh_info/MeshQualityShapeAndSize.cxx
Normal file
@ -0,0 +1,97 @@
|
||||
//============================================================================
|
||||
// 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/filter/mesh_info/MeshQualityShapeAndSize.h>
|
||||
#include <vtkm/filter/mesh_info/MeshQualityVolume.h>
|
||||
|
||||
#include <vtkm/filter/mesh_info/worklet/MeshQualityWorklet.h>
|
||||
#include <vtkm/filter/mesh_info/worklet/cellmetrics/CellShapeAndSizeMetric.h>
|
||||
|
||||
#include <vtkm/CellTraits.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
struct ShapeAndSizeWorklet : MeshQualityWorklet<ShapeAndSizeWorklet>
|
||||
{
|
||||
vtkm::Float64 AverageArea;
|
||||
vtkm::Float64 AverageVolume;
|
||||
|
||||
VTKM_CONT ShapeAndSizeWorklet(vtkm::Float64 averageArea, vtkm::Float64 averageVolume)
|
||||
: AverageArea(averageArea)
|
||||
, AverageVolume(averageVolume)
|
||||
{
|
||||
}
|
||||
|
||||
VTKM_EXEC vtkm::Float64 GetAverageSize(vtkm::CellTopologicalDimensionsTag<2>) const
|
||||
{
|
||||
return this->AverageArea;
|
||||
}
|
||||
VTKM_EXEC vtkm::Float64 GetAverageSize(vtkm::CellTopologicalDimensionsTag<3>) const
|
||||
{
|
||||
return this->AverageVolume;
|
||||
}
|
||||
template <vtkm::IdComponent Dimension>
|
||||
VTKM_EXEC vtkm::Float64 GetAverageSize(vtkm::CellTopologicalDimensionsTag<Dimension>) const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
template <typename OutType, typename PointCoordVecType, typename CellShapeType>
|
||||
VTKM_EXEC OutType ComputeMetric(const vtkm::IdComponent& numPts,
|
||||
const PointCoordVecType& pts,
|
||||
CellShapeType shape,
|
||||
vtkm::ErrorCode& ec) const
|
||||
{
|
||||
using DimensionTag = typename vtkm::CellTraits<CellShapeType>::TopologicalDimensionsTag;
|
||||
return vtkm::worklet::cellmetrics::CellShapeAndSizeMetric<OutType>(
|
||||
numPts, pts, static_cast<OutType>(this->GetAverageSize(DimensionTag{})), shape, ec);
|
||||
}
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace filter
|
||||
{
|
||||
namespace mesh_info
|
||||
{
|
||||
|
||||
MeshQualityShapeAndSize::MeshQualityShapeAndSize()
|
||||
{
|
||||
this->SetUseCoordinateSystemAsField(true);
|
||||
this->SetOutputFieldName("shapeAndSize");
|
||||
}
|
||||
|
||||
vtkm::cont::DataSet MeshQualityShapeAndSize::DoExecute(const vtkm::cont::DataSet& input)
|
||||
{
|
||||
ShapeAndSizeWorklet worklet(
|
||||
vtkm::filter::mesh_info::MeshQualityArea{}.ComputeAverageArea(input),
|
||||
vtkm::filter::mesh_info::MeshQualityVolume{}.ComputeAverageVolume(input));
|
||||
vtkm::cont::UnknownArrayHandle outArray = worklet.Run(input, this->GetFieldFromDataSet(input));
|
||||
|
||||
return this->CreateResultFieldCell(input, this->GetOutputFieldName(), outArray);
|
||||
}
|
||||
|
||||
} // namespace mesh_info
|
||||
} // namespace filter
|
||||
} // namespace vtkm
|
46
vtkm/filter/mesh_info/MeshQualityShapeAndSize.h
Normal file
46
vtkm/filter/mesh_info/MeshQualityShapeAndSize.h
Normal file
@ -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_MeshQualityShapeAndSize_h
|
||||
#define vtk_m_filter_mesh_info_MeshQualityShapeAndSize_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 MeshQualityShapeAndSize : public vtkm::filter::NewFilterField
|
||||
{
|
||||
public:
|
||||
MeshQualityShapeAndSize();
|
||||
|
||||
private:
|
||||
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override;
|
||||
};
|
||||
|
||||
} // namespace mesh_info
|
||||
} // namespace filter
|
||||
} // namespace vtkm
|
||||
|
||||
#endif //vtk_m_filter_mesh_info_MeshQualityShapeAndSize_h
|
@ -56,7 +56,7 @@ MeshQualityShear::MeshQualityShear()
|
||||
vtkm::cont::DataSet MeshQualityShear::DoExecute(const vtkm::cont::DataSet& input)
|
||||
{
|
||||
vtkm::cont::UnknownArrayHandle outArray =
|
||||
ShearWorklet::Run(input, this->GetFieldFromDataSet(input));
|
||||
ShearWorklet{}.Run(input, this->GetFieldFromDataSet(input));
|
||||
|
||||
return this->CreateResultFieldCell(input, this->GetOutputFieldName(), outArray);
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ MeshQualitySkew::MeshQualitySkew()
|
||||
vtkm::cont::DataSet MeshQualitySkew::DoExecute(const vtkm::cont::DataSet& input)
|
||||
{
|
||||
vtkm::cont::UnknownArrayHandle outArray =
|
||||
SkewWorklet::Run(input, this->GetFieldFromDataSet(input));
|
||||
SkewWorklet{}.Run(input, this->GetFieldFromDataSet(input));
|
||||
|
||||
return this->CreateResultFieldCell(input, this->GetOutputFieldName(), outArray);
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ MeshQualityStretch::MeshQualityStretch()
|
||||
vtkm::cont::DataSet MeshQualityStretch::DoExecute(const vtkm::cont::DataSet& input)
|
||||
{
|
||||
vtkm::cont::UnknownArrayHandle outArray =
|
||||
StretchWorklet::Run(input, this->GetFieldFromDataSet(input));
|
||||
StretchWorklet{}.Run(input, this->GetFieldFromDataSet(input));
|
||||
|
||||
return this->CreateResultFieldCell(input, this->GetOutputFieldName(), outArray);
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ MeshQualityTaper::MeshQualityTaper()
|
||||
vtkm::cont::DataSet MeshQualityTaper::DoExecute(const vtkm::cont::DataSet& input)
|
||||
{
|
||||
vtkm::cont::UnknownArrayHandle outArray =
|
||||
TaperWorklet::Run(input, this->GetFieldFromDataSet(input));
|
||||
TaperWorklet{}.Run(input, this->GetFieldFromDataSet(input));
|
||||
|
||||
return this->CreateResultFieldCell(input, this->GetOutputFieldName(), outArray);
|
||||
}
|
||||
|
@ -22,6 +22,8 @@
|
||||
|
||||
#include <vtkm/worklet/WorkletMapTopology.h>
|
||||
|
||||
#include <vtkm/cont/Algorithm.h>
|
||||
|
||||
#include <vtkm/ErrorCode.h>
|
||||
|
||||
#include <vtkm/exec/CellMeasure.h>
|
||||
@ -93,6 +95,40 @@ MeshQualityVolume::MeshQualityVolume()
|
||||
this->SetOutputFieldName("volume");
|
||||
}
|
||||
|
||||
vtkm::Float64 MeshQualityVolume::ComputeTotalVolume(const vtkm::cont::DataSet& input)
|
||||
{
|
||||
vtkm::cont::Field volumeField;
|
||||
if (input.HasCellField(this->GetOutputFieldName()))
|
||||
{
|
||||
volumeField = input.GetCellField(this->GetOutputFieldName());
|
||||
}
|
||||
else
|
||||
{
|
||||
vtkm::cont::DataSet volumeData = this->Execute(input);
|
||||
volumeField = volumeData.GetCellField(this->GetOutputFieldName());
|
||||
}
|
||||
|
||||
vtkm::Float64 totalVolume = 0;
|
||||
auto resolveType = [&](const auto& concrete) {
|
||||
totalVolume = vtkm::cont::Algorithm::Reduce(concrete, vtkm::Float64{ 0 });
|
||||
};
|
||||
this->CastAndCallScalarField(volumeField, resolveType);
|
||||
return totalVolume;
|
||||
}
|
||||
|
||||
vtkm::Float64 MeshQualityVolume::ComputeAverageVolume(const vtkm::cont::DataSet& input)
|
||||
{
|
||||
vtkm::Id numCells = input.GetNumberOfCells();
|
||||
if (numCells > 0)
|
||||
{
|
||||
return this->ComputeTotalVolume(input) / static_cast<vtkm::Float64>(numCells);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
vtkm::cont::DataSet MeshQualityVolume::DoExecute(const vtkm::cont::DataSet& input)
|
||||
{
|
||||
const auto& field = this->GetFieldFromDataSet(input);
|
||||
|
@ -35,6 +35,15 @@ class VTKM_FILTER_MESH_INFO_EXPORT MeshQualityVolume : public vtkm::filter::NewF
|
||||
public:
|
||||
MeshQualityVolume();
|
||||
|
||||
/// \brief Computes the volume of all polyhedral cells and returns the total area.
|
||||
vtkm::Float64 ComputeTotalVolume(const vtkm::cont::DataSet& input);
|
||||
|
||||
/// \brief Computes the average volume of cells.
|
||||
///
|
||||
/// This method first computes the total volume of all cells and then divides that by the
|
||||
/// number of cells in the dataset.
|
||||
vtkm::Float64 ComputeAverageVolume(const vtkm::cont::DataSet& input);
|
||||
|
||||
private:
|
||||
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override;
|
||||
};
|
||||
|
@ -56,7 +56,7 @@ MeshQualityWarpage::MeshQualityWarpage()
|
||||
vtkm::cont::DataSet MeshQualityWarpage::DoExecute(const vtkm::cont::DataSet& input)
|
||||
{
|
||||
vtkm::cont::UnknownArrayHandle outArray =
|
||||
WarpageWorklet::Run(input, this->GetFieldFromDataSet(input));
|
||||
WarpageWorklet{}.Run(input, this->GetFieldFromDataSet(input));
|
||||
|
||||
return this->CreateResultFieldCell(input, this->GetOutputFieldName(), outArray);
|
||||
}
|
||||
|
@ -37,7 +37,6 @@
|
||||
#include <vtkm/filter/mesh_info/worklet/cellmetrics/CellOddyMetric.h>
|
||||
#include <vtkm/filter/mesh_info/worklet/cellmetrics/CellRelativeSizeSquaredMetric.h>
|
||||
#include <vtkm/filter/mesh_info/worklet/cellmetrics/CellScaledJacobianMetric.h>
|
||||
#include <vtkm/filter/mesh_info/worklet/cellmetrics/CellShapeAndSizeMetric.h>
|
||||
#include <vtkm/worklet/WorkletMapTopology.h>
|
||||
|
||||
namespace vtkm
|
||||
@ -157,10 +156,6 @@ private:
|
||||
metricValue = vtkm::worklet::cellmetrics::CellRelativeSizeSquaredMetric<OutType>(
|
||||
numPts, pts, static_cast<OutType>(average), tag, ec);
|
||||
break;
|
||||
case vtkm::filter::mesh_info::CellMetric::ShapeAndSize:
|
||||
metricValue = vtkm::worklet::cellmetrics::CellShapeAndSizeMetric<OutType>(
|
||||
numPts, pts, static_cast<OutType>(average), tag, ec);
|
||||
break;
|
||||
case vtkm::filter::mesh_info::CellMetric::ScaledJacobian:
|
||||
metricValue =
|
||||
vtkm::worklet::cellmetrics::CellScaledJacobianMetric<OutType>(numPts, pts, tag, ec);
|
||||
|
@ -79,8 +79,8 @@ struct MeshQualityWorklet : vtkm::worklet::WorkletVisitCellsWithPoints
|
||||
}
|
||||
}
|
||||
|
||||
VTKM_CONT static vtkm::cont::UnknownArrayHandle Run(const vtkm::cont::DataSet& input,
|
||||
const vtkm::cont::Field& field)
|
||||
VTKM_CONT vtkm::cont::UnknownArrayHandle Run(const vtkm::cont::DataSet& input,
|
||||
const vtkm::cont::Field& field) const
|
||||
{
|
||||
if (!field.IsFieldPoint())
|
||||
{
|
||||
@ -94,7 +94,7 @@ struct MeshQualityWorklet : vtkm::worklet::WorkletVisitCellsWithPoints
|
||||
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);
|
||||
invoke(*reinterpret_cast<const Derived*>(this), input.GetCellSet(), concrete, result);
|
||||
outArray = result;
|
||||
};
|
||||
field.GetData()
|
||||
|
@ -40,7 +40,7 @@
|
||||
#include <vtkm/Matrix.h>
|
||||
#include <vtkm/VecTraits.h>
|
||||
#include <vtkm/VectorAnalysis.h>
|
||||
#include <vtkm/exec/FunctorBase.h>
|
||||
#include <vtkm/exec/CellMeasure.h>
|
||||
|
||||
#define UNUSED(expr) (void)(expr);
|
||||
|
||||
|
@ -31,12 +31,13 @@
|
||||
* metric)
|
||||
*/
|
||||
|
||||
#include "CellRelativeSizeSquaredMetric.h"
|
||||
#include "CellShapeMetric.h"
|
||||
#include "vtkm/CellShape.h"
|
||||
#include "vtkm/CellTraits.h"
|
||||
#include "vtkm/VecTraits.h"
|
||||
#include "vtkm/VectorAnalysis.h"
|
||||
#include "vtkm/exec/FunctorBase.h"
|
||||
#include <vtkm/CellShape.h>
|
||||
#include <vtkm/CellTraits.h>
|
||||
#include <vtkm/ErrorCode.h>
|
||||
#include <vtkm/VecTraits.h>
|
||||
#include <vtkm/VectorAnalysis.h>
|
||||
|
||||
#define UNUSED(expr) (void)(expr);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user