ENH: add UPstream::msgType() setter method and UPstream::incrMsgType()

- like UPstream::parRun() etc, returns old value
This commit is contained in:
Mark Olesen 2023-07-25 15:45:23 +02:00
parent 03ca52b036
commit b620152191
23 changed files with 80 additions and 114 deletions

View File

@ -292,8 +292,7 @@ updateCoeffs()
// Since we're inside initEvaluate/evaluate there might be processor
// comms underway. Change the tag we use.
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag+1;
const int oldTag = UPstream::incrMsgType();
// Get the coupling information from the mappedPatchBase
const label patchi = patch().index();
@ -471,10 +470,9 @@ updateCoeffs()
<< regionTypeNames_ << nl << exit(FatalError);
}
mixedFvPatchScalarField::updateCoeffs();
UPstream::msgType(oldTag); // Restore tag
// Restore tag
UPstream::msgType() = oldTag;
mixedFvPatchScalarField::updateCoeffs();
}

View File

@ -918,6 +918,24 @@ public:
return msgType_;
}
//- Set the message tag for standard messages
// \return the previous value
static int msgType(int val) noexcept
{
int old(msgType_);
msgType_ = val;
return old;
}
//- Increment the message tag for standard messages
// \return the previous value
static int incrMsgType(int val = 1) noexcept
{
int old(msgType_);
msgType_ += val;
return old;
}
//- Get the communications type of the stream
commsTypes commsType() const noexcept
{

View File

@ -210,12 +210,12 @@ int Foam::processorCyclicPolyPatch::tag() const
tag_ = string::hasher()(cycPatch.neighbPatch().name()) % 32768u;
}
if (tag_ == Pstream::msgType() || tag_ == -1)
if (tag_ == UPstream::msgType() || tag_ == -1)
{
FatalErrorInFunction
<< "Tag calculated from cyclic patch name " << tag_
<< " is the same as the current message type "
<< Pstream::msgType() << " or -1" << nl
<< UPstream::msgType() << " or -1" << nl
<< "Please set a non-conflicting, unique, tag by hand"
<< " using the 'tag' entry"
<< exit(FatalError);

View File

@ -151,8 +151,7 @@ Foam::PatchFunction1Types::Sampled<Type>::value
// Since we're inside initEvaluate/evaluate there might be processor
// comms underway. Change the tag we use.
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag + 1;
const int oldTag = UPstream::incrMsgType();
const fvMesh& thisMesh = refCast<const fvMesh>
(
@ -167,9 +166,8 @@ Foam::PatchFunction1Types::Sampled<Type>::value
if (!haveSampleField())
{
// Restore tag
UPstream::msgType() = oldTag;
newValues.setSize(this->mappedPatchBase::patch_.size());
UPstream::msgType(oldTag); // Restore tag
newValues.resize_nocopy(this->mappedPatchBase::patch_.size());
newValues = Zero;
return this->transform(tnewValues);
}
@ -304,8 +302,7 @@ Foam::PatchFunction1Types::Sampled<Type>::value
}
}
// Restore tag
UPstream::msgType() = oldTag;
UPstream::msgType(oldTag); // Restore tag
return this->transform(tnewValues);
}

View File

