diff --git a/src/mesh/snappyHexMesh/Make/files b/src/mesh/snappyHexMesh/Make/files index b4b1f69753..d29863fbc0 100644 --- a/src/mesh/snappyHexMesh/Make/files +++ b/src/mesh/snappyHexMesh/Make/files @@ -17,6 +17,7 @@ meshRefinement/meshRefinementGapRefine.C meshRefinement/meshRefinementBlock.C meshRefinement/wallPoints.C meshRefinement/patchFaceOrientation.C +meshRefinement/weightedPosition.C refinementFeatures/refinementFeatures.C refinementSurfaces/surfaceZonesInfo.C diff --git a/src/mesh/snappyHexMesh/meshRefinement/meshRefinementProblemCells.C b/src/mesh/snappyHexMesh/meshRefinement/meshRefinementProblemCells.C index 321e700909..58d964a33e 100644 --- a/src/mesh/snappyHexMesh/meshRefinement/meshRefinementProblemCells.C +++ b/src/mesh/snappyHexMesh/meshRefinement/meshRefinementProblemCells.C @@ -1093,7 +1093,7 @@ Foam::labelList Foam::meshRefinement::markFacesOnProblemCellsGeometric newPoints[meshPoints[i]] += disp[i]; } - syncTools::syncPointList + syncTools::syncPointPositions ( mesh_, newPoints, diff --git a/src/mesh/snappyHexMesh/meshRefinement/weightedPosition.C b/src/mesh/snappyHexMesh/meshRefinement/weightedPosition.C new file mode 100644 index 0000000000..d8652b6685 --- /dev/null +++ b/src/mesh/snappyHexMesh/meshRefinement/weightedPosition.C @@ -0,0 +1,153 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2020 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 . + +\*---------------------------------------------------------------------------*/ + +#include "weightedPosition.H" +#include "vectorTensorTransform.H" +#include "coupledPolyPatch.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +const Foam::weightedPosition Foam::pTraits::zero +( + scalar(0), + Foam::point::zero +); + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::weightedPosition::weightedPosition() +: + Tuple2() +{} + + +Foam::weightedPosition::weightedPosition(const scalar s, const point& p) +: + Tuple2(s, p) +{} + + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +void Foam::weightedPosition::getPoints +( + const UList& in, + List& out +) +{ + out.setSize(in.size()); + forAll(in, i) + { + out[i] = in[i].second(); + + if (mag(in[i].first()) > VSMALL) + { + out[i] /= in[i].first(); + } + } +} + + +void Foam::weightedPosition::setPoints +( + const UList& in, + List& out +) +{ + out.setSize(in.size()); + forAll(in, i) + { + out[i].second() = out[i].first()*in[i]; + } +} + + +void Foam::weightedPosition::plusEqOp +( + weightedPosition& x, + const weightedPosition& y +) +{ + x.first() += y.first(); + x.second() += y.second(); +} + + +void Foam::weightedPosition::operator() +( + const vectorTensorTransform& vt, + const bool forward, + List& fld +) const +{ + pointField pfld; + getPoints(fld, pfld); + + if (forward) + { + pfld = vt.transformPosition(pfld); + } + else + { + pfld = vt.invTransformPosition(pfld); + } + + setPoints(pfld, fld); +} + + +void Foam::weightedPosition::operator() +( + const vectorTensorTransform& vt, + const bool forward, + List>& flds +) const +{ + for (List& fld : flds) + { + operator()(vt, forward, fld); + } +} + + +void Foam::weightedPosition::operator() +( + const coupledPolyPatch& cpp, + Field& fld +) const +{ + pointField pfld; + getPoints(fld, pfld); + + cpp.transformPosition(pfld); + + setPoints(pfld, fld); +} + + +// ************************************************************************* // diff --git a/src/mesh/snappyHexMesh/meshRefinement/weightedPosition.H b/src/mesh/snappyHexMesh/meshRefinement/weightedPosition.H new file mode 100644 index 0000000000..8b05ca7ef7 --- /dev/null +++ b/src/mesh/snappyHexMesh/meshRefinement/weightedPosition.H @@ -0,0 +1,180 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2020 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 . + +Class + Foam::weightedPosition + +Description + Wrapper for position + weight to be used in e.g. averaging. + + This avoids the problems when synchronising locations with e.g. + parallel cyclics. The separation vector only applies to locations + and not e.g. summed locations. Note that there is no corresponding + problem for rotational cyclics. + + Typical use might be to e.g. average face centres to points on a patch + + const labelListList& pointFaces = pp.pointFaces(); + const pointField& faceCentres = pp.faceCentres(); + + Field avgBoundary(pointFaces.size()); + + forAll(pointFaces, pointi) + { + const labelList& pFaces = pointFaces[pointi]; + avgBoundary[pointi].first() = pFaces.size(); + avgBoundary[pointi].second() = sum(pointField(faceCentres, pFaces)); + } + syncTools::syncPointList + ( + mesh, + pp.meshPoints(), + avgBoundary, + weightedPosition::plusEqOp, // combine op + pTraits::zero,// null value (not used) + pTraits::zero // transform class + ); + + +SourceFiles + weightedPosition.C + +\*---------------------------------------------------------------------------*/ + +#ifndef weightedPosition_H +#define weightedPosition_H + +#include "Tuple2.H" +#include "point.H" +#include "Field.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward declarations +class weightedPosition; +class vectorTensorTransform; +class coupledPolyPatch; + +//- pTraits +template<> +class pTraits +{ +public: + typedef weightedPosition cmptType; + static const weightedPosition zero; +}; + + +/*---------------------------------------------------------------------------*\ + Class weightedPosition Declaration +\*---------------------------------------------------------------------------*/ + +class weightedPosition +: + public Tuple2 +{ +public: + + // Constructors + + //- Construct null + weightedPosition(); + + //- Construct from components + weightedPosition(const scalar s, const point& p); + + + // Member Functions + + // Helpers + + //- Get points + static void getPoints + ( + const UList& in, + List& out + ); + + //- Set points + static void setPoints + ( + const UList& in, + List& out + ); + + + //- Summation operator + static void plusEqOp(weightedPosition& x, const weightedPosition& y); + + + // Transformation operators + + void operator() + ( + const vectorTensorTransform& vt, + const bool forward, + List& fld + ) const; + + void operator() + ( + const vectorTensorTransform& vt, + const bool forward, + List>& flds + ) const; + + void operator() + ( + const coupledPolyPatch& cpp, + Field& fld + ) const; + + template class Container> + void operator() + ( + const coupledPolyPatch& cpp, + Container& map + ) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "weightedPositionTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/mesh/snappyHexMesh/meshRefinement/weightedPositionTemplates.C b/src/mesh/snappyHexMesh/meshRefinement/weightedPositionTemplates.C new file mode 100644 index 0000000000..3f461ada8c --- /dev/null +++ b/src/mesh/snappyHexMesh/meshRefinement/weightedPositionTemplates.C @@ -0,0 +1,61 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2020 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 . + +\*---------------------------------------------------------------------------*/ + +#include "vectorTensorTransform.H" +#include "coupledPolyPatch.H" + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +template class Container> +void Foam::weightedPosition::operator() +( + const coupledPolyPatch& cpp, + Container& map +) +const +{ + Field fld(map.size()); + label i = 0; + forAllConstIters(map, iter) + { + point pt(iter->second()); + if (mag(iter->first()) > VSMALL) + { + pt /= iter->first(); + } + fld[i++] = pt; + } + cpp.transformPosition(fld); + i = 0; + forAllIters(map, iter) + { + iter->second() = fld[i++]*iter->first(); + } +} + + +// ************************************************************************* // diff --git a/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappySnapDriver.C b/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappySnapDriver.C index ab7c3f2113..e8cbe2c1e7 100644 --- a/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappySnapDriver.C +++ b/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappySnapDriver.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2015-2019 OpenCFD Ltd. + Copyright (C) 2015-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -48,6 +48,7 @@ Description #include "localPointRegion.H" #include "PatchTools.H" #include "refinementFeatures.H" +#include "weightedPosition.H" #include "profiling.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -234,8 +235,11 @@ Foam::tmp Foam::snappySnapDriver::smoothInternalDisplacement // Calculate average of connected cells - labelList nCells(mesh.nPoints(), Zero); - pointField sumLocation(mesh.nPoints(), Zero); + Field sumLocation + ( + mesh.nPoints(), + pTraits::zero + ); forAll(isMovingPoint, pointi) { @@ -243,22 +247,22 @@ Foam::tmp Foam::snappySnapDriver::smoothInternalDisplacement { const labelList& pCells = mesh.pointCells(pointi); - forAll(pCells, i) + sumLocation[pointi].first() = pCells.size(); + for (const label celli : pCells) { - sumLocation[pointi] += mesh.cellCentres()[pCells[i]]; - nCells[pointi]++; + sumLocation[pointi].second() += mesh.cellCentres()[celli]; } } } // Sum - syncTools::syncPointList(mesh, nCells, plusEqOp