createPolyBoundary.C
Go to the documentation of this file.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
00031
00032
00033
00034
00035
00036
00037 #include "meshReader.H"
00038 #include "Time.H"
00039 #include "polyPatch.H"
00040 #include "emptyPolyPatch.H"
00041 #include "preservePatchTypes.H"
00042
00043
00044
00045 void Foam::meshReader::addPolyBoundaryFace
00046 (
00047 const label cellId,
00048 const label cellFaceId,
00049 const label nCreatedFaces
00050 )
00051 {
00052 #ifdef DEBUG_BOUNDARY
00053 Info<< nCreatedFaces
00054 << " add bnd for cell " << cellId
00055 << " face " << cellFaceId
00056 << " (original cell " << origCellId_[cellId] << ")"
00057 << endl;
00058 #endif
00059
00060
00061 const face& thisFace = cellFaces_[cellId][cellFaceId];
00062
00063
00064 if (cellPolys_[cellId][cellFaceId] > nInternalFaces_)
00065 {
00066 Info<< "meshReader::createPolyBoundary(): "
00067 << "Problem with face: " << thisFace << endl
00068 << "Probably multiple definitions "
00069 << "of a single boundary face." << endl
00070 << endl;
00071 }
00072 else if (cellPolys_[cellId][cellFaceId] >= 0)
00073 {
00074 Info<< "meshReader::createPolyBoundary(): "
00075 << "Problem with face: " << thisFace << endl
00076 << "Probably trying to define a boundary face "
00077 << "on a previously matched internal face." << endl
00078 << "Internal face: "
00079 << meshFaces_[cellPolys_[cellId][cellFaceId]]
00080 << endl;
00081 }
00082
00083 meshFaces_[nCreatedFaces] = thisFace;
00084 cellPolys_[cellId][cellFaceId] = nCreatedFaces;
00085 }
00086
00087
00088 void Foam::meshReader::addPolyBoundaryFace
00089 (
00090 const cellFaceIdentifier& identifier,
00091 const label nCreatedFaces
00092 )
00093 {
00094 addPolyBoundaryFace(identifier.cell, identifier.face, nCreatedFaces);
00095 }
00096
00097
00098
00099
00100 void Foam::meshReader::createPolyBoundary()
00101 {
00102 label nBoundaryFaces = 0;
00103 label nMissingFaces = 0;
00104 label nInterfaces = 0;
00105
00106 const faceListList& cFaces = cellFaces();
00107
00108
00109 forAll(cellPolys_, cellI)
00110 {
00111 cell& curCell = cellPolys_[cellI];
00112
00113 forAll(curCell, fI)
00114 {
00115 if (curCell[fI] < 0)
00116 {
00117 nMissingFaces++;
00118 }
00119 }
00120 }
00121
00122 forAll(boundaryIds_, patchI)
00123 {
00124 nBoundaryFaces += boundaryIds_[patchI].size();
00125 }
00126
00127 Info<< nl
00128 << "There are " << nMissingFaces
00129 << " faces to be patched and " << nBoundaryFaces
00130 << " specified - collect missed boundaries to final patch" << endl;
00131
00132 patchStarts_.setSize(boundaryIds_.size());
00133 patchSizes_.setSize(boundaryIds_.size());
00134
00135 label nCreatedFaces = nInternalFaces_;
00136 label baffleOffset = cFaces.size();
00137 interfaces_.setSize(baffleIds_.size());
00138 nBoundaryFaces = 0;
00139
00140 forAll(boundaryIds_, patchI)
00141 {
00142 const List<cellFaceIdentifier>& idList = boundaryIds_[patchI];
00143
00144 patchStarts_[patchI] = nCreatedFaces;
00145
00146
00147 if (patchPhysicalTypes_[patchI] == "baffle")
00148 {
00149 label count = 0;
00150
00151 for (label side = 0; side < 2; ++side)
00152 {
00153 label position = nInterfaces;
00154
00155 forAll(idList, bndI)
00156 {
00157 label baffleI = idList[bndI].cell - baffleOffset;
00158
00159 if
00160 (
00161 baffleI >= 0
00162 && baffleI < baffleFaces_.size()
00163 && baffleIds_[baffleI].size()
00164 )
00165 {
00166 addPolyBoundaryFace
00167 (
00168 baffleIds_[baffleI][side],
00169 nCreatedFaces
00170 );
00171
00172
00173 if (side == 1)
00174 {
00175 baffleIds_[baffleI].clear();
00176 }
00177
00178 interfaces_[position][side] = nCreatedFaces;
00179
00180 nBoundaryFaces++;
00181 nCreatedFaces++;
00182 position++;
00183 count++;
00184 }
00185 }
00186 }
00187
00188 nInterfaces += (count - (count % 2)) / 2;
00189 }
00190 else if (patchPhysicalTypes_[patchI] == "monitoring")
00191 {
00192
00193 List<label> monitoring(idList.size());
00194
00195 label monitorI = 0;
00196 forAll(idList, bndI)
00197 {
00198 label cellId = idList[bndI].cell;
00199 label faceId = idList[bndI].face;
00200
00201
00202 if (cellId < baffleOffset)
00203 {
00204 label faceNr = cellPolys_[cellId][faceId];
00205 if (faceNr >= 0)
00206 {
00207 monitoring[monitorI++] = faceNr;
00208 }
00209 }
00210 }
00211
00212 monitoringSets_.insert(patchNames_[patchI], monitoring);
00213 }
00214 else
00215 {
00216 forAll(idList, bndI)
00217 {
00218
00219 if (idList[bndI].cell < baffleOffset)
00220 {
00221 addPolyBoundaryFace
00222 (
00223 idList[bndI],
00224 nCreatedFaces
00225 );
00226
00227 nBoundaryFaces++;
00228 nCreatedFaces++;
00229 }
00230 }
00231 }
00232
00233 patchSizes_[patchI] = nCreatedFaces - patchStarts_[patchI];
00234 }
00235
00236
00237 Info<< "Missing faces added to patch after face "
00238 << nCreatedFaces << ":" <<endl;
00239 nMissingFaces = 0;
00240
00241
00242 for (label side = 0; side < 2; ++side)
00243 {
00244 label position = nInterfaces;
00245
00246 forAll(baffleIds_, baffleI)
00247 {
00248 if (baffleIds_[baffleI].size())
00249 {
00250
00251 addPolyBoundaryFace
00252 (
00253 baffleIds_[baffleI][side],
00254 nCreatedFaces
00255 );
00256
00257 interfaces_[position][side] = nCreatedFaces;
00258
00259
00260 if (side == 1)
00261 {
00262 baffleIds_[baffleI].clear();
00263 }
00264
00265 nMissingFaces++;
00266 nCreatedFaces++;
00267 position++;
00268 }
00269 }
00270 }
00271
00272 nInterfaces += (nMissingFaces - (nMissingFaces % 2)) / 2;
00273
00274
00275 forAll(cellPolys_, cellI)
00276 {
00277 const labelList& curFaces = cellPolys_[cellI];
00278
00279 forAll(curFaces, cellFaceI)
00280 {
00281 if (curFaces[cellFaceI] < 0)
00282 {
00283
00284 if (nMissingFaces < 4)
00285 {
00286 const face& thisFace = cFaces[cellI][cellFaceI];
00287
00288 Info<< " cell " << cellI << " face " << cellFaceI
00289 << " (original cell " << origCellId_[cellI] << ")"
00290 << " face: " << thisFace
00291 << endl;
00292 }
00293 else if (nMissingFaces == 5)
00294 {
00295 Info<< " ..." << nl << endl;
00296 }
00297
00298 addPolyBoundaryFace(cellI, cellFaceI, nCreatedFaces);
00299 nMissingFaces++;
00300 nCreatedFaces++;
00301 }
00302 }
00303 }
00304
00305 Info<< "Added " << nMissingFaces << " unmatched faces" << endl;
00306
00307 if (nMissingFaces > 0)
00308 {
00309 patchSizes_[patchSizes_.size() - 1] = nMissingFaces;
00310 }
00311 else
00312 {
00313 patchStarts_.setSize(patchStarts_.size() - 1);
00314 }
00315
00316
00317 meshFaces_.setSize(nCreatedFaces);
00318
00319
00320
00321 labelList markupFaces(meshFaces_.size(), 0);
00322
00323 forAll(cellPolys_, cellI)
00324 {
00325 const labelList& curFaces = cellPolys_[cellI];
00326
00327 forAll(curFaces, faceI)
00328 {
00329 markupFaces[curFaces[faceI]]++;
00330 }
00331 }
00332
00333 for (label i = nInternalFaces_; i < markupFaces.size(); i++)
00334 {
00335 markupFaces[i]++;
00336 }
00337
00338 label nProblemFaces = 0;
00339
00340 forAll(markupFaces, faceI)
00341 {
00342 if (markupFaces[faceI] != 2)
00343 {
00344 const face& problemFace = meshFaces_[faceI];
00345
00346 Info<< "meshReader::createPolyBoundary() : "
00347 << "problem with face " << faceI << ": addressed "
00348 << markupFaces[faceI] << " times (should be 2!). Face: "
00349 << problemFace << endl;
00350
00351 nProblemFaces++;
00352 }
00353 }
00354
00355 if (nProblemFaces > 0)
00356 {
00357 Info<< "Number of incorrectly matched faces: "
00358 << nProblemFaces << endl;
00359 }
00360
00361
00362 if (nInterfaces < interfaces_.size())
00363 {
00364 interfaces_.setSize(nInterfaces);
00365 }
00366
00367 Info<< "Number of boundary faces: " << nBoundaryFaces << nl
00368 << "Total number of faces: " << nCreatedFaces << nl
00369 << "Number of interfaces: " << nInterfaces << endl;
00370 }
00371
00372
00373
00374
00375 Foam::List<Foam::polyPatch*>
00376 Foam::meshReader::polyBoundaryPatches(const polyMesh& mesh)
00377 {
00378 label nUsed = 0, nEmpty = 0;
00379 label nPatches = patchStarts_.size();
00380
00381
00382 labelList oldToNew = identity(nPatches);
00383 forAll(patchSizes_, patchI)
00384 {
00385 if (patchSizes_[patchI] > 0)
00386 {
00387 oldToNew[patchI] = nUsed++;
00388 }
00389 else
00390 {
00391 nEmpty++;
00392 oldToNew[patchI] = nPatches - nEmpty;
00393 }
00394 }
00395
00396 nPatches = nUsed;
00397
00398 if (nEmpty)
00399 {
00400 Info<< "Removing " << nEmpty << " empty patches" << endl;
00401
00402 inplaceReorder(oldToNew, patchTypes_);
00403 inplaceReorder(oldToNew, patchNames_);
00404 inplaceReorder(oldToNew, patchStarts_);
00405 inplaceReorder(oldToNew, patchSizes_);
00406 }
00407
00408 patchTypes_.setSize(nPatches);
00409 patchNames_.setSize(nPatches);
00410 patchStarts_.setSize(nPatches);
00411 patchSizes_.setSize(nPatches);
00412
00413
00414 List<polyPatch*> p(nPatches);
00415
00416
00417 word defaultFacesType(emptyPolyPatch::typeName);
00418
00419
00420 preservePatchTypes
00421 (
00422 mesh,
00423 mesh.instance(),
00424 mesh.meshDir(),
00425 patchNames_,
00426 patchTypes_,
00427 "defaultFaces",
00428 defaultFacesType,
00429 patchPhysicalTypes_
00430 );
00431
00432 forAll(patchStarts_, patchI)
00433 {
00434 p[patchI] = polyPatch::New
00435 (
00436 patchTypes_[patchI],
00437 patchNames_[patchI],
00438 patchSizes_[patchI],
00439 patchStarts_[patchI],
00440 patchI,
00441 mesh.boundaryMesh()
00442 ).ptr();
00443 }
00444
00445 return p;
00446 }
00447
00448
00449
Copyright © 2000-2009 OpenCFD Ltd