diff --git a/applications/test/surfaceTree/Make/files b/applications/test/surfaceTree/Make/files new file mode 100644 index 0000000000..c877c9c1b4 --- /dev/null +++ b/applications/test/surfaceTree/Make/files @@ -0,0 +1,3 @@ +Test-surfaceTree.C + +EXE = $(FOAM_USER_APPBIN)/Test-surfaceTree diff --git a/applications/test/surfaceTree/Make/options b/applications/test/surfaceTree/Make/options new file mode 100644 index 0000000000..b6fa4bff16 --- /dev/null +++ b/applications/test/surfaceTree/Make/options @@ -0,0 +1,9 @@ +EXE_INC = \ + -I$(LIB_SRC)/fileFormats/lnInclude \ + -I$(LIB_SRC)/surfMesh/lnInclude \ + -I$(LIB_SRC)/meshTools/lnInclude + +EXE_LIBS = \ + -lfileFormats \ + -lsurfMesh \ + -lmeshTools diff --git a/applications/test/surfaceTree/Test-surfaceTree.C b/applications/test/surfaceTree/Test-surfaceTree.C new file mode 100644 index 0000000000..e79b6431dd --- /dev/null +++ b/applications/test/surfaceTree/Test-surfaceTree.C @@ -0,0 +1,157 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2022 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 . + +Application + Test-surfaceTree + +Description + Simple tests for building indexedOctree etc. + +\*---------------------------------------------------------------------------*/ + +#include "argList.H" +#include "clockTime.H" +#include "MeshedSurfaces.H" +#include "indexedOctree.H" +#include "AABBTree.H" +#include "treeDataPrimitivePatch.H" +#include "Random.H" +#include "ListListOps.H" + +using namespace Foam; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// Main program: + +int main(int argc, char *argv[]) +{ + argList::addNote + ( + "Test octree building etc" + ); + + argList::noBanner(); + argList::noParallel(); + argList::addArgument("input", "The input surface file"); + + argList::addOption("maxLevel", "int", "The max level"); + argList::addOption("leafSize", "int", "The min leaf size"); + argList::addBoolOption("AABB", "AABBTree instead of indexedOctree"); + + argList args(argc, argv); + + const auto importName = args.get(1); + + const bool useAABB = args.found("AABB"); + + label maxLevel = 10; + label leafSize = 10; + + if (useAABB) + { + // May want different settings.. + } + + args.readIfPresent("maxLevel", maxLevel); + args.readIfPresent("leafSize", leafSize); + + meshedSurface surf(importName); + + Random rndGen(123456); + + treeBoundBox overallBb + ( + treeBoundBox(surf.box()).extend(rndGen, 1e-4, ROOTVSMALL) + ); + + Info<< "Surface with " << surf.size() << " faces, " + << surf.nPoints() << " points" << endl; + + + clockTime timing; + + if (useAABB) + { + AABBTree tree + ( + surf, + surf.points(), + true, // Equal bins + maxLevel, // maxLevel + leafSize // minLeafSize + ); + + Info<< "Built AABBTree, maxLevel:" << maxLevel + << " minLeaf:" << leafSize + << " with " << tree.boundBoxes().size() + << " leaves - " << timing.elapsedTime() << 's' << endl; + + { + OFstream os("AABBTree.obj"); + tree.writeOBJ(os); + + Info<< "Wrote " << os.name() << endl; + } + + // Info<< "sizes: "; + // ListListOps::subSizes + // ( + // tree.addressing(), + // identityOp{} + // ).writeList(Info) << endl; + } + else + { + indexedOctree> tree + ( + treeDataPrimitivePatch(surf, 1e-6), + overallBb, + maxLevel, // maxLevel + leafSize, // leafSize + 3.0 // duplicity + ); + + Info<< "Built octree, maxLevel:" << maxLevel + << " minLeaf:" << leafSize + << " with " << tree.nodes().size() + << " nodes, " << tree.nLeafs() + << " leaves - " << timing.elapsedTime() << 's' << endl; + + { + OFstream os("indexedOctree.obj"); + tree.writeOBJ(os); + + Info<< "Wrote " << os.name() << endl; + } + } + + + Info<< "\nEnd\n" << endl; + return 0; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/algorithms/AABBTree/AABBTree.C b/src/OpenFOAM/algorithms/AABBTree/AABBTree.C index 6b760ff35d..8bbac68837 100644 --- a/src/OpenFOAM/algorithms/AABBTree/AABBTree.C +++ b/src/OpenFOAM/algorithms/AABBTree/AABBTree.C @@ -141,39 +141,36 @@ void Foam::AABBTree::createBoxes // Assign the objects to min or max bin DynamicList