diff --git a/src/sampling/probes/patchProbesTemplates.C b/src/sampling/probes/patchProbesTemplates.C index 96363443cf..530e1a7698 100644 --- a/src/sampling/probes/patchProbesTemplates.C +++ b/src/sampling/probes/patchProbesTemplates.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -49,12 +50,18 @@ void Foam::patchProbes::sampleAndWrite << setw(w) << vField.time().timeOutputValue(); - forAll(values, probei) + for (const auto& v : values) { - probeStream << ' ' << setw(w) << values[probei]; + probeStream << ' ' << setw(w) << v; } probeStream << endl; } + + const word& fieldName = vField.name(); + this->setResult("average(" + fieldName + ")", average(values)); + this->setResult("min(" + fieldName + ")", min(values)); + this->setResult("max(" + fieldName + ")", max(values)); + this->setResult("size(" + fieldName + ")", values.size()); } @@ -75,12 +82,18 @@ void Foam::patchProbes::sampleAndWrite << setw(w) << sField.time().timeOutputValue(); - forAll(values, probei) + for (const auto& v : values) { - probeStream << ' ' << setw(w) << values[probei]; + probeStream << ' ' << setw(w) << v; } probeStream << endl; } + + const word& fieldName = sField.name(); + this->setResult("average(" + fieldName + ")", average(values)); + this->setResult("min(" + fieldName + ")", min(values)); + this->setResult("max(" + fieldName + ")", max(values)); + this->setResult("size(" + fieldName + ")", values.size()); } @@ -90,17 +103,19 @@ void Foam::patchProbes::sampleAndWrite const fieldGroup& fields ) { - forAll(fields, fieldi) + typedef GeometricField VolFieldType; + + for (const auto& fieldName : fields) { if (loadFromFiles_) { sampleAndWrite ( - GeometricField + VolFieldType ( IOobject ( - fields[fieldi], + fieldName, mesh_.time().timeName(), mesh_, IOobject::MUST_READ, @@ -113,23 +128,11 @@ void Foam::patchProbes::sampleAndWrite } else { - objectRegistry::const_iterator iter = mesh_.find(fields[fieldi]); + objectRegistry::const_iterator iter = mesh_.find(fieldName); - if - ( - iter.found() - && iter()->type() - == GeometricField::typeName - ) + if (iter.found() && iter()->type() == VolFieldType::typeName) { - sampleAndWrite - ( - mesh_.lookupObject - > - ( - fields[fieldi] - ) - ); + sampleAndWrite(mesh_.lookupObject(fieldName)); } } } @@ -142,17 +145,19 @@ void Foam::patchProbes::sampleAndWriteSurfaceFields const fieldGroup& fields ) { - forAll(fields, fieldi) + typedef GeometricField SurfaceFieldType; + + for (const auto& fieldName : fields) { if (loadFromFiles_) { sampleAndWrite ( - GeometricField + SurfaceFieldType ( IOobject ( - fields[fieldi], + fieldName, mesh_.time().timeName(), mesh_, IOobject::MUST_READ, @@ -165,23 +170,11 @@ void Foam::patchProbes::sampleAndWriteSurfaceFields } else { - objectRegistry::const_iterator iter = mesh_.find(fields[fieldi]); + objectRegistry::const_iterator iter = mesh_.find(fieldName); - if - ( - iter.found() - && iter()->type() - == GeometricField::typeName - ) + if (iter.found() && iter()->type() == SurfaceFieldType::typeName) { - sampleAndWrite - ( - mesh_.lookupObject - > - ( - fields[fieldi] - ) - ); + sampleAndWrite(mesh_.lookupObject(fieldName)); } } } @@ -199,12 +192,8 @@ Foam::patchProbes::sample { const Type unsetVal(-VGREAT*pTraits::one); - tmp> tValues - ( - new Field(this->size(), unsetVal) - ); - - Field& values = tValues.ref(); + auto tValues = tmp>::New(Field(this->size(), unsetVal)); + auto& values = tValues.ref(); const polyBoundaryMesh& patches = mesh_.boundaryMesh(); @@ -250,12 +239,8 @@ Foam::patchProbes::sample { const Type unsetVal(-VGREAT*pTraits::one); - tmp> tValues - ( - new Field(this->size(), unsetVal) - ); - - Field& values = tValues.ref(); + auto tValues = tmp>::New(Field(this->size(), unsetVal)); + auto& values = tValues.ref(); const polyBoundaryMesh& patches = mesh_.boundaryMesh(); diff --git a/src/sampling/probes/probesTemplates.C b/src/sampling/probes/probesTemplates.C index 720665b892..1ad0d4bd1a 100644 --- a/src/sampling/probes/probesTemplates.C +++ b/src/sampling/probes/probesTemplates.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -90,6 +90,12 @@ void Foam::probes::sampleAndWrite } os << endl; } + + const word& fieldName = vField.name(); + this->setResult("average(" + fieldName + ")", average(values)); + this->setResult("min(" + fieldName + ")", min(values)); + this->setResult("max(" + fieldName + ")", max(values)); + this->setResult("size(" + fieldName + ")", values.size()); } @@ -117,23 +123,31 @@ void Foam::probes::sampleAndWrite } os << endl; } + + const word& fieldName = sField.name(); + this->setResult("average(" + fieldName + ")", average(values)); + this->setResult("min(" + fieldName + ")", min(values)); + this->setResult("max(" + fieldName + ")", max(values)); + this->setResult("size(" + fieldName + ")", values.size()); } template void Foam::probes::sampleAndWrite(const fieldGroup& fields) { - forAll(fields, fieldi) + typedef GeometricField VolFieldType; + + for (const auto& fieldName : fields) { if (loadFromFiles_) { sampleAndWrite ( - GeometricField + VolFieldType ( IOobject ( - fields[fieldi], + fieldName, mesh_.time().timeName(), mesh_, IOobject::MUST_READ, @@ -146,23 +160,11 @@ void Foam::probes::sampleAndWrite(const fieldGroup& fields) } else { - objectRegistry::const_iterator iter = mesh_.find(fields[fieldi]); + objectRegistry::const_iterator iter = mesh_.find(fieldName); - if - ( - iter.found() - && iter()->type() - == GeometricField::typeName - ) + if (iter.found() && iter()->type() == VolFieldType::typeName) { - sampleAndWrite - ( - mesh_.lookupObject - > - ( - fields[fieldi] - ) - ); + sampleAndWrite(mesh_.lookupObject(fieldName)); } } } @@ -172,17 +174,19 @@ void Foam::probes::sampleAndWrite(const fieldGroup& fields) template void Foam::probes::sampleAndWriteSurfaceFields(const fieldGroup& fields) { - forAll(fields, fieldi) + typedef GeometricField SurfaceFieldType; + + for (const auto& fieldName : fields) { if (loadFromFiles_) { sampleAndWrite ( - GeometricField + SurfaceFieldType ( IOobject ( - fields[fieldi], + fieldName, mesh_.time().timeName(), mesh_, IOobject::MUST_READ, @@ -195,23 +199,11 @@ void Foam::probes::sampleAndWriteSurfaceFields(const fieldGroup& fields) } else { - objectRegistry::const_iterator iter = mesh_.find(fields[fieldi]); + objectRegistry::const_iterator iter = mesh_.find(fieldName); - if - ( - iter.found() - && iter()->type() - == GeometricField::typeName - ) + if (iter.found() && iter()->type() == SurfaceFieldType::typeName) { - sampleAndWrite - ( - mesh_.lookupObject - > - ( - fields[fieldi] - ) - ); + sampleAndWrite(mesh_.lookupObject(fieldName)); } } } @@ -228,12 +220,8 @@ Foam::probes::sample { const Type unsetVal(-VGREAT*pTraits::one); - tmp> tValues - ( - new Field(this->size(), unsetVal) - ); - - Field& values = tValues.ref(); + auto tValues = tmp>::New(Field(this->size(), unsetVal)); + auto& values = tValues.ref(); if (fixedLocations_) { @@ -298,12 +286,8 @@ Foam::probes::sample { const Type unsetVal(-VGREAT*pTraits::one); - tmp> tValues - ( - new Field(this->size(), unsetVal) - ); - - Field& values = tValues.ref(); + auto tValues = tmp>::New(Field(this->size(), unsetVal)); + auto& values = tValues.ref(); forAll(*this, probei) {