@ -619,8 +619,7 @@ Foam::mappedPatchFieldBase<Type>::mappedField
// Since we're inside initEvaluate/evaluate there might be processor
// comms underway. Change the tag we use.
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag + 1;
const int oldTag = UPstream::incrMsgType();
const fvMesh& thisMesh = patchField_.patch().boundaryMesh().mesh();
@ -802,8 +801,7 @@ Foam::mappedPatchFieldBase<Type>::mappedField
}
}
// Restore tag
UPstream::msgType() = oldTag;
UPstream::msgType(oldTag); // Restore tag
return tnewValues;
}
@ -842,13 +840,11 @@ Foam::mappedPatchFieldBase<Type>::mappedInternalField() const
// Since we're inside initEvaluate/evaluate there might be processor
// comms underway. Change the tag we use.
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag+1;
const int oldTag = UPstream::incrMsgType();
distribute(fieldName_, nbrIntFld);
// Restore tag
UPstream::msgType() = oldTag;
UPstream::msgType(oldTag); // Restore tag
return tnbrIntFld;
}
@ -880,13 +876,11 @@ Foam::mappedPatchFieldBase<Type>::mappedWeightField() const
// Since we're inside initEvaluate/evaluate there might be processor
// comms underway. Change the tag we use.
const int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag+1;
const int oldTag = UPstream::incrMsgType();
distribute(fieldName_ + "_deltaCoeffs", nbrKDelta);
// Restore tag
UPstream::msgType() = oldTag;
UPstream::msgType(oldTag); // Restore tag
return tnbrKDelta;
}
@ -940,13 +934,11 @@ void Foam::mappedPatchFieldBase<Type>::mappedWeightField
// Since we're inside initEvaluate/evaluate there might be processor
// comms underway. Change the tag we use.
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag+1;
const int oldTag = UPstream::incrMsgType();
distribute(fieldName_ + "_weights", nbrWeights.ref());
// Restore tag
UPstream::msgType() = oldTag;
UPstream::msgType(oldTag); // Restore tag
}

View File

@ -106,8 +106,7 @@ void Foam::mappedFixedInternalValueFvPatchField<Type>::updateCoeffs()
// Since we're inside initEvaluate/evaluate there might be processor
// comms underway. Change the tag we use.
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag + 1;
const int oldTag = UPstream::incrMsgType();
// Retrieve the neighbour values and assign to this patch boundary field
mappedFixedValueFvPatchField<Type>::updateCoeffs();
@ -177,8 +176,7 @@ void Foam::mappedFixedInternalValueFvPatchField<Type>::updateCoeffs()
}
}
// Restore tag
UPstream::msgType() = oldTag;
UPstream::msgType(oldTag); // Restore tag
// Assign to (this) patch internal field its neighbour values
Field<Type>& intFld = const_cast<Field<Type>&>(this->primitiveField());

View File

@ -113,8 +113,7 @@ void Foam::mappedFlowRateFvPatchVectorField::updateCoeffs()
// Since we're inside initEvaluate/evaluate there might be processor
// comms underway. Change the tag we use.
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag+1;
const int oldTag = UPstream::incrMsgType();
// Get the coupling information from the mappedPatchBase
const mappedPatchBase& mpp = refCast<const mappedPatchBase>
@ -177,8 +176,7 @@ void Foam::mappedFlowRateFvPatchVectorField::updateCoeffs()
<< nl << exit(FatalError);
}
// Restore tag
UPstream::msgType() = oldTag;
UPstream::msgType(oldTag); // Restore tag
fixedValueFvPatchField<vector>::updateCoeffs();
}

View File

@ -147,8 +147,7 @@ void Foam::mappedVelocityFluxFixedValueFvPatchField::updateCoeffs()
// Since we're inside initEvaluate/evaluate there might be processor
// comms underway. Change the tag we use.
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag+1;
const int oldTag = UPstream::incrMsgType();
// Get the mappedPatchBase
const mappedPatchBase& mpp = refCast<const mappedPatchBase>
@ -224,8 +223,7 @@ void Foam::mappedVelocityFluxFixedValueFvPatchField::updateCoeffs()
phiField
).boundaryFieldRef()[patch().index()] == newPhiValues;
// Restore tag
UPstream::msgType() = oldTag;
UPstream::msgType(oldTag); // Restore tag
fixedValueFvPatchVectorField::updateCoeffs();
}

View File

@ -487,8 +487,7 @@ void Foam::turbulentDFSEMInletFvPatchVectorField::calcOverlappingProcEddies
List<List<eddy>>& overlappingEddies
) const
{
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag + 1;
const int oldTag = UPstream::incrMsgType();
List<boundBox> patchBBs(Pstream::nProcs());
patchBBs[Pstream::myProcNo()] = patchBounds_;
@ -546,8 +545,7 @@ void Foam::turbulentDFSEMInletFvPatchVectorField::calcOverlappingProcEddies
}
}
// Restore tag
UPstream::msgType() = oldTag;
UPstream::msgType(oldTag); // Restore tag
}

View File

