From 248fcc3a2d102dcac4de22346a479168459cd087 Mon Sep 17 00:00:00 2001 From: Vanja Skuric Date: Tue, 28 Feb 2017 16:33:45 +0100 Subject: [PATCH 1/3] Bugfix: Check for the zero-size WedgePointPatchField in parallel runs. Author: Zeljko Tukovic --- .../constraint/wedge/WedgePointPatchField.C | 464 +++++++++--------- 1 file changed, 234 insertions(+), 230 deletions(-) diff --git a/src/foam/fields/PointPatchFieldTemplates/constraint/wedge/WedgePointPatchField.C b/src/foam/fields/PointPatchFieldTemplates/constraint/wedge/WedgePointPatchField.C index b26ead887..6046e0ad7 100644 --- a/src/foam/fields/PointPatchFieldTemplates/constraint/wedge/WedgePointPatchField.C +++ b/src/foam/fields/PointPatchFieldTemplates/constraint/wedge/WedgePointPatchField.C @@ -1,230 +1,234 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | foam-extend: Open Source CFD - \\ / O peration | Version: 4.0 - \\ / A nd | Web: http://www.foam-extend.org - \\/ M anipulation | For copyright notice see file Copyright -------------------------------------------------------------------------------- -License - This file is part of foam-extend. - - foam-extend 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. - - foam-extend 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 foam-extend. If not, see . - -\*---------------------------------------------------------------------------*/ - -#include "WedgePointPatchField.H" -#include "transformField.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -template -< - template class PatchField, - class Mesh, - class PointPatch, - class WedgePointPatch, - template class MatrixType, - class Type -> -WedgePointPatchField -:: -WedgePointPatchField -( - const PointPatch& p, - const DimensionedField& iF -) -: - PatchField(p, iF) -{} - - -template -< - template class PatchField, - class Mesh, - class PointPatch, - class WedgePointPatch, - template class MatrixType, - class Type -> -WedgePointPatchField -:: -WedgePointPatchField -( - const PointPatch& p, - const DimensionedField& iF, - const dictionary& dict -) -: - PatchField(p, iF) -{ - if (!isType(p)) - { - FatalIOErrorIn - ( - "WedgePointPatchField" - "::WedgePointPatchField\n" - "(\n" - " const PointPatch& p,\n" - " const DimensionedField& field,\n" - " const dictionary& dict\n" - ")\n", - dict - ) << "patch " << this->patch().index() << " not wedge type. " - << "Patch type = " << p.type() - << exit(FatalIOError); - } -} - - -template -< - template class PatchField, - class Mesh, - class PointPatch, - class WedgePointPatch, - template class MatrixType, - class Type -> -WedgePointPatchField -:: -WedgePointPatchField -( - const WedgePointPatchField - &, - const PointPatch& p, - const DimensionedField& iF, - const PointPatchFieldMapper& -) -: - PatchField(p, iF) -{ - if (!isType(this->patch())) - { - FatalErrorIn - ( - "WedgePointPatchField" - "::WedgePointPatchField\n" - "(\n" - " const WedgePointPatchField" - " &,\n" - " const PointPatch& p,\n" - " const DimensionedField& iF,\n" - " const PointPatchFieldMapper& mapper\n" - ")\n" - ) << "Field type does not correspond to patch type for patch " - << this->patch().index() << "." << endl - << "Field type: " << typeName << endl - << "Patch type: " << this->patch().type() - << exit(FatalError); - } -} - - -template -< - template class PatchField, - class Mesh, - class PointPatch, - class WedgePointPatch, - template class MatrixType, - class Type -> -WedgePointPatchField -:: -WedgePointPatchField -( - const WedgePointPatchField - & ptf -) -: - PatchField(ptf) -{} - - -template -< - template class PatchField, - class Mesh, - class PointPatch, - class WedgePointPatch, - template class MatrixType, - class Type -> -WedgePointPatchField -:: -WedgePointPatchField -( - const WedgePointPatchField - & ptf, - const DimensionedField& iF -) -: - PatchField(ptf, iF) -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -// Evaluate patch field -template -< - template class PatchField, - class Mesh, - class PointPatch, - class WedgePointPatch, - template class MatrixType, - class Type -> -void -WedgePointPatchField -::evaluate -( - const Pstream::commsTypes commsType -) -{ - // In order to ensure that the wedge patch is always flat, take the - // normal vector from the first point - const vector& nHat = this->patch().pointNormals()[0]; - - tmp > tvalues = - transform(I - nHat*nHat, this->patchInternalField()); - const Field& values = tvalues(); - - // Get internal field to insert values into - Field& iF = const_cast&>(this->internalField()); - - // Get addressing - const labelList& meshPoints = this->patch().meshPoints(); - - forAll (meshPoints, pointI) - { - iF[meshPoints[pointI]] = values[pointI]; - } -} - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// ************************************************************************* // +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | foam-extend: Open Source CFD + \\ / O peration | Version: 4.0 + \\ / A nd | Web: http://www.foam-extend.org + \\/ M anipulation | For copyright notice see file Copyright +------------------------------------------------------------------------------- +License + This file is part of foam-extend. + + foam-extend 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. + + foam-extend 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 foam-extend. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "WedgePointPatchField.H" +#include "transformField.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +< + template class PatchField, + class Mesh, + class PointPatch, + class WedgePointPatch, + template class MatrixType, + class Type +> +WedgePointPatchField +:: +WedgePointPatchField +( + const PointPatch& p, + const DimensionedField& iF +) +: + PatchField(p, iF) +{} + + +template +< + template class PatchField, + class Mesh, + class PointPatch, + class WedgePointPatch, + template class MatrixType, + class Type +> +WedgePointPatchField +:: +WedgePointPatchField +( + const PointPatch& p, + const DimensionedField& iF, + const dictionary& dict +) +: + PatchField(p, iF) +{ + if (!isType(p)) + { + FatalIOErrorIn + ( + "WedgePointPatchField" + "::WedgePointPatchField\n" + "(\n" + " const PointPatch& p,\n" + " const DimensionedField& field,\n" + " const dictionary& dict\n" + ")\n", + dict + ) << "patch " << this->patch().index() << " not wedge type. " + << "Patch type = " << p.type() + << exit(FatalIOError); + } +} + + +template +< + template class PatchField, + class Mesh, + class PointPatch, + class WedgePointPatch, + template class MatrixType, + class Type +> +WedgePointPatchField +:: +WedgePointPatchField +( + const WedgePointPatchField + &, + const PointPatch& p, + const DimensionedField& iF, + const PointPatchFieldMapper& +) +: + PatchField(p, iF) +{ + if (!isType(this->patch())) + { + FatalErrorIn + ( + "WedgePointPatchField" + "::WedgePointPatchField\n" + "(\n" + " const WedgePointPatchField" + " &,\n" + " const PointPatch& p,\n" + " const DimensionedField& iF,\n" + " const PointPatchFieldMapper& mapper\n" + ")\n" + ) << "Field type does not correspond to patch type for patch " + << this->patch().index() << "." << endl + << "Field type: " << typeName << endl + << "Patch type: " << this->patch().type() + << exit(FatalError); + } +} + + +template +< + template class PatchField, + class Mesh, + class PointPatch, + class WedgePointPatch, + template class MatrixType, + class Type +> +WedgePointPatchField +:: +WedgePointPatchField +( + const WedgePointPatchField + & ptf +) +: + PatchField(ptf) +{} + + +template +< + template class PatchField, + class Mesh, + class PointPatch, + class WedgePointPatch, + template class MatrixType, + class Type +> +WedgePointPatchField +:: +WedgePointPatchField +( + const WedgePointPatchField + & ptf, + const DimensionedField& iF +) +: + PatchField(ptf, iF) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +// Evaluate patch field +template +< + template class PatchField, + class Mesh, + class PointPatch, + class WedgePointPatch, + template class MatrixType, + class Type +> +void +WedgePointPatchField +::evaluate +( + const Pstream::commsTypes commsType +) +{ + // ZT, 26/02/2017: Size of the patch could be zero in parallel runs + if (this->patch().meshPoints().size()) + { + // In order to ensure that the wedge patch is always flat, take the + // normal vector from the first point + const vector& nHat = this->patch().pointNormals()[0]; + + tmp > tvalues = + transform(I - nHat*nHat, this->patchInternalField()); + const Field& values = tvalues(); + + // Get internal field to insert values into + Field& iF = const_cast&>(this->internalField()); + + // Get addressing + const labelList& meshPoints = this->patch().meshPoints(); + + forAll (meshPoints, pointI) + { + iF[meshPoints[pointI]] = values[pointI]; + } + } +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// ************************************************************************* // From ab1330fc1cd062f80664bd28af497e65d7692666 Mon Sep 17 00:00:00 2001 From: Vanja Skuric Date: Fri, 3 Mar 2017 14:58:14 +0100 Subject: [PATCH 2/3] Bugfix: Corrected edge indexing in faMatrix::setValues() --- src/finiteArea/faMatrices/faMatrix/faMatrix.C | 5 +++-- src/finiteArea/faMesh/faMesh.C | 3 +++ src/finiteArea/faMesh/faMesh.H | 8 ++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/finiteArea/faMatrices/faMatrix/faMatrix.C b/src/finiteArea/faMatrices/faMatrix/faMatrix.C index 62b6fc489..7eba126e8 100644 --- a/src/finiteArea/faMatrices/faMatrix/faMatrix.C +++ b/src/finiteArea/faMatrices/faMatrix/faMatrix.C @@ -422,12 +422,13 @@ void faMatrix::setValues } else { - label patchi = mesh.boundary().whichPatch(edgei); + const label& curEdgeIndex = mesh.edgeIndex()[edgei]; + label patchi = mesh.boundary().whichPatch(curEdgeIndex); if (internalCoeffs_[patchi].size()) { label patchEdgei = - mesh.boundary()[patchi].whichEdge(edgei); + mesh.boundary()[patchi].whichEdge(curEdgeIndex); internalCoeffs_[patchi][patchEdgei] = pTraits::zero; diff --git a/src/finiteArea/faMesh/faMesh.C b/src/finiteArea/faMesh/faMesh.C index 1c1ab187b..164bdcee5 100644 --- a/src/finiteArea/faMesh/faMesh.C +++ b/src/finiteArea/faMesh/faMesh.C @@ -71,6 +71,7 @@ void Foam::faMesh::setPrimitiveMeshData() // Set faMesh edges edges_.setSize(bp.nEdges()); + edgeIndex_.setSize(bp.nEdges()); label edgeI = -1; @@ -80,6 +81,7 @@ void Foam::faMesh::setPrimitiveMeshData() for (label curEdge = 0; curEdge < nIntEdges; curEdge++) { edges_[++edgeI] = bp.edges()[curEdge]; + edgeIndex_[curEdge] = edgeI; } forAll (boundary(), patchI) @@ -89,6 +91,7 @@ void Foam::faMesh::setPrimitiveMeshData() forAll (curP, eI) { edges_[++edgeI] = bp.edges()[curP[eI]]; + edgeIndex_[curP[eI]] = edgeI; } } diff --git a/src/finiteArea/faMesh/faMesh.H b/src/finiteArea/faMesh/faMesh.H index 89f81abec..ab412dcfe 100644 --- a/src/finiteArea/faMesh/faMesh.H +++ b/src/finiteArea/faMesh/faMesh.H @@ -82,6 +82,9 @@ class faMesh //- Boundary mesh faBoundaryMesh boundary_; + //- Edge index + labelList edgeIndex_; + // Primitive mesh data @@ -397,6 +400,11 @@ public: return faceLabels_; } + //- Return faMesh edge indices + const labelList& edgeIndex() const + { + return edgeIndex_; + } //- Return parallel info const faGlobalMeshData& globalData() const; From 5b563af4641de8c6013fb790fdaca9ca9b0959fc Mon Sep 17 00:00:00 2001 From: Vanja Skuric Date: Fri, 3 Mar 2017 15:05:34 +0100 Subject: [PATCH 3/3] Bugfix: Checking if running in parallel during processor patch points correction --- src/finiteArea/faMesh/faMeshDemandDrivenData.C | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/finiteArea/faMesh/faMeshDemandDrivenData.C b/src/finiteArea/faMesh/faMeshDemandDrivenData.C index cbb94875e..07862c40b 100644 --- a/src/finiteArea/faMesh/faMeshDemandDrivenData.C +++ b/src/finiteArea/faMesh/faMeshDemandDrivenData.C @@ -1185,7 +1185,11 @@ void faMesh::calcPointAreaNormals() const // Processor patch points correction forAll (boundary(), patchI) { - if(boundary()[patchI].type() == processorFaPatch::typeName) + if + ( + Pstream::parRun() + && boundary()[patchI].type() == processorFaPatch::typeName + ) { const processorFaPatch& procPatch = refCast(boundary()[patchI]);