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

View File

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

View File

@ -115,6 +115,23 @@ Type Foam::fieldValues::cellSource::processValues
result = max(values);
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:
{
// Do nothing

View File

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

View File

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

View File

@ -134,6 +134,25 @@ Type Foam::fieldValues::faceSource::processValues
result = max(values);
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:
{
// Do nothing