#include "PostprocessOperationAverage.hpp" #include "dictionary.hpp" #include "fieldsDataBase.hpp" #include "fieldFunctions.hpp" /// Constructs average processor and initializes result field based on input field type pFlow::PostprocessOperationAverage::PostprocessOperationAverage ( const dictionary &opDict, const regionPoints ®Points, fieldsDataBase &fieldsDB ) : postprocessOperation(opDict, regPoints, fieldsDB), calculateFluctuation2_(opDict.getValOrSet("fluctuation2", Logical(false))) { if( fieldType() == getTypeName() ) { processedRegFieldPtr_ = makeUnique( regionField(processedFieldName(), regPoints, real(0))); } else if( fieldType() == getTypeName() ) { processedRegFieldPtr_ = makeUnique( regionField(processedFieldName(), regPoints, realx3(0))); } else if( fieldType() == getTypeName() ) { processedRegFieldPtr_ = makeUnique( 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; } } pFlow::PostprocessOperationAverage::PostprocessOperationAverage ( 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("fluctuation2", Logical(false))) { if( fieldType() == getTypeName() ) { processedRegFieldPtr_ = makeUnique( regionField(processedFieldName(), regPoints, real(0))); } else if( fieldType() == getTypeName() ) { processedRegFieldPtr_ = makeUnique( regionField(processedFieldName(), regPoints, realx3(0))); } else if( fieldType() == getTypeName() ) { processedRegFieldPtr_ = makeUnique( 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; } } /// Performs weighted average of field values within each region bool pFlow::PostprocessOperationAverage::execute ( const std::vector>& weights ) { 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 ( std::visit([&](auto&& field)->processedRegFieldType { return executeAverageOperation( procName, field, regP, dbVol, weights, phi, mask); }, allField) ); if(calculateFluctuation2_) { auto& processedRegField = processedRegFieldPtr_(); fluctuation2FieldPtr_ = makeUnique ( std::visit([&](auto& field)->processedRegFieldType { using T = typename std::decay_t>::valueType; if constexpr( std::is_same_v || std::is_same_v|| std::is_same_v) { return executeFluctuation2Operation( procName, field, std::get>(processedRegField), dbVol, weights, mask); } }, allField) ); } return true; }