From 141f89ae3009d701536cd53fa5a816bb1f527b9d Mon Sep 17 00:00:00 2001 From: Teng Zhang Date: Fri, 9 Jan 2026 16:37:46 +0800 Subject: [PATCH 1/2] Add support for the localBlended scheme. Fix #575. - The `UBlend` volScalarField should be exist in the 0 folder. This field can be initialized using setFields or funkySetFields. - Although we only support the localBlended scheme for div(phi,U), it can be easily extent to other variables. --- .../solvers/dfLowMachFoam/createFields.H | 4 +- .../solvers/dfLowMachFoam/createLocalBlend.H | 67 +++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 applications/solvers/dfLowMachFoam/createLocalBlend.H diff --git a/applications/solvers/dfLowMachFoam/createFields.H b/applications/solvers/dfLowMachFoam/createFields.H index 32c8cd2c..c1c9d7d9 100644 --- a/applications/solvers/dfLowMachFoam/createFields.H +++ b/applications/solvers/dfLowMachFoam/createFields.H @@ -115,6 +115,8 @@ rho = thermo.rho(); Info<< "Creating field kinetic energy K\n" << endl; volScalarField K("K", 0.5*magSqr(U)); +#include "createLocalBlend.H" + multivariateSurfaceInterpolationScheme::fieldTable fields; #include "createMRF.H" @@ -206,4 +208,4 @@ const Switch splitting = CanteraTorchProperties.lookupOrDefault("splittingStrate #ifdef USE_LIBTORCH const Switch log_ = CanteraTorchProperties.subDict("TorchSettings").lookupOrDefault("log", false); const Switch torch_ = CanteraTorchProperties.subDict("TorchSettings").lookupOrDefault("torch", false); -#endif +#endif \ No newline at end of file diff --git a/applications/solvers/dfLowMachFoam/createLocalBlend.H b/applications/solvers/dfLowMachFoam/createLocalBlend.H new file mode 100644 index 00000000..a4ea8f0b --- /dev/null +++ b/applications/solvers/dfLowMachFoam/createLocalBlend.H @@ -0,0 +1,67 @@ +/*---------------------------------------------------------------------------*\ +This function is designed to read the UBlendingFactor for localBlended +schemes used by the divSchemes, i.e.: +``` +divSchemes +{ + div(phi,U) Gauss localBlended linear upwind; +} +``` +\*---------------------------------------------------------------------------*/ + +// Find and parse the divSchemes sub-dictionary +const dictionary& divSchemesDict = mesh.schemesDict().subDict("divSchemes"); + +Switch foundLocalBlended = false; + +// Parse the divSchemes tokens +wordList keys = divSchemesDict.toc(); +forAll(keys, i) +{ + const word& key = keys[i]; + // Convert to string + ITstream& is = divSchemesDict.lookup(key); + OStringStream os; + os << is; + word schemeStr = os.str(); + + if (schemeStr.find("localBlended") != word::npos) + { + foundLocalBlended = true; + } +} + +// Create the localBlendingFactor field only if localBlended scheme is found +if (foundLocalBlended) +{ + Info << " Creating UBlendingFactor field for localBlended schemes " << endl; + + // Read the scalarField UBlend + volScalarField UBlend + ( + IOobject + ( + "UBlend", + mesh.time().timeName(), + mesh, + IOobject::MUST_READ, + IOobject::NO_WRITE + ), + mesh + ) + + // Construct the surfaceScalarField UBlendingFactor by interpolating UBlend to cell faces + surfaceScalarField UBlendingFactor + ( + IOobject + ( + "UBlendingFactor", + mesh.time().timeName(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh, + fvc::interpolate(UBlend) + ); +} From 5acca7a5e3526d2143e1930dcfc69be1c8ddacd0 Mon Sep 17 00:00:00 2001 From: Teng Zhang Date: Mon, 12 Jan 2026 12:45:00 +0800 Subject: [PATCH 2/2] Fix errors in createLocalBlend. --- .../solvers/dfLowMachFoam/createLocalBlend.H | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/applications/solvers/dfLowMachFoam/createLocalBlend.H b/applications/solvers/dfLowMachFoam/createLocalBlend.H index a4ea8f0b..80b5a47d 100644 --- a/applications/solvers/dfLowMachFoam/createLocalBlend.H +++ b/applications/solvers/dfLowMachFoam/createLocalBlend.H @@ -31,6 +31,9 @@ forAll(keys, i) } } +// Declare pointer for UBlendingFactor +autoPtr UBlendingFactorPtr; + // Create the localBlendingFactor field only if localBlended scheme is found if (foundLocalBlended) { @@ -48,20 +51,23 @@ if (foundLocalBlended) IOobject::NO_WRITE ), mesh - ) + ); // Construct the surfaceScalarField UBlendingFactor by interpolating UBlend to cell faces - surfaceScalarField UBlendingFactor + UBlendingFactorPtr.reset ( - IOobject + new surfaceScalarField ( - "UBlendingFactor", - mesh.time().timeName(), - mesh, - IOobject::NO_READ, - IOobject::NO_WRITE - ), - mesh, - fvc::interpolate(UBlend) + IOobject + ( + "UBlendingFactor", + mesh.time().timeName(), + mesh, + IOobject::READ_IF_PRESENT, + IOobject::NO_WRITE, + true + ), + fvc::interpolate(UBlend) + ) ); }