/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Copyright (C) 2011-2026 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . \*---------------------------------------------------------------------------*/ #include "refinementSurfaces.H" #include "Time.H" #include "searchableSurfaceList.H" #include "refinementRegions.H" #include "labelPair.H" #include "searchableSurfacesQueries.H" #include "UPtrList.H" #include "volumeType.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::refinementSurfaces::refinementSurfaces ( const searchableSurfaceList& allGeometry, const dictionary& surfacesDict, const label gapLevelIncrement ) : allGeometry_(allGeometry), surfaces_(surfacesDict.size()), names_(surfacesDict.size()), surfZones_(surfacesDict.size()), regionOffset_(surfacesDict.size()) { // Wildcard specification : loop over all surface, all regions // and try to find a match. // Count number of surfaces. label surfi = 0; forAll(allGeometry_.names(), geomi) { const word& geomName = allGeometry_.names()[geomi]; if (surfacesDict.found(geomName)) { surfi++; } } // Size lists surfaces_.setSize(surfi); names_.setSize(surfi); surfZones_.setSize(surfi); regionOffset_.setSize(surfi); labelList globalMinLevel(surfi, 0); labelList globalMaxLevel(surfi, 0); labelList globalLevelIncr(surfi, 0); scalarField globalAngle(surfi, -great); PtrList globalPatchInfo(surfi); List> regionMinLevel(surfi); List> regionMaxLevel(surfi); List> regionLevelIncr(surfi); List> regionAngle(surfi); List>> regionPatchInfo(surfi); HashSet unmatchedKeys(surfacesDict.toc()); surfi = 0; forAll(allGeometry_.names(), geomi) { const word& geomName = allGeometry_.names()[geomi]; const entry* ePtr = surfacesDict.lookupEntryPtr(geomName, false, true); if (ePtr) { const dictionary& dict = ePtr->dict(); unmatchedKeys.erase(ePtr->keyword()); names_[surfi] = geomName; surfaces_[surfi] = geomi; const labelPair refLevel(dict.lookup("level")); globalMinLevel[surfi] = refLevel[0]; globalMaxLevel[surfi] = refLevel[1]; globalLevelIncr[surfi] = dict.lookupOrDefault ( "gapLevelIncrement", gapLevelIncrement ); if ( globalMinLevel[surfi] < 0 || globalMaxLevel[surfi] < globalMinLevel[surfi] || globalLevelIncr[surfi] < 0 ) { FatalIOErrorInFunction ( dict ) << "Illegal level specification for surface " << names_[surfi] << " : minLevel:" << globalMinLevel[surfi] << " maxLevel:" << globalMaxLevel[surfi] << " levelincrement:" << globalLevelIncr[surfi] << exit(FatalIOError); } const searchableSurface& surface = allGeometry_[surfaces_[surfi]]; // Surface zones surfZones_.set(surfi, new surfaceZonesInfo(surface, dict)); // Global perpendicular angle if (dict.found("patchInfo")) { globalPatchInfo.set ( surfi, dict.subDict("patchInfo").clone() ); } dict.readIfPresent("perpendicularAngle", globalAngle[surfi]); if (dict.found("regions")) { const dictionary& regionsDict = dict.subDict("regions"); const wordList& regionNames = surface.regions(); forAll(regionNames, regioni) { if (regionsDict.found(regionNames[regioni])) { // Get the dictionary for region const dictionary& regionDict = regionsDict.subDict ( regionNames[regioni] ); const labelPair refLevel(regionDict.lookup("level")); regionMinLevel[surfi].insert(regioni, refLevel[0]); regionMaxLevel[surfi].insert(regioni, refLevel[1]); label levelincr = regionDict.lookupOrDefault ( "gapLevelIncrement", gapLevelIncrement ); regionLevelIncr[surfi].insert(regioni, levelincr); if ( refLevel[0] < 0 || refLevel[1] < refLevel[0] || levelincr < 0 ) { FatalIOErrorInFunction ( dict ) << "Illegal level specification for surface " << names_[surfi] << " region " << regionNames[regioni] << " : minLevel:" << refLevel[0] << " maxLevel:" << refLevel[1] << " levelincrement:" << levelincr << exit(FatalIOError); } if (regionDict.found("perpendicularAngle")) { regionAngle[surfi].insert ( regioni, regionDict.lookup("perpendicularAngle") ); } if (regionDict.found("patchInfo")) { regionPatchInfo[surfi].insert ( regioni, regionDict.subDict("patchInfo").clone() ); } } } } surfi++; } } if (unmatchedKeys.size() > 0) { IOWarningInFunction ( surfacesDict ) << "Not all entries in refinementSurfaces dictionary were used." << " The following entries were not used : " << unmatchedKeys.sortedToc() << endl; } // Calculate local to global region offset label nRegions = 0; forAll(surfaces_, surfi) { regionOffset_[surfi] = nRegions; nRegions += allGeometry_[surfaces_[surfi]].regions().size(); } // Rework surface specific information into information per global region minLevel_.setSize(nRegions); minLevel_ = 0; maxLevel_.setSize(nRegions); maxLevel_ = 0; gapLevel_.setSize(nRegions); gapLevel_ = -1; perpendicularAngle_.setSize(nRegions); perpendicularAngle_ = -great; patchInfo_.setSize(nRegions); forAll(globalMinLevel, surfi) { label nRegions = allGeometry_[surfaces_[surfi]].regions().size(); // Initialise to global (i.e. per surface) for (label i = 0; i < nRegions; i++) { label globalRegioni = regionOffset_[surfi] + i; minLevel_[globalRegioni] = globalMinLevel[surfi]; maxLevel_[globalRegioni] = globalMaxLevel[surfi]; gapLevel_[globalRegioni] = maxLevel_[globalRegioni] + globalLevelIncr[surfi]; perpendicularAngle_[globalRegioni] = globalAngle[surfi]; if (globalPatchInfo.set(surfi)) { patchInfo_.set ( globalRegioni, globalPatchInfo[surfi].clone() ); } } // Overwrite with region specific information forAllConstIter(Map