ENH: Added average option to fieldValueDelta function object

This commit is contained in:
andy
2013-01-16 16:39:14 +00:00
parent 89473d43dd
commit 55b083336c
3 changed files with 37 additions and 14 deletions

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation \\ / A nd | Copyright (C) 2012-2013 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -38,15 +38,16 @@ namespace Foam
template<> template<>
const char* const char*
NamedEnum<fieldValues::fieldValueDelta::operationType, 4>::names[] = NamedEnum<fieldValues::fieldValueDelta::operationType, 5>::names[] =
{ {
"add", "add",
"subtract", "subtract",
"min", "min",
"max" "max",
"average"
}; };
const NamedEnum<fieldValues::fieldValueDelta::operationType, 4> const NamedEnum<fieldValues::fieldValueDelta::operationType, 5>
fieldValues::fieldValueDelta::operationTypeNames_; fieldValues::fieldValueDelta::operationTypeNames_;
} }
@ -158,7 +159,7 @@ void Foam::fieldValues::fieldValueDelta::write()
if (log_) if (log_)
{ {
Info<< type() << " output:" << endl; Info<< type() << " " << name_ << " output:" << endl;
} }
bool found = false; bool found = false;
@ -179,10 +180,8 @@ void Foam::fieldValues::fieldValueDelta::write()
{ {
Info<< " none" << endl; Info<< " none" << endl;
} }
else
{ Info<< endl;
Info<< endl;
}
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation \\ / A nd | Copyright (C) 2012-2013 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -37,6 +37,8 @@ Description
{ {
type fieldValueDelta; type fieldValueDelta;
functionObjectLibs ("libfieldFunctionObjects.so"); functionObjectLibs ("libfieldFunctionObjects.so");
operation subtract;
fieldValue1 fieldValue1
{ {
... ...
@ -54,6 +56,15 @@ Description
type | type name: fieldValueDelta | yes | type | type name: fieldValueDelta | yes |
\endtable \endtable
\linebreak
The \c operation is one of:
\plaintable
add | add
subtract | subtract
min | minimum
max | maximum
average | average
\endplaintable
SeeAlso SeeAlso
Foam::fieldValue Foam::fieldValue
@ -92,11 +103,12 @@ public:
opAdd, opAdd,
opSubtract, opSubtract,
opMin, opMin,
opMax opMax,
opAverage
}; };
//- Operation type names //- Operation type names
static const NamedEnum<operationType, 4> operationTypeNames_; static const NamedEnum<operationType, 5> operationTypeNames_;
private: private:

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation \\ / A nd | Copyright (C) 2012-2013 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -25,6 +25,7 @@ License
#include "GeometricField.H" #include "GeometricField.H"
#include "volMesh.H" #include "volMesh.H"
#include "surfaceMesh.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -59,6 +60,11 @@ Type Foam::fieldValues::fieldValueDelta::applyOperation
result = max(value1, value2); result = max(value1, value2);
break; break;
} }
case opAverage:
{
result = 0.5*(value1 + value2);
break;
}
default: default:
{ {
FatalErrorIn FatalErrorIn
@ -83,6 +89,7 @@ template<class Type>
void Foam::fieldValues::fieldValueDelta::processFields(bool& found) void Foam::fieldValues::fieldValueDelta::processFields(bool& found)
{ {
typedef GeometricField<Type, fvPatchField, volMesh> vf; typedef GeometricField<Type, fvPatchField, volMesh> vf;
typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf;
const wordList& fields1 = source1Ptr_->fields(); const wordList& fields1 = source1Ptr_->fields();
@ -95,7 +102,12 @@ void Foam::fieldValues::fieldValueDelta::processFields(bool& found)
forAll(fields1, i) forAll(fields1, i)
{ {
const word& fieldName = fields1[i]; const word& fieldName = fields1[i];
if (obr_.foundObject<vf>(fieldName) && results2.found(fieldName))
if
(
(obr_.foundObject<vf>(fieldName) || obr_.foundObject<sf>(fieldName))
&& results2.found(fieldName)
)
{ {
results1.lookup(fieldName) >> r1; results1.lookup(fieldName) >> r1;
results2.lookup(fieldName) >> r2; results2.lookup(fieldName) >> r2;