19 #ifndef viskores_filter_flow_internal_DataSetIntegrator_h
20 #define viskores_filter_flow_internal_DataSetIntegrator_h
27 #include <viskores/filter/flow/worklet/EulerIntegrator.h>
28 #include <viskores/filter/flow/worklet/IntegratorStatus.h>
29 #include <viskores/filter/flow/worklet/ParticleAdvection.h>
30 #include <viskores/filter/flow/worklet/RK4Integrator.h>
31 #include <viskores/filter/flow/worklet/Stepper.h>
44 template <
typename ParticleType>
49 const std::vector<ParticleType>& v,
50 const viskores::filter::flow::internal::BoundsMap& boundsMap,
51 const std::unordered_map<
viskores::Id, std::vector<viskores::Id>>& particleBlockIDsMap)
52 : BoundsMap(boundsMap)
53 , ParticleBlockIDsMap(particleBlockIDsMap)
58 struct ParticleBlockIds
62 this->Particles.clear();
63 this->BlockIDs.clear();
66 void Add(
const ParticleType& p,
const std::vector<viskores::Id>& bids)
68 this->Particles.emplace_back(p);
69 this->BlockIDs[p.GetID()] = std::move(bids);
72 std::vector<ParticleType> Particles;
73 std::unordered_map<viskores::Id, std::vector<viskores::Id>> BlockIDs;
78 this->InBounds.Clear();
79 this->OutOfBounds.Clear();
80 this->TermIdx.clear();
87 if ((
static_cast<std::size_t
>(num) !=
88 (this->InBounds.Particles.size() + this->OutOfBounds.Particles.size() +
89 this->TermIdx.size())) ||
90 (this->InBounds.Particles.size() != this->InBounds.BlockIDs.size()) ||
91 (this->OutOfBounds.Particles.size() != this->OutOfBounds.BlockIDs.size()) ||
92 (this->TermIdx.size() != this->TermID.size()))
100 this->TermIdx.emplace_back(idx);
101 this->TermID.emplace_back(pID);
104 viskores::filter::flow::internal::BoundsMap BoundsMap;
105 std::unordered_map<viskores::Id, std::vector<viskores::Id>> ParticleBlockIDsMap;
107 ParticleBlockIds InBounds;
108 ParticleBlockIds OutOfBounds;
109 std::vector<ParticleType> Particles;
110 std::vector<viskores::Id> TermID;
111 std::vector<viskores::Id> TermIdx;
114 template <
typename Derived,
typename ParticleType>
115 class DataSetIntegrator
120 , SolverType(solverType)
121 , Rank(this->Comm.rank())
127 VISKORES_CONT void SetCopySeedFlag(
bool val) { this->CopySeedArray = val; }
130 void Advect(DSIHelperInfo<ParticleType>& b,
133 Derived* inst =
static_cast<Derived*
>(
this);
134 inst->DoAdvect(b, stepSize);
139 Derived* inst =
static_cast<Derived*
>(
this);
140 return inst->GetOutput(dataset);
146 DSIHelperInfo<ParticleType>& dsiInfo)
const;
153 bool CopySeedArray =
false;
156 template <
typename Derived,
typename ParticleType>
157 VISKORES_CONT inline void DataSetIntegrator<Derived, ParticleType>::ClassifyParticles(
159 DSIHelperInfo<ParticleType>& dsiInfo)
const
174 auto p = portal.Get(i);
177 if (p.GetStatus().CheckTerminate())
179 dsiInfo.AddTerminated(i, p.GetID());
185 const auto& it = dsiInfo.ParticleBlockIDsMap.find(p.GetID());
187 auto currBIDs = it->second;
190 std::vector<viskores::Id> newIDs;
191 if (p.GetStatus().CheckSpatialBounds() && !p.GetStatus().CheckTookAnySteps())
196 newIDs.assign(std::next(currBIDs.begin(), 1), currBIDs.end());
201 newIDs = dsiInfo.BoundsMap.FindBlocks(p.GetPosition(), currBIDs);
209 p.GetStatus().SetTerminate();
210 dsiInfo.AddTerminated(i, p.GetID());
216 if (newIDs.size() > 1)
218 for (
auto idit = newIDs.begin(); idit != newIDs.end(); idit++)
221 auto ranks = dsiInfo.BoundsMap.FindRank(bid);
222 if (std::find(ranks.begin(), ranks.end(), this->Rank) != ranks.end())
225 newIDs.insert(newIDs.begin(), bid);
231 dsiInfo.OutOfBounds.Add(p, newIDs);
246 #endif //viskores_filter_flow_internal_DataSetIntegrator_h