From 723f522c5166dde391b086987e47a0c533ce608d Mon Sep 17 00:00:00 2001 From: Will Bainbridge Date: Thu, 17 Nov 2022 16:25:02 +0000 Subject: [PATCH] cutPoly: New polyhedral cutting routines and isoSurface algorithm A set of routines for cutting polyhedra have been added. These can cut polyhedral cells based on the adjacent point values and an iso-value which defines the surface. The method operates directly on the polyhedral cells; it does not decompose them into tetrahedra at any point. The routines can compute the cut topology as well as integrals of properties above and below the cut surface. An iso-surface algorithm has been added based on these polyhedral cutting routines. It is significantly more robust than the previous algorithm, and produces compact surfaces equivalent to the previous algorithm's maximum filtering level. It is also approximately 3 times faster than the previous algorithm, and 10 times faster when run repeatedly on the same set of cells (this is because some addressing is cached and reused). This algorithm is used by the 'isoSurface', 'distanceSurface' and 'cutPlane' sampled surfaces. The 'cutPlane' sampled surface is a renaming of 'cuttingPlane' to make it consistent with the corresponding packaged function. The name 'cuttingPlane' has been retained for backwards compatibility and can still be used to select a 'cutPlane' surface. The legacy 'plane' surface has been removed. The 'average' keyword has been removed from specification of these sampled surfaces as cell-centred values are no longer used in the generation of or interpolation to an iso-surface. The 'filtering' keyword has also been removed as it relates to options within the previous algorithm. Zone support has been reinstated into the 'isoSurface' sampled surface. Interpolation to all these sampled surfaces has been corrected to exactly match the user-selected interpolation scheme, and the interpolation procedure no longer unnecessarily re-generates data that is already available. --- .../test/tetTetOverlap/Test-tetTetOverlap.C | 10 +- .../foamyHexMeshBackgroundMesh.C | 10 +- .../surface/cutPlaneSurface.cfg | 2 +- .../containers/HashTables/HashList/HashList.C | 110 ++ .../containers/HashTables/HashList/HashList.H | 104 ++ .../meshes/primitiveShapes/plane/plane.C | 10 +- .../meshes/primitiveShapes/plane/plane.H | 3 + src/finiteVolume/Make/files | 1 + .../cfdTools/general/levelSet/levelSet.C | 22 +- .../general/levelSet/levelSetTemplates.C | 16 +- .../interpolation/interpolation.C | 14 +- .../interpolation/interpolation.H | 47 +- .../interpolationCell/makeInterpolationCell.C | 5 +- .../makeInterpolationCellPatchConstrained.C | 13 +- .../interpolationCellPoint.C | 14 +- .../interpolationCellPoint.H | 15 +- .../interpolationCellPointI.H | 14 +- .../makeInterpolationCellPoint.C | 5 +- .../interpolationCellPointFace.C | 16 +- .../interpolationCellPointFace.H | 10 +- .../makeInterpolationCellPointFace.C | 5 +- .../makeInterpolationCellPointWallModified.C | 13 +- .../interpolationPointMVC.C | 12 +- .../interpolationPointMVC.H | 15 +- .../interpolationPointMVCI.H | 4 +- .../makeInterpolationPointMVC.C | 5 +- .../interpolationVolPointInterpolation.C | 62 + .../interpolationVolPointInterpolation.H | 111 ++ .../makeInterpolationVolPointInterpolation.C} | 33 +- src/meshTools/Make/files | 4 + src/meshTools/cutPoly/cellEdgeAddressing.C | 223 +++ src/meshTools/cutPoly/cellEdgeAddressing.H | 163 ++ src/meshTools/cutPoly/cellEdgeAddressingI.H | 50 + src/meshTools/cutPoly/cutPoly.C | 314 ++++ src/meshTools/cutPoly/cutPoly.H | 122 ++ src/meshTools/cutPoly/cutPolyIntegral.H | 115 ++ .../cutPoly/cutPolyIntegralTemplates.C | 498 ++++++ src/meshTools/cutPoly/cutPolyIsoSurface.C | 238 +++ src/meshTools/cutPoly/cutPolyIsoSurface.H | 147 ++ .../cutPoly/cutPolyIsoSurfaceTemplates.C | 65 + src/meshTools/cutPoly/cutPolyValue.H | 348 ++++ src/meshTools/cutPoly/cutPolyValueI.H | 41 + src/meshTools/cutPoly/cutPolyValueTemplates.C | 384 +++++ .../cut.H => meshTools/cutTriTet/cutTriTet.H} | 26 +- .../cutTriTet/cutTriTetI.H} | 36 +- .../cutTriTet/cutTriTetTemplates.C} | 12 +- .../tetOverlapVolume/tetOverlapVolume.C | 12 +- src/sampling/Make/files | 15 +- src/sampling/cuttingPlane/cuttingPlane.C | 430 ----- src/sampling/cuttingPlane/cuttingPlane.H | 195 --- .../distanceSurface/distanceSurface.C | 551 ------- .../distanceSurface/distanceSurface.H | 277 ---- .../distanceSurfaceTemplates.C | 97 -- .../sampledSurface/isoSurface/isoSurface.C | 1457 ----------------- .../sampledSurface/isoSurface/isoSurface.H | 297 ---- .../isoSurface/isoSurfaceTemplates.C | 91 - .../isoSurface/sampledIsoSurface.C | 425 ----- .../isoSurface/sampledIsoSurface.H | 252 --- .../isoSurface/sampledIsoSurfaceTemplates.C | 85 - .../sampledCutPlane/sampledCutPlane.C | 111 ++ .../sampledCutPlane/sampledCutPlane.H | 128 ++ .../sampledCuttingPlane/sampledCuttingPlane.C | 458 ------ .../sampledCuttingPlane/sampledCuttingPlane.H | 270 --- .../sampledCuttingPlaneTemplates.C | 94 -- .../sampledDistanceSurface.C | 154 ++ .../sampledDistanceSurface.H | 137 ++ .../sampledIsoSurface/sampledIsoSurface.C | 136 ++ .../sampledIsoSurface/sampledIsoSurface.H | 131 ++ .../sampledIsoSurfaceSurface.C | 141 ++ .../sampledIsoSurfaceSurface.H | 190 +++ .../sampledIsoSurfaceSurfaceTemplates.C} | 53 +- .../sampledPlane/sampledPlane.C | 243 --- .../sampledPlane/sampledPlane.H | 243 --- .../sampledSurface/sampledSurface.H | 9 +- .../sampledSurface/sampledSurfaceTemplates.C | 48 +- .../sampledThresholdCellFaces.C | 2 +- .../sampledThresholdCellFaces.H | 2 +- .../sampledThresholdCellFacesTemplates.C | 2 +- .../thresholdCellFaces.C | 0 .../thresholdCellFaces.H | 2 +- .../movingCone/system/cuttingPlane | 35 - .../motorBike/lesFiles/controlDict | 2 +- .../motorBike/motorBike/system/controlDict | 2 +- .../system/{cuttingPlane => cutPlane} | 4 +- .../motorBikeSteady/system/controlDict | 2 +- .../system/{cuttingPlane => cutPlane} | 4 +- .../movingCone/system/controlDict | 2 +- .../system/{cuttingPlane => cutPlane} | 4 +- .../propeller/system/surfaces | 2 +- 89 files changed, 4462 insertions(+), 5820 deletions(-) create mode 100644 src/OpenFOAM/containers/HashTables/HashList/HashList.C create mode 100644 src/OpenFOAM/containers/HashTables/HashList/HashList.H create mode 100644 src/finiteVolume/interpolation/interpolation/interpolationVolPointInterpolation/interpolationVolPointInterpolation.C create mode 100644 src/finiteVolume/interpolation/interpolation/interpolationVolPointInterpolation/interpolationVolPointInterpolation.H rename src/{sampling/cuttingPlane/cuttingPlaneTemplates.C => finiteVolume/interpolation/interpolation/interpolationVolPointInterpolation/makeInterpolationVolPointInterpolation.C} (68%) create mode 100644 src/meshTools/cutPoly/cellEdgeAddressing.C create mode 100644 src/meshTools/cutPoly/cellEdgeAddressing.H create mode 100644 src/meshTools/cutPoly/cellEdgeAddressingI.H create mode 100644 src/meshTools/cutPoly/cutPoly.C create mode 100644 src/meshTools/cutPoly/cutPoly.H create mode 100644 src/meshTools/cutPoly/cutPolyIntegral.H create mode 100644 src/meshTools/cutPoly/cutPolyIntegralTemplates.C create mode 100644 src/meshTools/cutPoly/cutPolyIsoSurface.C create mode 100644 src/meshTools/cutPoly/cutPolyIsoSurface.H create mode 100644 src/meshTools/cutPoly/cutPolyIsoSurfaceTemplates.C create mode 100644 src/meshTools/cutPoly/cutPolyValue.H create mode 100644 src/meshTools/cutPoly/cutPolyValueI.H create mode 100644 src/meshTools/cutPoly/cutPolyValueTemplates.C rename src/{OpenFOAM/meshes/primitiveShapes/cut/cut.H => meshTools/cutTriTet/cutTriTet.H} (96%) rename src/{OpenFOAM/meshes/primitiveShapes/cut/cutI.H => meshTools/cutTriTet/cutTriTetI.H} (91%) rename src/{OpenFOAM/meshes/primitiveShapes/cut/cutTemplates.C => meshTools/cutTriTet/cutTriTetTemplates.C} (94%) delete mode 100644 src/sampling/cuttingPlane/cuttingPlane.C delete mode 100644 src/sampling/cuttingPlane/cuttingPlane.H delete mode 100644 src/sampling/sampledSurface/distanceSurface/distanceSurface.C delete mode 100644 src/sampling/sampledSurface/distanceSurface/distanceSurface.H delete mode 100644 src/sampling/sampledSurface/distanceSurface/distanceSurfaceTemplates.C delete mode 100644 src/sampling/sampledSurface/isoSurface/isoSurface.C delete mode 100644 src/sampling/sampledSurface/isoSurface/isoSurface.H delete mode 100644 src/sampling/sampledSurface/isoSurface/isoSurfaceTemplates.C delete mode 100644 src/sampling/sampledSurface/isoSurface/sampledIsoSurface.C delete mode 100644 src/sampling/sampledSurface/isoSurface/sampledIsoSurface.H delete mode 100644 src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceTemplates.C create mode 100644 src/sampling/sampledSurface/sampledCutPlane/sampledCutPlane.C create mode 100644 src/sampling/sampledSurface/sampledCutPlane/sampledCutPlane.H delete mode 100644 src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C delete mode 100644 src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.H delete mode 100644 src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlaneTemplates.C create mode 100644 src/sampling/sampledSurface/sampledDistanceSurface/sampledDistanceSurface.C create mode 100644 src/sampling/sampledSurface/sampledDistanceSurface/sampledDistanceSurface.H create mode 100644 src/sampling/sampledSurface/sampledIsoSurface/sampledIsoSurface.C create mode 100644 src/sampling/sampledSurface/sampledIsoSurface/sampledIsoSurface.H create mode 100644 src/sampling/sampledSurface/sampledIsoSurfaceSurface/sampledIsoSurfaceSurface.C create mode 100644 src/sampling/sampledSurface/sampledIsoSurfaceSurface/sampledIsoSurfaceSurface.H rename src/sampling/sampledSurface/{sampledPlane/sampledPlaneTemplates.C => sampledIsoSurfaceSurface/sampledIsoSurfaceSurfaceTemplates.C} (56%) delete mode 100644 src/sampling/sampledSurface/sampledPlane/sampledPlane.C delete mode 100644 src/sampling/sampledSurface/sampledPlane/sampledPlane.H rename src/sampling/sampledSurface/{thresholdCellFaces => sampledThresholdCellFaces}/sampledThresholdCellFaces.C (99%) rename src/sampling/sampledSurface/{thresholdCellFaces => sampledThresholdCellFaces}/sampledThresholdCellFaces.H (99%) rename src/sampling/sampledSurface/{thresholdCellFaces => sampledThresholdCellFaces}/sampledThresholdCellFacesTemplates.C (97%) rename src/sampling/sampledSurface/{thresholdCellFaces => sampledThresholdCellFaces}/thresholdCellFaces.C (100%) rename src/sampling/sampledSurface/{thresholdCellFaces => sampledThresholdCellFaces}/thresholdCellFaces.H (98%) delete mode 100644 tutorials/compressible/rhoCentralFoam/movingCone/system/cuttingPlane rename tutorials/modules/incompressibleFluid/motorBike/motorBike/system/{cuttingPlane => cutPlane} (94%) rename tutorials/modules/incompressibleFluid/motorBikeSteady/system/{cuttingPlane => cutPlane} (94%) rename tutorials/modules/incompressibleFluid/movingCone/system/{cuttingPlane => cutPlane} (94%) diff --git a/applications/test/tetTetOverlap/Test-tetTetOverlap.C b/applications/test/tetTetOverlap/Test-tetTetOverlap.C index dbb3bbcdf0..aaf00f3098 100644 --- a/applications/test/tetTetOverlap/Test-tetTetOverlap.C +++ b/applications/test/tetTetOverlap/Test-tetTetOverlap.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2012-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -32,7 +32,7 @@ Description #include "tetPointRef.H" #include "OFstream.H" #include "meshTools.H" -#include "cut.H" +#include "cutTriTet.H" using namespace Foam; @@ -87,9 +87,9 @@ int main(int argc, char *argv[]) // Do intersection typedef DynamicList> tetList; tetList tetsIn1, tetsIn2, tetsOut; - cut::appendOp tetOpIn1(tetsIn1); - cut::appendOp tetOpIn2(tetsIn2); - cut::appendOp tetOpOut(tetsOut); + cutTriTet::appendOp tetOpIn1(tetsIn1); + cutTriTet::appendOp tetOpIn2(tetsIn2); + cutTriTet::appendOp tetOpOut(tetsOut); const plane p0(tetB[1], tetB[3], tetB[2]); tetsIn1.clear(); diff --git a/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshBackgroundMesh/foamyHexMeshBackgroundMesh.C b/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshBackgroundMesh/foamyHexMeshBackgroundMesh.C index 9b85dc5667..a6ee782131 100644 --- a/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshBackgroundMesh/foamyHexMeshBackgroundMesh.C +++ b/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshBackgroundMesh/foamyHexMeshBackgroundMesh.C @@ -41,7 +41,7 @@ Description #include "cellShape.H" #include "cellModeller.H" #include "DynamicField.H" -#include "isoSurface.H" +#include "cutPolyIsoSurface.H" #include "vtkSurfaceWriter.H" #include "syncTools.H" @@ -707,13 +707,7 @@ int main(int argc, char *argv[]) } } - isoSurface iso - ( - mesh, - cellDistance, - pointDistance, - 0 - ); + cutPolyIsoSurface iso(mesh, pointDistance, 0); isoFaces.setSize(iso.size()); forAll(isoFaces, i) diff --git a/etc/caseDicts/postProcessing/surface/cutPlaneSurface.cfg b/etc/caseDicts/postProcessing/surface/cutPlaneSurface.cfg index 9c8441821f..26a75b8ee8 100644 --- a/etc/caseDicts/postProcessing/surface/cutPlaneSurface.cfg +++ b/etc/caseDicts/postProcessing/surface/cutPlaneSurface.cfg @@ -12,7 +12,7 @@ surfaces ( cutPlane { - type cuttingPlane; + type cutPlane; interpolate $interpolate; planeType pointAndNormal; point $point; diff --git a/src/OpenFOAM/containers/HashTables/HashList/HashList.C b/src/OpenFOAM/containers/HashTables/HashList/HashList.C new file mode 100644 index 0000000000..2330d0f81f --- /dev/null +++ b/src/OpenFOAM/containers/HashTables/HashList/HashList.C @@ -0,0 +1,110 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2022 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 "HashList.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + template + const Key HashList::nullKey = Key::null; +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::HashList::HashList(const label size) +: + List>(size, Tuple2(nullKey, Type())) +{} + + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +template +bool Foam::HashList::insert(const Key& k, const Type& t) +{ + List>& map = *this; + + const label n = map.size(); + + const unsigned h = Hash()(k); + + for (label i = 0; i < n; i ++) + { + const label hi = (h + i) % n; + + if (map[hi].first() == nullKey) + { + map[hi] = Tuple2(k, t); + return true; + } + + if (map[hi].first() == k) + { + return false; + } + } + + FatalErrorInFunction + << "Hash list is full" + << exit(FatalError); + + return false; +} + + +// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * // + +template +const Type& Foam::HashList::operator[](const Key& k) const +{ + const List>& map = *this; + + const label n = map.size(); + + const unsigned h = Hash()(k); + + for (label i = 0; i < n; i ++) + { + const label hi = (h + i) % n; + + if (map[hi].first() == k) + { + return map[hi].second(); + } + } + + FatalErrorInFunction + << "Hash list does not contain key \"" << k << "\"" + << exit(FatalError); + + return NullObjectRef(); +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/containers/HashTables/HashList/HashList.H b/src/OpenFOAM/containers/HashTables/HashList/HashList.H new file mode 100644 index 0000000000..503779d0a0 --- /dev/null +++ b/src/OpenFOAM/containers/HashTables/HashList/HashList.H @@ -0,0 +1,104 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2022 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 . + +Class + Foam::HashList + +Description + HashList class. Like HashTable, but much less dynamic memory-y. Should be + faster for small sets of non-dynamic primitive types (labels, edges, + points, etc...). It is also much less functional at present. There is no + re-sizing, so you have to make sure it is constructed sufficiently large to + hold all the data that will ever be inserted into it. + +SourceFiles + HashList.C + +\*---------------------------------------------------------------------------*/ + +#include "List.H" +#include "Tuple2.H" +#include "word.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifndef HashList_H +#define HashList_H + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class HashList Declaration +\*---------------------------------------------------------------------------*/ + +template +class HashList +: + private List> +{ +public: + + // Public Static Member Data + + //- Null key value for unset elements in the list + static const Key nullKey; + + + // Constructors + + //- Construct given a size + HashList(const label size); + + + // Member Functions + + //- Insert into the hash list. Return true if the value was newly + // inserted, or false if it was already there. + bool insert(const Key& k, const Type& t); + + + // Member Operators + + //- Retrieve from the hash list + const Type& operator[](const Key& k) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "HashList.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C index 6b62a8fb06..3bda7520d0 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C +++ b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C @@ -309,13 +309,19 @@ Foam::point Foam::plane::aPoint() const Foam::point Foam::plane::nearestPoint(const point& p) const { - return p - normal_*((p - point_) & normal_); + return p - normal_*signedDistance(p); } Foam::scalar Foam::plane::distance(const point& p) const { - return mag((p - point_) & normal_); + return mag(signedDistance(p)); +} + + +Foam::scalar Foam::plane::signedDistance(const point& p) const +{ + return (p - point_) & normal_; } diff --git a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.H b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.H index f02161dd1c..bad6771c1a 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.H +++ b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.H @@ -194,6 +194,9 @@ public: //- Return distance from the given point to the plane scalar distance(const point& p) const; + //- Return signed distance from the given point to the plane + scalar signedDistance(const point& p) const; + //- Return cut coefficient for plane and line defined by // origin and direction scalar normalIntersect(const point& pnt0, const vector& dir) const; diff --git a/src/finiteVolume/Make/files b/src/finiteVolume/Make/files index ec52f5ae91..e4cc489d90 100644 --- a/src/finiteVolume/Make/files +++ b/src/finiteVolume/Make/files @@ -290,6 +290,7 @@ $(interpolation)/interpolation/interpolations.C $(interpolation)/interpolationCell/makeInterpolationCell.C $(interpolation)/interpolationCellPatchConstrained/makeInterpolationCellPatchConstrained.C +$(interpolation)/interpolationVolPointInterpolation/makeInterpolationVolPointInterpolation.C $(interpolation)/interpolationCellPoint/cellPointWeight/cellPointWeight.C $(interpolation)/interpolationCellPoint/makeInterpolationCellPoint.C $(interpolation)/interpolationCellPointFace/makeInterpolationCellPointFace.C diff --git a/src/finiteVolume/cfdTools/general/levelSet/levelSet.C b/src/finiteVolume/cfdTools/general/levelSet/levelSet.C index 3ec11f4b30..3811297b8d 100644 --- a/src/finiteVolume/cfdTools/general/levelSet/levelSet.C +++ b/src/finiteVolume/cfdTools/general/levelSet/levelSet.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2017-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -24,7 +24,7 @@ License \*---------------------------------------------------------------------------*/ #include "levelSet.H" -#include "cut.H" +#include "cutTriTet.H" #include "polyMeshTetDecomposition.H" #include "tetIndices.H" @@ -38,6 +38,9 @@ Foam::tmp Foam::levelSetFraction const bool above ) { + typedef cutTriTet::noOp noOp; + typedef cutTriTet::volumeOp volumeOp; + tmp tResult(new scalarField(mesh.nCells(), Zero)); scalarField& result = tResult.ref(); @@ -69,15 +72,15 @@ Foam::tmp Foam::levelSetFraction levelP[triIs[2]] }; - v += cut::volumeOp()(tet); + v += volumeOp()(tet); if (above) { - r += tetCut(tet, level, cut::volumeOp(), cut::noOp()); + r += tetCut(tet, level, volumeOp(), noOp()); } else { - r += tetCut(tet, level, cut::noOp(), cut::volumeOp()); + r += tetCut(tet, level, noOp(), volumeOp()); } } @@ -96,6 +99,9 @@ Foam::tmp Foam::levelSetFraction const bool above ) { + typedef cutTriTet::noOp noOp; + typedef cutTriTet::areaMagOp areaMagOp; + tmp tResult(new scalarField(patch.size(), 0)); scalarField& result = tResult.ref(); @@ -124,15 +130,15 @@ Foam::tmp Foam::levelSetFraction levelP[e[1]] }; - a += cut::areaMagOp()(tri); + a += areaMagOp()(tri); if (above) { - r += triCut(tri, level, cut::areaMagOp(), cut::noOp()); + r += triCut(tri, level, areaMagOp(), noOp()); } else { - r += triCut(tri, level, cut::noOp(), cut::areaMagOp()); + r += triCut(tri, level, noOp(), areaMagOp()); } } diff --git a/src/finiteVolume/cfdTools/general/levelSet/levelSetTemplates.C b/src/finiteVolume/cfdTools/general/levelSet/levelSetTemplates.C index 08c4fc26c3..ff9310f018 100644 --- a/src/finiteVolume/cfdTools/general/levelSet/levelSetTemplates.C +++ b/src/finiteVolume/cfdTools/general/levelSet/levelSetTemplates.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2017-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -24,7 +24,7 @@ License \*---------------------------------------------------------------------------*/ #include "levelSet.H" -#include "cut.H" +#include "cutTriTet.H" #include "polyMeshTetDecomposition.H" #include "tetIndices.H" @@ -73,7 +73,7 @@ Foam::tmp> Foam::levelSetAverage levelP[triIs[1]], levelP[triIs[2]] }; - const cut::volumeIntegrateOp + const cutTriTet::volumeIntegrateOp positive = FixedList ({ positiveC[cI], @@ -81,7 +81,7 @@ Foam::tmp> Foam::levelSetAverage positiveP[triIs[1]], positiveP[triIs[2]] }); - const cut::volumeIntegrateOp + const cutTriTet::volumeIntegrateOp negative = FixedList ({ negativeC[cI], @@ -90,7 +90,7 @@ Foam::tmp> Foam::levelSetAverage negativeP[triIs[2]] }); - v += cut::volumeOp()(tet); + v += cutTriTet::volumeOp()(tet); r += tetCut(tet, level, positive, negative); } @@ -142,14 +142,14 @@ Foam::tmp> Foam::levelSetAverage levelP[e[0]], levelP[e[1]] }; - const cut::areaMagIntegrateOp + const cutTriTet::areaMagIntegrateOp positive = FixedList ({ positiveF[fI], positiveP[e[0]], positiveP[e[1]] }); - const cut::areaMagIntegrateOp + const cutTriTet::areaMagIntegrateOp negative = FixedList ({ negativeF[fI], @@ -157,7 +157,7 @@ Foam::tmp> Foam::levelSetAverage negativeP[e[1]] }); - a += cut::areaMagOp()(tri); + a += cutTriTet::areaMagOp()(tri); r += triCut(tri, level, positive, negative); } diff --git a/src/finiteVolume/interpolation/interpolation/interpolation/interpolation.C b/src/finiteVolume/interpolation/interpolation/interpolation/interpolation.C index d9ac7742b0..5f82300c01 100644 --- a/src/finiteVolume/interpolation/interpolation/interpolation/interpolation.C +++ b/src/finiteVolume/interpolation/interpolation/interpolation/interpolation.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -103,8 +103,8 @@ Foam::tmp> Foam::fieldInterpolation::interpolate ( const vectorField& position, - const labelField& celli, - const labelField& facei + const labelList& celli, + const labelList& facei ) const { tmp> tField(new Field(position.size())); @@ -131,10 +131,10 @@ Foam::tmp> Foam::fieldInterpolation::interpolate ( const Field& coordinates, - const labelField& celli, - const labelField& tetFacei, - const labelField& tetPti, - const labelField& facei + const labelList& celli, + const labelList& tetFacei, + const labelList& tetPti, + const labelList& facei ) const { tmp> tField(new Field(coordinates.size())); diff --git a/src/finiteVolume/interpolation/interpolation/interpolation/interpolation.H b/src/finiteVolume/interpolation/interpolation/interpolation/interpolation.H index 56557a4f47..06741776f3 100644 --- a/src/finiteVolume/interpolation/interpolation/interpolation/interpolation.H +++ b/src/finiteVolume/interpolation/interpolation/interpolation/interpolation.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -136,8 +136,8 @@ public: virtual tmp> interpolate ( const vectorField& position, - const labelField& celli, - const labelField& facei = NullObjectRef() + const labelList& celli, + const labelList& facei = NullObjectRef() ) const = 0; //- Interpolate field to the given coordinates in the tetrahedron @@ -155,10 +155,10 @@ public: virtual tmp> interpolate ( const Field& coordinates, - const labelField& celli, - const labelField& tetFacei, - const labelField& tetPti, - const labelField& facei = NullObjectRef() + const labelList& celli, + const labelList& tetFacei, + const labelList& tetPti, + const labelList& facei = NullObjectRef() ) const = 0; }; @@ -186,18 +186,18 @@ public: virtual tmp> interpolate ( const vectorField& position, - const labelField& celli, - const labelField& facei = NullObjectRef() + const labelList& celli, + const labelList& facei = NullObjectRef() ) const; //- Interpolate field to the given coordinates in the given tetrahedra virtual tmp> interpolate ( const Field& coordinates, - const labelField& celli, - const labelField& tetFacei, - const labelField& tetPti, - const labelField& facei = NullObjectRef() + const labelList& celli, + const labelList& tetFacei, + const labelList& tetPti, + const labelList& facei = NullObjectRef() ) const; }; @@ -208,22 +208,13 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#define makeInterpolationType(SS, Type) \ - \ -defineNamedTemplateTypeNameAndDebug(SS, 0); \ - \ -interpolation::adddictionaryConstructorToTable> \ - add##SS##Type##ConstructorToTable_; - - -#define makeInterpolation(SS) \ - \ -makeInterpolationType(SS, scalar) \ -makeInterpolationType(SS, vector) \ -makeInterpolationType(SS, sphericalTensor) \ -makeInterpolationType(SS, symmTensor) \ -makeInterpolationType(SS, tensor) +#define defineInterpolation(Type, InterpolationType) \ + defineNamedTemplateTypeNameAndDebug(InterpolationType, 0); +#define makeInterpolation(Type, InterpolationType) \ + interpolation:: \ + adddictionaryConstructorToTable> \ + add##InterpolationType##Type##ConstructorToTable_; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/finiteVolume/interpolation/interpolation/interpolationCell/makeInterpolationCell.C b/src/finiteVolume/interpolation/interpolation/interpolationCell/makeInterpolationCell.C index d411310ead..c3f4a73c15 100644 --- a/src/finiteVolume/interpolation/interpolation/interpolationCell/makeInterpolationCell.C +++ b/src/finiteVolume/interpolation/interpolation/interpolationCell/makeInterpolationCell.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -29,7 +29,8 @@ License namespace Foam { - makeInterpolation(interpolationCell); + FOR_ALL_FIELD_TYPES(defineInterpolation, interpolationCell); + FOR_ALL_FIELD_TYPES(makeInterpolation, interpolationCell); } // ************************************************************************* // diff --git a/src/finiteVolume/interpolation/interpolation/interpolationCellPatchConstrained/makeInterpolationCellPatchConstrained.C b/src/finiteVolume/interpolation/interpolation/interpolationCellPatchConstrained/makeInterpolationCellPatchConstrained.C index d0151bcff9..05384fa1a3 100644 --- a/src/finiteVolume/interpolation/interpolation/interpolationCellPatchConstrained/makeInterpolationCellPatchConstrained.C +++ b/src/finiteVolume/interpolation/interpolation/interpolationCellPatchConstrained/makeInterpolationCellPatchConstrained.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -29,7 +29,16 @@ License namespace Foam { - makeInterpolation(interpolationCellPatchConstrained); + FOR_ALL_FIELD_TYPES + ( + defineInterpolation, + interpolationCellPatchConstrained + ); + FOR_ALL_FIELD_TYPES + ( + makeInterpolation, + interpolationCellPatchConstrained + ); } // ************************************************************************* // diff --git a/src/finiteVolume/interpolation/interpolation/interpolationCellPoint/interpolationCellPoint.C b/src/finiteVolume/interpolation/interpolation/interpolationCellPoint/interpolationCellPoint.C index 1b4d15e791..bbc71e000b 100644 --- a/src/finiteVolume/interpolation/interpolation/interpolationCellPoint/interpolationCellPoint.C +++ b/src/finiteVolume/interpolation/interpolation/interpolationCellPoint/interpolationCellPoint.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -35,15 +35,7 @@ Foam::interpolationCellPoint::interpolationCellPoint ) : fieldInterpolation>(psi), - psip_ - ( - volPointInterpolation::New(psi.mesh()).interpolate - ( - psi, - "volPointInterpolate(" + psi.name() + ')', - true // use cache - ) - ) + interpolationVolPointInterpolation(psi) { // Uses cellPointWeight to do interpolation which needs tet decomposition (void)psi.mesh().tetBasePtIs(); @@ -58,7 +50,7 @@ Foam::interpolationCellPoint::interpolationCellPoint ) : fieldInterpolation>(psi), - psip_(psip) + interpolationVolPointInterpolation(psi, psip) { // Uses cellPointWeight to do interpolation which needs tet decomposition (void)psi.mesh().tetBasePtIs(); diff --git a/src/finiteVolume/interpolation/interpolation/interpolationCellPoint/interpolationCellPoint.H b/src/finiteVolume/interpolation/interpolation/interpolationCellPoint/interpolationCellPoint.H index fd2ac4d755..bba60b0f00 100644 --- a/src/finiteVolume/interpolation/interpolation/interpolationCellPoint/interpolationCellPoint.H +++ b/src/finiteVolume/interpolation/interpolation/interpolationCellPoint/interpolationCellPoint.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -33,7 +33,7 @@ Description #ifndef interpolationCellPoint_H #define interpolationCellPoint_H -#include "interpolation.H" +#include "interpolationVolPointInterpolation.H" #include "cellPointWeight.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -48,16 +48,9 @@ namespace Foam template class interpolationCellPoint : - public fieldInterpolation> + public fieldInterpolation>, + public interpolationVolPointInterpolation { -protected: - - // Protected data - - //- Interpolated volfield - const GeometricField psip_; - - public: //- Runtime type information diff --git a/src/finiteVolume/interpolation/interpolation/interpolationCellPoint/interpolationCellPointI.H b/src/finiteVolume/interpolation/interpolation/interpolationCellPoint/interpolationCellPointI.H index b23235e6d6..10a83bb7cd 100644 --- a/src/finiteVolume/interpolation/interpolation/interpolationCellPoint/interpolationCellPointI.H +++ b/src/finiteVolume/interpolation/interpolation/interpolationCellPoint/interpolationCellPointI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -35,9 +35,9 @@ inline Type Foam::interpolationCellPoint::interpolate const triFace& faceVertices = cpw.faceVertices(); Type t = this->psi_[cpw.cell()]*weights[0]; - t += psip_[faceVertices[0]]*weights[1]; - t += psip_[faceVertices[1]]*weights[2]; - t += psip_[faceVertices[2]]*weights[3]; + t += this->psip_[faceVertices[0]]*weights[1]; + t += this->psip_[faceVertices[1]]*weights[2]; + t += this->psip_[faceVertices[2]]*weights[3]; return t; } @@ -83,9 +83,9 @@ inline Type Foam::interpolationCellPoint::interpolate return this->psi_[tetIs.cell()]*coordinates[0] - + psip_[triIs[0]]*coordinates[1] - + psip_[triIs[1]]*coordinates[2] - + psip_[triIs[2]]*coordinates[3]; + + this->psip_[triIs[0]]*coordinates[1] + + this->psip_[triIs[1]]*coordinates[2] + + this->psip_[triIs[2]]*coordinates[3]; } diff --git a/src/finiteVolume/interpolation/interpolation/interpolationCellPoint/makeInterpolationCellPoint.C b/src/finiteVolume/interpolation/interpolation/interpolationCellPoint/makeInterpolationCellPoint.C index af6c36bbb4..2287614911 100644 --- a/src/finiteVolume/interpolation/interpolation/interpolationCellPoint/makeInterpolationCellPoint.C +++ b/src/finiteVolume/interpolation/interpolation/interpolationCellPoint/makeInterpolationCellPoint.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -29,7 +29,8 @@ License namespace Foam { - makeInterpolation(interpolationCellPoint); + FOR_ALL_FIELD_TYPES(defineInterpolation, interpolationCellPoint); + FOR_ALL_FIELD_TYPES(makeInterpolation, interpolationCellPoint); } // ************************************************************************* // diff --git a/src/finiteVolume/interpolation/interpolation/interpolationCellPointFace/interpolationCellPointFace.C b/src/finiteVolume/interpolation/interpolation/interpolationCellPointFace/interpolationCellPointFace.C index 690e27bd65..98b79073a0 100644 --- a/src/finiteVolume/interpolation/interpolation/interpolationCellPointFace/interpolationCellPointFace.C +++ b/src/finiteVolume/interpolation/interpolation/interpolationCellPointFace/interpolationCellPointFace.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -40,15 +40,7 @@ Foam::interpolationCellPointFace::interpolationCellPointFace ) : fieldInterpolation>(psi), - psip_ - ( - volPointInterpolation::New(psi.mesh()).interpolate - ( - psi, - "volPointInterpolate(" + psi.name() + ')', - true // use cache - ) - ), + interpolationVolPointInterpolation(psi), psis_(linearInterpolate(psi)) {} @@ -211,7 +203,7 @@ Type Foam::interpolationCellPointFace::interpolate { for (label i=0; i<2; i++) { - ts[i] = psip_[tetPointLabels[i]]; + ts[i] = this->psip_[tetPointLabels[i]]; } if (closestFace < psis_.size()) @@ -301,7 +293,7 @@ Type Foam::interpolationCellPointFace::interpolate // add up the point values ... for (label i=0; i<2; i++) { - Type vel = psip_[tetPointLabels[i]]; + Type vel = this->psip_[tetPointLabels[i]]; t += phi[i]*vel; } diff --git a/src/finiteVolume/interpolation/interpolation/interpolationCellPointFace/interpolationCellPointFace.H b/src/finiteVolume/interpolation/interpolation/interpolationCellPointFace/interpolationCellPointFace.H index 8d5893149a..275a5adec5 100644 --- a/src/finiteVolume/interpolation/interpolation/interpolationCellPointFace/interpolationCellPointFace.H +++ b/src/finiteVolume/interpolation/interpolation/interpolationCellPointFace/interpolationCellPointFace.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -32,7 +32,7 @@ Description #ifndef interpolationCellPointFace_H #define interpolationCellPointFace_H -#include "interpolation.H" +#include "interpolationVolPointInterpolation.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -46,13 +46,11 @@ namespace Foam template class interpolationCellPointFace : - public fieldInterpolation> + public fieldInterpolation>, + public interpolationVolPointInterpolation { // Private Data - //- Interpolated volfield - const GeometricField psip_; - //- Linearly interpolated volfield const GeometricField psis_; diff --git a/src/finiteVolume/interpolation/interpolation/interpolationCellPointFace/makeInterpolationCellPointFace.C b/src/finiteVolume/interpolation/interpolation/interpolationCellPointFace/makeInterpolationCellPointFace.C index 027baf49f0..646a8f85fb 100644 --- a/src/finiteVolume/interpolation/interpolation/interpolationCellPointFace/makeInterpolationCellPointFace.C +++ b/src/finiteVolume/interpolation/interpolation/interpolationCellPointFace/makeInterpolationCellPointFace.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -29,7 +29,8 @@ License namespace Foam { - makeInterpolation(interpolationCellPointFace); + FOR_ALL_FIELD_TYPES(defineInterpolation, interpolationCellPointFace); + FOR_ALL_FIELD_TYPES(makeInterpolation, interpolationCellPointFace); } // ************************************************************************* // diff --git a/src/finiteVolume/interpolation/interpolation/interpolationCellPointWallModified/makeInterpolationCellPointWallModified.C b/src/finiteVolume/interpolation/interpolation/interpolationCellPointWallModified/makeInterpolationCellPointWallModified.C index b04e9bab32..1b9c672f4c 100644 --- a/src/finiteVolume/interpolation/interpolation/interpolationCellPointWallModified/makeInterpolationCellPointWallModified.C +++ b/src/finiteVolume/interpolation/interpolation/interpolationCellPointWallModified/makeInterpolationCellPointWallModified.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -29,7 +29,16 @@ License namespace Foam { - makeInterpolation(interpolationCellPointWallModified); + FOR_ALL_FIELD_TYPES + ( + defineInterpolation, + interpolationCellPointWallModified + ); + FOR_ALL_FIELD_TYPES + ( + makeInterpolation, + interpolationCellPointWallModified + ); } // ************************************************************************* // diff --git a/src/finiteVolume/interpolation/interpolation/interpolationPointMVC/interpolationPointMVC.C b/src/finiteVolume/interpolation/interpolation/interpolationPointMVC/interpolationPointMVC.C index b926726f48..3e9932d3fc 100644 --- a/src/finiteVolume/interpolation/interpolation/interpolationPointMVC/interpolationPointMVC.C +++ b/src/finiteVolume/interpolation/interpolation/interpolationPointMVC/interpolationPointMVC.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -35,15 +35,7 @@ Foam::interpolationPointMVC::interpolationPointMVC ) : fieldInterpolation>(psi), - psip_ - ( - volPointInterpolation::New(psi.mesh()).interpolate - ( - psi, - "volPointInterpolate(" + psi.name() + ')', - true // use cache - ) - ) + interpolationVolPointInterpolation(psi) {} diff --git a/src/finiteVolume/interpolation/interpolation/interpolationPointMVC/interpolationPointMVC.H b/src/finiteVolume/interpolation/interpolation/interpolationPointMVC/interpolationPointMVC.H index c777011ada..a858062010 100644 --- a/src/finiteVolume/interpolation/interpolation/interpolationPointMVC/interpolationPointMVC.H +++ b/src/finiteVolume/interpolation/interpolation/interpolationPointMVC/interpolationPointMVC.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -33,7 +33,7 @@ Description #ifndef interpolationPointMVC_H #define interpolationPointMVC_H -#include "interpolation.H" +#include "interpolationVolPointInterpolation.H" #include "pointMVCWeight.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -48,16 +48,9 @@ namespace Foam template class interpolationPointMVC : - public fieldInterpolation> + public fieldInterpolation>, + public interpolationVolPointInterpolation { -protected: - - // Protected data - - //- Interpolated volfield - const GeometricField psip_; - - public: //- Runtime type information diff --git a/src/finiteVolume/interpolation/interpolation/interpolationPointMVC/interpolationPointMVCI.H b/src/finiteVolume/interpolation/interpolation/interpolationPointMVC/interpolationPointMVCI.H index bf1fe8980a..96a7ca07ef 100644 --- a/src/finiteVolume/interpolation/interpolation/interpolationPointMVC/interpolationPointMVCI.H +++ b/src/finiteVolume/interpolation/interpolation/interpolationPointMVC/interpolationPointMVCI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -31,7 +31,7 @@ inline Type Foam::interpolationPointMVC::interpolate const pointMVCWeight& cpw ) const { - return cpw.interpolate(psip_); + return cpw.interpolate(this->psip_); } diff --git a/src/finiteVolume/interpolation/interpolation/interpolationPointMVC/makeInterpolationPointMVC.C b/src/finiteVolume/interpolation/interpolation/interpolationPointMVC/makeInterpolationPointMVC.C index d1adc230a2..c35ddf203a 100644 --- a/src/finiteVolume/interpolation/interpolation/interpolationPointMVC/makeInterpolationPointMVC.C +++ b/src/finiteVolume/interpolation/interpolation/interpolationPointMVC/makeInterpolationPointMVC.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -29,7 +29,8 @@ License namespace Foam { - makeInterpolation(interpolationPointMVC); + FOR_ALL_FIELD_TYPES(defineInterpolation, interpolationPointMVC); + FOR_ALL_FIELD_TYPES(makeInterpolation, interpolationPointMVC); } // ************************************************************************* // diff --git a/src/finiteVolume/interpolation/interpolation/interpolationVolPointInterpolation/interpolationVolPointInterpolation.C b/src/finiteVolume/interpolation/interpolation/interpolationVolPointInterpolation/interpolationVolPointInterpolation.C new file mode 100644 index 0000000000..5e95da52b7 --- /dev/null +++ b/src/finiteVolume/interpolation/interpolation/interpolationVolPointInterpolation/interpolationVolPointInterpolation.C @@ -0,0 +1,62 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2022 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 "interpolationVolPointInterpolation.H" +#include "volPointInterpolation.H" + +// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * // + +template +Foam::interpolationVolPointInterpolation:: +interpolationVolPointInterpolation +( + const GeometricField& psi +) +: + psip_ + ( + volPointInterpolation::New(psi.mesh()).interpolate + ( + psi, + "volPointInterpolate(" + psi.name() + ')', + true // use cache + ) + ) +{} + + +template +Foam::interpolationVolPointInterpolation:: +interpolationVolPointInterpolation +( + const GeometricField& psi, + tmp> psip +) +: + psip_(psip) +{} + + +// ************************************************************************* // diff --git a/src/finiteVolume/interpolation/interpolation/interpolationVolPointInterpolation/interpolationVolPointInterpolation.H b/src/finiteVolume/interpolation/interpolation/interpolationVolPointInterpolation/interpolationVolPointInterpolation.H new file mode 100644 index 0000000000..39eed4ba6d --- /dev/null +++ b/src/finiteVolume/interpolation/interpolation/interpolationVolPointInterpolation/interpolationVolPointInterpolation.H @@ -0,0 +1,111 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2022 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 . + +Class + Foam::interpolationVolPointInterpolation + +Description + Base class for interpolations that require a vol-point interpolated field + +\*---------------------------------------------------------------------------*/ + +#ifndef interpolationVolPointInterpolation_H +#define interpolationVolPointInterpolation_H + +#include "interpolation.H" +#include "cellPointWeight.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class interpolationVolPointInterpolation Declaration +\*---------------------------------------------------------------------------*/ + +template +class interpolationVolPointInterpolation +{ +protected: + + // Protected data + + //- Interpolated volfield + const GeometricField psip_; + + +public: + + //- Runtime type information + TypeName("interpolationVolPointInterpolation"); + + + + // Constructors + + //- Construct from components + interpolationVolPointInterpolation + ( + const GeometricField& psi + ); + + //- Construct from components + interpolationVolPointInterpolation + ( + const GeometricField& psi, + tmp> psip + ); + + + // Destructor + virtual ~interpolationVolPointInterpolation() + {} + + + // Member Functions + + //- Access the point field + inline const GeometricField& + psip() const + { + return psip_; + } +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "interpolationVolPointInterpolation.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/sampling/cuttingPlane/cuttingPlaneTemplates.C b/src/finiteVolume/interpolation/interpolation/interpolationVolPointInterpolation/makeInterpolationVolPointInterpolation.C similarity index 68% rename from src/sampling/cuttingPlane/cuttingPlaneTemplates.C rename to src/finiteVolume/interpolation/interpolation/interpolationVolPointInterpolation/makeInterpolationVolPointInterpolation.C index ad8ffbb673..1e0c77d28e 100644 --- a/src/sampling/cuttingPlane/cuttingPlaneTemplates.C +++ b/src/finiteVolume/interpolation/interpolation/interpolationVolPointInterpolation/makeInterpolationVolPointInterpolation.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -21,36 +21,19 @@ License You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . -Description - Cutting plane sampling functionality - \*---------------------------------------------------------------------------*/ -#include "cuttingPlane.H" +#include "interpolationVolPointInterpolation.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template -Foam::tmp> Foam::cuttingPlane::sample -( - const Field& fld -) const +namespace Foam { - return tmp>(new Field(fld, cutCells())); -} - - -template -Foam::tmp> Foam::cuttingPlane::sample -( - const tmp>& tfld -) const -{ - tmp> tsf = sample(tfld()); - tfld.clear(); - return tsf; + FOR_ALL_FIELD_TYPES + ( + defineInterpolation, + interpolationVolPointInterpolation + ); } // ************************************************************************* // diff --git a/src/meshTools/Make/files b/src/meshTools/Make/files index fdbdb6565c..ff5fe65921 100644 --- a/src/meshTools/Make/files +++ b/src/meshTools/Make/files @@ -255,6 +255,10 @@ tetOverlapVolume/tetOverlapVolume.C triIntersect/triIntersect.C triIntersect/triIntersectLocationIO.C +cutPoly/cellEdgeAddressing.C +cutPoly/cutPoly.C +cutPoly/cutPolyIsoSurface.C + nonConformal/polyPatches/nonConformal/nonConformalPolyPatch.C nonConformal/polyPatches/nonConformalCoupled/nonConformalCoupledPolyPatch.C nonConformal/polyPatches/nonConformalCyclic/nonConformalCyclicPolyPatch.C diff --git a/src/meshTools/cutPoly/cellEdgeAddressing.C b/src/meshTools/cutPoly/cellEdgeAddressing.C new file mode 100644 index 0000000000..9a528eb96c --- /dev/null +++ b/src/meshTools/cutPoly/cellEdgeAddressing.C @@ -0,0 +1,223 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2022 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 "cellEdgeAddressing.H" +#include "polyDistributionMap.H" +#include "polyTopoChangeMap.H" +#include "polyMeshMap.H" +#include "HashList.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// An edge hash functor that is much faster than Hash, but is also more +// prone to collisions +struct QuickHashEdge +{ + unsigned operator()(const edge& e) + { + return e[0]*e[1]; + } +}; + +// An invalid null edge for unset entries in the edge map +template<> +const edge HashList::nullKey(-labelMax, -labelMax); + +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::cellEdgeAddressing::cellEdgeAddressing +( + const cell& c, + const faceList& fs, + const bool cOwnsFirst +) +{ + // Compute the number of cell edges + label nCellEdges = 0; + forAll(c, cfi) + { + const face& f = fs[c[cfi]]; + + nCellEdges += f.size(); + } + nCellEdges /= 2; + + // Construct a map to enumerate the cell edges + HashList edgeToCei(nCellEdges*6); + { + label cellEdgei = 0; + + forAll(c, cfi) + { + const face& f = fs[c[cfi]]; + + forAll(f, fei) + { + cellEdgei += edgeToCei.insert(f.faceEdge(fei), cellEdgei); + } + } + } + + // Allocate and initialise the addressing + cfiAndFeiToCei_ = labelListList(c.size()); + ceiToCfiAndFei_ = + List> + ( + nCellEdges, + Pair(labelPair(-1, -1), labelPair(-1, -1)) + ); + + // Copy data out of the map into the addressing + forAll(c, cfi) + { + const face& f = fs[c[cfi]]; + + cfiAndFeiToCei_[cfi] = labelList(f.size(), -1); + + forAll(f, fei) + { + const label cei = edgeToCei[f.faceEdge(fei)]; + + cfiAndFeiToCei_[cfi][fei] = cei; + ceiToCfiAndFei_[cei] + [ + ceiToCfiAndFei_[cei][0] != labelPair(-1, -1) + ] = {cfi, fei}; + } + } + + // Allocate and initialise the face signs + cOwns_ = boolList(c.size(), false); + cOwns_[0] = cOwnsFirst; + boolList cOwnsIsSet(c.size(), false); + cOwnsIsSet[0] = true; + + // Compare cell-face-edges to determine face signs + forAll(c, cfi) + { + const face& f = fs[c[cfi]]; + + if (!cOwnsIsSet[cfi]) continue; + + forAll(f, fei) + { + const label cei = cfiAndFeiToCei_[cfi][fei]; + + const labelPair& other = + ceiToCfiAndFei_[cei] + [ + ceiToCfiAndFei_[cei][0] == labelPair(cfi, fei) + ]; + const label cfj = other[0], fej = other[1]; + + if (cOwnsIsSet[cfj]) continue; + + const label sign = + edge::compare + ( + f.faceEdge(fei), + fs[c[cfj]].faceEdge(fej) + ); + + cOwns_[cfj] = sign < 0 ? cOwns_[cfi] : !cOwns_[cfi]; + cOwnsIsSet[cfj] = true; + } + } +} + + +Foam::cellEdgeAddressingList::cellEdgeAddressingList(const polyMesh& mesh) +: + MeshObject(mesh), + list_(mesh.nCells()) +{} + + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +bool Foam::cellEdgeAddressingList::movePoints() +{ + return true; +} + + +void Foam::cellEdgeAddressingList::distribute(const polyDistributionMap& map) +{ + // We could be more selective here and try to keep addressing for cells + // that haven't changed + + list_.clear(); + list_.resize(map.mesh().nCells()); +} + + +void Foam::cellEdgeAddressingList::topoChange(const polyTopoChangeMap& map) +{ + // We could be more selective here and try to keep addressing for cells + // that haven't changed + + list_.clear(); + list_.resize(map.mesh().nCells()); +} + + +void Foam::cellEdgeAddressingList::mapMesh(const polyMeshMap& map) +{ + list_.clear(); + list_.resize(map.mesh().nCells()); +} + + +// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * // + +const Foam::cellEdgeAddressing& Foam::cellEdgeAddressingList::operator[] +( + const label celli +) const +{ + if (!list_.set(celli)) + { + const cell& c = mesh().cells()[celli]; + const faceList& fs = mesh().faces(); + const labelList& fOwners = mesh().faceOwner(); + + list_.set + ( + celli, + new cellEdgeAddressing(c, fs, fOwners[c[0]] == celli) + ); + } + + return list_[celli]; +} + + +// ************************************************************************* // diff --git a/src/meshTools/cutPoly/cellEdgeAddressing.H b/src/meshTools/cutPoly/cellEdgeAddressing.H new file mode 100644 index 0000000000..6a65ac66df --- /dev/null +++ b/src/meshTools/cutPoly/cellEdgeAddressing.H @@ -0,0 +1,163 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2022 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 . + +Class + Foam::cellEdgeAddressing + Foam::cellEdgeAddressingList + +Description + Engine for providing cell-local cell-edge to face-edge addressing + +SourceFiles + cellEdgeAddressing.C + cellEdgeAddressingI.H + +\*---------------------------------------------------------------------------*/ + +#ifndef cellEdgeAddressing_H +#define cellEdgeAddressing_H + +#include "MeshObject.H" +#include "polyMesh.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +class polyDistributionMap; +class polyTopoChangeMap; +class polyMeshMap; + +/*---------------------------------------------------------------------------*\ + Class cellEdgeAddressing Declaration +\*---------------------------------------------------------------------------*/ + +class cellEdgeAddressing +{ +private: + + // Private Data + + //- Map from cell-face-index and face-edge-index to cell-edge-index + labelListList cfiAndFeiToCei_; + + //- Map from cell-edge-index to cell-face-index and face-edge-index. + // Note that there are two sets of indices for each cell-edge, + // corresponding to the two faces that are connected to that edge. + List> ceiToCfiAndFei_; + + //- For each cell-face, whether or not the cell owns it. The same as + // the concept of owner in the polyMesh, except this is calculated + // using the direction of the face-edges. I.e., if the first face is + // know to be "owned" by the face then any face that is edge connected + // to the first face is also owned by the cell if the connecting + // face-edge is numbered in an opposing direction. + boolList cOwns_; + + +public: + + // Constructors + + //- Construct from a cell and its faces + cellEdgeAddressing + ( + const cell& c, + const faceList& fs, + const bool cOwnsFirst + ); + + + // Member Functions + + //- Map from cell-face-index and face-edge-index to cell-edge-index + inline const labelListList& cfiAndFeiToCei() const; + + //- Map from cell-edge-index to cell-face-index and face-edge-index + inline const List>& ceiToCfiAndFei() const; + + //- For each cell-face, whether or not the cell owns it + inline const boolList& cOwns() const; +}; + + +/*---------------------------------------------------------------------------*\ + Class cellEdgeAddressingList Declaration +\*---------------------------------------------------------------------------*/ + +class cellEdgeAddressingList +: + public MeshObject +{ +private: + + // Private Data + + //- Edge addressing for each cell + mutable PtrList list_; + + +public: + + // Constructors + + //- Construct for a mesh + cellEdgeAddressingList(const polyMesh& mesh); + + + // Member Functions + + //- Update following mesh motion + virtual bool movePoints(); + + //- Update following mesh distribution + virtual void distribute(const polyDistributionMap& map); + + //- Update following topology change + virtual void topoChange(const polyTopoChangeMap& map); + + //- Update following mapping + virtual void mapMesh(const polyMeshMap& map); + + + // Member Operators + + //- Get the addressing for a given cell + const cellEdgeAddressing& operator[](const label celli) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "cellEdgeAddressingI.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/meshTools/cutPoly/cellEdgeAddressingI.H b/src/meshTools/cutPoly/cellEdgeAddressingI.H new file mode 100644 index 0000000000..e5e8345286 --- /dev/null +++ b/src/meshTools/cutPoly/cellEdgeAddressingI.H @@ -0,0 +1,50 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2022 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 "cellEdgeAddressing.H" + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +inline const Foam::labelListList& +Foam::cellEdgeAddressing::cfiAndFeiToCei() const +{ + return cfiAndFeiToCei_; +} + + +inline const Foam::List>& +Foam::cellEdgeAddressing::ceiToCfiAndFei() const +{ + return ceiToCfiAndFei_; +} + + +inline const Foam::boolList& Foam::cellEdgeAddressing::cOwns() const +{ + return cOwns_; +} + + +// ************************************************************************* // diff --git a/src/meshTools/cutPoly/cutPoly.C b/src/meshTools/cutPoly/cutPoly.C new file mode 100644 index 0000000000..60d2a7d254 --- /dev/null +++ b/src/meshTools/cutPoly/cutPoly.C @@ -0,0 +1,314 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2022 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 "cutPolyValue.H" +#include "OBJstream.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +template +Type min(const UIndirectList& l) +{ + Type result = pTraits::max; + forAll(l, i) + { + result = min(result, l[i]); + } + return result; +} + +template +Type max(const UIndirectList& l) +{ + Type result = pTraits::min; + forAll(l, i) + { + result = max(result, l[i]); + } + return result; +} + +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +Foam::List Foam::cutPoly::faceCuts +( + const face& f, + const scalarField& pAlphas, + const scalar isoAlpha +) +{ + UIndirectList fAlphas(pAlphas, f); + + // Quick reject if all alpha values are above or below the iso value + if (min(fAlphas) > isoAlpha || isoAlpha > max(fAlphas)) + { + return List(); + } + + // Find the starting point + label fpi0 = 0; + while ((fAlphas[fpi0] < isoAlpha) == separatedBelow) + { + ++ fpi0; + } + + // Create cuts on every edge for which there is a sign change + DynamicList cuts(1); + label cuti = 0; + forAll(f, i) + { + const label fpi1 = f.fcIndex(fpi0); + + if ((fAlphas[fpi0] < isoAlpha) != (fAlphas[fpi1] < isoAlpha)) + { + if (cuti == 0) + { + cuts.append({fpi0, -1}); + } + else + { + cuts.last()[1] = fpi0; + } + + cuti = cuts.last().fcIndex(cuti); + } + + fpi0 = fpi1; + } + + // There should have been an even number of cuts + if (cuti != 0) + { + FatalErrorInFunction + << "Cutting values " << fAlphas << " with iso-value " << isoAlpha + << " resulted in an odd number of cuts" + << exit(FatalError); + } + + cuts.shrink(); + return cuts; +} + + +Foam::labelListList Foam::cutPoly::cellCuts +( + const cell& c, + const cellEdgeAddressing& cAddr, + const faceUList& fs, + const List>& fCuts, + const scalarField& pAlphas, + const scalar isoAlpha +) +{ + // Quick return if not cut + label nCellFaceCuts = 0; + forAll(c, cfi) + { + nCellFaceCuts += fCuts[c[cfi]].size(); + } + if (nCellFaceCuts == 0) + { + return labelListList(); + } + + // Get local cell-face-edge addressing + const labelListList& cfiAndFeiToCei = cAddr.cfiAndFeiToCei(); + const List>& ceiToCfiAndFei = cAddr.ceiToCfiAndFei(); + const boolList& cOwns = cAddr.cOwns(); + + // For each cell-face and face-edge, get the face-edge at the other end of + // the edge's cut, or -1 if the edge is not cut. This allows us to walk + // along face cuts. It also doubles as the "visited" array during the walk. + // As cuts are visited, the relevant label in this array is set to -1 to + // ensure that the cut is not considered twice. + labelListList cellFaceAndFaceEdgeCutToFaceEdge(c.size()); + forAll(c, cfi) + { + cellFaceAndFaceEdgeCutToFaceEdge[cfi] = + labelList(fs[c[cfi]].size(), -1); + + forAll(fCuts[c[cfi]], fci) + { + const label fei0 = fCuts[c[cfi]][fci].first(); + const label fei1 = fCuts[c[cfi]][fci].second(); + + if (cOwns[cfi]) + { + cellFaceAndFaceEdgeCutToFaceEdge[cfi][fei0] = fei1; + } + else + { + cellFaceAndFaceEdgeCutToFaceEdge[cfi][fei1] = fei0; + } + } + } + + // Walk around the face cuts to generate the cell cuts + DynamicList cuts; + { + label nCellFaceCutsVisited = 0; + label cfi0 = 0, fei0 = 0; + while (nCellFaceCutsVisited < nCellFaceCuts) + { + // Find the next unvisited connection + bool found = false; + for (label cfj0 = cfi0; cfj0 < c.size(); ++ cfj0) + { + for (label fej0 = fei0; fej0 < fs[c[cfj0]].size(); ++ fej0) + { + const label fej1 = + cellFaceAndFaceEdgeCutToFaceEdge[cfj0][fej0]; + + if (fej1 != -1) + { + cfi0 = cfj0; + fei0 = fej0; + found = true; + } + + if (found) break; + } + + if (found) break; + + fei0 = 0; + } + if (!found) + { + FatalErrorInFunction + << "Could not find next unvisited connection for cell cut" + << exit(FatalError); + } + + // Walk around the cell from face to face to form a cut + label cfi = cfi0, fei = fei0; + DynamicList