diff --git a/src/parallel/distributed/Make/files b/src/parallel/distributed/Make/files index 31a58d43f5..cb7aa466a5 100644 --- a/src/parallel/distributed/Make/files +++ b/src/parallel/distributed/Make/files @@ -1,3 +1,4 @@ distributedTriSurfaceMesh/distributedTriSurfaceMesh.C +patchDistMethods/exact/exactPatchDistMethod.C LIB = $(FOAM_LIBBIN)/libdistributed diff --git a/src/parallel/distributed/Make/options b/src/parallel/distributed/Make/options index 232875c504..6961bf298d 100644 --- a/src/parallel/distributed/Make/options +++ b/src/parallel/distributed/Make/options @@ -1,6 +1,7 @@ EXE_INC = \ -I$(LIB_SRC)/surfMesh/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \ + -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/parallel/decompose/decompositionMethods/lnInclude LIB_LIBS = \ diff --git a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C index 3613206a84..a83712886b 100644 --- a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C +++ b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C @@ -1240,7 +1240,7 @@ void Foam::distributedTriSurfaceMesh::surfaceSide // Nearest to face interior. Use faceNormal to determine side //scalar c = sampleNearestVec & surf.faceNormals()[facei]; - scalar c = sampleNearestVec & surf[facei].normal(points); + scalar c = sampleNearestVec & surf[facei].areaNormal(points); if (c > 0) { @@ -1292,7 +1292,7 @@ void Foam::distributedTriSurfaceMesh::surfaceSide label facei = pFaces[pFacei]; const triSurface::FaceType& f = surf[facei]; - label fp = findIndex(f, pointi); + label fp = f.find(pointi); label p1 = f[f.fcIndex(fp)]; label pMin1 = f[f.rcIndex(fp)]; diff --git a/src/parallel/distributed/patchDistMethods/exact/exactPatchDistMethod.C b/src/parallel/distributed/patchDistMethods/exact/exactPatchDistMethod.C new file mode 100644 index 0000000000..6901f0fdbf --- /dev/null +++ b/src/parallel/distributed/patchDistMethods/exact/exactPatchDistMethod.C @@ -0,0 +1,207 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 OpenCFD Ltd. + \\/ 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 "exactPatchDistMethod.H" +#include "distributedTriSurfaceMesh.H" +#include "addToRunTimeSelectionTable.H" +#include "volFields.H" +#include "DynamicField.H" +#include "OBJstream.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace patchDistMethods +{ + defineTypeNameAndDebug(exact, 0); + addToRunTimeSelectionTable(patchDistMethod, exact, dictionary); +} +} + +const Foam::distributedTriSurfaceMesh& +Foam::patchDistMethods::exact::patchSurface() const +{ + if (!patchSurfPtr_.valid()) + { + const polyBoundaryMesh& pbm = mesh_.boundaryMesh(); + + Random rndGen(0); + + boundBox localBb(mesh_.points(), false); + + // Determine mesh bounding boxes: + List meshBb + ( + 1, + treeBoundBox(localBb).extend(rndGen, 1E-3) + ); + + // Dummy bounds dictionary + dictionary dict; + dict.add("bounds", meshBb); + dict.add + ( + "distributionType", + distributedTriSurfaceMesh::distributionTypeNames_ + [ + //distributedTriSurfaceMesh::FOLLOW + distributedTriSurfaceMesh::INDEPENDENT + ] + ); + dict.add("mergeDistance", 1e-6*localBb.mag()); + + + Info<< "Triangulating local patch faces" << nl << endl; + + patchSurfPtr_.reset + ( + new distributedTriSurfaceMesh + ( + IOobject + ( + "wallSurface.stl", + mesh_.time().constant(),// directory + "triSurface", // instance + mesh_.time(), // registry + IOobject::NO_READ, + IOobject::NO_WRITE + ), + triSurfaceTools::triangulate + ( + pbm, + patchIDs_ + ), + dict + ) + ); + + // Do redistribution + Info<< "Redistributing surface" << nl << endl; + autoPtr faceMap; + autoPtr pointMap; + patchSurfPtr_().distribute + ( + meshBb, + false, //keepNonMapped, + faceMap, + pointMap + ); + faceMap.clear(); + pointMap.clear(); + } + return patchSurfPtr_(); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::patchDistMethods::exact::exact +( + const dictionary& dict, + const fvMesh& mesh, + const labelHashSet& patchIDs +) +: + patchDistMethod(mesh, patchIDs) +{} + + +Foam::patchDistMethods::exact::exact +( + const fvMesh& mesh, + const labelHashSet& patchIDs +) +: + patchDistMethod(mesh, patchIDs) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::patchDistMethods::exact::correct(volScalarField& y) +{ + return correct(y, const_cast(volVectorField::null())); +} + + +bool Foam::patchDistMethods::exact::correct +( + volScalarField& y, + volVectorField& n +) +{ + const distributedTriSurfaceMesh& surf = patchSurface(); + + List info; + surf.findNearest + ( + mesh_.cellCentres(), + scalarField(mesh_.nCells(), Foam::sqr(GREAT)), + info + ); + + // Take over hits + label nHits = 0; + forAll(info, cellI) + { + if (info[cellI].hit()) + { + const point& cc = mesh_.cellCentres()[cellI]; + y[cellI] = mag(cc-info[cellI].hitPoint()); + nHits++; + } + //else + //{ + // // Miss. Do what? Not possible with GREAT hopefully ... + //} + } + y.correctBoundaryConditions(); + + if (debug) + { + OBJstream str(mesh_.time().timePath()/"wallPoint.obj"); + Info<< type() << ": dumping nearest wall point to " << str.name() + << endl; + forAll(mesh_.cellCentres(), cellI) + { + const point& cc = mesh_.cellCentres()[cellI]; + str.write(linePointRef(cc, info[cellI].hitPoint())); + } + } + + + // Only calculate n if the field is defined + if (notNull(n)) + { + surf.getNormal(info, n.primitiveFieldRef()); + n.correctBoundaryConditions(); + } + + return true; +} + + +// ************************************************************************* // diff --git a/src/parallel/distributed/patchDistMethods/exact/exactPatchDistMethod.H b/src/parallel/distributed/patchDistMethods/exact/exactPatchDistMethod.H new file mode 100644 index 0000000000..3963fa06e3 --- /dev/null +++ b/src/parallel/distributed/patchDistMethods/exact/exactPatchDistMethod.H @@ -0,0 +1,139 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 OpenCFD Ltd. + \\/ 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::patchDistMethods::exact + +Description + Calculation of exact distance to nearest patch for all cells and + boundary by constructing a search tree for all patch faces. + +See also + Foam::patchDistMethod::meshWave + Foam::wallDist + +SourceFiles + exactPatchDistMethod.C + +\*---------------------------------------------------------------------------*/ + +#ifndef exactPatchDistMethod_H +#define exactPatchDistMethod_H + +#include "patchDistMethod.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +class distributedTriSurfaceMesh; + +namespace patchDistMethods +{ + +/*---------------------------------------------------------------------------*\ + Class exact Declaration +\*---------------------------------------------------------------------------*/ + +class exact +: + public patchDistMethod +{ + // Private Member Data + + //- Cache surface+searching of patch + mutable autoPtr patchSurfPtr_; + + + // Private Member Functions + + const distributedTriSurfaceMesh& patchSurface() const; + + //- Disallow default bitwise copy construct + exact(const exact&); + + //- Disallow default bitwise assignment + void operator=(const exact&); + + +public: + + //- Runtime type information + TypeName("exactDistance"); + + + // Constructors + + //- Construct from coefficients dictionary, mesh + // and fixed-value patch set + exact + ( + const dictionary& dict, + const fvMesh& mesh, + const labelHashSet& patchIDs + ); + + //- Construct from mesh and fixed-value patch set + exact + ( + const fvMesh& mesh, + const labelHashSet& patchIDs + ); + + + // Member Functions + + //- Update cached geometry when the mesh moves + virtual bool movePoints() + { + // ? Reconstruct patch surface? + //patchSurfPtr_.clear(); + return true; + } + + //- Update cached topology and geometry when the mesh changes + virtual void updateMesh(const mapPolyMesh&) + { + // ? Reconstruct patch surface? + //patchSurfPtr_.clear(); + } + + //- Correct the given distance-to-patch field + virtual bool correct(volScalarField& y); + + //- Correct the given distance-to-patch and normal-to-patch fields + virtual bool correct(volScalarField& y, volVectorField& n); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace patchDistMethods +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* //