From 713cb576d093b50fdd4264b92b5e66eac92fd9bb Mon Sep 17 00:00:00 2001 From: mattijs Date: Thu, 5 Sep 2013 13:39:58 +0100 Subject: [PATCH] ENH: fvPatchField: move mapping of exposed faces to fvPatchField. --- .../fvPatchFields/fvPatchField/fvPatchField.C | 44 ++++++++- .../fvMeshSubset/fvMeshSubsetInterpolate.C | 95 +++++++++++-------- 2 files changed, 99 insertions(+), 40 deletions(-) diff --git a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.C b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.C index 7fd83f41b1..3059eb5eea 100644 --- a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.C @@ -79,7 +79,49 @@ Foam::fvPatchField::fvPatchField updated_(false), manipulatedMatrix_(false), patchType_(ptf.patchType_) -{} +{ + // For unmapped faces set to internal field value (zero-gradient) + if (&iF && iF.size()) + { + Field& f = *this; + + if + ( + mapper.direct() + && &mapper.directAddressing() + && mapper.directAddressing().size() + ) + { + Field pif(this->patchInternalField()); + + const labelList& mapAddressing = mapper.directAddressing(); + + forAll(mapAddressing, i) + { + if (mapAddressing[i] < 0) + { + f[i] = pif[i]; + } + } + } + else if (!mapper.direct() && mapper.addressing().size()) + { + Field pif(this->patchInternalField()); + + const labelListList& mapAddressing = mapper.addressing(); + + forAll(mapAddressing, i) + { + const labelList& localAddrs = mapAddressing[i]; + + if (!localAddrs.size()) + { + f[i] = pif[i]; + } + } + } + } +} template diff --git a/src/finiteVolume/fvMesh/fvMeshSubset/fvMeshSubsetInterpolate.C b/src/finiteVolume/fvMesh/fvMeshSubset/fvMeshSubsetInterpolate.C index 7ee0d53577..33b782ea09 100644 --- a/src/finiteVolume/fvMesh/fvMeshSubset/fvMeshSubsetInterpolate.C +++ b/src/finiteVolume/fvMesh/fvMeshSubset/fvMeshSubsetInterpolate.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -45,10 +45,7 @@ tmp > fvMeshSubset::interpolate const labelList& faceMap ) { - // Create and map the internal-field values - Field internalField(vf.internalField(), cellMap); - - // Create and map the patch field values + // 1. Create the complete field with dummy patch fields PtrList > patchFields(patchMap.size()); forAll(patchFields, patchI) @@ -69,6 +66,49 @@ tmp > fvMeshSubset::interpolate ); } else + { + patchFields.set + ( + patchI, + new calculatedFvPatchField + ( + sMesh.boundary()[patchI], + DimensionedField::null() + ) + ); + } + } + + tmp > tresF + ( + new GeometricField + ( + IOobject + ( + "subset"+vf.name(), + sMesh.time().timeName(), + sMesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + sMesh, + vf.dimensions(), + Field(vf.internalField(), cellMap), + patchFields + ) + ); + GeometricField& resF = tresF(); + + + // 2. Change the fvPatchFields to the correct type using a mapper + // constructor (with reference to the now correct internal field) + + typename GeometricField:: + GeometricBoundaryField& bf = resF.boundaryField(); + + forAll(bf, patchI) + { + if (patchMap[patchI] != -1) { // Construct addressing const fvPatch& subPatch = sMesh.boundary()[patchI]; @@ -88,49 +128,26 @@ tmp > fvMeshSubset::interpolate } else { - // Mapped from internal face. Do what? Map from element - // 0 for now. - directAddressing[i] = 0; + // Mapped from internal face. Do what? Leave up to + // fvPatchField + directAddressing[i] = -1; } } - patchFields.set + bf.set ( patchI, fvPatchField::New ( vf.boundaryField()[patchMap[patchI]], - sMesh.boundary()[patchI], - DimensionedField::null(), + subPatch, + resF.dimensionedInternalField(), patchFieldSubset(directAddressing) ) ); - - // What to do with exposed internal faces if put into this patch? } } - - // Create the complete field from the pieces - tmp > tresF - ( - new GeometricField - ( - IOobject - ( - "subset"+vf.name(), - sMesh.time().timeName(), - sMesh, - IOobject::NO_READ, - IOobject::NO_WRITE - ), - sMesh, - vf.dimensions(), - internalField, - patchFields - ) - ); - return tresF; } @@ -212,9 +229,9 @@ tmp > fvMeshSubset::interpolate } else { - // Mapped from internal face. Do what? Map from element - // 0 for now. - directAddressing[i] = 0; + // Mapped from internal face. Do what? Leave up to + // patchField + directAddressing[i] = -1; } } @@ -344,8 +361,8 @@ fvMeshSubset::interpolate const pointPatch& subPatch = sMesh.boundary()[patchI]; const labelList& subMeshPoints = subPatch.meshPoints(); - // If mapped from outside patch use point 0 for lack of better. - labelList directAddressing(subPatch.size(), 0); + // If mapped from outside patch leave handling up to patchField + labelList directAddressing(subPatch.size(), -1); forAll(subMeshPoints, localI) {