From ff132ff5f6c44a05c462762ac5ab003f54f184ce Mon Sep 17 00:00:00 2001 From: Andrew Heather Date: Thu, 4 May 2017 15:32:51 +0100 Subject: [PATCH] ENH: orientedFields - updated mapping and parallel utils --- ...parFvFieldReconstructorReconstructFields.C | 18 +++- .../GeometricField/MapGeometricFields.H | 44 +++------ .../fvMeshSubset/fvMeshSubsetInterpolate.C | 9 +- .../fvFieldMappers/MapFvSurfaceField.H | 24 +++-- .../mapping/fvFieldMappers/MapFvVolField.H | 4 +- .../decompose/decompose/fvFieldDecomposer.C | 97 +++++++++---------- .../decompose/decompose/fvFieldDecomposer.H | 9 +- .../fvFieldDecomposerDecomposeFields.C | 53 ++++++---- .../fvFieldReconstructorReconstructFields.C | 18 +++- 9 files changed, 150 insertions(+), 126 deletions(-) diff --git a/applications/utilities/parallelProcessing/redistributePar/parFvFieldReconstructorReconstructFields.C b/applications/utilities/parallelProcessing/redistributePar/parFvFieldReconstructorReconstructFields.C index 6f1ebfd8a4..c561dc7183 100644 --- a/applications/utilities/parallelProcessing/redistributePar/parFvFieldReconstructorReconstructFields.C +++ b/applications/utilities/parallelProcessing/redistributePar/parFvFieldReconstructorReconstructFields.C @@ -66,7 +66,7 @@ Foam::parFvFieldReconstructor::reconstructFvVolumeInternalField IOobject::NO_WRITE ); - return tmp> + tmp> tfield ( new DimensionedField ( @@ -76,6 +76,10 @@ Foam::parFvFieldReconstructor::reconstructFvVolumeInternalField internalField ) ); + + tfield.ref().oriented() = fld.oriented(); + + return tfield; } @@ -209,7 +213,7 @@ Foam::parFvFieldReconstructor::reconstructFvVolumeField IOobject::NO_WRITE ); - return tmp> + tmp> tfield ( new GeometricField ( @@ -220,6 +224,10 @@ Foam::parFvFieldReconstructor::reconstructFvVolumeField basePatchFields ) ); + + tfield.ref().oriented()= fld.oriented(); + + return tfield; } @@ -372,7 +380,7 @@ Foam::parFvFieldReconstructor::reconstructFvSurfaceField IOobject::NO_WRITE ); - return tmp> + tmp> tfield ( new GeometricField ( @@ -383,6 +391,10 @@ Foam::parFvFieldReconstructor::reconstructFvSurfaceField basePatchFields ) ); + + tfield.ref().oriented() = fld.oriented(); + + return tfield; } diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/MapGeometricFields.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/MapGeometricFields.H index 93a47eda9f..864318a4b0 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/MapGeometricFields.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/MapGeometricFields.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -51,7 +51,7 @@ public: void operator() ( - Field& field, + DimensionedField& field, const MeshMapper& mapper ) const; }; @@ -72,10 +72,12 @@ void MapGeometricFields const MeshMapper& mapper ) { - HashTable*> fields + typedef GeometricField FieldType; + + HashTable fields ( mapper.thisDb().objectRegistry::template - lookupClass>() + lookupClass() ); // It is necessary to enforce that all old-time fields are stored @@ -83,17 +85,9 @@ void MapGeometricFields // old-time-level field is mapped before the field itself, sizes // will not match. - for - ( - typename HashTable*>:: - iterator fieldIter = fields.begin(); - fieldIter != fields.end(); - ++fieldIter - ) + forAllConstIter(typename HashTable, fields, fieldIter) { - GeometricField& field = - const_cast&> - (*fieldIter()); + FieldType& field = const_cast(*fieldIter()); //Note: check can be removed once pointFields are actually stored on // the pointMesh instead of now on the polyMesh! @@ -103,17 +97,9 @@ void MapGeometricFields } } - for - ( - typename HashTable*>:: - iterator fieldIter = fields.begin(); - fieldIter != fields.end(); - ++fieldIter - ) + forAllConstIter(typename HashTable, fields, fieldIter) { - GeometricField& field = - const_cast&> - (*fieldIter()); + FieldType& field = const_cast(*fieldIter()); if (&field.mesh() == &mapper.mesh()) { @@ -124,15 +110,11 @@ void MapGeometricFields } // Map the internal field - MapInternalField() - ( - field.primitiveFieldRef(), - mapper - ); + MapInternalField()(field.ref(), mapper); // Map the patch fields - typename GeometricField - ::Boundary& bfield = field.boundaryFieldRef(); + typename FieldType::Boundary& bfield = field.boundaryFieldRef(); + forAll(bfield, patchi) { // Cannot check sizes for patch fields because of diff --git a/src/dynamicMesh/fvMeshSubset/fvMeshSubsetInterpolate.C b/src/dynamicMesh/fvMeshSubset/fvMeshSubsetInterpolate.C index 8e5680737d..228b7df26d 100644 --- a/src/dynamicMesh/fvMeshSubset/fvMeshSubsetInterpolate.C +++ b/src/dynamicMesh/fvMeshSubset/fvMeshSubsetInterpolate.C @@ -102,6 +102,7 @@ tmp> fvMeshSubset::interpolate ) ); GeometricField& resF = tresF.ref(); + resF.oriented() = vf.oriented(); // 2. Change the fvPatchFields to the correct type using a mapper @@ -183,8 +184,6 @@ tmp> fvMeshSubset::interpolate const labelList& faceMap ) { - const bool negateIfFlipped = vf.oriented()(); - // 1. Create the complete field with dummy patch fields PtrList> patchFields(patchMap.size()); @@ -248,6 +247,7 @@ tmp> fvMeshSubset::interpolate ) ); GeometricField& resF = tresF.ref(); + resF.oriented() = vf.oriented(); // 2. Change the fvsPatchFields to the correct type using a mapper @@ -311,7 +311,7 @@ tmp> fvMeshSubset::interpolate { Type val = vf.internalField()[baseFacei]; - if (cellMap[fc[i]] == own[baseFacei] || !negateIfFlipped) + if (cellMap[fc[i]] == own[baseFacei] || !vf.oriented()()) { pfld[i] = val; } @@ -422,6 +422,7 @@ fvMeshSubset::interpolate ) ); GeometricField& resF = tresF.ref(); + resF.oriented() = vf.oriented(); // 2. Change the pointPatchFields to the correct type using a mapper @@ -531,6 +532,8 @@ tmp> fvMeshSubset::interpolate ) ); + tresF.ref().oriented() = df.oriented(); + return tresF; } diff --git a/src/finiteVolume/interpolation/mapping/fvFieldMappers/MapFvSurfaceField.H b/src/finiteVolume/interpolation/mapping/fvFieldMappers/MapFvSurfaceField.H index 40dfd16f79..f9e58e589b 100644 --- a/src/finiteVolume/interpolation/mapping/fvFieldMappers/MapFvSurfaceField.H +++ b/src/finiteVolume/interpolation/mapping/fvFieldMappers/MapFvSurfaceField.H @@ -48,7 +48,7 @@ public: void operator() ( - Field& field, + DimensionedField& field, const MeshMapper& mapper ) const; }; @@ -57,7 +57,7 @@ public: template void MapInternalField::operator() ( - Field& field, + DimensionedField& field, const MeshMapper& mapper ) const { @@ -69,16 +69,22 @@ void MapInternalField::operator() << abort(FatalError); } - field.autoMap(mapper.surfaceMap()); + // Passing in oriented flag so that oriented fields (e.g. phi) are negated + // if flipped. Un-oriented fields, e.g U interpolated to faces (Uf) are not + // touched + field.autoMap(mapper.surfaceMap(), field.oriented().oriented()); - // Flip the flux - const labelList flipFaces = mapper.surfaceMap().flipFaceFlux().toc(); - - forAll(flipFaces, i) + if (field.oriented().oriented()) { - if (flipFaces[i] < field.size()) + // Flip the flux + const labelList flipFaces = mapper.surfaceMap().flipFaceFlux().toc(); + + forAll(flipFaces, i) { - field[flipFaces[i]] *= -1.0; + if (flipFaces[i] < field.size()) + { + field[flipFaces[i]] *= -1.0; + } } } } diff --git a/src/finiteVolume/interpolation/mapping/fvFieldMappers/MapFvVolField.H b/src/finiteVolume/interpolation/mapping/fvFieldMappers/MapFvVolField.H index db8c9ce72b..f23517342f 100644 --- a/src/finiteVolume/interpolation/mapping/fvFieldMappers/MapFvVolField.H +++ b/src/finiteVolume/interpolation/mapping/fvFieldMappers/MapFvVolField.H @@ -48,7 +48,7 @@ public: void operator() ( - Field& field, + DimensionedField& field, const MeshMapper& mapper ) const; }; @@ -57,7 +57,7 @@ public: template void MapInternalField::operator() ( - Field& field, + DimensionedField& field, const MeshMapper& mapper ) const { diff --git a/src/parallel/decompose/decompose/fvFieldDecomposer.C b/src/parallel/decompose/decompose/fvFieldDecomposer.C index 310d0ce1fe..8ff6ee3e06 100644 --- a/src/parallel/decompose/decompose/fvFieldDecomposer.C +++ b/src/parallel/decompose/decompose/fvFieldDecomposer.C @@ -107,7 +107,7 @@ processorSurfacePatchFieldDecomposer weights_[i].setSize(1); addressing_[i][0] = mag(addressingSlice[i]) - 1; - weights_[i][0] = sign(addressingSlice[i]); + weights_[i][0] = 1; } } @@ -126,59 +126,75 @@ Foam::fvFieldDecomposer::fvFieldDecomposer faceAddressing_(faceAddressing), cellAddressing_(cellAddressing), boundaryAddressing_(boundaryAddressing), - patchFieldDecomposerPtrs_ - ( - procMesh_.boundary().size(), - static_cast(nullptr) - ), - processorVolPatchFieldDecomposerPtrs_ - ( - procMesh_.boundary().size(), - static_cast(nullptr) - ), - processorSurfacePatchFieldDecomposerPtrs_ - ( - procMesh_.boundary().size(), - static_cast(nullptr) - ) + patchFieldDecomposerPtrs_(procMesh_.boundary().size()), + processorVolPatchFieldDecomposerPtrs_(procMesh_.boundary().size()), + processorSurfacePatchFieldDecomposerPtrs_(procMesh_.boundary().size()), + faceSign_(procMesh_.boundary().size()) { forAll(boundaryAddressing_, patchi) { + const fvPatch& fvp = procMesh_.boundary()[patchi]; + if ( boundaryAddressing_[patchi] >= 0 && !isA(procMesh.boundary()[patchi]) ) { - patchFieldDecomposerPtrs_[patchi] = new patchFieldDecomposer + patchFieldDecomposerPtrs_.set ( - procMesh_.boundary()[patchi].patchSlice(faceAddressing_), - completeMesh_.boundaryMesh() - [ - boundaryAddressing_[patchi] - ].start() + patchi, + new patchFieldDecomposer + ( + fvp.patchSlice(faceAddressing_), + completeMesh_.boundaryMesh() + [ + boundaryAddressing_[patchi] + ].start() + ) ); } else { - processorVolPatchFieldDecomposerPtrs_[patchi] = + processorVolPatchFieldDecomposerPtrs_.set + ( + patchi, new processorVolPatchFieldDecomposer ( completeMesh_, - procMesh_.boundary()[patchi].patchSlice(faceAddressing_) - ); + fvp.patchSlice(faceAddressing_) + ) + ); - processorSurfacePatchFieldDecomposerPtrs_[patchi] = + processorSurfacePatchFieldDecomposerPtrs_.set + ( + patchi, new processorSurfacePatchFieldDecomposer ( static_cast ( - procMesh_.boundary()[patchi].patchSlice + fvp.patchSlice ( faceAddressing_ ) ) - ); + ) + ); + + faceSign_.set + ( + patchi, + new scalarField(fvp.patchSlice(faceAddressing_).size()) + ); + + { + const SubList