VTK
dox/Filters/FlowPaths/vtkTemporalStreamTracer.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkTemporalStreamTracer.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00026 #ifndef __vtkTemporalStreamTracer_h
00027 #define __vtkTemporalStreamTracer_h
00028 
00029 #include "vtkFiltersFlowPathsModule.h" // For export macro
00030 #include "vtkSmartPointer.h" // For protected ivars.
00031 #include "vtkStreamTracer.h"
00032 
00033 //BTX
00034 #include <vector> // STL Header
00035 #include <list>   // STL Header
00036 //ETX
00037 
00038 class vtkMultiProcessController;
00039 
00040 class vtkMultiBlockDataSet;
00041 class vtkDataArray;
00042 class vtkDoubleArray;
00043 class vtkGenericCell;
00044 class vtkIntArray;
00045 class vtkTemporalInterpolatedVelocityField;
00046 class vtkPoints;
00047 class vtkCellArray;
00048 class vtkDoubleArray;
00049 class vtkFloatArray;
00050 class vtkIntArray;
00051 class vtkCharArray;
00052 class vtkAbstractParticleWriter;
00053 
00054 //BTX
00055 namespace vtkTemporalStreamTracerNamespace
00056 {
00057   typedef struct { double x[4]; } Position;
00058   typedef struct {
00059     // These are used during iteration
00060     Position      CurrentPosition;
00061     int           CachedDataSetId[2];
00062     vtkIdType     CachedCellId[2];
00063     int           LocationState;
00064     // These are computed scalars we might display
00065     int           SourceID;
00066     int           TimeStepAge;
00067     int           InjectedPointId;
00068     int           InjectedStepId;
00069     int           UniqueParticleId;
00070     // These are useful to track for debugging etc
00071     int           ErrorCode;
00072     float         age;
00073     // these are needed across time steps to compute vorticity
00074     float         rotation;
00075     float         angularVel;
00076     float         time;
00077     float         speed;
00078   } ParticleInformation;
00079 
00080   typedef std::vector<ParticleInformation>  ParticleVector;
00081   typedef ParticleVector::iterator             ParticleIterator;
00082   typedef std::list<ParticleInformation>    ParticleDataList;
00083   typedef ParticleDataList::iterator           ParticleListIterator;
00084 };
00085 //ETX
00086 
00087 class VTKFILTERSFLOWPATHS_EXPORT vtkTemporalStreamTracer : public vtkStreamTracer
00088 {
00089 public:
00090 
00091     vtkTypeMacro(vtkTemporalStreamTracer,vtkStreamTracer);
00092     void PrintSelf(ostream& os, vtkIndent indent);
00093 
00095     static vtkTemporalStreamTracer *New();
00096 
00098 
00101     vtkSetMacro(TimeStep,unsigned int);
00102     vtkGetMacro(TimeStep,unsigned int);
00104 
00106 
00108     vtkSetMacro(IgnorePipelineTime, int);
00109     vtkGetMacro(IgnorePipelineTime, int);
00110     vtkBooleanMacro(IgnorePipelineTime, int);
00112 
00114 
00119     vtkSetMacro(TimeStepResolution,double);
00120     vtkGetMacro(TimeStepResolution,double);
00122 
00124 
00131     vtkSetMacro(ForceReinjectionEveryNSteps,int);
00132     vtkGetMacro(ForceReinjectionEveryNSteps,int);
00134 
00135 //BTX
00136   enum Units
00137   {
00138     TERMINATION_TIME_UNIT,
00139     TERMINATION_STEP_UNIT
00140   };
00141 //ETX
00142 
00144 
00148     vtkSetMacro(TerminationTime,double);
00149     vtkGetMacro(TerminationTime,double);
00151 
00153 
00155     vtkSetMacro(TerminationTimeUnit,int);
00156     vtkGetMacro(TerminationTimeUnit,int);
00157     void SetTerminationTimeUnitToTimeUnit()
00158     {this->SetTerminationTimeUnit(TERMINATION_TIME_UNIT);};
00159     void SetTerminationTimeUnitToStepUnit()
00160     {this->SetTerminationTimeUnit(TERMINATION_STEP_UNIT);};
00162 
00164 
00170     vtkSetMacro(StaticSeeds,int);
00171     vtkGetMacro(StaticSeeds,int);
00172     vtkBooleanMacro(StaticSeeds,int);
00174 
00176 
00181     vtkSetMacro(StaticMesh,int);
00182     vtkGetMacro(StaticMesh,int);
00183     vtkBooleanMacro(StaticMesh,int);
00185 
00187 
00191     virtual void SetParticleWriter(vtkAbstractParticleWriter *pw);
00192     vtkGetObjectMacro(ParticleWriter, vtkAbstractParticleWriter);
00194 
00196 
00198     vtkSetStringMacro(ParticleFileName);
00199     vtkGetStringMacro(ParticleFileName);
00201 
00203 
00205     vtkSetMacro(EnableParticleWriting,int);
00206     vtkGetMacro(EnableParticleWriting,int);
00207     vtkBooleanMacro(EnableParticleWriting,int);
00209 
00211 
00212     void AddSourceConnection(vtkAlgorithmOutput* input);
00213     void RemoveAllSources();
00215 
00216   protected:
00217 
00218      vtkTemporalStreamTracer();
00219     ~vtkTemporalStreamTracer();
00220 
00221     //
00222     // Make sure the pipeline knows what type we expect as input
00223     //
00224     virtual int FillInputPortInformation(int port, vtkInformation* info);
00225 
00226     //
00227     // The usual suspects
00228     //
00229     virtual int ProcessRequest(vtkInformation* request,
00230                                vtkInformationVector** inputVector,
00231                                vtkInformationVector* outputVector);
00232 
00233     //
00234     // Store any information we need in the output and fetch what we can
00235     // from the input
00236     //
00237     virtual int RequestInformation(vtkInformation* request,
00238                                   vtkInformationVector** inputVector,
00239                                   vtkInformationVector* outputVector);
00240 
00241     //
00242     // Compute input time steps given the output step
00243     //
00244     virtual int RequestUpdateExtent(vtkInformation* request,
00245                                     vtkInformationVector** inputVector,
00246                                     vtkInformationVector* outputVector);
00247 
00248     //
00249     // what the pipeline calls for each time step
00250     //
00251     virtual int RequestData(vtkInformation* request,
00252                             vtkInformationVector** inputVector,
00253                             vtkInformationVector* outputVector);
00254 
00255     //
00256     // these routines are internally called to actually generate the output
00257     //
00258     virtual int ProcessInput(vtkInformationVector** inputVector);
00259 
00260     virtual int GenerateOutput(vtkInformationVector** inputVector,
00261                                vtkInformationVector* outputVector);
00262 
00263     //
00264     // Initialization of input (vector-field) geometry
00265     //
00266     int InitializeInterpolator();
00267     int SetTemporalInput(vtkDataObject *td, int index);
00268 
00269 //BTX
00270 //
00271 
00273 
00275     void TestParticles(
00276       vtkTemporalStreamTracerNamespace::ParticleVector &candidates,
00277       vtkTemporalStreamTracerNamespace::ParticleVector &passed,
00278       int &count);
00280 
00282 
00286     virtual void AssignSeedsToProcessors(
00287       vtkDataSet *source, int sourceID, int ptId,
00288       vtkTemporalStreamTracerNamespace::ParticleVector &LocalSeedPoints,
00289       int &LocalAssignedCount);
00291 
00293 
00295     virtual void AssignUniqueIds(
00296       vtkTemporalStreamTracerNamespace::ParticleVector &LocalSeedPoints);
00298 
00300 
00302     void UpdateParticleList(
00303       vtkTemporalStreamTracerNamespace::ParticleVector &candidates);
00305 
00307 
00310     virtual void TransmitReceiveParticles(
00311       vtkTemporalStreamTracerNamespace::ParticleVector &outofdomain,
00312       vtkTemporalStreamTracerNamespace::ParticleVector &received,
00313       bool removeself);
00315 
00317 
00318     void IntegrateParticle(
00319       vtkTemporalStreamTracerNamespace::ParticleListIterator &it,
00320       double currenttime, double terminationtime,
00321       vtkInitialValueProblemSolver* integrator);
00323 
00325 
00330     bool RetryWithPush(
00331       vtkTemporalStreamTracerNamespace::ParticleInformation &info,
00332       double velocity[3], double delT);
00334 
00335     // if the particle is added to send list, then returns value is 1,
00336     // if it is kept on this process after a retry return value is 0
00337     bool SendParticleToAnotherProcess(
00338       vtkTemporalStreamTracerNamespace::ParticleInformation &info,
00339       double point1[4], double delT);
00340 
00341     void AddParticleToMPISendList(
00342       vtkTemporalStreamTracerNamespace::ParticleInformation &info);
00343 
00345 
00348     bool ComputeDomainExitLocation(
00349       double pos[4], double p2[4], double intersection[4],
00350       vtkGenericCell *cell);
00352 
00353 //
00354 //ETX
00355 //
00356     //Track internally which round of RequestData it is--between 0 and 2
00357     int           RequestIndex;
00358 
00359     // Track which process we are
00360     int           UpdatePiece;
00361     int           UpdateNumPieces;
00362 
00363     // Important for Caching of Cells/Ids/Weights etc
00364     int           AllFixedGeometry;
00365     int           StaticMesh;
00366     int           StaticSeeds;
00367 
00368     // Support 'pipeline' time or manual SetTimeStep
00369     unsigned int  TimeStep;
00370     unsigned int  ActualTimeStep;
00371     int           IgnorePipelineTime;
00372     unsigned int  NumberOfInputTimeSteps;
00373 //BTX
00374     std::vector<double>  InputTimeValues;
00375     std::vector<double>  OutputTimeValues;
00376 //ETX
00377 
00378     // more time management
00379     double        EarliestTime;
00380     double        CurrentTimeSteps[2];
00381     double        TimeStepResolution;
00382 
00383     // Particle termination after time
00384     double        TerminationTime;
00385     int           TerminationTimeUnit;
00386 
00387     // Particle injection+Reinjection
00388     int           ForceReinjectionEveryNSteps;
00389     bool          ReinjectionFlag;
00390     int           ReinjectionCounter;
00391     vtkTimeStamp  ParticleInjectionTime;
00392 
00393     // Particle writing to disk
00394     vtkAbstractParticleWriter *ParticleWriter;
00395     char                      *ParticleFileName;
00396     int                        EnableParticleWriting;
00397 
00398 //BTX
00399     // The main lists which are held during operation- between time step updates
00400     unsigned int                                        NumberOfParticles;
00401     vtkTemporalStreamTracerNamespace::ParticleDataList  ParticleHistories;
00402     vtkTemporalStreamTracerNamespace::ParticleVector    LocalSeeds;
00403 //ETX
00404 
00405 //BTX
00406     //
00407     // Scalar arrays that are generated as each particle is updated
00408     //
00409     vtkSmartPointer<vtkFloatArray>    ParticleAge;
00410     vtkSmartPointer<vtkIntArray>      ParticleIds;
00411     vtkSmartPointer<vtkCharArray>     ParticleSourceIds;
00412     vtkSmartPointer<vtkIntArray>      InjectedPointIds;
00413     vtkSmartPointer<vtkIntArray>      InjectedStepIds;
00414     vtkSmartPointer<vtkIntArray>      ErrorCode;
00415     vtkSmartPointer<vtkFloatArray>    ParticleVorticity;
00416     vtkSmartPointer<vtkFloatArray>    ParticleRotation;
00417     vtkSmartPointer<vtkFloatArray>    ParticleAngularVel;
00418     vtkSmartPointer<vtkDoubleArray>   cellVectors;
00419     vtkSmartPointer<vtkPointData>     OutputPointData;
00420     int                               InterpolationCount;
00421 
00422     // The output geometry
00423     vtkSmartPointer<vtkCellArray>     ParticleCells;
00424     vtkSmartPointer<vtkPoints>        OutputCoordinates;
00425 
00426     // List used for transmitting between processors during parallel operation
00427     vtkTemporalStreamTracerNamespace::ParticleVector MPISendList;
00428 
00429     // The velocity interpolator
00430     vtkSmartPointer<vtkTemporalInterpolatedVelocityField>  Interpolator;
00431 
00432     // The input datasets which are stored by time step 0 and 1
00433     vtkSmartPointer<vtkMultiBlockDataSet> InputDataT[2];
00434     vtkSmartPointer<vtkDataSet>           DataReferenceT[2];
00435 
00436     // Cache bounds info for each dataset we will use repeatedly
00437     typedef struct {
00438       double b[6];
00439     } bounds;
00440     std::vector<bounds> CachedBounds[2];
00441 
00442     // utility function we use to test if a point is inside any of our local datasets
00443     bool InsideBounds(double point[]);
00444 
00445 //ETX
00446 
00447   // global Id counter used to give particles a stamp
00448   vtkIdType UniqueIdCounter;
00449   vtkIdType UniqueIdCounterMPI;
00450   // for debugging only;
00451   int substeps;
00452 
00453 private:
00455   void SetInterpolatorPrototype(vtkAbstractInterpolatedVelocityField*) {}
00456 
00457 private:
00458   vtkTemporalStreamTracer(const vtkTemporalStreamTracer&);  // Not implemented.
00459   void operator=(const vtkTemporalStreamTracer&);  // Not implemented.
00460 };
00461 
00462 #endif