ENH: faceSource functionObject : allow 'sampledSurface' to supply faces and data

This commit is contained in:
mattijs
2010-11-08 10:09:42 +00:00
parent e674b0c765
commit 012178576d
8 changed files with 159 additions and 54 deletions

View File

@ -198,11 +198,10 @@ void Foam::fieldValues::cellSource::write()
if (active_) if (active_)
{ {
scalar totalVolume = gSum(filterField(mesh().V()));
if (Pstream::master()) if (Pstream::master())
{ {
outputFilePtr_() outputFilePtr_() << obr_.time().value() << tab << totalVolume;
<< obr_.time().value() << tab
<< sum(filterField(mesh().V()));
} }
forAll(fields_, i) forAll(fields_, i)

View File

@ -61,11 +61,23 @@ functions
// Output field values as well // Output field values as well
valueOutput true; valueOutput true;
// Patch or faceZone to sample // Type of source: patch/faceZone/sampledSurface
source patch; source patch;
// if patch or faceZone: name of patch or faceZone
sourceName movingWall; sourceName movingWall;
// source faceZone;
// sourceName f0; //// if sampledSurface: dictionary with a sampledSurface
//sampledSurfaceDict
//{
// type cuttingPlane;
// planeType pointAndNormal;
// pointAndNormalDict
// {
// basePoint (0 0.099 0);
// normalVector (0 1 0);
// }
//}
// Operation: areaAverage/sum/weightedAverage ... // Operation: areaAverage/sum/weightedAverage ...
operation areaAverage; operation areaAverage;
@ -73,7 +85,7 @@ functions
fields fields
( (
p p
phi phi // surface fields not supported for sampledSurface
U U
); );
} }

View File

