VTK  9.3.20240425
vtkParticleTracerBase.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
16#ifndef vtkParticleTracerBase_h
17#define vtkParticleTracerBase_h
18
19#include "vtkFiltersFlowPathsModule.h" // For export macro
21#include "vtkSmartPointer.h" // For vtkSmartPointer
22
23#include <list> // STL Header
24#include <mutex> // STL Header
25#include <vector> // STL Header
26
27VTK_ABI_NAMESPACE_BEGIN
29class vtkCellArray;
31class vtkDataArray;
32class vtkDataSet;
33class vtkDoubleArray;
34class vtkFloatArray;
35class vtkGenericCell;
37class vtkIntArray;
40class vtkPointData;
41class vtkPoints;
42class vtkPolyData;
45VTK_ABI_NAMESPACE_END
46
48{
49VTK_ABI_NAMESPACE_BEGIN
51{
52 double x[4];
53};
54using Position = struct Position_t;
55
57{
58 // These are used during iteration
63 // These are computed scalars we might display
65 int TimeStepAge; // amount of time steps the particle has advanced
67 int InjectedStepId; // time step the particle was injected
70 // These are useful to track for debugging etc
72 float age;
73 // these are needed across time steps to compute vorticity
74 float rotation;
76 float time;
77 float speed;
78 // once the particle is added, PointId is valid and is the tuple location
79 // in ProtoPD.
81 // if PointId is negative then in parallel this particle was just
82 // received and we need to get the tuple value from vtkPParticleTracerBase::Tail.
84};
86
87typedef std::vector<ParticleInformation> ParticleVector;
88typedef ParticleVector::iterator ParticleIterator;
89typedef std::list<ParticleInformation> ParticleDataList;
90typedef ParticleDataList::iterator ParticleListIterator;
91struct ParticleTracerFunctor;
92VTK_ABI_NAMESPACE_END
93}
94
95VTK_ABI_NAMESPACE_BEGIN
96class VTKFILTERSFLOWPATHS_EXPORT vtkParticleTracerBase : public vtkPolyDataAlgorithm
97{
98public:
99 friend struct vtkParticleTracerBaseNamespace::ParticleTracerFunctor;
101 {
106 UNKNOWN
107 };
108
110 void PrintSelf(ostream& os, vtkIndent indent) override;
112
114
119 vtkGetMacro(ComputeVorticity, bool);
122
124
127 vtkGetMacro(TerminalSpeed, double);
128 void SetTerminalSpeed(double);
130
132
136 vtkGetMacro(RotationScale, double);
137 void SetRotationScale(double);
139
141
145 vtkSetMacro(IgnorePipelineTime, vtkTypeBool);
146 vtkGetMacro(IgnorePipelineTime, vtkTypeBool);
147 vtkBooleanMacro(IgnorePipelineTime, vtkTypeBool);
149
151
160 vtkGetMacro(ForceReinjectionEveryNSteps, int);
163
165
171 void SetTerminationTime(double t);
172 vtkGetMacro(TerminationTime, double);
174
176 vtkGetObjectMacro(Integrator, vtkInitialValueProblemSolver);
177
178 void SetIntegratorType(int type);
180
182
186 vtkGetMacro(StartTime, double);
187 void SetStartTime(double t);
189
191
200 vtkSetMacro(StaticSeeds, vtkTypeBool);
201 vtkGetMacro(StaticSeeds, vtkTypeBool);
203
208 {
209 DIFFERENT = 0,
210 STATIC = 1,
211 LINEAR_TRANSFORMATION = 2,
212 SAME_TOPOLOGY = 3
213 };
214
216 /*
217 * Set/Get the type of variance of the mesh over time.
218 *
219 * DIFFERENT = 0,
220 * STATIC = 1,
221 * LINEAR_TRANSFORMATION = 2
222 * SAME_TOPOLOGY = 3
223 */
224 virtual void SetMeshOverTime(int meshOverTime);
225 virtual int GetMeshOverTimeMinValue() { return DIFFERENT; }
226 virtual int GetMeshOverTimeMaxValue() { return SAME_TOPOLOGY; }
227 void SetMeshOverTimeToDifferent() { this->SetMeshOverTime(DIFFERENT); }
228 void SetMeshOverTimeToStatic() { this->SetMeshOverTime(STATIC); }
229 void SetMeshOverTimeToLinearTransformation() { this->SetMeshOverTime(LINEAR_TRANSFORMATION); }
230 void SetMeshOverTimeToSameTopology() { this->SetMeshOverTime(SAME_TOPOLOGY); }
231 vtkGetMacro(MeshOverTime, int);
233
234 enum
235 {
237 INTERPOLATOR_WITH_CELL_LOCATOR
238 };
239
251 void SetInterpolatorType(int interpolatorType);
252
261
269
271
278 vtkGetObjectMacro(ParticleWriter, vtkAbstractParticleWriter);
280
282
286 vtkSetFilePathMacro(ParticleFileName);
287 vtkGetFilePathMacro(ParticleFileName);
289
291
295 vtkSetMacro(EnableParticleWriting, vtkTypeBool);
296 vtkGetMacro(EnableParticleWriting, vtkTypeBool);
297 vtkBooleanMacro(EnableParticleWriting, vtkTypeBool);
299
301
306 vtkSetMacro(DisableResetCache, vtkTypeBool);
307 vtkGetMacro(DisableResetCache, vtkTypeBool);
308 vtkBooleanMacro(DisableResetCache, vtkTypeBool);
310
312
318
320
324 vtkGetMacro(ForceSerialExecution, bool);
325 vtkSetMacro(ForceSerialExecution, bool);
326 vtkBooleanMacro(ForceSerialExecution, bool);
328protected:
329 vtkSmartPointer<vtkPolyData> Output; // managed by child classes
331
336 vtkIdType UniqueIdCounter; // global Id counter used to give particles a stamp
338 vtkSmartPointer<vtkPointData> ParticlePointData; // the current particle point data consistent
339 // with particle history
340 // Everything related to time
341 vtkTypeBool IgnorePipelineTime; // whether to use the pipeline time for termination
342 vtkTypeBool DisableResetCache; // whether to enable ResetCache() method
344
345 // Control execution as serial or threaded
347
350
351 //
352 // Make sure the pipeline knows what type we expect as input
353 //
354 int FillInputPortInformation(int port, vtkInformation* info) override;
355
356 //
357 // The usual suspects
358 //
360 vtkInformationVector* outputVector) override;
361
362 //
363 // Store any information we need in the output and fetch what we can
364 // from the input
365 //
367 vtkInformationVector* outputVector) override;
368
369 //
370 // Compute input time steps given the output step
371 //
373 vtkInformationVector* outputVector) override;
374
375 //
376 // what the pipeline calls for each time step
377 //
379 vtkInformationVector* outputVector) override;
380
381 //
382 // these routines are internally called to actually generate the output
383 //
384 virtual int ProcessInput(vtkInformationVector** inputVector);
385
386 // This is the main part of the algorithm:
387 // * move all the particles one step
388 // * Reinject particles (by adding them to this->ParticleHistories)
389 // either at the beginning or at the end of each step (modulo
390 // this->ForceReinjectionEveryNSteps)
391 // * Output a polydata representing the moved particles
392 // Note that if the starting and the ending time coincide, the polydata is still valid.
393 virtual vtkPolyData* Execute(vtkInformationVector** inputVector);
394
395 // the RequestData will call these methods in turn
396 virtual void Initialize() {} // the first iteration
397 virtual int OutputParticles(vtkPolyData* poly) = 0; // every iteration
398 virtual void Finalize() {} // the last iteration
399
404 virtual std::vector<vtkDataSet*> GetSeedSources(vtkInformationVector* inputVector, int timeStep);
405
406 // Initialization of input (vector-field) geometry
409
416
418 vtkParticleTracerBaseNamespace::ParticleVector& candidates, std::vector<int>& passed);
419
426 virtual void AssignSeedsToProcessors(double time, vtkDataSet* source, int sourceID, int ptId,
427 vtkParticleTracerBaseNamespace::ParticleVector& localSeedPoints, int& localAssignedCount);
428
434
440
446 virtual bool UpdateParticleListFromOtherProcesses() { return false; }
447
452 double currentTime, double targetTime, vtkInitialValueProblemSolver* integrator,
453 vtkTemporalInterpolatedVelocityField* interpolator, vtkDoubleArray* cellVectors,
454 std::atomic<vtkIdType>& particleCount, std::mutex& eraseMutex, bool sequential);
455
456 // if the particle is added to send list, then returns value is 1,
457 // if it is kept on this process after a retry return value is 0
460 {
461 return true;
462 }
463
471 double pos[4], double p2[4], double intersection[4], vtkGenericCell* cell);
472
473 //
474 // Scalar arrays that are generated as each particle is updated
475 //
477
487
488 // utility function we use to test if a point is inside any of our local datasets
489 bool InsideBounds(double point[]);
490
492 vtkGenericCell* cell, double pcoords[3], vtkDoubleArray* cellVectors, double vorticity[3]);
493
494 //------------------------------------------------------
495
496 double GetCacheDataTime(int i);
498
499 virtual void ResetCache();
501 vtkTemporalInterpolatedVelocityField* interpolator, vtkIdType particleId,
502 vtkDoubleArray* cellVectors);
503
505
510 virtual bool IsPointDataValid(vtkDataObject* input);
511 bool IsPointDataValid(vtkCompositeDataSet* input, std::vector<std::string>& arrayNames);
512 void GetPointDataArrayNames(vtkDataSet* input, std::vector<std::string>& names);
514
515 vtkGetMacro(ReinjectionCounter, int);
516 vtkGetMacro(CurrentTimeValue, double);
517
518 void ResizeArrays(vtkIdType numTuples);
519
524 virtual void InitializeExtraPointDataArrays(vtkPointData* vtkNotUsed(outputPD)) {}
525
528 {
529 }
530
532
537 virtual void AddRestartSeeds(vtkInformationVector** /*inputVector*/) {}
538
544
545private:
555 bool RetryWithPush(vtkParticleTracerBaseNamespace::ParticleInformation& info, double* point1,
556 double delT, int subSteps, vtkTemporalInterpolatedVelocityField* interpolator);
557
558 bool SetTerminationTimeNoModify(double t);
559
560 // Parameters of tracing
562 double IntegrationStep;
563 double MaximumError;
564 bool ComputeVorticity;
565 double RotationScale;
566 double TerminalSpeed;
567
568 // A counter to keep track of how many times we reinjected
569 int ReinjectionCounter;
570
571 // Important for Caching of Cells/Ids/Weights etc
572 vtkTypeBool AllFixedGeometry;
573 int MeshOverTime;
574 vtkTypeBool StaticSeeds;
575
576 std::vector<double> InputTimeValues;
577 double StartTime;
578 double TerminationTime;
579 double CurrentTimeValue;
580
581 int StartTimeStep; // InputTimeValues[StartTimeStep] <= StartTime <=
582 // InputTimeValues[StartTimeStep+1]
583 int CurrentTimeStep;
584 int TerminationTimeStep; // computed from start time
585 bool FirstIteration;
586
587 // Innjection parameters
588 int ForceReinjectionEveryNSteps;
589 vtkTimeStamp ParticleInjectionTime;
590 bool HasCache;
591
592 // Particle writing to disk
593 vtkAbstractParticleWriter* ParticleWriter;
594 char* ParticleFileName;
595 vtkTypeBool EnableParticleWriting;
596
597 // The main lists which are held during operation- between time step updates
599
600 // The velocity interpolator
602
603 // Data for time step CurrentTimeStep-1 and CurrentTimeStep
605
606 // Cache bounds info for each dataset we will use repeatedly
607 struct bounds_t
608 {
609 double b[6];
610 };
611 using bounds = struct bounds_t;
612 std::vector<bounds> CachedBounds[2];
613
614 // variables used by Execute() to produce output
615
616 vtkSmartPointer<vtkDataSet> DataReferenceT[2];
617
618 vtkSmartPointer<vtkPoints> OutputCoordinates;
619 vtkSmartPointer<vtkIdTypeArray> ParticleCellsConnectivity;
620 vtkSmartPointer<vtkIdTypeArray> ParticleCellsOffsets;
621 vtkSmartPointer<vtkCellArray> ParticleCells;
622
625 vtkSmartPointer<vtkSignedCharArray> ParticleSourceIds;
626 vtkSmartPointer<vtkIntArray> InjectedPointIds;
627 vtkSmartPointer<vtkIntArray> InjectedStepIds;
628 vtkSmartPointer<vtkIntArray> ErrorCodeArray;
629 vtkSmartPointer<vtkFloatArray> ParticleVorticity;
630 vtkSmartPointer<vtkFloatArray> ParticleRotation;
631 vtkSmartPointer<vtkFloatArray> ParticleAngularVel;
632 vtkSmartPointer<vtkPointData> OutputPointData;
633
634 // temp array
636
638 void operator=(const vtkParticleTracerBase&) = delete;
639 vtkTimeStamp ExecuteTime;
640
641 unsigned int NumberOfParticles();
642
645
646 static const double Epsilon;
647};
648
649VTK_ABI_NAMESPACE_END
650#endif
abstract class to write particle data to file
Proxy object to connect input/output ports.
object to represent cell connectivity
abstract superclass for composite (multi-block or AMR) datasets
abstract superclass for arrays of numeric data
general representation of visualization data
abstract class to specify dataset behavior
Definition vtkDataSet.h:166
dynamic, self-adjusting array of double
dynamic, self-adjusting array of float
provides thread-safe access to cells
a simple class to control print indentation
Definition vtkIndent.h:108
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
Integrate a set of ordinary differential equations (initial value problem) in time.
dynamic, self-adjusting array of int
Composite dataset that organizes datasets into blocks.
Multiprocessing communication superclass.
A particle tracer for vector fields.
vtkTypeBool DisableResetCache
ProtoPD is used just to keep track of the input array names and number of components for copy allocat...
vtkFloatArray * GetParticleVorticity(vtkPointData *)
vtkSmartPointer< vtkPointData > ProtoPD
ProtoPD is used just to keep track of the input array names and number of components for copy allocat...
virtual void RenameGhostArray(vtkPointData *pd)
Recover the ghost array in provided point data and rename it by adding "Original_" in front of it,...
void SetComputeVorticity(bool)
Turn on/off vorticity computation at streamline points (necessary for generating proper stream-ribbon...
vtkSmartPointer< vtkPointData > ParticlePointData
ProtoPD is used just to keep track of the input array names and number of components for copy allocat...
vtkIntArray * GetInjectedPointIds(vtkPointData *)
vtkFloatArray * GetParticleAge(vtkPointData *)
void TestParticles(vtkParticleTracerBaseNamespace::ParticleVector &candidates, std::vector< int > &passed)
virtual void AddRestartSeeds(vtkInformationVector **)
For restarts of particle paths, we add in the ability to add in particles from a previous computation...
bool IsPointDataValid(vtkCompositeDataSet *input, std::vector< std::string > &arrayNames)
Methods that check that the input arrays are ordered the same on all data sets.
void SetInterpolatorTypeToCellLocator()
Set the velocity field interpolator type to one that uses a cell locator to perform spatial searching...
void SetTerminationTime(double t)
Setting TerminationTime to a positive value will cause particles to terminate when the time is reache...
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
This is called by the superclass.
vtkIntArray * GetInjectedStepIds(vtkPointData *)
virtual bool UpdateParticleListFromOtherProcesses()
this is used during classification of seed points and also between iterations of the main loop as par...
virtual std::vector< vtkDataSet * > GetSeedSources(vtkInformationVector *inputVector, int timeStep)
Method to get the data set seed sources.
vtkIntArray * GetErrorCodeArr(vtkPointData *)
void SetParticle(vtkParticleTracerBaseNamespace::ParticleInformation &info, double *velocity, vtkTemporalInterpolatedVelocityField *interpolator, vtkIdType particleId, vtkDoubleArray *cellVectors)
void UpdateParticleList(vtkParticleTracerBaseNamespace::ParticleVector &candidates)
and sending between processors, into a list, which is used as the master list on this processor
vtkGetFilePathMacro(ParticleFileName)
Set/Get the filename to be used with the particle writer when dumping particles to disk.
virtual void SetToExtraPointDataArrays(vtkIdType, vtkParticleTracerBaseNamespace::ParticleInformation &)
vtkFloatArray * GetParticleAngularVel(vtkPointData *)
double GetCacheDataTime(int i)
void TestParticles(vtkParticleTracerBaseNamespace::ParticleVector &candidates, vtkParticleTracerBaseNamespace::ParticleVector &passed, int &count)
inside our data.
vtkTypeBool ProcessRequest(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
Upstream/Downstream requests form the generalized interface through which executives invoke a algorit...
void AddSourceConnection(vtkAlgorithmOutput *input)
Provide support for multiple seed sources.
virtual vtkPolyData * Execute(vtkInformationVector **inputVector)
void RemoveAllSources()
Provide support for multiple seed sources.
void CalculateVorticity(vtkGenericCell *cell, double pcoords[3], vtkDoubleArray *cellVectors, double vorticity[3])
void CreateProtoPD(vtkDataObject *input)
virtual int ProcessInput(vtkInformationVector **inputVector)
virtual bool SendParticleToAnotherProcess(vtkParticleTracerBaseNamespace::ParticleInformation &, vtkParticleTracerBaseNamespace::ParticleInformation &, vtkPointData *)
vtkIntArray * GetParticleIds(vtkPointData *)
MeshOverTimeTypes
Types of Variance of Mesh over time.
void SetForceReinjectionEveryNSteps(int)
When animating particles, it is nice to inject new ones every Nth step to produce a continuous flow.
int UpdateDataCache(vtkDataObject *td)
void SetTerminalSpeed(double)
Specify the terminal speed value, below which integration is terminated.
virtual void SetParticleWriter(vtkAbstractParticleWriter *pw)
Set/Get the Writer associated with this Particle Tracer Ideally a parallel IO capable vtkH5PartWriter...
void SetRotationScale(double)
This can be used to scale the rate with which the streamribbons twist.
vtkParticleTracerBaseNamespace::ParticleDataList ParticleHistories
ProtoPD is used just to keep track of the input array names and number of components for copy allocat...
vtkFloatArray * GetParticleRotation(vtkPointData *)
void IntegrateParticle(vtkParticleTracerBaseNamespace::ParticleListIterator &it, double currentTime, double targetTime, vtkInitialValueProblemSolver *integrator, vtkTemporalInterpolatedVelocityField *interpolator, vtkDoubleArray *cellVectors, std::atomic< vtkIdType > &particleCount, std::mutex &eraseMutex, bool sequential)
particle between the two times supplied.
void GetPointDataArrayNames(vtkDataSet *input, std::vector< std::string > &names)
Methods that check that the input arrays are ordered the same on all data sets.
void SetInterpolatorType(int interpolatorType)
Set the type of the velocity field interpolator to determine whether INTERPOLATOR_WITH_DATASET_POINT_...
virtual void SetMeshOverTime(int meshOverTime)
int RequestUpdateExtent(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
This is called by the superclass.
void SetStartTime(double t)
Set the time value for particle tracing to begin.
virtual void AssignSeedsToProcessors(double time, vtkDataSet *source, int sourceID, int ptId, vtkParticleTracerBaseNamespace::ParticleVector &localSeedPoints, int &localAssignedCount)
all the injection/seed points according to which processor they belong to.
vtkTypeBool IgnorePipelineTime
ProtoPD is used just to keep track of the input array names and number of components for copy allocat...
bool InsideBounds(double point[])
virtual bool IsPointDataValid(vtkDataObject *input)
Methods that check that the input arrays are ordered the same on all data sets.
int RequestInformation(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
vtkTemporalInterpolatedVelocityField * GetInterpolator()
void SetIntegratorType(int type)
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int FillInputPortInformation(int port, vtkInformation *info) override
Fill the input port information objects for this algorithm.
vtkIdType UniqueIdCounter
ProtoPD is used just to keep track of the input array names and number of components for copy allocat...
virtual void InitializeExtraPointDataArrays(vtkPointData *vtkNotUsed(outputPD))
Methods to append values to existing point data arrays that may only be desired on specific concrete ...
~vtkParticleTracerBase() override
void SetIntegrator(vtkInitialValueProblemSolver *)
bool ComputeDomainExitLocation(double pos[4], double p2[4], double intersection[4], vtkGenericCell *cell)
This is an old routine kept for possible future use.
virtual void ResetCache()
void ResizeArrays(vtkIdType numTuples)
void SetInterpolatorTypeToDataSetPointLocator()
Set the velocity field interpolator type to one that uses a point locator to perform local spatial se...
vtkSignedCharArray * GetParticleSourceIds(vtkPointData *)
virtual void AssignUniqueIds(vtkParticleTracerBaseNamespace::ParticleVector &localSeedPoints)
give each one a unique ID.
vtkSetFilePathMacro(ParticleFileName)
Set/Get the filename to be used with the particle writer when dumping particles to disk.
virtual int OutputParticles(vtkPolyData *poly)=0
vtkSmartPointer< vtkPolyData > Output
represent and manipulate point attribute data
represent and manipulate 3D points
Definition vtkPoints.h:139
Superclass for algorithms that produce only polydata as output.
concrete dataset represents vertices, lines, polygons, and triangle strips
dynamic, self-adjusting array of signed char
Hold a reference to a vtkObjectBase instance.
A helper class for interpolating between times during particle tracing.
record modification and/or execution time
ParticleVector::iterator ParticleIterator
std::list< ParticleInformation > ParticleDataList
ParticleDataList::iterator ParticleListIterator
std::vector< ParticleInformation > ParticleVector
int vtkTypeBool
Definition vtkABI.h:64
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
int vtkIdType
Definition vtkType.h:315