VTK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
58 namespace vtkParticleTracerBaseNamespace
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;
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 
82  vtkIdType PointId; //once the partice is added, PointId is valid
84 
85  typedef std::vector<ParticleInformation> ParticleVector;
86  typedef ParticleVector::iterator ParticleIterator;
87  typedef std::list<ParticleInformation> ParticleDataList;
88  typedef ParticleDataList::iterator ParticleListIterator;
89 };
90 //ETX
91 
93 {
94 public:
95  enum Solvers
96  {
101  UNKNOWN
102  };
103 
105  void PrintSelf(ostream& os, vtkIndent indent);
106  void PrintParticleHistories();
107 
109 
111  vtkGetMacro(ComputeVorticity, bool);
112  void SetComputeVorticity(bool);
114 
116 
118  vtkGetMacro(TerminalSpeed, double);
119  void SetTerminalSpeed(double);
121 
123 
125  vtkGetMacro(RotationScale, double);
126  void SetRotationScale(double);
128 
130 
132  vtkSetMacro(IgnorePipelineTime, int);
133  vtkGetMacro(IgnorePipelineTime, int);
134  vtkBooleanMacro(IgnorePipelineTime, int);
136 
138 
145  vtkGetMacro(ForceReinjectionEveryNSteps,int);
146  void SetForceReinjectionEveryNSteps(int);
148 
150 
154  void SetTerminationTime(double t);
155  vtkGetMacro(TerminationTime,double);
157 
158  void SetIntegrator(vtkInitialValueProblemSolver *);
159  vtkGetObjectMacro ( Integrator, vtkInitialValueProblemSolver );
160 
161  void SetIntegratorType(int type);
162  int GetIntegratorType();
163 
165 
169  vtkGetMacro(StartTime, double);
170  void SetStartTime(double t);
172 
174 
180  vtkSetMacro(StaticSeeds,int);
181  vtkGetMacro(StaticSeeds,int);
183 
185 
191  vtkSetMacro(StaticMesh,int);
192  vtkGetMacro(StaticMesh,int);
194 
196 
200  virtual void SetParticleWriter(vtkAbstractParticleWriter *pw);
203 
205 
207  vtkSetStringMacro(ParticleFileName);
208  vtkGetStringMacro(ParticleFileName);
210 
212 
214  vtkSetMacro(EnableParticleWriting,int);
215  vtkGetMacro(EnableParticleWriting,int);
216  vtkBooleanMacro(EnableParticleWriting,int);
218 
220 
222  vtkSetMacro(DisableResetCache,int);
223  vtkGetMacro(DisableResetCache,int);
224  vtkBooleanMacro(DisableResetCache,int);
226 
228 
229  void AddSourceConnection(vtkAlgorithmOutput* input);
230  void RemoveAllSources();
232 
233  protected:
234  vtkSmartPointer<vtkPolyData> Output; //managed by child classes
236  vtkIdType UniqueIdCounter;// global Id counter used to give particles a stamp
237  vtkParticleTracerBaseNamespace::ParticleDataList ParticleHistories;
238  vtkSmartPointer<vtkPointData> ParticlePointData; //the current particle point data consistent
239  //with particle history
240  int ReinjectionCounter;
241 
242  //Everything related to time
243  int IgnorePipelineTime; //whether to use the pipeline time for termination
244  int DisableResetCache; //whether to enable ResetCache() method
245 
246 
248  virtual ~vtkParticleTracerBase();
249 
250  //
251  // Make sure the pipeline knows what type we expect as input
252  //
253  virtual int FillInputPortInformation(int port, vtkInformation* info);
254 
255  //
256  // The usual suspects
257  //
258  virtual int ProcessRequest(vtkInformation* request,
259  vtkInformationVector** inputVector,
260  vtkInformationVector* outputVector);
261 
262  //
263  // Store any information we need in the output and fetch what we can
264  // from the input
265  //
266  virtual int RequestInformation(vtkInformation* request,
267  vtkInformationVector** inputVector,
268  vtkInformationVector* outputVector);
269 
270  //
271  // Compute input time steps given the output step
272  //
273  virtual int RequestUpdateExtent(vtkInformation* request,
274  vtkInformationVector** inputVector,
275  vtkInformationVector* outputVector);
276 
277  //
278  // what the pipeline calls for each time step
279  //
280  virtual int RequestData(vtkInformation* request,
281  vtkInformationVector** inputVector,
282  vtkInformationVector* outputVector);
283 
284  //
285  // these routines are internally called to actually generate the output
286  //
287  virtual int ProcessInput(vtkInformationVector** inputVector);
288 
289  // This is the main part of the algorithm:
290  // * move all the particles one step
291  // * Reinject particles (by adding them to this->ParticleHistories)
292  // either at the beginning or at the end of each step (modulo this->ForceReinjectionEveryNSteps)
293  // * Output a polydata representing the moved particles
294  // Note that if the starting and the ending time coincide, the polydata is still valid.
295  virtual vtkPolyData* Execute(vtkInformationVector** inputVector);
296 
297  // the RequestData will call these methods in turn
298  virtual void Initialize(){} //the first iteration
299  virtual int OutputParticles(vtkPolyData* poly)=0; //every iteration
300  virtual void Finalize(){} //the last iteration
301 
302  //
303  // Initialization of input (vector-field) geometry
304  //
305  int InitializeInterpolator();
306  int UpdateDataCache(vtkDataObject *td);
307 
309 
311  void TestParticles(
314  int &count);
316 
317  void TestParticles(
318  vtkParticleTracerBaseNamespace::ParticleVector &candidates, std::vector<int> &passed);
319 
321 
325  virtual void AssignSeedsToProcessors(double time,
326  vtkDataSet *source, int sourceID, int ptId,
328  int &localAssignedCount);
330 
332 
334  virtual void AssignUniqueIds(
337 
339 
341  void UpdateParticleList(
344 
348 
350 
351  void IntegrateParticle(
353  double currenttime, double terminationtime,
354  vtkInitialValueProblemSolver* integrator);
356 
357  // if the particle is added to send list, then returns value is 1,
358  // if it is kept on this process after a retry return value is 0
362  {
363  return true;
364  }
365 
367 
371  bool ComputeDomainExitLocation(
372  double pos[4], double p2[4], double intersection[4],
373  vtkGenericCell *cell);
375 
376  //
377  // Scalar arrays that are generated as each particle is updated
378  //
379  void CreateProtoPD(vtkDataObject* input);
380 
381  vtkFloatArray* GetParticleAge(vtkPointData*);
382  vtkIntArray* GetParticleIds(vtkPointData*);
383  vtkCharArray* GetParticleSourceIds(vtkPointData*);
384  vtkIntArray* GetInjectedPointIds(vtkPointData*);
385  vtkIntArray* GetInjectedStepIds(vtkPointData*);
386  vtkIntArray* GetErrorCodeArr(vtkPointData*);
387  vtkFloatArray* GetParticleVorticity(vtkPointData*);
388  vtkFloatArray* GetParticleRotation(vtkPointData*);
389  vtkFloatArray* GetParticleAngularVel(vtkPointData*);
390 
391 
392  // utility function we use to test if a point is inside any of our local datasets
393  bool InsideBounds(double point[]);
394 
395 
396 
397  void CalculateVorticity( vtkGenericCell* cell, double pcoords[3],
398  vtkDoubleArray* cellVectors, double vorticity[3] );
399 
400  //------------------------------------------------------
401 
402 
403  double GetCacheDataTime(int i);
404  double GetCacheDataTime();
405 
406  virtual void ResetCache();
407  void AddParticle(vtkParticleTracerBaseNamespace::ParticleInformation &info, double* velocity);
408 
410 
413  virtual bool IsPointDataValid(vtkDataObject* input);
414  bool IsPointDataValid(vtkCompositeDataSet* input, std::vector<std::string>& arrayNames);
415  void GetPointDataArrayNames(vtkDataSet* input, std::vector<std::string>& names);
417 
418 private:
420  void SetInterpolatorPrototype(vtkAbstractInterpolatedVelocityField*) {}
421 
423 
430  bool RetryWithPush(
431  vtkParticleTracerBaseNamespace::ParticleInformation &info, double* point1,double delT, int subSteps);
433 
434  //Parameters of tracing
435  vtkInitialValueProblemSolver* Integrator;
436  double IntegrationStep;
437  double MaximumError;
438  bool ComputeVorticity;
439  double RotationScale;
440  double TerminalSpeed;
441 
442  // Important for Caching of Cells/Ids/Weights etc
443  int AllFixedGeometry;
444  int StaticMesh;
445  int StaticSeeds;
446 
447  std::vector<double> InputTimeValues;
448  double StartTime;
449  double TerminationTime;
450  double CurrentTime;
451 
452  int StartTimeStep; //InputTimeValues[StartTimeStep] <= StartTime <= InputTimeValues[StartTimeStep+1]
453  int CurrentTimeStep;
454  int TerminationTimeStep; //computed from start time
455  bool FirstIteration;
456 
457  //Innjection parameters
458  int ForceReinjectionEveryNSteps;
459  vtkTimeStamp ParticleInjectionTime;
460  bool HasCache;
461 
462  // Particle writing to disk
463  vtkAbstractParticleWriter *ParticleWriter;
464  char *ParticleFileName;
465  int EnableParticleWriting;
466 
467 
468  // The main lists which are held during operation- between time step updates
470 
471 
472  // The velocity interpolator
474  vtkAbstractInterpolatedVelocityField * InterpolatorPrototype;
475 
476  // Data for time step CurrentTimeStep-1 and CurrentTimeStep
478 
479  // Cache bounds info for each dataset we will use repeatedly
480  typedef struct {
481  double b[6];
482  } bounds;
483  std::vector<bounds> CachedBounds[2];
484 
485  // temporary variables used by Exeucte(), for convenience only
486 
487  vtkSmartPointer<vtkPoints> OutputCoordinates;
488  vtkSmartPointer<vtkFloatArray> ParticleAge;
489  vtkSmartPointer<vtkIntArray> ParticleIds;
490  vtkSmartPointer<vtkCharArray> ParticleSourceIds;
491  vtkSmartPointer<vtkIntArray> InjectedPointIds;
492  vtkSmartPointer<vtkIntArray> InjectedStepIds;
494  vtkSmartPointer<vtkFloatArray> ParticleVorticity;
495  vtkSmartPointer<vtkFloatArray> ParticleRotation;
496  vtkSmartPointer<vtkFloatArray> ParticleAngularVel;
498  vtkSmartPointer<vtkPointData> OutputPointData;
499  vtkSmartPointer<vtkDataSet> DataReferenceT[2];
500  vtkSmartPointer<vtkCellArray> ParticleCells;
501 
502  vtkParticleTracerBase(const vtkParticleTracerBase&); // Not implemented.
503  void operator=(const vtkParticleTracerBase&); // Not implemented.
504  vtkTimeStamp ExecuteTime;
505 
506  unsigned int NumberOfParticles();
507 
510 
511  static const double Epsilon;
512 
513 };
514 
515 #endif
#define VTKFILTERSFLOWPATHS_EXPORT
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:60
#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:268
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:619
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
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
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:700
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:39
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.