VTK
vtkParticleTracerBase.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkParticleTracerBase.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
28 #ifndef vtkParticleTracerBase_h
29 #define vtkParticleTracerBase_h
30 
31 #include "vtkFiltersFlowPathsModule.h" // For export macro
32 #include "vtkSmartPointer.h" // For protected ivars.
33 #include "vtkPolyDataAlgorithm.h"
34 
35 #include <vector> // STL Header
36 #include <list> // STL Header
37 
40 class vtkCellArray;
41 class vtkCharArray;
43 class vtkDataArray;
44 class vtkDataSet;
45 class vtkDoubleArray;
46 class vtkFloatArray;
47 class vtkGenericCell;
49 class vtkIntArray;
52 class vtkPointData;
53 class vtkPoints;
54 class vtkPolyData;
56 
58 {
59  typedef struct { double x[4]; } Position;
60  typedef struct {
61  // These are used during iteration
63  int CachedDataSetId[2];
64  vtkIdType CachedCellId[2];
66  // These are computed scalars we might display
67  int SourceID;
68  int TimeStepAge; // amount of time steps the particle has advanced
70  int InjectedStepId; // time step the particle was injected
73  // These are useful to track for debugging etc
74  int ErrorCode;
75  float age;
76  // these are needed across time steps to compute vorticity
77  float rotation;
78  float angularVel;
79  float time;
80  float speed;
81  // once the partice is added, PointId is valid and is the tuple location
82  // in ProtoPD.
84  // if PointId is negative then in parallel this particle was just
85  // received and we need to get the tuple value from vtkPParticleTracerBase::Tail.
88 
89  typedef std::vector<ParticleInformation> ParticleVector;
90  typedef ParticleVector::iterator ParticleIterator;
91  typedef std::list<ParticleInformation> ParticleDataList;
92  typedef ParticleDataList::iterator ParticleListIterator;
93 };
94 
95 class VTKFILTERSFLOWPATHS_EXPORT vtkParticleTracerBase : public vtkPolyDataAlgorithm
96 {
97 public:
98  enum Solvers
99  {
104  UNKNOWN
105  };
106 
108  void PrintSelf(ostream& os, vtkIndent indent) override;
109  void PrintParticleHistories();
110 
112 
117  vtkGetMacro(ComputeVorticity, bool);
118  void SetComputeVorticity(bool);
120 
122 
125  vtkGetMacro(TerminalSpeed, double);
126  void SetTerminalSpeed(double);
128 
130 
134  vtkGetMacro(RotationScale, double);
135  void SetRotationScale(double);
137 
139 
143  vtkSetMacro(IgnorePipelineTime, vtkTypeBool);
144  vtkGetMacro(IgnorePipelineTime, vtkTypeBool);
145  vtkBooleanMacro(IgnorePipelineTime, vtkTypeBool);
147 
149 
158  vtkGetMacro(ForceReinjectionEveryNSteps,int);
159  void SetForceReinjectionEveryNSteps(int);
161 
163 
169  void SetTerminationTime(double t);
170  vtkGetMacro(TerminationTime,double);
172 
173  void SetIntegrator(vtkInitialValueProblemSolver *);
174  vtkGetObjectMacro ( Integrator, vtkInitialValueProblemSolver );
175 
176  void SetIntegratorType(int type);
177  int GetIntegratorType();
178 
180 
184  vtkGetMacro(StartTime, double);
185  void SetStartTime(double t);
187 
189 
198  vtkSetMacro(StaticSeeds,int);
199  vtkGetMacro(StaticSeeds,int);
201 
203 
212  vtkSetMacro(StaticMesh,int);
213  vtkGetMacro(StaticMesh,int);
215 
217 
223  virtual void SetParticleWriter(vtkAbstractParticleWriter *pw);
224  vtkGetObjectMacro(ParticleWriter, vtkAbstractParticleWriter);
226 
228 
232  vtkSetStringMacro(ParticleFileName);
233  vtkGetStringMacro(ParticleFileName);
235 
237 
241  vtkSetMacro(EnableParticleWriting,vtkTypeBool);
242  vtkGetMacro(EnableParticleWriting,vtkTypeBool);
243  vtkBooleanMacro(EnableParticleWriting,vtkTypeBool);
245 
247 
252  vtkSetMacro(DisableResetCache,vtkTypeBool);
253  vtkGetMacro(DisableResetCache,vtkTypeBool);
254  vtkBooleanMacro(DisableResetCache,vtkTypeBool);
256 
258 
261  void AddSourceConnection(vtkAlgorithmOutput* input);
262  void RemoveAllSources();
264 
265  protected:
266  vtkSmartPointer<vtkPolyData> Output; //managed by child classes
268 
273  vtkIdType UniqueIdCounter;// global Id counter used to give particles a stamp
275  vtkSmartPointer<vtkPointData> ParticlePointData; //the current particle point data consistent
276  //with particle history
277  //Everything related to time
278  vtkTypeBool IgnorePipelineTime; //whether to use the pipeline time for termination
279  vtkTypeBool DisableResetCache; //whether to enable ResetCache() method
281 
283  ~vtkParticleTracerBase() override;
284 
285  //
286  // Make sure the pipeline knows what type we expect as input
287  //
288  int FillInputPortInformation(int port, vtkInformation* info) override;
289 
290  //
291  // The usual suspects
292  //
293  int ProcessRequest(vtkInformation* request,
294  vtkInformationVector** inputVector,
295  vtkInformationVector* outputVector) override;
296 
297  //
298  // Store any information we need in the output and fetch what we can
299  // from the input
300  //
301  int RequestInformation(vtkInformation* request,
302  vtkInformationVector** inputVector,
303  vtkInformationVector* outputVector) override;
304 
305  //
306  // Compute input time steps given the output step
307  //
308  int RequestUpdateExtent(vtkInformation* request,
309  vtkInformationVector** inputVector,
310  vtkInformationVector* outputVector) override;
311 
312  //
313  // what the pipeline calls for each time step
314  //
315  int RequestData(vtkInformation* request,
316  vtkInformationVector** inputVector,
317  vtkInformationVector* outputVector) override;
318 
319  //
320  // these routines are internally called to actually generate the output
321  //
322  virtual int ProcessInput(vtkInformationVector** inputVector);
323 
324  // This is the main part of the algorithm:
325  // * move all the particles one step
326  // * Reinject particles (by adding them to this->ParticleHistories)
327  // either at the beginning or at the end of each step (modulo this->ForceReinjectionEveryNSteps)
328  // * Output a polydata representing the moved particles
329  // Note that if the starting and the ending time coincide, the polydata is still valid.
330  virtual vtkPolyData* Execute(vtkInformationVector** inputVector);
331 
332  // the RequestData will call these methods in turn
333  virtual void Initialize(){} //the first iteration
334  virtual int OutputParticles(vtkPolyData* poly)=0; //every iteration
335  virtual void Finalize(){} //the last iteration
336 
341  virtual std::vector<vtkDataSet*> GetSeedSources(vtkInformationVector* inputVector, int timeStep);
342 
343  //
344  // Initialization of input (vector-field) geometry
345  //
346  int InitializeInterpolator();
347  int UpdateDataCache(vtkDataObject *td);
348 
353  void TestParticles(
356  int &count);
357 
358  void TestParticles(
359  vtkParticleTracerBaseNamespace::ParticleVector &candidates, std::vector<int> &passed);
360 
367  virtual void AssignSeedsToProcessors(
368  double time, vtkDataSet *source, int sourceID, int ptId,
370  int &localAssignedCount);
371 
376  virtual void AssignUniqueIds(
378 
383  void UpdateParticleList(
385 
391  virtual bool UpdateParticleListFromOtherProcesses(){return false;}
392 
396  void IntegrateParticle(
398  double currenttime, double terminationtime,
399  vtkInitialValueProblemSolver* integrator);
400 
401  // if the particle is added to send list, then returns value is 1,
402  // if it is kept on this process after a retry return value is 0
406  {
407  return true;
408  }
409 
416  bool ComputeDomainExitLocation(
417  double pos[4], double p2[4], double intersection[4],
418  vtkGenericCell *cell);
419 
420  //
421  // Scalar arrays that are generated as each particle is updated
422  //
423  void CreateProtoPD(vtkDataObject* input);
424 
425  vtkFloatArray* GetParticleAge(vtkPointData*);
426  vtkIntArray* GetParticleIds(vtkPointData*);
427  vtkCharArray* GetParticleSourceIds(vtkPointData*);
428  vtkIntArray* GetInjectedPointIds(vtkPointData*);
429  vtkIntArray* GetInjectedStepIds(vtkPointData*);
430  vtkIntArray* GetErrorCodeArr(vtkPointData*);
431  vtkFloatArray* GetParticleVorticity(vtkPointData*);
432  vtkFloatArray* GetParticleRotation(vtkPointData*);
433  vtkFloatArray* GetParticleAngularVel(vtkPointData*);
434 
435  // utility function we use to test if a point is inside any of our local datasets
436  bool InsideBounds(double point[]);
437 
438  void CalculateVorticity( vtkGenericCell* cell, double pcoords[3],
439  vtkDoubleArray* cellVectors, double vorticity[3] );
440 
441  //------------------------------------------------------
442 
443 
444  double GetCacheDataTime(int i);
445  double GetCacheDataTime();
446 
447  virtual void ResetCache();
448  void AddParticle(vtkParticleTracerBaseNamespace::ParticleInformation &info, double* velocity);
449 
451 
456  virtual bool IsPointDataValid(vtkDataObject* input);
457  bool IsPointDataValid(vtkCompositeDataSet* input, std::vector<std::string>& arrayNames);
458  void GetPointDataArrayNames(vtkDataSet* input, std::vector<std::string>& names);
460 
461  vtkGetMacro(ReinjectionCounter, int);
462  vtkGetMacro(CurrentTimeValue, double);
463 
468  virtual void InitializeExtraPointDataArrays(vtkPointData* vtkNotUsed(outputPD)) {}
469 
471 
472  vtkTemporalInterpolatedVelocityField* GetInterpolator();
473 
478  virtual void AddRestartSeeds(vtkInformationVector** /*inputVector*/) {}
479 
480  private:
484  void SetInterpolatorPrototype(vtkAbstractInterpolatedVelocityField*) {}
485 
495  bool RetryWithPush(
496  vtkParticleTracerBaseNamespace::ParticleInformation &info, double* point1,double delT, int subSteps);
497 
498  bool SetTerminationTimeNoModify(double t);
499 
500  //Parameters of tracing
501  vtkInitialValueProblemSolver* Integrator;
502  double IntegrationStep;
503  double MaximumError;
504  bool ComputeVorticity;
505  double RotationScale;
506  double TerminalSpeed;
507 
508  // A counter to keep track of how many times we reinjected
509  int ReinjectionCounter;
510 
511  // Important for Caching of Cells/Ids/Weights etc
512  int AllFixedGeometry;
513  int StaticMesh;
514  int StaticSeeds;
515 
516  std::vector<double> InputTimeValues;
517  double StartTime;
518  double TerminationTime;
519  double CurrentTimeValue;
520 
521  int StartTimeStep; //InputTimeValues[StartTimeStep] <= StartTime <= InputTimeValues[StartTimeStep+1]
522  int CurrentTimeStep;
523  int TerminationTimeStep; //computed from start time
524  bool FirstIteration;
525 
526  //Innjection parameters
527  int ForceReinjectionEveryNSteps;
528  vtkTimeStamp ParticleInjectionTime;
529  bool HasCache;
530 
531  // Particle writing to disk
532  vtkAbstractParticleWriter *ParticleWriter;
533  char *ParticleFileName;
534  vtkTypeBool EnableParticleWriting;
535 
536 
537  // The main lists which are held during operation- between time step updates
539 
540  // The velocity interpolator
542  vtkAbstractInterpolatedVelocityField * InterpolatorPrototype;
543 
544  // Data for time step CurrentTimeStep-1 and CurrentTimeStep
546 
547  // Cache bounds info for each dataset we will use repeatedly
548  typedef struct {
549  double b[6];
550  } bounds;
551  std::vector<bounds> CachedBounds[2];
552 
553  // temporary variables used by Exeucte(), for convenience only
554 
555  vtkSmartPointer<vtkPoints> OutputCoordinates;
556  vtkSmartPointer<vtkFloatArray> ParticleAge;
557  vtkSmartPointer<vtkIntArray> ParticleIds;
558  vtkSmartPointer<vtkCharArray> ParticleSourceIds;
559  vtkSmartPointer<vtkIntArray> InjectedPointIds;
560  vtkSmartPointer<vtkIntArray> InjectedStepIds;
561  vtkSmartPointer<vtkIntArray> ErrorCodeArray;
562  vtkSmartPointer<vtkFloatArray> ParticleVorticity;
563  vtkSmartPointer<vtkFloatArray> ParticleRotation;
564  vtkSmartPointer<vtkFloatArray> ParticleAngularVel;
566  vtkSmartPointer<vtkPointData> OutputPointData;
567  vtkSmartPointer<vtkDataSet> DataReferenceT[2];
568  vtkSmartPointer<vtkCellArray> ParticleCells;
569 
571  void operator=(const vtkParticleTracerBase&) = delete;
572  vtkTimeStamp ExecuteTime;
573 
574  unsigned int NumberOfParticles();
575 
578 
579  static const double Epsilon;
580 };
581 
582 #endif
A helper class for interpolating between times during particle tracing.
abstract class to write particle data to file
represent and manipulate point attribute data
Definition: vtkPointData.h:37
Store vtkAlgorithm input/output information.
abstract class to specify dataset behavior
Definition: vtkDataSet.h:62
record modification and/or execution time
Definition: vtkTimeStamp.h:35
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:41
An abstract class for obtaining the interpolated velocity values at a point.
Hold a reference to a vtkObjectBase instance.
virtual bool SendParticleToAnotherProcess(vtkParticleTracerBaseNamespace::ParticleInformation &, vtkParticleTracerBaseNamespace::ParticleInformation &, vtkPointData *)
int vtkIdType
Definition: vtkType.h:347
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:85
ParticleVector::iterator ParticleIterator
provides thread-safe access to cells
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...
int vtkTypeBool
Definition: vtkABI.h:69
virtual void AppendToExtraPointDataArrays(vtkParticleTracerBaseNamespace::ParticleInformation &)
dynamic, self-adjusting array of char
Definition: vtkCharArray.h:38
dynamic, self-adjusting array of int
Definition: vtkIntArray.h:45
abstract superclass for composite (multi-block or AMR) datasets
Superclass for algorithms that produce only polydata as output.
a simple class to control print indentation
Definition: vtkIndent.h:39
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
virtual void InitializeExtraPointDataArrays(vtkPointData *vtkNotUsed(outputPD))
Methods to append values to existing point data arrays that may only be desired on specific concrete ...
std::list< ParticleInformation > ParticleDataList
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
object to represent cell connectivity
Definition: vtkCellArray.h:50
Composite dataset that organizes datasets into blocks.
std::vector< ParticleInformation > ParticleVector
Store zero or more vtkInformation instances.
ParticleDataList::iterator ParticleListIterator
general representation of visualization data
Definition: vtkDataObject.h:64
represent and manipulate 3D points
Definition: vtkPoints.h:39
virtual bool UpdateParticleListFromOtherProcesses()
this is used during classification of seed points and also between iterations of the main loop as par...
Integrate a set of ordinary differential equations (initial value problem) in time.
A particle tracer for vector fields.
Multiprocessing communication superclass.