Skip to content
Snippets Groups Projects
Commit f17efd1b authored by Kutalmış Berçin's avatar Kutalmış Berçin Committed by Kutalmış Berçin
Browse files

WIP: fieldStatistics: introduce flag to process internal fields only

parent 97044901
No related branches found
No related tags found
No related merge requests found
......@@ -153,6 +153,8 @@ bool Foam::functionObjects::fieldStatistics::read(const dictionary& dict)
return false;
}
internal_ = dict.getOrDefault("internal", false);
mode_ = modeTypeNames_.getOrDefault("mode", dict, modeType::mdMag);
// Reset and reprepare the input field names
......
......@@ -52,6 +52,7 @@ Usage
// Optional entries
mode <word>;
internal <bool>;
// Inherited entries
...
......@@ -66,6 +67,8 @@ Usage
fields | List of operand fields | wordList | yes | -
statistics | List of operand statistics | wordList | yes | -
mode | Output format of the statistical results | word | no | magnitude
internal | Flag to use internal fields only in computing statistics <!--
--> | bool | no | false
\endtable
Available statistics of the operand field through the \c statistics entry:
......@@ -135,10 +138,10 @@ class fieldStatistics
//- Type-safe union for input field types
using variantInput = std::variant
<
volScalarField,
volVectorField,
volSymmTensorField,
volTensorField
scalarField,
vectorField,
symmTensorField,
tensorField
>;
//- Type-safe union for output data types
......@@ -163,6 +166,9 @@ class fieldStatistics
// Private Data
//- Flag to use internal fields only in computing statistics
bool internal_;
//- Output-format mode - only applicable for tensor ranks > 0
modeType mode_;
......@@ -193,7 +199,7 @@ class fieldStatistics
//- Return the arithmetic mean of the given input field
template<class T>
T calcMean(const VolumeField<T>& field);
T calcMean(const Field<T>& field);
// Dispersion statistics
......@@ -201,17 +207,23 @@ class fieldStatistics
//- Return the minimum value of the given input field
// Store the processor index, cell index and location of the minimum
template<class T>
T calcMin(const VolumeField<T>& field);
T calcMin(const Field<T>& field);
//- Return the maximum value of the given input field
// Store the processor index, cell index and location of the maximum
template<class T>
T calcMax(const VolumeField<T>& field);
T calcMax(const Field<T>& field);
//- Return the sample variance of the given input field
template<class T>
T calcVariance(const VolumeField<T>& field);
T calcVariance(const Field<T>& field);
//-
template<class GeoField>
tmp<Field<typename GeoField::value_type>> flatten
(
const GeoField& field
);
//- Output the file header information
void writeFileHeader(Ostream& os, const word& fieldName);
......
......@@ -30,6 +30,51 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class GeoField>
Foam::tmp<Foam::Field<typename GeoField::value_type>>
Foam::functionObjects::fieldStatistics::flatten(const GeoField& fld)
{
typedef typename GeoField::value_type value_type;
typedef Field<value_type> FieldType;
label n = fld.size();
if (!internal_)
{
for (const auto& pfld : fld.boundaryField())
{
if (!pfld.coupled())
{
n += pfld.size();
}
}
}
auto tflatFld = tmp<FieldType>::New(n);
auto& flatFld = tflatFld.ref();
// Insert internal values
SubList<value_type>(flatFld, fld.size(), 0) = fld.primitiveField();
if (!internal_)
{
// Insert boundary values
n = fld.size();
for (const auto& pfld : fld.boundaryField())
{
if (!pfld.coupled())
{
SubList<value_type>(flatFld, pfld.size(), n) = pfld;
n += pfld.size();
}
}
}
return tflatFld;
}
template<class Type>
bool Foam::functionObjects::fieldStatistics::calcStat(const word& fieldName)
{
......@@ -42,13 +87,16 @@ bool Foam::functionObjects::fieldStatistics::calcStat(const word& fieldName)
const VolFieldType& field = lookupObject<VolFieldType>(fieldName);
tmp<Field<Type>> tfld = flatten(field);
const Field<Type> fld = tfld.cref();
HashTable<variantOutput> result;
for (const auto& iter : statistics_.csorted())
{
const statistic& stat = iter.val();
// Assign a new entry, overwriting existing entries
result.set(stat.name_, stat.calc(field));
result.set(stat.name_, stat.calc(fld));
}
results_.set(fieldName, result);
......@@ -58,14 +106,14 @@ bool Foam::functionObjects::fieldStatistics::calcStat(const word& fieldName)
template<class T>
T Foam::functionObjects::fieldStatistics::calcMean(const VolumeField<T>& field)
T Foam::functionObjects::fieldStatistics::calcMean(const Field<T>& field)
{
return gAverage(field);
}
template<class T>
T Foam::functionObjects::fieldStatistics::calcMin(const VolumeField<T>& field)
T Foam::functionObjects::fieldStatistics::calcMin(const Field<T>& field)
{
const label proci = Pstream::myProcNo();
......@@ -81,24 +129,6 @@ T Foam::functionObjects::fieldStatistics::calcMin(const VolumeField<T>& field)
minVs[proci] = field[minId];
}
// Find min boundary field info
const auto& fieldBoundary = field.boundaryField();
forAll(fieldBoundary, patchi)
{
const Field<T>& fp = fieldBoundary[patchi];
if (fp.size())
{
minMaxIds = findMinMax(fp);
minId = minMaxIds.first();
if (minVs[proci] > fp[minId])
{
minVs[proci] = fp[minId];
}
}
}
// Collect info from all processors and output
Pstream::allGatherList(minVs);
......@@ -109,7 +139,7 @@ T Foam::functionObjects::fieldStatistics::calcMin(const VolumeField<T>& field)
template<class T>
T Foam::functionObjects::fieldStatistics::calcMax(const VolumeField<T>& field)
T Foam::functionObjects::fieldStatistics::calcMax(const Field<T>& field)
{
const label proci = Pstream::myProcNo();
......@@ -125,25 +155,6 @@ T Foam::functionObjects::fieldStatistics::calcMax(const VolumeField<T>& field)
maxVs[proci] = field[maxId];
}
// Find max boundary field info
const auto& fieldBoundary = field.boundaryField();
forAll(fieldBoundary, patchi)
{
const Field<T>& fp = fieldBoundary[patchi];
if (fp.size())
{
minMaxIds = findMinMax(fp);
maxId = minMaxIds.second();
if (maxVs[proci] < fp[maxId])
{
maxVs[proci] = fp[maxId];
}
}
}
// Collect info from all processors and output
Pstream::allGatherList(maxVs);
......@@ -156,7 +167,7 @@ T Foam::functionObjects::fieldStatistics::calcMax(const VolumeField<T>& field)
template<class T>
T Foam::functionObjects::fieldStatistics::calcVariance
(
const VolumeField<T>& field
const Field<T>& field
)
{
label n = field.size();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment