Commit 03e6aa1a authored by Mark Olesen's avatar Mark Olesen Committed by Andrew Heather
Browse files

ENH: replace surfMesh/fields support with polySurface/fields support (#1206)

- fits better into the general sampling framework, improves flexibilty
  and allows code reduction.

ENH: include surface fields on sampledSurfaces that support it
parent 181c974b
......@@ -32,7 +32,9 @@ Group
Description
Calculates average quantities for a user-specified selection of volumetric
and surface fields.
With the %subRegion option, also supports fields on a surfMesh.
With the %subRegion option, also supports fields on functionObject
surface output (eg, sampledSurfaces).
Fields are entered as a list of sub-dictionaries, which indicate the type of
averages to perform, and can be updated during the calculation. The current
......@@ -104,15 +106,15 @@ Usage
Where the entries comprise:
\table
Property | Description | Required | Default
type | type name: fieldAverage | yes |
restartOnRestart | Restart the averaging on restart | no | no
restartOnOutput | Restart the averaging on output | no | no
periodicRestart | Periodically restart the averaging | no | no
restartPeriod | Periodic restart period | conditional |
restartTime | One-shot reset of the averaging | no | great
fields | list of fields and averaging options | yes |
subRegion | name of a sub-region such as a surface name | no |
Property | Description | Required | Default
type | Type name: fieldAverage | yes |
restartOnRestart| Restart the averaging on restart | no | no
restartOnOutput | Restart the averaging on output | no | no
periodicRestart | Periodically restart the averaging | no | no
restartPeriod | Periodic restart period | conditional |
restartTime | One-shot reset of the averaging | no | great
fields | list of fields and averaging options | yes |
subRegion | Name for alternative objectRegistry | no | ""
\endtable
......
......@@ -28,7 +28,7 @@ License
#include "fieldAverageItem.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "surfFields.H"
#include "polySurfaceFields.H"
#include "OFstream.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
......@@ -99,7 +99,7 @@ void Foam::functionObjects::fieldAverage::addMeanField
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
typedef DimensionedField<Type, surfGeoMesh> SurfFieldType;
typedef DimensionedField<Type, polySurfaceGeoMesh> SurfFieldType;
if (item.mean())
{
......@@ -169,7 +169,7 @@ void Foam::functionObjects::fieldAverage::restoreWindowFields
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
typedef DimensionedField<Type, surfGeoMesh> SurfFieldType;
typedef DimensionedField<Type, polySurfaceGeoMesh> SurfFieldType;
if (item.window() > 0)
{
......@@ -243,11 +243,11 @@ void Foam::functionObjects::fieldAverage::addPrime2MeanField
{
typedef GeometricField<Type1, fvPatchField, volMesh> VolFieldType1;
typedef GeometricField<Type1, fvsPatchField, surfaceMesh> SurfaceFieldType1;
typedef DimensionedField<Type1, surfGeoMesh> SurfFieldType1;
typedef DimensionedField<Type1, polySurfaceGeoMesh> SurfFieldType1;
typedef GeometricField<Type2, fvPatchField, volMesh> VolFieldType2;
typedef GeometricField<Type2, fvsPatchField, surfaceMesh> SurfaceFieldType2;
typedef DimensionedField<Type2, surfGeoMesh> SurfFieldType2;
typedef DimensionedField<Type2, polySurfaceGeoMesh> SurfFieldType2;
if (item.prime2Mean())
{
......@@ -312,7 +312,7 @@ void Foam::functionObjects::fieldAverage::storeWindowFields()
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
typedef DimensionedField<Type, surfGeoMesh> SurfFieldType;
typedef DimensionedField<Type, polySurfaceGeoMesh> SurfFieldType;
for (fieldAverageItem& item : faItems_)
{
......@@ -331,7 +331,7 @@ void Foam::functionObjects::fieldAverage::calculateMeanFields() const
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
typedef DimensionedField<Type, surfGeoMesh> SurfFieldType;
typedef DimensionedField<Type, polySurfaceGeoMesh> SurfFieldType;
for (const fieldAverageItem& item : faItems_)
{
......@@ -347,11 +347,11 @@ void Foam::functionObjects::fieldAverage::calculatePrime2MeanFields() const
{
typedef GeometricField<Type1, fvPatchField, volMesh> VolFieldType1;
typedef GeometricField<Type1, fvsPatchField, surfaceMesh> SurfaceFieldType1;
typedef DimensionedField<Type1, surfGeoMesh> SurfFieldType1;
typedef DimensionedField<Type1, polySurfaceGeoMesh> SurfFieldType1;
typedef GeometricField<Type2, fvPatchField, volMesh> VolFieldType2;
typedef GeometricField<Type2, fvsPatchField, surfaceMesh> SurfaceFieldType2;
typedef DimensionedField<Type2, surfGeoMesh> SurfFieldType2;
typedef DimensionedField<Type2, polySurfaceGeoMesh> SurfFieldType2;
for (const fieldAverageItem& item : faItems_)
{
......@@ -391,11 +391,11 @@ void Foam::functionObjects::fieldAverage::addMeanSqrToPrime2Mean() const
{
typedef GeometricField<Type1, fvPatchField, volMesh> VolFieldType1;
typedef GeometricField<Type1, fvsPatchField, surfaceMesh> SurfaceFieldType1;
typedef DimensionedField<Type1, surfGeoMesh> SurfFieldType1;
typedef DimensionedField<Type1, polySurfaceGeoMesh> SurfFieldType1;
typedef GeometricField<Type2, fvPatchField, volMesh> VolFieldType2;
typedef GeometricField<Type2, fvsPatchField, surfaceMesh> SurfaceFieldType2;
typedef DimensionedField<Type2, surfGeoMesh> SurfFieldType2;
typedef DimensionedField<Type2, polySurfaceGeoMesh> SurfFieldType2;
for (const fieldAverageItem& item : faItems_)
{
......@@ -431,7 +431,7 @@ void Foam::functionObjects::fieldAverage::writeFields() const
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
typedef DimensionedField<Type, surfGeoMesh> SurfFieldType;
typedef DimensionedField<Type, polySurfaceGeoMesh> SurfFieldType;
for (const fieldAverageItem& item : faItems_)
{
......
......@@ -60,7 +60,7 @@ Foam::functionObjects::fieldValues::surfaceFieldValue::regionTypeNames_
({
{ regionTypes::stFaceZone, "faceZone" },
{ regionTypes::stPatch, "patch" },
{ regionTypes::stSurface, "surface" },
{ regionTypes::stObject, "functionObjectSurface" },
{ regionTypes::stSampled, "sampledSurface" },
});
......@@ -118,9 +118,9 @@ Foam::functionObjects::fieldValues::surfaceFieldValue::postOperationTypeNames_
const Foam::objectRegistry&
Foam::functionObjects::fieldValues::surfaceFieldValue::obr() const
{
if (stSurface == regionType_)
if (stObject == regionType_)
{
return mesh_.lookupObject<objectRegistry>(regionName_);
return storedObjects().lookupObject<polySurface>(regionName_);
}
return mesh_;
......@@ -368,9 +368,9 @@ combineSurfaceGeometry
pointField& points
) const
{
if (stSurface == regionType_)
if (stObject == regionType_)
{
const surfMesh& s = dynamicCast<const surfMesh>(obr());
const polySurface& s = dynamicCast<const polySurface>(obr());
if (Pstream::parRun())
{
......@@ -436,9 +436,9 @@ Foam::functionObjects::fieldValues::surfaceFieldValue::totalArea() const
{
scalar totalArea = 0;
if (stSurface == regionType_)
if (stObject == regionType_)
{
const surfMesh& s = dynamicCast<const surfMesh>(obr());
const polySurface& s = dynamicCast<const polySurface>(obr());
totalArea = gSum(s.magSf());
}
......@@ -505,9 +505,9 @@ bool Foam::functionObjects::fieldValues::surfaceFieldValue::update()
setPatchFaces();
break;
}
case stSurface:
case stObject:
{
const surfMesh& s = dynamicCast<const surfMesh>(obr());
const polySurface& s = dynamicCast<const polySurface>(obr());
nFaces_ = returnReduce(s.size(), sumOp<label>());
break;
}
......@@ -1007,9 +1007,9 @@ bool Foam::functionObjects::fieldValues::surfaceFieldValue::write()
vectorField Sf;
if (usesSf())
{
if (stSurface == regionType_)
if (stObject == regionType_)
{
const surfMesh& s = dynamicCast<const surfMesh>(obr());
const polySurface& s = dynamicCast<const polySurface>(obr());
Sf = s.Sf();
}
else if (sampledPtr_.valid())
......
......@@ -98,7 +98,7 @@ Usage
\plaintable
faceZone | The \b name entry to specify the faceZone
patch | The \b name entry to specify the patch
surface | The \b name entry to specify the surfMesh
functionObjectSurface | The \b name entry to specify a polySurface
sampledSurface | A \b sampledSurfaceDict sub-dictionary and \b name
\endplaintable
......@@ -134,13 +134,14 @@ Note
- The values reported by the areaNormalAverage and areaNormalIntegrate
operations are written as the first component of a field with the same
rank as the input field.
- faces on empty patches get ignored
- if the field is a volField the \c faceZone can only consist of boundary
- Faces on empty patches get ignored
- If the field is a volField the \c faceZone can only consist of boundary
faces
- Using \c surface:
- Using \c functionObjectSurface:
- The keyword %subRegion should not be used to select surfaces.
Specify instead the regionType 'surface' and provide the surface name.
- using \c sampledSurface:
Instead specify the regionType 'functionObjectSurface' and provide
the name.
- Using \c sampledSurface:
- not available for surface fields
- if interpolate=true they use \c interpolationCellPoint
otherwise they use cell values
......@@ -180,11 +181,11 @@ SourceFiles
#include "fieldValue.H"
#include "Enum.H"
#include "meshedSurf.H"
#include "surfaceMesh.H"
#include "polySurface.H"
#include "fvsPatchField.H"
#include "volFieldsFwd.H"
#include "surfFieldsFwd.H"
#include "polySurfaceFieldsFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -217,7 +218,7 @@ public:
{
stFaceZone = 0x01, //!< Calculate on a faceZone
stPatch = 0x02, //!< Calculate on a patch
stSurface = 0x11, //!< Calculate with fields on a surfMesh
stObject = 0x11, //!< Calculate with function object surface
stSampled = 0x12 //!< Sample onto surface and calculate
};
......
......@@ -26,13 +26,19 @@ License
\*---------------------------------------------------------------------------*/
#include "Time.H"
#include "sampledSurface.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
inline bool Foam::functionObjects::fieldValues::surfaceFieldValue::
withSurfaceFields() const
{
return (stFaceZone == regionType_ || stPatch == regionType_);
return
(
stFaceZone == regionType_
|| stPatch == regionType_
|| (sampledPtr_.valid() && sampledPtr_->withSurfaceFields())
);
}
......
......@@ -27,7 +27,7 @@ License
#include "surfaceFieldValue.H"
#include "surfaceFields.H"
#include "surfFields.H"
#include "polySurfaceFields.H"
#include "volFields.H"
#include "sampledSurface.H"
#include "surfaceWriter.H"
......@@ -58,7 +58,7 @@ bool Foam::functionObjects::fieldValues::surfaceFieldValue::validField
{
typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf;
typedef GeometricField<Type, fvPatchField, volMesh> vf;
typedef DimensionedField<Type, surfGeoMesh> smt;
typedef DimensionedField<Type, polySurfaceGeoMesh> smt;
return
(
......@@ -79,7 +79,7 @@ Foam::functionObjects::fieldValues::surfaceFieldValue::getFieldValues
{
typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf;
typedef GeometricField<Type, fvPatchField, volMesh> vf;
typedef DimensionedField<Type, surfGeoMesh> smt;
typedef DimensionedField<Type, polySurfaceGeoMesh> smt;
if (foundObject<smt>(fieldName))
{
......
......@@ -27,7 +27,7 @@ License
#include "volFields.H"
#include "surfaceFields.H"
#include "surfFields.H"
#include "polySurfaceFields.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
......@@ -36,7 +36,7 @@ bool Foam::functionObjects::fieldsExpression::calcFieldTypes(FOType& fo)
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
typedef DimensionedField<Type, surfGeoMesh> SurfFieldType;
typedef DimensionedField<Type, polySurfaceGeoMesh> SurfFieldType;
if (foundObject<VolFieldType>(fieldNames_[0]))
{
......
......@@ -27,8 +27,7 @@ License
#include "fluxSummary.H"
#include "surfaceFields.H"
#include "surfFields.H"
#include "surfMesh.H"
#include "polySurfaceFields.H"
#include "dictionary.H"
#include "Time.H"
#include "syncTools.H"
......@@ -65,6 +64,7 @@ Foam::functionObjects::fluxSummary::modeTypeNames_
{ modeType::mdFaceZone , "faceZone" },
{ modeType::mdFaceZoneAndDirection, "faceZoneAndDirection" },
{ modeType::mdCellZoneAndDirection, "cellZoneAndDirection" },
{ modeType::mdSurface, "functionObjectSurface" },
{ modeType::mdSurface, "surface" },
{ modeType::mdSurfaceAndDirection, "surfaceAndDirection" },
});
......@@ -116,14 +116,15 @@ void Foam::functionObjects::fluxSummary::initialiseSurface
DynamicList<boolList>& faceFlip
) const
{
const surfMesh* surfptr = mesh_.cfindObject<surfMesh>(surfName);
const polySurface* surfptr =
storedObjects().cfindObject<polySurface>(surfName);
if (!surfptr)
{
FatalErrorInFunction
<< "Unable to find surface " << surfName
<< ". Valid surfaces: "
<< mesh_.sortedNames<surfMesh>() << nl
<< storedObjects().sortedNames<polySurface>() << nl
<< exit(FatalError);
}
......@@ -142,14 +143,15 @@ void Foam::functionObjects::fluxSummary::initialiseSurfaceAndDirection
DynamicList<boolList>& faceFlip
) const
{
const surfMesh* surfptr = mesh_.cfindObject<surfMesh>(surfName);
const polySurface* surfptr =
storedObjects().cfindObject<polySurface>(surfName);
if (!surfptr)
{
FatalErrorInFunction
<< "Unable to find surface " << surfName
<< ". Valid surfaces: "
<< mesh_.sortedNames<surfMesh>() << nl
<< storedObjects().sortedNames<polySurface>() << nl
<< exit(FatalError);
}
......@@ -661,7 +663,9 @@ Foam::scalar Foam::functionObjects::fluxSummary::totalArea
if (isSurfaceMode())
{
const surfMesh& s = mesh_.lookupObject<surfMesh>(zoneNames_[idx]);
const polySurface& s =
storedObjects().lookupObject<polySurface>(zoneNames_[idx]);
sumMagSf = sum(s.magSf());
}
else
......@@ -693,11 +697,12 @@ Foam::scalar Foam::functionObjects::fluxSummary::totalArea
bool Foam::functionObjects::fluxSummary::surfaceModeWrite()
{
if (zoneNames_.size())
for (const word& surfName : zoneNames_)
{
const label surfi = 0;
const surfMesh& s = mesh_.lookupObject<surfMesh>(zoneNames_[surfi]);
const surfVectorField& phi = s.lookupObject<surfVectorField>(phiName_);
const polySurface& s =
storedObjects().lookupObject<polySurface>(surfName);
const auto& phi = s.lookupObject<polySurfaceVectorField>(phiName_);
Log << type() << ' ' << name() << ' '
<< checkFlowType(phi.dimensions(), phi.name()) << " write:" << nl;
......@@ -706,8 +711,10 @@ bool Foam::functionObjects::fluxSummary::surfaceModeWrite()
forAll(zoneNames_, surfi)
{
const surfMesh& s = mesh_.lookupObject<surfMesh>(zoneNames_[surfi]);
const surfVectorField& phi = s.lookupObject<surfVectorField>(phiName_);
const polySurface& s =
storedObjects().lookupObject<polySurface>(zoneNames_[surfi]);
const auto& phi = s.lookupObject<polySurfaceVectorField>(phiName_);
checkFlowType(phi.dimensions(), phi.name());
......
......@@ -120,14 +120,14 @@ public:
//- Face mode type
enum modeType
{
mdFaceZone, //!< face zone
mdFaceZoneAndDirection, //!< face zone with prescribed direction
mdCellZoneAndDirection, //!< cell zone with prescribed direction
mdSurface, //!< surfMesh
mdSurfaceAndDirection //!< surfMesh with prescribed direction
mdFaceZone, //!< Face zone
mdFaceZoneAndDirection, //!< Face zone with prescribed direction
mdCellZoneAndDirection, //!< Cell zone with prescribed direction
mdSurface, //!< A functionObject surface
mdSurfaceAndDirection //!< A surface with prescribed direction
};
//- Mode type names
//- Face mode names
static const Enum<modeType> modeTypeNames_;
......
......@@ -34,7 +34,8 @@ Description
The operation can be applied to any volume or surface fields generating a
volume or surface scalar field.
With the %subRegion option, also supports fields on a surfMesh.
With the %subRegion option, also supports fields on functionObject
surface output (eg, sampledSurfaces).
See also
Foam::functionObjects::fvMeshFunctionObject
......
......@@ -27,7 +27,7 @@ License
#include "volFields.H"
#include "surfaceFields.H"
#include "surfFields.H"
#include "polySurfaceFields.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
......@@ -36,7 +36,7 @@ bool Foam::functionObjects::mag::calcMag()
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
typedef DimensionedField<Type, surfGeoMesh> SurfFieldType;
typedef DimensionedField<Type, polySurfaceGeoMesh> SurfFieldType;
if (foundObject<VolFieldType>(fieldName_, false))
{
......
......@@ -34,7 +34,8 @@ Description
The operation can be applied to any volume or surface field generating a
volume or surface scalar field.
With the %subRegion option, also supports fields on a surfMesh.
With the %subRegion option, also supports fields on functionObject
surface output (eg, sampledSurfaces).
See also
Foam::functionObjects::fvMeshFunctionObject
......
......@@ -27,7 +27,7 @@ License
#include "volFields.H"
#include "surfaceFields.H"
#include "surfFields.H"
#include "polySurfaceFields.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
......@@ -36,7 +36,7 @@ bool Foam::functionObjects::magSqr::calcMagSqr()
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
typedef DimensionedField<Type, surfGeoMesh> SurfFieldType;
typedef DimensionedField<Type, polySurfaceGeoMesh> SurfFieldType;
if (foundObject<VolFieldType>(fieldName_, false))
{
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015-2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -28,7 +28,6 @@ License
#include "readFields.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "surfFields.H"
#include "Time.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -38,7 +37,7 @@ bool Foam::functionObjects::readFields::loadField(const word& fieldName)
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
typedef DimensionedField<Type, surfGeoMesh> SurfFieldType;
/// typedef DimensionedField<Type, surfGeoMesh> SurfFieldType;
if (foundObject<VolFieldType>(fieldName))
{
......@@ -54,13 +53,13 @@ bool Foam::functionObjects::readFields::loadField(const word& fieldName)
<< " " << fieldName << " already exists in database"
<< " already in database" << endl;
}
else if (foundObject<SurfFieldType>(fieldName))
{
DebugInfo
<< "readFields: " << SurfFieldType::typeName
<< " " << fieldName << " already exists in database"
<< " already in database" << endl;
}
/// else if (foundObject<SurfFieldType>(fieldName))
/// {
/// DebugInfo
/// << "readFields: " << SurfFieldType::typeName
/// << " " << fieldName << " already exists in database"
/// << " already in database" << endl;
/// }
else
{
IOobject fieldHeader
......@@ -76,35 +75,32 @@ bool Foam::functionObjects::readFields::loadField(const word& fieldName)
{
// Store field on mesh database
Log << " Reading " << fieldName << endl;
VolFieldType* vfPtr(new VolFieldType(fieldHeader, mesh_));
mesh_.objectRegistry::store(vfPtr);
VolFieldType* fldPtr(new VolFieldType(fieldHeader, mesh_));
mesh_.objectRegistry::store(fldPtr);
return true;
}
else if (fieldHeader.typeHeaderOk<SurfaceFieldType>(true, true, false))
{
// Store field on mesh database
Log << " Reading " << fieldName << endl;
SurfaceFieldType* sfPtr(new SurfaceFieldType(fieldHeader, mesh_));
mesh_.objectRegistry::store(sfPtr);
SurfaceFieldType* fldPtr(new SurfaceFieldType(fieldHeader, mesh_));
mesh_.objectRegistry::store(fldPtr);
return true;
}
else if (fieldHeader.typeHeaderOk<SurfFieldType>(true, true, false))
{
if (isA<surfMesh>(obr()))
{
const surfMesh& s = dynamicCast<const surfMesh>(obr());
// Store field on surfMesh database
Log << " Reading " << fieldName << endl;
SurfFieldType* sfPtr(new SurfFieldType(fieldHeader, s));
s.store(sfPtr);
return true;
}
else
{
return false;
}
}
/// else if (fieldHeader.typeHeaderOk<SurfFieldType>(true, true, false))
/// {
/// const surfMesh* surfptr = isA<surfMesh>(obr());
/// if (surfptr)
/// {
/// const surfMesh& s = surfptr;
///
/// // Store field on surfMesh database
/// Log << " Reading " << fieldName << endl;
/// SurfFieldType* fldPtr(new SurfFieldType(fieldHeader, s));
/// s.store(fldPtr);
/// return true;
/// }
/// }
}
return false;
......
......@@ -3,20 +3,20 @@
// Averaging of volume fields or fields on an externally loaded surface.
avg-tracer0-0.25
{
${settings_avg}
subRegion plane-0.25;
${__settings_avg}
subRegion sampled.plane-0.25;
}