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