ENH: Added coefficient of variance (CoV) operation to fieldValues function objects

This commit is contained in:
andy
2011-11-21 14:00:18 +00:00
parent 9dd55c02cb
commit 49b0676573
6 changed files with 52 additions and 10 deletions

View File

@ -50,7 +50,7 @@ namespace Foam
const char* Foam::NamedEnum const char* Foam::NamedEnum
< <
Foam::fieldValues::cellSource::operationType, Foam::fieldValues::cellSource::operationType,
7 8
>::names[] = >::names[] =
{ {
"none", "none",
@ -59,7 +59,8 @@ namespace Foam
"volIntegrate", "volIntegrate",
"weightedAverage", "weightedAverage",
"min", "min",
"max" "max",
"CoV"
}; };
} }
@ -67,7 +68,7 @@ namespace Foam
const Foam::NamedEnum<Foam::fieldValues::cellSource::sourceType, 2> const Foam::NamedEnum<Foam::fieldValues::cellSource::sourceType, 2>
Foam::fieldValues::cellSource::sourceTypeNames_; Foam::fieldValues::cellSource::sourceTypeNames_;
const Foam::NamedEnum<Foam::fieldValues::cellSource::operationType, 7> const Foam::NamedEnum<Foam::fieldValues::cellSource::operationType, 8>
Foam::fieldValues::cellSource::operationTypeNames_; Foam::fieldValues::cellSource::operationTypeNames_;

View File

@ -52,6 +52,7 @@ Description
- volAverage - volAverage
- volIntegrate - volIntegrate
- weightedAverage - weightedAverage
- CoV (Coefficient of variation: standard deviation/mean)
SourceFiles SourceFiles
cellSource.C cellSource.C
@ -106,11 +107,12 @@ public:
opVolIntegrate, opVolIntegrate,
opWeightedAverage, opWeightedAverage,
opMin, opMin,
opMax opMax,
opCoV
}; };
//- Operation type names //- Operation type names
static const NamedEnum<operationType, 7> operationTypeNames_; static const NamedEnum<operationType, 8> operationTypeNames_;
private: private:

View File

@ -115,6 +115,23 @@ Type Foam::fieldValues::cellSource::processValues
result = max(values); result = max(values);
break; break;
} }
case opCoV:
{
Type meanValue = sum(values*V)/sum(V);
const label nComp = pTraits<Type>::nComponents;
for (direction d=0; d<nComp; ++d)
{
scalarField vals(values.component(d));
scalar mean = component(meanValue, d);
scalar& res = setComponent(result, d);
res = sqrt(sum(V*sqr(vals - mean))/(V.size()*sum(V)))/mean;
}
break;
}
default: default:
{ {
// Do nothing // Do nothing

View File

@ -53,7 +53,7 @@ namespace Foam
const char* Foam::NamedEnum const char* Foam::NamedEnum
< <
Foam::fieldValues::faceSource::operationType, Foam::fieldValues::faceSource::operationType,
7 8
>::names[] = >::names[] =
{ {
"none", "none",
@ -62,7 +62,8 @@ namespace Foam
"areaIntegrate", "areaIntegrate",
"weightedAverage", "weightedAverage",
"min", "min",
"max" "max",
"CoV"
}; };
} }
@ -71,7 +72,7 @@ namespace Foam
const Foam::NamedEnum<Foam::fieldValues::faceSource::sourceType, 3> const Foam::NamedEnum<Foam::fieldValues::faceSource::sourceType, 3>
Foam::fieldValues::faceSource::sourceTypeNames_; Foam::fieldValues::faceSource::sourceTypeNames_;
const Foam::NamedEnum<Foam::fieldValues::faceSource::operationType, 7> const Foam::NamedEnum<Foam::fieldValues::faceSource::operationType, 8>
Foam::fieldValues::faceSource::operationTypeNames_; Foam::fieldValues::faceSource::operationTypeNames_;

View File

@ -62,6 +62,7 @@ Description
- weightedAverage - weightedAverage
- min - min
- max - max
- CoV (Coefficient of variation: standard deviation/mean)
Notes: Notes:
- faces on empty patches get ignored - faces on empty patches get ignored
@ -132,11 +133,12 @@ public:
opAreaIntegrate, opAreaIntegrate,
opWeightedAverage, opWeightedAverage,
opMin, opMin,
opMax opMax,
opCoV
}; };
//- Operation type names //- Operation type names
static const NamedEnum<operationType, 7> operationTypeNames_; static const NamedEnum<operationType, 8> operationTypeNames_;
private: private:

View File

@ -134,6 +134,25 @@ Type Foam::fieldValues::faceSource::processValues
result = max(values); result = max(values);
break; break;
} }
case opCoV:
{
Type meanValue = sum(values*magSf)/sum(magSf);
const label nComp = pTraits<Type>::nComponents;
for (direction d=0; d<nComp; ++d)
{
scalarField vals(values.component(d));
scalar mean = component(meanValue, d);
scalar& res = setComponent(result, d);
res =
sqrt(sum(magSf*sqr(vals - mean))/(magSf.size()*sum(magSf)))
/mean;
}
break;
}
default: default:
{ {
// Do nothing // Do nothing