From 7943603bf0a8f04794791f84d73e3138f7aa77ce Mon Sep 17 00:00:00 2001 From: Mattijs Janssens Date: Thu, 6 Dec 2018 15:56:26 +0000 Subject: [PATCH] ENH: isoSurfaceTopo: replacement for isoSurfaceCell. --- src/sampling/Make/files | 2 + .../isoSurface/sampledIsoSurfaceTopo.C | 328 +++++ .../isoSurface/sampledIsoSurfaceTopo.H | 291 ++++ .../sampledIsoSurfaceTopoTemplates.C | 95 ++ .../surface/isoSurface/isoSurfaceTopo.C | 1234 +++++++++++++++++ .../surface/isoSurface/isoSurfaceTopo.H | 266 ++++ .../isoSurface/isoSurfaceTopoTemplates.C | 91 ++ 7 files changed, 2307 insertions(+) create mode 100644 src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceTopo.C create mode 100644 src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceTopo.H create mode 100644 src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceTopoTemplates.C create mode 100644 src/sampling/surface/isoSurface/isoSurfaceTopo.C create mode 100644 src/sampling/surface/isoSurface/isoSurfaceTopo.H create mode 100644 src/sampling/surface/isoSurface/isoSurfaceTopoTemplates.C diff --git a/src/sampling/Make/files b/src/sampling/Make/files index 3e42081cc0..dbef3b3987 100644 --- a/src/sampling/Make/files +++ b/src/sampling/Make/files @@ -29,6 +29,7 @@ surface/cutting/cuttingSurfaceBaseSelection.C surface/distanceSurface/distanceSurface.C surface/isoSurface/isoSurface.C surface/isoSurface/isoSurfaceCell.C +surface/isoSurface/isoSurfaceTopo.C surface/thresholdCellFaces/thresholdCellFaces.C surface/triSurfaceMesh/discreteSurface.C @@ -44,6 +45,7 @@ sampledSurface/sampledPatchInternalField/sampledPatchInternalField.C sampledSurface/sampledPlane/sampledPlane.C sampledSurface/isoSurface/sampledIsoSurface.C sampledSurface/isoSurface/sampledIsoSurfaceCell.C +sampledSurface/isoSurface/sampledIsoSurfaceTopo.C sampledSurface/distanceSurface/sampledDistanceSurface.C sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C sampledSurface/sampledCuttingSurface/sampledCuttingSurface.C diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceTopo.C b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceTopo.C new file mode 100644 index 0000000000..6f3ff764f0 --- /dev/null +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceTopo.C @@ -0,0 +1,328 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 OpenFOAM Foundation + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "sampledIsoSurfaceTopo.H" +#include "dictionary.H" +#include "volFields.H" +#include "volPointInterpolation.H" +#include "addToRunTimeSelectionTable.H" +#include "fvMesh.H" +#include "isoSurfaceTopo.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(sampledIsoSurfaceTopo, 0); + addNamedToRunTimeSelectionTable + ( + sampledSurface, + sampledIsoSurfaceTopo, + word, + isoSurfaceTopo + ); +} + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +bool Foam::sampledIsoSurfaceTopo::updateGeometry() const +{ + const fvMesh& fvm = static_cast(mesh()); + + // No update needed + if (fvm.time().timeIndex() == prevTimeIndex_) + { + return false; + } + + prevTimeIndex_ = fvm.time().timeIndex(); + + // Clear derived data + sampledSurface::clearGeom(); + + // Use field from database, or try to read it in + + const auto* cellFldPtr = fvm.findObject(isoField_); + + if (debug) + { + if (cellFldPtr) + { + InfoInFunction << "Lookup " << isoField_ << endl; + } + else + { + InfoInFunction + << "Reading " << isoField_ + << " from time " << fvm.time().timeName() + << endl; + } + } + + // For holding the volScalarField read in. + autoPtr fieldReadPtr; + + if (!cellFldPtr) + { + // Bit of a hack. Read field and store. + + fieldReadPtr = autoPtr::New + ( + IOobject + ( + isoField_, + fvm.time().timeName(), + fvm, + IOobject::MUST_READ, + IOobject::NO_WRITE, + false + ), + fvm + ); + } + + const volScalarField& cellFld = + (fieldReadPtr.valid() ? *fieldReadPtr : *cellFldPtr); + + auto tpointFld = volPointInterpolation::New(fvm).interpolate(cellFld); + + //- Direct from cell field and point field. Gives bad continuity. + isoSurfaceTopo surf + ( + fvm, + cellFld.primitiveField(), + tpointFld().primitiveField(), + isoVal_, + (regularise_ ? isoSurfaceTopo::DIAGCELL : isoSurfaceTopo::NONE) + ); + + MeshedSurface& mySurface = const_cast(*this); + + mySurface.transfer(static_cast(surf)); + meshCells_ = std::move(surf.meshCells()); + + // triangulate uses remapFaces() + // - this is somewhat less efficient since it recopies the faces + // that we just created, but we probably don't want to do this + // too often anyhow. + if (triangulate_) + { + labelList faceMap; + mySurface.triangulate(faceMap); + meshCells_ = UIndirectList