diff --git a/src/TurbulenceModels/turbulenceModels/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.C b/src/TurbulenceModels/turbulenceModels/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.C index 8c78d59614..9f9df980b1 100644 --- a/src/TurbulenceModels/turbulenceModels/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.C +++ b/src/TurbulenceModels/turbulenceModels/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.C @@ -613,7 +613,7 @@ void Foam::epsilonWallFunctionFvPatchScalarField::manipulateMatrix return; } - matrix.setValues(patch().faceCells(), patchInternalField()); + matrix.setValues(patch().index(), patchInternalField()()); fvPatchField::manipulateMatrix(matrix); } diff --git a/src/TurbulenceModels/turbulenceModels/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaWallFunction/omegaWallFunctionFvPatchScalarField.C b/src/TurbulenceModels/turbulenceModels/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaWallFunction/omegaWallFunctionFvPatchScalarField.C index 2a1770659a..8b5a77c089 100644 --- a/src/TurbulenceModels/turbulenceModels/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaWallFunction/omegaWallFunctionFvPatchScalarField.C +++ b/src/TurbulenceModels/turbulenceModels/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaWallFunction/omegaWallFunctionFvPatchScalarField.C @@ -603,7 +603,7 @@ void Foam::omegaWallFunctionFvPatchScalarField::manipulateMatrix return; } - matrix.setValues(patch().faceCells(), patchInternalField()); + matrix.setValues(patch().index(), patchInternalField()); fvPatchField::manipulateMatrix(matrix); } diff --git a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C index b2b64f0d13..0aaeded657 100644 --- a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C +++ b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2016-2024 OpenCFD Ltd. + Copyright (C) 2016-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -1006,6 +1006,111 @@ void Foam::fvMatrix::setValues } +template +void Foam::fvMatrix::setValues +( + const label setPatchi, + const UList& values +) +{ +// this->setValuesFromList(cellLabels, values); + const fvMesh& mesh = psi_.mesh(); + const auto& cellLabels = mesh.boundaryMesh()[setPatchi].faceCells(); + + const cellList& cells = mesh.cells(); + const labelUList& own = mesh.owner(); + const labelUList& nei = mesh.neighbour(); + + scalarField& Diag = diag(); + Field& psi = + const_cast + < + GeometricField& + >(psi_).primitiveFieldRef(); + + + // Following actions: + // - adjust local field psi + // - set local matrix to be diagonal (so adjust source) + // - cut connections to neighbours + // - make (on non-adjusted cells) contribution explicit + + if (symmetric() || asymmetric()) + { + forAll(cellLabels, i) + { + const label celli = cellLabels[i]; + const Type& value = values[i]; + + for (const label facei : cells[celli]) + { + const label patchi = mesh.boundaryMesh().patchID(facei); + + if (patchi == -1) + { + if (symmetric()) + { + if (celli == own[facei]) + { + source_[nei[facei]] -= upper()[facei]*value; + } + else + { + source_[own[facei]] -= upper()[facei]*value; + } + + upper()[facei] = 0.0; + } + else + { + if (celli == own[facei]) + { + source_[nei[facei]] -= lower()[facei]*value; + } + else + { + source_[own[facei]] -= upper()[facei]*value; + } + + upper()[facei] = 0.0; + lower()[facei] = 0.0; + } + } + else if (patchi != setPatchi) + { + if (internalCoeffs_[patchi].size()) + { + const label patchFacei = + mesh.boundaryMesh()[patchi].whichFace(facei); + + internalCoeffs_[patchi][patchFacei] = Zero; + boundaryCoeffs_[patchi][patchFacei] = Zero; + } + } + } + } + + // Can explictly zero out contribution from setPatchi + if (internalCoeffs_[setPatchi].size()) + { + internalCoeffs_[setPatchi] = Zero; + boundaryCoeffs_[setPatchi] = Zero; + } + } + + // Note: above loop might have affected source terms on adjusted cells + // so make sure to adjust them afterwards + forAll(cellLabels, i) + { + const label celli = cellLabels[i]; + const Type& value = values[i]; + + psi[celli] = value; + source_[celli] = value*Diag[celli]; + } +} + + template void Foam::fvMatrix::setReference ( diff --git a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.H b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.H index 78f18d22c3..68405a7080 100644 --- a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.H +++ b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2016-2023 OpenCFD Ltd. + Copyright (C) 2016-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -541,6 +541,15 @@ public: const UIndirectList& values ); + //- Set solution in cells next to the given patch to the specified + //- values and eliminate the corresponding equations from the + //- matrix. + void setValues + ( + const label patchi, + const UList& values + ); + //- Set reference level for solution void setReference (