diff --git a/applications/test/patchIntersection/Make/files b/applications/test/patchIntersection/Make/files new file mode 100644 index 0000000000..e4d7cb29a9 --- /dev/null +++ b/applications/test/patchIntersection/Make/files @@ -0,0 +1,3 @@ +Test-patchIntersection.C + +EXE = $(FOAM_USER_APPBIN)/Test-patchIntersection diff --git a/applications/test/patchIntersection/Make/options b/applications/test/patchIntersection/Make/options new file mode 100644 index 0000000000..d820876f44 --- /dev/null +++ b/applications/test/patchIntersection/Make/options @@ -0,0 +1,7 @@ +EXE_INC = \ + -I$(LIB_SRC)/fileFormats/lnInclude \ + -I$(LIB_SRC)/meshTools/lnInclude + +EXE_LIBS = \ + -lfileFormats \ + -lmeshTools diff --git a/applications/test/patchIntersection/Test-patchIntersection.C b/applications/test/patchIntersection/Test-patchIntersection.C new file mode 100644 index 0000000000..6a4e18202d --- /dev/null +++ b/applications/test/patchIntersection/Test-patchIntersection.C @@ -0,0 +1,114 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2024 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 "argList.H" +#include "labelVector.H" +#include "ListOps.H" +#include "polyMesh.H" +#include "primitivePatchIntersection.H" +#include "Time.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +using namespace Foam; + +int main(int argc, char *argv[]) +{ + static const scalar defaultSnapTol = Foam::sqrt(rootSmall); + + argList::validArgs.append("source"); + argList::validArgs.append("target"); + argList::addOption + ( + "snapTol", + "snapTol", + "snapping tolerance - default is " + name(defaultSnapTol) + ); + + #include "setRootCase.H" + #include "createTime.H" + #include "createPolyMesh.H" + + const polyPatch& srcPatch = mesh.boundaryMesh()[args[1]]; + const polyPatch& tgtPatch = mesh.boundaryMesh()[args[2]]; + const scalar snapTol = + args.optionLookupOrDefault("snapTol", defaultSnapTol); + + if (mesh.nGeometricD() != 2 && mesh.nGeometricD() != 3) + { + FatalErrorInFunction + << "Primitive patch intersection can only be done on 2 or " + << "3-dimensional meshes" << exit(FatalError); + } + + primitivePatchIntersection intersection(srcPatch, tgtPatch, snapTol); + + // Check the patch-edge-points start and end in the right places + auto check = [&](const bool isSrc) + { + const primitivePatch& patch = isSrc ? srcPatch : tgtPatch; + + const labelList& patchPointPoints = + isSrc + ? intersection.srcPointPoints() + : intersection.tgtPointPoints(); + + const List>& patchEdgePoints = + isSrc + ? intersection.srcEdgePoints() + : intersection.tgtEdgePoints(); + + forAll(patch.edges(), edgei) + { + const edge& patchE = patch.edges()[edgei]; + + const edge ictE + ( + patchPointPoints[patchE.start()], + patchPointPoints[patchE.end()] + ); + + const labelList& ictEPs = patchEdgePoints[edgei]; + + if (ictE != edge(ictEPs.first(), ictEPs.last())) + { + FatalErrorInFunction + << "Patch-edge " << patchE << " has intersection end " + << "points " << ictE << ", but these do not match the " + << "first and last of all the intersection points " + << ictEPs << exit(FatalError); + } + } + }; + check(true); + check(false); + + Info<< nl << "End" << nl << endl; + + return 0; +} + + +// ************************************************************************* //