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 #include "blockMesh.H"
00028 #include "Time.H"
00029 #include "preservePatchTypes.H"
00030 #include "emptyPolyPatch.H"
00031
00032
00033
00034 bool Foam::blockMesh::blockLabelsOK
00035 (
00036 const label blockLabel,
00037 const pointField& points,
00038 const cellShape& blockShape
00039 )
00040 {
00041 bool ok = true;
00042
00043 forAll(blockShape, blockI)
00044 {
00045 if (blockShape[blockI] < 0)
00046 {
00047 ok = false;
00048
00049 WarningIn
00050 (
00051 "bool Foam::blockMesh::blockLabelsOK"
00052 "(const label blockLabel, const pointField& points, "
00053 "const cellShape& blockShape)"
00054 ) << "block " << blockLabel
00055 << " point label " << blockShape[blockI]
00056 << " less than zero" << endl;
00057 }
00058 else if (blockShape[blockI] >= points.size())
00059 {
00060 ok = false;
00061
00062 WarningIn
00063 (
00064 "bool Foam::blockMesh::blockLabelsOK"
00065 "(const label blockLabel, const pointField& points, "
00066 "const cellShape& blockShape)"
00067 ) << "block " << blockLabel
00068 << " point label " << blockShape[blockI]
00069 << " larger than " << points.size() - 1
00070 << " the largest defined point label" << endl;
00071 }
00072 }
00073
00074 return ok;
00075 }
00076
00077
00078 bool Foam::blockMesh::patchLabelsOK
00079 (
00080 const label patchLabel,
00081 const pointField& points,
00082 const faceList& patchFaces
00083 )
00084 {
00085 bool ok = true;
00086
00087 forAll(patchFaces, faceI)
00088 {
00089 const labelList& f = patchFaces[faceI];
00090
00091 forAll(f, fp)
00092 {
00093 if (f[fp] < 0)
00094 {
00095 ok = false;
00096
00097 WarningIn
00098 (
00099 "bool Foam::blockMesh::patchLabelsOK(...)"
00100 ) << "patch " << patchLabel
00101 << " face " << faceI
00102 << " point label " << f[fp]
00103 << " less than zero" << endl;
00104 }
00105 else if (f[fp] >= points.size())
00106 {
00107 ok = false;
00108
00109 WarningIn
00110 (
00111 "bool Foam::blockMesh::patchLabelsOK(...)"
00112 ) << "patch " << patchLabel
00113 << " face " << faceI
00114 << " point label " << f[fp]
00115 << " larger than " << points.size() - 1
00116 << " the largest defined point label" << endl;
00117 }
00118 }
00119 }
00120
00121 return ok;
00122 }
00123
00124
00125
00126
00127 Foam::polyMesh* Foam::blockMesh::createTopology(IOdictionary& meshDescription)
00128 {
00129 bool topologyOK = true;
00130
00131 blockMesh& blocks = *this;
00132
00133 word defaultPatchName = "defaultFaces";
00134 word defaultPatchType = emptyPolyPatch::typeName;
00135
00136
00137
00138
00139 if (const dictionary* dictPtr = meshDescription.subDictPtr("defaultPatch"))
00140 {
00141 dictPtr->readIfPresent("name", defaultPatchName);
00142 dictPtr->readIfPresent("type", defaultPatchType);
00143 }
00144
00145 Info<< nl << "Creating blockCorners" << endl;
00146
00147
00148 pointField tmpBlockPoints(meshDescription.lookup("vertices"));
00149
00150 if (meshDescription.found("edges"))
00151 {
00152
00153 Info<< nl << "Creating curved edges" << endl;
00154
00155 ITstream& edgesStream(meshDescription.lookup("edges"));
00156
00157 label nEdges = 0;
00158
00159 token firstToken(edgesStream);
00160
00161 if (firstToken.isLabel())
00162 {
00163 nEdges = firstToken.labelToken();
00164 edges_.setSize(nEdges);
00165 }
00166 else
00167 {
00168 edgesStream.putBack(firstToken);
00169 }
00170
00171
00172 edgesStream.readBegin("edges");
00173
00174 nEdges = 0;
00175
00176 token lastToken(edgesStream);
00177 while
00178 (
00179 !(
00180 lastToken.isPunctuation()
00181 && lastToken.pToken() == token::END_LIST
00182 )
00183 )
00184 {
00185 if (edges_.size() <= nEdges)
00186 {
00187 edges_.setSize(nEdges + 1);
00188 }
00189
00190 edgesStream.putBack(lastToken);
00191
00192 edges_.set
00193 (
00194 nEdges,
00195 curvedEdge::New(tmpBlockPoints, edgesStream)
00196 );
00197
00198 nEdges++;
00199
00200 edgesStream >> lastToken;
00201 }
00202 edgesStream.putBack(lastToken);
00203
00204
00205 edgesStream.readEnd("edges");
00206 }
00207 else
00208 {
00209 Info<< nl << "There are no non-linear edges" << endl;
00210 }
00211
00212
00213 Info<< nl << "Creating blocks" << endl;
00214 {
00215 ITstream& blockDescriptorStream(meshDescription.lookup("blocks"));
00216
00217
00218 label nBlocks = 0;
00219
00220 token firstToken(blockDescriptorStream);
00221
00222 if (firstToken.isLabel())
00223 {
00224 nBlocks = firstToken.labelToken();
00225 blocks.setSize(nBlocks);
00226 }
00227 else
00228 {
00229 blockDescriptorStream.putBack(firstToken);
00230 }
00231
00232
00233 blockDescriptorStream.readBegin("blocks");
00234
00235 nBlocks = 0;
00236
00237 token lastToken(blockDescriptorStream);
00238 while
00239 (
00240 !(
00241 lastToken.isPunctuation()
00242 && lastToken.pToken() == token::END_LIST
00243 )
00244 )
00245 {
00246 if (blocks.size() <= nBlocks)
00247 {
00248 blocks.setSize(nBlocks + 1);
00249 }
00250
00251 blockDescriptorStream.putBack(lastToken);
00252
00253 blocks.set
00254 (
00255 nBlocks,
00256 new block
00257 (
00258 blockDescriptor
00259 (
00260 tmpBlockPoints,
00261 edges_,
00262 blockDescriptorStream
00263 )
00264 )
00265 );
00266
00267 topologyOK = topologyOK && blockLabelsOK
00268 (
00269 nBlocks,
00270 tmpBlockPoints,
00271 blocks[nBlocks].blockDef().blockShape()
00272 );
00273
00274 nBlocks++;
00275
00276 blockDescriptorStream >> lastToken;
00277 }
00278 blockDescriptorStream.putBack(lastToken);
00279
00280
00281 blockDescriptorStream.readEnd("blocks");
00282 }
00283
00284
00285 Info<< nl << "Creating patches" << endl;
00286
00287 faceListList tmpBlocksPatches;
00288 wordList patchNames;
00289 wordList patchTypes;
00290
00291 {
00292 ITstream& patchStream(meshDescription.lookup("patches"));
00293
00294
00295 label nPatches = 0;
00296
00297 token firstToken(patchStream);
00298
00299 if (firstToken.isLabel())
00300 {
00301 nPatches = firstToken.labelToken();
00302
00303 tmpBlocksPatches.setSize(nPatches);
00304 patchNames.setSize(nPatches);
00305 patchTypes.setSize(nPatches);
00306 }
00307 else
00308 {
00309 patchStream.putBack(firstToken);
00310 }
00311
00312
00313 patchStream.readBegin("patches");
00314
00315 nPatches = 0;
00316
00317 token lastToken(patchStream);
00318 while
00319 (
00320 !(
00321 lastToken.isPunctuation()
00322 && lastToken.pToken() == token::END_LIST
00323 )
00324 )
00325 {
00326 if (tmpBlocksPatches.size() <= nPatches)
00327 {
00328 tmpBlocksPatches.setSize(nPatches + 1);
00329 patchNames.setSize(nPatches + 1);
00330 patchTypes.setSize(nPatches + 1);
00331 }
00332
00333 patchStream.putBack(lastToken);
00334
00335 patchStream
00336 >> patchTypes[nPatches]
00337 >> patchNames[nPatches]
00338 >> tmpBlocksPatches[nPatches];
00339
00340
00341
00342 for (label i = 0; i < nPatches; i++)
00343 {
00344 if (patchNames[nPatches] == patchNames[i])
00345 {
00346 FatalErrorIn
00347 (
00348 "blockMesh::createTopology(IOdictionary&)"
00349 ) << "Duplicate patch " << patchNames[nPatches]
00350 << " at line " << patchStream.lineNumber()
00351 << ". Exiting !" << nl
00352 << exit(FatalError);
00353 }
00354 }
00355
00356 topologyOK = topologyOK && patchLabelsOK
00357 (
00358 nPatches,
00359 tmpBlockPoints,
00360 tmpBlocksPatches[nPatches]
00361 );
00362
00363 nPatches++;
00364
00365 patchStream >> lastToken;
00366 }
00367 patchStream.putBack(lastToken);
00368
00369
00370 patchStream.readEnd("patches");
00371 }
00372
00373
00374 if (!topologyOK)
00375 {
00376 FatalErrorIn("blockMesh::createTopology(IOdictionary&)")
00377 << "Cannot create mesh due to errors in topology, exiting !" << nl
00378 << exit(FatalError);
00379 }
00380
00381
00382 Info<< nl << "Creating block mesh topology" << endl;
00383
00384 PtrList<cellShape> tmpBlockCells(blocks.size());
00385 forAll(blocks, blockLabel)
00386 {
00387 tmpBlockCells.set
00388 (
00389 blockLabel,
00390 new cellShape(blocks[blockLabel].blockDef().blockShape())
00391 );
00392
00393 if (tmpBlockCells[blockLabel].mag(tmpBlockPoints) < 0.0)
00394 {
00395 WarningIn
00396 (
00397 "blockMesh::createTopology(IOdictionary&)"
00398 ) << "negative volume block : " << blockLabel
00399 << ", probably defined inside-out" << endl;
00400 }
00401 }
00402
00403 wordList patchPhysicalTypes(tmpBlocksPatches.size());
00404
00405 preservePatchTypes
00406 (
00407 meshDescription.time(),
00408 meshDescription.time().constant(),
00409 polyMesh::meshSubDir,
00410 patchNames,
00411 patchTypes,
00412 defaultPatchName,
00413 defaultPatchType,
00414 patchPhysicalTypes
00415 );
00416
00417 polyMesh* blockMeshPtr = new polyMesh
00418 (
00419 IOobject
00420 (
00421 "blockMesh",
00422 meshDescription.time().constant(),
00423 meshDescription.time(),
00424 IOobject::NO_READ,
00425 IOobject::NO_WRITE,
00426 false
00427 ),
00428 xferMove(tmpBlockPoints),
00429 tmpBlockCells,
00430 tmpBlocksPatches,
00431 patchNames,
00432 patchTypes,
00433 defaultPatchName,
00434 defaultPatchType,
00435 patchPhysicalTypes
00436 );
00437
00438 checkBlockMesh(*blockMeshPtr);
00439
00440 return blockMeshPtr;
00441 }
00442
00443
00444