VAPoR  0.1
AMRData.h
Go to the documentation of this file.
1 //
2 // $Id$
3 //
4 //***********************************************************************
5 // *
6 // Copyright (C) 2006 *
7 // University Corporation for Atmospheric Research *
8 // All Rights Reserved *
9 // *
10 //***********************************************************************
11 //
12 // File: AMRData.h
13 //
14 // Author: John Clyne
15 // National Center for Atmospheric Research
16 // PO 3000, Boulder, Colorado
17 //
18 // Date: Thu Jan 5 16:57:20 MST 2006
19 //
20 // Description:
21 //
22 //
23 
24 #ifndef _AMRData_h_
25 #define _AMRData_h_
26 
27 #include <vector>
28 #include <vapor/common.h>
29 #include <vapor/MyBase.h>
30 #include <vapor/AMRTree.h>
31 
32 
33 namespace VAPoR {
34 
35 //
60 //
61 
62 class AMRData : public VetsUtil::MyBase {
63 
64 public:
65 
66 
67 
92  //
93  AMRData(
94  const AMRTree *tree,
95  const size_t cell_dim[3],
96  const size_t bmin[3],
97  const size_t bmax[3],
98  int reflevel = -1
99  );
100 
103  //
104  AMRData(
105  const AMRTree *tree,
106  const size_t cell_dim[3],
107  int reflevel = -1
108  );
109 
112  //
113  AMRData(
114  const AMRTree *tree
115  );
116 
137  //
138  AMRData(
139  const AMRTree *tree,
140  const size_t cell_dim[3],
141  const int paramesh_gids[][15],
142  const float paramesh_bboxs [][3][2],
143  const float paramesh_unk[],
144  int total_blocks,
145  int reflevel = -1
146  );
147 
148  virtual ~AMRData() {_AMRDataFree();};
149 
163  //
164  int SetRegion(
165  const size_t min[3],
166  const size_t max[3],
167  int reflevel
168  );
169 
176  //
177  void GetRegion(
178  const size_t **min,
179  const size_t **max,
180  int *reflevel
181  ) const;
182 
183 
191  void Update();
192 
202  //
203  int WriteNCDF(
204  const string &path,
205  int reflevel = -1
206  );
207 
225  //
226  int ReadNCDF(
227  const string &path,
228  const size_t bmin[3],
229  const size_t bmax[3],
230  int reflevel = -1
231  );
232 
235  int ReadNCDF(
236  const string &path,
237  int reflevel = -1
238  );
239 
255  //
256  static int ReadAttributesNCDF(
257  const string &path, size_t cell_dim[3], size_t bmin[3], size_t bmax[3],
258  float data_range[2], int &reflevel, size_t &num_nodes
259  );
260 
261 
269  //
270  float *GetBlock(
271  AMRTree::cid_t cellid
272  ) const;
273 
299  int ReGrid(
300  const size_t bmin[3],
301  const size_t bmax[3],
302  int reflevel,
303  float *grid,
304  const size_t dim[3]
305  ) const;
306 
315  const float *GetDataRange() const {return (_dataRange);};
316 
317 
318  const AMRTree *GetTree() const {return(_tree);};
319 
320  void GetBounds(size_t bmin[3], size_t bmax[3]) const {
321  for (int i=0; i<3; i++) {bmin[i] = _bmin[i]; bmax[i] = _bmax[i];}
322  }
323 
324 private:
325 
326  static const string _numNodeToken;
327  static const string _blockSizeXToken;
328  static const string _blockSizeYToken;
329  static const string _blockSizeZToken;
330  static const string _varToken;
331  static const string _blockMinToken;
332  static const string _blockMaxToken;
333  static const string _refinementLevelToken;
334  static const string _scalarRangeToken;
335 
336  const AMRTree *_tree;
337  size_t _cellDim[3]; // Dimensions, in # samples, of each cell
338  float **_treeData; // data for each tree branch
339  int *_treeDataMemSize; // mem size allocated to treeData
340  size_t _bmin[3]; // bounds of tree subregion (in base blocks)
341  size_t _bmax[3];
342  int _maxRefinementLevel; // Maximum refinement level present
343  float _dataRange[2]; // min and max range of data;
344 
345  void _AMRData(
346  const AMRTree *tree,
347  const size_t cell_dim[3],
348  const size_t min[3],
349  const size_t max[3],
350  int reflevel = -1
351  );
352 
353  void _AMRDataFree();
354 
355  int paramesh_copy_data(
356  int index,
357  int pid,
358  const int paramesh_gids[][15],
359  const float paramesh_unk[]
360  );
361 
362  // Resample a tree branch (base block and children) to a regular
363  // Cartesian grid. x,y,z are the topological coordinates of the tree
364  // branch, specified in base blocks (blocks at refinement level 0).
365  // min and max specify the extents
366  // of the area to be resampled
367  // in block coordinates **relative to the indicated refinement level**.
368  // The coordinate system for min and max is global, i.e. the origin is
369  // the corner of the first base block.
370  //
371  void regrid_branch(
372  unsigned int x,
373  unsigned int y,
374  unsigned int z,
375  const size_t min[3],
376  const size_t max[3],
377  int reflevel,
378  float *grid,
379  const size_t dim[3]
380  ) const;
381 
382  // Resample a single cell to a regular grid. This is a help method called
383  // by resample_branch. tbranch is the tree branch containing the cell to
384  // be processed.
385  //
386  void regrid_cell(
387  const AMRTreeBranch *tbranch,
388  const float *branch_data, // data associated with tbranch
389  AMRTreeBranch::cid_t cellid, // id of cell to be resampled.
390  const size_t min[3], // same is in regrid_branch
391  const size_t max[3],
392  int reflevel,
393  float *grid,
394  const size_t dim[3]
395  ) const;
396 
397 };
398 
399 };
400 
401 #endif // _AMRData_h_
This class manages an octree data structure.
Definition: AMRTreeBranch.h:65
This class manages an Adaptive Mesh Refinement grid.
Definition: AMRData.h:62
int ReGrid(const size_t bmin[3], const size_t bmax[3], int reflevel, float *grid, const size_t dim[3]) const
int ReadNCDF(const string &path, const size_t bmin[3], const size_t bmax[3], int reflevel=-1)
void GetRegion(const size_t **min, const size_t **max, int *reflevel) const
int SetRegion(const size_t min[3], const size_t max[3], int reflevel)
float * GetBlock(AMRTree::cid_t cellid) const
const float * GetDataRange() const
Definition: AMRData.h:315
const AMRTree * GetTree() const
Definition: AMRData.h:318
static int ReadAttributesNCDF(const string &path, size_t cell_dim[3], size_t bmin[3], size_t bmax[3], float data_range[2], int &reflevel, size_t &num_nodes)
void GetBounds(size_t bmin[3], size_t bmax[3]) const
Definition: AMRData.h:320
AMRTreeBranch::cid_t cid_t
Definition: AMRTree.h:69
int WriteNCDF(const string &path, int reflevel=-1)
VetsUtil base class.
Definition: MyBase.h:68
AMRData(const AMRTree *tree, const size_t cell_dim[3], const size_t bmin[3], const size_t bmax[3], int reflevel=-1)
This class manages an AMR tree data structure.
Definition: AMRTree.h:62
virtual ~AMRData()
Definition: AMRData.h:148