00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <iostream>
00027
00028 #include <BoxDomain.H>
00029
00030 BoxDomain&
00031 BoxDomain::intersect (const Box& b)
00032 {
00033 BoxList::intersect(b);
00034 BL_ASSERT(ok());
00035 return *this;
00036 }
00037
00038 void
00039 BoxLib::intersect (BoxDomain& dest,
00040 const BoxDomain& fin,
00041 const Box& b)
00042 {
00043 dest = fin;
00044 dest.intersect(b);
00045 }
00046
00047 BoxDomain&
00048 BoxDomain::refine (int ratio)
00049 {
00050 BoxList::refine(ratio);
00051 BL_ASSERT(ok());
00052 return *this;
00053 }
00054
00055 void
00056 BoxLib::refine (BoxDomain& dest,
00057 const BoxDomain& fin,
00058 int ratio)
00059 {
00060 dest = fin;
00061 dest.refine(ratio);
00062 }
00063
00064 void
00065 BoxLib::accrete (BoxDomain& dest,
00066 const BoxDomain& fin,
00067 int sz)
00068 {
00069 dest = fin;
00070 dest.accrete(sz);
00071 }
00072
00073 void
00074 BoxLib::coarsen (BoxDomain& dest,
00075 const BoxDomain& fin,
00076 int ratio)
00077 {
00078 dest = fin;
00079 dest.coarsen(ratio);
00080 }
00081
00082 BoxDomain&
00083 BoxDomain::complementIn (const Box& b,
00084 const BoxDomain& bl)
00085 {
00086 BoxList::complementIn(b,bl);
00087 BL_ASSERT(ok());
00088 return *this;
00089 }
00090
00091 BoxDomain
00092 BoxLib::complementIn (const Box& b,
00093 const BoxDomain& bl)
00094 {
00095 BoxDomain result;
00096 result.complementIn(b,bl);
00097 return result;
00098 }
00099
00100 BoxList
00101 BoxDomain::boxList () const
00102 {
00103 return BoxList(*this);
00104 }
00105
00106 bool
00107 BoxDomain::operator== (const BoxDomain& rhs) const
00108 {
00109 return BoxList::operator==(rhs);
00110 }
00111
00112 bool
00113 BoxDomain::operator!= (const BoxDomain& rhs) const
00114 {
00115 return !BoxList::operator==(rhs);
00116 }
00117
00118 BoxDomain::BoxDomain ()
00119 :
00120 BoxList(IndexType::TheCellType())
00121 {}
00122
00123 BoxDomain::BoxDomain (IndexType _ctype)
00124 :
00125 BoxList(_ctype)
00126 {}
00127
00128 BoxDomain::BoxDomain (const Box& bx)
00129 :
00130 BoxList(bx.ixType())
00131 {
00132 add(bx);
00133 }
00134
00135 void
00136 BoxDomain::add (const Box& b)
00137 {
00138 BL_ASSERT(b.ixType() == ixType());
00139
00140 std::list<Box> check;
00141 check.push_back(b);
00142 for (iterator bli = lbox.begin(); bli != lbox.end(); ++bli)
00143 {
00144 std::list<Box> tmp;
00145 for (iterator ci = check.begin(); ci != check.end(); )
00146 {
00147 if (ci->intersects(*bli))
00148 {
00149
00150
00151
00152
00153
00154 BoxList tmpbl(BoxLib::boxDiff(*ci, *bli));
00155 tmp.splice(tmp.end(), tmpbl.listBox());
00156 check.erase(ci++);
00157 }
00158 else
00159 {
00160 ++ci;
00161 }
00162 }
00163 check.splice(check.end(), tmp);
00164 }
00165
00166
00167
00168
00169 lbox.splice(lbox.end(), check);
00170 BL_ASSERT(ok());
00171 }
00172
00173 void
00174 BoxDomain::add (const BoxList& bl)
00175 {
00176 for (BoxList::const_iterator bli = bl.begin(); bli != bl.end(); ++bli)
00177 add(*bli);
00178 }
00179
00180 BoxDomain&
00181 BoxDomain::rmBox (const Box& b)
00182 {
00183 BL_ASSERT(b.ixType() == ixType());
00184
00185 std::list<Box> tmp;
00186
00187 for (std::list<Box>::iterator bli = lbox.begin(); bli != lbox.end(); )
00188 {
00189 if (bli->intersects(b))
00190 {
00191 BoxList tmpbl(BoxLib::boxDiff(*bli,b));
00192 tmp.splice(tmp.end(), tmpbl.listBox());
00193 lbox.erase(bli++);
00194 }
00195 else
00196 {
00197 ++bli;
00198 }
00199 }
00200 lbox.splice(lbox.end(), tmp);
00201 return *this;
00202 }
00203
00204 bool
00205 BoxDomain::ok () const
00206 {
00207
00208
00209
00210 bool status = BoxList::ok();
00211 if (status)
00212 {
00213
00214
00215
00216 for (const_iterator bli = begin(); bli != end(); ++bli)
00217 {
00218 const_iterator blii = bli; ++blii;
00219 for ( ; blii != end(); ++blii)
00220 {
00221 if (bli->intersects(*blii))
00222 {
00223 std::cout << "Invalid DOMAIN, boxes overlap" << '\n'
00224 << "b1 = " << *bli << '\n'
00225 << "b2 = " << *blii << '\n';
00226 status = false;
00227 }
00228 }
00229 }
00230 }
00231 return status;
00232 }
00233
00234 BoxDomain&
00235 BoxDomain::accrete (int sz)
00236 {
00237 BoxList bl(*this);
00238 bl.accrete(sz);
00239 clear();
00240 add(bl);
00241 return *this;
00242 }
00243
00244 BoxDomain&
00245 BoxDomain::coarsen (int ratio)
00246 {
00247 BoxList bl(*this);
00248 bl.coarsen(ratio);
00249 clear();
00250 add(bl);
00251 return *this;
00252 }
00253
00254 std::ostream&
00255 operator<< (std::ostream& os,
00256 const BoxDomain& bd)
00257 {
00258 os << "(BoxDomain " << bd.boxList() << ")" << std::flush;
00259 if (os.fail())
00260 BoxLib::Error("operator<<(ostream&,BoxDomain&) failed");
00261 return os;
00262 }
00263