2025-04-15 21:30:54 +03:30
|
|
|
#include "PostprocessOperationAverage.hpp"
|
|
|
|
#include "dictionary.hpp"
|
|
|
|
#include "fieldsDataBase.hpp"
|
2025-04-18 15:32:53 +03:30
|
|
|
#include "operationFunctions.hpp"
|
2025-04-15 21:30:54 +03:30
|
|
|
|
2025-04-24 23:31:43 +03:30
|
|
|
namespace pFlow::postprocessData
|
|
|
|
{
|
|
|
|
|
2025-04-15 21:30:54 +03:30
|
|
|
/// Constructs average processor and initializes result field based on input field type
|
2025-04-24 23:31:43 +03:30
|
|
|
PostprocessOperationAverage::PostprocessOperationAverage
|
2025-04-15 21:30:54 +03:30
|
|
|
(
|
|
|
|
const dictionary &opDict,
|
|
|
|
const regionPoints ®Points,
|
|
|
|
fieldsDataBase &fieldsDB
|
|
|
|
)
|
|
|
|
:
|
|
|
|
postprocessOperation(opDict, regPoints, fieldsDB),
|
|
|
|
calculateFluctuation2_(opDict.getValOrSet<Logical>("fluctuation2", Logical(false)))
|
|
|
|
{
|
|
|
|
if( fieldType() == getTypeName<real>() )
|
|
|
|
{
|
|
|
|
processedRegFieldPtr_ = makeUnique<processedRegFieldType>(
|
|
|
|
regionField(processedFieldName(), regPoints, real(0)));
|
|
|
|
}
|
|
|
|
else if( fieldType() == getTypeName<realx3>() )
|
|
|
|
{
|
|
|
|
processedRegFieldPtr_ = makeUnique<processedRegFieldType>(
|
|
|
|
regionField(processedFieldName(), regPoints, realx3(0)));
|
|
|
|
}
|
|
|
|
else if( fieldType() == getTypeName<realx4>() )
|
|
|
|
{
|
|
|
|
processedRegFieldPtr_ = makeUnique<processedRegFieldType>(
|
|
|
|
regionField(processedFieldName(), regPoints, realx4(0)));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fatalErrorInFunction<<" in dictionary "<< opDict.globalName()
|
|
|
|
<< " field type is not supported for average operation"
|
|
|
|
<< " field type is "<< fieldType()
|
|
|
|
<< endl;
|
|
|
|
fatalExit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-04-24 23:31:43 +03:30
|
|
|
PostprocessOperationAverage::PostprocessOperationAverage
|
2025-04-15 21:30:54 +03:30
|
|
|
(
|
|
|
|
const dictionary &opDict,
|
|
|
|
const word &fieldName,
|
|
|
|
const word &phiName,
|
|
|
|
const word &includeName,
|
|
|
|
const regionPoints ®Points,
|
|
|
|
fieldsDataBase &fieldsDB
|
|
|
|
)
|
|
|
|
:
|
|
|
|
postprocessOperation(opDict, fieldName, phiName, includeName, regPoints, fieldsDB),
|
|
|
|
calculateFluctuation2_(opDict.getValOrSet<Logical>("fluctuation2", Logical(false)))
|
|
|
|
{
|
|
|
|
if( fieldType() == getTypeName<real>() )
|
|
|
|
{
|
|
|
|
processedRegFieldPtr_ = makeUnique<processedRegFieldType>(
|
|
|
|
regionField(processedFieldName(), regPoints, real(0)));
|
|
|
|
}
|
|
|
|
else if( fieldType() == getTypeName<realx3>() )
|
|
|
|
{
|
|
|
|
processedRegFieldPtr_ = makeUnique<processedRegFieldType>(
|
|
|
|
regionField(processedFieldName(), regPoints, realx3(0)));
|
|
|
|
}
|
|
|
|
else if( fieldType() == getTypeName<realx4>() )
|
|
|
|
{
|
|
|
|
processedRegFieldPtr_ = makeUnique<processedRegFieldType>(
|
|
|
|
regionField(processedFieldName(), regPoints, realx4(0)));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fatalErrorInFunction<<" in dictionary "<< opDict.globalName()
|
|
|
|
<< " field type is not supported for average operation"
|
|
|
|
<< " field type is "<< fieldType()
|
|
|
|
<< endl;
|
|
|
|
fatalExit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-04-24 14:08:17 +03:30
|
|
|
|
2025-04-15 21:30:54 +03:30
|
|
|
/// Performs weighted average of field values within each region
|
2025-04-24 23:31:43 +03:30
|
|
|
bool PostprocessOperationAverage::execute
|
2025-04-15 21:30:54 +03:30
|
|
|
(
|
2025-04-18 15:32:53 +03:30
|
|
|
const std::vector<span<real>>& weights,
|
|
|
|
const regionField<real>& volFactor
|
2025-04-15 21:30:54 +03:30
|
|
|
)
|
|
|
|
{
|
|
|
|
auto allField = database().updateFieldAll(fieldName());
|
|
|
|
auto phi = database().updateFieldReal(
|
|
|
|
phiFieldName());
|
|
|
|
|
|
|
|
auto mask = getMask();
|
|
|
|
word procName = processedFieldName();
|
|
|
|
const auto& regP = regPoints();
|
|
|
|
bool dbVol = divideByVolume();
|
|
|
|
|
|
|
|
processedRegFieldPtr_ = makeUnique<processedRegFieldType>
|
|
|
|
(
|
|
|
|
std::visit([&](auto&& field)->processedRegFieldType
|
|
|
|
{
|
|
|
|
return executeAverageOperation(
|
|
|
|
procName,
|
|
|
|
field,
|
2025-04-18 15:32:53 +03:30
|
|
|
volFactor,
|
2025-04-15 21:30:54 +03:30
|
|
|
dbVol,
|
|
|
|
weights,
|
|
|
|
phi,
|
|
|
|
mask);
|
|
|
|
},
|
|
|
|
allField)
|
|
|
|
);
|
|
|
|
|
2025-04-24 14:08:17 +03:30
|
|
|
if(calculateFluctuation2_())
|
2025-04-15 21:30:54 +03:30
|
|
|
{
|
|
|
|
auto& processedRegField = processedRegFieldPtr_();
|
|
|
|
fluctuation2FieldPtr_ = makeUnique<processedRegFieldType>
|
|
|
|
(
|
|
|
|
std::visit([&](auto& field)->processedRegFieldType
|
|
|
|
{
|
|
|
|
using T = typename std::decay_t<std::remove_reference_t< decltype(field)>>::valueType;
|
|
|
|
if constexpr( std::is_same_v<T,real> ||
|
|
|
|
std::is_same_v<T,realx3>||
|
|
|
|
std::is_same_v<T,realx4>)
|
|
|
|
{
|
|
|
|
return executeFluctuation2Operation(
|
|
|
|
procName,
|
|
|
|
field,
|
|
|
|
std::get<regionField<T>>(processedRegField),
|
2025-04-18 15:32:53 +03:30
|
|
|
volFactor,
|
2025-04-15 21:30:54 +03:30
|
|
|
dbVol,
|
|
|
|
weights,
|
|
|
|
mask);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
allField)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2025-04-24 14:08:17 +03:30
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2025-04-24 23:31:43 +03:30
|
|
|
bool PostprocessOperationAverage::write(const fileSystem &parDir) const
|
2025-04-24 14:08:17 +03:30
|
|
|
{
|
|
|
|
if(! postprocessOperation::write(parDir))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(!calculateFluctuation2_())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto ti = time().TimeInfo();
|
|
|
|
|
|
|
|
if(!os2Ptr_)
|
|
|
|
{
|
|
|
|
fileSystem path = parDir+(
|
|
|
|
processedFieldName()+"_prime2" + ".Start_" + ti.timeName());
|
|
|
|
os2Ptr_ = makeUnique<oFstream>(path);
|
|
|
|
|
|
|
|
regPoints().write(os2Ptr_());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::visit
|
|
|
|
(
|
|
|
|
[&](auto&& arg)->bool
|
|
|
|
{
|
|
|
|
return writeField(os2Ptr_(), ti.t(), arg, threshold());
|
|
|
|
},
|
|
|
|
fluctuation2FieldPtr_()
|
|
|
|
);
|
|
|
|
|
2025-04-15 21:30:54 +03:30
|
|
|
return true;
|
2025-04-24 23:31:43 +03:30
|
|
|
}
|
|
|
|
|
2025-07-01 18:18:53 +03:30
|
|
|
bool PostprocessOperationAverage::write(iOstream &os) const
|
|
|
|
{
|
|
|
|
if(! postprocessOperation::write(os))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(!calculateFluctuation2_())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
std::visit
|
|
|
|
(
|
|
|
|
[&](auto&& arg)->bool
|
|
|
|
{
|
|
|
|
return arg.writeFieldToVtk(os);
|
|
|
|
},
|
|
|
|
fluctuation2FieldPtr_()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2025-04-24 23:31:43 +03:30
|
|
|
} // namespace pFlow::postprocessData
|