ENH: IOobject headerClassName now initialised to empty value

- was previously populated with "IOobject" (the typeName) but then
  cannot easily detect if the object was actually read.
  Also clear the headerClassName on a failed read

BUG: parallel inconsistency in regIOobject::readHeaderOk

- headerOk() checked with master, but possible parallel operations
  within it
This commit is contained in:
mattijs
2022-11-08 11:17:46 +00:00
committed by Mark Olesen
parent e401e8f132
commit 69be54107d
4 changed files with 17 additions and 15 deletions

View File

@ -272,18 +272,18 @@ void evaluate
); );
io.typeHeaderOk<IOobject>(false); io.typeHeaderOk<IOobject>(false);
oldFieldType = io.headerClassName(); if (!io.hasHeaderClass() || io.isHeaderClass<IOobject>())
if (oldFieldType == IOobject::typeName)
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Field " << fieldName << "(type: " << oldFieldType << "Field '" << fieldName
<< ") seems to be missing. Use 'create'" << nl << "' seems to be missing. Use 'create'" << nl
<< exit(FatalError); << exit(FatalError);
} }
oldFieldType = io.headerClassName();
Info<< "Modify field: " << fieldName Info<< "Modify field: " << fieldName
<< " (type " << oldFieldType << ')'; << " (type: " << oldFieldType << ')';
} }

View File

@ -321,7 +321,7 @@ Foam::IOobject::IOobject
sizeofScalar_(static_cast<unsigned char>(sizeof(scalar))), sizeofScalar_(static_cast<unsigned char>(sizeof(scalar))),
name_(name), name_(name),
headerClassName_(typeName), headerClassName_(),
note_(), note_(),
instance_(instance), instance_(instance),
local_(), local_(),
@ -331,8 +331,7 @@ Foam::IOobject::IOobject
if (objectRegistry::debug) if (objectRegistry::debug)
{ {
InfoInFunction InfoInFunction
<< "Constructing IOobject called " << name_ << "Constructing IOobject: " << name_ << endl;
<< " of type " << headerClassName_ << endl;
} }
} }
@ -352,7 +351,7 @@ Foam::IOobject::IOobject
sizeofScalar_(static_cast<unsigned char>(sizeof(scalar))), sizeofScalar_(static_cast<unsigned char>(sizeof(scalar))),
name_(name), name_(name),
headerClassName_(typeName), headerClassName_(),
note_(), note_(),
instance_(instance), instance_(instance),
local_(local), local_(local),
@ -362,8 +361,7 @@ Foam::IOobject::IOobject
if (objectRegistry::debug) if (objectRegistry::debug)
{ {
InfoInFunction InfoInFunction
<< "Constructing IOobject called " << name_ << "Constructing IOobject: " << name_ << endl;
<< " of type " << headerClassName_ << endl;
} }
} }
@ -381,7 +379,7 @@ Foam::IOobject::IOobject
sizeofScalar_(static_cast<unsigned char>(sizeof(scalar))), sizeofScalar_(static_cast<unsigned char>(sizeof(scalar))),
name_(), name_(),
headerClassName_(typeName), headerClassName_(),
note_(), note_(),
instance_(), instance_(),
local_(), local_(),
@ -398,8 +396,7 @@ Foam::IOobject::IOobject
if (objectRegistry::debug) if (objectRegistry::debug)
{ {
InfoInFunction InfoInFunction
<< "Constructing IOobject called " << name_ << "Constructing IOobject: " << name_ << endl;
<< " of type " << headerClassName_ << endl;
} }
} }

View File

@ -120,6 +120,9 @@ bool Foam::IOobject::readHeader(dictionary& headerDict, Istream& is)
writeHeader(Info); writeHeader(Info);
// Mark as not read
headerClassName_.clear();
return false; return false;
} }

View File

@ -60,7 +60,9 @@ bool Foam::regIOobject::readHeaderOk
{ {
if (Pstream::master()) if (Pstream::master())
{ {
const bool oldParRun = Pstream::parRun(false);
isHeaderOk = headerOk(); isHeaderOk = headerOk();
Pstream::parRun(oldParRun);
} }
Pstream::broadcast(isHeaderOk); Pstream::broadcast(isHeaderOk);
} }