patchFields: Fixes to patchType handling

This change fixes failures that occur with the mapping of fields with
patchType overrides. It fixes a crash that previously occurred when
redistributing patch fields with patchType overrides. It also makes
decomposition correctly maintain patchType overrides on cyclics when
those cyclics are separated and become processorCyclics.

These fixes have been achieved by removing the patchType override data
from the fv and point patches. Whether or not the field overrides the
underlying patchType constraint is now determined on the fly from the
patch and field names and what is available on the field run-time
selection table.
This commit is contained in:
Will Bainbridge
2021-06-29 14:20:54 +01:00
parent fbfbe79bcd
commit 261d5ccd6d
15 changed files with 208 additions and 230 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -38,8 +38,7 @@ Foam::pointPatchField<Type>::pointPatchField
:
patch_(p),
internalField_(iF),
updated_(false),
patchType_(word::null)
updated_(false)
{}
@ -53,8 +52,7 @@ Foam::pointPatchField<Type>::pointPatchField
:
patch_(p),
internalField_(iF),
updated_(false),
patchType_(dict.lookupOrDefault<word>("patchType", word::null))
updated_(false)
{}
@ -69,8 +67,7 @@ Foam::pointPatchField<Type>::pointPatchField
:
patch_(p),
internalField_(iF),
updated_(false),
patchType_(ptf.patchType_)
updated_(false)
{}
@ -83,8 +80,7 @@ Foam::pointPatchField<Type>::pointPatchField
:
patch_(ptf.patch_),
internalField_(iF),
updated_(false),
patchType_(ptf.patchType_)
updated_(false)
{}
@ -102,9 +98,9 @@ void Foam::pointPatchField<Type>::write(Ostream& os) const
{
writeEntry(os, "type", type());
if (patchType_.size())
if (overridesConstraint())
{
writeEntry(os, "patchType", patchType_);
writeEntry(os, "patchType", patch().type());
}
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -93,11 +93,6 @@ class pointPatchField
// the construction of the matrix
bool updated_;
//- Optional patch type, used to allow specified boundary conditions
// to be applied to constraint patches by providing the constraint
// patch type as 'patchType'
word patchType_;
public:
@ -265,10 +260,10 @@ public:
// Member Functions
// Access
// Attributes
//- Return local objectRegistry
const objectRegistry& db() const;
//- Return the type of the calculated form of pointPatchField
static const word& calculatedType();
//- Return size
label size() const
@ -276,37 +271,6 @@ public:
return patch().size();
}
//- Return patch
const pointPatch& patch() const
{
return patch_;
}
//- Return dimensioned internal field reference
const DimensionedField<Type, pointMesh>&
internalField() const
{
return internalField_;
}
//- Return internal field reference
const Field<Type>& primitiveField() const
{
return internalField_;
}
//- Optional patch type
const word& patchType() const
{
return patchType_;
}
//- Optional patch type
word& patchType()
{
return patchType_;
}
//- Return true if this patch field fixes a value
virtual bool fixesValue() const
{
@ -319,6 +283,52 @@ public:
return false;
}
//- Return the constraint type this pointPatchField implements.
virtual const word& constraintType() const
{
return word::null;
}
//- Return true if this overrides the underlying constraint type
bool overridesConstraint() const
{
if (constraintType() == patch_.constraintType())
{
return false;
}
typename pointPatchConstructorTable::iterator patchTypeCstrIter
= pointPatchConstructorTablePtr_->find(patch_.type());
return
patchTypeCstrIter
!= pointPatchConstructorTablePtr_->end();
}
// Access
//- Return local objectRegistry
const objectRegistry& db() const;
//- Return patch
const pointPatch& patch() const
{
return patch_;
}
//- Return dimensioned internal field reference
const DimensionedField<Type, pointMesh>& internalField() const
{
return internalField_;
}
//- Return internal field reference
const Field<Type>& primitiveField() const
{
return internalField_;
}
//- Return true if the boundary condition has already been updated
bool updated() const
{
@ -383,15 +393,6 @@ public:
const Field<Type1>& pF
) const;
//- Return the type of the calculated form of pointPatchField
static const word& calculatedType();
//- Return the constraint type this pointPatchField implements.
virtual const word& constraintType() const
{
return word::null;
}
// Mapping functions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -78,13 +78,6 @@ Foam::autoPtr<Foam::pointPatchField<Type>> Foam::pointPatchField<Type>::New
return patchTypeCstrIter()(p, iF);
}
}
else
{
if (pointPatchConstructorTablePtr_->found(p.type()))
{
pfPtr().patchType() = actualPatchType;
}
}
return pfPtr;
}

