From 294a489f5bfc541fff4e1c99b0435e99c349e432 Mon Sep 17 00:00:00 2001 From: Dave Pugmire Date: Mon, 23 May 2022 15:29:54 -0400 Subject: [PATCH 001/104] Rough draft at particle advection filters. --- vtkm/filter/CMakeLists.txt | 4 +- vtkm/filter/FilterParticleAdvection.h | 19 +- vtkm/filter/FilterParticleAdvection.hxx | 3 + vtkm/filter/ParticleAdvection.hxx | 9 +- vtkm/filter/ParticleAdvection2.h | 48 +++ vtkm/filter/ParticleAdvection2.hxx | 102 +++++ vtkm/filter/PathParticle.hxx | 10 +- vtkm/filter/Pathline.hxx | 4 + vtkm/filter/Streamline.hxx | 9 +- vtkm/filter/particleadvection/ABA.h | 381 ++++++++++++++++++ .../particleadvection/AdvectorBaseAlgorithm.h | 37 +- .../AdvectorBaseThreadedAlgorithm.h | 2 + vtkm/filter/particleadvection/BoundsMap.h | 2 +- vtkm/filter/particleadvection/CMakeLists.txt | 4 + vtkm/filter/particleadvection/DSI.h | 100 +++++ vtkm/filter/particleadvection/DSI.hxx | 95 +++++ .../particleadvection/DataSetIntegrator.h | 1 + vtkm/filter/particleadvection/PAV.h | 70 ++++ .../ParticleAdvectionAlgorithm.h | 4 +- .../ParticleAdvectionTypes.h | 42 ++ .../particleadvection/ParticleMessenger.cxx | 54 ++- .../particleadvection/ParticleMessenger.h | 19 +- .../testing/UnitTestStreamlineFilter.cxx | 13 +- 23 files changed, 975 insertions(+), 57 deletions(-) create mode 100644 vtkm/filter/ParticleAdvection2.h create mode 100644 vtkm/filter/ParticleAdvection2.hxx create mode 100644 vtkm/filter/particleadvection/ABA.h create mode 100644 vtkm/filter/particleadvection/DSI.h create mode 100644 vtkm/filter/particleadvection/DSI.hxx create mode 100644 vtkm/filter/particleadvection/PAV.h create mode 100644 vtkm/filter/particleadvection/ParticleAdvectionTypes.h diff --git a/vtkm/filter/CMakeLists.txt b/vtkm/filter/CMakeLists.txt index 45b3cd7ab..356356bbf 100644 --- a/vtkm/filter/CMakeLists.txt +++ b/vtkm/filter/CMakeLists.txt @@ -105,6 +105,7 @@ set(extra_headers LagrangianStructures.h MIRFilter.h ParticleAdvection.h + ParticleAdvection2.h Pathline.h PathParticle.h Streamline.h @@ -120,6 +121,7 @@ set(extra_header_template_sources LagrangianStructures.hxx MIRFilter.hxx ParticleAdvection.hxx + ParticleAdvection2.hxx Pathline.hxx PathParticle.hxx Streamline.hxx @@ -128,7 +130,7 @@ set(extra_header_template_sources set(extra_sources_device particleadvection/Messenger.cxx - particleadvection/ParticleMessenger.cxx + #particleadvection/ParticleMessenger.cxx ) set(core_headers diff --git a/vtkm/filter/FilterParticleAdvection.h b/vtkm/filter/FilterParticleAdvection.h index 8567ca494..5abbc056c 100644 --- a/vtkm/filter/FilterParticleAdvection.h +++ b/vtkm/filter/FilterParticleAdvection.h @@ -15,6 +15,7 @@ #include #include #include +#include namespace vtkm { @@ -47,6 +48,17 @@ public: this->Seeds = vtkm::cont::make_ArrayHandle(seeds, copyFlag); } + VTKM_CONT + void SetSolverRK4() + { + this->SolverType = vtkm::filter::particleadvection::IntegrationSolverType::RK4_TYPE; + } + VTKM_CONT + void SetSolverEuler() + { + this->SolverType = vtkm::filter::particleadvection::IntegrationSolverType::EULER_TYPE; + } + VTKM_CONT void SetSeeds(vtkm::cont::ArrayHandle& seeds) { this->Seeds = seeds; } @@ -71,14 +83,19 @@ public: protected: VTKM_CONT virtual void ValidateOptions() const; + /* VTKM_CONT std::vector CreateDataSetIntegrators(const vtkm::cont::PartitionedDataSet& input, const vtkm::filter::particleadvection::BoundsMap& boundsMap) const; + */ vtkm::Id NumberOfSteps; - vtkm::FloatDefault StepSize; + vtkm::filter::particleadvection::ParticleAdvectionResultType ResultType; vtkm::cont::ArrayHandle Seeds; + vtkm::filter::particleadvection::IntegrationSolverType SolverType; + vtkm::FloatDefault StepSize; bool UseThreadedAlgorithm; + vtkm::filter::particleadvection::VectorFieldType VecFieldType; private: }; diff --git a/vtkm/filter/FilterParticleAdvection.hxx b/vtkm/filter/FilterParticleAdvection.hxx index dee896cda..7627e6d79 100644 --- a/vtkm/filter/FilterParticleAdvection.hxx +++ b/vtkm/filter/FilterParticleAdvection.hxx @@ -22,6 +22,7 @@ template inline VTKM_CONT FilterParticleAdvection::FilterParticleAdvection() : vtkm::filter::FilterDataSetWithField() , NumberOfSteps(0) + , SolverType(vtkm::filter::particleadvection::RK4_TYPE) , StepSize(0) , UseThreadedAlgorithm(false) { @@ -40,6 +41,7 @@ void FilterParticleAdvection::ValidateOptions() const throw vtkm::cont::ErrorFilterExecution("Step size not specified."); } +/* template std::vector FilterParticleAdvection::CreateDataSetIntegrators( @@ -66,6 +68,7 @@ FilterParticleAdvection::CreateDataSetIntegrators( return dsi; } + */ //----------------------------------------------------------------------------- template diff --git a/vtkm/filter/ParticleAdvection.hxx b/vtkm/filter/ParticleAdvection.hxx index 3b910b592..cafec087a 100644 --- a/vtkm/filter/ParticleAdvection.hxx +++ b/vtkm/filter/ParticleAdvection.hxx @@ -36,11 +36,13 @@ ParticleAdvectionBase::PrepareForExecution( const vtkm::cont::PartitionedDataSet& input, const vtkm::filter::PolicyBase&) { - using AlgorithmType = vtkm::filter::particleadvection::ParticleAdvectionAlgorithm; - using ThreadedAlgorithmType = vtkm::filter::particleadvection::ParticleAdvectionThreadedAlgorithm; - using DSIType = vtkm::filter::particleadvection::DataSetIntegrator; + // using AlgorithmType = vtkm::filter::particleadvection::ParticleAdvectionAlgorithm; + // using ThreadedAlgorithmType = vtkm::filter::particleadvection::ParticleAdvectionThreadedAlgorithm; + // using DSIType = vtkm::filter::particleadvection::DataSetIntegrator; this->ValidateOptions(); + return input; +#if 0 vtkm::filter::particleadvection::BoundsMap boundsMap(input); auto dsi = this->CreateDataSetIntegrators(input, boundsMap); @@ -50,6 +52,7 @@ ParticleAdvectionBase::PrepareForExecution( else return vtkm::filter::particleadvection::RunAlgo( boundsMap, dsi, this->NumberOfSteps, this->StepSize, this->Seeds); +#endif } } diff --git a/vtkm/filter/ParticleAdvection2.h b/vtkm/filter/ParticleAdvection2.h new file mode 100644 index 000000000..a7e03aaea --- /dev/null +++ b/vtkm/filter/ParticleAdvection2.h @@ -0,0 +1,48 @@ +//============================================================================ +// 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. +//============================================================================ + +#ifndef vtk_m_filter_ParticleAdvection2_h +#define vtk_m_filter_ParticleAdvection2_h + +#include +#include + +namespace vtkm +{ +namespace filter +{ +/// \brief Advect particles in a vector field. + +/// Takes as input a vector field and seed locations and generates the +/// end points for each seed through the vector field. + +class ParticleAdvection2 + : public vtkm::filter::FilterParticleAdvection +{ +public: + VTKM_CONT ParticleAdvection2(); + + template + vtkm::cont::PartitionedDataSet PrepareForExecution( + const vtkm::cont::PartitionedDataSet& input, + const vtkm::filter::PolicyBase& policy); + + + vtkm::cont::UnknownArrayHandle SeedArray; +}; + +} +} // namespace vtkm::filter + +#ifndef vtk_m_filter_ParticleAdvection2_hxx +#include +#endif + +#endif // vtk_m_filter_ParticleAdvection_h diff --git a/vtkm/filter/ParticleAdvection2.hxx b/vtkm/filter/ParticleAdvection2.hxx new file mode 100644 index 000000000..819693e64 --- /dev/null +++ b/vtkm/filter/ParticleAdvection2.hxx @@ -0,0 +1,102 @@ +//============================================================================ +// 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. +//============================================================================ +#ifndef vtk_m_filter_ParticleAdvection2_hxx +#define vtk_m_filter_ParticleAdvection2_hxx + +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace vtkm +{ +namespace filter +{ + +//----------------------------------------------------------------------------- +inline VTKM_CONT ParticleAdvection2::ParticleAdvection2() + : vtkm::filter::FilterParticleAdvection() +{ +} + +//----------------------------------------------------------------------------- +template +inline VTKM_CONT vtkm::cont::PartitionedDataSet ParticleAdvection2::PrepareForExecution( + const vtkm::cont::PartitionedDataSet& input, + const vtkm::filter::PolicyBase&) +{ + // using AlgorithmType = vtkm::filter::particleadvection::ParticleAdvectionAlgorithm; + // using ThreadedAlgorithmType = vtkm::filter::particleadvection::ParticleAdvectionThreadedAlgorithm; + using DSIType = vtkm::filter::particleadvection::DSI; + + this->ValidateOptions(); + //Make sure everything matches up ok. + this->VecFieldType = vtkm::filter::particleadvection::VELOCITY_FIELD_TYPE; + + vtkm::filter::particleadvection::BoundsMap boundsMap(input); + std::string activeField = this->GetActiveFieldName(); + + std::vector dsi; + for (vtkm::Id i = 0; i < input.GetNumberOfPartitions(); i++) + { + vtkm::Id blockId = boundsMap.GetLocalBlockId(i); + auto ds = input.GetPartition(i); + if (!ds.HasPointField(activeField) && !ds.HasCellField(activeField)) + throw vtkm::cont::ErrorFilterExecution("Unsupported field assocation"); + + dsi.push_back(DSIType(ds, blockId, activeField, this->SolverType, this->VecFieldType)); + } + + std::vector seeds; + seeds.push_back(this->Seeds.ReadPortal().Get(0)); + seeds.push_back(this->Seeds.ReadPortal().Get(1)); + seeds.push_back(this->Seeds.ReadPortal().Get(2)); + std::cout << "SEEDS= " << seeds[0].Pos << " " << seeds[1].Pos << " " << seeds[2].Pos << std::endl; + + //this->SeedArray = this->Seeds; + //vtkm::cont::UncertainArrayHandle, vtkm::cont::StorageListBasic> arr; + //arr = this->Seeds; + + vtkm::filter::particleadvection::PAV pav(boundsMap, dsi, this->UseThreadedAlgorithm); + return pav.Execute(this->NumberOfSteps, this->StepSize, this->Seeds); + +#if 0 + //std::vector ddsi; + /* + vtkm::filter::particleadvection::RunAlgo( + boundsMap, ddsi, this->NumberOfSteps, this->StepSize, this->Seeds); + */ + + vtkm::cont::PartitionedDataSet output; + return output; + + /* + //using DSIType = vtkm::filter::particleadvection::DataSetIntegrator; + //std::vector dsi; + auto dsi = this->CreateDataSetIntegrators(input, boundsMap); + + if (this->GetUseThreadedAlgorithm()) + return vtkm::filter::particleadvection::RunAlgo( + boundsMap, dsi, this->NumberOfSteps, this->StepSize, this->Seeds); + else + return vtkm::filter::particleadvection::RunAlgo( + boundsMap, dsi, this->NumberOfSteps, this->StepSize, this->Seeds); + */ +#endif +} + +} +} // namespace vtkm::filter +#endif diff --git a/vtkm/filter/PathParticle.hxx b/vtkm/filter/PathParticle.hxx index aa82da0ef..960491b05 100644 --- a/vtkm/filter/PathParticle.hxx +++ b/vtkm/filter/PathParticle.hxx @@ -36,10 +36,13 @@ inline VTKM_CONT vtkm::cont::PartitionedDataSet PathParticleBase:: const vtkm::cont::PartitionedDataSet& input, const vtkm::filter::PolicyBase&) { - using AlgorithmType = vtkm::filter::particleadvection::PathParticleAlgorithm; - using ThreadedAlgorithmType = vtkm::filter::particleadvection::PathParticleThreadedAlgorithm; - using TDSIType = vtkm::filter::particleadvection::TemporalDataSetIntegrator; + // using AlgorithmType = vtkm::filter::particleadvection::PathParticleAlgorithm; + // using ThreadedAlgorithmType = vtkm::filter::particleadvection::PathParticleThreadedAlgorithm; + // using TDSIType = vtkm::filter::particleadvection::TemporalDataSetIntegrator; + return input; + + /* this->ValidateOptions(input); vtkm::filter::particleadvection::BoundsMap boundsMap(input); @@ -51,6 +54,7 @@ inline VTKM_CONT vtkm::cont::PartitionedDataSet PathParticleBase:: else return vtkm::filter::particleadvection::RunAlgo( boundsMap, dsi, this->NumberOfSteps, this->StepSize, this->Seeds); + */ } } diff --git a/vtkm/filter/Pathline.hxx b/vtkm/filter/Pathline.hxx index a25476b7c..ec932a5d3 100644 --- a/vtkm/filter/Pathline.hxx +++ b/vtkm/filter/Pathline.hxx @@ -36,10 +36,12 @@ inline VTKM_CONT vtkm::cont::PartitionedDataSet PathlineBase::Prep const vtkm::cont::PartitionedDataSet& input, const vtkm::filter::PolicyBase&) { + /* using AlgorithmType = vtkm::filter::particleadvection::PathlineAlgorithm; using ThreadedAlgorithmType = vtkm::filter::particleadvection::PathlineThreadedAlgorithm; using TDSIType = vtkm::filter::particleadvection::TemporalDataSetIntegrator; + this->ValidateOptions(input); vtkm::filter::particleadvection::BoundsMap boundsMap(input); @@ -51,6 +53,8 @@ inline VTKM_CONT vtkm::cont::PartitionedDataSet PathlineBase::Prep else return vtkm::filter::particleadvection::RunAlgo( boundsMap, dsi, this->NumberOfSteps, this->StepSize, this->Seeds); + */ + return input; } } diff --git a/vtkm/filter/Streamline.hxx b/vtkm/filter/Streamline.hxx index 86316193a..4c82b541f 100644 --- a/vtkm/filter/Streamline.hxx +++ b/vtkm/filter/Streamline.hxx @@ -35,11 +35,13 @@ inline VTKM_CONT vtkm::cont::PartitionedDataSet StreamlineBase::Pr const vtkm::cont::PartitionedDataSet& input, const vtkm::filter::PolicyBase&) { - using AlgorithmType = vtkm::filter::particleadvection::StreamlineAlgorithm; - using ThreadedAlgorithmType = vtkm::filter::particleadvection::StreamlineThreadedAlgorithm; - using DSIType = vtkm::filter::particleadvection::DataSetIntegrator; + // using AlgorithmType = vtkm::filter::particleadvection::StreamlineAlgorithm; + // using ThreadedAlgorithmType = vtkm::filter::particleadvection::StreamlineThreadedAlgorithm; + // using DSIType = vtkm::filter::particleadvection::DataSetIntegrator; this->ValidateOptions(); + return input; +#if 0 vtkm::filter::particleadvection::BoundsMap boundsMap(input); auto dsi = this->CreateDataSetIntegrators(input, boundsMap); @@ -49,6 +51,7 @@ inline VTKM_CONT vtkm::cont::PartitionedDataSet StreamlineBase::Pr else return vtkm::filter::particleadvection::RunAlgo( boundsMap, dsi, this->NumberOfSteps, this->StepSize, this->Seeds); +#endif } } diff --git a/vtkm/filter/particleadvection/ABA.h b/vtkm/filter/particleadvection/ABA.h new file mode 100644 index 000000000..ad7a38176 --- /dev/null +++ b/vtkm/filter/particleadvection/ABA.h @@ -0,0 +1,381 @@ +//============================================================================ +// 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. +//============================================================================ + +#ifndef vtk_m_filter_ABA_h +#define vtk_m_filter_ABA_h + +#include +#include +#include +#include + + +namespace vtkm +{ +namespace filter +{ +namespace particleadvection +{ + +template