From d4a959a93f95bc373f944cb04d58b316f716b39d Mon Sep 17 00:00:00 2001 From: Mattijs Janssens Date: Mon, 17 Mar 2025 14:11:12 +0000 Subject: [PATCH] BUG: fan: bc value not updated. See #3211 --- .../GeometricField/GeometricField.C | 69 +++++++++++++++++++ .../pointPatchField/pointPatchField.H | 6 ++ .../processor/processorFaPatchField.H | 2 +- .../faPatchFields/faPatchField/faPatchField.H | 6 ++ .../faePatchField/faePatchField.H | 25 +++++++ .../faePatchField/faePatchFieldBase.C | 16 +++-- .../constraint/cyclic/cyclicFvPatchField.H | 2 +- .../jumpCyclic/jumpCyclicFvPatchField.H | 2 +- .../jumpCyclicAMI/jumpCyclicAMIFvPatchField.H | 2 +- .../fvPatchFields/fvPatchField/fvPatchField.H | 8 ++- .../fvsPatchField/fvsPatchField.H | 25 +++++++ .../fvsPatchField/fvsPatchFieldBase.C | 12 ++-- 12 files changed, 161 insertions(+), 14 deletions(-) diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C index f3037d7e1b..2ef9c028ad 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C @@ -1355,6 +1355,15 @@ void Foam::GeometricField::operator= internalFieldRef() = gf.internalField(); boundaryFieldRef() = gf.boundaryField(); + + // Make sure any e.g. jump-cyclic are updated. + boundaryFieldRef().evaluate_if + ( + [](const auto& pfld) -> bool + { + return pfld.constraintOverride(); + } + ); } @@ -1391,6 +1400,15 @@ void Foam::GeometricField::operator= boundaryFieldRef() = gf.boundaryField(); tgf.clear(); + + // Make sure any e.g. jump-cyclic are updated. + boundaryFieldRef().evaluate_if + ( + [](const auto& pfld) -> bool + { + return pfld.constraintOverride(); + } + ); } @@ -1402,6 +1420,15 @@ void Foam::GeometricField::operator= { internalFieldRef() = dt; boundaryFieldRef() = dt.value(); + + // Make sure any e.g. jump-cyclic are updated. + boundaryFieldRef().evaluate_if + ( + [](const auto& pfld) -> bool + { + return pfld.constraintOverride(); + } + ); } @@ -1421,6 +1448,15 @@ void Foam::GeometricField::operator== boundaryFieldRef() == gf.boundaryField(); tgf.clear(); + + // Make sure any e.g. jump-cyclic are updated. + boundaryFieldRef().evaluate_if + ( + [](const auto& pfld) -> bool + { + return pfld.constraintOverride(); + } + ); } @@ -1432,6 +1468,15 @@ void Foam::GeometricField::operator== { internalFieldRef() = dt; boundaryFieldRef() == dt.value(); + + // Make sure any e.g. jump-cyclic are updated. + boundaryFieldRef().evaluate_if + ( + [](const auto& pfld) -> bool + { + return pfld.constraintOverride(); + } + ); } @@ -1447,6 +1492,14 @@ void Foam::GeometricField::operator op \ \ internalFieldRef() op gf.internalField(); \ boundaryFieldRef() op gf.boundaryField(); \ + \ + boundaryFieldRef().evaluate_if \ + ( \ + [](const auto& pfld) -> bool \ + { \ + return pfld.constraintOverride(); \ + } \ + ); \ } \ \ template class PatchField, class GeoMesh> \ @@ -1457,6 +1510,14 @@ void Foam::GeometricField::operator op \ { \ operator op(tgf()); \ tgf.clear(); \ + \ + boundaryFieldRef().evaluate_if \ + ( \ + [](const auto& pfld) -> bool \ + { \ + return pfld.constraintOverride(); \ + } \ + ); \ } \ \ template class PatchField, class GeoMesh> \ @@ -1467,6 +1528,14 @@ void Foam::GeometricField::operator op \ { \ internalFieldRef() op dt; \ boundaryFieldRef() op dt.value(); \ + \ + boundaryFieldRef().evaluate_if \ + ( \ + [](const auto& pfld) -> bool \ + { \ + return pfld.constraintOverride(); \ + } \ + ); \ } COMPUTED_ASSIGNMENT(Type, +=) diff --git a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.H b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.H index fa064ba77e..dea8560919 100644 --- a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.H +++ b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.H @@ -213,6 +213,12 @@ public: return patchType_; } + //- True if the type does not correspond to the constraint type + virtual bool constraintOverride() const + { + return !patchType_.empty() && patchType_ != type(); + } + // Solution diff --git a/src/finiteArea/fields/faPatchFields/constraint/processor/processorFaPatchField.H b/src/finiteArea/fields/faPatchFields/constraint/processor/processorFaPatchField.H index e50d5a2a91..65ebe8a830 100644 --- a/src/finiteArea/fields/faPatchFields/constraint/processor/processorFaPatchField.H +++ b/src/finiteArea/fields/faPatchFields/constraint/processor/processorFaPatchField.H @@ -175,7 +175,7 @@ public: virtual bool ready() const; //- Return neighbour field given internal field - tmp> patchNeighbourField() const; + virtual tmp> patchNeighbourField() const; // Evaluation diff --git a/src/finiteArea/fields/faPatchFields/faPatchField/faPatchField.H b/src/finiteArea/fields/faPatchFields/faPatchField/faPatchField.H index 0c47bd2ceb..4750c887c9 100644 --- a/src/finiteArea/fields/faPatchFields/faPatchField/faPatchField.H +++ b/src/finiteArea/fields/faPatchFields/faPatchField/faPatchField.H @@ -205,6 +205,12 @@ public: return patchType_; } + //- True if the type does not correspond to the constraint type + virtual bool constraintOverride() const + { + return !patchType_.empty() && patchType_ != type(); + } + // Solution diff --git a/src/finiteArea/fields/faePatchFields/faePatchField/faePatchField.H b/src/finiteArea/fields/faePatchFields/faePatchField/faePatchField.H index bf487edd2d..439e290d6e 100644 --- a/src/finiteArea/fields/faePatchFields/faePatchField/faePatchField.H +++ b/src/finiteArea/fields/faePatchFields/faePatchField/faePatchField.H @@ -83,6 +83,13 @@ class faePatchFieldBase //- Reference to patch const faPatch& patch_; + //- 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_; + + protected: // Protected Member Functions @@ -176,6 +183,24 @@ public: return patch_; } + //- The optional patch type + const word& patchType() const noexcept + { + return patchType_; + } + + //- The optional patch type + word& patchType() noexcept + { + return patchType_; + } + + //- True if the type does not correspond to the constraint type + virtual bool constraintOverride() const + { + return !patchType_.empty() && patchType_ != type(); + } + // Solution diff --git a/src/finiteArea/fields/faePatchFields/faePatchField/faePatchFieldBase.C b/src/finiteArea/fields/faePatchFields/faePatchField/faePatchFieldBase.C index 0c039570c5..88575cf924 100644 --- a/src/finiteArea/fields/faePatchFields/faePatchField/faePatchFieldBase.C +++ b/src/finiteArea/fields/faePatchFields/faePatchField/faePatchFieldBase.C @@ -47,7 +47,8 @@ int Foam::faePatchFieldBase::disallowGenericPatchField Foam::faePatchFieldBase::faePatchFieldBase(const faPatch& p) : - patch_(p) + patch_(p), + patchType_() {} @@ -57,7 +58,8 @@ Foam::faePatchFieldBase::faePatchFieldBase const word& patchType ) : - faePatchFieldBase(p) + patch_(p), + patchType_(patchType) {} @@ -79,20 +81,24 @@ Foam::faePatchFieldBase::faePatchFieldBase const faPatch& p ) : - patch_(p) + patch_(p), + patchType_(rhs.patchType_) {} Foam::faePatchFieldBase::faePatchFieldBase(const faePatchFieldBase& rhs) : - patch_(rhs.patch_) + patch_(rhs.patch_), + patchType_(rhs.patchType_) {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // void Foam::faePatchFieldBase::readDict(const dictionary& dict) -{} +{ + // TBD. read patchType_ +} const Foam::objectRegistry& Foam::faePatchFieldBase::db() const diff --git a/src/finiteVolume/fields/fvPatchFields/constraint/cyclic/cyclicFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/constraint/cyclic/cyclicFvPatchField.H index b8199cb28e..84e8dcb6f9 100644 --- a/src/finiteVolume/fields/fvPatchFields/constraint/cyclic/cyclicFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/constraint/cyclic/cyclicFvPatchField.H @@ -170,7 +170,7 @@ public: // Evaluation functions //- Return neighbour coupled internal cell data - tmp> patchNeighbourField() const; + virtual tmp> patchNeighbourField() const; //- Return reference to neighbour patchField const cyclicFvPatchField& neighbourPatchField() const; diff --git a/src/finiteVolume/fields/fvPatchFields/constraint/jumpCyclic/jumpCyclicFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/constraint/jumpCyclic/jumpCyclicFvPatchField.H index 199215c628..5d46b8f67f 100644 --- a/src/finiteVolume/fields/fvPatchFields/constraint/jumpCyclic/jumpCyclicFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/constraint/jumpCyclic/jumpCyclicFvPatchField.H @@ -128,7 +128,7 @@ public: // Evaluation functions //- Return neighbour coupled given internal cell data - tmp> patchNeighbourField() const; + virtual tmp> patchNeighbourField() const; //- Update result field based on interface functionality virtual void updateInterfaceMatrix diff --git a/src/finiteVolume/fields/fvPatchFields/constraint/jumpCyclicAMI/jumpCyclicAMIFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/constraint/jumpCyclicAMI/jumpCyclicAMIFvPatchField.H index 4787e0ef0b..236514fd04 100644 --- a/src/finiteVolume/fields/fvPatchFields/constraint/jumpCyclicAMI/jumpCyclicAMIFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/constraint/jumpCyclicAMI/jumpCyclicAMIFvPatchField.H @@ -137,7 +137,7 @@ public: virtual void evaluate(const Pstream::commsTypes commsType); //- Initialise interface functionality - void initInterfaceMatrixUpdate + virtual void initInterfaceMatrixUpdate ( solveScalarField& result, const bool add, diff --git a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.H b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.H index 5acccdf4d0..0eae7727c4 100644 --- a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2019-2024 OpenCFD Ltd. + Copyright (C) 2019-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -233,6 +233,12 @@ public: return patchType_; } + //- True if the type does not correspond to the constraint type + virtual bool constraintOverride() const + { + return !patchType_.empty() && patchType_ != type(); + } + // Solution diff --git a/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchField.H b/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchField.H index 65f170e7d5..9fcaa453b3 100644 --- a/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchField.H +++ b/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchField.H @@ -81,6 +81,13 @@ class fvsPatchFieldBase //- Reference to patch const fvPatch& patch_; + //- 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_; + + protected: // Protected Member Functions @@ -177,6 +184,24 @@ public: return patch_; } + //- The optional patch type + const word& patchType() const noexcept + { + return patchType_; + } + + //- The optional patch type + word& patchType() noexcept + { + return patchType_; + } + + //- True if the type does not correspond to the constraint type + virtual bool constraintOverride() const + { + return !patchType_.empty() && patchType_ != type(); + } + // Solution diff --git a/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchFieldBase.C b/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchFieldBase.C index a55787fce0..1d64654a06 100644 --- a/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchFieldBase.C +++ b/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchFieldBase.C @@ -45,7 +45,8 @@ int Foam::fvsPatchFieldBase::disallowGenericPatchField Foam::fvsPatchFieldBase::fvsPatchFieldBase(const fvPatch& p) : - patch_(p) + patch_(p), + patchType_() {} @@ -55,7 +56,8 @@ Foam::fvsPatchFieldBase::fvsPatchFieldBase const dictionary& dict ) : - patch_(p) + patch_(p), + patchType_() {} @@ -65,13 +67,15 @@ Foam::fvsPatchFieldBase::fvsPatchFieldBase const fvPatch& p ) : - patch_(p) + patch_(p), + patchType_(rhs.patchType_) {} Foam::fvsPatchFieldBase::fvsPatchFieldBase(const fvsPatchFieldBase& rhs) : - patch_(rhs.patch_) + patch_(rhs.patch_), + patchType_(rhs.patchType_) {}