/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. \\/ 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 \*----------------------------------------------------------------------------*/ #include "autoRefineDriver.H" #include "meshRefinement.H" #include "fvMesh.H" #include "Time.H" #include "cellSet.H" #include "syncTools.H" #include "refinementParameters.H" #include "featureEdgeMesh.H" #include "refinementSurfaces.H" #include "shellSurfaces.H" #include "mapDistributePolyMesh.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { defineTypeNameAndDebug(autoRefineDriver, 0); } // End namespace Foam // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // Read explicit feature edges Foam::label Foam::autoRefineDriver::readFeatureEdges ( const PtrList& featDicts, PtrList& featureMeshes, labelList& featureLevels ) const { Info<< "Reading external feature lines." << endl; const fvMesh& mesh = meshRefiner_.mesh(); featureMeshes.setSize(featDicts.size()); featureLevels.setSize(featDicts.size()); forAll(featDicts, i) { const dictionary& dict = featDicts[i]; fileName featFileName(dict.lookup("file")); featureMeshes.set ( i, new featureEdgeMesh ( IOobject ( featFileName, // name //mesh.time().findInstance("triSurface", featFileName), // // instance mesh.time().constant(), // instance "triSurface", // local mesh.time(), // registry IOobject::MUST_READ, IOobject::NO_WRITE, false ) ) ); featureMeshes[i].mergePoints(meshRefiner_.mergeDistance()); featureLevels[i] = readLabel(dict.lookup("level")); Info<< "Refinement level " << featureLevels[i] << " for all cells crossed by feature " << featFileName << " (" << featureMeshes[i].points().size() << " points, " << featureMeshes[i].edges().size() << " edges)." << endl; } Info<< "Read feature lines in = " << mesh.time().cpuTimeIncrement() << " s" << nl << endl; return featureMeshes.size(); } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // Construct from components Foam::autoRefineDriver::autoRefineDriver ( meshRefinement& meshRefiner, decompositionMethod& decomposer, fvMeshDistribute& distributor, const labelList& globalToPatch ) : meshRefiner_(meshRefiner), decomposer_(decomposer), distributor_(distributor), globalToPatch_(globalToPatch) {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // Foam::label Foam::autoRefineDriver::featureEdgeRefine ( const refinementParameters& refineParams, const PtrList& featDicts, const label maxIter, const label minRefine ) { const fvMesh& mesh = meshRefiner_.mesh(); // Read explicit feature edges PtrList featureMeshes; // Per feature the refinement level labelList featureLevels; readFeatureEdges(featDicts, featureMeshes, featureLevels); label iter = 0; if (featureMeshes.size() && maxIter > 0) { for (; iter < maxIter; iter++) { Info<< nl << "Feature refinement iteration " << iter << nl << "------------------------------" << nl << endl; labelList candidateCells ( meshRefiner_.refineCandidates ( refineParams.keepPoints()[0], // For now only use one. refineParams.curvature(), featureMeshes, featureLevels, true, // featureRefinement false, // internalRefinement false, // surfaceRefinement false, // curvatureRefinement refineParams.maxGlobalCells(), refineParams.maxLocalCells() ) ); labelList cellsToRefine ( meshRefiner_.meshCutter().consistentRefinement ( candidateCells, true ) ); Info<< "Determined cells to refine in = " << mesh.time().cpuTimeIncrement() << " s" << endl; label nCellsToRefine = cellsToRefine.size(); reduce(nCellsToRefine, sumOp