00001 #ifdef CH_LANG_CC
00002
00003
00004
00005
00006
00007
00008
00009 #endif
00010
00011 #ifndef _MULTISPHEREIF_H_
00012 #define _MULTISPHEREIF_H_
00013
00014 #include "MayDay.H"
00015 #include "RealVect.H"
00016 #include "RefCountedPtr.H"
00017
00018 #include "BaseIF.H"
00019 #include "ComplementIF.H"
00020
00021 #include "NamespaceHeader.H"
00022
00023 class RealBox
00024 {
00025 public:
00026 RealBox()
00027 {
00028 m_lo = -RealVect::Unit;
00029 m_hi = RealVect::Zero;
00030 };
00031
00032 RealBox(const RealVect& a_lo,
00033 const RealVect& a_hi)
00034 {
00035 m_lo = a_lo;
00036 m_hi = a_hi;
00037 };
00038
00039 void operator=(const RealBox& a_realBox)
00040 {
00041 m_lo = a_realBox.m_lo;
00042 m_hi = a_realBox.m_hi;
00043 };
00044
00045 virtual ~RealBox()
00046 {
00047 };
00048
00049 virtual void define(const RealVect& a_lo,
00050 const RealVect& a_hi)
00051 {
00052 m_lo = a_lo;
00053 m_hi = a_hi;
00054 };
00055
00056 bool contains(const RealVect& a_point)
00057 {
00058 bool inside = true;
00059
00060 for (int idir = 0; idir < SpaceDim; idir++)
00061 {
00062 if (a_point[idir] < m_lo[idir] || a_point[idir] > m_hi[idir])
00063 {
00064 inside = false;
00065 break;
00066 }
00067 }
00068
00069 return inside;
00070 };
00071
00072 RealVect size() const
00073 {
00074 return (m_hi - m_lo);
00075 };
00076
00077 const RealVect& getLo() const
00078 {
00079 return m_lo;
00080 };
00081
00082 RealVect getLo()
00083 {
00084 return m_lo;
00085 };
00086
00087 const RealVect& getHi() const
00088 {
00089 return m_hi;
00090 };
00091
00092 RealVect getHi()
00093 {
00094 return m_hi;
00095 };
00096
00097 void setLo(const RealVect& a_lo)
00098 {
00099 m_lo = a_lo;
00100 };
00101
00102 void setHi(const RealVect& a_hi)
00103 {
00104 m_hi = a_hi;
00105 };
00106
00107 protected:
00108 RealVect m_lo;
00109 RealVect m_hi;
00110 };
00111
00112 class SphereTree
00113 {
00114 public:
00115 SphereTree(const RealBox& a_bbox,
00116 const Vector<Real>& a_radii,
00117 const Vector<RealVect>& a_centers);
00118
00119 virtual ~SphereTree()
00120 {
00121 if (m_left != NULL) {
00122 delete m_left;
00123 }
00124
00125 if (m_right != NULL) {
00126 delete m_right;
00127 }
00128 };
00129
00130 const SphereTree& findNode(const RealVect& a_point) const
00131 {
00132 if (m_numSpheres != 0)
00133 {
00134 return *this;
00135 }
00136 else if (m_left->m_bbox.contains(a_point))
00137 {
00138 return m_left->findNode(a_point);
00139 }
00140 else if (m_right->m_bbox.contains(a_point))
00141 {
00142 return m_right->findNode(a_point);
00143 }
00144 else
00145 {
00146 pout() << "SphereTree::findNode - " << a_point
00147 << " not contained in " << m_bbox.getLo()
00148 << " - " << m_bbox.getHi()
00149 << endl;
00150
00151 MayDay::Error("SphereTree::findNode - Couldn't find a node containing the given point");
00152 }
00153 };
00154
00155 const int& getNumSpheres() const
00156 {
00157 return m_numSpheres;
00158 };
00159
00160 int getNumSpheres()
00161 {
00162 return m_numSpheres;
00163 };
00164
00165 const Vector<Real>& getRadii() const
00166 {
00167 return m_radii;
00168 };
00169
00170 Vector<Real> getRadii()
00171 {
00172 return m_radii;
00173 };
00174
00175 const Vector<RealVect>& getCenters() const
00176 {
00177 return m_centers;
00178 };
00179
00180 Vector<RealVect> getCenters()
00181 {
00182 return m_centers;
00183 };
00184
00185 protected:
00186 RealBox m_bbox;
00187
00188 int m_numSpheres;
00189 Vector<Real> m_radii;
00190 Vector<RealVect> m_centers;
00191
00192 SphereTree* m_left;
00193 SphereTree* m_right;
00194
00195 private:
00196 SphereTree()
00197 {
00198 MayDay::Abort("SphereTree uses strong construction");
00199 }
00200
00201 void operator=(const SphereTree& a_inputIF)
00202 {
00203 MayDay::Abort("SphereTree doesn't allow assignment");
00204 }
00205 };
00206
00207
00208
00209
00210
00211 class MultiSphereIF: public BaseIF
00212 {
00213 public:
00214
00215
00216
00217
00218
00219 MultiSphereIF(const Vector<Real>& a_radii,
00220 const Vector<RealVect>& a_centers,
00221 const bool& a_inside);
00222
00223 MultiSphereIF(const int& a_numSpheres,
00224 const bool& a_inside,
00225 const RealBox& a_bbox,
00226 RefCountedPtr<SphereTree> a_sphereTree);
00227
00228
00229 virtual ~MultiSphereIF();
00230
00231
00232
00233
00234
00235 virtual Real value(const IndexTM<int,GLOBALDIM> & a_partialDerivative,
00236 const IndexTM<Real,GLOBALDIM>& a_point) const;
00237
00238
00239
00240
00241
00242 virtual Real value(const RealVect& a_point) const;
00243
00244 virtual BaseIF* newImplicitFunction() const;
00245
00246 protected:
00247 void partitionSpace(const Vector<Real>& a_radii,
00248 const Vector<RealVect>& a_centers);
00249
00250 int m_numSpheres;
00251 bool m_inside;
00252
00253 RealBox m_bbox;
00254
00255 RefCountedPtr<SphereTree> m_sphereTree;
00256
00257 private:
00258 MultiSphereIF()
00259 {
00260 MayDay::Abort("MultiSphereIF uses strong construction");
00261 }
00262
00263 MultiSphereIF(const MultiSphereIF& a_inputIF)
00264 {
00265 MayDay::Abort("MultiSphereIF doesn't allow copy construction");
00266 }
00267
00268 void operator=(const MultiSphereIF& a_inputIF)
00269 {
00270 MayDay::Abort("MultiSphereIF doesn't allow assignment");
00271 }
00272 };
00273
00274 #include "NamespaceFooter.H"
00275 #endif