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;
69  int TimeStepAge; // amount of time steps the particle has advanced
71  int InjectedStepId; // time step the particle was injected
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 
255  virtual ~vtkParticleTracerBase();
256 
257  //
258  // Make sure the pipeline knows what type we expect as input
259  //
260  virtual int FillInputPortInformation(int port, vtkInformation* info);
261 
262  //
263  // The usual suspects
264  //
265  virtual int ProcessRequest(vtkInformation* request,
266  vtkInformationVector** inputVector,
267  vtkInformationVector* outputVector);
268 
269  //
270  // Store any information we need in the output and fetch what we can
271  // from the input
272  //
273  virtual int RequestInformation(vtkInformation* request,
274  vtkInformationVector** inputVector,
275  vtkInformationVector* outputVector);
276 
277  //
278  // Compute input time steps given the output step
279  //
280  virtual int RequestUpdateExtent(vtkInformation* request,
281  vtkInformationVector** inputVector,
282  vtkInformationVector* outputVector);
283 
284  //
285  // what the pipeline calls for each time step
286  //
287  virtual int RequestData(vtkInformation* request,
288  vtkInformationVector** inputVector,
289  vtkInformationVector* outputVector);
290 
291  //
292  // these routines are internally called to actually generate the output
293  //
294  virtual int ProcessInput(vtkInformationVector** inputVector);
295 
296  // This is the main part of the algorithm:
297  // * move all the particles one step
298  // * Reinject particles (by adding them to this->ParticleHistories)
299  // either at the beginning or at the end of each step (modulo this->ForceReinjectionEveryNSteps)
300  // * Output a polydata representing the moved particles
301  // Note that if the starting and the ending time coincide, the polydata is still valid.
302  virtual vtkPolyData* Execute(vtkInformationVector** inputVector);
303 
304  // the RequestData will call these methods in turn
305  virtual void Initialize(){} //the first iteration
306  virtual int OutputParticles(vtkPolyData* poly)=0; //every iteration
307  virtual void Finalize(){} //the last iteration
308 
311  virtual std::vector<vtkDataSet*> GetSeedSources(vtkInformationVector* inputVector, int timeStep);
312 
313  //
314  // Initialization of input (vector-field) geometry
315  //
316  int InitializeInterpolator();
317  int UpdateDataCache(vtkDataObject *td);
318 
320 
322  void TestParticles(
325  int &count);
327 
328  void TestParticles(
329  vtkParticleTracerBaseNamespace::ParticleVector &candidates, std::vector<int> &passed);
330 
332 
336  virtual void AssignSeedsToProcessors(
337  double time, vtkDataSet *source, int sourceID, int ptId,
339  int &localAssignedCount);
341 
343 
345  virtual void AssignUniqueIds(
348 
350 
352  void UpdateParticleList(
355 
360  virtual bool UpdateParticleListFromOtherProcesses(){return false;}
361 
363 
364  void IntegrateParticle(
366  double currenttime, double terminationtime,
367  vtkInitialValueProblemSolver* integrator);
369 
370  // if the particle is added to send list, then returns value is 1,
371  // if it is kept on this process after a retry return value is 0
375  {
376  return true;
377  }
378 
380 
384  bool ComputeDomainExitLocation(
385  double pos[4], double p2[4], double intersection[4],
386  vtkGenericCell *cell);
388 
389  //
390  // Scalar arrays that are generated as each particle is updated
391  //
392  void CreateProtoPD(vtkDataObject* input);
393 
394  vtkFloatArray* GetParticleAge(vtkPointData*);
395  vtkIntArray* GetParticleIds(vtkPointData*);
396  vtkCharArray* GetParticleSourceIds(vtkPointData*);
397  vtkIntArray* GetInjectedPointIds(vtkPointData*);
398  vtkIntArray* GetInjectedStepIds(vtkPointData*);
399  vtkIntArray* GetErrorCodeArr(vtkPointData*);
400  vtkFloatArray* GetParticleVorticity(vtkPointData*);
401  vtkFloatArray* GetParticleRotation(vtkPointData*);
402  vtkFloatArray* GetParticleAngularVel(vtkPointData*);
403 
404  // utility function we use to test if a point is inside any of our local datasets
405  bool InsideBounds(double point[]);
406 
407  void CalculateVorticity( vtkGenericCell* cell, double pcoords[3],
408  vtkDoubleArray* cellVectors, double vorticity[3] );
409 
410  //------------------------------------------------------
411 
412 
413  double GetCacheDataTime(int i);
414  double GetCacheDataTime();
415 
416  virtual void ResetCache();
417  void AddParticle(vtkParticleTracerBaseNamespace::ParticleInformation &info, double* velocity);
418 
420 
423  virtual bool IsPointDataValid(vtkDataObject* input);
424  bool IsPointDataValid(vtkCompositeDataSet* input, std::vector<std::string>& arrayNames);
425  void GetPointDataArrayNames(vtkDataSet* input, std::vector<std::string>& names);
427 
428  vtkGetMacro(ReinjectionCounter, int);
429  vtkGetMacro(CurrentTimeValue, double);
430 
433  virtual void InitializeExtraPointDataArrays(vtkPointData* vtkNotUsed(outputPD)) {}
434 
436 
437  vtkTemporalInterpolatedVelocityField* GetInterpolator();
438 
441  virtual void AddRestartSeeds(vtkInformationVector** /*inputVector*/) {}
442 
443  private:
445  void SetInterpolatorPrototype(vtkAbstractInterpolatedVelocityField*) {}
446 
448 
455  bool RetryWithPush(
456  vtkParticleTracerBaseNamespace::ParticleInformation &info, double* point1,double delT, int subSteps);
458 
459  bool SetTerminationTimeNoModify(double t);
460 
461  //Parameters of tracing
462  vtkInitialValueProblemSolver* Integrator;
463  double IntegrationStep;
464  double MaximumError;
465  bool ComputeVorticity;
466  double RotationScale;
467  double TerminalSpeed;
468 
469  // A counter to keep track of how many times we reinjected
470  int ReinjectionCounter;
471 
472  // Important for Caching of Cells/Ids/Weights etc
473  int AllFixedGeometry;
474  int StaticMesh;
475  int StaticSeeds;
476 
477  std::vector<double> InputTimeValues;
478  double StartTime;
479  double TerminationTime;
480  double CurrentTimeValue;
481 
482  int StartTimeStep; //InputTimeValues[StartTimeStep] <= StartTime <= InputTimeValues[StartTimeStep+1]
483  int CurrentTimeStep;
484  int TerminationTimeStep; //computed from start time
485  bool FirstIteration;
486 
487  //Innjection parameters
488  int ForceReinjectionEveryNSteps;
489  vtkTimeStamp ParticleInjectionTime;
490  bool HasCache;
491 
492  // Particle writing to disk
493  vtkAbstractParticleWriter *ParticleWriter;
494  char *ParticleFileName;
495  int EnableParticleWriting;
496 
497 
498  // The main lists which are held during operation- between time step updates
500 
501  // The velocity interpolator
503  vtkAbstractInterpolatedVelocityField * InterpolatorPrototype;
504 
505  // Data for time step CurrentTimeStep-1 and CurrentTimeStep
507 
508  // Cache bounds info for each dataset we will use repeatedly
509  typedef struct {
510  double b[6];
511  } bounds;
512  std::vector<bounds> CachedBounds[2];
513 
514  // temporary variables used by Exeucte(), for convenience only
515 
516  vtkSmartPointer<vtkPoints> OutputCoordinates;
517  vtkSmartPointer<vtkFloatArray> ParticleAge;
518  vtkSmartPointer<vtkIntArray> ParticleIds;
519  vtkSmartPointer<vtkCharArray> ParticleSourceIds;
520  vtkSmartPointer<vtkIntArray> InjectedPointIds;
521  vtkSmartPointer<vtkIntArray> InjectedStepIds;
523  vtkSmartPointer<vtkFloatArray> ParticleVorticity;
524  vtkSmartPointer<vtkFloatArray> ParticleRotation;
525  vtkSmartPointer<vtkFloatArray> ParticleAngularVel;
527  vtkSmartPointer<vtkPointData> OutputPointData;
528  vtkSmartPointer<vtkDataSet> DataReferenceT[2];
529  vtkSmartPointer<vtkCellArray> ParticleCells;
530 
531  vtkParticleTracerBase(const vtkParticleTracerBase&); // Not implemented.
532  void operator=(const vtkParticleTracerBase&); // Not implemented.
533  vtkTimeStamp ExecuteTime;
534 
535  unsigned int NumberOfParticles();
536 
539 
540  static const double Epsilon;
541 };
542 
543 #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:247
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:84
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 **)
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.