Chombo + EB  3.0
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 
84 ///
85 /**
86  This is a list showing the connectivity of a given cell. This
87  has the special property of also being able to set itself to regular
88  or covered by setting the current nodeimplem pointer to 1 or 0.
89  */
90 class GraphNode
91 {
92 public:
93  ///
94  /**
95  Constructor sets node to regular as default.
96  */
97  inline GraphNode();
98 
99  ///
100  /**
101  */
102  inline ~GraphNode();
103 
104  ///
105  int size() const;
106 
107  ///
108  /**
109  Deletes memory if it has been allocated and sets
110  members to 0
111  */
112  inline void clear();
113 
114  ///
115  /**
116  Return true if the node is covered (m_cellList==0).
117  */
118  inline bool isCovered() const;
119 
120  ///
121  /**
122  Return true if the node is regular.
123  */
124  inline bool isRegular() const;
125 
126  ///
127  /**
128  Return true if the node is regular and has a single-valued parent
129  (m_cellList==1).
130  */
131  inline bool isRegularWithSingleValuedParent() const;
132 
133  ///
134  /**
135  Return true if the node is regular and has a multi-valued parent
136  (m_cellList is a valid pointer)
137  */
138  inline bool isRegularWithMultiValuedParent() const;
139 
140  ///
141  /**
142  Return true if the node is neither regular or covered.
143  */
144  inline bool isIrregular() const;
145 
146  ///
147  /**
148  Return true if the node has a valid m_cellList pointer
149  */
150  inline bool hasValidCellList() const;
151 
152  ///
153  /**
154  Set Node to regular. If previously set to irregular,
155  deletes their memory.
156  */
157  inline void defineAsRegular();
158 
159  ///
160  /**
161  Set Node to covered. If previously set to irregular,
162  deletes their memory.
163  */
164  inline void defineAsCovered();
165 
166  ///
167  /**
168  Get the faces in the direction and side
169  for the vof in the list. if the vof's cell
170  index is not found in the list, abort.
171  Use the input vof's grid index for a the grid index
172  of the list.
173  */
175  getFaces(const VolIndex& a_vof,
176  const int& a_idir,
177  const Side::LoHiSide& a_sd,
178  const ProblemDomain& a_domain) const;
179 
180  ///
182  getFaces(const IntVect& a_iv,
183  const int& a_idir,
184  const Side::LoHiSide& a_sd,
185  const ProblemDomain& a_domain) const;
186 
187  ///
188  /**
189  Return all the vofs in the list, using the input
190  intvect for the gridIndex
191  */
193  getVoFs(const IntVect& a_iv) const;
194 
195  ///
196  const GraphNode& operator=(const GraphNode& ebiin);
197 
198  ///
199  GraphNode(const GraphNode& ebiin);
200 
201  ///
202  /**
203  Returns the corresponding set of VoFs from the next finer
204  EBGraph (factor of two refinement). The result is only
205  defined if this {\tt EBGraph} was defined by coarsening.
206  */
207  Vector<VolIndex> refine(const VolIndex& a_coarVoF) const;
208 
209  ///
210  /**
211  Returns the corresponding VoF from the next coarser
212  EBGraph (same solution location, different index space, factor
213  of two refinement ratio).
214  */
215  VolIndex coarsen(const VolIndex& a_fineVoF) const;
216 
217  ///
218  /**
219  */
220  void addIrregularNode(const GraphNodeImplem& a_nodein, int cellIndex);
221  ///
222  /**
223  */
224  void addIrregularNode(const GraphNodeImplem& a_nodein);
225 
226  ///
227  /**
228  Get all sets of connected vofs within the box (used in coarsening)
229  */
230  Vector<Vector<VolIndex> > getVoFSets(const Box& a_box) const;
231 
232  ///
233  int linearSize() const;
234 
235  ///
236  void linearOut(void* buffer ) const;
237 
238  ///
239  void linearIn(void* buffer );
240 
241  /// internal use only
242  inline void setDefaults();
243 
244  void* alloc();
245  ///
246  /**
247  The connectivity data at this point.
248  If m_cellList == 0, node is covered.
249  If m_cellList == 1, node is regular and parent is single-valued.
250  otherwise, it is a real list (node may still be regular).
251  */
253 
254  static BArena s_Arena;
255 };
256 
257 /* Inline functions */
258 /*******************************/
260 {
261  clear();
262 }
263 
264 /*******************************/
265 inline bool GraphNode::isCovered() const
266 {
267  return (m_cellList == ((Vector<GraphNodeImplem>*) 0));
268 }
269 
270 /*******************************/
271 inline bool GraphNode::isRegular() const
272 {
273  return (isRegularWithSingleValuedParent() ||
274  isRegularWithMultiValuedParent());
275 }
276 
277 /*******************************/
279 {
280  return (m_cellList == ((Vector<GraphNodeImplem>*) 1));
281 }
282 
283 /*******************************/
285 {
286  return (((m_cellList != ((Vector<GraphNodeImplem>*) 0)) &&
287  ((*m_cellList).size() == 1) &&
288  ((*m_cellList)[0]).m_isRegular));
289 }
290 
291 /*******************************/
292 inline bool GraphNode::hasValidCellList() const
293 {
294  return (!isCovered() && !isRegularWithSingleValuedParent());
295 }
296 
297 /*******************************/
298 inline bool GraphNode::isIrregular() const
299 {
300  return ((!isRegular()) && (!isCovered()));
301 }
302 
303 /*******************************/
305 {
306  m_cellList = (Vector<GraphNodeImplem>*)1;
307 }
308 
309 /*******************************/
311 {
312  setDefaults();
313 }
314 
315 /*******************************/
316 inline void GraphNode::clear()
317 {
318  if (hasValidCellList())
319  {
320  // delete m_cellList;
321  m_cellList->~Vector<GraphNodeImplem>();
322  s_Arena.free(m_cellList);
323 #ifdef CH_USE_MEMORY_TRACKING
324  s_Arena.bytes -= sizeof(Vector<GraphNodeImplem>);
325  CH_assert(s_Arena.bytes >= 0);
326 #endif
327  }
328  setDefaults();
329 }
330 
331 /*******************************/
333 {
334  clear();
335  m_cellList = (Vector<GraphNodeImplem>*) 1;
336 }
337 
338 /*******************************/
340 {
341  clear();
342  m_cellList = (Vector<GraphNodeImplem>*) 0;
343 }
344 
345 /*******************************/
347  : m_isRegular(false),
348  m_isValid(true),
349  m_coarserNode(-1),
350  m_nodeInd(-1)
351 {
352 }
353 
354 /*******************************/
356 {
357 }
358 
359 /*******************************/
360 inline int GraphNodeImplem::index(int a_idir,
361  Side::LoHiSide a_sd) const
362 {
363  CH_assert(a_idir >= 0 && a_idir < SpaceDim);
364  return a_idir + a_sd*CH_SPACEDIM;
365 }
366 
367 /*
368  if (a_sd == Side::Lo)
369  {
370  retval = a_idir;
371  }
372  else
373  {
374  retval = a_idir + SpaceDim;
375  }
376  return retval;
377 }
378 */
379 
380 #include "NamespaceFooter.H"
381 
382 #endif
int linearSize() const
bool isCovered() const
Definition: GraphNode.H:265
void linearIn(void *buffer)
#define CH_SPACEDIM
Definition: SPACE.H:52
#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:130
bool m_isValid
Used to mark a GraphNode as invalid - used in getting connected components of the graph...
Definition: GraphNode.H:51
GraphNodeImplem & operator=(const GraphNodeImplem &a_impin)
void defineAsCovered()
Definition: GraphNode.H:339
int m_coarserNode
Cell index of this vof is the index into the vector.
Definition: GraphNode.H:63
bool isRegular() const
Definition: GraphNode.H:271
~GraphNodeImplem()
Definition: GraphNode.H:355
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:39
int m_nodeInd
Index into node vector (for construction).
Definition: GraphNode.H:66
~GraphNode()
Definition: GraphNode.H:259
IndexTM< T, N > coarsen(const IndexTM< T, N > &a_p, T a_s)
Definition: IndexTMI.H:432
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:360
GraphNode()
Definition: GraphNode.H:310
void setDefaults()
internal use only
Definition: GraphNode.H:304
bool isRegularWithMultiValuedParent() const
Definition: GraphNode.H:284
GraphNodeImplem()
Definition: GraphNode.H:346
LoHiSide
Definition: LoHiSide.H:27
bool isIrregular() const
Definition: GraphNode.H:298
void clear()
Definition: GraphNode.H:316
void linearOut(void *buffer) const
static BArena s_Arena
Definition: GraphNode.H:254
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:278
Volume of Fluid Index.
Definition: VolIndex.H:31
Vector< int > m_arc[2 *SpaceDim]
Definition: GraphNode.H:58
void defineAsRegular()
Definition: GraphNode.H:332
Vector< GraphNodeImplem > * m_cellList
Definition: GraphNode.H:252
Definition: GraphNode.H:90
bool hasValidCellList() const
Definition: GraphNode.H:292