11 #ifndef vtk_m_filter_flow_internal_DataSetIntegrator_h
12 #define vtk_m_filter_flow_internal_DataSetIntegrator_h
19 #include <vtkm/filter/flow/worklet/EulerIntegrator.h>
20 #include <vtkm/filter/flow/worklet/IntegratorStatus.h>
21 #include <vtkm/filter/flow/worklet/ParticleAdvection.h>
22 #include <vtkm/filter/flow/worklet/RK4Integrator.h>
23 #include <vtkm/filter/flow/worklet/Stepper.h>
36 template <
typename ParticleType>
40 DSIHelperInfo(
const std::vector<ParticleType>& v,
41 const vtkm::filter::flow::internal::BoundsMap& boundsMap,
42 const std::unordered_map<
vtkm::Id, std::vector<vtkm::Id>>& particleBlockIDsMap)
43 : BoundsMap(boundsMap)
44 , ParticleBlockIDsMap(particleBlockIDsMap)
49 struct ParticleBlockIds
53 this->Particles.clear();
54 this->BlockIDs.clear();
57 void Add(
const ParticleType& p,
const std::vector<vtkm::Id>& bids)
59 this->Particles.emplace_back(p);
60 this->BlockIDs[p.GetID()] = std::move(bids);
63 std::vector<ParticleType> Particles;
64 std::unordered_map<vtkm::Id, std::vector<vtkm::Id>> BlockIDs;
69 this->InBounds.Clear();
70 this->OutOfBounds.Clear();
71 this->TermIdx.clear();
78 if ((
static_cast<std::size_t
>(num) !=
79 (this->InBounds.Particles.size() + this->OutOfBounds.Particles.size() +
80 this->TermIdx.size())) ||
81 (this->InBounds.Particles.size() != this->InBounds.BlockIDs.size()) ||
82 (this->OutOfBounds.Particles.size() != this->OutOfBounds.BlockIDs.size()) ||
83 (this->TermIdx.size() != this->TermID.size()))
91 this->TermIdx.emplace_back(idx);
92 this->TermID.emplace_back(pID);
95 vtkm::filter::flow::internal::BoundsMap BoundsMap;
96 std::unordered_map<vtkm::Id, std::vector<vtkm::Id>> ParticleBlockIDsMap;
98 ParticleBlockIds InBounds;
99 ParticleBlockIds OutOfBounds;
100 std::vector<ParticleType> Particles;
101 std::vector<vtkm::Id> TermID;
102 std::vector<vtkm::Id> TermIdx;
105 template <
typename Derived,
typename ParticleType>
106 class DataSetIntegrator
111 , SolverType(solverType)
112 , Rank(this->Comm.rank())
118 VTKM_CONT void SetCopySeedFlag(
bool val) { this->CopySeedArray = val; }
121 void Advect(DSIHelperInfo<ParticleType>& b,
124 Derived* inst =
static_cast<Derived*
>(
this);
125 inst->DoAdvect(b, stepSize);
130 Derived* inst =
static_cast<Derived*
>(
this);
131 return inst->GetOutput(dataset);
136 DSIHelperInfo<ParticleType>& dsiInfo)
const;
143 bool CopySeedArray =
false;
146 template <
typename Derived,
typename ParticleType>
147 VTKM_CONT inline void DataSetIntegrator<Derived, ParticleType>::ClassifyParticles(
149 DSIHelperInfo<ParticleType>& dsiInfo)
const
160 vtkm::Id n = portal.GetNumberOfValues();
164 auto p = portal.Get(i);
167 if (p.GetStatus().CheckTerminate())
169 dsiInfo.AddTerminated(i, p.GetID());
175 const auto& it = dsiInfo.ParticleBlockIDsMap.find(p.GetID());
176 VTKM_ASSERT(it != dsiInfo.ParticleBlockIDsMap.end());
177 auto currBIDs = it->second;
180 std::vector<vtkm::Id> newIDs;
181 if (p.GetStatus().CheckSpatialBounds() && !p.GetStatus().CheckTookAnySteps())
186 newIDs.assign(std::next(currBIDs.begin(), 1), currBIDs.end());
191 newIDs = dsiInfo.BoundsMap.FindBlocks(p.GetPosition(), currBIDs);
199 p.GetStatus().SetTerminate();
200 dsiInfo.AddTerminated(i, p.GetID());
206 if (newIDs.size() > 1)
208 for (
auto idit = newIDs.begin(); idit != newIDs.end(); idit++)
211 auto ranks = dsiInfo.BoundsMap.FindRank(bid);
212 if (std::find(ranks.begin(), ranks.end(), this->Rank) != ranks.end())
215 newIDs.insert(newIDs.begin(), bid);
221 dsiInfo.OutOfBounds.Add(p, newIDs);
236 #endif //vtk_m_filter_flow_internal_DataSetIntegrator_h