mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
added weighted average option
This commit is contained in:
@ -50,10 +50,13 @@ namespace Foam
|
|||||||
fieldValues::faceSource::sourceTypeNames_;
|
fieldValues::faceSource::sourceTypeNames_;
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
const char* NamedEnum<fieldValues::faceSource::operationType, 4>::
|
const char* NamedEnum<fieldValues::faceSource::operationType, 5>::
|
||||||
names[] = {"none", "sum", "areaAverage", "areaIntegrate"};
|
names[] =
|
||||||
|
{
|
||||||
|
"none", "sum", "areaAverage", "areaIntegrate", "weightedAverage"
|
||||||
|
};
|
||||||
|
|
||||||
const NamedEnum<fieldValues::faceSource::operationType, 4>
|
const NamedEnum<fieldValues::faceSource::operationType, 5>
|
||||||
fieldValues::faceSource::operationTypeNames_;
|
fieldValues::faceSource::operationTypeNames_;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -68,6 +71,8 @@ void Foam::fieldValues::faceSource::setFaceZoneFaces()
|
|||||||
if (zoneId < 0)
|
if (zoneId < 0)
|
||||||
{
|
{
|
||||||
FatalErrorIn("faceSource::faceSource::setFaceZoneFaces()")
|
FatalErrorIn("faceSource::faceSource::setFaceZoneFaces()")
|
||||||
|
<< type() << " " << name_ << ": "
|
||||||
|
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl
|
||||||
<< " Unknown face zone name: " << sourceName_
|
<< " Unknown face zone name: " << sourceName_
|
||||||
<< ". Valid face zones are: " << mesh().faceZones().names()
|
<< ". Valid face zones are: " << mesh().faceZones().names()
|
||||||
<< nl << exit(FatalError);
|
<< nl << exit(FatalError);
|
||||||
@ -164,6 +169,8 @@ void Foam::fieldValues::faceSource::setPatchFaces()
|
|||||||
if (patchId < 0)
|
if (patchId < 0)
|
||||||
{
|
{
|
||||||
FatalErrorIn("faceSource::constructFaceAddressing()")
|
FatalErrorIn("faceSource::constructFaceAddressing()")
|
||||||
|
<< type() << " " << name_ << ": "
|
||||||
|
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl
|
||||||
<< " Unknown patch name: " << sourceName_
|
<< " Unknown patch name: " << sourceName_
|
||||||
<< ". Valid patch names are: "
|
<< ". Valid patch names are: "
|
||||||
<< mesh().boundaryMesh().names() << nl
|
<< mesh().boundaryMesh().names() << nl
|
||||||
@ -197,7 +204,7 @@ void Foam::fieldValues::faceSource::setPatchFaces()
|
|||||||
|
|
||||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
void Foam::fieldValues::faceSource::initialise()
|
void Foam::fieldValues::faceSource::initialise(const dictionary& dict)
|
||||||
{
|
{
|
||||||
switch (source_)
|
switch (source_)
|
||||||
{
|
{
|
||||||
@ -214,15 +221,40 @@ void Foam::fieldValues::faceSource::initialise()
|
|||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
FatalErrorIn("faceSource::constructFaceAddressing()")
|
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);
|
<< sourceTypeNames_ << nl << exit(FatalError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Info<< type() << " " << name_ << ":" << nl
|
Info<< type() << " " << name_ << ":" << nl
|
||||||
<< " total faces = " << faceId_.size() << nl
|
<< " total faces = " << faceId_.size() << nl
|
||||||
<< " total area = " << sum(filterField(mesh().magSf()))
|
<< " total area = " << sum(filterField(mesh().magSf())) << nl;
|
||||||
<< nl << endl;
|
|
||||||
|
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_(),
|
faceId_(),
|
||||||
facePatchId_(),
|
facePatchId_(),
|
||||||
flipMap_(),
|
flipMap_(),
|
||||||
outputFilePtr_(NULL)
|
outputFilePtr_(NULL),
|
||||||
|
weightFieldName_("undefinedWeightedFieldName")
|
||||||
{
|
{
|
||||||
initialise();
|
|
||||||
|
|
||||||
if (active_)
|
if (active_)
|
||||||
{
|
{
|
||||||
|
initialise(dict);
|
||||||
|
|
||||||
// Create the output file if not already created
|
// Create the output file if not already created
|
||||||
makeFile();
|
makeFile();
|
||||||
}
|
}
|
||||||
@ -327,7 +360,7 @@ void Foam::fieldValues::faceSource::read(const dictionary& dict)
|
|||||||
if (active_)
|
if (active_)
|
||||||
{
|
{
|
||||||
fieldValue::read(dict);
|
fieldValue::read(dict);
|
||||||
initialise();
|
initialise(dict);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -39,7 +39,7 @@ Description
|
|||||||
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: faceZone, patch
|
||||||
sourceName f0;
|
sourceName f0;
|
||||||
operation sum; // none, sum, areaAverage, areaIntegrate
|
operation sum;
|
||||||
fields
|
fields
|
||||||
(
|
(
|
||||||
p
|
p
|
||||||
@ -48,6 +48,13 @@ Description
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
where operation is one of:
|
||||||
|
- none
|
||||||
|
- sum
|
||||||
|
- areaAverage
|
||||||
|
- areaIntegrate
|
||||||
|
- weightedAverage
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
faceSource.C
|
faceSource.C
|
||||||
|
|
||||||
@ -100,11 +107,12 @@ public:
|
|||||||
opNone,
|
opNone,
|
||||||
opSum,
|
opSum,
|
||||||
opAreaAverage,
|
opAreaAverage,
|
||||||
opAreaIntegrate
|
opAreaIntegrate,
|
||||||
|
opWeightedAverage
|
||||||
};
|
};
|
||||||
|
|
||||||
//- Operation type names
|
//- Operation type names
|
||||||
static const NamedEnum<operationType, 4> operationTypeNames_;
|
static const NamedEnum<operationType, 5> operationTypeNames_;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -143,11 +151,14 @@ protected:
|
|||||||
//- Output file pointer
|
//- Output file pointer
|
||||||
autoPtr<OFstream> outputFilePtr_;
|
autoPtr<OFstream> outputFilePtr_;
|
||||||
|
|
||||||
|
//- Weight field name - only used for opWeightedAverage mode
|
||||||
|
word weightFieldName_;
|
||||||
|
|
||||||
|
|
||||||
// Protected member functions
|
// Protected member functions
|
||||||
|
|
||||||
//- Initialise, e.g. face addressing
|
//- Initialise, e.g. face addressing
|
||||||
void initialise();
|
void initialise(const dictionary& dict);
|
||||||
|
|
||||||
//- Insert field values into values list
|
//- Insert field values into values list
|
||||||
template<class Type>
|
template<class Type>
|
||||||
|
|||||||
@ -129,6 +129,47 @@ Type Foam::fieldValues::faceSource::processValues
|
|||||||
result = sum(values*filterField(mesh().magSf()));
|
result = sum(values*filterField(mesh().magSf()));
|
||||||
break;
|
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:
|
default:
|
||||||
{
|
{
|
||||||
// Do nothing
|
// Do nothing
|
||||||
|
|||||||
@ -137,7 +137,7 @@ public:
|
|||||||
//- Return the output field values flag
|
//- Return the output field values flag
|
||||||
const Switch& valueOutput() const;
|
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;
|
const fvMesh& mesh() const;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user