/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright held by original author \\/ 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 2 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, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Description Tries to figure out what the refinement level is on refined cartesian meshes. Run BEFORE snapping. Writes - volScalarField 'refinementLevel' with current refinement level. - cellSet 'refCells' which are the cells that need to be refined to satisfy 2:1 refinement. Works by dividing cells into volume bins. \*---------------------------------------------------------------------------*/ #include "argList.H" #include "Time.H" #include "polyMesh.H" #include "cellSet.H" #include "SortableList.H" #include "labelIOList.H" #include "fvMesh.H" #include "volFields.H" using namespace Foam; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // Return true if any cells had to be split to keep a difference between // neighbouring refinement levels < limitDiff. Puts cells into refCells and // update refLevel to account for refinement. bool limitRefinementLevel ( const primitiveMesh& mesh, labelList& refLevel, cellSet& refCells ) { const labelListList& cellCells = mesh.cellCells(); label oldNCells = refCells.size(); forAll(cellCells, cellI) { const labelList& cCells = cellCells[cellI]; forAll(cCells, i) { if (refLevel[cCells[i]] > (refLevel[cellI]+1)) { // Found neighbour with >=2 difference in refLevel. refCells.insert(cellI); refLevel[cellI]++; break; } } } if (refCells.size() > oldNCells) { Info<< "Added an additional " << refCells.size() - oldNCells << " cells to satisfy 1:2 refinement level" << endl; return true; } else { return false; } } // Main program: int main(int argc, char *argv[]) { argList::validOptions.insert("readLevel", ""); # include "setRootCase.H" # include "createTime.H" # include "createPolyMesh.H" Info<< "Dividing cells into bins depending on cell volume.\nThis will" << " correspond to refinement levels for a mesh with only 2x2x2" << " refinement\n" << "The upper range for every bin is always 1.1 times the lower range" << " to allow for some truncation error." << nl << endl; bool readLevel = args.options().found("readLevel"); const scalarField& vols = mesh.cellVolumes(); SortableList sortedVols(vols); // All cell labels, sorted per bin. DynamicList > bins; // Lower/upper limits DynamicList lowerLimits; DynamicList upperLimits; // Create bin0. Have upperlimit as factor times lowerlimit. bins.append(DynamicList