From 35d77aaec049a9afdeafc2b8835b894b9c4bbcd7 Mon Sep 17 00:00:00 2001 From: Andrew Heather <> Date: Thu, 12 Sep 2019 10:40:19 +0100 Subject: [PATCH] ENH: mapFields FO - mapping now on call to execute --- .../field/mapFields/mapFields.C | 19 ++++++++++++ .../field/mapFields/mapFields.H | 8 +++-- .../field/mapFields/mapFieldsTemplates.C | 29 ++++++++++++++++--- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/src/functionObjects/field/mapFields/mapFields.C b/src/functionObjects/field/mapFields/mapFields.C index 522d31b449..3e54d471d5 100644 --- a/src/functionObjects/field/mapFields/mapFields.C +++ b/src/functionObjects/field/mapFields/mapFields.C @@ -177,6 +177,25 @@ bool Foam::functionObjects::mapFields::read(const dictionary& dict) bool Foam::functionObjects::mapFields::execute() { + Log << type() << " " << name() << " execute:" << nl; + + bool ok = false; + + ok = mapFieldType() || ok; + ok = mapFieldType() || ok; + ok = mapFieldType() || ok; + ok = mapFieldType() || ok; + ok = mapFieldType() || ok; + + if (log) + { + if (!ok) + { + Info<< " none" << nl; + } + + Info<< endl; + } return true; } diff --git a/src/functionObjects/field/mapFields/mapFields.H b/src/functionObjects/field/mapFields/mapFields.H index 4d80b1baa7..ea43f0bf64 100644 --- a/src/functionObjects/field/mapFields/mapFields.H +++ b/src/functionObjects/field/mapFields/mapFields.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -119,7 +119,11 @@ class mapFields GeometricField& fld ) const; - //- Helper function to interpolate and write the field + //- Helper function to map the \ fields + template + bool mapFieldType() const; + + //- Helper function to write the \ fields template bool writeFieldType() const; diff --git a/src/functionObjects/field/mapFields/mapFieldsTemplates.C b/src/functionObjects/field/mapFields/mapFieldsTemplates.C index baacbd84c6..187e50ed3e 100644 --- a/src/functionObjects/field/mapFields/mapFieldsTemplates.C +++ b/src/functionObjects/field/mapFields/mapFieldsTemplates.C @@ -115,14 +115,14 @@ void Foam::functionObjects::mapFields::evaluateConstraintTypes template -bool Foam::functionObjects::mapFields::writeFieldType() const +bool Foam::functionObjects::mapFields::mapFieldType() const { typedef GeometricField VolFieldType; const fvMesh& mapRegion = mapRegionPtr_(); wordList fieldNames(this->mesh_.names(VolFieldType::typeName)); - labelList selected = findStrings(fieldNames_, fieldNames); + const labelList selected = findStrings(fieldNames_, fieldNames); for (const label fieldi : selected) { const word& fieldName = fieldNames[fieldi]; @@ -149,17 +149,38 @@ bool Foam::functionObjects::mapFields::writeFieldType() const } VolFieldType& mappedField = - mapRegion.lookupObjectRef(fieldName); + mapRegion.template lookupObjectRef(fieldName); mappedField = interpPtr_->mapTgtToSrc(field); Log << " " << fieldName << ": interpolated"; evaluateConstraintTypes(mappedField); + } + + return selected.size() > 0; +} + + +template +bool Foam::functionObjects::mapFields::writeFieldType() const +{ + typedef GeometricField VolFieldType; + + const fvMesh& mapRegion = mapRegionPtr_(); + + wordList fieldNames(this->mesh_.names(VolFieldType::typeName)); + const labelList selected = findStrings(fieldNames_, fieldNames); + for (const label fieldi : selected) + { + const word& fieldName = fieldNames[fieldi]; + + const VolFieldType& mappedField = + mapRegion.template lookupObject(fieldName); mappedField.write(); - Log << " and written" << nl; + Log << " " << fieldName << ": written"; } return selected.size() > 0;