OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

layerParameters.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "layerParameters.H"
00028 #include "polyBoundaryMesh.H"
00029 #include "mathematicalConstants.H"
00030 #include "refinementSurfaces.H"
00031 #include "searchableSurfaces.H"
00032 #include "regExp.H"
00033 
00034 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00035 
00036 const Foam::scalar Foam::layerParameters::defaultConcaveAngle = 90;
00037 
00038 
00039 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00040 
00041 // Read the number of layers from dictionary. Per patch 0 or the number
00042 // of layers.
00043 Foam::labelList Foam::layerParameters::readNumLayers
00044 (
00045     const PtrList<dictionary>& surfaceDicts,
00046     const refinementSurfaces& refineSurfaces,
00047     const labelList& globalToPatch,
00048     const polyBoundaryMesh& boundaryMesh
00049 )
00050 {
00051     // Per surface the number of layers
00052     labelList globalSurfLayers(surfaceDicts.size());
00053     // Per surface, per region the number of layers
00054     List<Map<label> > regionSurfLayers(surfaceDicts.size());
00055 
00056     const labelList& surfaceIndices = refineSurfaces.surfaces();
00057 
00058     forAll(surfaceDicts, surfI)
00059     {
00060         const dictionary& dict = surfaceDicts[surfI];
00061 
00062         globalSurfLayers[surfI] = readLabel(dict.lookup("surfaceLayers"));
00063 
00064         if (dict.found("regions"))
00065         {
00066             // Per-region layer information
00067 
00068             PtrList<dictionary> regionDicts(dict.lookup("regions"));
00069 
00070             const wordList& regionNames =
00071                 refineSurfaces.geometry()[surfaceIndices[surfI]].regions();
00072 
00073             forAll(regionDicts, dictI)
00074             {
00075                 const dictionary& regionDict = regionDicts[dictI];
00076 
00077                 const word regionName(regionDict.lookup("name"));
00078 
00079                 label regionI = findIndex(regionNames, regionName);
00080 
00081                 label nLayers = readLabel(regionDict.lookup("surfaceLayers"));
00082 
00083                 Info<< "    region " << regionName << ':'<< nl
00084                     << "        surface layers:" << nLayers << nl;
00085 
00086                 regionSurfLayers[surfI].insert(regionI, nLayers);
00087             }
00088         }
00089     }
00090 
00091 
00092     // Transfer per surface/region information into patchwise region info
00093 
00094     labelList nLayers(boundaryMesh.size(), 0);
00095 
00096     forAll(surfaceIndices, surfI)
00097     {
00098         const wordList& regionNames =
00099             refineSurfaces.geometry()[surfaceIndices[surfI]].regions();
00100 
00101         forAll(regionNames, regionI)
00102         {
00103             const word& regionName = regionNames[regionI];
00104 
00105             label global = refineSurfaces.globalRegion(surfI, regionI);
00106 
00107             label patchI = globalToPatch[global];
00108 
00109             // Initialise to surface-wise layers
00110             nLayers[patchI] = globalSurfLayers[surfI];
00111 
00112             // Override with region specific data if available
00113             Map<label>::const_iterator iter =
00114                 regionSurfLayers[surfI].find(regionI);
00115 
00116             if (iter != regionSurfLayers[surfI].end())
00117             {
00118                 nLayers[patchI] = iter();
00119             }
00120 
00121             // Check
00122             if (nLayers[patchI] < 0)
00123             {
00124                 FatalErrorIn
00125                 (
00126                     "layerParameters::readNumLayers(..)"
00127                 )   << "Illegal number of layers " << nLayers[patchI]
00128                     << " for surface "
00129                     << refineSurfaces.names()[surfI]
00130                     << " region " << regionName << endl
00131                     << exit(FatalError);
00132             }
00133         }
00134     }
00135     return nLayers;
00136 }
00137 
00138 
00139 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00140 
00141 // Construct from dictionary
00142 Foam::layerParameters::layerParameters
00143 (
00144     const PtrList<dictionary>& surfaceDicts,
00145     const refinementSurfaces& refineSurfaces,
00146     const labelList& globalToPatch,
00147     const dictionary& dict,
00148     const polyBoundaryMesh& boundaryMesh
00149 )
00150 :
00151     numLayers_
00152     (
00153         readNumLayers
00154         (
00155             surfaceDicts,
00156             refineSurfaces,
00157             globalToPatch,
00158             boundaryMesh
00159         )
00160     ),
00161     expansionRatio_
00162     (
00163         numLayers_.size(),
00164         readScalar(dict.lookup("expansionRatio"))
00165     ),
00166     relativeSizes_(false),
00167     finalLayerThickness_
00168     (
00169         numLayers_.size(),
00170         readScalar(dict.lookup("finalLayerRatio"))
00171     ),
00172     minThickness_
00173     (
00174         numLayers_.size(),
00175         readScalar(dict.lookup("minThickness"))
00176     ),
00177     featureAngle_(readScalar(dict.lookup("featureAngle"))),
00178     concaveAngle_
00179     (
00180         dict.lookupOrDefault("concaveAngle", defaultConcaveAngle)
00181     ),
00182     nGrow_(readLabel(dict.lookup("nGrow"))),
00183     nSmoothSurfaceNormals_
00184     (
00185         readLabel(dict.lookup("nSmoothSurfaceNormals"))
00186     ),
00187     nSmoothNormals_(readLabel(dict.lookup("nSmoothNormals"))),
00188     nSmoothThickness_(readLabel(dict.lookup("nSmoothThickness"))),
00189     maxFaceThicknessRatio_
00190     (
00191         readScalar(dict.lookup("maxFaceThicknessRatio"))
00192     ),
00193     layerTerminationCos_
00194     (
00195         Foam::cos
00196         (
00197             0.5
00198           * featureAngle_
00199           * mathematicalConstant::pi/180.
00200         )
00201     ),
00202     maxThicknessToMedialRatio_
00203     (
00204         readScalar(dict.lookup("maxThicknessToMedialRatio"))
00205     ),
00206     minMedianAxisAngleCos_
00207     (
00208         Foam::cos(readScalar(dict.lookup("minMedianAxisAngle")))
00209       * mathematicalConstant::pi/180.
00210     ),
00211     nBufferCellsNoExtrude_
00212     (
00213         readLabel(dict.lookup("nBufferCellsNoExtrude"))
00214     ),
00215     nSnap_(readLabel(dict.lookup("nSnap"))),
00216     nLayerIter_(readLabel(dict.lookup("nLayerIter"))),
00217     nRelaxedIter_(labelMax)
00218 {
00219     if (dict.found("nRelaxedIter"))
00220     {
00221         dict.lookup("nRelaxedIter") >> nRelaxedIter_;
00222     }
00223 
00224     if (nLayerIter_ < 0 || nRelaxedIter_ < 0)
00225     {
00226         FatalErrorIn("layerParameters::layerParameters(..)")
00227             << "Layer iterations should be >= 0." << endl
00228             << "nLayerIter:" << nLayerIter_
00229             << " nRelaxedIter:" << nRelaxedIter_
00230             << exit(FatalError);
00231     }
00232 }
00233 
00234 
00235 // Construct from dictionary
00236 Foam::layerParameters::layerParameters
00237 (
00238     const dictionary& dict,
00239     const polyBoundaryMesh& boundaryMesh
00240 )
00241 :
00242     numLayers_(boundaryMesh.size(), 0),
00243     expansionRatio_
00244     (
00245         boundaryMesh.size(),
00246         readScalar(dict.lookup("expansionRatio"))
00247     ),
00248     relativeSizes_(dict.lookup("relativeSizes")),
00249     finalLayerThickness_
00250     (
00251         boundaryMesh.size(),
00252         readScalar(dict.lookup("finalLayerThickness"))
00253     ),
00254     minThickness_
00255     (
00256         boundaryMesh.size(),
00257         readScalar(dict.lookup("minThickness"))
00258     ),
00259     featureAngle_(readScalar(dict.lookup("featureAngle"))),
00260     concaveAngle_
00261     (
00262         dict.lookupOrDefault("concaveAngle", defaultConcaveAngle)
00263     ),
00264     nGrow_(readLabel(dict.lookup("nGrow"))),
00265     nSmoothSurfaceNormals_
00266     (
00267         readLabel(dict.lookup("nSmoothSurfaceNormals"))
00268     ),
00269     nSmoothNormals_(readLabel(dict.lookup("nSmoothNormals"))),
00270     nSmoothThickness_(readLabel(dict.lookup("nSmoothThickness"))),
00271     maxFaceThicknessRatio_
00272     (
00273         readScalar(dict.lookup("maxFaceThicknessRatio"))
00274     ),
00275     layerTerminationCos_
00276     (
00277         Foam::cos
00278         (
00279             0.5
00280           * featureAngle_
00281           * mathematicalConstant::pi/180.
00282         )
00283     ),
00284     maxThicknessToMedialRatio_
00285     (
00286         readScalar(dict.lookup("maxThicknessToMedialRatio"))
00287     ),
00288     minMedianAxisAngleCos_
00289     (
00290         Foam::cos(readScalar(dict.lookup("minMedianAxisAngle")))
00291       * mathematicalConstant::pi/180.
00292     ),
00293     nBufferCellsNoExtrude_
00294     (
00295         readLabel(dict.lookup("nBufferCellsNoExtrude"))
00296     ),
00297     nSnap_(readLabel(dict.lookup("nRelaxIter"))),
00298     nLayerIter_(readLabel(dict.lookup("nLayerIter"))),
00299     nRelaxedIter_(labelMax)
00300 {
00301     if (dict.found("nRelaxedIter"))
00302     {
00303         dict.lookup("nRelaxedIter") >> nRelaxedIter_;
00304     }
00305     if (nLayerIter_ < 0 || nRelaxedIter_ < 0)
00306     {
00307         FatalErrorIn("layerParameters::layerParameters(..)")
00308             << "Layer iterations should be >= 0." << endl
00309             << "nLayerIter:" << nLayerIter_
00310             << " nRelaxedIter:" << nRelaxedIter_
00311             << exit(FatalError);
00312     }
00313 
00314 
00315     const dictionary& layersDict = dict.subDict("layers");
00316 
00317     forAll(boundaryMesh, patchI)
00318     {
00319         const word& patchName = boundaryMesh[patchI].name();
00320 
00321         if (layersDict.found(patchName))
00322         {
00323             const dictionary& layerDict = layersDict.subDict(patchName);
00324 
00325             numLayers_[patchI] =
00326                 readLabel(layerDict.lookup("nSurfaceLayers"));
00327 
00328             layerDict.readIfPresent
00329             (
00330                 "expansionRatio",
00331                 expansionRatio_[patchI]
00332             );
00333             layerDict.readIfPresent
00334             (
00335                 "finalLayerThickness",
00336                 finalLayerThickness_[patchI]
00337             );
00338             layerDict.readIfPresent
00339             (
00340                 "minThickness",
00341                 minThickness_[patchI]
00342             );
00343         }
00344     }
00345 
00346 
00347     // Check whether layer specification matches any patches
00348     const List<keyType> wildCards = layersDict.keys(true);
00349 
00350     forAll(wildCards, i)
00351     {
00352         regExp re(wildCards[i]);
00353 
00354         bool hasMatch = false;
00355         forAll(boundaryMesh, patchI)
00356         {
00357             if (re.match(boundaryMesh[patchI].name()))
00358             {
00359                 hasMatch = true;
00360                 break;
00361             }
00362         }
00363         if (!hasMatch)
00364         {
00365             IOWarningIn("layerParameters::layerParameters(..)", layersDict)
00366                 << "Wildcard layer specification for " << wildCards[i]
00367                 << " does not match any patch." << endl;
00368         }
00369     }
00370 
00371     const List<keyType> nonWildCards = layersDict.keys(false);
00372 
00373     forAll(nonWildCards, i)
00374     {
00375         if (boundaryMesh.findPatchID(nonWildCards[i]) == -1)
00376         {
00377             IOWarningIn("layerParameters::layerParameters(..)", layersDict)
00378                 << "Layer specification for " << nonWildCards[i]
00379                 << " does not match any patch." << endl;
00380         }
00381     }
00382 }
00383 
00384 
00385 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd