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 "autoHexMeshDriver.H"
00028 #include "fvMesh.H"
00029 #include "Time.H"
00030 #include "boundBox.H"
00031 #include "globalIndex.H"
00032 #include "wallPolyPatch.H"
00033 #include "mapDistributePolyMesh.H"
00034 #include "cellSet.H"
00035 #include "syncTools.H"
00036 #include "motionSmoother.H"
00037 #include "refinementParameters.H"
00038 #include "snapParameters.H"
00039 #include "layerParameters.H"
00040 #include "autoRefineDriver.H"
00041 #include "autoSnapDriver.H"
00042 #include "autoLayerDriver.H"
00043 #include "triSurfaceMesh.H"
00044
00045
00046
00047 namespace Foam
00048 {
00049 defineTypeNameAndDebug(autoHexMeshDriver, 0);
00050 }
00051
00052
00053
00054
00055
00056 Foam::scalar Foam::autoHexMeshDriver::getMergeDistance(const scalar mergeTol)
00057 const
00058 {
00059 const boundBox& meshBb = mesh_.bounds();
00060 scalar mergeDist = mergeTol * meshBb.mag();
00061 scalar writeTol = std::pow
00062 (
00063 scalar(10.0),
00064 -scalar(IOstream::defaultPrecision())
00065 );
00066
00067 Info<< nl
00068 << "Overall mesh bounding box : " << meshBb << nl
00069 << "Relative tolerance : " << mergeTol << nl
00070 << "Absolute matching distance : " << mergeDist << nl
00071 << endl;
00072
00073 if (mesh_.time().writeFormat() == IOstream::ASCII && mergeTol < writeTol)
00074 {
00075 FatalErrorIn("autoHexMeshDriver::getMergeDistance(const scalar) const")
00076 << "Your current settings specify ASCII writing with "
00077 << IOstream::defaultPrecision() << " digits precision." << endl
00078 << "Your merging tolerance (" << mergeTol << ") is finer than this."
00079 << endl
00080 << "Please change your writeFormat to binary"
00081 << " or increase the writePrecision" << endl
00082 << "or adjust the merge tolerance (-mergeTol)."
00083 << exit(FatalError);
00084 }
00085
00086 return mergeDist;
00087 }
00088
00089
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148 Foam::autoHexMeshDriver::autoHexMeshDriver
00149 (
00150 fvMesh& mesh,
00151 const bool overwrite,
00152 const dictionary& dict,
00153 const dictionary& decomposeDict
00154 )
00155 :
00156 mesh_(mesh),
00157 dict_(dict),
00158 debug_(readLabel(dict_.lookup("debug"))),
00159 mergeDist_(getMergeDistance(readScalar(dict_.lookup("mergeTolerance"))))
00160 {
00161 if (debug_ > 0)
00162 {
00163 meshRefinement::debug = debug_;
00164 autoHexMeshDriver::debug = debug_;
00165 autoRefineDriver::debug = debug;
00166 autoSnapDriver::debug = debug;
00167 autoLayerDriver::debug = debug;
00168 }
00169
00170 refinementParameters refineParams(dict, 1);
00171
00172 Info<< "Overall cell limit : "
00173 << refineParams.maxGlobalCells() << endl;
00174 Info<< "Per processor cell limit : "
00175 << refineParams.maxLocalCells() << endl;
00176 Info<< "Minimum number of cells to refine : "
00177 << refineParams.minRefineCells() << endl;
00178 Info<< "Curvature : "
00179 << refineParams.curvature() << nl << endl;
00180 Info<< "Layers between different refinement levels : "
00181 << refineParams.nBufferLayers() << endl;
00182
00183 PtrList<dictionary> shellDicts(dict_.lookup("refinementShells"));
00184
00185 PtrList<dictionary> surfaceDicts(dict_.lookup("surfaces"));
00186
00187
00188
00189
00190
00191 {
00192 Info<< "Reading all geometry." << endl;
00193
00194
00195 dictionary geometryDict;
00196
00197 forAll(shellDicts, shellI)
00198 {
00199 dictionary shellDict = shellDicts[shellI];
00200 const word name(shellDict.lookup("name"));
00201 shellDict.remove("name");
00202 shellDict.remove("level");
00203 shellDict.remove("refineInside");
00204 geometryDict.add(name, shellDict);
00205 }
00206
00207 forAll(surfaceDicts, surfI)
00208 {
00209 dictionary surfDict = surfaceDicts[surfI];
00210 const word name(string::validate<word>(surfDict.lookup("file")));
00211 surfDict.remove("file");
00212 surfDict.remove("regions");
00213 if (!surfDict.found("name"))
00214 {
00215 surfDict.add("name", name);
00216 }
00217 surfDict.add("type", triSurfaceMesh::typeName);
00218 geometryDict.add(name, surfDict);
00219 }
00220
00221 allGeometryPtr_.reset
00222 (
00223 new searchableSurfaces
00224 (
00225 IOobject
00226 (
00227 "abc",
00228 mesh_.time().findInstance("triSurface", word::null),
00229 "triSurface",
00230 mesh_.time(),
00231 IOobject::MUST_READ,
00232 IOobject::NO_WRITE
00233 ),
00234 geometryDict
00235 )
00236 );
00237
00238 Info<< "Read geometry in = "
00239 << mesh_.time().cpuTimeIncrement() << " s" << endl;
00240 }
00241
00242
00243
00244
00245
00246 {
00247 Info<< "Reading surfaces and constructing search trees." << endl;
00248
00249 surfacesPtr_.reset
00250 (
00251 new refinementSurfaces
00252 (
00253 allGeometryPtr_(),
00254 surfaceDicts
00255 )
00256 );
00257 Info<< "Read surfaces in = "
00258 << mesh_.time().cpuTimeIncrement() << " s" << endl;
00259 }
00260
00261
00262
00263
00264 {
00265 Info<< "Reading refinement shells." << endl;
00266 shellsPtr_.reset
00267 (
00268 new shellSurfaces
00269 (
00270 allGeometryPtr_(),
00271 shellDicts
00272 )
00273 );
00274 Info<< "Read refinement shells in = "
00275 << mesh_.time().cpuTimeIncrement() << " s" << endl;
00276
00278
00279
00280
00281
00282
00283
00284 Info<< "Setting refinement level of surface to be consistent"
00285 << " with shells." << endl;
00286 surfacesPtr_().setMinLevelFields(shells());
00287 Info<< "Checked shell refinement in = "
00288 << mesh_.time().cpuTimeIncrement() << " s" << endl;
00289 }
00290
00291
00292
00293 meshRefinement::checkCoupledFaceZones(mesh_);
00294
00295
00296
00297
00298
00299 {
00300 Info<< nl
00301 << "Determining initial surface intersections" << nl
00302 << "-----------------------------------------" << nl
00303 << endl;
00304
00305
00306 meshRefinerPtr_.reset
00307 (
00308 new meshRefinement
00309 (
00310 mesh,
00311 mergeDist_,
00312 overwrite,
00313 surfaces(),
00314 shells()
00315 )
00316 );
00317 Info<< "Calculated surface intersections in = "
00318 << mesh_.time().cpuTimeIncrement() << " s" << endl;
00319
00320
00321 meshRefinerPtr_().printMeshInfo(debug_, "Initial mesh");
00322
00323 meshRefinerPtr_().write
00324 (
00325 debug_&meshRefinement::OBJINTERSECTIONS,
00326 mesh_.time().path()/meshRefinerPtr_().timeName()
00327 );
00328 }
00329
00330
00331
00332
00333
00334 {
00335 Info<< nl
00336 << "Adding patches for surface regions" << nl
00337 << "----------------------------------" << nl
00338 << endl;
00339
00340
00341 globalToPatch_.setSize(surfaces().nRegions(), -1);
00342
00343 Info<< "Patch\tRegion" << nl
00344 << "-----\t------"
00345 << endl;
00346
00347 const labelList& surfaceGeometry = surfaces().surfaces();
00348 forAll(surfaceGeometry, surfI)
00349 {
00350 label geomI = surfaceGeometry[surfI];
00351
00352 const wordList& regNames = allGeometryPtr_().regionNames()[geomI];
00353
00354 Info<< surfaces().names()[surfI] << ':' << nl << nl;
00355
00356 forAll(regNames, i)
00357 {
00358 label patchI = meshRefinerPtr_().addMeshedPatch
00359 (
00360 regNames[i],
00361 wallPolyPatch::typeName
00362 );
00363
00364 Info<< patchI << '\t' << regNames[i] << nl;
00365
00366 globalToPatch_[surfaces().globalRegion(surfI, i)] = patchI;
00367 }
00368
00369 Info<< nl;
00370 }
00371 Info<< "Added patches in = "
00372 << mesh_.time().cpuTimeIncrement() << " s" << nl << endl;
00373 }
00374
00375
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418 {
00419
00420 decomposerPtr_ = decompositionMethod::New
00421 (
00422 decomposeDict,
00423 mesh_
00424 );
00425 decompositionMethod& decomposer = decomposerPtr_();
00426
00427
00428 if (Pstream::parRun() && !decomposer.parallelAware())
00429 {
00430 FatalErrorIn("autoHexMeshDriver::autoHexMeshDriver"
00431 "(const IOobject&, fvMesh&)")
00432 << "You have selected decomposition method "
00433 << decomposer.typeName
00434 << " which is not parallel aware." << endl
00435 << "Please select one that is (parMetis, hierarchical)"
00436 << exit(FatalError);
00437 }
00438
00439
00440 distributorPtr_.reset(new fvMeshDistribute(mesh_, mergeDist_));
00441 }
00442 }
00443
00444
00445
00446
00447 void Foam::autoHexMeshDriver::writeMesh(const string& msg) const
00448 {
00449 const meshRefinement& meshRefiner = meshRefinerPtr_();
00450
00451 meshRefiner.printMeshInfo(debug_, msg);
00452 Info<< "Writing mesh to time " << meshRefiner.timeName() << endl;
00453
00454 meshRefiner.write(meshRefinement::MESH|meshRefinement::SCALARLEVELS, "");
00455 if (debug_ & meshRefinement::OBJINTERSECTIONS)
00456 {
00457 meshRefiner.write
00458 (
00459 meshRefinement::OBJINTERSECTIONS,
00460 mesh_.time().path()/meshRefiner.timeName()
00461 );
00462 }
00463 Info<< "Written mesh in = "
00464 << mesh_.time().cpuTimeIncrement() << " s." << endl;
00465 }
00466
00467
00468 void Foam::autoHexMeshDriver::doMesh()
00469 {
00470 Switch wantRefine(dict_.lookup("doRefine"));
00471 Switch wantSnap(dict_.lookup("doSnap"));
00472 Switch wantLayers(dict_.lookup("doLayers"));
00473
00474 Info<< "Do refinement : " << wantRefine << nl
00475 << "Do snapping : " << wantSnap << nl
00476 << "Do layers : " << wantLayers << nl
00477 << endl;
00478
00479 if (wantRefine)
00480 {
00481 const dictionary& motionDict = dict_.subDict("motionDict");
00482
00483 autoRefineDriver refineDriver
00484 (
00485 meshRefinerPtr_(),
00486 decomposerPtr_(),
00487 distributorPtr_(),
00488 globalToPatch_
00489 );
00490
00491
00492 refinementParameters refineParams(dict_, 1);
00493
00494 refineDriver.doRefine(dict_, refineParams, wantSnap, motionDict);
00495
00496
00497 writeMesh("Refined mesh");
00498 }
00499
00500 if (wantSnap)
00501 {
00502 const dictionary& snapDict = dict_.subDict("snapDict");
00503 const dictionary& motionDict = dict_.subDict("motionDict");
00504
00505 autoSnapDriver snapDriver
00506 (
00507 meshRefinerPtr_(),
00508 globalToPatch_
00509 );
00510
00511
00512 snapParameters snapParams(snapDict, 1);
00513
00514 snapDriver.doSnap(snapDict, motionDict, snapParams);
00515
00516
00517 writeMesh("Snapped mesh");
00518 }
00519
00520 if (wantLayers)
00521 {
00522 const dictionary& motionDict = dict_.subDict("motionDict");
00523 const dictionary& shrinkDict = dict_.subDict("shrinkDict");
00524 PtrList<dictionary> surfaceDicts(dict_.lookup("surfaces"));
00525
00526 autoLayerDriver layerDriver(meshRefinerPtr_());
00527
00528
00529 layerParameters layerParams
00530 (
00531 surfaceDicts,
00532 surfacesPtr_(),
00533 globalToPatch_,
00534 shrinkDict,
00535 mesh_.boundaryMesh()
00536 );
00537
00538 layerDriver.doLayers
00539 (
00540 shrinkDict,
00541 motionDict,
00542 layerParams,
00543 decomposerPtr_(),
00544 distributorPtr_()
00545 );
00546
00547
00548 writeMesh("Layer mesh");
00549 }
00550 }
00551
00552
00553