mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: surfaceDistance: FO to calc distance-to-surface field. Fixes #1523.
This commit is contained in:
@ -37,6 +37,8 @@ processorField/processorField.C
|
|||||||
proudmanAcousticPower/proudmanAcousticPower.C
|
proudmanAcousticPower/proudmanAcousticPower.C
|
||||||
readFields/readFields.C
|
readFields/readFields.C
|
||||||
|
|
||||||
|
surfaceDistance/surfaceDistance.C
|
||||||
|
|
||||||
setFlow/setFlow.C
|
setFlow/setFlow.C
|
||||||
|
|
||||||
streamLine/streamLine.C
|
streamLine/streamLine.C
|
||||||
|
|||||||
241
src/functionObjects/field/surfaceDistance/surfaceDistance.C
Normal file
241
src/functionObjects/field/surfaceDistance/surfaceDistance.C
Normal file
@ -0,0 +1,241 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Copyright (C) 2019 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::functionObjects::surfaceDistance::~surfaceDistance()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
bool Foam::functionObjects::surfaceDistance::read
|
||||||
|
(
|
||||||
|
const dictionary& dict
|
||||||
|
)
|
||||||
|
{
|
||||||
|
fvMeshFunctionObject::read(dict);
|
||||||
|
|
||||||
|
doCells_ = dict.lookupOrDefault("calculateCells", true);
|
||||||
|
|
||||||
|
geomPtr_.clear();
|
||||||
|
geomPtr_.set
|
||||||
|
(
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
172
src/functionObjects/field/surfaceDistance/surfaceDistance.H
Normal file
172
src/functionObjects/field/surfaceDistance/surfaceDistance.H
Normal file
@ -0,0 +1,172 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Copyright (C) 2019 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/>.
|
||||||
|
|
||||||
|
Class
|
||||||
|
Foam::functionObjects::surfaceDistance
|
||||||
|
|
||||||
|
Group
|
||||||
|
grpFieldFunctionObjects
|
||||||
|
|
||||||
|
Description
|
||||||
|
Writes a scalar field whose value is the distance to the nearest surface.
|
||||||
|
The output field name is 'surfaceDistance'.
|
||||||
|
|
||||||
|
Usage
|
||||||
|
Example of function object specification:
|
||||||
|
\verbatim
|
||||||
|
surfaceDistance
|
||||||
|
{
|
||||||
|
// Where to load it from
|
||||||
|
libs (libfieldFunctionObjects);
|
||||||
|
type surfaceDistance;
|
||||||
|
|
||||||
|
geometry
|
||||||
|
{
|
||||||
|
motorBike.obj
|
||||||
|
{
|
||||||
|
type triSurfaceMesh;
|
||||||
|
name motorBike;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
\endverbatim
|
||||||
|
|
||||||
|
Where the entries comprise:
|
||||||
|
\table
|
||||||
|
Property | Description | Required | Default
|
||||||
|
type | Type name: surfaceDistance | yes |
|
||||||
|
geometry | Surfaces | yes | no
|
||||||
|
doCells | Calculate distance from cell | no | true
|
||||||
|
\endtable
|
||||||
|
|
||||||
|
Run with e.g.
|
||||||
|
|
||||||
|
postProcess -func surfaceDistance
|
||||||
|
|
||||||
|
|
||||||
|
See also
|
||||||
|
Foam::functionObjects::fvMeshFunctionObject
|
||||||
|
Foam::functionObjects::timeControl
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
surfaceDistance.C
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef functionObjects_surfaceDistance_H
|
||||||
|
#define functionObjects_surfaceDistance_H
|
||||||
|
|
||||||
|
#include "fvMeshFunctionObject.H"
|
||||||
|
#include "searchableSurfaces.H"
|
||||||
|
#include "volFields.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
|
||||||
|
// Forward declaration of classes
|
||||||
|
class objectRegistry;
|
||||||
|
class dictionary;
|
||||||
|
class mapPolyMesh;
|
||||||
|
|
||||||
|
namespace functionObjects
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class surfaceDistance Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
class surfaceDistance
|
||||||
|
:
|
||||||
|
public fvMeshFunctionObject
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// Protected data
|
||||||
|
|
||||||
|
//- Switch to calculate distance-to-cells
|
||||||
|
Switch doCells_;
|
||||||
|
|
||||||
|
//- Geometry
|
||||||
|
autoPtr<searchableSurfaces> geomPtr_;
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
// Private member functions
|
||||||
|
|
||||||
|
//- No copy construct
|
||||||
|
surfaceDistance(const surfaceDistance&) = delete;
|
||||||
|
|
||||||
|
//- No copy assignment
|
||||||
|
void operator=(const surfaceDistance&) = delete;
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//- Runtime type information
|
||||||
|
TypeName("surfaceDistance");
|
||||||
|
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Construct for given objectRegistry and dictionary.
|
||||||
|
// Allow the possibility to load fields from files
|
||||||
|
surfaceDistance
|
||||||
|
(
|
||||||
|
const word& name,
|
||||||
|
const Time& runTime,
|
||||||
|
const dictionary& dict
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//- Destructor
|
||||||
|
virtual ~surfaceDistance();
|
||||||
|
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
//- Read the controls
|
||||||
|
virtual bool read(const dictionary&);
|
||||||
|
|
||||||
|
//- Calculate the interpolated fields
|
||||||
|
virtual bool execute();
|
||||||
|
|
||||||
|
//- Write the interpolated fields
|
||||||
|
virtual bool write();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace functionObjects
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
Reference in New Issue
Block a user