View File

@ -45,13 +45,27 @@ Foam::fixedGradientFvPatchField<Type>::fixedGradientFvPatchField
(
const fvPatch& p,
const DimensionedField<Type, volMesh>& iF,
const dictionary& dict
const dictionary& dict,
const bool gradientRequired
)
:
fvPatchField<Type>(p, iF, dict, false),
gradient_("gradient", dict, p.size())
gradient_(p.size())
{
evaluate();
if (gradientRequired)
{
if (dict.found("gradient"))
{
gradient_ = Field<Type>("gradient", dict, p.size());
evaluate();
}
else
{
FatalIOErrorInFunction(dict)
<< "Essential entry 'gradient' missing"
<< exit(FatalIOError);
}
}
}
@ -61,12 +75,23 @@ Foam::fixedGradientFvPatchField<Type>::fixedGradientFvPatchField
const fixedGradientFvPatchField<Type>& ptf,
const fvPatch& p,
const DimensionedField<Type, volMesh>& iF,
const fvPatchFieldMapper& mapper
const fvPatchFieldMapper& mapper,
const bool mappingRequired
)
:
fvPatchField<Type>(ptf, p, iF, mapper),
gradient_(mapper(ptf.gradient_))
{}
fvPatchField<Type>(ptf, p, iF, mapper, mappingRequired),
gradient_(p.size())
{
if (mappingRequired)
{
// For unmapped faces set to internal field value (zero-gradient)
if (mapper.hasUnmapped())
{
gradient_ = Zero;
}
mapper(gradient_, ptf);
}
}
template<class Type>

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -104,7 +104,8 @@ public:
(
const fvPatch&,
const DimensionedField<Type, volMesh>&,
const dictionary&
const dictionary&,
const bool gradientRequired=true
);
//- Construct by mapping the given fixedGradientFvPatchField
@ -114,7 +115,8 @@ public:
const fixedGradientFvPatchField<Type>&,
const fvPatch&,
const DimensionedField<Type, volMesh>&,
const fvPatchFieldMapper&
const fvPatchFieldMapper&,
const bool mappingRequired=true
);
//- Disallow copy without setting internal field reference

View File

@ -49,21 +49,18 @@ Foam::fixedFluxPressureFvPatchScalarField::fixedFluxPressureFvPatchScalarField
const dictionary& dict
)
:
fixedGradientFvPatchScalarField(p, iF),
fixedGradientFvPatchScalarField(p, iF, dict, false),
curTimeIndex_(-1)
{
if (dict.found("value") && dict.found("gradient"))
{
fvPatchField<scalar>::operator=
(
scalarField("value", dict, p.size())
);
fvPatchField<scalar>::operator=(scalarField("value", dict, p.size()));
gradient() = scalarField("gradient", dict, p.size());
}
else
{
fvPatchField<scalar>::operator=(patchInternalField());
gradient() = 0.0;
gradient() = Zero;
}
}
@ -76,34 +73,9 @@ Foam::fixedFluxPressureFvPatchScalarField::fixedFluxPressureFvPatchScalarField
const fvPatchFieldMapper& mapper
)
:
fixedGradientFvPatchScalarField(p, iF),
fixedGradientFvPatchScalarField(ptf, p, iF, mapper),
curTimeIndex_(-1)
{
patchType() = ptf.patchType();
// Map gradient. Set unmapped values and overwrite with mapped ptf
gradient() = 0.0;
mapper(gradient(), ptf.gradient());
// Evaluate the value field from the gradient if the internal field is valid
// if (notNull(iF) && iF.size())
// {
// scalarField::operator=
// (
// // patchInternalField() + gradient()/patch().deltaCoeffs()
// // ***HGW Hack to avoid the construction of mesh.deltaCoeffs
// // which fails for AMI patches for some mapping operations
// patchInternalField()
// + gradient()*(patch().nf() & patch().delta())
// );
// }
// else
{
// Enforce mapping of values so we have a valid starting value. This
// constructor is used when reconstructing fields
mapper(*this, ptf);
}
}
{}
Foam::fixedFluxPressureFvPatchScalarField::fixedFluxPressureFvPatchScalarField

View File

