From c879c2441293b3cb91d3cdf91c88dc30512f529e Mon Sep 17 00:00:00 2001 From: mattijs Date: Thu, 26 Nov 2020 13:45:53 +0000 Subject: [PATCH] ENH: redistributePar: suppress warning. Fixes #1937. --- .../fvMeshDistributeTemplates.C | 4 +- src/dynamicMesh/fvMeshSubset/fvMeshSubset.H | 28 +++++++--- .../fvMeshSubset/fvMeshSubsetInterpolate.C | 54 ++++++++++++++++--- 3 files changed, 70 insertions(+), 16 deletions(-) diff --git a/src/dynamicMesh/fvMeshDistribute/fvMeshDistributeTemplates.C b/src/dynamicMesh/fvMeshDistribute/fvMeshDistributeTemplates.C index f98e21d643..f735afd4e3 100644 --- a/src/dynamicMesh/fvMeshDistribute/fvMeshDistributeTemplates.C +++ b/src/dynamicMesh/fvMeshDistribute/fvMeshDistributeTemplates.C @@ -372,7 +372,9 @@ void Foam::fvMeshDistribute::sendFields const GeoField& fld = subsetter.baseMesh().lookupObject(fieldName); - tmp tsubfld = subsetter.interpolate(fld); + // Note: use subsetter to get sub field. Override default behaviour + // to warn for unset fields since they will be reset later on + tmp tsubfld = subsetter.interpolate(fld, true); toNbr << fieldName << token::NL << token::BEGIN_BLOCK diff --git a/src/dynamicMesh/fvMeshSubset/fvMeshSubset.H b/src/dynamicMesh/fvMeshSubset/fvMeshSubset.H index 5b1af19c5b..fe193ab9a8 100644 --- a/src/dynamicMesh/fvMeshSubset/fvMeshSubset.H +++ b/src/dynamicMesh/fvMeshSubset/fvMeshSubset.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2016-2018 OpenCFD Ltd. + Copyright (C) 2016-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -339,7 +339,8 @@ public: // Field Mapping - //- Map volume field + //- Map volume field. Optionally allow unmapped faces not to produce + // a warning template static tmp> interpolate @@ -348,14 +349,16 @@ public: const fvMesh& sMesh, const labelUList& patchMap, const labelUList& cellMap, - const labelUList& faceMap + const labelUList& faceMap, + const bool allowUnmapped = false ); template tmp> interpolate ( - const GeometricField& + const GeometricField&, + const bool allowUnmapped = false ) const; //- Map surface field. Optionally negates value if flipping @@ -371,11 +374,14 @@ public: const labelUList& faceMap ); + //- Map surface field. Optionally allow unmapped faces not to produce + // a warning (not currently used) template tmp> interpolate ( - const GeometricField& + const GeometricField&, + const bool allowUnmapped = false ) const; //- Map point field @@ -389,11 +395,14 @@ public: const labelUList& pointMap ); + //- Map point field. Optionally allow unmapped points not to produce + // a warning (not currently used) template tmp> interpolate ( - const GeometricField& + const GeometricField&, + const bool allowUnmapped = false ) const; //- Map dimensioned field @@ -406,9 +415,14 @@ public: const labelUList& cellMap ); + //- Map Dimensioned. Optional unmapped argument not used template tmp> - interpolate(const DimensionedField&) const; + interpolate + ( + const DimensionedField&, + const bool allowUnmapped = false + ) const; // Compatibility diff --git a/src/dynamicMesh/fvMeshSubset/fvMeshSubsetInterpolate.C b/src/dynamicMesh/fvMeshSubset/fvMeshSubsetInterpolate.C index 0741341ad5..b9af0753c6 100644 --- a/src/dynamicMesh/fvMeshSubset/fvMeshSubsetInterpolate.C +++ b/src/dynamicMesh/fvMeshSubset/fvMeshSubsetInterpolate.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -47,7 +47,8 @@ Foam::fvMeshSubset::interpolate const fvMesh& sMesh, const labelUList& patchMap, const labelUList& cellMap, - const labelUList& faceMap + const labelUList& faceMap, + const bool allowUnmapped ) { // 1. Create the complete field with dummy patch fields @@ -139,6 +140,17 @@ Foam::fvMeshSubset::interpolate } } + + directFvPatchFieldMapper mapper(directAddressing); + + // allowUnmapped : special mode for if we do not want to be + // warned for unmapped faces (e.g. from fvMeshDistribute). + const bool hasUnmapped = mapper.hasUnmapped(); + if (allowUnmapped) + { + mapper.hasUnmapped() = false; + } + bf.set ( patchi, @@ -147,9 +159,30 @@ Foam::fvMeshSubset::interpolate vf.boundaryField()[basePatchId], subPatch, result(), - directFvPatchFieldMapper(directAddressing) + mapper ) ); + + if (allowUnmapped && hasUnmapped) + { + // Set unmapped values to zeroGradient. This is the default + // action for unmapped fvPatchFields. Note that this bypasses + // any special logic for handling unmapped fvPatchFields but + // since this is only used inside fvMeshDistribute ... + + tmp> tfld(bf[patchi].patchInternalField()); + const Field& fld = tfld(); + + Field value(bf[patchi]); + forAll(directAddressing, i) + { + if (directAddressing[i] == -1) + { + value[i] = fld[i]; + } + } + bf[patchi].fvPatchField::operator=(value); + } } } @@ -164,7 +197,8 @@ Foam::tmp > Foam::fvMeshSubset::interpolate ( - const GeometricField& vf + const GeometricField& vf, + const bool allowUnmapped ) const { return interpolate @@ -173,7 +207,8 @@ Foam::fvMeshSubset::interpolate subMesh(), patchMap(), cellMap(), - faceMap() + faceMap(), + allowUnmapped ); } @@ -347,7 +382,8 @@ Foam::tmp > Foam::fvMeshSubset::interpolate ( - const GeometricField& sf + const GeometricField& sf, + const bool allowUnmapped ) const { return interpolate @@ -499,7 +535,8 @@ Foam::tmp > Foam::fvMeshSubset::interpolate ( - const GeometricField& sf + const GeometricField& sf, + const bool allowUnmapped ) const { return interpolate @@ -551,7 +588,8 @@ Foam::tmp > Foam::fvMeshSubset::interpolate ( - const DimensionedField& df + const DimensionedField& df, + const bool allowUnmapped ) const { return interpolate(df, subMesh(), cellMap());