VAPoR  0.1
AMRTree.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: AMRTree.h
13 //
14 // Author: John Clyne
15 // National Center for Atmospheric Research
16 // PO 3000, Boulder, Colorado
17 //
18 // Date: Thu Jan 5 16:58:05 MST 2006
19 //
20 // Description:
21 //
22 //
23 
24 #ifndef _AMRTree_h_
25 #define _AMRTree_h_
26 
27 #include <vector>
28 #include <vapor/common.h>
29 #include <vapor/MyBase.h>
30 #include <vapor/EasyThreads.h>
31 #include <vapor/AMRTreeBranch.h>
32 #include <vapor/ExpatParseMgr.h>
33 
34 
35 namespace VAPoR {
36 
37 //
60 //
61 
62 class AMRTree : public VetsUtil::MyBase, public ParsedXml {
63 
64 public:
65 
66 
67  // An unique identifier for each cell in the tree
68  //
70 
71 
82  //
83  AMRTree(
84  const size_t basedim[3],
85  const double min[3],
86  const double max[3]
87  );
88 
97  AMRTree(
98  const string &path
99  );
100 
117  //
118  AMRTree(
119  const size_t basedim[3],
120  const int paramesh_gids[][15],
121  const float paramesh_bboxs [][3][2],
122  const int paramesh_refine_levels[],
123  int paramesh_total_blocks
124  );
125 
130  //
131  AMRTree();
132 
133  virtual ~AMRTree();
134 
147  //
148  void DecodeCellID(
149  AMRTree::cid_t cellid,
150  AMRTree::cid_t *baseblockidx,
151  AMRTree::cid_t *nodeidx
152  ) const;
153 
160  //
161  int DeleteCell(AMRTree::cid_t cellid);
162 
163 
180  //
181  AMRTree::cid_t FindCell(const double ucoord[3], int reflevel = -1) const;
182 
201  int GetCellLocation(
202  AMRTree::cid_t cellid, size_t xyz[3], int *reflevel
203  ) const;
204 
219  AMRTree::cid_t GetCellID(const size_t xyz[3], int reflevel) const;
220 
227  //
228  const size_t *GetBaseDim() const { return(_baseDim); };
229 
239  //
240  const AMRTreeBranch *GetBranch(const size_t xyz[3]) const;
241 
243  const AMRTreeBranch *GetBranch(cid_t baseblockidx) const;
244 
258  int GetCellBounds(
259  cid_t cellid, double minu[3], double maxu[3]
260  ) const;
261 
274  //
276 
277 
286  //
287  int GetCellLevel(AMRTree::cid_t cellid) const;
288 
289 
290 
306  //
308  AMRTree::cid_t cellid, int face
309  ) const;
310 
311 
321  //
323 
326  int GetRefinementLevel(const size_t min[3], const size_t max[3]) const;
327 
329  //
330  int GetRefinementLevel() const;
331 
349  const size_t min [3],
350  const size_t max[3],
351  int reflevel = -1
352  ) const;
353 
365  //
366  AMRTree::cid_t GetNumCells(int reflevel = -1) const;
367 
368 
379 
389  void EndRefinement();
390 
406  AMRTree::cid_t GetNextCell(bool restart);
407 
408 
409  int MapUserToVoxel(
410  int reflevel, const double ucoord[3], size_t vcoord[3]
411  );
412 
417  //
418  int Write(const string &path) const;
419 
424  //
425  int Read(const string &path);
426 
428  vector <int> &baseblocks,
429  const size_t basedim[3],
430  const int gids[][15],
431  const float bboxs [][3][2],
432  int totalblocks
433  ) const;
434 
435 private:
436 
437  cid_t _x_index; // tree traversal index;
438  int _tbits; // # bits used to encode base cell index
439  int _tbbits; // # bits used to encode branch cell id
440  static const string _rootTag;
441  static const string _minExtentsAttr;
442  static const string _maxExtentsAttr;
443  static const string _baseDimAttr;
444  static const string _fileVersionAttr;
445 
446  int _xml_help_loc; // hack to maintains XML state info at different levels
447  int _objIsInitialized;
448 
449  size_t _baseDim[3]; // Dimension of tree expressed in base blocks
450  double _minBounds[3]; // Min domain extents expressed in user coordinates
451  double _maxBounds[3]; // Max domain extents expressed in user coordinates
452 
453 
454  AMRTreeBranch **_treeBranches; // One branch per base block;
455 
456  XmlNode *_rootNode; // root of XML tree used to represent AMR tree
457 
458  int _fileVersion;
459 
460  int _AMRTree(
461  const size_t basedim[3],
462  const double min[3],
463  const double max[3]
464  );
465 
466  void _freeAMRTree();
467 
468  void _encode_cellid(
469  cid_t baseblockidx, cid_t nodeidx, cid_t *cellid
470  ) const;
471 
472  int paramesh_refine_baseblocks(
473  int index,
474  int pid,
475  const int gids[][15]
476  );
477 
478  bool elementStartHandler(
479  ExpatParseMgr*, int depth , std::string& tag, const char **attr
480  );
481  bool elementEndHandler(ExpatParseMgr*, int depth , std::string&);
482 
483  // XML Expat element handler helps. A different handler is defined
484  // for each possible state (depth of XML tree) from 0 to 3
485  //
486  void _startElementHandler0(ExpatParseMgr*,const string &tag, const char **attrs);
487  void _startElementHandler1(ExpatParseMgr*,const string &tag, const char **attrs);
488  void _startElementHandler2(ExpatParseMgr*,const string &tag, const char **attrs);
489  void _endElementHandler0(ExpatParseMgr*,const string &tag);
490  void _endElementHandler1(ExpatParseMgr*,const string &tag);
491  void _endElementHandler2(ExpatParseMgr*,const string &tag);
492 
493 
494 
495 };
496 
497 };
498 
499 #endif // _AMRTree_h_
This class manages an octree data structure.
Definition: AMRTreeBranch.h:65
AMRTree::cid_t GetCellID(const size_t xyz[3], int reflevel) const
AMRTree::cid_t RefineCell(AMRTree::cid_t cellid)
int DeleteCell(AMRTree::cid_t cellid)
int Write(const string &path) const
AMRTree::cid_t GetCellNeighbor(AMRTree::cid_t cellid, int face) const
An Xml tree.
Definition: XmlNode.h:47
AMRTree::cid_t GetNumCells(const size_t min[3], const size_t max[3], int reflevel=-1) const
const AMRTreeBranch * GetBranch(const size_t xyz[3]) const
AMRTree::cid_t FindCell(const double ucoord[3], int reflevel=-1) const
AMRTreeBranch::cid_t cid_t
Definition: AMRTree.h:69
AMRTree::cid_t GetCellParent(AMRTree::cid_t cellid) const
AMRTree::cid_t GetNextCell(bool restart)
AMRTree::cid_t GetCellChildren(AMRTree::cid_t cellid) const
void EndRefinement()
VetsUtil base class.
Definition: MyBase.h:68
int GetCellLocation(AMRTree::cid_t cellid, size_t xyz[3], int *reflevel) const
int GetCellLevel(AMRTree::cid_t cellid) const
int Read(const string &path)
int MapUserToVoxel(int reflevel, const double ucoord[3], size_t vcoord[3])
const size_t * GetBaseDim() const
Definition: AMRTree.h:228
int _parameshGetBaseBlocks(vector< int > &baseblocks, const size_t basedim[3], const int gids[][15], const float bboxs[][3][2], int totalblocks) const
This class manages an AMR tree data structure.
Definition: AMRTree.h:62
int GetRefinementLevel() const
Returns the maximum refinement of the entire tree.
int GetCellBounds(cid_t cellid, double minu[3], double maxu[3]) const
void DecodeCellID(AMRTree::cid_t cellid, AMRTree::cid_t *baseblockidx, AMRTree::cid_t *nodeidx) const
virtual ~AMRTree()