Chombo + EB  3.2
GraphNode.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 // ANAG, LBNL
12 
13 #ifndef _GRAPHNODE_H_
14 #define _GRAPHNODE_H_
15 
16 #include "REAL.H"
17 #include "ProblemDomain.H"
18 #include "IntVect.H"
19 #include "VolIndex.H"
20 #include "FaceIndex.H"
21 #include "Vector.H"
22 #include "Arena.H"
23 #include "NamespaceHeader.H"
24 
25 ///
26 /**
27  This is the graph data held for each irregular node.
28  Warning: each GraphNode holds a <EM>Vector</EM> of GraphNodeImplems.
29  */
31 {
32 public:
33  ///
34  inline
36 
37  ///
38  inline
40 
41  ///
42  GraphNodeImplem& operator=(const GraphNodeImplem& a_impin);
43 
44  ///
45  GraphNodeImplem(const GraphNodeImplem& a_impin);
46 
47  /// If true, this represents a regular cell and only m_coarserNode will be valid
49 
50  /// Used to mark a GraphNode as invalid - used in getting connected components of the graph
51  bool m_isValid;
52 
53  ///
54  /**
55  Cell indicies of neighboring cells.
56  If the arc is a boundary face, the int = -1
57  */
59 
60  /// Cell index of this vof is the index into the vector
61 
62  /// Cell index of next coarser vof
64 
65  /// Index into node vector (for construction).
66  int m_nodeInd;
67 
68  /// List of finer vofs
70 
71  /// Return the index into the arc vector
72  inline int index(int a_idir, Side::LoHiSide a_side) const;
73 
74  ///
75  int linearSize() const;
76 
77  ///
78  void linearOut(void* buffer ) const;
79 
80  ///
81  void linearIn(void* buffer );
82 
83  friend class EBISLevel;
84 };
85 
86 ///
87 /**
88  This is a list showing the connectivity of a given cell. This
89  has the special property of also being able to set itself to regular
90  or covered by setting the current nodeimplem pointer to 1 or 0.
91  */
92 class GraphNode
93 {
94 public:
95  ///
96  /**
97  Constructor sets node to regular as default.
98  */
99  inline GraphNode();
100 
101  ///
102  /**
103  */
104  inline ~GraphNode();
105 
106  ///
107  int size() const;
108 
109  ///
110  /**
111  Deletes memory if it has been allocated and sets
112  members to 0
113  */
114  inline void clear();
115 
116  ///
117  /**
118  Return true if the node is covered (m_cellList==0).
119  */
120  inline bool isCovered() const;
121 
122  ///
123  /**
124  Return true if the node is regular.
125  */
126  inline bool isRegular() const;
127 
128  ///
129  /**
130  Return true if the node is regular and has a single-valued parent
131  (m_cellList==1).
132  */
133  inline bool isRegularWithSingleValuedParent() const;
134 
135  ///
136  /**
137  Return true if the node is regular and has a multi-valued parent
138  (m_cellList is a valid pointer)
139  */
140  inline bool isRegularWithMultiValuedParent() const;
141 
142  ///
143  /**
144  Return true if the node is neither regular or covered.
145  */
146  inline bool isIrregular() const;
147 
148  ///
149  /**
150  Return true if the node has a valid m_cellList pointer
151  */
152  inline bool hasValidCellList() const;
153 
154  ///
155  /**
156  Set Node to regular. If previously set to irregular,
157  deletes their memory.
158  */
159  inline void defineAsRegular();
160 
161  ///
162  /**
163  Set Node to covered. If previously set to irregular,
164  deletes their memory.
165  */
166  inline void defineAsCovered();
167 
168  ///
169  /**
170  Get the faces in the direction and side
171  for the vof in the list. if the vof's cell
172  index is not found in the list, abort.
173  Use the input vof's grid index for a the grid index
174  of the list.
175  */
177  getFaces(const VolIndex& a_vof,
178  const int& a_idir,
179  const Side::LoHiSide& a_sd,
180  const ProblemDomain& a_domain) const;
181 
182  ///
184  getFaces(const IntVect& a_iv,
185  const int& a_idir,
186  const Side::LoHiSide& a_sd,
187  const ProblemDomain& a_domain) const;
188 
189  ///
190  /**
191  Return all the vofs in the list, using the input
192  intvect for the gridIndex
193  */
195  getVoFs(const IntVect& a_iv) const;
196 
197  ///
198  const GraphNode& operator=(const GraphNode& ebiin);
199 
200  ///
201  GraphNode(const GraphNode& ebiin);
202 
203  ///
204  /**
205  Returns the corresponding set of VoFs from the next finer
206  EBGraph (factor of two refinement). The result is only
207  defined if this {\tt EBGraph} was defined by coarsening.
208  */
209  Vector<VolIndex> refine(const VolIndex& a_coarVoF) const;
210 
211  ///
212  /**
213  Returns the corresponding VoF from the next coarser
214  EBGraph (same solution location, different index space, factor
215  of two refinement ratio).
216  */
217  VolIndex coarsen(const VolIndex& a_fineVoF) const;
218 
219  ///
220  /**
221  */
222  void addIrregularNode(const GraphNodeImplem& a_nodein, int cellIndex);
223  ///
224  /**
225  */
226  void addIrregularNode(const GraphNodeImplem& a_nodein);
227 
228  ///
229  /**
230  Get all sets of connected vofs within the box (used in coarsening)
231  */
232  Vector<Vector<VolIndex> > getVoFSets(const Box& a_box) const;
233 
234  ///
235  int linearSize() const;
236 
237  ///
238  void linearOut(void* buffer ) const;
239 
240  ///
241  void linearIn(void* buffer );
242 
243  /// internal use only
244  inline void setDefaults();
245 
246  void* alloc();
247  ///
248  /**
249  The connectivity data at this point.
250  If m_cellList == 0, node is covered.
251  If m_cellList == 1, node is regular and parent is single-valued.
252  otherwise, it is a real list (node may still be regular).
253  */
255 
256  static BArena s_Arena;
257 
258  friend class EBISLevel;
259 };
260 
261 /* Inline functions */
262 /*******************************/
264 {
265  clear();
266 }
267 
268 /*******************************/
269 inline bool GraphNode::isCovered() const
270 {
271  return (m_cellList == ((Vector<GraphNodeImplem>*) 0));
272 }
273 
274 /*******************************/
275 inline bool GraphNode::isRegular() const
276 {
277  return (isRegularWithSingleValuedParent() ||
278  isRegularWithMultiValuedParent());
279 }
280 
281 /*******************************/
283 {
284  return (m_cellList == ((Vector<GraphNodeImplem>*) 1));
285 }
286 
287 /*******************************/
289 {
290  return (((m_cellList != ((Vector<GraphNodeImplem>*) 0)) &&
291  ((*m_cellList).size() == 1) &&
292  ((*m_cellList)[0]).m_isRegular));
293 }
294 
295 /*******************************/
296 inline bool GraphNode::hasValidCellList() const
297 {
298  return (!isCovered() && !isRegularWithSingleValuedParent());
299 }
300 
301 /*******************************/
302 inline bool GraphNode::isIrregular() const
303 {
304  return ((!isRegular()) && (!isCovered()));
305 }
306 
307 /*******************************/
309 {
310  m_cellList = (Vector<GraphNodeImplem>*)1;
311 }
312 
313 /*******************************/
315 {
316  setDefaults();
317 }
318 
319 /*******************************/
320 inline void GraphNode::clear()
321 {
322  if (hasValidCellList())
323  {
324  // delete m_cellList;
325  m_cellList->~Vector<GraphNodeImplem>();
326  s_Arena.free(m_cellList);
327 #ifdef CH_USE_MEMORY_TRACKING
328  ch_memcount-=sizeof(Vector<GraphNodeImplem>);
329  s_Arena.bytes -= sizeof(Vector<GraphNodeImplem>);
330  CH_assert(s_Arena.bytes >= 0);
331 #endif
332  }
333  setDefaults();
334 }
335 
336 /*******************************/
338 {
339  clear();
340  m_cellList = (Vector<GraphNodeImplem>*) 1;
341 }
342 
343 /*******************************/
345 {
346  clear();
347  m_cellList = (Vector<GraphNodeImplem>*) 0;
348 }
349 
350 /*******************************/
352  : m_isRegular(false),
353  m_isValid(true),
354  m_coarserNode(-1),
355  m_nodeInd(-1)
356 {
357 }
358 
359 /*******************************/
361 {
362 }
363 
364 /*******************************/
365 inline int GraphNodeImplem::index(int a_idir,
366  Side::LoHiSide a_sd) const
367 {
368  CH_assert(a_idir >= 0 && a_idir < SpaceDim);
369  return a_idir + a_sd*CH_SPACEDIM;
370 }
371 
372 /*
373  if (a_sd == Side::Lo)
374  {
375  retval = a_idir;
376  }
377  else
378  {
379  retval = a_idir + SpaceDim;
380  }
381  return retval;
382 }
383 */
384 
385 #include "NamespaceFooter.H"
386 
387 #endif
int linearSize() const
bool isCovered() const
Definition: GraphNode.H:269
void linearIn(void *buffer)
#define CH_SPACEDIM
Definition: SPACE.H:51
#define CH_assert(cond)
Definition: CHArray.H:37
Box refine(const Box &b, const IntVect &refinement_ratio)
A class to facilitate interaction with physical boundary conditions.
Definition: ProblemDomain.H:141
bool m_isValid
Used to mark a GraphNode as invalid - used in getting connected components of the graph...
Definition: GraphNode.H:51
Definition: EBISLevel.H:84
GraphNodeImplem & operator=(const GraphNodeImplem &a_impin)
void defineAsCovered()
Definition: GraphNode.H:344
int m_coarserNode
Cell index of this vof is the index into the vector.
Definition: GraphNode.H:63
bool isRegular() const
Definition: GraphNode.H:275
~GraphNodeImplem()
Definition: GraphNode.H:360
A Concrete Class for Dynamic Memory Management.
Definition: Arena.H:124
bool m_isRegular
If true, this represents a regular cell and only m_coarserNode will be valid.
Definition: GraphNode.H:48
const int SpaceDim
Definition: SPACE.H:38
int m_nodeInd
Index into node vector (for construction).
Definition: GraphNode.H:66
~GraphNode()
Definition: GraphNode.H:263
IndexTM< T, N > coarsen(const IndexTM< T, N > &a_p, T a_s)
Definition: IndexTMI.H:430
Vector< VolIndex > m_finerNodes
List of finer vofs.
Definition: GraphNode.H:69
int index(int a_idir, Side::LoHiSide a_side) const
Return the index into the arc vector.
Definition: GraphNode.H:365
GraphNode()
Definition: GraphNode.H:314
void setDefaults()
internal use only
Definition: GraphNode.H:308
bool isRegularWithMultiValuedParent() const
Definition: GraphNode.H:288
GraphNodeImplem()
Definition: GraphNode.H:351
LoHiSide
Definition: LoHiSide.H:27
bool isIrregular() const
Definition: GraphNode.H:302
void clear()
Definition: GraphNode.H:320
void linearOut(void *buffer) const
static BArena s_Arena
Definition: GraphNode.H:256
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:465
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
Definition: GraphNode.H:30
bool isRegularWithSingleValuedParent() const
Definition: GraphNode.H:282
Volume of Fluid Index.
Definition: VolIndex.H:31
Vector< int > m_arc[2 *SpaceDim]
Definition: GraphNode.H:58
void defineAsRegular()
Definition: GraphNode.H:337
Vector< GraphNodeImplem > * m_cellList
Definition: GraphNode.H:254
Definition: GraphNode.H:92
bool hasValidCellList() const
Definition: GraphNode.H:296