VAPoR  0.1
AMRTreeBranch.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: AMRTreeBranch.h
13 //
14 // Author: John Clyne
15 // National Center for Atmospheric Research
16 // PO 3000, Boulder, Colorado
17 //
18 // Date: Thu Jan 5 16:59:42 MST 2006
19 //
20 // Description:
21 //
22 //
23 #ifndef _AMRTreeBranch_h_
24 #define _AMRTreeBranch_h_
25 
26 #include <vector>
27 #include <vapor/common.h>
28 #include <vapor/MyBase.h>
29 #include <vapor/EasyThreads.h>
30 #include <vapor/XmlNode.h>
31 
32 
33 namespace VAPoR {
34 
35 //
63 //
64 
66 
67 public:
68 
69  typedef long cid_t;
70 
71  //
72  // Tag names for data stored in the XML tree
73  //
74  static const string _rootTag; // root of the XML tree
75  static const string _refinementLevelTag; // max refinement depth of branch
76  // List of parent cells in breath first traversal order
77  static const string _parentTableTag;
78 
79 
80  //
81  // Attribute names for data stored in the XML tree
82  //
83  static const string _minExtentsAttr; // min coord bounds of branch
84  static const string _maxExtentsAttr; // max coord bounds of branch
85  static const string _locationAttr; // toplogical coords of branch
86 
87 
100  //
102  XmlNode *parent,
103  const double min[3],
104  const double max[3],
105  const size_t location[3]
106  );
107 
108  virtual ~AMRTreeBranch();
109 
110  void Update();
111 
118  //
119  int DeleteCell(cid_t cellid);
120 
137  //
138  cid_t FindCell(const double ucoord[3], int ref_level = -1) const;
139 
140  bool ValidCell(cid_t cellid) const {
141  return(cellid < _octree->get_num_cells(_octree->get_max_level()));
142  };
143 
158  int GetCellBounds(
159  cid_t cellid, double minu[3], double maxu[3]
160  ) const;
161 
181  int GetCellLocation(cid_t cellid, size_t xyz[3],int *reflevel) const;
182 
183 
198  AMRTreeBranch::cid_t GetCellID(const size_t xyz[3], int reflevel) const;
199 
200 
213  //
214  cid_t GetCellChildren(cid_t cellid) const;
215 
224  //
225  int GetCellLevel(cid_t cellid) const;
226 
227 
243  cid_t GetCellNeighbor(cid_t cellid, int face) const;
244 
249  cid_t GetNumCells() const;
250 
256  cid_t GetNumCells(int ref_level) const;
257 
267  //
268  cid_t GetCellParent(cid_t cellid) const;
269 
271  //
272  int GetRefinementLevel() const {
273  return ((int) (_octree->get_max_level()));
274  };
275 
277  //
278  cid_t GetRoot() const {return(0);};
279 
284  //
285  int HasChildren(cid_t cellid) const;
286 
287 
297  //
299 
300 
303  //
304  void EndRefinement();
305 
307  //
308  AMRTreeBranch::cid_t GetNextCell(bool restart);
309 
317  //
318  long GetCellOffset(cid_t cellid) const;
319 
320  int SetParentTable(const vector<long> &table);
321 
322 private:
323 
324  //
325  // cell ids indicate the order in which the cell was added to the
326  // tree via refinement. They also determine the octant that a cell
327  // occupies by virtue of the fact that refinement generates 8 new
328  // cells, inserted into the tree in octant order. The root of the
329  // tree always has id==0
330  //
331  class octree {
332  public:
333 
334 
335  octree();
336  void clear();
337  cid_t refine_cell(cid_t cellid);
338  void end_refinement();
339  cid_t get_parent(cid_t cellid) const;
340 
341  //
342  // returns the cellid of the child in the first octant. The
343  // id's of the remaining children are numbered sequentially
344  //
345  cid_t get_children(cid_t cellid) const;
346 
347  bool has_children(cid_t cellid) const;
348  //
349  // Get id of next child in a breadth first traversal of
350  // the tree. If 'restart' is true, traversal starts from the
351  // top of the tree, else traversal starts from the cell returned
352  // from the previous call. When the tree has been completely
353  // treversed a negative number is returned.
354  //
355  cid_t get_next(bool restart);
356 
357  long get_offset(cid_t cellid) const;
358 
359  //
360  // Return the octant occupied by 'cellid'. Octants are numbered
361  // sequentially from 0 with X varying fastest, followed by y, than Z.
362  //
363  int get_octant(cid_t cellid) const;
364  int get_max_level() const {return(_max_level); };
365 
366 
367  // Get the cellid for the cell with the specified coordinates (if
368  // it exists). The cartesian coordinates are respective
369  // to the refinement level of the cell. Their range is from
370  // 0..(2^j)-1, where j is the refinment level. If no cell
371  // exists at (xyz, level) a negative int is returned.
372  //
373  cid_t get_cellid(const size_t xyz[3], int level) const;
374 
375  int get_location(cid_t cellid, size_t xyz[3], int *level) const;
376 
377  int get_level(cid_t cellid) const;
378 
379  cid_t get_num_cells(int ref_level) const;
380 
381  private:
382 
383  vector <cid_t> _bft_next;
384  vector <cid_t>::iterator _bft_itr;
385  vector <cid_t> _bft_children;
386  vector <cid_t> _num_cells;
387  int _max_level; // maximum refinment level in tree. Base level is 0
388 
389  vector <long> _offsets; // vector of offsets to speed breath-first search
390 
391  typedef struct {
392  cid_t parent;
393  cid_t child; // id of first child. Remaining children have
394  // consecutivie ids
395  } _node_t;
396 
397  vector <_node_t> _tree; // interal octree representation.
398 
399  void _init();
400 
401 
402  };
403 
404 
405  octree *_octree;
406 
407  size_t _location[3]; // Topological coords of branch in blocks
408  double _minBounds[3]; // Min domain extents expressed in user coordinates
409  double _maxBounds[3]; // Max domain extents expressed in user coordinates
410 
411  XmlNode *_rootNode; // root of XML tree used to represent AMR tree
412 
413 
414 };
415 
416 };
417 
418 #endif // _AMRTreeBranch_h_
This class manages an octree data structure.
Definition: AMRTreeBranch.h:65
AMRTreeBranch::cid_t GetNextCell(bool restart)
cid_t GetCellNeighbor(cid_t cellid, int face) const
cid_t GetCellParent(cid_t cellid) const
static const string _maxExtentsAttr
Definition: AMRTreeBranch.h:84
cid_t FindCell(const double ucoord[3], int ref_level=-1) const
static const string _locationAttr
Definition: AMRTreeBranch.h:85
AMRTreeBranch::cid_t GetCellID(const size_t xyz[3], int reflevel) const
int DeleteCell(cid_t cellid)
AMRTreeBranch(XmlNode *parent, const double min[3], const double max[3], const size_t location[3])
An Xml tree.
Definition: XmlNode.h:47
virtual ~AMRTreeBranch()
long GetCellOffset(cid_t cellid) const
int GetRefinementLevel() const
Returns the maximum refinement level of any cell in this branch.
static const string _rootTag
Definition: AMRTreeBranch.h:74
int GetCellLocation(cid_t cellid, size_t xyz[3], int *reflevel) const
int SetParentTable(const vector< long > &table)
static const string _parentTableTag
Definition: AMRTreeBranch.h:77
bool ValidCell(cid_t cellid) const
cid_t GetNumCells() const
static const string _minExtentsAttr
Definition: AMRTreeBranch.h:83
VetsUtil base class.
Definition: MyBase.h:68
static const string _refinementLevelTag
Definition: AMRTreeBranch.h:75
int GetCellBounds(cid_t cellid, double minu[3], double maxu[3]) const
cid_t GetRoot() const
Returns the cellid root node.
AMRTreeBranch::cid_t RefineCell(cid_t cellid)
cid_t GetCellChildren(cid_t cellid) const
int GetCellLevel(cid_t cellid) const
int HasChildren(cid_t cellid) const