From 0ee9ddb2b23c12df8765e18526ff7b476b41f1e0 Mon Sep 17 00:00:00 2001 From: Hrvoje Jasak Date: Tue, 13 Mar 2012 17:19:19 +0000 Subject: [PATCH] Direct mapped patch parallel comms bug fix --- .../directMappedFixedValueFvPatchField.C | 296 ++++++++++-------- .../directMappedFixedValueFvPatchField.H | 27 +- .../directMappedPolyPatch.C | 17 +- .../directMappedWallPolyPatch.C | 17 +- 4 files changed, 208 insertions(+), 149 deletions(-) diff --git a/src/finiteVolume/fields/fvPatchFields/derived/directMappedFixedValue/directMappedFixedValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/directMappedFixedValue/directMappedFixedValueFvPatchField.C index aaf927849..9146919d0 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/directMappedFixedValue/directMappedFixedValueFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/directMappedFixedValue/directMappedFixedValueFvPatchField.C @@ -33,124 +33,12 @@ License namespace Foam { -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // template -directMappedFixedValueFvPatchField::directMappedFixedValueFvPatchField -( - const fvPatch& p, - const DimensionedField& iF -) -: - fixedValueFvPatchField(p, iF), - setAverage_(false), - average_(pTraits::zero) -{} - - -template -directMappedFixedValueFvPatchField::directMappedFixedValueFvPatchField -( - const directMappedFixedValueFvPatchField& ptf, - const fvPatch& p, - const DimensionedField& iF, - const fvPatchFieldMapper& mapper -) -: - fixedValueFvPatchField(ptf, p, iF, mapper), - setAverage_(ptf.setAverage_), - average_(ptf.average_) +void directMappedFixedValueFvPatchField::mapField() { - if (!isA(this->patch().patch())) - { - FatalErrorIn - ( - "directMappedFixedValueFvPatchField::" - "directMappedFixedValueFvPatchField\n" - "(\n" - " const directMappedFixedValueFvPatchField&,\n" - " const fvPatch&,\n" - " const Field&,\n" - " const fvPatchFieldMapper&\n" - ")\n" - ) << "\n patch type '" << p.type() - << "' not type '" << directMappedPatchBase::typeName << "'" - << "\n for patch " << p.name() - << " of field " << this->dimensionedInternalField().name() - << " in file " << this->dimensionedInternalField().objectPath() - << exit(FatalError); - } -} - - -template -directMappedFixedValueFvPatchField::directMappedFixedValueFvPatchField -( - const fvPatch& p, - const DimensionedField& iF, - const dictionary& dict -) -: - fixedValueFvPatchField(p, iF, dict), - setAverage_(readBool(dict.lookup("setAverage"))), - average_(pTraits(dict.lookup("average"))) -{ - if (!isA(this->patch().patch())) - { - FatalErrorIn - ( - "directMappedFixedValueFvPatchField::" - "directMappedFixedValueFvPatchField\n" - "(\n" - " const fvPatch& p,\n" - " const DimensionedField& iF,\n" - " const dictionary& dict\n" - ")\n" - ) << "\n patch type '" << p.type() - << "' not type '" << directMappedPatchBase::typeName << "'" - << "\n for patch " << p.name() - << " of field " << this->dimensionedInternalField().name() - << " in file " << this->dimensionedInternalField().objectPath() - << exit(FatalError); - } -} - - -template -directMappedFixedValueFvPatchField::directMappedFixedValueFvPatchField -( - const directMappedFixedValueFvPatchField& ptf -) -: - fixedValueFvPatchField(ptf), - setAverage_(ptf.setAverage_), - average_(ptf.average_) -{} - - -template -directMappedFixedValueFvPatchField::directMappedFixedValueFvPatchField -( - const directMappedFixedValueFvPatchField& ptf, - const DimensionedField& iF -) -: - fixedValueFvPatchField(ptf, iF), - setAverage_(ptf.setAverage_), - average_(ptf.average_) -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template -void directMappedFixedValueFvPatchField::updateCoeffs() -{ - if (this->updated()) - { - return; - } - typedef GeometricField fieldType; // Get the scheduling information from the directMappedPatchBase @@ -167,7 +55,11 @@ void directMappedFixedValueFvPatchField::updateCoeffs() const word& fldName = this->dimensionedInternalField().name(); // Result of obtaining remote values - Field newValues; + if (debug) + { + Info<< "direct mapping field " + << this->dimensionedInternalField().name() << endl; + } switch (mpp.mode()) { @@ -175,11 +67,11 @@ void directMappedFixedValueFvPatchField::updateCoeffs() { if (mpp.sameRegion()) { - newValues = this->internalField(); + newValues_ = this->internalField(); } else { - newValues = nbrMesh.lookupObject + newValues_ = nbrMesh.lookupObject ( fldName ).internalField(); @@ -191,7 +83,7 @@ void directMappedFixedValueFvPatchField::updateCoeffs() distMap.constructSize(), distMap.subMap(), distMap.constructMap(), - newValues + newValues_ ); break; @@ -218,7 +110,7 @@ void directMappedFixedValueFvPatchField::updateCoeffs() ( fldName ); - newValues = nbrField.boundaryField()[nbrPatchID]; + newValues_ = nbrField.boundaryField()[nbrPatchID]; mapDistribute::distribute ( Pstream::defaultCommsType, @@ -226,7 +118,7 @@ void directMappedFixedValueFvPatchField::updateCoeffs() distMap.constructSize(), distMap.subMap(), distMap.constructMap(), - newValues + newValues_ ); break; @@ -261,7 +153,7 @@ void directMappedFixedValueFvPatchField::updateCoeffs() allValues ); - newValues = this->patch().patchSlice(allValues); + newValues_ = this->patch().patchSlice(allValues); break; } @@ -278,32 +170,174 @@ void directMappedFixedValueFvPatchField::updateCoeffs() if (setAverage_) { Type averagePsi = - gSum(this->patch().magSf()*newValues) + gSum(this->patch().magSf()*newValues_) /gSum(this->patch().magSf()); if (mag(averagePsi)/mag(average_) > 0.5) { - newValues *= mag(average_)/mag(averagePsi); + newValues_ *= mag(average_)/mag(averagePsi); } else { - newValues += (average_ - averagePsi); + newValues_ += (average_ - averagePsi); } } - this->operator==(newValues); - if (debug) { Info<< "directMapped on field:" << fldName << " patch:" << this->patch().name() - << " avg:" << gAverage(*this) - << " min:" << gMin(*this) - << " max:" << gMax(*this) + << " avg:" << gAverage(newValues_) + << " min:" << gMin(newValues_) + << " max:" << gMax(newValues_) << endl; } +} - fixedValueFvPatchField::updateCoeffs(); + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +directMappedFixedValueFvPatchField::directMappedFixedValueFvPatchField +( + const fvPatch& p, + const DimensionedField& iF +) +: + fixedValueFvPatchField(p, iF), + setAverage_(false), + average_(pTraits::zero), + curTimeIndex_(-1) +{} + + +template +directMappedFixedValueFvPatchField::directMappedFixedValueFvPatchField +( + const fvPatch& p, + const DimensionedField& iF, + const dictionary& dict +) +: + fixedValueFvPatchField(p, iF, dict), + setAverage_(readBool(dict.lookup("setAverage"))), + average_(pTraits(dict.lookup("average"))), + curTimeIndex_(-1) +{ + if (!isA(this->patch().patch())) + { + FatalErrorIn + ( + "directMappedFixedValueFvPatchField::" + "directMappedFixedValueFvPatchField\n" + "(\n" + " const fvPatch& p,\n" + " const DimensionedField& iF,\n" + " const dictionary& dict\n" + ")\n" + ) << "\n patch type '" << p.type() + << "' not type '" << directMappedPatchBase::typeName << "'" + << "\n for patch " << p.name() + << " of field " << this->dimensionedInternalField().name() + << " in file " << this->dimensionedInternalField().objectPath() + << exit(FatalError); + } +} + + +template +directMappedFixedValueFvPatchField::directMappedFixedValueFvPatchField +( + const directMappedFixedValueFvPatchField& ptf, + const fvPatch& p, + const DimensionedField& iF, + const fvPatchFieldMapper& mapper +) +: + fixedValueFvPatchField(ptf, p, iF, mapper), + setAverage_(ptf.setAverage_), + average_(ptf.average_), + curTimeIndex_(-1) +{ + if (!isA(this->patch().patch())) + { + FatalErrorIn + ( + "directMappedFixedValueFvPatchField::" + "directMappedFixedValueFvPatchField\n" + "(\n" + " const directMappedFixedValueFvPatchField&,\n" + " const fvPatch&,\n" + " const Field&,\n" + " const fvPatchFieldMapper&\n" + ")\n" + ) << "\n patch type '" << p.type() + << "' not type '" << directMappedPatchBase::typeName << "'" + << "\n for patch " << p.name() + << " of field " << this->dimensionedInternalField().name() + << " in file " << this->dimensionedInternalField().objectPath() + << exit(FatalError); + } +} + + +template +directMappedFixedValueFvPatchField::directMappedFixedValueFvPatchField +( + const directMappedFixedValueFvPatchField& ptf +) +: + fixedValueFvPatchField(ptf), + setAverage_(ptf.setAverage_), + average_(ptf.average_), + curTimeIndex_(-1) +{} + + +template +directMappedFixedValueFvPatchField::directMappedFixedValueFvPatchField +( + const directMappedFixedValueFvPatchField& ptf, + const DimensionedField& iF +) +: + fixedValueFvPatchField(ptf, iF), + setAverage_(ptf.setAverage_), + average_(ptf.average_), + curTimeIndex_(-1) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +void directMappedFixedValueFvPatchField::initEvaluate +( + const Pstream::commsTypes commsType +) +{ + // Note: All parallel comms need to happen at this stage + // HJ, 13/Mar/2012 + + // Only map + if (curTimeIndex_ != this->db().time().timeIndex()) + { + mapField(); + + curTimeIndex_ = this->db().time().timeIndex(); + } +} + + +template +void directMappedFixedValueFvPatchField::evaluate +( + const Pstream::commsTypes commsType +) +{ + this->operator==(newValues_); + + fixedValueFvPatchField::evaluate(); } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/directMappedFixedValue/directMappedFixedValueFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/directMappedFixedValue/directMappedFixedValueFvPatchField.H index 714a679c8..0e1ed5adf 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/directMappedFixedValue/directMappedFixedValueFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/directMappedFixedValue/directMappedFixedValueFvPatchField.H @@ -62,6 +62,18 @@ class directMappedFixedValueFvPatchField // setAverage_ is set true Type average_; + //- Current time index + label curTimeIndex_; + + //- New values from interpolation + Field newValues_; + + // Private member functions + + //- Map field data + void mapField(); + + public: //- Runtime type information @@ -134,8 +146,19 @@ public: // Evaluation functions - //- Update the coefficients associated with the patch field - virtual void updateCoeffs(); + //- Initialise the evaluation of the patch field + virtual void initEvaluate + ( + const Pstream::commsTypes commsType = Pstream::blocking + ); + + + //- Evaluate the patch field, sets Updated to false + virtual void evaluate + ( + const Pstream::commsTypes commsType = Pstream::blocking + ); + //- Write virtual void write(Ostream&) const; diff --git a/src/meshTools/directMapped/directMappedPolyPatch/directMappedPolyPatch.C b/src/meshTools/directMapped/directMappedPolyPatch/directMappedPolyPatch.C index 41fca1912..dbd687074 100644 --- a/src/meshTools/directMapped/directMappedPolyPatch/directMappedPolyPatch.C +++ b/src/meshTools/directMapped/directMappedPolyPatch/directMappedPolyPatch.C @@ -38,10 +38,7 @@ namespace Foam } -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - - -// * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::directMappedPolyPatch::directMappedPolyPatch ( @@ -159,42 +156,46 @@ Foam::directMappedPolyPatch::~directMappedPolyPatch() void Foam::directMappedPolyPatch::initGeometry() { polyPatch::initGeometry(); - directMappedPatchBase::clearOut(); } //- Calculate the patch geometry void Foam::directMappedPolyPatch::calcGeometry() { polyPatch::calcGeometry(); - directMappedPatchBase::clearOut(); } //- Initialise the patches for moving points void Foam::directMappedPolyPatch::initMovePoints(const pointField& p) { polyPatch::initMovePoints(p); + + // Force recalculation of mapping with new point position + // Note: this uses parallel communications. HJ, 13/Mar/2012 directMappedPatchBase::clearOut(); + directMappedPatchBase::map(); } //- Correct patches after moving points void Foam::directMappedPolyPatch::movePoints(const pointField& p) { polyPatch::movePoints(p); - directMappedPatchBase::clearOut(); } //- Initialise the update of the patch topology void Foam::directMappedPolyPatch::initUpdateMesh() { polyPatch::initUpdateMesh(); + + // Force recalculation of mapping with new point position + // Note: this uses parallel communications. HJ, 13/Mar/2012 directMappedPatchBase::clearOut(); + directMappedPatchBase::map(); } //- Update of the patch topology void Foam::directMappedPolyPatch::updateMesh() { polyPatch::updateMesh(); - directMappedPatchBase::clearOut(); } diff --git a/src/meshTools/directMapped/directMappedPolyPatch/directMappedWallPolyPatch.C b/src/meshTools/directMapped/directMappedPolyPatch/directMappedWallPolyPatch.C index 72657892e..af5e46e06 100644 --- a/src/meshTools/directMapped/directMappedPolyPatch/directMappedWallPolyPatch.C +++ b/src/meshTools/directMapped/directMappedPolyPatch/directMappedWallPolyPatch.C @@ -43,10 +43,7 @@ namespace Foam } -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - - -// * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::directMappedWallPolyPatch::directMappedWallPolyPatch ( @@ -164,42 +161,46 @@ Foam::directMappedWallPolyPatch::~directMappedWallPolyPatch() void Foam::directMappedWallPolyPatch::initGeometry() { wallPolyPatch::initGeometry(); - directMappedPatchBase::clearOut(); } //- Calculate the patch geometry void Foam::directMappedWallPolyPatch::calcGeometry() { wallPolyPatch::calcGeometry(); - directMappedPatchBase::clearOut(); } //- Initialise the patches for moving points void Foam::directMappedWallPolyPatch::initMovePoints(const pointField& p) { wallPolyPatch::initMovePoints(p); + + // Force recalculation of mapping with new point position + // Note: this uses parallel communications. HJ, 13/Mar/2012 directMappedPatchBase::clearOut(); + directMappedPatchBase::map(); } //- Correct patches after moving points void Foam::directMappedWallPolyPatch::movePoints(const pointField& p) { wallPolyPatch::movePoints(p); - directMappedPatchBase::clearOut(); } //- Initialise the update of the patch topology void Foam::directMappedWallPolyPatch::initUpdateMesh() { wallPolyPatch::initUpdateMesh(); + + // Force recalculation of mapping with new point position + // Note: this uses parallel communications. HJ, 13/Mar/2012 directMappedPatchBase::clearOut(); + directMappedPatchBase::map(); } //- Update of the patch topology void Foam::directMappedWallPolyPatch::updateMesh() { wallPolyPatch::updateMesh(); - directMappedPatchBase::clearOut(); }