From 9952d06d168ba0edb5630e922fec73a9d4aed8b4 Mon Sep 17 00:00:00 2001 From: Henry <Henry> Date: Thu, 5 Feb 2015 12:09:34 +0000 Subject: [PATCH] mapFields: Minimum hack provided by Mattijs to get mapFields working again This version is very inefficient in parallel and does not provide the -parallelSource or -parallelTarget options which will need to be reinstanted in the future or we could revert mapFields to the OpenFOAM-2.2 version. --- .../preProcessing/mapFields/mapFields.C | 64 ++------- .../meshToMesh/meshToMeshTemplates.C | 61 ++++++++- .../meshToMesh/weightedFvPatchFieldMapper.H | 122 ++++++++++++++++++ 3 files changed, 188 insertions(+), 59 deletions(-) create mode 100644 src/sampling/meshToMeshInterpolation/meshToMesh/weightedFvPatchFieldMapper.H diff --git a/applications/utilities/preProcessing/mapFields/mapFields.C b/applications/utilities/preProcessing/mapFields/mapFields.C index 5a293d79708..891c14a4f12 100644 --- a/applications/utilities/preProcessing/mapFields/mapFields.C +++ b/applications/utilities/preProcessing/mapFields/mapFields.C @@ -41,8 +41,7 @@ void mapConsistentMesh ( const fvMesh& meshSource, const fvMesh& meshTarget, - const word& mapMethod, - const word& AMIMapMethod, + const meshToMesh::interpolationMethod& mapMethod, const bool subtract, const HashSet<word>& selectedFields, const bool noLagrangian @@ -51,7 +50,7 @@ void mapConsistentMesh Info<< nl << "Consistently creating and mapping fields for time " << meshSource.time().timeName() << nl << endl; - meshToMesh interp(meshSource, meshTarget, mapMethod, AMIMapMethod); + meshToMesh interp(meshSource, meshTarget, mapMethod); if (subtract) { @@ -80,8 +79,7 @@ void mapSubMesh const fvMesh& meshTarget, const HashTable<word>& patchMap, const wordList& cuttingPatches, - const word& mapMethod, - const word& AMIMapMethod, + const meshToMesh::interpolationMethod& mapMethod, const bool subtract, const HashSet<word>& selectedFields, const bool noLagrangian @@ -95,7 +93,6 @@ void mapSubMesh meshSource, meshTarget, mapMethod, - AMIMapMethod, patchMap, cuttingPatches ); @@ -187,13 +184,7 @@ int main(int argc, char *argv[]) ( "mapMethod", "word", - "specify the mapping method (direct|mapNearest|cellVolumeWeight)" - ); - argList::addOption - ( - "patchMapMethod", - "word", - "specify the patch mapping method (direct|mapNearest|faceAreaWeight)" + "specify the mapping method" ); argList::addBoolOption ( @@ -240,50 +231,17 @@ int main(int argc, char *argv[]) const bool consistent = args.optionFound("consistent"); + meshToMesh::interpolationMethod mapMethod = + meshToMesh::imCellVolumeWeight; - word mapMethod = meshToMesh::interpolationMethodNames_ - [ - meshToMesh::imCellVolumeWeight - ]; - - if (args.optionReadIfPresent("mapMethod", mapMethod)) + if (args.optionFound("mapMethod")) { - Info<< "Mapping method: " << mapMethod << endl; - } + mapMethod = meshToMesh::interpolationMethodNames_[args["mapMethod"]]; - - word patchMapMethod; - if (meshToMesh::interpolationMethodNames_.found(mapMethod)) - { - // Lookup corresponding AMI method - meshToMesh::interpolationMethod method = - meshToMesh::interpolationMethodNames_[mapMethod]; - - patchMapMethod = AMIPatchToPatchInterpolation::interpolationMethodToWord - ( - meshToMesh::interpolationMethodAMI(method) - ); + Info<< "Mapping method: " + << meshToMesh::interpolationMethodNames_[mapMethod] << endl; } - // Optionally override - if (args.optionFound("patchMapMethod")) - { - patchMapMethod = args["patchMapMethod"]; - - Info<< "Patch mapping method: " << patchMapMethod << endl; - } - - - if (patchMapMethod.empty()) - { - FatalErrorIn(args.executable()) - << "No valid patchMapMethod for method " << mapMethod - << ". Please supply one through the 'patchMapMethod' option" - << exit(FatalError); - } - - - const bool subtract = args.optionFound("subtract"); if (subtract) { @@ -356,7 +314,6 @@ int main(int argc, char *argv[]) meshSource, meshTarget, mapMethod, - patchMapMethod, subtract, selectedFields, noLagrangian @@ -371,7 +328,6 @@ int main(int argc, char *argv[]) patchMap, addProcessorPatches(meshTarget, cuttingPatches), mapMethod, - patchMapMethod, subtract, selectedFields, noLagrangian diff --git a/src/sampling/meshToMeshInterpolation/meshToMesh/meshToMeshTemplates.C b/src/sampling/meshToMeshInterpolation/meshToMesh/meshToMeshTemplates.C index c5e1f669d6b..155fc817ba1 100644 --- a/src/sampling/meshToMeshInterpolation/meshToMesh/meshToMeshTemplates.C +++ b/src/sampling/meshToMeshInterpolation/meshToMesh/meshToMeshTemplates.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2012-2014 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2015 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -27,6 +27,7 @@ License #include "volFields.H" #include "directFvPatchFieldMapper.H" #include "calculatedFvPatchField.H" +#include "weightedFvPatchFieldMapper.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -347,8 +348,33 @@ void Foam::meshToMesh::mapSrcToTgt label srcPatchI = srcPatchID_[i]; label tgtPatchI = tgtPatchID_[i]; - const Field<Type>& srcField = field.boundaryField()[srcPatchI]; - Field<Type>& tgtField = result.boundaryField()[tgtPatchI]; + const fvPatchField<Type>& srcField = field.boundaryField()[srcPatchI]; + fvPatchField<Type>& tgtField = result.boundaryField()[tgtPatchI]; + + // 2.3 does not do distributed mapping yet so only do if + // running on single processor + if (AMIList[i].singlePatchProc() != -1) + { + // Clone and map (since rmap does not do general mapping) + tmp<fvPatchField<Type> > tnewTgt + ( + fvPatchField<Type>::New + ( + srcField, + tgtField.patch(), + result.dimensionedInternalField(), + weightedFvPatchFieldMapper + ( + AMIList[i].tgtAddress(), + AMIList[i].tgtWeights() + ) + ) + ); + + // Transfer all mapped quantities (value and e.g. gradient) onto + // tgtField. Value will get overwritten below. + tgtField.rmap(tnewTgt(), identity(tgtField.size())); + } tgtField = pTraits<Type>::zero; @@ -511,8 +537,33 @@ void Foam::meshToMesh::mapTgtToSrc label srcPatchI = srcPatchID_[i]; label tgtPatchI = tgtPatchID_[i]; - Field<Type>& srcField = result.boundaryField()[srcPatchI]; - const Field<Type>& tgtField = field.boundaryField()[tgtPatchI]; + fvPatchField<Type>& srcField = result.boundaryField()[srcPatchI]; + const fvPatchField<Type>& tgtField = field.boundaryField()[tgtPatchI]; + + // 2.3 does not do distributed mapping yet so only do if + // running on single processor + if (AMIList[i].singlePatchProc() != -1) + { + // Clone and map (since rmap does not do general mapping) + tmp<fvPatchField<Type> > tnewSrc + ( + fvPatchField<Type>::New + ( + tgtField, + srcField.patch(), + result.dimensionedInternalField(), + weightedFvPatchFieldMapper + ( + AMIList[i].srcAddress(), + AMIList[i].srcWeights() + ) + ) + ); + + // Transfer all mapped quantities (value and e.g. gradient) onto + // srcField. Value will get overwritten below + srcField.rmap(tnewSrc(), identity(srcField.size())); + } srcField = pTraits<Type>::zero; diff --git a/src/sampling/meshToMeshInterpolation/meshToMesh/weightedFvPatchFieldMapper.H b/src/sampling/meshToMeshInterpolation/meshToMesh/weightedFvPatchFieldMapper.H new file mode 100644 index 00000000000..c14b5500fd4 --- /dev/null +++ b/src/sampling/meshToMeshInterpolation/meshToMesh/weightedFvPatchFieldMapper.H @@ -0,0 +1,122 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +Class + Foam::weightedFvPatchFieldMapper + +Description + FieldMapper with weighted mapping. + +\*---------------------------------------------------------------------------*/ + +#ifndef weightedFvPatchFieldMapper_H +#define weightedFvPatchFieldMapper_H + +#include "fvPatchFieldMapper.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class weightedFvPatchFieldMapper Declaration +\*---------------------------------------------------------------------------*/ + +class weightedFvPatchFieldMapper +: + public fvPatchFieldMapper +{ + const labelListList& addressing_; + + const scalarListList& weights_; + + bool hasUnmapped_; + +public: + + // Constructors + + //- Construct given addressing + weightedFvPatchFieldMapper + ( + const labelListList& addressing, + const scalarListList& weights + ) + : + addressing_(addressing), + weights_(weights), + hasUnmapped_(false) + { + forAll(addressing_, i) + { + if (addressing_[i].size() == 0) + { + hasUnmapped_ = true; + } + } + } + + //- Destructor + virtual ~weightedFvPatchFieldMapper() + {} + + + // Member Functions + + virtual label size() const + { + return addressing().size(); + } + + virtual bool direct() const + { + return false; + } + + virtual bool hasUnmapped() const + { + return hasUnmapped_; + } + + virtual const labelListList& addressing() const + { + return addressing_; + } + + virtual const scalarListList& weights() const + { + return weights_; + } + +}; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // -- GitLab