/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation Copyright (C) 2015-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- 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 . Description All to do with adding cell layers \*----------------------------------------------------------------------------*/ #include "snappyLayerDriver.H" #include "fvMesh.H" #include "Time.H" #include "meshRefinement.H" #include "removePoints.H" #include "pointFields.H" #include "motionSmoother.H" #include "unitConversion.H" #include "pointSet.H" #include "faceSet.H" #include "cellSet.H" #include "polyTopoChange.H" #include "mapPolyMesh.H" #include "addPatchCellLayer.H" #include "mapDistributePolyMesh.H" #include "OBJstream.H" #include "layerParameters.H" #include "combineFaces.H" #include "IOmanip.H" #include "globalIndex.H" #include "DynamicField.H" #include "PatchTools.H" #include "slipPointPatchFields.H" #include "fixedValuePointPatchFields.H" #include "zeroFixedValuePointPatchFields.H" #include "calculatedPointPatchFields.H" #include "cyclicSlipPointPatchFields.H" #include "fixedValueFvPatchFields.H" #include "localPointRegion.H" #include "externalDisplacementMeshMover.H" #include "scalarIOField.H" #include "profiling.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { defineTypeNameAndDebug(snappyLayerDriver, 0); } // End namespace Foam // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // For debugging: Dump displacement to .obj files void Foam::snappyLayerDriver::dumpDisplacement ( const fileName& prefix, const indirectPrimitivePatch& pp, const vectorField& patchDisp, const List& extrudeStatus ) { OBJstream dispStr(prefix + "_disp.obj"); Info<< "Writing all displacements to " << dispStr.name() << endl; forAll(patchDisp, patchPointi) { const point& pt = pp.localPoints()[patchPointi]; dispStr.write(linePointRef(pt, pt + patchDisp[patchPointi])); } OBJstream illStr(prefix + "_illegal.obj"); Info<< "Writing invalid displacements to " << illStr.name() << endl; forAll(patchDisp, patchPointi) { if (extrudeStatus[patchPointi] != EXTRUDE) { const point& pt = pp.localPoints()[patchPointi]; illStr.write(linePointRef(pt, pt + patchDisp[patchPointi])); } } } Foam::tmp Foam::snappyLayerDriver::avgPointData ( const indirectPrimitivePatch& pp, const scalarField& pointFld ) { tmp tfaceFld(new scalarField(pp.size(), Zero)); scalarField& faceFld = tfaceFld.ref(); forAll(pp.localFaces(), facei) { const face& f = pp.localFaces()[facei]; if (f.size()) { forAll(f, fp) { faceFld[facei] += pointFld[f[fp]]; } faceFld[facei] /= f.size(); } } return tfaceFld; } // Check that primitivePatch is not multiply connected. Collect non-manifold // points in pointSet. void Foam::snappyLayerDriver::checkManifold ( const indirectPrimitivePatch& fp, pointSet& nonManifoldPoints ) { // Check for non-manifold points (surface pinched at point) fp.checkPointManifold(false, &nonManifoldPoints); // Check for edge-faces (surface pinched at edge) const labelListList& edgeFaces = fp.edgeFaces(); forAll(edgeFaces, edgei) { const labelList& eFaces = edgeFaces[edgei]; if (eFaces.size() > 2) { const edge& e = fp.edges()[edgei]; nonManifoldPoints.insert(fp.meshPoints()[e[0]]); nonManifoldPoints.insert(fp.meshPoints()[e[1]]); } } } void Foam::snappyLayerDriver::checkMeshManifold() const { const fvMesh& mesh = meshRefiner_.mesh(); Info<< nl << "Checking mesh manifoldness ..." << endl; pointSet nonManifoldPoints ( mesh, "nonManifoldPoints", mesh.nPoints() / 100 ); // Build primitivePatch out of faces and check it for problems. checkManifold ( indirectPrimitivePatch ( IndirectList ( mesh.faces(), identity(mesh.boundaryMesh().range()) // All outside faces ), mesh.points() ), nonManifoldPoints ); label nNonManif = returnReduce(nonManifoldPoints.size(), sumOp