@ -28,21 +28,20 @@ License
#include "cyclicPolyPatch.H" #include "cyclicPolyPatch.H"
#include "emptyPolyPatch.H" #include "emptyPolyPatch.H"
#include "coupledPolyPatch.H" #include "coupledPolyPatch.H"
#include "surfaceFields.H" #include "sampledSurface.H"
#include "volFields.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(Foam::fieldValues::faceSource, 0); defineTypeNameAndDebug(Foam::fieldValues::faceSource, 0);
template<> template<>
const char* Foam::NamedEnum<Foam::fieldValues::faceSource::sourceType, 2>:: const char* Foam::NamedEnum<Foam::fieldValues::faceSource::sourceType, 3>::
names[] = 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_; 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 * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::fieldValues::faceSource::initialise(const dictionary& dict) void Foam::fieldValues::faceSource::initialise(const dictionary& dict)
@ -204,20 +216,37 @@ void Foam::fieldValues::faceSource::initialise(const dictionary& dict)
setPatchFaces(); setPatchFaces();
break; break;
} }
case stSampledSurface:
{
sampledSurfaceFaces(dict);
break;
}
default: default:
{ {
FatalErrorIn("faceSource::initialise()") FatalErrorIn("faceSource::initialise()")
<< type() << " " << name_ << ": " << type() << " " << name_ << ": "
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):" << sourceTypeNames_[source_] << "(" << sourceName_ << "):"
<< nl << " Unknown source type. Valid source types are:" << 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 Info<< type() << " " << name_ << ":" << nl
<< " total faces = " << nFaces_ << " total faces = " << nFaces_
<< nl << nl
<< " total area = " << gSum(filterField(mesh().magSf(), false)) << " total area = " << totalArea
<< nl; << nl;
if (operation_ == opWeightedAverage) if (operation_ == opWeightedAverage)
@ -280,11 +309,11 @@ Foam::fieldValues::faceSource::faceSource
fieldValue(name, obr, dict, loadFromFiles), fieldValue(name, obr, dict, loadFromFiles),
source_(sourceTypeNames_.read(dict.lookup("source"))), source_(sourceTypeNames_.read(dict.lookup("source"))),
operation_(operationTypeNames_.read(dict.lookup("operation"))), operation_(operationTypeNames_.read(dict.lookup("operation"))),
weightFieldName_("undefinedWeightedFieldName"),
nFaces_(0), nFaces_(0),
faceId_(), faceId_(),
facePatchId_(), facePatchId_(),
faceSign_(), faceSign_()
weightFieldName_("undefinedWeightedFieldName")
{ {
read(dict); read(dict);
} }
@ -315,11 +344,22 @@ void Foam::fieldValues::faceSource::write()
if (active_) if (active_)
{ {
scalar totalArea;
if (surfacePtr_.valid())
{
surfacePtr_().update();
totalArea = gSum(surfacePtr_().magSf());
}
else
{
totalArea = gSum(filterField(mesh().magSf(), false));
}
if (Pstream::master()) if (Pstream::master())
{ {
outputFilePtr_() outputFilePtr_() << obr_.time().value() << tab << totalArea;
<< obr_.time().value() << tab
<< sum(filterField(mesh().magSf(), false));
} }
forAll(fields_, i) forAll(fields_, i)

View File

@ -36,8 +36,9 @@ Description
outputControl outputTime; outputControl outputTime;
log true; // log to screen? log true; // log to screen?
valueOutput true; // Write values at run-time output times? valueOutput true; // Write values at run-time output times?
source faceZone; // Type of face source: faceZone, patch source faceZone; // Type of face source:
sourceName f0; // faceZone,patch,sampledSurface
sourceName f0; // faceZone name, see below
operation sum; operation sum;
fields 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 - none
- sum - sum
- areaAverage - areaAverage
@ -80,6 +87,9 @@ SourceFiles
namespace Foam namespace Foam
{ {
class sampledSurface;
namespace fieldValues namespace fieldValues
{ {
@ -100,11 +110,12 @@ public:
enum sourceType enum sourceType
{ {
stFaceZone, stFaceZone,
stPatch stPatch,
stSampledSurface
}; };
//- Source type names //- Source type names
static const NamedEnum<sourceType, 2> sourceTypeNames_; static const NamedEnum<sourceType, 3> sourceTypeNames_;
//- Operation type enumeration //- Operation type enumeration
@ -133,6 +144,9 @@ private:
//- Set faces to evaluate based on a patch //- Set faces to evaluate based on a patch
void setPatchFaces(); void setPatchFaces();
//- Set faces according to sampledSurface
void sampledSurfaceFaces(const dictionary&);
protected: protected:
@ -144,20 +158,30 @@ protected:
//- Operation to apply to values //- Operation to apply to values
operationType operation_; operationType operation_;
//- Weight field name - only used for opWeightedAverage mode
word weightFieldName_;
//- Global number of faces //- Global number of faces
label nFaces_; label nFaces_;
// If operating on mesh faces (faceZone,patch)
//- Local list of face IDs //- Local list of face IDs
labelList faceId_; labelList faceId_;
//- Local list of patch ID per face //- Local list of patch ID per face
labelList facePatchId_; labelList facePatchId_;
//- List of +1/-1 representing face flip map (1 use as is, -1 negate) //- List of +1/-1 representing face flip map
// (1 use as is, -1 negate)
labelList faceSign_; labelList faceSign_;
//- Weight field name - only used for opWeightedAverage mode // If operating on sampledSurface
word weightFieldName_;
//- underlying sampledSurface
autoPtr<sampledSurface> surfacePtr_;
// Protected Member Functions // Protected Member Functions
@ -171,7 +195,7 @@ protected:
//- Return field values by looking up field name //- Return field values by looking up field name
template<class Type> 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 //- Apply the 'operation' to the values
template<class Type> template<class Type>

View File

@ -26,7 +26,7 @@ License
#include "faceSource.H" #include "faceSource.H"
#include "surfaceFields.H" #include "surfaceFields.H"
#include "volFields.H" #include "volFields.H"
#include "ListListOps.H" #include "sampledSurface.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * 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, fvsPatchField, surfaceMesh> sf;
typedef GeometricField<Type, fvPatchField, volMesh> vf; typedef GeometricField<Type, fvPatchField, volMesh> vf;
if (obr_.foundObject<sf>(fieldName)) if (source_ != stSampledSurface && obr_.foundObject<sf>(fieldName))
{ {
return true; return true;
} }
@ -50,7 +50,7 @@ bool Foam::fieldValues::faceSource::validField(const word& fieldName) const
template<class Type> 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 word& fieldName
) const ) const
@ -58,14 +58,21 @@ Foam::tmp<Foam::Field<Type> > Foam::fieldValues::faceSource::setFieldValues
typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf; typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf;
typedef GeometricField<Type, fvPatchField, volMesh> vf; 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); return filterField(obr_.lookupObject<sf>(fieldName), true);
} }
else if (obr_.foundObject<vf>(fieldName)) else if (obr_.foundObject<vf>(fieldName))
{
if (surfacePtr_.valid())
{
return surfacePtr_().sample(obr_.lookupObject<vf>(fieldName));
}
else
{ {
return filterField(obr_.lookupObject<vf>(fieldName), true); return filterField(obr_.lookupObject<vf>(fieldName), true);
} }
}
return tmp<Field<Type> >(new Field<Type>(0)); return tmp<Field<Type> >(new Field<Type>(0));
} }
@ -131,15 +138,26 @@ bool Foam::fieldValues::faceSource::writeValues(const word& fieldName)
if (ok) if (ok)
{ {
// Get (correctly oriented) field Field<Type> values = getFieldValues<Type>(fieldName);
Field<Type> values = combineFields(setFieldValues<Type>(fieldName)); scalarField weightField = getFieldValues<scalar>(weightFieldName_);
scalarField magSf;
if (surfacePtr_.valid())
{
// Get unoriented magSf // Get unoriented magSf
scalarField magSf = combineFields(filterField(mesh().magSf(), false)); 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()) if (Pstream::master())
{ {

View File

@ -130,7 +130,7 @@ Foam::fieldValue::fieldValue
obr_(obr), obr_(obr),
active_(true), active_(true),
log_(false), log_(false),
sourceName_(dict.lookup("sourceName")), sourceName_(dict.lookupOrDefault<word>("sourceName", "sampledSurface")),
fields_(dict.lookup("fields")), fields_(dict.lookup("fields")),
valueOutput_(dict.lookup("valueOutput")), valueOutput_(dict.lookup("valueOutput")),
outputFilePtr_(NULL) outputFilePtr_(NULL)

View File

@ -164,12 +164,14 @@ public:
//- Execute the at the final time-loop, currently does nothing //- Execute the at the final time-loop, currently does nothing
virtual void end(); virtual void end();
//- Comnbine fields from all processor domains into single field //- Combine fields from all processor domains into single field
template<class Type> template<class Type>
tmp<Field<Type> > combineFields tmp<Field<Type> > combineFields(const Field<Type>& field) const;
(
const tmp<Field<Type> >& field //- Combine fields from all processor domains into single field
) const; template<class Type>
tmp<Field<Type> > combineFields(const tmp<Field<Type> >&) const;
}; };

View File

@ -32,12 +32,12 @@ License
template<class Type> template<class Type>
Foam::tmp<Foam::Field<Type> > Foam::fieldValue::combineFields Foam::tmp<Foam::Field<Type> > Foam::fieldValue::combineFields
( (
const tmp<Field<Type> >& field const Field<Type>& field
) const ) const
{ {
List<Field<Type> > allValues(Pstream::nProcs()); List<Field<Type> > allValues(Pstream::nProcs());
allValues[Pstream::myProcNo()] = field(); allValues[Pstream::myProcNo()] = field;
Pstream::gatherList(allValues); Pstream::gatherList(allValues);
@ -57,9 +57,19 @@ Foam::tmp<Foam::Field<Type> > Foam::fieldValue::combineFields
} }
else else
{ {
return field(); return field;
} }
} }
template<class Type>
Foam::tmp<Foam::Field<Type> > Foam::fieldValue::combineFields
(
const tmp<Field<Type> >& field
) const
{
return combineFields(field());
}
// ************************************************************************* // // ************************************************************************* //