@ -68,7 +68,7 @@ void Foam::distributedDILUPreconditioner::updateMatrixInterfaces
// From lduMatrix::initMatrixInterfaces
// Avoid any conflicts with inter-processor comms
UPstream::msgType() += 321;
const int oldTag = UPstream::incrMsgType(321);
for (const label interfacei : selectedInterfaces)
{
@ -103,7 +103,7 @@ void Foam::distributedDILUPreconditioner::updateMatrixInterfaces
);
}
UPstream::msgType() -= 321;
UPstream::msgType(oldTag); // Restore tag
}

View File

@ -148,9 +148,7 @@ void Foam::filmPyrolysisTemperatureCoupledFvPatchScalarField::updateCoeffs()
// Since we're inside initEvaluate/evaluate there might be processor
// comms underway. Change the tag we use.
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag+1;
const int oldTag = UPstream::incrMsgType();
scalarField& Tp = *this;
@ -175,8 +173,7 @@ void Foam::filmPyrolysisTemperatureCoupledFvPatchScalarField::updateCoeffs()
// Evaluate temperature
Tp = alphaFilm*TFilm + (1.0 - alphaFilm)*TPyr;
// Restore tag
UPstream::msgType() = oldTag;
UPstream::msgType(oldTag); // Restore tag
fixedValueFvPatchScalarField::updateCoeffs();
}

View File

@ -149,9 +149,7 @@ void Foam::filmPyrolysisVelocityCoupledFvPatchVectorField::updateCoeffs()
// Since we're inside initEvaluate/evaluate there might be processor
// comms underway. Change the tag we use.
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag+1;
const int oldTag = UPstream::incrMsgType();
vectorField& Up = *this;
@ -200,8 +198,7 @@ void Foam::filmPyrolysisVelocityCoupledFvPatchVectorField::updateCoeffs()
// Evaluate velocity
Up = alphaFilm*UFilm + (1.0 - alphaFilm)*UAvePyr*nf;
// Restore tag
UPstream::msgType() = oldTag;
UPstream::msgType(oldTag); // Restore tag
fixedValueFvPatchVectorField::updateCoeffs();
}

View File

@ -207,8 +207,7 @@ Foam::regionModels::regionModel::interRegionAMI
const polyPatch& p = regionMesh().boundaryMesh()[regionPatchi];
const polyPatch& nbrP = nbrRegionMesh.boundaryMesh()[nbrPatchi];
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag + 1;
const int oldTag = UPstream::incrMsgType();
interRegionAMI_[nbrRegionID].set
(
@ -223,7 +222,7 @@ Foam::regionModels::regionModel::interRegionAMI
interRegionAMI_[nbrRegionID][regionPatchi].calculate(p, nbrP);
UPstream::msgType() = oldTag;
UPstream::msgType(oldTag); // Restore tag
}
return interRegionAMI_[nbrRegionID][regionPatchi];
@ -237,7 +236,7 @@ Foam::regionModels::regionModel::interRegionAMI
const polyPatch& p = regionMesh().boundaryMesh()[regionPatchi];
const polyPatch& nbrP = nbrRegionMesh.boundaryMesh()[nbrPatchi];
label nPatch = regionMesh().boundaryMesh().size();
const label nPatch = regionMesh().boundaryMesh().size();
interRegionAMI_.resize(nbrRegionID + 1);
@ -248,8 +247,7 @@ Foam::regionModels::regionModel::interRegionAMI
new PtrList<AMIPatchToPatchInterpolation>(nPatch)
);
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag + 1;
const int oldTag = UPstream::incrMsgType();
interRegionAMI_[nbrRegionID].set
(
@ -264,7 +262,7 @@ Foam::regionModels::regionModel::interRegionAMI
interRegionAMI_[nbrRegionID][regionPatchi].calculate(p, nbrP);
UPstream::msgType() = oldTag;
UPstream::msgType(oldTag); // Restore tag
return interRegionAMI_[nbrRegionID][regionPatchi];
}

View File

