VTK  9.5.20250629
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#include "vtkTemporalAlgorithm.h" // For vtkTemporalAlgorithm
23#include "vtkWeakPointer.h" // For vtkWeakPointer
24
25#include <list> // STL Header
26#include <mutex> // STL Header
27#include <numeric> // STL Header
28#include <unordered_map> // STL Header
29#include <vector> // STL Header
30
31#ifndef __VTK_WRAP__
32#define vtkPolyDataAlgorithm vtkTemporalAlgorithm<vtkPolyDataAlgorithm>
33#endif
34
35VTK_ABI_NAMESPACE_BEGIN
38class vtkDataArray;
39class vtkDataSet;
40class vtkDoubleArray;
41class vtkFloatArray;
42class vtkGenericCell;
44class vtkIntArray;
48class vtkPointData;
49class vtkPoints;
50class vtkPolyData;
53VTK_ABI_NAMESPACE_END
54
56{
57VTK_ABI_NAMESPACE_BEGIN
59{
60 double x[4];
61};
62using Position = struct Position_t;
63
65{
66 // These are used during iteration
71 // These are computed scalars we might display
73 int TimeStepAge; // amount of time steps the particle has advanced
75 int InjectedStepId; // time step the particle was injected
77 // These are useful to track for debugging etc
79 float age;
80 // these are needed across time steps to compute vorticity
81 float rotation;
83 float time;
84 float speed;
85 // once the particle is added, PointId is valid and is the tuple location
86 // in ProtoPD.
88
89 double velocity[3];
90};
92
93typedef std::vector<ParticleInformation> ParticleVector;
94typedef ParticleVector::iterator ParticleIterator;
95typedef std::list<ParticleInformation> ParticleDataList;
96typedef ParticleDataList::iterator ParticleListIterator;
97struct ParticleTracerFunctor;
98VTK_ABI_NAMESPACE_END
99}
100
101VTK_ABI_NAMESPACE_BEGIN
102class VTKFILTERSFLOWPATHS_EXPORT vtkParticleTracerBase : public vtkPolyDataAlgorithm
103{
104public:
105 friend struct vtkParticleTracerBaseNamespace::ParticleTracerFunctor;
107 {
112 UNKNOWN
113 };
114
117
118#ifndef __VTK_WRAP__
119#undef vtkPolyDataAlgorithm
120#endif
122 void PrintSelf(ostream& os, vtkIndent indent) override;
124
125#if defined(__VTK_WRAP__) || defined(__WRAP_GCCXML)
127#endif
128
130
137
139
144 vtkGetMacro(ComputeVorticity, bool);
147
149
152 vtkGetMacro(TerminalSpeed, double);
153 void SetTerminalSpeed(double);
155
157
161 vtkGetMacro(RotationScale, double);
162 void SetRotationScale(double);
164
166
170 vtkSetMacro(IgnorePipelineTime, vtkTypeBool);
171 vtkGetMacro(IgnorePipelineTime, vtkTypeBool);
172 vtkBooleanMacro(IgnorePipelineTime, vtkTypeBool);
174
176
185 vtkGetMacro(ForceReinjectionEveryNSteps, int);
188
190 vtkGetObjectMacro(Integrator, vtkInitialValueProblemSolver);
191
192 void SetIntegratorType(int type);
194
196
205 vtkSetMacro(StaticSeeds, vtkTypeBool);
206 vtkGetMacro(StaticSeeds, vtkTypeBool);
208
213 {
214 DIFFERENT = 0,
215 STATIC = 1,
216 LINEAR_TRANSFORMATION = 2,
217 SAME_TOPOLOGY = 3
218 };
219
221 /*
222 * Set/Get the type of variance of the mesh over time.
223 *
224 * DIFFERENT = 0,
225 * STATIC = 1,
226 * LINEAR_TRANSFORMATION = 2
227 * SAME_TOPOLOGY = 3
228 */
229 virtual void SetMeshOverTime(int meshOverTime);
230 virtual int GetMeshOverTimeMinValue() { return DIFFERENT; }
231 virtual int GetMeshOverTimeMaxValue() { return SAME_TOPOLOGY; }
232 void SetMeshOverTimeToDifferent() { this->SetMeshOverTime(DIFFERENT); }
233 void SetMeshOverTimeToStatic() { this->SetMeshOverTime(STATIC); }
234 void SetMeshOverTimeToLinearTransformation() { this->SetMeshOverTime(LINEAR_TRANSFORMATION); }
235 void SetMeshOverTimeToSameTopology() { this->SetMeshOverTime(SAME_TOPOLOGY); }
236 vtkGetMacro(MeshOverTime, int);
238
239 enum
240 {
242 INTERPOLATOR_WITH_CELL_LOCATOR
243 };
244
256 void SetInterpolatorType(int interpolatorType);
257
266
274
276
283 vtkGetObjectMacro(ParticleWriter, vtkAbstractParticleWriter);
285
287
291 vtkSetFilePathMacro(ParticleFileName);
292 vtkGetFilePathMacro(ParticleFileName);
294
296
300 vtkSetMacro(EnableParticleWriting, vtkTypeBool);
301 vtkGetMacro(EnableParticleWriting, vtkTypeBool);
302 vtkBooleanMacro(EnableParticleWriting, vtkTypeBool);
304
306
312
314
318 vtkGetMacro(ForceSerialExecution, bool);
319 vtkSetMacro(ForceSerialExecution, bool);
320 vtkBooleanMacro(ForceSerialExecution, bool);
322protected:
324
330 vtkTypeBool IgnorePipelineTime; // whether to use the pipeline time for termination
332
333 // Control execution as serial or threaded
335
337
340
341 //
342 // Make sure the pipeline knows what type we expect as input
343 //
344 int FillInputPortInformation(int port, vtkInformation* info) override;
345
349 int Initialize(vtkInformation* request, vtkInformationVector** inputVector,
350 vtkInformationVector* outputVector) override;
351
359 int Execute(vtkInformation* request, vtkInformationVector** inputVector,
360 vtkInformationVector* outputVector) override;
361
366
371 virtual std::vector<vtkDataSet*> GetSeedSources(vtkInformationVector* inputVector);
372
373 // Initialization of input (vector-field) geometry
375
381
388
390 vtkParticleTracerBaseNamespace::ParticleVector& candidates, std::vector<int>& passed);
391
398 virtual void AssignSeedsToProcessors(double time, vtkDataSet* source,
400
406 bool SendReceiveParticles(std::vector<vtkIdType>&);
407
413
420
425 double currentTime, double targetTime, vtkInitialValueProblemSolver* integrator,
426 vtkTemporalInterpolatedVelocityField* interpolator, vtkDoubleArray* cellVectors,
427 std::atomic<vtkIdType>& particleCount, std::mutex& eraseMutex, bool sequential);
428
436 double pos[4], double p2[4], double intersection[4], vtkGenericCell* cell);
437
438 //
439 // Scalar arrays that are generated as each particle is updated
440 //
442
452
453 // utility function we use to test if a point is inside any of our local datasets
454 bool InsideBounds(double point[]);
455
457 vtkGenericCell* cell, double pcoords[3], vtkDoubleArray* cellVectors, double vorticity[3]);
458
459 //------------------------------------------------------
460
462 vtkTemporalInterpolatedVelocityField* interpolator, vtkDoubleArray* cellVectors);
463
464 std::unordered_map<vtkIdType, int> InjectedPointIdToProcessId;
465
467
472 virtual bool IsPointDataValid(vtkDataObject* input);
473 bool IsPointDataValid(vtkCompositeDataSet* input, std::vector<std::string>& arrayNames);
474 void GetPointDataArrayNames(vtkDataSet* input, std::vector<std::string>& names);
476
477 vtkGetMacro(ReinjectionCounter, int);
478
479 void ResizeArrays(vtkIdType numTuples);
480
485 virtual void InitializeExtraPointDataArrays(vtkPointData* vtkNotUsed(outputPD)) {}
486
489 {
490 }
491
493
498 virtual void AddRestartSeeds(vtkInformationVector** /*inputVector*/) {}
499
510 double delT, int subSteps, vtkTemporalInterpolatedVelocityField* interpolator);
511
513
515
516 // Parameters of tracing
523
524 // A counter to keep track of how many times we reinjected
526
527 // Important for Caching of Cells/Ids/Weights etc
531
532 // Innjection parameters
536
537 // Particle writing to disk
541
543
544 // The velocity interpolator
546
547 // MPI controller needed when running in parallel
549
555
563 std::unordered_map<vtkIdType, vtkParticleTracerBaseNamespace::ParticleInformation> MPIRecvList;
564
565 // Cache bounds info for each dataset we will use repeatedly
566 struct bounds_t
567 {
568 double b[6];
569 };
570 using bounds = struct bounds_t;
571 std::vector<bounds> CachedBounds[2];
572
573 // variables used by Execute() to produce output
574
576
579
590
591 // temp array
593
595 void operator=(const vtkParticleTracerBase&) = delete;
597
598 unsigned int NumberOfParticles();
599
600 friend class ParticlePathFilterInternal;
601 friend class StreaklineFilterInternal;
602
603 static const double Epsilon;
604
605private:
606 // Internal method to initialize CachedData[1] using the provided input
607 void InitializeNextCachedData(vtkDataObject* input);
608
609 // Data for time step CurrentTimeStep-1 and CurrentTimeStep
611};
612
613VTK_ABI_NAMESPACE_END
614#endif
abstract class to write particle data to file
Proxy object to connect input/output ports.
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:165
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.
Allocate and hold a VTK object.
Definition vtkNew.h:167
A particle tracer for vector fields.
vtkFloatArray * GetParticleVorticity(vtkPointData *)
vtkInitialValueProblemSolver * Integrator
vtkSmartPointer< vtkPointData > ProtoPD
ProtoPD is used just to keep track of the input array names and number of components for copy allocat...
vtkNew< vtkPoints > OutputCoordinates
vtkNew< vtkPointData > OutputPointData
void SetComputeVorticity(bool)
Turn on/off vorticity computation at streamline points (necessary for generating proper stream-ribbon...
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...
vtkNew< vtkFloatArray > ParticleRotation
vtkNew< vtkDoubleArray > CellVectors
vtkNew< vtkIdTypeArray > ParticleCellsConnectivity
vtkIntArray * GetInjectedStepIds(vtkPointData *)
virtual bool UpdateParticleListFromOtherProcesses()
this is used during classification of seed points and also between iterations of the main loop as par...
vtkIntArray * GetErrorCodeArr(vtkPointData *)
bool RetryWithPush(vtkParticleTracerBaseNamespace::ParticleInformation &info, double *point1, double delT, int subSteps, vtkTemporalInterpolatedVelocityField *interpolator)
When particles leave the domain, they must be collected and sent to the other processes for possible ...
vtkSmartPointer< vtkTemporalInterpolatedVelocityField > Interpolator
int Initialize(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
Resets internal cache for a clean start.
vtkNew< vtkIdTypeArray > InjectedPointIds
void operator=(const vtkParticleTracerBase &)=delete
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 *)
bool SendReceiveParticles(std::vector< vtkIdType > &)
this is used during classification of seed points and also between iterations of the main loop as par...
std::unordered_map< vtkIdType, int > InjectedPointIdToProcessId
void AddSourceConnection(vtkAlgorithmOutput *input)
Provide support for multiple seed sources.
vtkNew< vtkIntArray > ErrorCodeArray
void RemoveAllSources()
Provide support for multiple seed sources.
void CalculateVorticity(vtkGenericCell *cell, double pcoords[3], vtkDoubleArray *cellVectors, double vorticity[3])
void CreateProtoPD(vtkDataObject *input)
std::unordered_map< vtkIdType, vtkParticleTracerBaseNamespace::ParticleInformation > MPIRecvList
Storage of the particles we received.
virtual void SetController(vtkMultiProcessController *)
Get/Set the controller to use.
vtkIntArray * GetParticleIds(vtkPointData *)
vtkNew< vtkIntArray > InjectedStepIds
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.
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...
virtual std::vector< vtkDataSet * > GetSeedSources(vtkInformationVector *inputVector)
Method to get the data set seed sources.
void SetRotationScale(double)
This can be used to scale the rate with which the streamribbons twist.
vtkParticleTracerBaseNamespace::ParticleVector MPISendList
Storage of the particles we want to send to another rank.
vtkParticleTracerBaseNamespace::ParticleDataList ParticleHistories
ProtoPD is used just to keep track of the input array names and number of components for copy allocat...
vtkParticleTracerBase(const vtkParticleTracerBase &)=delete
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.
vtkNew< vtkFloatArray > ParticleVorticity
virtual void InitializeExtraPointDataArrays(vtkPointData *outputPD)
Methods to append values to existing point data arrays that may only be desired on specific concrete ...
void SetInterpolatorType(int interpolatorType)
Set the type of the velocity field interpolator to determine whether INTERPOLATOR_WITH_DATASET_POINT_...
virtual void SetMeshOverTime(int meshOverTime)
bool SetTerminationTimeNoModify(double t)
int Finalize(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
Generates an output using the data provided after Execute was ran.
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[])
void TestParticles(vtkParticleTracerBaseNamespace::ParticleVector &candidates, vtkParticleTracerBaseNamespace::ParticleVector &passed)
inside our data.
virtual bool IsPointDataValid(vtkDataObject *input)
Methods that check that the input arrays are ordered the same on all data sets.
vtkTemporalInterpolatedVelocityField * GetInterpolator()
void SetIntegratorType(int type)
vtkNew< vtkIntArray > ParticleIds
vtkParticleTracerBaseNamespace::ParticleVector LocalSeeds
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.
unsigned int NumberOfParticles()
vtkNew< vtkSignedCharArray > ParticleSourceIds
void SetParticle(vtkParticleTracerBaseNamespace::ParticleInformation &info, vtkTemporalInterpolatedVelocityField *interpolator, vtkDoubleArray *cellVectors)
void EnqueueParticleToAnotherProcess(vtkParticleTracerBaseNamespace::ParticleInformation &)
vtkNew< vtkFloatArray > ParticleAngularVel
~vtkParticleTracerBase() override
static const double Epsilon
virtual void AssignSeedsToProcessors(double time, vtkDataSet *source, vtkParticleTracerBaseNamespace::ParticleVector &localSeedPoints)
all the injection/seed points according to which processor they belong to.
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.
void ResizeArrays(vtkIdType numTuples)
vtkNew< vtkFloatArray > ParticleAge
void SetInterpolatorTypeToDataSetPointLocator()
Set the velocity field interpolator type to one that uses a point locator to perform local spatial se...
vtkSmartPointer< vtkMultiProcessController > Controller
vtkSignedCharArray * GetParticleSourceIds(vtkPointData *)
vtkSetFilePathMacro(ParticleFileName)
Set/Get the filename to be used with the particle writer when dumping particles to disk.
virtual vtkMultiProcessController * GetController()
Get/Set the controller to use.
vtkAbstractParticleWriter * ParticleWriter
vtkSmartPointer< vtkDataSet > Seeds
All ranks have the same representation of the seeds.
int Execute(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
Moves the particles one time step further.
composite dataset to encapsulates a dataset consisting of partitions.
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 *)
#define vtkCreateWrappedTemporalAlgorithmInterface()
int vtkIdType
Definition vtkType.h:332