VTK
dox/Parallel/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 "vtkSmartPointer.h" // For protected ivars.
00030 #include "vtkStreamTracer.h"
00031 
00032 //BTX
00033 #include <vector> // STL Header
00034 #include <list>   // STL Header
00035 //ETX
00036 
00037 class vtkMultiProcessController;
00038 
00039 class vtkMultiBlockDataSet;
00040 class vtkDataArray;
00041 class vtkDoubleArray;
00042 class vtkGenericCell;
00043 class vtkIntArray;
00044 class vtkTemporalInterpolatedVelocityField;
00045 class vtkPoints;
00046 class vtkCellArray;
00047 class vtkDoubleArray;
00048 class vtkFloatArray;
00049 class vtkIntArray;
00050 class vtkCharArray;
00051 class vtkAbstractParticleWriter;
00052 class vtkTemporalDataSet;
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 VTK_PARALLEL_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 SetController(vtkMultiProcessController* controller);
00192     vtkGetObjectMacro(Controller, vtkMultiProcessController);
00194 
00196 
00200     virtual void SetParticleWriter(vtkAbstractParticleWriter *pw);
00201     vtkGetObjectMacro(ParticleWriter, vtkAbstractParticleWriter);
00203 
00205 
00207     vtkSetStringMacro(ParticleFileName);
00208     vtkGetStringMacro(ParticleFileName);
00210 
00212 
00214     vtkSetMacro(EnableParticleWriting,int);
00215     vtkGetMacro(EnableParticleWriting,int);
00216     vtkBooleanMacro(EnableParticleWriting,int);
00218     
00220 
00221     void AddSourceConnection(vtkAlgorithmOutput* input);
00222     void RemoveAllSources();
00224 
00225   protected:
00226 
00227      vtkTemporalStreamTracer();
00228     ~vtkTemporalStreamTracer();
00229 
00230     //
00231     // Make sure the pipeline knows what type we expect as input
00232     //
00233     virtual int FillInputPortInformation(int port, vtkInformation* info);
00234 
00235     //
00236     // The usual suspects
00237     //
00238     virtual int ProcessRequest(vtkInformation* request,
00239                                vtkInformationVector** inputVector,
00240                                vtkInformationVector* outputVector);
00241 
00242     //
00243     // Store any information we need in the output and fetch what we can
00244     // from the input
00245     //
00246     virtual int RequestInformation(vtkInformation* request,
00247                                   vtkInformationVector** inputVector,
00248                                   vtkInformationVector* outputVector);
00249 
00250     //
00251     // Compute input time steps given the output step
00252     //
00253     virtual int RequestUpdateExtent(vtkInformation* request,
00254                                     vtkInformationVector** inputVector,
00255                                     vtkInformationVector* outputVector);
00256 
00257     //
00258     // Generate output
00259     //
00260     virtual int RequestData(vtkInformation* request,
00261                             vtkInformationVector** inputVector,
00262                             vtkInformationVector* outputVector);
00263 
00264     //
00265     // Initialization of input (vector-field) geometry
00266     // 
00267     int InitializeInterpolator();
00268     int AddTemporalInput(vtkTemporalDataSet *td);
00269 
00270 //
00271 //BTX
00272 //
00273 
00275 
00277     void TestParticles(
00278       vtkTemporalStreamTracerNamespace::ParticleVector &candidates, 
00279       vtkTemporalStreamTracerNamespace::ParticleVector &passed,
00280       int &count);
00282 
00284 
00288     void AssignSeedsToProcessors(
00289       vtkDataSet *source, int sourceID, int ptId, 
00290       vtkTemporalStreamTracerNamespace::ParticleVector &LocalSeedPoints, 
00291       int &LocalAssignedCount);
00293 
00295 
00297     void AssignUniqueIds(
00298       vtkTemporalStreamTracerNamespace::ParticleVector &LocalSeedPoints);
00300 
00302 
00304     void UpdateParticleList(
00305       vtkTemporalStreamTracerNamespace::ParticleVector &candidates);
00307 
00309 
00312     void TransmitReceiveParticles(
00313       vtkTemporalStreamTracerNamespace::ParticleVector &outofdomain, 
00314       vtkTemporalStreamTracerNamespace::ParticleVector &received, 
00315       bool removeself);
00317 
00319 
00320     void IntegrateParticle(
00321       vtkTemporalStreamTracerNamespace::ParticleListIterator &it, 
00322       double currenttime, double terminationtime,
00323       vtkInitialValueProblemSolver* integrator);
00325 
00327 
00332     bool RetryWithPush(
00333       vtkTemporalStreamTracerNamespace::ParticleInformation &info, 
00334       double velocity[3], double delT);
00336 
00337     // if the particle is added to send list, then returns value is 1, 
00338     // if it is kept on this process after a retry return value is 0
00339     bool SendParticleToAnotherProcess(
00340       vtkTemporalStreamTracerNamespace::ParticleInformation &info, 
00341       double point1[4], double delT);
00342 
00343     void AddParticleToMPISendList(
00344       vtkTemporalStreamTracerNamespace::ParticleInformation &info);
00345 
00347 
00350     bool ComputeDomainExitLocation(
00351       double pos[4], double p2[4], double intersection[4],
00352       vtkGenericCell *cell);
00354 
00355 //
00356 //ETX
00357 //
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 funtion we use to test if a point is inside any of our local datasets
00443     bool InsideBounds(double point[]);
00444 
00445 //ETX
00446 
00447   // MPI controller needed when running in parallel
00448   vtkMultiProcessController* Controller;
00449 
00450   // global Id counter used to give particles a stamp
00451   vtkIdType UniqueIdCounter;
00452   vtkIdType UniqueIdCounterMPI;
00453   // for debugging only;
00454   int substeps;
00455 
00456 private:
00458   void SetInterpolatorPrototype(vtkAbstractInterpolatedVelocityField*) {};
00459 
00460 private:
00461   vtkTemporalStreamTracer(const vtkTemporalStreamTracer&);  // Not implemented.
00462   void operator=(const vtkTemporalStreamTracer&);  // Not implemented.
00463 };
00464 
00465 
00466 #endif
00467 
00468