ENH: Added sumDirection operation into faceSource function object

This commit is contained in:
andy
2013-01-16 16:38:37 +00:00
parent d4787dce18
commit 89473d43dd
6 changed files with 121 additions and 13 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -48,10 +48,11 @@ namespace Foam
template<>
const char* NamedEnum<fieldValues::faceSource::operationType, 11>::names[] =
const char* NamedEnum<fieldValues::faceSource::operationType, 12>::names[] =
{
"none",
"sum",
"sumDirection",
"average",
"weightedAverage",
"areaAverage",
@ -74,7 +75,7 @@ namespace Foam
const Foam::NamedEnum<Foam::fieldValues::faceSource::sourceType, 3>
Foam::fieldValues::faceSource::sourceTypeNames_;
const Foam::NamedEnum<Foam::fieldValues::faceSource::operationType, 11>
const Foam::NamedEnum<Foam::fieldValues::faceSource::operationType, 12>
Foam::fieldValues::faceSource::operationTypeNames_;
@ -486,6 +487,46 @@ void Foam::fieldValues::faceSource::writeFileHeader(const label i)
}
template<>
Foam::scalar Foam::fieldValues::faceSource::processValues
(
const Field<scalar>& values,
const vectorField& Sf,
const scalarField& weightField
) const
{
switch (operation_)
{
case opSumDirection:
{
const vector direction(dict_.lookup("direction"));
scalar v = 0.0;
forAll(Sf, i)
{
scalar d = Sf[i] & direction;
if (d > 0)
{
v += pos(values[i])*values[i];
}
else
{
v += neg(values[i])*values[i];
}
}
return v;
}
default:
{
// Fall through to other operations
return processSameTypeValues(values, Sf, weightField);
}
}
}
template<>
Foam::vector Foam::fieldValues::faceSource::processValues
(
@ -496,14 +537,35 @@ Foam::vector Foam::fieldValues::faceSource::processValues
{
switch (operation_)
{
case opSumDirection:
{
const vector direction(dict_.lookup("direction"));
vector v(vector::zero);
forAll(Sf, i)
{
scalar d = Sf[i] & direction;
if (d > 0)
{
v += pos(values[i] & direction)*values[i];
}
else
{
v += neg(values[i] & direction)*values[i];
}
}
return v;
}
case opAreaNormalAverage:
{
scalar result = sum(values&Sf)/sum(mag(Sf));
scalar result = sum(values & Sf)/sum(mag(Sf));
return vector(result, 0.0, 0.0);
}
case opAreaNormalIntegrate:
{
scalar result = sum(values&Sf);
scalar result = sum(values & Sf);
return vector(result, 0.0, 0.0);
}
default:

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -87,6 +87,7 @@ Description
\plaintable
none | no operation
sum | sum
sumDirection | sum values which are positive in given direction
average | ensemble average
weightedAverage | weighted average
areaAverage | area weighted average
@ -176,6 +177,7 @@ public:
{
opNone,
opSum,
opSumDirection,
opAverage,
opWeightedAverage,
opAreaAverage,
@ -188,7 +190,7 @@ public:
};
//- Operation type names
static const NamedEnum<operationType, 11> operationTypeNames_;
static const NamedEnum<operationType, 12> operationTypeNames_;
private:
@ -366,8 +368,17 @@ public:
};
//- Specialisation of processing vectors for opAreaNormalAverage,
// opAreaNormalIntegrate (use inproduct - dimension reducing operation)
//- Specialisation of processing scalars
template<>
scalar faceSource::processValues
(
const Field<scalar>& values,
const vectorField& Sf,
const scalarField& weightField
) const;
//- Specialisation of processing vectors
template<>
vector faceSource::processValues
(

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -141,6 +141,26 @@ Type Foam::fieldValues::faceSource::processSameTypeValues
result = sum(values);
break;
}
case opSumDirection:
{
FatalErrorIn
(
"template<class Type>"
"Type Foam::fieldValues::faceSource::processSameTypeValues"
"("
"const Field<Type>&, "
"const vectorField&, "
"const scalarField&"
") const"
)
<< "Operation " << operationTypeNames_[operation_]
<< " not available for values of type "
<< pTraits<Type>::typeName
<< exit(FatalError);
result = pTraits<Type>::zero;
break;
}
case opAverage:
{
result = sum(values)/values.size();

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -43,6 +43,8 @@ void Foam::fieldValue::read(const dictionary& dict)
{
if (active_)
{
dict_ = dict;
log_ = dict.lookupOrDefault<Switch>("log", false);
dict.lookup("fields") >> fields_;
dict.lookup("valueOutput") >> valueOutput_;
@ -78,6 +80,7 @@ Foam::fieldValue::fieldValue
functionObjectFile(obr, name, valueType),
name_(name),
obr_(obr),
dict_(dict),
active_(true),
log_(false),
sourceName_(dict.lookupOrDefault<word>("sourceName", "sampledSurface")),

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -75,6 +75,9 @@ protected:
//- Database this class is registered to
const objectRegistry& obr_;
//- Construction dictionary
dictionary dict_;
//- Active flag
bool active_;
@ -149,6 +152,9 @@ public:
//- Return the reference to the object registry
inline const objectRegistry& obr() const;
//- Return the reference to the construction dictionary
inline const dictionary& dict() const;
//- Return the active flag
inline bool active() const;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -40,6 +40,12 @@ inline const Foam::objectRegistry& Foam::fieldValue::obr() const
}
inline const Foam::dictionary& Foam::fieldValue::dict() const
{
return dict_;
}
inline bool Foam::fieldValue::active() const
{
return active_;