VAPOR3 3.9.4
Advection.h
Go to the documentation of this file.
1/*
2 * This class performances advection calculations.
3 * It also holds all the particles resulting from an advection.
4 */
5
6#ifndef ADVECTION_H
7#define ADVECTION_H
8
9#include "vapor/Particle.h"
10#include "vapor/Field.h"
11#include "vapor/common.h"
12#include <string>
13#include <vector>
14
15namespace flow {
16class FLOW_API Advection final {
17public:
18 enum class ADVECTION_METHOD {
19 EULER = 0,
20 RK4 = 1 // Runge-Kutta 4th order
21 };
22
23 // Constructor and destructor
25
26 //
27 // Major action functions
28 //
29 // Advect all particles as long as they are within spatial and temporal boundary
30 // for a specified number if steps.
31 int AdvectSteps(Field *velocityField, double deltaT, size_t maxSteps, bool fixedStepSize, ADVECTION_METHOD method = ADVECTION_METHOD::RK4);
32 // Advect as many steps as necessary to reach a certain time: targetT.
33 // Note: it only considers particles that have already passed startT.
34 int AdvectTillTime(Field *velocityField, double startT, double deltaT, double targetT, bool fixedStepSize, ADVECTION_METHOD method = ADVECTION_METHOD::RK4);
35
36 // Retrieve field values of a particle based on its location, and put the result in
37 // the "value" field or the "properties" field of a particle
38 // If "skipNonZero" is true, then this function only overwrites zeros.
39 // Otherwise, it will overwrite values anyway.
40 int CalculateParticleValues(Field *scalarField, bool skipNonZero);
41 int CalculateParticleIntegratedValues(Field *scalarField, const bool skipNonZero, const float distScale = 1.f, const std::vector<double> &integrateWithinVolumeMin = {-FLT_MAX, -FLT_MAX, -FLT_MAX},
42 const std::vector<double> &integrateWithinVolumeMax = {FLT_MAX, FLT_MAX, FLT_MAX});
43 void SetAllStreamValuesToFinalValue(int realNSamples);
45
46 void CalculateParticleHistogram(std::vector<double> &bounds, std::vector<long> &bins);
47
48 // Reset all particle values to zero
50 // Clear all existing properties of a particle
52 // Clear particle property with a certain name.
53 // If the the specified property name does not exist, then nothing is done.
54 void RemoveParticleProperty(const std::string &);
55
56 // Set advection basics
57 void UseSeedParticles(const std::vector<Particle> &seeds);
58
59 // Retrieve the resulting particles as "streams."
60 size_t GetNumberOfStreams() const;
61 const std::vector<Particle> &GetStreamAt(size_t i) const;
62
63 // Retrieve the maximum number of particles in any stream
64 size_t GetMaxNumOfPart() const;
65
66 // Query properties (most are properties of the velocity field)
67 int CheckReady() const;
68
69 // Specify periodicity, and periodic bounds on each dimension
70 void SetXPeriodicity(bool, float min, float max);
71 void SetYPeriodicity(bool, float min, float max);
72 void SetZPeriodicity(bool, float min, float max);
73
74 // Retrieve the names of value variable and property variables.
75 auto GetValueVarName() const -> std::string;
76 auto GetPropertyVarNames() const -> std::vector<std::string>;
77
78private:
79 std::vector<std::vector<Particle>> _streams;
80 std::string _valueVarName;
81 std::vector<std::string> _propertyVarNames;
82
83 const float _lowerAngle, _upperAngle; // Thresholds for step size adjustment
84 float _lowerAngleCos, _upperAngleCos; // Cosine values of the threshold angles
85 std::vector<int> _separatorCount; // how many separators does each stream have.
86 // Useful to determine how many steps are there in a stream.
87 // If the advection is performed in a periodic fashion along one or more dimensions.
88 // These variables are **not** intended to be decided by Advection, but by someone
89 // who's more knowledgeable about the field.
90 std::array<bool, 3> _isPeriodic; // is it periodic in X, Y, Z dimensions?
91 std::array<glm::vec2, 3> _periodicBounds; // periodic boundaries in X, Y, Z dimensions
92
93 // Advection methods here could assume all input is valid.
94 int _advectEuler(Field *, const Particle &, double deltaT, // Input
95 Particle &p1) const; // Output
96 int _advectRK4(Field *, const Particle &, double deltaT, // Input
97 Particle &p1) const; // Output
98
99 // Get an adjust factor for deltaT based on how curvy the past two steps are.
100 // A value in range (0.0, 1.0) means shrink deltaT.
101 // A value in range (1.0, inf) means enlarge deltaT.
102 // A value equals to 1.0 means not touching deltaT.
103 float _calcAdjustFactor(const Particle &past2, const Particle &past1, const Particle &current) const;
104
105 // Adjust input "val" according to the bound specified by min and max.
106 // Returns the value after adjustment.
107 float _applyPeriodic(float val, float min, float max) const;
108
109 // Print return code if it's non-zero and compiled in debug mode.
110 void _printNonZero(int rtn, const char *file, const char *func, int line) const;
111
112 void _calculateParticleIntegratedValue(Particle &p, const Particle &prev, const Field *scalarField, const bool skipNonZero, const float distScale,
113 const std::vector<double> &integrateWithinVolumeMin, const std::vector<double> &integrateWithinVolumeMax) const;
114 static bool _isParticleInsideVolume(const Particle &p, const std::vector<double> &min, const std::vector<double> &max);
115};
116}; // namespace flow
117
118#endif
size_t GetNumberOfStreams() const
int AdvectSteps(Field *velocityField, double deltaT, size_t maxSteps, bool fixedStepSize, ADVECTION_METHOD method=ADVECTION_METHOD::RK4)
void UseSeedParticles(const std::vector< Particle > &seeds)
void SetXPeriodicity(bool, float min, float max)
void SetAllStreamValuesToFinalValue(int realNSamples)
int CalculateParticleValues(Field *scalarField, bool skipNonZero)
void ResetParticleValues()
void SetYPeriodicity(bool, float min, float max)
void CalculateParticleHistogram(std::vector< double > &bounds, std::vector< long > &bins)
auto GetValueVarName() const -> std::string
const std::vector< Particle > & GetStreamAt(size_t i) const
size_t GetMaxNumOfPart() const
int CalculateParticleIntegratedValues(Field *scalarField, const bool skipNonZero, const float distScale=1.f, const std::vector< double > &integrateWithinVolumeMin={-FLT_MAX, -FLT_MAX, -FLT_MAX}, const std::vector< double > &integrateWithinVolumeMax={FLT_MAX, FLT_MAX, FLT_MAX})
void ClearParticleProperties()
int CheckReady() const
void RemoveParticleProperty(const std::string &)
void SetZPeriodicity(bool, float min, float max)
int CalculateParticleProperties(Field *scalarField)
int AdvectTillTime(Field *velocityField, double startT, double deltaT, double targetT, bool fixedStepSize, ADVECTION_METHOD method=ADVECTION_METHOD::RK4)
#define FLOW_API
Definition: common.h:75
Definition: Advection.h:15