VAPOR3 3.9.4
VaporField.h
Go to the documentation of this file.
1#ifndef VAPORFIELD_H
2#define VAPORFIELD_H
3
4#include "vapor/Field.h"
5#include "vapor/Particle.h"
6#include "vapor/DataMgr.h"
7#include "vapor/FlowParams.h"
8#include "vapor/Grid.h"
9#include "vapor/ptr_cache.hpp"
10
11namespace flow {
12
13//
14// Helper class: it is used to identify a specific grid.
15//
17private:
18 uint32_t _timestep = std::numeric_limits<uint32_t>::max(); // almost impossible value
19 int32_t _refLev = -2; // Impossible value
20 int32_t _compLev = -2; // Impossible value
21 std::string _varName;
22 VAPoR::CoordType _ext_min = {0.0, 0.0, 0.0};
23 VAPoR::CoordType _ext_max = {0.0, 0.0, 0.0};
24
25public:
26 void Reset(uint32_t, int32_t, int32_t, std::string, VAPoR::CoordType, VAPoR::CoordType);
27
28 bool emptyVar() const;
29
30 // == operator to be used in the cache
31 bool operator==(const GridKey &) const;
32};
33
34//
35// Helper class: it wraps a grid and a data manager pointer to ensure
36// the grid is properly destroyed.
37//
38class FLOW_API GridWrapper final {
39private:
40 const VAPoR::Grid *const _gridPtr;
41 VAPoR::DataMgr *const _mgr; // The pointer itself cannot be changed
42
43public:
45 // Rule of five
46 GridWrapper(const GridWrapper &) = delete;
47 GridWrapper(const GridWrapper &&) = delete;
48 GridWrapper &operator=(const GridWrapper &) = delete;
49 GridWrapper &operator=(const GridWrapper &&) = delete;
51
52 // Access the real pointer
53 const VAPoR::Grid *grid() const;
54};
55
56//
57// Note on variable names in a VaporField:
58// If a variable name is an empty string, then this variable is still valid,
59// but contains all zero values in it.
60//
61class FLOW_API VaporField final : public Field {
62public:
63 //
64 // Functions from class Field
65 //
66 virtual bool InsideVolumeVelocity(double time, glm::vec3 pos) const override;
67 virtual bool InsideVolumeScalar(double time, glm::vec3 pos) const override;
68 virtual uint32_t GetNumberOfTimesteps() const override;
69
70 virtual int GetVelocity(double time, glm::vec3 pos, // input
71 glm::vec3 &vel) const override; // output
72 virtual int GetScalar(double time, glm::vec3 pos, // input
73 float &scalar) const override; // output
74
75 //
76 // Functions for interaction with VAPOR components
77 //
80 void ReleaseLockedGrids(); // Supposed to be invoked at the end of each paintGL event.
81
82 //
83 // Find one index whose timestamp is just below a given time
84 // I.e., _timestamps[floor] <= time
85 //
86 int LocateTimestamp(double time, // Input
87 size_t &floor) const; // Output
88
89 //
90 // Returns the intersection domain of 3 velocity variables at a specific time step.
91 // It returns non-zeros upon failure.
92 //
93 int GetVelocityIntersection(size_t ts, glm::vec3 &minxyz, glm::vec3 &maxxyz) const;
94
95 //
96 // Calculate a reasonable deltaT based on the velocity speed and domain size.
97 // This is used as a one-time operation when getting ready a velocity field.
98 // It'll return 0 on success, and non-zero on error conditions.
99 //
100 int CalcDeltaTFromCurrentTimeStep(double &delT) const;
101
102 //
103 // It turns that interactions from FlowParams can be expensive.
104 // Let's implement a mechanism to cache information and interact with them less frequently.
105 // Specifically, the following two functions are used to `lock` into (and `unlock` from)
106 // the current set of params from FlowParams, so we don't need to interact with it anymore.
107 //
108 virtual auto LockParams() -> int override;
109 virtual auto UnlockParams() -> int override;
110
111private:
112 //
113 // Member variables
114 //
115 std::vector<double> _timestamps; // in ascending order
116 VAPoR::DataMgr * _datamgr = nullptr;
117 const VAPoR::FlowParams *_params = nullptr;
118
119 using cacheType = VAPoR::ptr_cache<GridKey, GridWrapper, 6, true>;
120 mutable cacheType _recentGrids;
121 mutable std::mutex _grid_operation_mutex;
122
123 // The following variables are cache states from DataMgr and Params.
124 bool _params_locked = false;
125 uint32_t _c_currentTS = 0; // cached timestep
126 int32_t _c_refLev = -2; // cached ref levels
127 int32_t _c_compLev = -2; // cached ref levels
128 float _c_vel_mult = 0.0f; // cached velocity multiplier
129 VAPoR::CoordType _c_ext_min; // cached extents
130 VAPoR::CoordType _c_ext_max; // cached extents
131
132 //
133 // Member functions
134 //
135 // Are the following member pointers correctly set?
136 // 1) _datamgr, 2) _params
137 bool _isReady() const;
138
139 // _getAGrid will use _params to retrieve/generate grids.
140 // In the case of failing to generate a requested grid, nullptr will be returned.
141 // This failure will also be recorded to MyBase.
142 // Note: If a variable name is empty, we then return a ConstantField.
143 const VAPoR::Grid *_getAGrid(uint32_t timestep, const std::string &varName) const;
144};
145}; // namespace flow
146
147#endif
A cache based data reader.
Definition: DataMgr.h:110
Abstract base class for a 2D or 3D structured or unstructured grid.
Definition: Grid.h:56
bool emptyVar() const
bool operator==(const GridKey &) const
void Reset(uint32_t, int32_t, int32_t, std::string, VAPoR::CoordType, VAPoR::CoordType)
const VAPoR::Grid * grid() const
GridWrapper & operator=(const GridWrapper &&)=delete
GridWrapper(const GridWrapper &&)=delete
GridWrapper(const GridWrapper &)=delete
GridWrapper(const VAPoR::Grid *gp, VAPoR::DataMgr *mp)
GridWrapper & operator=(const GridWrapper &)=delete
int CalcDeltaTFromCurrentTimeStep(double &delT) const
virtual auto UnlockParams() -> int override
void AssignDataManager(VAPoR::DataMgr *dmgr)
virtual auto LockParams() -> int override
virtual bool InsideVolumeVelocity(double time, glm::vec3 pos) const override
virtual int GetScalar(double time, glm::vec3 pos, float &scalar) const override
void ReleaseLockedGrids()
virtual bool InsideVolumeScalar(double time, glm::vec3 pos) const override
int GetVelocityIntersection(size_t ts, glm::vec3 &minxyz, glm::vec3 &maxxyz) const
void UpdateParams(const VAPoR::FlowParams *)
int LocateTimestamp(double time, size_t &floor) const
virtual uint32_t GetNumberOfTimesteps() const override
virtual int GetVelocity(double time, glm::vec3 pos, glm::vec3 &vel) const override
#define FLOW_API
Definition: common.h:75
std::array< double, 3 > CoordType
Type for specifying floating point coordinates.
Definition: Grid.h:23
Definition: Advection.h:15