@ -88,8 +88,6 @@ Foam::uniformInletOutletFvPatchField<Type>::uniformInletOutletFvPatchField
phiName_(ptf.phiName_),
uniformInletValue_(ptf.uniformInletValue_, false)
{
this->patchType() = ptf.patchType();
// Evaluate refValue since not mapped
this->refValue() =
uniformInletValue_->value(this->db().time().timeOutputValue());

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -96,8 +96,6 @@ uniformTotalPressureFvPatchScalarField
gamma_(ptf.gamma_),
p0_(ptf.p0_, false)
{
patchType() = ptf.patchType();
// Set the patch pressure to the current total pressure
// This is not ideal but avoids problems with the creation of patch faces
const scalar t = this->db().time().timeOutputValue();

View File

@ -42,8 +42,7 @@ Foam::fvPatchField<Type>::fvPatchField
patch_(p),
internalField_(iF),
updated_(false),
manipulatedMatrix_(false),
patchType_(word::null)
manipulatedMatrix_(false)
{}
@ -59,8 +58,7 @@ Foam::fvPatchField<Type>::fvPatchField
patch_(p),
internalField_(iF),
updated_(false),
manipulatedMatrix_(false),
patchType_(word::null)
manipulatedMatrix_(false)
{}
@ -77,8 +75,7 @@ Foam::fvPatchField<Type>::fvPatchField
patch_(p),
internalField_(iF),
updated_(false),
manipulatedMatrix_(false),
patchType_(dict.lookupOrDefault<word>("patchType", word::null))
manipulatedMatrix_(false)
{
if (valueRequired)
{
@ -115,8 +112,7 @@ Foam::fvPatchField<Type>::fvPatchField
patch_(p),
internalField_(iF),
updated_(false),
manipulatedMatrix_(false),
patchType_(ptf.patchType_)
manipulatedMatrix_(false)
{
if (mappingRequired)
{
@ -141,8 +137,7 @@ Foam::fvPatchField<Type>::fvPatchField
patch_(ptf.patch_),
internalField_(iF),
updated_(false),
manipulatedMatrix_(false),
patchType_(ptf.patchType_)
manipulatedMatrix_(false)
{}
@ -266,9 +261,9 @@ void Foam::fvPatchField<Type>::write(Ostream& os) const
{
writeEntry(os, "type", type());
if (patchType_.size())
if (overridesConstraint())
{
writeEntry(os, "patchType", patchType_);
writeEntry(os, "patchType", patch().type());
}
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -101,11 +101,6 @@ class fvPatchField
// during the construction of the matrix
bool manipulatedMatrix_;
//- Optional patch type, used to allow specified boundary conditions
// to be applied to constraint patches by providing the constraint
// patch type as 'patchType'
word patchType_;
public:
@ -317,6 +312,22 @@ public:
return false;
}
//- Return true if this overrides the underlying constraint type
bool overridesConstraint() const
{
if (type() == patch_.type())
{
return false;
}
typename patchConstructorTable::iterator patchTypeCstrIter
= patchConstructorTablePtr_->find(patch_.type());
return
patchTypeCstrIter
!= patchConstructorTablePtr_->end();
}
// Access
@ -330,8 +341,7 @@ public:
}
//- Return dimensioned internal field reference
const DimensionedField<Type, volMesh>&
internalField() const
const DimensionedField<Type, volMesh>& internalField() const
{
return internalField_;
}
@ -342,18 +352,6 @@ public:
return internalField_;
}
//- Optional patch type
const word& patchType() const
{
return patchType_;
}
//- Optional patch type
word& patchType()
{
return patchType_;
}
//- Return true if the boundary condition has already been updated
bool updated() const
{

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -55,15 +55,15 @@ Foam::tmp<Foam::fvPatchField<Type>> Foam::fvPatchField<Type>::New
<< exit(FatalError);
}
typename patchConstructorTable::iterator patchTypeCstrIter =
patchConstructorTablePtr_->find(p.type());
if
(
actualPatchType == word::null
|| actualPatchType != p.type()
)
{
typename patchConstructorTable::iterator patchTypeCstrIter =
patchConstructorTablePtr_->find(p.type());
if (patchTypeCstrIter != patchConstructorTablePtr_->end())
{
return patchTypeCstrIter()(p, iF);
@ -75,14 +75,7 @@ Foam::tmp<Foam::fvPatchField<Type>> Foam::fvPatchField<Type>::New
}
else
{
tmp<fvPatchField<Type>> tfvp = cstrIter()(p, iF);
// Check if constraint type override and store patchType if so
if ((patchTypeCstrIter != patchConstructorTablePtr_->end()))
{
tfvp.ref().patchType() = actualPatchType;
}
return tfvp;
return cstrIter()(p, iF);
}
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -263,11 +263,10 @@ void Foam::volPointInterpolation::interpolateBoundaryField
wordList patchTypes(pf.boundaryField().size(), word::null);
forAll(pf.boundaryField(), patchi)
{
const word patchType = pf.boundaryField()[patchi].patchType();
if (patchType != word::null)
if (pf.boundaryField()[patchi].overridesConstraint())
{
havePatchTypes = true;
patchTypes[patchi] = patchType;
patchTypes[patchi] = pf.boundaryField()[patchi].patch().type();
}
}
if (!havePatchTypes)

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -165,7 +165,7 @@ public:
//- Return the constraint type this pointPatchField implements
virtual const word& constraintType() const
{
return cyclicAMIPointPatch::typeName;
return type();
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -146,22 +146,27 @@ Foam::fvFieldDecomposer::fvFieldDecomposer
{
forAll(boundaryAddressing_, patchi)
{
if
(
boundaryAddressing_[patchi] >= 0
&& !isA<processorLduInterface>(procMesh.boundary()[patchi])
)
const fvPatch& procPatch = procMesh.boundary()[patchi];
label fromPatchi = boundaryAddressing_[patchi];
if (fromPatchi < 0 && isA<processorCyclicFvPatch>(procPatch))
{
const label referPatchi =
refCast<const processorCyclicPolyPatch>
(procPatch.patch()).referPatchID();
fromPatchi = boundaryAddressing_[referPatchi];
}
if (fromPatchi >= 0)
{
patchFieldDecomposerPtrs_[patchi] = new patchFieldDecomposer
(
procMesh_.boundary()[patchi].patchSlice(faceAddressing_),
completeMesh_.boundaryMesh()
[
boundaryAddressing_[patchi]
].start()
completeMesh_.boundaryMesh()[fromPatchi].start()
);
}
else
if (boundaryAddressing_[patchi] < 0)
{
processorVolPatchFieldDecomposerPtrs_[patchi] =
new processorVolPatchFieldDecomposer

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -124,14 +124,26 @@ Foam::fvFieldDecomposer::decomposeField
{
const fvPatch& procPatch = procMesh_.boundary()[patchi];
if (patchFieldDecomposerPtrs_[patchi])
label fromPatchi = boundaryAddressing_[patchi];
if (fromPatchi < 0 && isA<processorCyclicFvPatch>(procPatch))
{
const label referPatchi =
refCast<const processorCyclicPolyPatch>
(procPatch.patch()).referPatchID();
if (field.boundaryField()[referPatchi].overridesConstraint())
{
fromPatchi = boundaryAddressing_[referPatchi];
}
}
if (fromPatchi >= 0)
{
bf.set
(
patchi,
fvPatchField<Type>::New
(
field.boundaryField()[boundaryAddressing_[patchi]],
field.boundaryField()[fromPatchi],
procPatch,
resF(),
*patchFieldDecomposerPtrs_[patchi]
@ -288,7 +300,7 @@ Foam::fvFieldDecomposer::decomposeField
{
const fvPatch& procPatch = procMesh_.boundary()[patchi];
if (patchFieldDecomposerPtrs_[patchi])
if (boundaryAddressing_[patchi] >= 0)
{
bf.set
(
@ -302,57 +314,48 @@ Foam::fvFieldDecomposer::decomposeField
)
);
}
else if (isA<processorCyclicFvPatch>(procPatch))
{
// Do our own mapping. Avoids a lot of mapping complexity.
bf.set
(
patchi,
new processorCyclicFvsPatchField<Type>
(
procPatch,
resF(),
mapField
(
allFaceField,
procPatch.patchSlice(faceAddressing_),
doFlip
)
)
);
}
else if (isA<processorFvPatch>(procPatch))
{
// Do our own mapping. Avoids a lot of mapping complexity.
bf.set
(
patchi,
new processorFvsPatchField<Type>
(
procPatch,
resF(),
mapField
(
allFaceField,
procPatch.patchSlice(faceAddressing_),
doFlip
)
)
);
}
else
{
// Do our own mapping - avoids a lot of mapping complexity
if (isA<processorCyclicFvPatch>(procPatch))
{
bf.set
(
patchi,
new processorCyclicFvsPatchField<Type>
(
procPatch,
resF(),
mapField
(
allFaceField,
procPatch.patchSlice
(
faceAddressing_
),
doFlip
)
)
);
}
else if (isA<processorFvPatch>(procPatch))
{
bf.set
(
patchi,
new processorFvsPatchField<Type>
(
procPatch,
resF(),
mapField
(
allFaceField,
procPatch.patchSlice
(
faceAddressing_
),
doFlip
)
)
);
}
else
{
FatalErrorInFunction
<< "Unknown type." << abort(FatalError);
}
FatalErrorInFunction
<< "Unknown type." << abort(FatalError);
}
}