Chombo + EB + MF  3.2
MultiSphereIF.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 #ifndef _MULTISPHEREIF_H_
12 #define _MULTISPHEREIF_H_
13 
14 #include "MayDay.H"
15 #include "RealVect.H"
16 #include "RefCountedPtr.H"
17 
18 #include "BaseIF.H"
19 #include "ComplementIF.H"
20 
21 #include "NamespaceHeader.H"
22 
23 class RealBox
24 {
25 public:
27  {
30  };
31 
32  RealBox(const RealVect& a_lo,
33  const RealVect& a_hi)
34  {
35  m_lo = a_lo;
36  m_hi = a_hi;
37  };
38 
39  void operator=(const RealBox& a_realBox)
40  {
41  m_lo = a_realBox.m_lo;
42  m_hi = a_realBox.m_hi;
43  };
44 
45  virtual ~RealBox()
46  {
47  };
48 
49  virtual void define(const RealVect& a_lo,
50  const RealVect& a_hi)
51  {
52  m_lo = a_lo;
53  m_hi = a_hi;
54  };
55 
56  bool contains(const RealVect& a_point)
57  {
58  bool inside = true;
59 
60  for (int idir = 0; idir < SpaceDim; idir++)
61  {
62  if (a_point[idir] < m_lo[idir] || a_point[idir] > m_hi[idir])
63  {
64  inside = false;
65  break;
66  }
67  }
68 
69  return inside;
70  };
71 
72  RealVect size() const
73  {
74  return (m_hi - m_lo);
75  };
76 
77  const RealVect& getLo() const
78  {
79  return m_lo;
80  };
81 
83  {
84  return m_lo;
85  };
86 
87  const RealVect& getHi() const
88  {
89  return m_hi;
90  };
91 
93  {
94  return m_hi;
95  };
96 
97  void setLo(const RealVect& a_lo)
98  {
99  m_lo = a_lo;
100  };
101 
102  void setHi(const RealVect& a_hi)
103  {
104  m_hi = a_hi;
105  };
106 
107 protected:
108  RealVect m_lo;
110 };
111 
113 {
114 public:
115  SphereTree(const RealBox& a_bbox,
116  const Vector<Real>& a_radii,
117  const Vector<RealVect>& a_centers);
118 
119  virtual ~SphereTree()
120  {
121  if (m_left != NULL) {
122  delete m_left;
123  }
124 
125  if (m_right != NULL) {
126  delete m_right;
127  }
128  };
129 
130  const SphereTree& findNode(const RealVect& a_point) const
131  {
132  if (m_numSpheres != 0)
133  {
134  return *this;
135  }
136  else if (m_left->m_bbox.contains(a_point))
137  {
138  return m_left->findNode(a_point);
139  }
140  else if (m_right->m_bbox.contains(a_point))
141  {
142  return m_right->findNode(a_point);
143  }
144  else
145  {
146  pout() << "SphereTree::findNode - " << a_point
147  << " not contained in " << m_bbox.getLo()
148  << " - " << m_bbox.getHi()
149  << endl;
150 
151  MayDay::Error("SphereTree::findNode - Couldn't find a node containing the given point");
152  }
153  };
154 
155  const int& getNumSpheres() const
156  {
157  return m_numSpheres;
158  };
159 
161  {
162  return m_numSpheres;
163  };
164 
165  const Vector<Real>& getRadii() const
166  {
167  return m_radii;
168  };
169 
171  {
172  return m_radii;
173  };
174 
176  {
177  return m_centers;
178  };
179 
181  {
182  return m_centers;
183  };
184 
185 protected:
186  RealBox m_bbox;
187 
191 
194 
195 private:
197  {
198  MayDay::Abort("SphereTree uses strong construction");
199  }
200 
201  void operator=(const SphereTree& a_inputIF)
202  {
203  MayDay::Abort("SphereTree doesn't allow assignment");
204  }
205 };
206 
207 ///
208 /**
209  This implicit function specifies a union of spheres.
210  */
211 class MultiSphereIF: public BaseIF
212 {
213 public:
214  ///
215  /**
216  Constructor specifying sphere radii (a_radii), centers (a_centers), and
217  whether the domain is on the inside (a_inside).
218  */
219  MultiSphereIF(const Vector<Real>& a_radii,
220  const Vector<RealVect>& a_centers,
221  const bool& a_inside);
222 
223  MultiSphereIF(const int& a_numSpheres,
224  const bool& a_inside,
225  const RealBox& a_bbox,
226  RefCountedPtr<SphereTree> a_sphereTree);
227 
228  /// Destructor
229  virtual ~MultiSphereIF();
230 
231  ///
232  /**
233  Return the value of the function at a_point.
234  */
235  virtual Real value(const IndexTM<int,GLOBALDIM> & a_partialDerivative,
236  const IndexTM<Real,GLOBALDIM>& a_point) const;
237 
238  ///
239  /**
240  Return the value of the function at a_point.
241  */
242  virtual Real value(const RealVect& a_point) const;
243 
244  virtual BaseIF* newImplicitFunction() const;
245 
246 protected:
247  void partitionSpace(const Vector<Real>& a_radii,
248  const Vector<RealVect>& a_centers);
249 
250  int m_numSpheres; // number of spheres
251  bool m_inside; // inside flag
252 
254 
256 
257 private:
259  {
260  MayDay::Abort("MultiSphereIF uses strong construction");
261  }
262 
263  MultiSphereIF(const MultiSphereIF& a_inputIF)
264  {
265  MayDay::Abort("MultiSphereIF doesn't allow copy construction");
266  }
267 
268  void operator=(const MultiSphereIF& a_inputIF)
269  {
270  MayDay::Abort("MultiSphereIF doesn't allow assignment");
271  }
272 };
273 
274 #include "NamespaceFooter.H"
275 #endif
std::ostream & pout()
Use this in place of std::cout for program output.
RealVect size() const
Definition: MultiSphereIF.H:72
Vector< RealVect > m_centers
Definition: MultiSphereIF.H:190
RealVect m_hi
Definition: MultiSphereIF.H:109
SphereTree * m_right
Definition: MultiSphereIF.H:193
const RealVect & getHi() const
Definition: MultiSphereIF.H:87
Definition: MultiSphereIF.H:112
RealBox(const RealVect &a_lo, const RealVect &a_hi)
Definition: MultiSphereIF.H:32
virtual void define(const RealVect &a_lo, const RealVect &a_hi)
Definition: MultiSphereIF.H:49
SphereTree * m_left
Definition: MultiSphereIF.H:192
RefCountedPtr< SphereTree > m_sphereTree
Definition: MultiSphereIF.H:255
void operator=(const MultiSphereIF &a_inputIF)
Definition: MultiSphereIF.H:268
Vector< Real > m_radii
Definition: MultiSphereIF.H:189
Vector< Real > getRadii()
Definition: MultiSphereIF.H:170
const int SpaceDim
Definition: SPACE.H:38
Definition: IndexTM.H:36
void operator=(const RealBox &a_realBox)
Definition: MultiSphereIF.H:39
static const RealVect Unit
Definition: RealVect.H:427
const RealVect & getLo() const
Definition: MultiSphereIF.H:77
RealVect m_lo
Definition: MultiSphereIF.H:105
bool m_inside
Definition: MultiSphereIF.H:251
Definition: BaseIF.H:32
static const RealVect Zero
Definition: RealVect.H:421
bool contains(const RealVect &a_point)
Definition: MultiSphereIF.H:56
MultiSphereIF()
Definition: MultiSphereIF.H:258
int m_numSpheres
Definition: MultiSphereIF.H:250
int m_numSpheres
Definition: MultiSphereIF.H:188
double Real
Definition: REAL.H:33
RealVect getHi()
Definition: MultiSphereIF.H:92
void setHi(const RealVect &a_hi)
Definition: MultiSphereIF.H:102
const SphereTree & findNode(const RealVect &a_point) const
Definition: MultiSphereIF.H:130
virtual ~SphereTree()
Definition: MultiSphereIF.H:119
RealVect getLo()
Definition: MultiSphereIF.H:82
void operator=(const SphereTree &a_inputIF)
Definition: MultiSphereIF.H:201
SphereTree()
Definition: MultiSphereIF.H:196
const int & getNumSpheres() const
Definition: MultiSphereIF.H:155
static void Error(const char *const a_msg=m_nullString, int m_exitCode=CH_DEFAULT_ERROR_CODE)
Print out message to cerr and exit with the specified exit code.
const Vector< Real > & getRadii() const
Definition: MultiSphereIF.H:165
A Real vector in SpaceDim-dimensional space.
Definition: RealVect.H:41
const Vector< RealVect > & getCenters() const
Definition: MultiSphereIF.H:175
void setLo(const RealVect &a_lo)
Definition: MultiSphereIF.H:97
virtual ~RealBox()
Definition: MultiSphereIF.H:45
Definition: MultiSphereIF.H:23
Vector< RealVect > getCenters()
Definition: MultiSphereIF.H:180
RealBox()
Definition: MultiSphereIF.H:26
Definition: MultiSphereIF.H:211
int getNumSpheres()
Definition: MultiSphereIF.H:160
MultiSphereIF(const MultiSphereIF &a_inputIF)
Definition: MultiSphereIF.H:263
RealBox m_bbox
Definition: MultiSphereIF.H:183
static void Abort(const char *const a_msg=m_nullString)
Print out message to cerr and exit via abort() (if serial) or MPI_Abort() (if parallel).
RealBox m_bbox
Definition: MultiSphereIF.H:253