VAPOR3 3.9.4
GridHelper.h
Go to the documentation of this file.
1#include <vector>
2#include <unordered_map>
3#include <list>
4#include <cstddef>
5#include <stdexcept>
6#include <vapor/DC.h>
7#include <vapor/MyBase.h>
9#include <vapor/LayeredGrid.h>
10#include <vapor/RegularGrid.h>
11#include <vapor/StretchedGrid.h>
14
15#ifndef GRIDMGR_H
16 #define GRIDMGR_H
17
18namespace VAPoR {
19
20class UnstructuredGrid3D;
21
23public:
24 GridHelper(size_t max_size = 10) : _qtrCache(max_size) {}
25
27
28 string GetGridType(const DC::Mesh &m, const std::vector<DC::CoordVar> &cvarsinfo, const std::vector<vector<string>> &cdimnames) const;
29
30 bool IsUnstructured(std::string gridType) const;
31 bool IsStructured(std::string gridType) const;
32
33 // var: variable info
34 // roi_dims: spatial dimensions of ROI
35 // dims: spatial dimensions of full variable domain in voxels
36 // blkvec: data blocks, and coordinate blocks
37 // bsvec: data block dimensions, and coordinate block dimensions
38 // bminvec: ROI offsets in blocks, full domain, data and coordinates
39 // bmaxvec: ROI offsets in blocks, full domain, data and coordinates
40 //
41 StructuredGrid *MakeGridStructured(string gridType, size_t ts, int level, int lod, const DC::DataVar &var, const std::vector<DC::CoordVar> &cvarsinfo, const DimsType &roi_dims,
42 const DimsType &dims, const std::vector<float *> &blkvec, const std::vector<DimsType> &bsvec, const std::vector<DimsType> &bminvec,
43 const std::vector<DimsType> &bmaxvec);
44
45 UnstructuredGrid *MakeGridUnstructured(string gridType, size_t ts, int level, int lod, const DC::DataVar &var, const std::vector<DC::CoordVar> &cvarsinfo, const DimsType &roi_dims,
46 const DimsType &dims, const std::vector<float *> &blkvec, const std::vector<DimsType> &bsvec, const std::vector<DimsType> &bminvec,
47 const std::vector<DimsType> &bmaxvec, const std::vector<int *> &conn_blkvec, const std::vector<DimsType> &conn_bsvec,
48 const std::vector<DimsType> &conn_bminvec, const std::vector<DimsType> &conn_bmaxvec, const DimsType &vertexDims, const DimsType &faceDims,
49 const DimsType &edgeDims, UnstructuredGrid::Location location, size_t maxVertexPerFace, size_t maxFacePerVertex, long vertexOffset, long faceOffset);
50
51private:
52 template<typename key_t, typename value_t> class lru_cache {
53 public:
54 typedef typename std::pair<key_t, value_t> key_value_pair_t;
55 typedef typename std::list<key_value_pair_t>::iterator list_iterator_t;
56
57 lru_cache() : _max_size(10) {}
58
59 lru_cache(size_t max_size) : _max_size(max_size) {}
60
61 value_t put(const key_t &key, value_t value)
62 {
63 value_t rvalue = NULL;
64 auto it = _cache_items_map.find(key);
65 _cache_items_list.push_front(key_value_pair_t(key, value));
66 if (it != _cache_items_map.end()) {
67 rvalue = it->second->second;
68 _cache_items_list.erase(it->second);
69 _cache_items_map.erase(it);
70 }
71 _cache_items_map[key] = _cache_items_list.begin();
72
73 if (_cache_items_map.size() > _max_size) {
74 auto last = _cache_items_list.end();
75 last--;
76 rvalue = last->second;
77 _cache_items_map.erase(last->first);
78 _cache_items_list.pop_back();
79 }
80 return (rvalue);
81 }
82
83 value_t get(const key_t &key)
84 {
85 auto it = _cache_items_map.find(key);
86 if (it == _cache_items_map.end()) return (NULL);
87
88 _cache_items_list.splice(_cache_items_list.begin(), _cache_items_list, it->second);
89 return it->second->second;
90 }
91
92 value_t remove_lru()
93 {
94 if (!_cache_items_map.size()) return (NULL);
95
96 auto last = _cache_items_list.end();
97 last--;
98 value_t rvalue = last->second;
99 last->second = nullptr; // necessary for delete?
100 _cache_items_map.erase(last->first);
101 _cache_items_list.pop_back();
102 return (rvalue);
103 }
104
105 bool exists(const key_t &key) const;
106
107 size_t size() const { return _cache_items_map.size(); }
108
109 private:
110 std::list<key_value_pair_t> _cache_items_list;
111 std::unordered_map<key_t, list_iterator_t> _cache_items_map;
112 size_t _max_size;
113 };
114
115 lru_cache<string, std::shared_ptr<const QuadTreeRectangleP>> _qtrCache;
116
117 RegularGrid *_make_grid_regular(const DimsType &dims, const std::vector<float *> &blkvec, const DimsType &bs, const DimsType &bmin, const DimsType &bmax
118
119 ) const;
120
121 StretchedGrid *_make_grid_stretched(const DimsType &dims, const std::vector<float *> &blkvec, const DimsType &bs, const DimsType &bmin, const DimsType &bmax) const;
122
123 LayeredGrid *_make_grid_layered(const DimsType &dims, const std::vector<float *> &blkvec, const DimsType &bs, const DimsType &bmin, const DimsType &bmax) const;
124
125 CurvilinearGrid *_make_grid_curvilinear(size_t ts, int level, int lod, const std::vector<DC::CoordVar> &cvarsinfo, const DimsType &dims, const std::vector<float *> &blkvec, const DimsType &bs,
126 const DimsType &bmin, const DimsType &bmax);
127
128 UnstructuredGrid2D *_make_grid_unstructured2d(size_t ts, int level, int lod, const DC::DataVar &var, const std::vector<DC::CoordVar> &cvarsinfo, const DimsType &dims,
129 const std::vector<float *> &blkvec, const DimsType &bs, const DimsType &bmin, const DimsType &bmax, const std::vector<int *> &conn_blkvec,
130 const DimsType &conn_bs, const DimsType &conn_bmin, const DimsType &conn_bmax, const DimsType &vertexDims, const DimsType &faceDims,
131 const DimsType &edgeDims, UnstructuredGrid::Location location, size_t maxVertexPerFace, size_t maxFacePerVertex, long vertexOffset, long faceOffset);
132
133 UnstructuredGridLayered *_make_grid_unstructured_layered(size_t ts, int level, int lod, const DC::DataVar &var, const vector<DC::CoordVar> &cvarsinfo, const DimsType &dims,
134 const vector<float *> &blkvec, const DimsType &bs, const DimsType &bmin, const DimsType &bmax, const vector<int *> &conn_blkvec,
135 const DimsType &conn_bs, const DimsType &conn_bmin, const DimsType &conn_bmax, const DimsType &vertexDims, const DimsType &faceDims,
136 const DimsType &edgeDims, UnstructuredGrid::Location location, size_t maxVertexPerFace, size_t maxFacePerVertex, long vertexOffset,
137 long faceOffset);
138
139 UnstructuredGrid3D *_make_grid_unstructured_3d(size_t ts, int level, int lod, const DC::DataVar &var, const vector<DC::CoordVar> &cvarsinfo, const DimsType &dims, const vector<float *> &blkvec,
140 const DimsType &bs, const DimsType &bmin, const DimsType &bmax, const vector<int *> &conn_blkvec, const DimsType &conn_bs, const DimsType &conn_bmin,
141 const DimsType &conn_bmax, const DimsType &vertexDims, const DimsType &faceDims, const DimsType &edgeDims, UnstructuredGrid::Location location,
142 size_t maxVertexPerFace, size_t maxFacePerVertex, long vertexOffset, long faceOffset);
143
144 void _makeGridHelper(const DC::DataVar &var, const DimsType &roi_dims, const DimsType &dims, Grid *g) const;
145
146 string _getQuadTreeRectangleKey(size_t ts, int level, int lod, const vector<DC::CoordVar> &cvarsinfo, const DimsType &bmin, const DimsType &bmax) const;
147};
148
149}; // namespace VAPoR
150#endif
Data variable metadata.
Definition: DC.h:987
Metadata describing a computational mesh.
Definition: DC.h:310
string GetGridType(const DC::Mesh &m, const std::vector< DC::CoordVar > &cvarsinfo, const std::vector< vector< string > > &cdimnames) const
StructuredGrid * MakeGridStructured(string gridType, size_t ts, int level, int lod, const DC::DataVar &var, const std::vector< DC::CoordVar > &cvarsinfo, const DimsType &roi_dims, const DimsType &dims, const std::vector< float * > &blkvec, const std::vector< DimsType > &bsvec, const std::vector< DimsType > &bminvec, const std::vector< DimsType > &bmaxvec)
GridHelper(size_t max_size=10)
Definition: GridHelper.h:24
UnstructuredGrid * MakeGridUnstructured(string gridType, size_t ts, int level, int lod, const DC::DataVar &var, const std::vector< DC::CoordVar > &cvarsinfo, const DimsType &roi_dims, const DimsType &dims, const std::vector< float * > &blkvec, const std::vector< DimsType > &bsvec, const std::vector< DimsType > &bminvec, const std::vector< DimsType > &bmaxvec, const std::vector< int * > &conn_blkvec, const std::vector< DimsType > &conn_bsvec, const std::vector< DimsType > &conn_bminvec, const std::vector< DimsType > &conn_bmaxvec, const DimsType &vertexDims, const DimsType &faceDims, const DimsType &edgeDims, UnstructuredGrid::Location location, size_t maxVertexPerFace, size_t maxFacePerVertex, long vertexOffset, long faceOffset)
bool IsStructured(std::string gridType) const
bool IsUnstructured(std::string gridType) const
Abstract base class for a 2D or 3D structured grid.
Abstract base class for a 2D or 3D unstructured grid.
Wasp base class.
Definition: MyBase.h:67
#define VDF_API
Definition: common.h:73
std::array< size_t, 3 > DimsType
Type for specifying integer indices.
Definition: Grid.h:26