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 
83  vtkIdType PointId; //once the partice is added, PointId is valid
85 
86  typedef std::vector<ParticleInformation> ParticleVector;
87  typedef ParticleVector::iterator ParticleIterator;
88  typedef std::list<ParticleInformation> ParticleDataList;
89  typedef ParticleDataList::iterator ParticleListIterator;
90 };
91 //ETX
92 
94 {
95 public:
96  enum Solvers
97  {
102  UNKNOWN
103  };
104 
106  void PrintSelf(ostream& os, vtkIndent indent);
107  void PrintParticleHistories();
108 
110 
112  vtkGetMacro(ComputeVorticity, bool);
113  void SetComputeVorticity(bool);
115 
117 
119  vtkGetMacro(TerminalSpeed, double);
120  void SetTerminalSpeed(double);
122 
124 
126  vtkGetMacro(RotationScale, double);
127  void SetRotationScale(double);
129 
131 
133  vtkSetMacro(IgnorePipelineTime, int);
134  vtkGetMacro(IgnorePipelineTime, int);
135  vtkBooleanMacro(IgnorePipelineTime, int);
137 
139 
146  vtkGetMacro(ForceReinjectionEveryNSteps,int);
147  void SetForceReinjectionEveryNSteps(int);
149 
151 
155  void SetTerminationTime(double t);
156  vtkGetMacro(TerminationTime,double);
158 
159  void SetIntegrator(vtkInitialValueProblemSolver *);
160  vtkGetObjectMacro ( Integrator, vtkInitialValueProblemSolver );
161 
162  void SetIntegratorType(int type);
163  int GetIntegratorType();
164 
166 
170  vtkGetMacro(StartTime, double);
171  void SetStartTime(double t);
173 
175 
181  vtkSetMacro(StaticSeeds,int);
182  vtkGetMacro(StaticSeeds,int);
184 
186 
192  vtkSetMacro(StaticMesh,int);
193  vtkGetMacro(StaticMesh,int);
195 
197 
201  virtual void SetParticleWriter(vtkAbstractParticleWriter *pw);
204 
206 
208  vtkSetStringMacro(ParticleFileName);
209  vtkGetStringMacro(ParticleFileName);
211 
213 
215  vtkSetMacro(EnableParticleWriting,int);
216  vtkGetMacro(EnableParticleWriting,int);
217  vtkBooleanMacro(EnableParticleWriting,int);
219 
221 
223  vtkSetMacro(DisableResetCache,int);
224  vtkGetMacro(DisableResetCache,int);
225  vtkBooleanMacro(DisableResetCache,int);
227 
229 
230  void AddSourceConnection(vtkAlgorithmOutput* input);
231  void RemoveAllSources();
233 
234  protected:
235  vtkSmartPointer<vtkPolyData> Output; //managed by child classes
237  vtkIdType UniqueIdCounter;// global Id counter used to give particles a stamp
239  vtkSmartPointer<vtkPointData> ParticlePointData; //the current particle point data consistent
240  //with particle history
241  //Everything related to time
242  int IgnorePipelineTime; //whether to use the pipeline time for termination
243  int DisableResetCache; //whether to enable ResetCache() method
244 
245 
247  virtual ~vtkParticleTracerBase();
248 
249  //
250  // Make sure the pipeline knows what type we expect as input
251  //
252  virtual int FillInputPortInformation(int port, vtkInformation* info);
253 
254  //
255  // The usual suspects
256  //
257  virtual int ProcessRequest(vtkInformation* request,
258  vtkInformationVector** inputVector,
259  vtkInformationVector* outputVector);
260 
261  //
262  // Store any information we need in the output and fetch what we can
263  // from the input
264  //
265  virtual int RequestInformation(vtkInformation* request,
266  vtkInformationVector** inputVector,
267  vtkInformationVector* outputVector);
268 
269  //
270  // Compute input time steps given the output step
271  //
272  virtual int RequestUpdateExtent(vtkInformation* request,
273  vtkInformationVector** inputVector,
274  vtkInformationVector* outputVector);
275 
276  //
277  // what the pipeline calls for each time step
278  //
279  virtual int RequestData(vtkInformation* request,
280  vtkInformationVector** inputVector,
281  vtkInformationVector* outputVector);
282 
283  //
284  // these routines are internally called to actually generate the output
285  //
286  virtual int ProcessInput(vtkInformationVector** inputVector);
287 
288  // This is the main part of the algorithm:
289  // * move all the particles one step
290  // * Reinject particles (by adding them to this->ParticleHistories)
291  // either at the beginning or at the end of each step (modulo this->ForceReinjectionEveryNSteps)
292  // * Output a polydata representing the moved particles
293  // Note that if the starting and the ending time coincide, the polydata is still valid.
294  virtual vtkPolyData* Execute(vtkInformationVector** inputVector);
295 
296  // the RequestData will call these methods in turn
297  virtual void Initialize(){} //the first iteration
298  virtual int OutputParticles(vtkPolyData* poly)=0; //every iteration
299  virtual void Finalize(){} //the last iteration
300 
301  //
302  // Initialization of input (vector-field) geometry
303  //
304  int InitializeInterpolator();
305  int UpdateDataCache(vtkDataObject *td);
306 
308 
310  void TestParticles(
313  int &count);
315 
316  void TestParticles(
317  vtkParticleTracerBaseNamespace::ParticleVector &candidates, std::vector<int> &passed);
318 
320 
324  virtual void AssignSeedsToProcessors(double time,
325  vtkDataSet *source, int sourceID, int ptId,
327  int &localAssignedCount);
329 
331 
333  virtual void AssignUniqueIds(
336 
338 
340  void UpdateParticleList(
343 
347 
349 
350  void IntegrateParticle(
352  double currenttime, double terminationtime,
353  vtkInitialValueProblemSolver* integrator);
355 
356  // if the particle is added to send list, then returns value is 1,
357  // if it is kept on this process after a retry return value is 0
361  {
362  return true;
363  }
364 
366 
370  bool ComputeDomainExitLocation(
371  double pos[4], double p2[4], double intersection[4],
372  vtkGenericCell *cell);
374 
375  //
376  // Scalar arrays that are generated as each particle is updated
377  //
378  void CreateProtoPD(vtkDataObject* input);
379 
380  vtkFloatArray* GetParticleAge(vtkPointData*);
381  vtkIntArray* GetParticleIds(vtkPointData*);
382  vtkCharArray* GetParticleSourceIds(vtkPointData*);
383  vtkIntArray* GetInjectedPointIds(vtkPointData*);
384  vtkIntArray* GetInjectedStepIds(vtkPointData*);
385  vtkIntArray* GetErrorCodeArr(vtkPointData*);
386  vtkFloatArray* GetParticleVorticity(vtkPointData*);
387  vtkFloatArray* GetParticleRotation(vtkPointData*);
388  vtkFloatArray* GetParticleAngularVel(vtkPointData*);
389 
390  // utility function we use to test if a point is inside any of our local datasets
391  bool InsideBounds(double point[]);
392 
393  void CalculateVorticity( vtkGenericCell* cell, double pcoords[3],
394  vtkDoubleArray* cellVectors, double vorticity[3] );
395 
396  //------------------------------------------------------
397 
398 
399  double GetCacheDataTime(int i);
400  double GetCacheDataTime();
401 
402  virtual void ResetCache();
403  void AddParticle(vtkParticleTracerBaseNamespace::ParticleInformation &info, double* velocity);
404 
406 
409  virtual bool IsPointDataValid(vtkDataObject* input);
410  bool IsPointDataValid(vtkCompositeDataSet* input, std::vector<std::string>& arrayNames);
411  void GetPointDataArrayNames(vtkDataSet* input, std::vector<std::string>& names);
413 
414  vtkGetMacro(ReinjectionCounter, int);
415  vtkGetMacro(CurrentTimeValue, double);
416 
420 
422 private:
424  void SetInterpolatorPrototype(vtkAbstractInterpolatedVelocityField*) {}
425 
427 
434  bool RetryWithPush(
435  vtkParticleTracerBaseNamespace::ParticleInformation &info, double* point1,double delT, int subSteps);
437 
438  bool SetTerminationTimeNoModify(double t);
439 
440  //Parameters of tracing
441  vtkInitialValueProblemSolver* Integrator;
442  double IntegrationStep;
443  double MaximumError;
444  bool ComputeVorticity;
445  double RotationScale;
446  double TerminalSpeed;
447 
448  // A counter to keep track of how many times we reinjected
449  int ReinjectionCounter;
450 
451  // Important for Caching of Cells/Ids/Weights etc
452  int AllFixedGeometry;
453  int StaticMesh;
454  int StaticSeeds;
455 
456  std::vector<double> InputTimeValues;
457  double StartTime;
458  double TerminationTime;
459  double CurrentTimeValue;
460 
461  int StartTimeStep; //InputTimeValues[StartTimeStep] <= StartTime <= InputTimeValues[StartTimeStep+1]
462  int CurrentTimeStep;
463  int TerminationTimeStep; //computed from start time
464  bool FirstIteration;
465 
466  //Innjection parameters
467  int ForceReinjectionEveryNSteps;
468  vtkTimeStamp ParticleInjectionTime;
469  bool HasCache;
470 
471  // Particle writing to disk
472  vtkAbstractParticleWriter *ParticleWriter;
473  char *ParticleFileName;
474  int EnableParticleWriting;
475 
476 
477  // The main lists which are held during operation- between time step updates
479 
480 
481  // The velocity interpolator
483  vtkAbstractInterpolatedVelocityField * InterpolatorPrototype;
484 
485  // Data for time step CurrentTimeStep-1 and CurrentTimeStep
487 
488  // Cache bounds info for each dataset we will use repeatedly
489  typedef struct {
490  double b[6];
491  } bounds;
492  std::vector<bounds> CachedBounds[2];
493 
494  // temporary variables used by Exeucte(), for convenience only
495 
496  vtkSmartPointer<vtkPoints> OutputCoordinates;
497  vtkSmartPointer<vtkFloatArray> ParticleAge;
498  vtkSmartPointer<vtkIntArray> ParticleIds;
499  vtkSmartPointer<vtkCharArray> ParticleSourceIds;
500  vtkSmartPointer<vtkIntArray> InjectedPointIds;
501  vtkSmartPointer<vtkIntArray> InjectedStepIds;
503  vtkSmartPointer<vtkFloatArray> ParticleVorticity;
504  vtkSmartPointer<vtkFloatArray> ParticleRotation;
505  vtkSmartPointer<vtkFloatArray> ParticleAngularVel;
507  vtkSmartPointer<vtkPointData> OutputPointData;
508  vtkSmartPointer<vtkDataSet> DataReferenceT[2];
509  vtkSmartPointer<vtkCellArray> ParticleCells;
510 
511  vtkParticleTracerBase(const vtkParticleTracerBase&); // Not implemented.
512  void operator=(const vtkParticleTracerBase&); // Not implemented.
513  vtkTimeStamp ExecuteTime;
514 
515  unsigned int NumberOfParticles();
516 
519 
520  static const double Epsilon;
521 
522 };
523 
524 #endif
#define VTKFILTERSFLOWPATHS_EXPORT
#define vtkNotUsed(x)
Definition: vtkSetGet.h:547
A helper class for interpolating between times during particle tracing.
virtual void UpdateParticleListFromOtherProcesses()
GLboolean GLboolean GLboolean b
Definition: vtkgl.h:12312
GLuint GLuint GLsizei GLenum type
Definition: vtkgl.h:11315
abstract class to write particle data to file
represent and manipulate point attribute data
Definition: vtkPointData.h:36
Store vtkAlgorithm input/output information.
GLenum GLenum GLenum input
Definition: vtkgl.h:15941
abstract class to specify dataset behavior
Definition: vtkDataSet.h:59
#define vtkGetMacro(name, type)
Definition: vtkSetGet.h:83
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.
GLuint GLuint GLsizei count
Definition: vtkgl.h:11315
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
Hold a reference to a vtkObjectBase instance.
virtual bool SendParticleToAnotherProcess(vtkParticleTracerBaseNamespace::ParticleInformation &, vtkParticleTracerBaseNamespace::ParticleInformation &, vtkPointData *)
int vtkIdType
Definition: vtkType.h:281
GLdouble GLdouble t
Definition: vtkgl.h:11602
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:83
#define vtkSetStringMacro(name)
Definition: vtkSetGet.h:94
ParticleVector::iterator ParticleIterator
#define vtkTypeMacro(thisClass, superclass)
Definition: vtkSetGet.h:632
provides thread-safe access to cells
Proxy object to connect input/output ports.
dynamic, self-adjusting array of double
GLint GLint GLint GLint GLint x
Definition: vtkgl.h:11318
virtual void AppendToExtraPointDataArrays(vtkParticleTracerBaseNamespace::ParticleInformation &)
dynamic, self-adjusting array of char
Definition: vtkCharArray.h:42
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:38
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:53
#define vtkGetStringMacro(name)
Definition: vtkSetGet.h:120
#define vtkGetObjectMacro(name, type)
Definition: vtkSetGet.h:222
GLuint GLuint * names
Definition: vtkgl.h:19215
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.
#define vtkBooleanMacro(name, type)
Definition: vtkSetGet.h:234
ParticleDataList::iterator ParticleListIterator
general representation of visualization data
Definition: vtkDataObject.h:64
represent and manipulate 3D points
Definition: vtkPoints.h:38
Integrate a set of ordinary differential equations (initial value problem) in time.
A particle tracer for vector fields.
#define vtkSetMacro(name, type)
Definition: vtkSetGet.h:69
Multiprocessing communication superclass.