vtkLegacyParticleTracerBase.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 vtkLegacyParticleTracerBase_h
17 #define vtkLegacyParticleTracerBase_h
18 
19 #include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_2_0
20 #include "vtkPVVTKExtensionsFiltersGeneralMPIModule.h" // For export macro
21 #include "vtkParaViewDeprecation.h" // For PARAVIEW_DEPRECATED_IN_6_3_0
22 #include "vtkPolyDataAlgorithm.h"
23 #include "vtkSmartPointer.h" // For vtkSmartPointer
24 
25 #include <list> // STL Header
26 #include <mutex> // STL Header
27 #include <vector> // STL Header
28 
30 class vtkCellArray;
32 class vtkDataArray;
33 class vtkDataSet;
34 class vtkDoubleArray;
35 class vtkFloatArray;
36 class vtkGenericCell;
38 class vtkIntArray;
41 class vtkPointData;
42 class vtkPoints;
43 class vtkPolyData;
44 class vtkSignedCharArray;
46 
48 {
49 struct Position_t
50 {
51  double x[4];
52 };
53 using Position = struct Position_t;
54 
56 {
57  // These are used during iteration
59  int CachedDataSetId[2];
60  vtkIdType CachedCellId[2];
62  // These are computed scalars we might display
63  int SourceID;
64  int TimeStepAge; // amount of time steps the particle has advanced
66  int InjectedStepId; // time step the particle was injected
69  // These are useful to track for debugging etc
70  int ErrorCode;
71  float age;
72  // these are needed across time steps to compute vorticity
73  float rotation;
74  float angularVel;
75  float time;
76  float speed;
77  // once the particle is added, PointId is valid and is the tuple location
78  // in ProtoPD.
80  // if PointId is negative then in parallel this particle was just
81  // received and we need to get the tuple value from vtkPParticleTracerBase::Tail.
83 };
85 
86 typedef std::vector<ParticleInformation> ParticleVector;
87 typedef ParticleVector::iterator ParticleIterator;
88 typedef std::list<ParticleInformation> ParticleDataList;
89 typedef ParticleDataList::iterator ParticleListIterator;
90 struct ParticleTracerFunctor;
91 }
92 
93 class PARAVIEW_DEPRECATED_IN_6_3_0("Use vtkPParticlePathFilter instead.")
94  VTKPVVTKEXTENSIONSFILTERSGENERALMPI_EXPORT vtkLegacyParticleTracerBase
95  : public vtkPolyDataAlgorithm
96 {
97 public:
98  friend struct vtkLegacyParticleTracerBaseNamespace::ParticleTracerFunctor;
99  enum Solvers
100  {
105  UNKNOWN
106  };
107 
109  void PrintSelf(ostream& os, vtkIndent indent) override;
110  void PrintParticleHistories();
111 
113 
118  vtkGetMacro(ComputeVorticity, bool);
119  void SetComputeVorticity(bool);
121 
123 
126  vtkGetMacro(TerminalSpeed, double);
127  void SetTerminalSpeed(double);
129 
131 
135  vtkGetMacro(RotationScale, double);
136  void SetRotationScale(double);
138 
140 
144  vtkSetMacro(IgnorePipelineTime, vtkTypeBool);
145  vtkGetMacro(IgnorePipelineTime, vtkTypeBool);
146  vtkBooleanMacro(IgnorePipelineTime, vtkTypeBool);
148 
150 
159  vtkGetMacro(ForceReinjectionEveryNSteps, int);
160  void SetForceReinjectionEveryNSteps(int);
162 
164 
170  void SetTerminationTime(double t);
171  vtkGetMacro(TerminationTime, double);
173 
174  void SetIntegrator(vtkInitialValueProblemSolver*);
175  vtkGetObjectMacro(Integrator, vtkInitialValueProblemSolver);
176 
177  void SetIntegratorType(int type);
178  int GetIntegratorType();
179 
181 
185  vtkGetMacro(StartTime, double);
186  void SetStartTime(double t);
188 
190 
199  vtkSetMacro(StaticSeeds, vtkTypeBool);
200  vtkGetMacro(StaticSeeds, vtkTypeBool);
202 
207  {
208  DIFFERENT = 0,
209  STATIC = 1,
210  LINEAR_TRANSFORMATION = 2,
211  SAME_TOPOLOGY = 3
212  };
213 
215  /*
216  * Set/Get the type of variance of the mesh over time.
217  *
218  * DIFFERENT = 0,
219  * STATIC = 1,
220  * LINEAR_TRANSFORMATION = 2
221  * SAME_TOPOLOGY = 3
222  */
223  virtual void SetMeshOverTime(int meshOverTime);
224  virtual int GetMeshOverTimeMinValue() { return DIFFERENT; }
225  virtual int GetMeshOverTimeMaxValue() { return SAME_TOPOLOGY; }
226  void SetMeshOverTimeToDifferent() { this->SetMeshOverTime(DIFFERENT); }
227  void SetMeshOverTimeToStatic() { this->SetMeshOverTime(STATIC); }
228  void SetMeshOverTimeToLinearTransformation() { this->SetMeshOverTime(LINEAR_TRANSFORMATION); }
229  void SetMeshOverTimeToSameTopology() { this->SetMeshOverTime(SAME_TOPOLOGY); }
230  vtkGetMacro(MeshOverTime, int);
232 
234 
243  VTK_DEPRECATED_IN_9_2_0("Use SetMeshOverTime instead")
244  virtual void SetStaticMesh(vtkTypeBool staticMesh)
245  {
246  this->SetMeshOverTime(staticMesh ? STATIC : DIFFERENT);
247  }
248  VTK_DEPRECATED_IN_9_2_0("Use GetMeshOverTime instead")
249  virtual vtkTypeBool GetStaticMesh() { return this->MeshOverTime == STATIC; }
251 
252  enum
253  {
255  INTERPOLATOR_WITH_CELL_LOCATOR
256  };
257 
269  void SetInterpolatorType(int interpolatorType);
270 
278  void SetInterpolatorTypeToDataSetPointLocator();
279 
286  void SetInterpolatorTypeToCellLocator();
287 
289 
295  virtual void SetParticleWriter(vtkAbstractParticleWriter* pw);
296  vtkGetObjectMacro(ParticleWriter, vtkAbstractParticleWriter);
298 
300 
304  vtkSetFilePathMacro(ParticleFileName);
305  vtkGetFilePathMacro(ParticleFileName);
307 
309 
313  vtkSetMacro(EnableParticleWriting, vtkTypeBool);
314  vtkGetMacro(EnableParticleWriting, vtkTypeBool);
315  vtkBooleanMacro(EnableParticleWriting, vtkTypeBool);
317 
319 
324  vtkSetMacro(DisableResetCache, vtkTypeBool);
325  vtkGetMacro(DisableResetCache, vtkTypeBool);
326  vtkBooleanMacro(DisableResetCache, vtkTypeBool);
328 
330 
333  void AddSourceConnection(vtkAlgorithmOutput* input);
334  void RemoveAllSources();
336 
338 
342  vtkGetMacro(ForceSerialExecution, bool);
343  vtkSetMacro(ForceSerialExecution, bool);
344  vtkBooleanMacro(ForceSerialExecution, bool);
346 protected:
347  vtkSmartPointer<vtkPolyData> Output; // managed by child classes
349 
354  vtkIdType UniqueIdCounter; // global Id counter used to give particles a stamp
356  vtkSmartPointer<vtkPointData> ParticlePointData; // the current particle point data consistent
357  // with particle history
358  // Everything related to time
359  vtkTypeBool IgnorePipelineTime; // whether to use the pipeline time for termination
360  vtkTypeBool DisableResetCache; // whether to enable ResetCache() method
362 
363  // Control execution as serial or threaded
365 
367  ~vtkLegacyParticleTracerBase() override;
368 
369  //
370  // Make sure the pipeline knows what type we expect as input
371  //
372  int FillInputPortInformation(int port, vtkInformation* info) override;
373 
374  //
375  // The usual suspects
376  //
377  vtkTypeBool ProcessRequest(vtkInformation* request, vtkInformationVector** inputVector,
378  vtkInformationVector* outputVector) override;
379 
380  //
381  // Store any information we need in the output and fetch what we can
382  // from the input
383  //
384  int RequestInformation(vtkInformation* request, vtkInformationVector** inputVector,
385  vtkInformationVector* outputVector) override;
386 
387  //
388  // Compute input time steps given the output step
389  //
390  int RequestUpdateExtent(vtkInformation* request, vtkInformationVector** inputVector,
391  vtkInformationVector* outputVector) override;
392 
393  //
394  // what the pipeline calls for each time step
395  //
396  int RequestData(vtkInformation* request, vtkInformationVector** inputVector,
397  vtkInformationVector* outputVector) override;
398 
399  //
400  // these routines are internally called to actually generate the output
401  //
402  virtual int ProcessInput(vtkInformationVector** inputVector);
403 
404  // This is the main part of the algorithm:
405  // * move all the particles one step
406  // * Reinject particles (by adding them to this->ParticleHistories)
407  // either at the beginning or at the end of each step (modulo
408  // this->ForceReinjectionEveryNSteps)
409  // * Output a polydata representing the moved particles
410  // Note that if the starting and the ending time coincide, the polydata is still valid.
411  virtual vtkPolyData* Execute(vtkInformationVector** inputVector);
412 
413  // the RequestData will call these methods in turn
414  virtual void Initialize() {} // the first iteration
415  virtual int OutputParticles(vtkPolyData* poly) = 0; // every iteration
416  virtual void Finalize() {} // the last iteration
417 
422  virtual std::vector<vtkDataSet*> GetSeedSources(vtkInformationVector* inputVector, int timeStep);
423 
424  // Initialization of input (vector-field) geometry
425  int InitializeInterpolator();
426  int UpdateDataCache(vtkDataObject* td);
427 
432  void TestParticles(vtkLegacyParticleTracerBaseNamespace::ParticleVector& candidates,
434 
435  void TestParticles(
436  vtkLegacyParticleTracerBaseNamespace::ParticleVector& candidates, std::vector<int>& passed);
437 
444  virtual void AssignSeedsToProcessors(double time, vtkDataSet* source, int sourceID, int ptId,
445  vtkLegacyParticleTracerBaseNamespace::ParticleVector& localSeedPoints, int& localAssignedCount);
446 
451  virtual void AssignUniqueIds(
453 
458  void UpdateParticleList(vtkLegacyParticleTracerBaseNamespace::ParticleVector& candidates);
459 
465  virtual bool UpdateParticleListFromOtherProcesses() { return false; }
466 
471  double currentTime, double targetTime, vtkInitialValueProblemSolver* integrator,
472  vtkTemporalInterpolatedVelocityField* interpolator, vtkDoubleArray* cellVectors,
473  std::atomic<vtkIdType>& particleCount, std::mutex& eraseMutex, bool sequential);
474 
475  // if the particle is added to send list, then returns value is 1,
476  // if it is kept on this process after a retry return value is 0
480  {
481  return true;
482  }
483 
490  bool ComputeDomainExitLocation(
491  double pos[4], double p2[4], double intersection[4], vtkGenericCell* cell);
492 
493  //
494  // Scalar arrays that are generated as each particle is updated
495  //
496  void CreateProtoPD(vtkDataObject* input);
497 
498  vtkFloatArray* GetParticleAge(vtkPointData*);
499  vtkIntArray* GetParticleIds(vtkPointData*);
500  vtkSignedCharArray* GetParticleSourceIds(vtkPointData*);
501  vtkIntArray* GetInjectedPointIds(vtkPointData*);
502  vtkIntArray* GetInjectedStepIds(vtkPointData*);
503  vtkIntArray* GetErrorCodeArr(vtkPointData*);
504  vtkFloatArray* GetParticleVorticity(vtkPointData*);
505  vtkFloatArray* GetParticleRotation(vtkPointData*);
506  vtkFloatArray* GetParticleAngularVel(vtkPointData*);
507 
508  // utility function we use to test if a point is inside any of our local datasets
509  bool InsideBounds(double point[]);
510 
511  void CalculateVorticity(
512  vtkGenericCell* cell, double pcoords[3], vtkDoubleArray* cellVectors, double vorticity[3]);
513 
514  //------------------------------------------------------
515 
516  double GetCacheDataTime(int i);
517  double GetCacheDataTime();
518 
519  virtual void ResetCache();
521  double* velocity, vtkTemporalInterpolatedVelocityField* interpolator, vtkIdType particleId,
522  vtkDoubleArray* cellVectors);
523 
525 
530  virtual bool IsPointDataValid(vtkDataObject* input);
531  bool IsPointDataValid(vtkCompositeDataSet* input, std::vector<std::string>& arrayNames);
532  void GetPointDataArrayNames(vtkDataSet* input, std::vector<std::string>& names);
534 
535  vtkGetMacro(ReinjectionCounter, int);
536  vtkGetMacro(CurrentTimeValue, double);
537 
538  void ResizeArrays(vtkIdType numTuples);
539 
544  virtual void InitializeExtraPointDataArrays(vtkPointData* vtkNotUsed(outputPD)) {}
545 
548  {
549  }
550 
551  vtkTemporalInterpolatedVelocityField* GetInterpolator();
552 
557  virtual void AddRestartSeeds(vtkInformationVector** /*inputVector*/) {}
558 
563  virtual void RenameGhostArray(vtkPointData* pd);
564 
565 private:
576  double* point1, double delT, int subSteps, vtkTemporalInterpolatedVelocityField* interpolator);
577 
578  bool SetTerminationTimeNoModify(double t);
579 
580  // Parameters of tracing
581  vtkInitialValueProblemSolver* Integrator;
582  double IntegrationStep;
583  double MaximumError;
584  bool ComputeVorticity;
585  double RotationScale;
586  double TerminalSpeed;
587 
588  // A counter to keep track of how many times we reinjected
589  int ReinjectionCounter;
590 
591  // Important for Caching of Cells/Ids/Weights etc
592  vtkTypeBool AllFixedGeometry;
593  int MeshOverTime;
594  vtkTypeBool StaticSeeds;
595 
596  std::vector<double> InputTimeValues;
597  double StartTime;
598  double TerminationTime;
599  double CurrentTimeValue;
600 
601  int StartTimeStep; // InputTimeValues[StartTimeStep] <= StartTime <=
602  // InputTimeValues[StartTimeStep+1]
603  int CurrentTimeStep;
604  int TerminationTimeStep; // computed from start time
605  bool FirstIteration;
606 
607  // Innjection parameters
608  int ForceReinjectionEveryNSteps;
609  vtkTimeStamp ParticleInjectionTime;
610  bool HasCache;
611 
612  // Particle writing to disk
613  vtkAbstractParticleWriter* ParticleWriter;
614  char* ParticleFileName;
615  vtkTypeBool EnableParticleWriting;
616 
617  // The main lists which are held during operation- between time step updates
619 
620  // The velocity interpolator
622 
623  // Data for time step CurrentTimeStep-1 and CurrentTimeStep
625 
626  // Cache bounds info for each dataset we will use repeatedly
627  struct bounds_t
628  {
629  double b[6];
630  };
631  using bounds = struct bounds_t;
632  std::vector<bounds> CachedBounds[2];
633 
634  // variables used by Execute() to produce output
635 
636  vtkSmartPointer<vtkDataSet> DataReferenceT[2];
637 
638  vtkSmartPointer<vtkPoints> OutputCoordinates;
639  vtkSmartPointer<vtkIdTypeArray> ParticleCellsConnectivity;
640  vtkSmartPointer<vtkIdTypeArray> ParticleCellsOffsets;
641  vtkSmartPointer<vtkCellArray> ParticleCells;
642 
643  vtkSmartPointer<vtkFloatArray> ParticleAge;
644  vtkSmartPointer<vtkIntArray> ParticleIds;
645  vtkSmartPointer<vtkSignedCharArray> ParticleSourceIds;
646  vtkSmartPointer<vtkIntArray> InjectedPointIds;
647  vtkSmartPointer<vtkIntArray> InjectedStepIds;
648  vtkSmartPointer<vtkIntArray> ErrorCodeArray;
649  vtkSmartPointer<vtkFloatArray> ParticleVorticity;
650  vtkSmartPointer<vtkFloatArray> ParticleRotation;
651  vtkSmartPointer<vtkFloatArray> ParticleAngularVel;
652  vtkSmartPointer<vtkPointData> OutputPointData;
653 
654  // temp array
656 
658  void operator=(const vtkLegacyParticleTracerBase&) = delete;
659  vtkTimeStamp ExecuteTime;
660 
661  unsigned int NumberOfParticles();
662 
664 
665  static const double Epsilon;
666 };
667 
668 #endif
A particle tracer for vector fields.
std::list< ParticleInformation > ParticleDataList
virtual void AddRestartSeeds(vtkInformationVector **)
For restarts of particle paths, we add in the ability to add in particles from a previous computation...
vtkTypeBool IgnorePipelineTime
ProtoPD is used just to keep track of the input array names and number of components for copy allocat...
MeshOverTimeTypes
Types of Variance of Mesh over time.
info
int vtkIdType
vtkLegacyParticleTracerBaseNamespace::ParticleDataList ParticleHistories
ProtoPD is used just to keep track of the input array names and number of components for copy allocat...
vtkSmartPointer< vtkPolyData > Output
vtkIdType UniqueIdCounter
ProtoPD is used just to keep track of the input array names and number of components for copy allocat...
vtkSmartPointer< vtkPointData > ProtoPD
ProtoPD is used just to keep track of the input array names and number of components for copy allocat...
int vtkTypeBool
vtkTypeBool DisableResetCache
ProtoPD is used just to keep track of the input array names and number of components for copy allocat...
time
source
A Parallel Particle tracer for unsteady vector fields.
std::vector< ParticleInformation > ParticleVector
virtual bool SendParticleToAnotherProcess(vtkLegacyParticleTracerBaseNamespace::ParticleInformation &, vtkLegacyParticleTracerBaseNamespace::ParticleInformation &, vtkPointData *)
virtual bool UpdateParticleListFromOtherProcesses()
this is used during classification of seed points and also between iterations of the main loop as par...
virtual void SetToExtraPointDataArrays(vtkIdType, vtkLegacyParticleTracerBaseNamespace::ParticleInformation &)
point
virtual void InitializeExtraPointDataArrays(vtkPointData *vtkNotUsed(outputPD))
Methods to append values to existing point data arrays that may only be desired on specific concrete ...
vtkSmartPointer< vtkPointData > ParticlePointData
ProtoPD is used just to keep track of the input array names and number of components for copy allocat...