Commit 42f82562 authored by Andrew Heather's avatar Andrew Heather
Browse files

added weighted average option

parent 3c54d945
......@@ -50,10 +50,13 @@ namespace Foam
fieldValues::faceSource::sourceTypeNames_;
template<>
const char* NamedEnum<fieldValues::faceSource::operationType, 4>::
names[] = {"none", "sum", "areaAverage", "areaIntegrate"};
const char* NamedEnum<fieldValues::faceSource::operationType, 5>::
names[] =
{
"none", "sum", "areaAverage", "areaIntegrate", "weightedAverage"
};
const NamedEnum<fieldValues::faceSource::operationType, 4>
const NamedEnum<fieldValues::faceSource::operationType, 5>
fieldValues::faceSource::operationTypeNames_;
}
......@@ -68,7 +71,9 @@ void Foam::fieldValues::faceSource::setFaceZoneFaces()
if (zoneId < 0)
{
FatalErrorIn("faceSource::faceSource::setFaceZoneFaces()")
<< "Unknown face zone name: " << sourceName_
<< type() << " " << name_ << ": "
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl
<< " Unknown face zone name: " << sourceName_
<< ". Valid face zones are: " << mesh().faceZones().names()
<< nl << exit(FatalError);
}
......@@ -164,7 +169,9 @@ void Foam::fieldValues::faceSource::setPatchFaces()
if (patchId < 0)
{
FatalErrorIn("faceSource::constructFaceAddressing()")
<< "Unknown patch name: " << sourceName_
<< type() << " " << name_ << ": "
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl
<< " Unknown patch name: " << sourceName_
<< ". Valid patch names are: "
<< mesh().boundaryMesh().names() << nl
<< exit(FatalError);
......@@ -197,7 +204,7 @@ void Foam::fieldValues::faceSource::setPatchFaces()
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::fieldValues::faceSource::initialise()
void Foam::fieldValues::faceSource::initialise(const dictionary& dict)
{
switch (source_)
{
......@@ -214,15 +221,40 @@ void Foam::fieldValues::faceSource::initialise()
default:
{
FatalErrorIn("faceSource::constructFaceAddressing()")
<< "Unknown source type. Valid source types are:"
<< type() << " " << name_ << ": "
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):"
<< nl << " Unknown source type. Valid source types are:"
<< sourceTypeNames_ << nl << exit(FatalError);
}
}
Info<< type() << " " << name_ << ":" << nl
<< " total faces = " << faceId_.size() << nl
<< " total area = " << sum(filterField(mesh().magSf()))
<< nl << endl;
<< " total faces = " << faceId_.size() << nl
<< " total area = " << sum(filterField(mesh().magSf())) << nl;
if (operation_ == opWeightedAverage)
{
dict.lookup("weightField") >> weightFieldName_;
if
(
obr().foundObject<volScalarField>(weightFieldName_)
|| obr().foundObject<surfaceScalarField>(weightFieldName_)
)
{
Info<< " weight field = " << weightFieldName_;
}
else
{
FatalErrorIn("faceSource::constructFaceAddressing()")
<< type() << " " << name_ << ": "
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):"
<< nl << " Weight field " << weightFieldName_
<< " must be either a " << volScalarField::typeName << " or "
<< surfaceScalarField::typeName << nl << exit(FatalError);
}
}
Info<< nl << endl;
}
......@@ -302,12 +334,13 @@ Foam::fieldValues::faceSource::faceSource
faceId_(),
facePatchId_(),
flipMap_(),
outputFilePtr_(NULL)
outputFilePtr_(NULL),
weightFieldName_("undefinedWeightedFieldName")
{
initialise();
if (active_)
{
initialise(dict);
// Create the output file if not already created
makeFile();
}
......@@ -327,7 +360,7 @@ void Foam::fieldValues::faceSource::read(const dictionary& dict)
if (active_)
{
fieldValue::read(dict);
initialise();
initialise(dict);
}
}
......
......@@ -39,7 +39,7 @@ Description
valueOutput true; // Write values at run-time output times?
source faceZone; // Type of face source: faceZone, patch
sourceName f0;
operation sum; // none, sum, areaAverage, areaIntegrate
operation sum;
fields
(
p
......@@ -48,6 +48,13 @@ Description
);
}
where operation is one of:
- none
- sum
- areaAverage
- areaIntegrate
- weightedAverage
SourceFiles
faceSource.C
......@@ -100,11 +107,12 @@ public:
opNone,
opSum,
opAreaAverage,
opAreaIntegrate
opAreaIntegrate,
opWeightedAverage
};
//- Operation type names
static const NamedEnum<operationType, 4> operationTypeNames_;
static const NamedEnum<operationType, 5> operationTypeNames_;
private:
......@@ -143,11 +151,14 @@ protected:
//- Output file pointer
autoPtr<OFstream> outputFilePtr_;
//- Weight field name - only used for opWeightedAverage mode
word weightFieldName_;
// Protected member functions
//- Initialise, e.g. face addressing
void initialise();
void initialise(const dictionary& dict);
//- Insert field values into values list
template<class Type>
......
......@@ -129,6 +129,47 @@ Type Foam::fieldValues::faceSource::processValues
result = sum(values*filterField(mesh().magSf()));
break;
}
case opWeightedAverage:
{
if (mesh().foundObject<volScalarField>(weightFieldName_))
{
tmp<scalarField> wField =
filterField
(
mesh().lookupObject<volScalarField>(weightFieldName_)
);
result = sum(values*wField())/sum(wField());
}
else if (mesh().foundObject<surfaceScalarField>(weightFieldName_))
{
tmp<scalarField> wField =
filterField
(
mesh().lookupObject<surfaceScalarField>
(
weightFieldName_
)
);
result = sum(values*wField())/sum(wField());
}
else
{
FatalErrorIn
(
"fieldValues::faceSource::processValues"
"("
"List<Type>&"
") const"
) << type() << " " << name_ << ": "
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):"
<< nl
<< " Weight field " << weightFieldName_
<< " must be either a " << volScalarField::typeName
<< " or " << surfaceScalarField::typeName << nl
<< abort(FatalError);
}
break;
}
default:
{
// Do nothing
......
......@@ -137,7 +137,7 @@ public:
//- Return the output field values flag
const Switch& valueOutput() const;
//- Helper funvction to return the reference to the mesh
//- Helper function to return the reference to the mesh
const fvMesh& mesh() const;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment