ENH: portable scoping char for solver info names (#2224, #1675)

COMP: implicit cast scope name to C++-string in IOobject::scopedName

- handles 'const char*' and allows a check for an empty scope name

COMP: avoid potential name conflict in local function (Istream)

- reportedly some resolution issues (unconfirmed) with Fujitsu clang
This commit is contained in:
Mark Olesen
2021-11-09 09:27:26 +01:00
parent 9371c517b9
commit c45c649d15
6 changed files with 34 additions and 38 deletions

View File

@ -314,9 +314,12 @@ public:
static word member(const word& name); static word member(const word& name);
//- Create scope:name or scope_name string //- Create scope:name or scope_name string
// An empty scope or name is ignored. // An empty scope is ignored.
template<class StringType> static inline word scopedName
static inline word scopedName(StringType scope, const word& name); (
const std::string& scope,
const word& name
);
//- Return the IOobject, but also consider an alternative file name. //- Return the IOobject, but also consider an alternative file name.
// //

View File

@ -43,18 +43,13 @@ inline Foam::word Foam::IOobject::groupName
} }
template<class StringType>
inline Foam::word Foam::IOobject::scopedName inline Foam::word Foam::IOobject::scopedName
( (
StringType scope, const std::string& scope,
const word& name const word& name
) )
{ {
if (name.empty()) if (scope.empty())
{
return scope;
}
else if (scope.empty())
{ {
return name; return name;
} }

View File

@ -31,22 +31,18 @@ License
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace Foam namespace
{ {
// Return the current get position for std input stream
static inline std::streampos tellg(Istream* isptr)
{
ISstream* sptr = dynamic_cast<ISstream*>(isptr);
if (sptr) // The current get position (std::istream only)
{ inline std::streampos stream_tellg(Foam::Istream* isptr)
return sptr->stdStream().tellg(); {
} auto* sptr = dynamic_cast<Foam::ISstream*>(isptr);
return sptr ? sptr->stdStream().tellg() : std::streampos(0);
return 0;
}
} }
} // End anonymous namespace
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -141,7 +137,7 @@ bool Foam::Istream::readEnd(const char* funcName)
<< "Expected a '" << token::END_LIST << "Expected a '" << token::END_LIST
<< "' while reading " << funcName << "' while reading " << funcName
<< ", found " << delimiter.info() << ", found " << delimiter.info()
<< " at stream position " << tellg(this) << nl << " at stream position " << stream_tellg(this) << nl
<< exit(FatalIOError); << exit(FatalIOError);
} }
@ -182,7 +178,7 @@ char Foam::Istream::readEndList(const char* funcName)
<< "' or a '" << token::END_BLOCK << "' or a '" << token::END_BLOCK
<< "' while reading " << funcName << "' while reading " << funcName
<< ", found " << delimiter.info() << ", found " << delimiter.info()
<< " at stream position " << tellg(this) << nl << " at stream position " << stream_tellg(this) << nl
<< exit(FatalIOError); << exit(FatalIOError);
return '\0'; return '\0';

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd. Copyright (C) 2019-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -330,18 +330,13 @@ void Foam::lduMatrix::setResidualField
return; return;
} }
word lookupName;
if (initial)
{
lookupName = word("initialResidual:" + fieldName);
}
else
{
lookupName = word("residual:" + fieldName);
}
scalarIOField* residualPtr = scalarIOField* residualPtr =
mesh().thisDb().getObjectPtr<scalarIOField>(lookupName); mesh().thisDb().getObjectPtr<scalarIOField>
(
initial
? IOobject::scopedName("initialResidual", fieldName)
: IOobject::scopedName("residual", fieldName)
);
if (residualPtr) if (residualPtr)
{ {

View File

@ -484,7 +484,11 @@ Foam::functionObjects::stabilityBlendingFactor::stabilityBlendingFactor
), ),
residualName_ residualName_
( (
dict.getOrDefault<word>("residual", "initialResidual:p") dict.getOrDefault<word>
(
"residual",
IOobject::scopedName("initialResidual", "p")
)
), ),
UName_ UName_
( (

View File

@ -86,7 +86,10 @@ void Foam::functionObjects::solverInfo::createResidualField
return; return;
} }
const word residualName("initialResidual:" + fieldName); const word residualName
(
IOobject::scopedName("initialResidual", fieldName)
);
if (!mesh_.foundObject<IOField<scalar>>(residualName)) if (!mesh_.foundObject<IOField<scalar>>(residualName))
{ {