2#include <unordered_map>
20class UnstructuredGrid3D;
24 GridHelper(
size_t max_size = 10) : _qtrCache(max_size) {}
28 string GetGridType(
const DC::Mesh &m,
const std::vector<DC::CoordVar> &cvarsinfo,
const std::vector<vector<string>> &cdimnames)
const;
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);
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,
52 template<
typename key_t,
typename value_t>
class lru_cache {
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;
57 lru_cache() : _max_size(10) {}
59 lru_cache(
size_t max_size) : _max_size(max_size) {}
61 value_t put(
const key_t &key, value_t value)
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);
71 _cache_items_map[key] = _cache_items_list.begin();
73 if (_cache_items_map.size() > _max_size) {
74 auto last = _cache_items_list.end();
76 rvalue = last->second;
77 _cache_items_map.erase(last->first);
78 _cache_items_list.pop_back();
83 value_t get(
const key_t &key)
85 auto it = _cache_items_map.find(key);
86 if (it == _cache_items_map.end())
return (NULL);
88 _cache_items_list.splice(_cache_items_list.begin(), _cache_items_list, it->second);
89 return it->second->second;
94 if (!_cache_items_map.size())
return (NULL);
96 auto last = _cache_items_list.end();
98 value_t rvalue = last->second;
99 last->second =
nullptr;
100 _cache_items_map.erase(last->first);
101 _cache_items_list.pop_back();
105 bool exists(
const key_t &key)
const;
107 size_t size()
const {
return _cache_items_map.size(); }
110 std::list<key_value_pair_t> _cache_items_list;
111 std::unordered_map<key_t, list_iterator_t> _cache_items_map;
115 lru_cache<string, std::shared_ptr<const QuadTreeRectangleP>> _qtrCache;
117 RegularGrid *_make_grid_regular(
const DimsType &dims,
const std::vector<float *> &blkvec,
const DimsType &bs,
const DimsType &bmin,
const DimsType &bmax
121 StretchedGrid *_make_grid_stretched(
const DimsType &dims,
const std::vector<float *> &blkvec,
const DimsType &bs,
const DimsType &bmin,
const DimsType &bmax)
const;
123 LayeredGrid *_make_grid_layered(
const DimsType &dims,
const std::vector<float *> &blkvec,
const DimsType &bs,
const DimsType &bmin,
const DimsType &bmax)
const;
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);
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);
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,
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);
144 void _makeGridHelper(
const DC::DataVar &var,
const DimsType &roi_dims,
const DimsType &dims, Grid *g)
const;
146 string _getQuadTreeRectangleKey(
size_t ts,
int level,
int lod,
const vector<DC::CoordVar> &cvarsinfo,
const DimsType &bmin,
const DimsType &bmax)
const;
Metadata describing a computational mesh.
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)
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.
std::array< size_t, 3 > DimsType
Type for specifying integer indices.