ENH: mapFields FO - mapping now on call to execute

This commit is contained in:
Andrew Heather
2019-09-12 10:40:19 +01:00
parent df2db077cf
commit 35d77aaec0
3 changed files with 50 additions and 6 deletions

View File

@ -177,6 +177,25 @@ bool Foam::functionObjects::mapFields::read(const dictionary& dict)
bool Foam::functionObjects::mapFields::execute() bool Foam::functionObjects::mapFields::execute()
{ {
Log << type() << " " << name() << " execute:" << nl;
bool ok = false;
ok = mapFieldType<scalar>() || ok;
ok = mapFieldType<vector>() || ok;
ok = mapFieldType<sphericalTensor>() || ok;
ok = mapFieldType<symmTensor>() || ok;
ok = mapFieldType<tensor>() || ok;
if (log)
{
if (!ok)
{
Info<< " none" << nl;
}
Info<< endl;
}
return true; return true;
} }

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-2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -119,7 +119,11 @@ class mapFields
GeometricField<Type, fvPatchField, volMesh>& fld GeometricField<Type, fvPatchField, volMesh>& fld
) const; ) const;
//- Helper function to interpolate and write the field //- Helper function to map the \<Type\> fields
template<class Type>
bool mapFieldType() const;
//- Helper function to write the \<Type\> fields
template<class Type> template<class Type>
bool writeFieldType() const; bool writeFieldType() const;

View File

@ -115,14 +115,14 @@ void Foam::functionObjects::mapFields::evaluateConstraintTypes
template<class Type> template<class Type>
bool Foam::functionObjects::mapFields::writeFieldType() const bool Foam::functionObjects::mapFields::mapFieldType() const
{ {
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType; typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
const fvMesh& mapRegion = mapRegionPtr_(); const fvMesh& mapRegion = mapRegionPtr_();
wordList fieldNames(this->mesh_.names(VolFieldType::typeName)); wordList fieldNames(this->mesh_.names(VolFieldType::typeName));
labelList selected = findStrings(fieldNames_, fieldNames); const labelList selected = findStrings(fieldNames_, fieldNames);
for (const label fieldi : selected) for (const label fieldi : selected)
{ {
const word& fieldName = fieldNames[fieldi]; const word& fieldName = fieldNames[fieldi];
@ -149,17 +149,38 @@ bool Foam::functionObjects::mapFields::writeFieldType() const
} }
VolFieldType& mappedField = VolFieldType& mappedField =
mapRegion.lookupObjectRef<VolFieldType>(fieldName); mapRegion.template lookupObjectRef<VolFieldType>(fieldName);
mappedField = interpPtr_->mapTgtToSrc(field); mappedField = interpPtr_->mapTgtToSrc(field);
Log << " " << fieldName << ": interpolated"; Log << " " << fieldName << ": interpolated";
evaluateConstraintTypes(mappedField); evaluateConstraintTypes(mappedField);
}
return selected.size() > 0;
}
template<class Type>
bool Foam::functionObjects::mapFields::writeFieldType() const
{
typedef GeometricField<Type, fvPatchField, volMesh> 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<VolFieldType>(fieldName);
mappedField.write(); mappedField.write();
Log << " and written" << nl; Log << " " << fieldName << ": written";
} }
return selected.size() > 0; return selected.size() > 0;