ENH: mapFields FO - read schemes and cache mapped fields by default. See #1390

This commit is contained in:
Andrew Heather
2019-08-05 09:48:25 +01:00
parent ef9bb4ae16
commit 492c30c34e
2 changed files with 40 additions and 22 deletions

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -66,10 +66,12 @@ void Foam::functionObjects::mapFields::createInterpolation
( (
mapRegionName, mapRegionName,
meshTarget.time().constant(), meshTarget.time().constant(),
meshTarget.time() meshTarget.time(),
) IOobject::MUST_READ
)
) )
); );
const fvMesh& mapRegion = mapRegionPtr_(); const fvMesh& mapRegion = mapRegionPtr_();
const word mapMethodName(dict.get<word>("mapMethod")); const word mapMethodName(dict.get<word>("mapMethod"));
if (!meshToMesh::interpolationMethodNames_.found(mapMethodName)) if (!meshToMesh::interpolationMethodNames_.found(mapMethodName))
@ -161,11 +163,15 @@ Foam::functionObjects::mapFields::mapFields
bool Foam::functionObjects::mapFields::read(const dictionary& dict) 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_); return true;
createInterpolation(dict); }
return true;
return false;
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -123,29 +123,41 @@ bool Foam::functionObjects::mapFields::writeFieldType() const
wordList fieldNames(this->mesh_.names(VolFieldType::typeName)); wordList fieldNames(this->mesh_.names(VolFieldType::typeName));
labelList selected = findStrings(fieldNames_, fieldNames); 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<VolFieldType>(fieldName); const VolFieldType& field = lookupObject<VolFieldType>(fieldName);
Log << " " << fieldName; if (!mapRegion.foundObject<VolFieldType>(fieldName))
{
VolFieldType* tmappedField =
new VolFieldType
(
IOobject
(
fieldName,
time_.timeName(),
mapRegion,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mapRegion,
dimensioned<Type>(field.dimensions(), Zero)
);
IOobject mapRegionIO tmappedField->store();
( }
fieldName,
time_.timeName(),
mapRegion
);
tmp<VolFieldType> tfieldMapRegion(interpPtr_->mapTgtToSrc(field)); VolFieldType& mappedField =
mapRegion.lookupObjectRef<VolFieldType>(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; Log << " and written" << nl;
} }