@ -36,15 +36,14 @@ Foam::regionModels::regionModel::mapRegionPatchField
const bool flip
) const
{
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag + 1;
const int oldTag = UPstream::incrMsgType();
const AMIPatchToPatchInterpolation& ami =
interRegionAMI(nbrRegion, regionPatchi, nbrPatchi, flip);
tmp<Field<Type>> tresult(ami.interpolateToSource(nbrField));
UPstream::msgType() = oldTag;
UPstream::msgType(oldTag); // Restore tag
return tresult;
}
@ -68,8 +67,7 @@ Foam::regionModels::regionModel::mapRegionPatchField
{
const label nbrPatchi = nbrCoupledPatchID(nbrRegion, regionPatchi);
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag + 1;
const int oldTag = UPstream::incrMsgType();
const AMIPatchToPatchInterpolation& ami =
interRegionAMI(nbrRegion, regionPatchi, nbrPatchi, flip);
@ -81,7 +79,7 @@ Foam::regionModels::regionModel::mapRegionPatchField
tmp<Field<Type>> tresult(ami.interpolateToSource(nbrFieldp));
UPstream::msgType() = oldTag;
UPstream::msgType(oldTag); // Restore tag
return tresult;
}
@ -112,8 +110,7 @@ Foam::regionModels::regionModel::mapRegionPatchInternalField
{
const label nbrPatchi = nbrCoupledPatchID(nbrRegion, regionPatchi);
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag + 1;
const int oldTag = UPstream::incrMsgType();
const AMIPatchToPatchInterpolation& ami =
interRegionAMI(nbrRegion, regionPatchi, nbrPatchi, flip);
@ -129,7 +126,7 @@ Foam::regionModels::regionModel::mapRegionPatchInternalField
ami.interpolateToSource(nbrFieldp.patchInternalField())
);
UPstream::msgType() = oldTag;
UPstream::msgType(oldTag); // Restore tag
return tresult;
}

View File

@ -160,8 +160,7 @@ void alphatFilmWallFunctionFvPatchScalarField::updateCoeffs()
// Since we're inside initEvaluate/evaluate there might be processor
// comms underway. Change the tag we use.
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag+1;
const int oldTag = UPstream::incrMsgType();
const label patchi = patch().index();
@ -234,8 +233,7 @@ void alphatFilmWallFunctionFvPatchScalarField::updateCoeffs()
alphat[facei] = max(alphaEff - alphaw[facei], scalar(0));
}
// Restore tag
UPstream::msgType() = oldTag;
UPstream::msgType(oldTag); // Restore tag
fixedValueFvPatchScalarField::updateCoeffs();
}

View File

@ -339,8 +339,7 @@ void thermalBaffle1DFvPatchScalarField<solidType>::updateCoeffs()
}
// Since we're inside initEvaluate/evaluate there might be processor
// comms underway. Change the tag we use.
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag+1;
const int oldTag = UPstream::incrMsgType();
const mapDistribute& mapDist = this->mappedPatchBase::map();
@ -416,8 +415,7 @@ void thermalBaffle1DFvPatchScalarField<solidType>::updateCoeffs()
}
}
// Restore tag
UPstream::msgType() = oldTag;
UPstream::msgType(oldTag); // Restore tag
mixedFvPatchScalarField::updateCoeffs();
}

View File

@ -311,8 +311,7 @@ void turbulentTemperatureCoupledBaffleMixedFvPatchScalarField::updateCoeffs()
// Since we're inside initEvaluate/evaluate there might be processor
// comms underway. Change the tag we use.
const int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag+1;
const int oldTag = UPstream::incrMsgType();
// Get the coupling information from the mappedPatchBase
const mappedPatchBase& mpp =
@ -400,8 +399,7 @@ void turbulentTemperatureCoupledBaffleMixedFvPatchScalarField::updateCoeffs()
<< endl;
}
// Restore tag
UPstream::msgType() = oldTag;
UPstream::msgType(oldTag); // Restore tag
}

View File

@ -454,8 +454,7 @@ void turbulentTemperatureRadCoupledMixedFvPatchScalarField::updateCoeffs()
// Since we're inside initEvaluate/evaluate there might be processor
// comms underway. Change the tag we use.
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag+1;
const int oldTag = UPstream::incrMsgType();
// Get the coupling information from the mappedPatchBase
const label patchi = patch().index();
@ -772,8 +771,7 @@ void turbulentTemperatureRadCoupledMixedFvPatchScalarField::updateCoeffs()
storeHTCFields(prefix_, htc, htcPatch);
}
// Restore tag
UPstream::msgType() = oldTag;
UPstream::msgType(oldTag); // Restore tag
}

