VTK  9.7.1
vtkParticleTracerBase.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
16 #ifndef vtkParticleTracerBase_h
17 #define vtkParticleTracerBase_h
18 
19 #include "vtkFiltersFlowPathsModule.h" // For export macro
20 #include "vtkPolyDataAlgorithm.h"
21 #include "vtkSmartPointer.h" // For vtkSmartPointer
22 #include "vtkTemporalAlgorithm.h" // For vtkTemporalAlgorithm
23 #include "vtkWeakPointer.h" // For vtkWeakPointer
24 
25 #include <list> // STL Header
26 #include <mutex> // STL Header
27 #include <numeric> // STL Header
28 #include <unordered_map> // STL Header
29 #include <vector> // STL Header
30 
31 #ifndef __VTK_WRAP__
32 #define vtkPolyDataAlgorithm vtkTemporalAlgorithm<vtkPolyDataAlgorithm>
33 #endif
34 
35 VTK_ABI_NAMESPACE_BEGIN
38 class vtkDataArray;
39 class vtkDataSet;
40 class vtkDoubleArray;
41 class vtkFloatArray;
42 class vtkGenericCell;
44 class vtkIntArray;
48 class vtkPointData;
49 class vtkPoints;
50 class vtkPolyData;
51 class vtkSignedCharArray;
53 VTK_ABI_NAMESPACE_END
54 
56 {
57 VTK_ABI_NAMESPACE_BEGIN
58 struct Position_t
59 {
60  double x[4];
61 };
62 using Position = struct Position_t;
63 
65 {
66  // These are used during iteration
71  // These are computed scalars we might display
72  int SourceID;
73  int TimeStepAge; // amount of time steps the particle has advanced
75  int InjectedStepId; // time step the particle was injected
77  // These are useful to track for debugging etc
78  int ErrorCode;
79  float age;
80  // these are needed across time steps to compute vorticity
81  float rotation;
82  float angularVel;
83  float time;
84  float speed;
85  // once the particle is added, PointId is valid and is the tuple location
86  // in ProtoPD.
88 
89  double velocity[3];
90 };
92 
93 typedef std::vector<ParticleInformation> ParticleVector;
94 typedef ParticleVector::iterator ParticleIterator;
95 typedef std::list<ParticleInformation> ParticleDataList;
96 typedef ParticleDataList::iterator ParticleListIterator;
97 struct ParticleTracerFunctor;
98 VTK_ABI_NAMESPACE_END
99 }
100 
101 VTK_ABI_NAMESPACE_BEGIN
102 class VTKFILTERSFLOWPATHS_EXPORT vtkParticleTracerBase : public vtkPolyDataAlgorithm
103 {
104 public:
105  friend struct vtkParticleTracerBaseNamespace::ParticleTracerFunctor;
106  enum Solvers
107  {
113  };
114 
116  void PrintParticleHistories();
117 
118 #ifndef __VTK_WRAP__
119 #undef vtkPolyDataAlgorithm
120 #endif
121  void PrintSelf(ostream& os, vtkIndent indent) override;
124 
125 #if defined(__VTK_WRAP__) || defined(__WRAP_GCCXML)
127 #endif
128 
130 
134  virtual void SetController(vtkMultiProcessController*);
135  virtual vtkMultiProcessController* GetController();
137 
139 
144  vtkGetMacro(ComputeVorticity, bool);
145  void SetComputeVorticity(bool);
147 
149 
152  vtkGetMacro(TerminalSpeed, double);
153  void SetTerminalSpeed(double);
155 
157 
161  vtkGetMacro(RotationScale, double);
162  void SetRotationScale(double);
164 
166 
170  vtkSetMacro(IgnorePipelineTime, vtkTypeBool);
171  vtkGetMacro(IgnorePipelineTime, vtkTypeBool);
172  vtkBooleanMacro(IgnorePipelineTime, vtkTypeBool);
174 
176 
185  vtkGetMacro(ForceReinjectionEveryNSteps, int);
186  void SetForceReinjectionEveryNSteps(int);
188 
189  void SetIntegrator(vtkInitialValueProblemSolver*);
190  vtkGetObjectMacro(Integrator, vtkInitialValueProblemSolver);
191 
192  void SetIntegratorType(int type);
193  int GetIntegratorType();
194 
196 
205  vtkSetMacro(StaticSeeds, vtkTypeBool);
206  vtkGetMacro(StaticSeeds, vtkTypeBool);
208 
213  {
214  DIFFERENT = 0,
215  STATIC = 1,
216  LINEAR_TRANSFORMATION = 2,
217  SAME_TOPOLOGY = 3
218  };
219 
221  /*
222  * Set/Get the type of variance of the mesh over time.
223  *
224  * DIFFERENT = 0,
225  * STATIC = 1,
226  * LINEAR_TRANSFORMATION = 2
227  * SAME_TOPOLOGY = 3
228  */
229  virtual void SetMeshOverTime(int meshOverTime);
230  virtual int GetMeshOverTimeMinValue() { return DIFFERENT; }
231  virtual int GetMeshOverTimeMaxValue() { return SAME_TOPOLOGY; }
232  void SetMeshOverTimeToDifferent() { this->SetMeshOverTime(DIFFERENT); }
233  void SetMeshOverTimeToStatic() { this->SetMeshOverTime(STATIC); }
234  void SetMeshOverTimeToLinearTransformation() { this->SetMeshOverTime(LINEAR_TRANSFORMATION); }
235  void SetMeshOverTimeToSameTopology() { this->SetMeshOverTime(SAME_TOPOLOGY); }
236  vtkGetMacro(MeshOverTime, int);
238 
239  enum
240  {
241  INTERPOLATOR_WITH_DATASET_POINT_LOCATOR VTK_DEPRECATED_IN_9_7_0(
242  "Use SetCellLocatorToJumpAndWalkCellLocator() instead"),
243  INTERPOLATOR_WITH_CELL_LOCATOR VTK_DEPRECATED_IN_9_7_0(
244  "Use SetCellLocatorToStaticCellLocator() instead")
245  };
246 
258  VTK_DEPRECATED_IN_9_7_0("Use SetCellLocator(vtkAbstractCellLocator*) instead")
259  void SetInterpolatorType(int interpolatorType);
260 
262 
267  virtual void SetCellLocator(vtkAbstractCellLocator*);
268  virtual void SetCellLocatorToStaticCellLocator();
269  virtual void SetCellLocatorToJumpAndWalkCellLocator();
271 
279  VTK_DEPRECATED_IN_9_7_0("Use SetCellLocatorToJumpAndWalkCellLocator() instead")
280  void SetInterpolatorTypeToDataSetPointLocator();
281 
288  VTK_DEPRECATED_IN_9_7_0("Use SetCellLocatorToStaticCellLocator() instead")
289  void SetInterpolatorTypeToCellLocator();
290 
292 
298  virtual void SetParticleWriter(vtkAbstractParticleWriter* pw);
299  vtkGetObjectMacro(ParticleWriter, vtkAbstractParticleWriter);
301 
303 
307  vtkSetFilePathMacro(ParticleFileName);
308  vtkGetFilePathMacro(ParticleFileName);
310 
312 
316  vtkSetMacro(EnableParticleWriting, vtkTypeBool);
317  vtkGetMacro(EnableParticleWriting, vtkTypeBool);
318  vtkBooleanMacro(EnableParticleWriting, vtkTypeBool);
320 
322 
325  void AddSourceConnection(vtkAlgorithmOutput* input);
326  void RemoveAllSources();
328 
330 
334  vtkGetMacro(ForceSerialExecution, bool);
335  vtkSetMacro(ForceSerialExecution, bool);
336  vtkBooleanMacro(ForceSerialExecution, bool);
338 protected:
340 
344  vtkSmartPointer<vtkPointData> ProtoPD;
346  vtkTypeBool IgnorePipelineTime; // whether to use the pipeline time for termination
348 
349  // Control execution as serial or threaded
350  bool ForceSerialExecution;
351 
352  void EnqueueParticleToAnotherProcess(vtkParticleTracerBaseNamespace::ParticleInformation&);
353 
355  ~vtkParticleTracerBase() override;
356 
357  //
358  // Make sure the pipeline knows what type we expect as input
359  //
360  int FillInputPortInformation(int port, vtkInformation* info) override;
361 
365  int Initialize(vtkInformation* request, vtkInformationVector** inputVector,
366  vtkInformationVector* outputVector) override;
367 
375  int Execute(vtkInformation* request, vtkInformationVector** inputVector,
376  vtkInformationVector* outputVector) override;
377 
381  int Finalize(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
382 
387  virtual std::vector<vtkDataSet*> GetSeedSources(vtkInformationVector* inputVector);
388 
389  // Initialization of input (vector-field) geometry
390  int InitializeInterpolator();
391 
397 
402  void TestParticles(vtkParticleTracerBaseNamespace::ParticleVector& candidates,
404 
405  void TestParticles(
406  vtkParticleTracerBaseNamespace::ParticleVector& candidates, std::vector<int>& passed);
407 
414  virtual void AssignSeedsToProcessors(double time, vtkDataSet* source,
416 
422  bool SendReceiveParticles(std::vector<vtkIdType>&);
423 
428  void UpdateParticleList(vtkParticleTracerBaseNamespace::ParticleVector& candidates);
429 
435  virtual bool UpdateParticleListFromOtherProcesses();
436 
440  void IntegrateParticle(vtkParticleTracerBaseNamespace::ParticleListIterator& it,
441  double currentTime, double targetTime, vtkInitialValueProblemSolver* integrator,
442  vtkTemporalInterpolatedVelocityField* interpolator, vtkDoubleArray* cellVectors,
443  std::atomic<vtkIdType>& particleCount, std::mutex& eraseMutex, bool sequential);
444 
451  bool ComputeDomainExitLocation(
452  double pos[4], double p2[4], double intersection[4], vtkGenericCell* cell);
453 
454  //
455  // Scalar arrays that are generated as each particle is updated
456  //
457  void CreateProtoPD(vtkDataObject* input);
458 
459  vtkFloatArray* GetParticleAge(vtkPointData*);
460  vtkIntArray* GetParticleIds(vtkPointData*);
461  vtkSignedCharArray* GetParticleSourceIds(vtkPointData*);
462  vtkIntArray* GetInjectedPointIds(vtkPointData*);
463  vtkIntArray* GetInjectedStepIds(vtkPointData*);
464  vtkIntArray* GetErrorCodeArr(vtkPointData*);
465  vtkFloatArray* GetParticleVorticity(vtkPointData*);
466  vtkFloatArray* GetParticleRotation(vtkPointData*);
467  vtkFloatArray* GetParticleAngularVel(vtkPointData*);
468 
469  // utility function we use to test if a point is inside any of our local datasets
470  bool InsideBounds(double point[]);
471 
472  void CalculateVorticity(
473  vtkGenericCell* cell, double pcoords[3], vtkDoubleArray* cellVectors, double vorticity[3]);
474 
475  //------------------------------------------------------
476 
477  void SetParticle(vtkParticleTracerBaseNamespace::ParticleInformation& info,
478  vtkTemporalInterpolatedVelocityField* interpolator, vtkDoubleArray* cellVectors);
479 
480  std::unordered_map<vtkIdType, int> InjectedPointIdToProcessId;
481 
483 
488  virtual bool IsPointDataValid(vtkDataObject* input);
489  bool IsPointDataValid(vtkCompositeDataSet* input, std::vector<std::string>& arrayNames);
490  void GetPointDataArrayNames(vtkDataSet* input, std::vector<std::string>& names);
492 
493  vtkGetMacro(ReinjectionCounter, int);
494 
495  void ResizeArrays(vtkIdType numTuples);
496 
501  virtual void InitializeExtraPointDataArrays(vtkPointData* vtkNotUsed(outputPD)) {}
502 
505  {
506  }
507 
508  vtkTemporalInterpolatedVelocityField* GetInterpolator();
509 
514  virtual void AddRestartSeeds(vtkInformationVector** /*inputVector*/) {}
515 
525  bool RetryWithPush(vtkParticleTracerBaseNamespace::ParticleInformation& info, double* point1,
526  double delT, int subSteps, vtkTemporalInterpolatedVelocityField* interpolator);
527 
528  bool SetTerminationTimeNoModify(double t);
529 
531 
532  // Parameters of tracing
535  double MaximumError;
539 
540  // A counter to keep track of how many times we reinjected
542 
543  // Important for Caching of Cells/Ids/Weights etc
547 
548  // Innjection parameters
551  bool HasCache;
552 
553  // Particle writing to disk
557 
559 
560  // The velocity interpolator
562 
563  // MPI controller needed when running in parallel
565 
571 
579  std::unordered_map<vtkIdType, vtkParticleTracerBaseNamespace::ParticleInformation> MPIRecvList;
580 
581  // Cache bounds info for each dataset we will use repeatedly
582  struct bounds_t
583  {
584  double b[6];
585  };
586  using bounds = struct bounds_t;
587  std::vector<bounds> CachedBounds[2];
588 
589  // variables used by Execute() to produce output
590 
591  vtkSmartPointer<vtkDataSet> DataReferenceT[2];
592 
595 
606 
607  // temp array
609 
611  void operator=(const vtkParticleTracerBase&) = delete;
613 
614  unsigned int NumberOfParticles();
615 
616  friend class ParticlePathFilterInternal;
617  friend class StreaklineFilterInternal;
618 
619  static const double Epsilon;
620 
621 private:
622  // Internal method to initialize CachedData[1] using the provided input
623  void InitializeNextCachedData(vtkDataObject* input);
624 
625  // Data for time step CurrentTimeStep-1 and CurrentTimeStep
627 };
628 
629 VTK_ABI_NAMESPACE_END
630 #endif
virtual int GetMeshOverTimeMinValue()
composite dataset to encapsulates a dataset consisting of partitions.
A helper class for interpolating between times during particle tracing.
abstract class to write particle data to file
MeshOverTimeTypes
Types of Variance of Mesh over time.
vtkInitialValueProblemSolver * Integrator
#define vtkCreateWrappedTemporalAlgorithmInterface()
represent and manipulate point attribute data
Definition: vtkPointData.h:30
vtkNew< vtkPointData > OutputPointData
Store vtkAlgorithm input/output information.
abstract class to specify dataset behavior
Definition: vtkDataSet.h:56
std::unordered_map< vtkIdType, vtkParticleTracerBaseNamespace::ParticleInformation > MPIRecvList
Storage of the particles we received.
record modification and/or execution time
Definition: vtkTimeStamp.h:24
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:31
an abstract base class for locators which find cells
vtkNew< vtkSignedCharArray > ParticleSourceIds
Hold a reference to a vtkObjectBase instance.
Definition: vtkMeta.h:23
int vtkIdType
Definition: vtkType.h:363
vtkNew< vtkDoubleArray > CellVectors
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:71
vtkSmartPointer< vtkTemporalInterpolatedVelocityField > Interpolator
ParticleVector::iterator ParticleIterator
provides thread-safe access to cells
vtkNew< vtkPoints > OutputCoordinates
virtual int GetMeshOverTimeMaxValue()
Proxy object to connect input/output ports.
dynamic, self-adjusting array of double
virtual void AddRestartSeeds(vtkInformationVector **)
For restarts of particle paths, we add in the ability to add in particles from a previous computation...
static const double Epsilon
int vtkTypeBool
Definition: vtkABI.h:64
dynamic, self-adjusting array of int
Definition: vtkIntArray.h:35
abstract superclass for composite (multi-block or AMR) datasets
Superclass for algorithms that produce only polydata as output.
vtkParticleTracerBaseNamespace::ParticleVector MPISendList
Storage of the particles we want to send to another rank.
a simple class to control print indentation
Definition: vtkIndent.h:28
vtkNew< vtkIdTypeArray > ParticleCellsConnectivity
vtkNew< vtkFloatArray > ParticleVorticity
vtkNew< vtkIntArray > ErrorCodeArray
vtkNew< vtkFloatArray > ParticleRotation
struct ParticleInformation_t ParticleInformation
vtkNew< vtkFloatArray > ParticleAge
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
vtkAbstractParticleWriter * ParticleWriter
vtkNew< vtkIntArray > InjectedStepIds
vtkNew< vtkFloatArray > ParticleAngularVel
dynamic, self-adjusting array of signed char
vtkParticleTracerBaseNamespace::ParticleVector LocalSeeds
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
vtkSmartPointer< vtkMultiProcessController > Controller
std::list< ParticleInformation > ParticleDataList
vtkNew< vtkIdTypeArray > InjectedPointIds
virtual void SetToExtraPointDataArrays(vtkIdType, vtkParticleTracerBaseNamespace::ParticleInformation &)
Composite dataset that organizes datasets into blocks.
std::vector< ParticleInformation > ParticleVector
Store zero or more vtkInformation instances.
vtkNew< vtkIntArray > ParticleIds
ParticleDataList::iterator ParticleListIterator
general representation of visualization data
Definition: vtkDataObject.h:55
#define VTK_DEPRECATED_IN_9_7_0(reason)
represent and manipulate 3D points
Definition: vtkPoints.h:30
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
Integrate a set of ordinary differential equations (initial value problem) in time.
A particle tracer for vector fields.
Multiprocessing communication superclass.