From 24d7331bec17ff21053eef44fea690d154030a4f Mon Sep 17 00:00:00 2001 From: mattijs <mattijs> Date: Wed, 12 Mar 2025 17:20:14 +0000 Subject: [PATCH] ENH: constraint: only evaluate constraint-overrides. Fixes #3211 --- .../GeometricField/GeometricField.C | 95 +++++++++++++++---- .../faePatchField/faePatchField.H | 19 ++++ .../faePatchField/faePatchFieldBase.C | 16 +++- .../fvsPatchField/fvsPatchField.H | 19 ++++ .../fvsPatchField/fvsPatchFieldBase.C | 12 ++- 5 files changed, 134 insertions(+), 27 deletions(-) diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C index de8bde34d7d..5c6c40393fa 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C @@ -1356,9 +1356,16 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::operator= internalFieldRef() = gf.internalField(); boundaryFieldRef() = gf.boundaryField(); - // Make sure any e.g. jump-cyclic are updated. Note: unfortunately also - // triggers e.g. cyclic interpolation. - this->correctLocalBoundaryConditions(); + // Make sure any e.g. jump-cyclic are updated. + boundaryFieldRef().evaluate_if + ( + [](const auto& pfld) -> bool + { + const auto& pType = pfld.patchType(); + return !pType.empty() && pType != pfld.type(); + }, + UPstream::defaultCommsType + ); } @@ -1396,9 +1403,16 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::operator= tgf.clear(); - // Make sure any e.g. jump-cyclic are updated. Note: unfortunately also - // triggers e.g. cyclic interpolation. - this->correctLocalBoundaryConditions(); + // Make sure any e.g. jump-cyclic are updated. + boundaryFieldRef().evaluate_if + ( + [](const auto& pfld) -> bool + { + const auto& pType = pfld.patchType(); + return !pType.empty() && pType != pfld.type(); + }, + UPstream::defaultCommsType + ); } @@ -1411,9 +1425,16 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::operator= internalFieldRef() = dt; boundaryFieldRef() = dt.value(); - // Make sure any e.g. jump-cyclic are updated. Note: unfortunately also - // triggers e.g. cyclic interpolation. - this->correctLocalBoundaryConditions(); + // Make sure any e.g. jump-cyclic are updated. + boundaryFieldRef().evaluate_if + ( + [](const auto& pfld) -> bool + { + const auto& pType = pfld.patchType(); + return !pType.empty() && pType != pfld.type(); + }, + UPstream::defaultCommsType + ); } @@ -1434,9 +1455,16 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::operator== tgf.clear(); - // Make sure any e.g. jump-cyclic are updated. Note: unfortunately also - // triggers e.g. cyclic interpolation. - this->correctLocalBoundaryConditions(); + // Make sure any e.g. jump-cyclic are updated. + boundaryFieldRef().evaluate_if + ( + [](const auto& pfld) -> bool + { + const auto& pType = pfld.patchType(); + return !pType.empty() && pType != pfld.type(); + }, + UPstream::defaultCommsType + ); } @@ -1449,9 +1477,16 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::operator== internalFieldRef() = dt; boundaryFieldRef() == dt.value(); - // Make sure any e.g. jump-cyclic are updated. Note: unfortunately also - // triggers e.g. cyclic interpolation. - this->correctLocalBoundaryConditions(); + // Make sure any e.g. jump-cyclic are updated. + boundaryFieldRef().evaluate_if + ( + [](const auto& pfld) -> bool + { + const auto& pType = pfld.patchType(); + return !pType.empty() && pType != pfld.type(); + }, + UPstream::defaultCommsType + ); } @@ -1468,7 +1503,15 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::operator op \ internalFieldRef() op gf.internalField(); \ boundaryFieldRef() op gf.boundaryField(); \ \ - this->correctLocalBoundaryConditions(); \ + boundaryFieldRef().evaluate_if \ + ( \ + [](const auto& pfld) -> bool \ + { \ + const auto& pType = pfld.patchType(); \ + return !pType.empty() && pType != pfld.type(); \ + }, \ + UPstream::defaultCommsType \ + ); \ } \ \ template<class Type, template<class> class PatchField, class GeoMesh> \ @@ -1480,7 +1523,15 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::operator op \ operator op(tgf()); \ tgf.clear(); \ \ - this->correctLocalBoundaryConditions(); \ + boundaryFieldRef().evaluate_if \ + ( \ + [](const auto& pfld) -> bool \ + { \ + const auto& pType = pfld.patchType(); \ + return !pType.empty() && pType != pfld.type(); \ + }, \ + UPstream::defaultCommsType \ + ); \ } \ \ template<class Type, template<class> class PatchField, class GeoMesh> \ @@ -1492,7 +1543,15 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::operator op \ internalFieldRef() op dt; \ boundaryFieldRef() op dt.value(); \ \ - this->correctLocalBoundaryConditions(); \ + boundaryFieldRef().evaluate_if \ + ( \ + [](const auto& pfld) -> bool \ + { \ + const auto& pType = pfld.patchType(); \ + return !pType.empty() && pType != pfld.type(); \ + }, \ + UPstream::defaultCommsType \ + ); \ } COMPUTED_ASSIGNMENT(Type, +=) diff --git a/src/finiteArea/fields/faePatchFields/faePatchField/faePatchField.H b/src/finiteArea/fields/faePatchFields/faePatchField/faePatchField.H index bf487edd2d2..b1348a471b3 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,18 @@ public: return patch_; } + //- The optional patch type + const word& patchType() const noexcept + { + return patchType_; + } + + //- The optional patch type + word& patchType() noexcept + { + return patchType_; + } + // Solution diff --git a/src/finiteArea/fields/faePatchFields/faePatchField/faePatchFieldBase.C b/src/finiteArea/fields/faePatchFields/faePatchField/faePatchFieldBase.C index 0c039570c5a..841edaabf82 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_(word::null) {} @@ -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/fvsPatchFields/fvsPatchField/fvsPatchField.H b/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchField.H index 65f170e7d5d..d8132e6f62e 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,18 @@ public: return patch_; } + //- The optional patch type + const word& patchType() const noexcept + { + return patchType_; + } + + //- The optional patch type + word& patchType() noexcept + { + return patchType_; + } + // Solution diff --git a/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchFieldBase.C b/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchFieldBase.C index a55787fce06..4198adc6a99 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_(word::null) {} @@ -55,7 +56,8 @@ Foam::fvsPatchFieldBase::fvsPatchFieldBase const dictionary& dict ) : - patch_(p) + patch_(p), + patchType_(word::null) // TBD. {} @@ -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_) {} -- GitLab