mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: faceSource functionObject : allow 'sampledSurface' to supply faces and data
This commit is contained in:
@ -28,21 +28,20 @@ License
|
||||
#include "cyclicPolyPatch.H"
|
||||
#include "emptyPolyPatch.H"
|
||||
#include "coupledPolyPatch.H"
|
||||
#include "surfaceFields.H"
|
||||
#include "volFields.H"
|
||||
#include "sampledSurface.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
defineTypeNameAndDebug(Foam::fieldValues::faceSource, 0);
|
||||
|
||||
template<>
|
||||
const char* Foam::NamedEnum<Foam::fieldValues::faceSource::sourceType, 2>::
|
||||
const char* Foam::NamedEnum<Foam::fieldValues::faceSource::sourceType, 3>::
|
||||
names[] =
|
||||
{
|
||||
"faceZone", "patch"
|
||||
"faceZone", "patch", "sampledSurface"
|
||||
};
|
||||
|
||||
const Foam::NamedEnum<Foam::fieldValues::faceSource::sourceType, 2>
|
||||
const Foam::NamedEnum<Foam::fieldValues::faceSource::sourceType, 3>
|
||||
Foam::fieldValues::faceSource::sourceTypeNames_;
|
||||
|
||||
|
||||
@ -188,6 +187,19 @@ void Foam::fieldValues::faceSource::setPatchFaces()
|
||||
}
|
||||
|
||||
|
||||
void Foam::fieldValues::faceSource::sampledSurfaceFaces(const dictionary& dict)
|
||||
{
|
||||
surfacePtr_ = sampledSurface::New
|
||||
(
|
||||
name_,
|
||||
mesh(),
|
||||
dict.subDict("sampledSurfaceDict")
|
||||
);
|
||||
surfacePtr_().update();
|
||||
nFaces_ = returnReduce(surfacePtr_().faces().size(), sumOp<label>());
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::fieldValues::faceSource::initialise(const dictionary& dict)
|
||||
@ -204,20 +216,37 @@ void Foam::fieldValues::faceSource::initialise(const dictionary& dict)
|
||||
setPatchFaces();
|
||||
break;
|
||||
}
|
||||
case stSampledSurface:
|
||||
{
|
||||
sampledSurfaceFaces(dict);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
FatalErrorIn("faceSource::initialise()")
|
||||
<< type() << " " << name_ << ": "
|
||||
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):"
|
||||
<< nl << " Unknown source type. Valid source types are:"
|
||||
<< sourceTypeNames_ << nl << exit(FatalError);
|
||||
<< sourceTypeNames_.sortedToc() << nl << exit(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
scalar totalArea;
|
||||
|
||||
if (surfacePtr_.valid())
|
||||
{
|
||||
surfacePtr_().update();
|
||||
totalArea = gSum(surfacePtr_().magSf());
|
||||
}
|
||||
else
|
||||
{
|
||||
totalArea = gSum(filterField(mesh().magSf(), false));
|
||||
}
|
||||
|
||||
Info<< type() << " " << name_ << ":" << nl
|
||||
<< " total faces = " << nFaces_
|
||||
<< nl
|
||||
<< " total area = " << gSum(filterField(mesh().magSf(), false))
|
||||
<< " total area = " << totalArea
|
||||
<< nl;
|
||||
|
||||
if (operation_ == opWeightedAverage)
|
||||
@ -280,11 +309,11 @@ Foam::fieldValues::faceSource::faceSource
|
||||
fieldValue(name, obr, dict, loadFromFiles),
|
||||
source_(sourceTypeNames_.read(dict.lookup("source"))),
|
||||
operation_(operationTypeNames_.read(dict.lookup("operation"))),
|
||||
weightFieldName_("undefinedWeightedFieldName"),
|
||||
nFaces_(0),
|
||||
faceId_(),
|
||||
facePatchId_(),
|
||||
faceSign_(),
|
||||
weightFieldName_("undefinedWeightedFieldName")
|
||||
faceSign_()
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
@ -315,11 +344,22 @@ void Foam::fieldValues::faceSource::write()
|
||||
|
||||
if (active_)
|
||||
{
|
||||
scalar totalArea;
|
||||
|
||||
if (surfacePtr_.valid())
|
||||
{
|
||||
surfacePtr_().update();
|
||||
totalArea = gSum(surfacePtr_().magSf());
|
||||
}
|
||||
else
|
||||
{
|
||||
totalArea = gSum(filterField(mesh().magSf(), false));
|
||||
}
|
||||
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
outputFilePtr_()
|
||||
<< obr_.time().value() << tab
|
||||
<< sum(filterField(mesh().magSf(), false));
|
||||
outputFilePtr_() << obr_.time().value() << tab << totalArea;
|
||||
}
|
||||
|
||||
forAll(fields_, i)
|
||||
|
||||
@ -36,8 +36,9 @@ Description
|
||||
outputControl outputTime;
|
||||
log true; // log to screen?
|
||||
valueOutput true; // Write values at run-time output times?
|
||||
source faceZone; // Type of face source: faceZone, patch
|
||||
sourceName f0;
|
||||
source faceZone; // Type of face source:
|
||||
// faceZone,patch,sampledSurface
|
||||
sourceName f0; // faceZone name, see below
|
||||
operation sum;
|
||||
fields
|
||||
(
|
||||
@ -47,7 +48,13 @@ Description
|
||||
);
|
||||
}
|
||||
|
||||
where operation is one of:
|
||||
source:
|
||||
- faceZone : requires a 'sourceName' entry to specify the faceZone
|
||||
- patch : "" patch
|
||||
- sampledSurface : requires a 'sampledSurfaceDict' subdictionary. See e.g.
|
||||
sampleDict.
|
||||
|
||||
operation is one of:
|
||||
- none
|
||||
- sum
|
||||
- areaAverage
|
||||
@ -80,6 +87,9 @@ SourceFiles
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
class sampledSurface;
|
||||
|
||||
namespace fieldValues
|
||||
{
|
||||
|
||||
@ -100,11 +110,12 @@ public:
|
||||
enum sourceType
|
||||
{
|
||||
stFaceZone,
|
||||
stPatch
|
||||
stPatch,
|
||||
stSampledSurface
|
||||
};
|
||||
|
||||
//- Source type names
|
||||
static const NamedEnum<sourceType, 2> sourceTypeNames_;
|
||||
static const NamedEnum<sourceType, 3> sourceTypeNames_;
|
||||
|
||||
|
||||
//- Operation type enumeration
|
||||
@ -133,6 +144,9 @@ private:
|
||||
//- Set faces to evaluate based on a patch
|
||||
void setPatchFaces();
|
||||
|
||||
//- Set faces according to sampledSurface
|
||||
void sampledSurfaceFaces(const dictionary&);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
@ -144,20 +158,30 @@ protected:
|
||||
//- Operation to apply to values
|
||||
operationType operation_;
|
||||
|
||||
//- Weight field name - only used for opWeightedAverage mode
|
||||
word weightFieldName_;
|
||||
|
||||
//- Global number of faces
|
||||
label nFaces_;
|
||||
|
||||
//- Local list of face IDs
|
||||
labelList faceId_;
|
||||
|
||||
//- Local list of patch ID per face
|
||||
labelList facePatchId_;
|
||||
// If operating on mesh faces (faceZone,patch)
|
||||
|
||||
//- List of +1/-1 representing face flip map (1 use as is, -1 negate)
|
||||
labelList faceSign_;
|
||||
//- Local list of face IDs
|
||||
labelList faceId_;
|
||||
|
||||
//- Local list of patch ID per face
|
||||
labelList facePatchId_;
|
||||
|
||||
//- List of +1/-1 representing face flip map
|
||||
// (1 use as is, -1 negate)
|
||||
labelList faceSign_;
|
||||
|
||||
// If operating on sampledSurface
|
||||
|
||||
//- underlying sampledSurface
|
||||
autoPtr<sampledSurface> surfacePtr_;
|
||||
|
||||
//- Weight field name - only used for opWeightedAverage mode
|
||||
word weightFieldName_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
@ -171,7 +195,7 @@ protected:
|
||||
|
||||
//- Return field values by looking up field name
|
||||
template<class Type>
|
||||
tmp<Field<Type> > setFieldValues(const word& fieldName) const;
|
||||
tmp<Field<Type> > getFieldValues(const word& fieldName) const;
|
||||
|
||||
//- Apply the 'operation' to the values
|
||||
template<class Type>
|
||||
|
||||
@ -26,7 +26,7 @@ License
|
||||
#include "faceSource.H"
|
||||
#include "surfaceFields.H"
|
||||
#include "volFields.H"
|
||||
#include "ListListOps.H"
|
||||
#include "sampledSurface.H"
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
@ -36,7 +36,7 @@ bool Foam::fieldValues::faceSource::validField(const word& fieldName) const
|
||||
typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf;
|
||||
typedef GeometricField<Type, fvPatchField, volMesh> vf;
|
||||
|
||||
if (obr_.foundObject<sf>(fieldName))
|
||||
if (source_ != stSampledSurface && obr_.foundObject<sf>(fieldName))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -50,7 +50,7 @@ bool Foam::fieldValues::faceSource::validField(const word& fieldName) const
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::tmp<Foam::Field<Type> > Foam::fieldValues::faceSource::setFieldValues
|
||||
Foam::tmp<Foam::Field<Type> > Foam::fieldValues::faceSource::getFieldValues
|
||||
(
|
||||
const word& fieldName
|
||||
) const
|
||||
@ -58,13 +58,20 @@ Foam::tmp<Foam::Field<Type> > Foam::fieldValues::faceSource::setFieldValues
|
||||
typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf;
|
||||
typedef GeometricField<Type, fvPatchField, volMesh> vf;
|
||||
|
||||
if (obr_.foundObject<sf>(fieldName))
|
||||
if (source_ != stSampledSurface && obr_.foundObject<sf>(fieldName))
|
||||
{
|
||||
return filterField(obr_.lookupObject<sf>(fieldName), true);
|
||||
}
|
||||
else if (obr_.foundObject<vf>(fieldName))
|
||||
{
|
||||
return filterField(obr_.lookupObject<vf>(fieldName), true);
|
||||
if (surfacePtr_.valid())
|
||||
{
|
||||
return surfacePtr_().sample(obr_.lookupObject<vf>(fieldName));
|
||||
}
|
||||
else
|
||||
{
|
||||
return filterField(obr_.lookupObject<vf>(fieldName), true);
|
||||
}
|
||||
}
|
||||
|
||||
return tmp<Field<Type> >(new Field<Type>(0));
|
||||
@ -131,15 +138,26 @@ bool Foam::fieldValues::faceSource::writeValues(const word& fieldName)
|
||||
|
||||
if (ok)
|
||||
{
|
||||
// Get (correctly oriented) field
|
||||
Field<Type> values = combineFields(setFieldValues<Type>(fieldName));
|
||||
Field<Type> values = getFieldValues<Type>(fieldName);
|
||||
scalarField weightField = getFieldValues<scalar>(weightFieldName_);
|
||||
scalarField magSf;
|
||||
|
||||
// Get unoriented magSf
|
||||
scalarField magSf = combineFields(filterField(mesh().magSf(), false));
|
||||
if (surfacePtr_.valid())
|
||||
{
|
||||
// Get unoriented magSf
|
||||
magSf = surfacePtr_().magSf();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get unoriented magSf
|
||||
magSf = combineFields(filterField(mesh().magSf(), false));
|
||||
}
|
||||
|
||||
// Combine onto master
|
||||
values = combineFields(values);
|
||||
magSf = combineFields(magSf);
|
||||
weightField = combineFields(weightField);
|
||||
|
||||
// Get (correctly oriented) weighting field
|
||||
scalarField weightField =
|
||||
combineFields(setFieldValues<scalar>(weightFieldName_));
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user