Commit 57d2eabc authored by Mark Olesen's avatar Mark Olesen Committed by Andrew Heather
Browse files

DEFEATURE: remove surfMesh samplers - superseded by sampledSurfaces

- this functionality was originally added to allow sampling of volume
  fields onto a surface in order to perform calculations on them.

  However, the sampling framework essentially mirrored the
  sampledSurface, but was less complete.

  It is now possible to store sampled surfaces on a registry and
  do calculation with their fields. This is the preferred method,
  and thus removing the surfMeshSample duplicate code.
parent 647a86b7
......@@ -33,12 +33,6 @@ surface/isoSurface/isoSurfaceTopo.C
surface/thresholdCellFaces/thresholdCellFaces.C
surface/triSurfaceMesh/discreteSurface.C
surfMeshSample/surfMeshSample/surfMeshSample.C
surfMeshSample/surfMeshSamplers/surfMeshSamplers.C
surfMeshSample/distanceSurface/surfMeshSampleDistanceSurface.C
surfMeshSample/plane/surfMeshSamplePlane.C
surfMeshSample/triSurfaceMesh/surfMeshSampleDiscrete.C
sampledSurface/sampledNone/sampledNone.C
sampledSurface/sampledPatch/sampledPatch.C
sampledSurface/sampledPatchInternalField/sampledPatchInternalField.C
......
......@@ -118,9 +118,6 @@ Note
The interpolationScheme is only used if interpolate=true is used by any
of the surfaces.
See also
Foam::surfMeshSamplers
SourceFiles
sampledSurfaces.C
......
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "surfMeshSampleDistanceSurface.H"
#include "dictionary.H"
#include "polyMesh.H"
#include "volFields.H"
#include "coordinateSystem.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(surfMeshSampleDistanceSurface, 0);
addNamedToRunTimeSelectionTable
(
surfMeshSample,
surfMeshSampleDistanceSurface,
word,
distanceSurface
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::surfMeshSampleDistanceSurface::surfMeshSampleDistanceSurface
(
const word& name,
const polyMesh& mesh,
const dictionary& dict
)
:
surfMeshSample(name, mesh, dict),
SurfaceSource(name, mesh, dict),
needsUpdate_(true)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::surfMeshSampleDistanceSurface::needsUpdate() const
{
return needsUpdate_;
}
bool Foam::surfMeshSampleDistanceSurface::expire()
{
// Already marked as expired
if (needsUpdate_)
{
return false;
}
needsUpdate_ = true;
return true;
}
bool Foam::surfMeshSampleDistanceSurface::update()
{
if (!needsUpdate_)
{
return false;
}
SurfaceSource::createGeometry();
// Transfer content
getOrCreateSurfMesh().transfer
(
SurfaceSource::surface()
);
if (debug)
{
print(Pout);
Pout<< endl;
}
needsUpdate_ = false;
return true;
}
bool Foam::surfMeshSampleDistanceSurface::sample
(
const word& fieldName,
const word& sampleScheme
) const
{
return
(
sampleType<scalar>(fieldName, sampleScheme)
|| sampleType<vector>(fieldName, sampleScheme)
|| sampleType<sphericalTensor>(fieldName, sampleScheme)
|| sampleType<symmTensor>(fieldName, sampleScheme)
|| sampleType<tensor>(fieldName, sampleScheme)
);
}
void Foam::surfMeshSampleDistanceSurface::print(Ostream& os) const
{
os << "distanceSurface: " << name() << " :"
<< " surface:" << surfaceName()
<< " distance:" << distance()
<< " faces:" << surface().faces().size()
<< " points:" << surface().points().size();
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
Class
Foam::surfMeshSampleDistanceSurface
Description
Sampling surfFields onto a surfMesh based on a plane.
The cuttingPlane algorithm 'cuts' the mesh.
The plane is triangulated by default.
Note
Does not actually cut until update() called.
SourceFiles
surfMeshSampleDistanceSurface.C
surfMeshSampleDistanceSurfaceTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef surfMeshSampleDistanceSurface_H
#define surfMeshSampleDistanceSurface_H
#include "surfMeshSample.H"
#include "distanceSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class surfMeshSampleDistanceSurface Declaration
\*---------------------------------------------------------------------------*/
class surfMeshSampleDistanceSurface
:
public surfMeshSample,
private distanceSurface
{
// Private typedefs for convenience
typedef distanceSurface SurfaceSource;
// Private data
//- Track if the surface needs an update
mutable bool needsUpdate_;
// Private Member Functions
//- Sample field on surface
template<class Type>
tmp<Field<Type>> sampleOnFaces
(
const interpolation<Type>& sampler
) const;
//- Sample field on surface.
template<class Type>
bool sampleType
(
const word& fieldName,
const word& sampleScheme
) const;
public:
//- Runtime type information
TypeName("surfMeshSampleDistanceSurface");
// Constructors
//- Construct from dictionary
surfMeshSampleDistanceSurface
(
const word& name,
const polyMesh& mesh,
const dictionary& dict
);
//- Destructor
virtual ~surfMeshSampleDistanceSurface() = default;
// Member Functions
//- The surface is from surfMesh
using surfMeshSample::surface;
//- Does the surface need an update?
virtual bool needsUpdate() const;
//- Mark the surface as needing an update.
// May also free up unneeded data.
// Return false if surface was already marked as expired.
virtual bool expire();
//- Update the surface as required.
// Do nothing (and return false) if no update was needed
virtual bool update();
//- Sample the volume field onto surface
virtual bool sample
(
const word& fieldName,
const word& sampleScheme = "cell"
) const;
//- Write
virtual void print(Ostream& os) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "surfMeshSampleDistanceSurfaceTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "surfMeshSampleDistanceSurface.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type>
Foam::tmp<Foam::Field<Type>>
Foam::surfMeshSampleDistanceSurface::sampleOnFaces
(
const interpolation<Type>& sampler
) const
{
return surfMeshSample::sampleOnFaces
(
sampler,
SurfaceSource::meshCells(),
surface().faces(),
surface().points()
);
}
template<class Type>
bool Foam::surfMeshSampleDistanceSurface::sampleType
(
const word& fieldName,
const word& sampleScheme
) const
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
const auto* volFldPtr = mesh().findObject<VolFieldType>(fieldName);
if (!volFldPtr)
{
return false;
}
auto samplerPtr = interpolation<Type>::New(sampleScheme, *volFldPtr);
getOrCreateSurfField<Type>(*volFldPtr).field() =
sampleOnFaces(*samplerPtr);
return true;
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2019 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "surfMeshSamplePlane.H"
#include "dictionary.H"
#include "polyMesh.H"
#include "volFields.H"
#include "cartesianCS.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(surfMeshSamplePlane, 0);
addNamedToRunTimeSelectionTable
(
surfMeshSample,
surfMeshSamplePlane,
word,
plane
);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::bitSet Foam::surfMeshSamplePlane::cellSelection(const bool warn) const
{
return cuttingPlane::cellSelection
(
mesh(),
bounds_,
zoneNames_,
name(),
warn
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::surfMeshSamplePlane::surfMeshSamplePlane
(
const word& name,
const polyMesh& mesh,
const plane& planeDesc,
const wordRes& zones,
const bool triangulate
)
:
surfMeshSample(name, mesh),
SurfaceSource(planeDesc),
zoneNames_(zones),
bounds_(),
triangulate_(triangulate),
needsUpdate_(true)
{
if (debug)
{
if (!zoneNames_.empty())
{
Info<< "cellZones " << flatOutput(zoneNames_);
if (-1 == mesh.cellZones().findIndex(zoneNames_))
{
Info<< " not found!";
}
Info<< endl;
}
}
}
Foam::surfMeshSamplePlane::surfMeshSamplePlane
(
const word& name,
const polyMesh& mesh,
const dictionary& dict
)
:
surfMeshSample(name, mesh, dict),
SurfaceSource(plane(dict)),
zoneNames_(),
bounds_(dict.lookupOrDefault("bounds", boundBox::invertedBox)),
triangulate_(dict.lookupOrDefault("triangulate", true)),
needsUpdate_(true)
{
if (!dict.readIfPresent("zones", zoneNames_) && dict.found("zone"))
{
zoneNames_.resize(1);
dict.readEntry("zone", zoneNames_.first());
}
// Make plane relative to the coordinateSystem (Cartesian)
// allow lookup from global coordinate systems
if (dict.found(coordinateSystem::typeName_()))
{
coordSystem::cartesian cs
(
coordinateSystem::New(mesh, dict, coordinateSystem::typeName_())
);
plane& pln = planeDesc();
const point orig = cs.globalPosition(pln.origin());
const vector norm = cs.globalVector(pln.normal());
if (debug)
{
Info<< "plane " << name << " :"
<< " origin:" << origin()
<< " normal:" << normal()
<< " defined within a local coordinateSystem" << endl;
}
// Reassign the plane
pln = plane(orig, norm);
}
if (debug)
{
Info<< "plane " << name << " :"
<< " origin:" << origin()
<< " normal:" << normal();
if (bounds_.valid())
{
Info<< " bounds:" << bounds_;
}
if (!zoneNames_.empty())
{
Info<< " cellZones " << flatOutput(zoneNames_);
if (-1 == mesh.cellZones().findIndex(zoneNames_))
{
Info<< " not found!";
}
}
Info<< endl;
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::surfMeshSamplePlane::needsUpdate() const
{
return needsUpdate_;
}
bool Foam::surfMeshSamplePlane::expire()
{
// Already marked as expired
if (needsUpdate_)
{
return false;
}
needsUpdate_ = true;
return true;
}
bool Foam::surfMeshSamplePlane::update()
{
if (!needsUpdate_)
{
return false;
}
performCut(mesh(), triangulate_, cellSelection(true));
if (debug)
{
print(Pout);
Pout<< endl;
}
// Transfer content
getOrCreateSurfMesh().transfer
(
static_cast<SurfaceSource&>(*this)
);