#include "PostprocessOperationAverage.hpp" #include "dictionary.hpp" #include "fieldsDataBase.hpp" #include "operationFunctions.hpp" namespace pFlow::postprocessData { /// Constructs average processor and initializes result field based on input field type 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; } } 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 PostprocessOperationAverage::execute ( const std::vector>& weights, const regionField& volFactor ) { 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, volFactor, 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), volFactor, dbVol, weights, mask); } }, allField) ); } return true; } bool PostprocessOperationAverage::write(const fileSystem &parDir) const { 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(path); regPoints().write(os2Ptr_()); } std::visit ( [&](auto&& arg)->bool { return writeField(os2Ptr_(), ti.t(), arg, threshold()); }, fluctuation2FieldPtr_() ); return true; } 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_() ); } } // namespace pFlow::postprocessData