mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: Added coefficient of variance (CoV) operation to fieldValues function objects
This commit is contained in:
@ -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_;
|
||||
|
||||
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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_;
|
||||
|
||||
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user