diff --git a/src/functionObjects/field/mapFields/mapFields.C b/src/functionObjects/field/mapFields/mapFields.C index 656274f73c..522d31b449 100644 --- a/src/functionObjects/field/mapFields/mapFields.C +++ b/src/functionObjects/field/mapFields/mapFields.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -66,10 +66,12 @@ void Foam::functionObjects::mapFields::createInterpolation ( mapRegionName, meshTarget.time().constant(), - meshTarget.time() - ) + meshTarget.time(), + IOobject::MUST_READ + ) ) ); + const fvMesh& mapRegion = mapRegionPtr_(); const word mapMethodName(dict.get("mapMethod")); if (!meshToMesh::interpolationMethodNames_.found(mapMethodName)) @@ -161,11 +163,15 @@ Foam::functionObjects::mapFields::mapFields bool Foam::functionObjects::mapFields::read(const dictionary& dict) { - fvMeshFunctionObject::read(dict); + if (fvMeshFunctionObject::read(dict)) + { + dict.readEntry("fields", fieldNames_); + createInterpolation(dict); - dict.readEntry("fields", fieldNames_); - createInterpolation(dict); - return true; + return true; + } + + return false; } diff --git a/src/functionObjects/field/mapFields/mapFieldsTemplates.C b/src/functionObjects/field/mapFields/mapFieldsTemplates.C index 792dff4e59..baacbd84c6 100644 --- a/src/functionObjects/field/mapFields/mapFieldsTemplates.C +++ b/src/functionObjects/field/mapFields/mapFieldsTemplates.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -123,29 +123,41 @@ bool Foam::functionObjects::mapFields::writeFieldType() const wordList fieldNames(this->mesh_.names(VolFieldType::typeName)); labelList selected = findStrings(fieldNames_, fieldNames); - forAll(selected, i) + for (const label fieldi : selected) { - const word& fieldName = fieldNames[selected[i]]; + const word& fieldName = fieldNames[fieldi]; const VolFieldType& field = lookupObject(fieldName); - Log << " " << fieldName; + if (!mapRegion.foundObject(fieldName)) + { + VolFieldType* tmappedField = + new VolFieldType + ( + IOobject + ( + fieldName, + time_.timeName(), + mapRegion, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mapRegion, + dimensioned(field.dimensions(), Zero) + ); - IOobject mapRegionIO - ( - fieldName, - time_.timeName(), - mapRegion - ); + tmappedField->store(); + } - tmp tfieldMapRegion(interpPtr_->mapTgtToSrc(field)); + VolFieldType& mappedField = + mapRegion.lookupObjectRef(fieldName); - Log << ": interpolated"; + mappedField = interpPtr_->mapTgtToSrc(field); - VolFieldType fieldMapRegion(mapRegionIO, tfieldMapRegion); + Log << " " << fieldName << ": interpolated"; - evaluateConstraintTypes(fieldMapRegion); + evaluateConstraintTypes(mappedField); - fieldMapRegion.write(); + mappedField.write(); Log << " and written" << nl; }