View File

@ -123,8 +123,7 @@ void Foam::radiation::MarshakRadiationFvPatchScalarField::updateCoeffs()
// Since we're inside initEvaluate/evaluate there might be processor
// comms underway. Change the tag we use.
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag+1;
const int oldTag = UPstream::incrMsgType();
// Temperature field
const auto& Tp = patch().lookupPatchField<volScalarField>(TName_);
@ -150,8 +149,7 @@ void Foam::radiation::MarshakRadiationFvPatchScalarField::updateCoeffs()
// Set value fraction
valueFraction() = 1.0/(1.0 + gamma*patch().deltaCoeffs()/Ep);
// Restore tag
UPstream::msgType() = oldTag;
UPstream::msgType(oldTag); // Restore tag
mixedFvPatchScalarField::updateCoeffs();
}

View File

@ -147,8 +147,7 @@ updateCoeffs()
// Since we're inside initEvaluate/evaluate there might be processor
// comms underway. Change the tag we use.
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag+1;
const int oldTag = UPstream::incrMsgType();
// Re-calc reference value
refValue() = 4.0*constant::physicoChemical::sigma.value()*pow4(Trad_);
@ -173,8 +172,7 @@ updateCoeffs()
// Set value fraction
valueFraction() = 1.0/(1.0 + gamma*patch().deltaCoeffs()/Ep);
// Restore tag
UPstream::msgType() = oldTag;
UPstream::msgType(oldTag); // Restore tag
mixedFvPatchScalarField::updateCoeffs();
}

View File

@ -143,8 +143,7 @@ updateCoeffs()
// Since we're inside initEvaluate/evaluate there might be processor
// comms underway. Change the tag we use.
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag+1;
const int oldTag = UPstream::incrMsgType();
const auto& Tp = patch().lookupPatchField<volScalarField>(TName_);
@ -356,8 +355,7 @@ updateCoeffs()
}
}
// Restore tag
UPstream::msgType() = oldTag;
UPstream::msgType(oldTag); // Restore tag
mixedFvPatchScalarField::updateCoeffs();
}

View File

@ -128,8 +128,7 @@ updateCoeffs()
// Since we're inside initEvaluate/evaluate there might be processor
// comms underway. Change the tag we use.
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag+1;
const int oldTag = UPstream::incrMsgType();
const radiationModel& radiation =
db().lookupObject<radiationModel>("radiationProperties");
@ -288,8 +287,7 @@ updateCoeffs()
}
}
// Restore tag
UPstream::msgType() = oldTag;
UPstream::msgType(oldTag); // Restore tag
mixedFvPatchScalarField::updateCoeffs();
}

View File

@ -103,8 +103,7 @@ Foam::tmp<Foam::scalarField> Foam::radiation::solidAbsorption::a
{
// Since we're inside initEvaluate/evaluate there might be processor
// comms underway. Change the tag we use.
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag+1;
const int oldTag = UPstream::incrMsgType();
const fvMesh& nbrMesh = nbrRegion();
@ -129,8 +128,7 @@ Foam::tmp<Foam::scalarField> Foam::radiation::solidAbsorption::a
mpp.distribute(absorptivity);
// Restore tag
UPstream::msgType() = oldTag;
UPstream::msgType(oldTag); // Restore tag
return tmp<scalarField>::New(std::move(absorptivity));
}
@ -157,8 +155,7 @@ Foam::tmp<Foam::scalarField> Foam::radiation::solidAbsorption::e
// Since we're inside initEvaluate/evaluate there might be processor
// comms underway. Change the tag we use.
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag+1;
const int oldTag = UPstream::incrMsgType();
const fvMesh& nbrMesh = nbrRegion();
@ -183,8 +180,7 @@ Foam::tmp<Foam::scalarField> Foam::radiation::solidAbsorption::e
mpp.distribute(emissivity);
// Restore tag
UPstream::msgType() = oldTag;
UPstream::msgType(oldTag); // Restore tag
return tmp<scalarField>::New(std::move(emissivity));
}