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
00027
00028
00029
00030 #include "cellZone.H"
00031 #include "addToRunTimeSelectionTable.H"
00032 #include "cellZoneMesh.H"
00033 #include "polyMesh.H"
00034 #include "primitiveMesh.H"
00035 #include "IOstream.H"
00036 #include "demandDrivenData.H"
00037
00038
00039
00040 namespace Foam
00041 {
00042 defineTypeNameAndDebug(cellZone, 0);
00043
00044 defineRunTimeSelectionTable(cellZone, dictionary);
00045 addToRunTimeSelectionTable(cellZone, cellZone, dictionary);
00046 }
00047
00048
00049
00050 const Foam::Map<Foam::label>& Foam::cellZone::cellLookupMap() const
00051 {
00052 if (!cellLookupMapPtr_)
00053 {
00054 calcCellLookupMap();
00055 }
00056
00057 return *cellLookupMapPtr_;
00058 }
00059
00060
00061 void Foam::cellZone::calcCellLookupMap() const
00062 {
00063 if (debug)
00064 {
00065 Info<< "void cellZone::calcCellLookupMap() const : "
00066 << "Calculating cell lookup map"
00067 << endl;
00068 }
00069
00070 if (cellLookupMapPtr_)
00071 {
00072 FatalErrorIn
00073 (
00074 "void cellZone::calcCellLookupMap() const"
00075 ) << "cell lookup map already calculated"
00076 << abort(FatalError);
00077 }
00078
00079 const labelList& addr = *this;
00080
00081 cellLookupMapPtr_ = new Map<label>(2*addr.size());
00082 Map<label>& clm = *cellLookupMapPtr_;
00083
00084 forAll (addr, cellI)
00085 {
00086 clm.insert(addr[cellI], cellI);
00087 }
00088
00089 if (debug)
00090 {
00091 Info<< "void cellZone::calcCellLookupMap() const : "
00092 << "Finished calculating cell lookup map"
00093 << endl;
00094 }
00095 }
00096
00097
00098
00099
00100
00101 Foam::cellZone::cellZone
00102 (
00103 const word& name,
00104 const labelList& addr,
00105 const label index,
00106 const cellZoneMesh& zm
00107 )
00108 :
00109 labelList(addr),
00110 name_(name),
00111 index_(index),
00112 zoneMesh_(zm),
00113 cellLookupMapPtr_(NULL)
00114 {}
00115
00116
00117 Foam::cellZone::cellZone
00118 (
00119 const word& name,
00120 const Xfer<labelList>& addr,
00121 const label index,
00122 const cellZoneMesh& zm
00123 )
00124 :
00125 labelList(addr),
00126 name_(name),
00127 index_(index),
00128 zoneMesh_(zm),
00129 cellLookupMapPtr_(NULL)
00130 {}
00131
00132
00133
00134 Foam::cellZone::cellZone
00135 (
00136 const word& name,
00137 const dictionary& dict,
00138 const label index,
00139 const cellZoneMesh& zm
00140 )
00141 :
00142 labelList(dict.lookup("cellLabels")),
00143 name_(name),
00144 index_(index),
00145 zoneMesh_(zm),
00146 cellLookupMapPtr_(NULL)
00147 {}
00148
00149
00150
00151
00152 Foam::cellZone::cellZone
00153 (
00154 const cellZone& cz,
00155 const labelList& addr,
00156 const label index,
00157 const cellZoneMesh& zm
00158 )
00159 :
00160 labelList(addr),
00161 name_(cz.name()),
00162 index_(index),
00163 zoneMesh_(zm),
00164 cellLookupMapPtr_(NULL)
00165 {}
00166
00167 Foam::cellZone::cellZone
00168 (
00169 const cellZone& cz,
00170 const Xfer<labelList>& addr,
00171 const label index,
00172 const cellZoneMesh& zm
00173 )
00174 :
00175 labelList(addr),
00176 name_(cz.name()),
00177 index_(index),
00178 zoneMesh_(zm),
00179 cellLookupMapPtr_(NULL)
00180 {}
00181
00182
00183
00184
00185 Foam::cellZone::~cellZone()
00186 {
00187 clearAddressing();
00188 }
00189
00190
00191
00192
00193 Foam::label Foam::cellZone::whichCell(const label globalCellID) const
00194 {
00195 const Map<label>& clm = cellLookupMap();
00196
00197 Map<label>::const_iterator clmIter = clm.find(globalCellID);
00198
00199 if (clmIter == clm.end())
00200 {
00201 return -1;
00202 }
00203 else
00204 {
00205 return clmIter();
00206 }
00207 }
00208
00209
00210 const Foam::cellZoneMesh& Foam::cellZone::zoneMesh() const
00211 {
00212 return zoneMesh_;
00213 }
00214
00215
00216 void Foam::cellZone::clearAddressing()
00217 {
00218 deleteDemandDrivenData(cellLookupMapPtr_);
00219 }
00220
00221
00222 bool Foam::cellZone::checkDefinition(const bool report) const
00223 {
00224 const labelList& addr = *this;
00225
00226 bool boundaryError = false;
00227
00228 forAll(addr, i)
00229 {
00230 if (addr[i] < 0 || addr[i] >= zoneMesh_.mesh().nCells())
00231 {
00232 boundaryError = true;
00233
00234 if (report)
00235 {
00236 SeriousErrorIn
00237 (
00238 "bool cellZone::checkDefinition("
00239 "const bool report) const"
00240 ) << "Zone " << name()
00241 << " contains invalid cell label " << addr[i] << nl
00242 << "Valid cell labels are 0.."
00243 << zoneMesh_.mesh().nCells()-1 << endl;
00244 }
00245 }
00246 }
00247 return boundaryError;
00248 }
00249
00250
00251 void Foam::cellZone::write(Ostream& os) const
00252 {
00253 os << nl << name()
00254 << nl << static_cast<const labelList&>(*this);
00255 }
00256
00257
00258 void Foam::cellZone::writeDict(Ostream& os) const
00259 {
00260 os << nl << name() << nl << token::BEGIN_BLOCK << nl
00261 << " type " << type() << token::END_STATEMENT << nl;
00262
00263 writeEntry("cellLabels", os);
00264
00265 os << token::END_BLOCK << endl;
00266 }
00267
00268
00269
00270
00271 void Foam::cellZone::operator=(const cellZone& cz)
00272 {
00273 clearAddressing();
00274 labelList::operator=(cz);
00275 }
00276
00277
00278 void Foam::cellZone::operator=(const labelList& addr)
00279 {
00280 clearAddressing();
00281 labelList::operator=(addr);
00282 }
00283
00284
00285
00286
00287 Foam::Ostream& Foam::operator<<(Ostream& os, const cellZone& p)
00288 {
00289 p.write(os);
00290 os.check("Ostream& operator<<(Ostream& f, const cellZone& p");
00291 return os;
00292 }
00293
00294
00295