Files
openfoam/src/functionObjects/field/surfaceDistance/surfaceDistance.C
Mark Olesen 6e3bc1f7d0 STYLE: can add compile-time deprecated message for autoPtr::set()
- deprecated Feb-2018, but not marked as such.

  The set() method originally enforce an additional run-time check
  (Fatal if pointer was already set), but this was rarely used.
  In fact, the set() method was invariably used in constructors
  where the pointer by definition was unset.

  Can now mark as deprecated to catch the last of these.
  We prefer reset() for similarity with std::unique_ptr

  Eg,
  FOAM_EXTRA_CXXFLAGS="-DFoam_autoPtr_deprecate_setMethod"  wmake
2020-11-19 16:57:45 +01:00

230 lines
6.1 KiB
C

/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019-2020 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "surfaceDistance.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(surfaceDistance, 0);
addToRunTimeSelectionTable(functionObject, surfaceDistance, dictionary);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::surfaceDistance::surfaceDistance
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fvMeshFunctionObject(name, runTime, dict)
{
read(dict);
volScalarField* procFieldPtr
(
new volScalarField
(
IOobject
(
"surfaceDistance",
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
dimensionedScalar(dimLength, Zero)
)
);
mesh_.objectRegistry::store(procFieldPtr);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::surfaceDistance::read
(
const dictionary& dict
)
{
fvMeshFunctionObject::read(dict);
doCells_ = dict.getOrDefault("calculateCells", true);
geomPtr_.reset(nullptr);
geomPtr_.reset
(
new searchableSurfaces
(
IOobject
(
"abc", // dummy name
mesh_.time().constant(), // directory
"triSurface", // instance
mesh_.time(), // registry
IOobject::MUST_READ,
IOobject::NO_WRITE
),
dict.subDict("geometry"),
true // allow single-region shortcut
)
);
return true;
}
bool Foam::functionObjects::surfaceDistance::execute()
{
volScalarField& distance = mesh_.lookupObjectRef<volScalarField>
(
"surfaceDistance"
);
volScalarField::Boundary& bfld = distance.boundaryFieldRef();
forAll(bfld, patchi)
{
if (!polyPatch::constraintType(bfld[patchi].patch().type()))
{
const pointField& fc = mesh_.C().boundaryField()[patchi];
labelList surfaces;
List<pointIndexHit> nearestInfo;
geomPtr_().findNearest
(
fc,
scalarField(fc.size(), GREAT),
surfaces,
nearestInfo
);
scalarField dist(fc.size());
forAll(nearestInfo, i)
{
dist[i] = mag(nearestInfo[i].hitPoint()-fc[i]);
}
bfld[patchi] == dist;
}
}
if (doCells_)
{
const pointField& cc = mesh_.C();
labelList surfaces;
List<pointIndexHit> nearestInfo;
geomPtr_().findNearest
(
cc,
scalarField(cc.size(), GREAT),
surfaces,
nearestInfo
);
forAll(nearestInfo, celli)
{
distance[celli] = mag(nearestInfo[celli].hitPoint()-cc[celli]);
}
}
distance.correctBoundaryConditions();
return true;
}
bool Foam::functionObjects::surfaceDistance::write()
{
Log << " functionObjects::" << type() << " " << name()
<< " writing distance-to-surface field" << endl;
const volScalarField& distance =
mesh_.lookupObject<volScalarField>("surfaceDistance");
// volScalarField::Boundary& bfld = distance.boundaryFieldRef();
// forAll(bfld, patchi)
// {
// if (!polyPatch::constraintType(bfld[patchi].patch().type()))
// {
// const pointField& fc = mesh_.C().boundaryField()[patchi];
//
// labelList surfaces;
// List<pointIndexHit> nearestInfo;
// geomPtr_().findNearest
// (
// fc,
// scalarField(fc.size(), GREAT),
// surfaces,
// nearestInfo
// );
//
// scalarField dist(fc.size());
// forAll(nearestInfo, i)
// {
// dist[i] = mag(nearestInfo[i].hitPoint()-fc[i]);
// }
// bfld[patchi] == dist;
// }
// }
//
// if (doCells_)
// {
// const pointField& cc = mesh_.C();
//
// labelList surfaces;
// List<pointIndexHit> nearestInfo;
// geomPtr_().findNearest
// (
// cc,
// scalarField(cc.size(), GREAT),
// surfaces,
// nearestInfo
// );
//
// forAll(nearestInfo, celli)
// {
// distance[celli] = mag(nearestInfo[celli].hitPoint()-cc[celli]);
// }
// }
// distance.correctBoundaryConditions();
distance.write();
return true;
}
// ************************************************************************* //