diff --git a/src/finiteVolume/finiteVolume/fvSchemes/fvSchemes.C b/src/finiteVolume/finiteVolume/fvSchemes/fvSchemes.C index 749f887cd4..629e9cb9f6 100644 --- a/src/finiteVolume/finiteVolume/fvSchemes/fvSchemes.C +++ b/src/finiteVolume/finiteVolume/fvSchemes/fvSchemes.C @@ -193,6 +193,106 @@ void Foam::fvSchemes::read(const dictionary& dict) } +Foam::word Foam::fvSchemes::filterGroup(const word& name) const +{ + word filteredName(name); + + word::size_type n = 0; + word::iterator iter2 = filteredName.begin(); + + bool found = false; + + for + ( + word::const_iterator iter1 = filteredName.begin(); + iter1 != filteredName.end(); + ++iter1 + ) + { + const char c = *iter1; + + if (c == '.') + { + found = true; + } + else if (!found || !isalnum(c)) + { + found = false; + *iter2++ = c; + n++; + } + } + + filteredName.resize(n); + + return filteredName; +} + + +Foam::ITstream& Foam::fvSchemes::lookupScheme +( + const word& name, + const dictionary& schemes, + const ITstream& defaultScheme +) const +{ + if (debug) + { + Info<< "Lookup scheme for " << name + << " in dictionary " << schemes.name().caseName() << endl; + } + + // Lookup scheme with optional wildcards + const entry* schemePtr = schemes.lookupEntryPtr(name, false, true); + + if (schemePtr) + { + return schemePtr->stream(); + } + else + { + // If scheme not found check if it contains group names + bool filtered = (name.find('.') != word::npos); + + if (filtered) + { + // Filter-out the group names and lookup + const entry* schemePtr = + schemes.lookupEntryPtr(filterGroup(name), false, true); + + if (schemePtr) + { + return schemePtr->stream(); + } + } + + // If scheme still not found check if a default scheme is provided + if (!defaultScheme.empty()) + { + const_cast(defaultScheme).rewind(); + return const_cast(defaultScheme); + } + else + { + // Cannot find scheme + + FatalIOErrorInFunction(schemes) + << "Cannot find scheme for " << name; + + if (filtered) + { + FatalIOError << " or " << filterGroup(name); + } + + FatalIOError + << " in dictionary " << schemes.name().caseName() + << exit(FatalIOError); + return const_cast(defaultScheme); + } + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::fvSchemes::fvSchemes(const objectRegistry& obr) @@ -349,138 +449,48 @@ const Foam::dictionary& Foam::fvSchemes::dict() const Foam::ITstream& Foam::fvSchemes::ddt(const word& name) const { - if (debug) - { - Info<< "Lookup ddtScheme for " << name << endl; - } - - if (ddtSchemes_.found(name) || defaultDdtScheme_.empty()) - { - return ddtSchemes_.lookup(name); - } - else - { - const_cast(defaultDdtScheme_).rewind(); - return const_cast(defaultDdtScheme_); - } + return lookupScheme(name, ddtSchemes_, defaultDdtScheme_); } Foam::ITstream& Foam::fvSchemes::d2dt2(const word& name) const { - if (debug) - { - Info<< "Lookup d2dt2Scheme for " << name << endl; - } - - if (d2dt2Schemes_.found(name) || defaultD2dt2Scheme_.empty()) - { - return d2dt2Schemes_.lookup(name); - } - else - { - const_cast(defaultD2dt2Scheme_).rewind(); - return const_cast(defaultD2dt2Scheme_); - } + return lookupScheme(name, d2dt2Schemes_, defaultD2dt2Scheme_); } Foam::ITstream& Foam::fvSchemes::interpolation(const word& name) const { - if (debug) - { - Info<< "Lookup interpolationScheme for " << name << endl; - } - - if + return lookupScheme ( - interpolationSchemes_.found(name) - || defaultInterpolationScheme_.empty() - ) - { - return interpolationSchemes_.lookup(name); - } - else - { - const_cast(defaultInterpolationScheme_).rewind(); - return const_cast(defaultInterpolationScheme_); - } + name, + interpolationSchemes_, + defaultInterpolationScheme_ + ); } Foam::ITstream& Foam::fvSchemes::div(const word& name) const { - if (debug) - { - Info<< "Lookup divScheme for " << name << endl; - } - - if (divSchemes_.found(name) || defaultDivScheme_.empty()) - { - return divSchemes_.lookup(name); - } - else - { - const_cast(defaultDivScheme_).rewind(); - return const_cast(defaultDivScheme_); - } + return lookupScheme(name, divSchemes_, defaultDivScheme_); } Foam::ITstream& Foam::fvSchemes::grad(const word& name) const { - if (debug) - { - Info<< "Lookup gradScheme for " << name << endl; - } - - if (gradSchemes_.found(name) || defaultGradScheme_.empty()) - { - return gradSchemes_.lookup(name); - } - else - { - const_cast(defaultGradScheme_).rewind(); - return const_cast(defaultGradScheme_); - } + return lookupScheme(name, gradSchemes_, defaultGradScheme_); } Foam::ITstream& Foam::fvSchemes::snGrad(const word& name) const { - if (debug) - { - Info<< "Lookup snGradScheme for " << name << endl; - } - - if (snGradSchemes_.found(name) || defaultSnGradScheme_.empty()) - { - return snGradSchemes_.lookup(name); - } - else - { - const_cast(defaultSnGradScheme_).rewind(); - return const_cast(defaultSnGradScheme_); - } + return lookupScheme(name, snGradSchemes_, defaultSnGradScheme_); } Foam::ITstream& Foam::fvSchemes::laplacian(const word& name) const { - if (debug) - { - Info<< "Lookup laplacianScheme for " << name << endl; - } - - if (laplacianSchemes_.found(name) || defaultLaplacianScheme_.empty()) - { - return laplacianSchemes_.lookup(name); - } - else - { - const_cast(defaultLaplacianScheme_).rewind(); - return const_cast(defaultLaplacianScheme_); - } + return lookupScheme(name, laplacianSchemes_, defaultLaplacianScheme_); } diff --git a/src/finiteVolume/finiteVolume/fvSchemes/fvSchemes.H b/src/finiteVolume/finiteVolume/fvSchemes/fvSchemes.H index f666a95b4e..53c7be8ac0 100644 --- a/src/finiteVolume/finiteVolume/fvSchemes/fvSchemes.H +++ b/src/finiteVolume/finiteVolume/fvSchemes/fvSchemes.H @@ -91,6 +91,19 @@ class fvSchemes //- Read settings from the dictionary void read(const dictionary&); + //- Filter group extensions + word filterGroup(const word& name) const; + + //- Lookup and return scheme for name from the schemes dictionary + // or return defaultScheme if defined. + // Wildcard lookup and group extension are enabled + ITstream& lookupScheme + ( + const word& name, + const dictionary& schemes, + const ITstream& defaultScheme + ) const; + public: diff --git a/tutorials/multiphase/multiphaseEulerFoam/laminar/bubbleColumn/system/fvSchemes b/tutorials/multiphase/multiphaseEulerFoam/laminar/bubbleColumn/system/fvSchemes index 45e7b3cf2c..777d7b8e7c 100644 --- a/tutorials/multiphase/multiphaseEulerFoam/laminar/bubbleColumn/system/fvSchemes +++ b/tutorials/multiphase/multiphaseEulerFoam/laminar/bubbleColumn/system/fvSchemes @@ -26,22 +26,19 @@ gradSchemes divSchemes { - default none; + default none; - div(phi,alpha.air) Gauss vanLeer; - div(phi,alpha.water) Gauss vanLeer; - div(phir,alpha.water,alpha.air) Gauss vanLeer; - div(phir,alpha.air,alpha.water) Gauss vanLeer; + div(phi,alpha) Gauss vanLeer; + div(phir,alpha,alpha) Gauss vanLeer; - "div\(alphaRhoPhi.*,U.*\)" Gauss limitedLinearV 1; - "div\(phi.*,U.*\)" Gauss limitedLinearV 1; + div(alphaRhoPhi,U) Gauss limitedLinearV 1; + div(phi,U) Gauss limitedLinearV 1; - "div\(alphaRhoPhi.*,(h|e).*\)" Gauss limitedLinear 1; - "div\(alphaRhoPhi.*,K.*\)" Gauss limitedLinear 1; - "div\(alphaRhoPhi.*,\(p\|rho.*\)\)" Gauss limitedLinear 1; - "div\(alphaRhoPhi.*,\(p\|rho.*\)\)" Gauss limitedLinear 1; + div(alphaRhoPhi,e) Gauss limitedLinear 1; + div(alphaRhoPhi,K) Gauss limitedLinear 1; + div(alphaRhoPhi,(p|rho)) Gauss limitedLinear 1; - "div\(\(\(\(alpha.*\*rho.*\)*nuEff.*\)\*dev2\(T\(grad\(U.*\)\)\)\)\)" Gauss linear; + div((((alpha*rho)*nuEff)*dev2(T(grad(U))))) Gauss linear; } laplacianSchemes