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 =========================================================================*/
27 #ifndef vtkParticleTracerBase_h
28 #define vtkParticleTracerBase_h
29 
30 #include "vtkFiltersFlowPathsModule.h" // For export macro
31 #include "vtkSmartPointer.h" // For protected ivars.
32 #include "vtkPolyDataAlgorithm.h"
33 //BTX
34 #include <vector> // STL Header
35 #include <list> // STL Header
36 //ETX
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 
57 //BTX
59 {
60  typedef struct { double x[4]; } Position;
61  typedef struct {
62  // These are used during iteration
64  int CachedDataSetId[2];
65  vtkIdType CachedCellId[2];
67  // These are computed scalars we might display
68  int SourceID;
74  // These are useful to track for debugging etc
75  int ErrorCode;
76  float age;
77  // these are needed across time steps to compute vorticity
78  float rotation;
79  float angularVel;
80  float time;
81  float speed;
82  // once the partice is added, PointId is valid and is the tuple location
83  // in ProtoPD.
85  // if PointId is negative then in parallel this particle was just
86  // received and we need to get the tuple value from vtkPParticleTracerBase::Tail.
89 
90  typedef std::vector<ParticleInformation> ParticleVector;
91  typedef ParticleVector::iterator ParticleIterator;
92  typedef std::list<ParticleInformation> ParticleDataList;
93  typedef ParticleDataList::iterator ParticleListIterator;
94 };
95 //ETX
96 
98 {
99 public:
100  enum Solvers
101  {
106  UNKNOWN
107  };
108 
110  void PrintSelf(ostream& os, vtkIndent indent);
111  void PrintParticleHistories();
112 
114 
116  vtkGetMacro(ComputeVorticity, bool);
117  void SetComputeVorticity(bool);
119 
121 
123  vtkGetMacro(TerminalSpeed, double);
124  void SetTerminalSpeed(double);
126 
128 
130  vtkGetMacro(RotationScale, double);
131  void SetRotationScale(double);
133 
135 
137  vtkSetMacro(IgnorePipelineTime, int);
138  vtkGetMacro(IgnorePipelineTime, int);
139  vtkBooleanMacro(IgnorePipelineTime, int);
141 
143 
150  vtkGetMacro(ForceReinjectionEveryNSteps,int);
151  void SetForceReinjectionEveryNSteps(int);
153 
155 
159  void SetTerminationTime(double t);
160  vtkGetMacro(TerminationTime,double);
162 
163  void SetIntegrator(vtkInitialValueProblemSolver *);
164  vtkGetObjectMacro ( Integrator, vtkInitialValueProblemSolver );
165 
166  void SetIntegratorType(int type);
167  int GetIntegratorType();
168 
170 
174  vtkGetMacro(StartTime, double);
175  void SetStartTime(double t);
177 
179 
185  vtkSetMacro(StaticSeeds,int);
186  vtkGetMacro(StaticSeeds,int);
188 
190 
196  vtkSetMacro(StaticMesh,int);
197  vtkGetMacro(StaticMesh,int);
199 
201 
205  virtual void SetParticleWriter(vtkAbstractParticleWriter *pw);
206  vtkGetObjectMacro(ParticleWriter, vtkAbstractParticleWriter);
208 
210 
212  vtkSetStringMacro(ParticleFileName);
213  vtkGetStringMacro(ParticleFileName);
215 
217 
219  vtkSetMacro(EnableParticleWriting,int);
220  vtkGetMacro(EnableParticleWriting,int);
221  vtkBooleanMacro(EnableParticleWriting,int);
223 
225 
227  vtkSetMacro(DisableResetCache,int);
228  vtkGetMacro(DisableResetCache,int);
229  vtkBooleanMacro(DisableResetCache,int);
231 
233 
234  void AddSourceConnection(vtkAlgorithmOutput* input);
235  void RemoveAllSources();
237 
238  protected:
239  vtkSmartPointer<vtkPolyData> Output; //managed by child classes
241 
245  vtkIdType UniqueIdCounter;// global Id counter used to give particles a stamp
247  vtkSmartPointer<vtkPointData> ParticlePointData; //the current particle point data consistent
248  //with particle history
249  //Everything related to time
250  int IgnorePipelineTime; //whether to use the pipeline time for termination
251  int DisableResetCache; //whether to enable ResetCache() method
253 
254 
256  virtual ~vtkParticleTracerBase();
257 
258  //
259  // Make sure the pipeline knows what type we expect as input
260  //
261  virtual int FillInputPortInformation(int port, vtkInformation* info);
262 
263  //
264  // The usual suspects
265  //
266  virtual int ProcessRequest(vtkInformation* request,
267  vtkInformationVector** inputVector,
268  vtkInformationVector* outputVector);
269 
270  //
271  // Store any information we need in the output and fetch what we can
272  // from the input
273  //
274  virtual int RequestInformation(vtkInformation* request,
275  vtkInformationVector** inputVector,
276  vtkInformationVector* outputVector);
277 
278  //
279  // Compute input time steps given the output step
280  //
281  virtual int RequestUpdateExtent(vtkInformation* request,
282  vtkInformationVector** inputVector,
283  vtkInformationVector* outputVector);
284 
285  //
286  // what the pipeline calls for each time step
287  //
288  virtual int RequestData(vtkInformation* request,
289  vtkInformationVector** inputVector,
290  vtkInformationVector* outputVector);
291 
292  //
293  // these routines are internally called to actually generate the output
294  //
295  virtual int ProcessInput(vtkInformationVector** inputVector);
296 
297  // This is the main part of the algorithm:
298  // * move all the particles one step
299  // * Reinject particles (by adding them to this->ParticleHistories)
300  // either at the beginning or at the end of each step (modulo this->ForceReinjectionEveryNSteps)
301  // * Output a polydata representing the moved particles
302  // Note that if the starting and the ending time coincide, the polydata is still valid.
303  virtual vtkPolyData* Execute(vtkInformationVector** inputVector);
304 
305  // the RequestData will call these methods in turn
306  virtual void Initialize(){} //the first iteration
307  virtual int OutputParticles(vtkPolyData* poly)=0; //every iteration
308  virtual void Finalize(){} //the last iteration
309 
310  //
311  // Initialization of input (vector-field) geometry
312  //
313  int InitializeInterpolator();
314  int UpdateDataCache(vtkDataObject *td);
315 
317 
319  void TestParticles(
322  int &count);
324 
325  void TestParticles(
326  vtkParticleTracerBaseNamespace::ParticleVector &candidates, std::vector<int> &passed);
327 
329 
333  virtual void AssignSeedsToProcessors(double time,
334  vtkDataSet *source, int sourceID, int ptId,
336  int &localAssignedCount);
338 
340 
342  virtual void AssignUniqueIds(
345 
347 
349  void UpdateParticleList(
352 
357  virtual bool UpdateParticleListFromOtherProcesses(){return false;}
358 
360 
361  void IntegrateParticle(
363  double currenttime, double terminationtime,
364  vtkInitialValueProblemSolver* integrator);
366 
367  // if the particle is added to send list, then returns value is 1,
368  // if it is kept on this process after a retry return value is 0
372  {
373  return true;
374  }
375 
377 
381  bool ComputeDomainExitLocation(
382  double pos[4], double p2[4], double intersection[4],
383  vtkGenericCell *cell);
385 
386  //
387  // Scalar arrays that are generated as each particle is updated
388  //
389  void CreateProtoPD(vtkDataObject* input);
390 
391  vtkFloatArray* GetParticleAge(vtkPointData*);
392  vtkIntArray* GetParticleIds(vtkPointData*);
393  vtkCharArray* GetParticleSourceIds(vtkPointData*);
394  vtkIntArray* GetInjectedPointIds(vtkPointData*);
395  vtkIntArray* GetInjectedStepIds(vtkPointData*);
396  vtkIntArray* GetErrorCodeArr(vtkPointData*);
397  vtkFloatArray* GetParticleVorticity(vtkPointData*);
398  vtkFloatArray* GetParticleRotation(vtkPointData*);
399  vtkFloatArray* GetParticleAngularVel(vtkPointData*);
400 
401  // utility function we use to test if a point is inside any of our local datasets
402  bool InsideBounds(double point[]);
403 
404  void CalculateVorticity( vtkGenericCell* cell, double pcoords[3],
405  vtkDoubleArray* cellVectors, double vorticity[3] );
406 
407  //------------------------------------------------------
408 
409 
410  double GetCacheDataTime(int i);
411  double GetCacheDataTime();
412 
413  virtual void ResetCache();
414  void AddParticle(vtkParticleTracerBaseNamespace::ParticleInformation &info, double* velocity);
415 
417 
420  virtual bool IsPointDataValid(vtkDataObject* input);
421  bool IsPointDataValid(vtkCompositeDataSet* input, std::vector<std::string>& arrayNames);
422  void GetPointDataArrayNames(vtkDataSet* input, std::vector<std::string>& names);
424 
425  vtkGetMacro(ReinjectionCounter, int);
426  vtkGetMacro(CurrentTimeValue, double);
427 
430  virtual void InitializeExtraPointDataArrays(vtkPointData* vtkNotUsed(outputPD)) {}
431 
433 
434  vtkTemporalInterpolatedVelocityField* GetInterpolator();
435 private:
437  void SetInterpolatorPrototype(vtkAbstractInterpolatedVelocityField*) {}
438 
440 
447  bool RetryWithPush(
448  vtkParticleTracerBaseNamespace::ParticleInformation &info, double* point1,double delT, int subSteps);
450 
451  bool SetTerminationTimeNoModify(double t);
452 
453  //Parameters of tracing
454  vtkInitialValueProblemSolver* Integrator;
455  double IntegrationStep;
456  double MaximumError;
457  bool ComputeVorticity;
458  double RotationScale;
459  double TerminalSpeed;
460 
461  // A counter to keep track of how many times we reinjected
462  int ReinjectionCounter;
463 
464  // Important for Caching of Cells/Ids/Weights etc
465  int AllFixedGeometry;
466  int StaticMesh;
467  int StaticSeeds;
468 
469  std::vector<double> InputTimeValues;
470  double StartTime;
471  double TerminationTime;
472  double CurrentTimeValue;
473 
474  int StartTimeStep; //InputTimeValues[StartTimeStep] <= StartTime <= InputTimeValues[StartTimeStep+1]
475  int CurrentTimeStep;
476  int TerminationTimeStep; //computed from start time
477  bool FirstIteration;
478 
479  //Innjection parameters
480  int ForceReinjectionEveryNSteps;
481  vtkTimeStamp ParticleInjectionTime;
482  bool HasCache;
483 
484  // Particle writing to disk
485  vtkAbstractParticleWriter *ParticleWriter;
486  char *ParticleFileName;
487  int EnableParticleWriting;
488 
489 
490  // The main lists which are held during operation- between time step updates
492 
493  // The velocity interpolator
495  vtkAbstractInterpolatedVelocityField * InterpolatorPrototype;
496 
497  // Data for time step CurrentTimeStep-1 and CurrentTimeStep
499 
500  // Cache bounds info for each dataset we will use repeatedly
501  typedef struct {
502  double b[6];
503  } bounds;
504  std::vector<bounds> CachedBounds[2];
505 
506  // temporary variables used by Exeucte(), for convenience only
507 
508  vtkSmartPointer<vtkPoints> OutputCoordinates;
509  vtkSmartPointer<vtkFloatArray> ParticleAge;
510  vtkSmartPointer<vtkIntArray> ParticleIds;
511  vtkSmartPointer<vtkCharArray> ParticleSourceIds;
512  vtkSmartPointer<vtkIntArray> InjectedPointIds;
513  vtkSmartPointer<vtkIntArray> InjectedStepIds;
515  vtkSmartPointer<vtkFloatArray> ParticleVorticity;
516  vtkSmartPointer<vtkFloatArray> ParticleRotation;
517  vtkSmartPointer<vtkFloatArray> ParticleAngularVel;
519  vtkSmartPointer<vtkPointData> OutputPointData;
520  vtkSmartPointer<vtkDataSet> DataReferenceT[2];
521  vtkSmartPointer<vtkCellArray> ParticleCells;
522 
523  vtkParticleTracerBase(const vtkParticleTracerBase&); // Not implemented.
524  void operator=(const vtkParticleTracerBase&); // Not implemented.
525  vtkTimeStamp ExecuteTime;
526 
527  unsigned int NumberOfParticles();
528 
531 
532  static const double Epsilon;
533 
534 };
535 
536 #endif
#define VTKFILTERSFLOWPATHS_EXPORT
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:36
Store vtkAlgorithm input/output information.
abstract class to specify dataset behavior
Definition: vtkDataSet.h:61
record modification and/or execution time
Definition: vtkTimeStamp.h:34
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:45
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:275
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:83
ParticleVector::iterator ParticleIterator
provides thread-safe access to cells
Proxy object to connect input/output ports.
dynamic, self-adjusting array of double
virtual void AppendToExtraPointDataArrays(vtkParticleTracerBaseNamespace::ParticleInformation &)
dynamic, self-adjusting array of char
Definition: vtkCharArray.h:42
dynamic, self-adjusting array of int
Definition: vtkIntArray.h:49
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:38
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
virtual void InitializeExtraPointDataArrays(vtkPointData *vtkNotUsed(outputPD))
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:49
unsigned long ErrorCode
Definition: vtkAlgorithm.h:708
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:38
virtual bool UpdateParticleListFromOtherProcesses()
Integrate a set of ordinary differential equations (initial value problem) in time.
A particle tracer for vector fields.
Multiprocessing communication superclass.