BUG: READ_IF_PRESENT: return false if not read. Fixes #3193

This commit is contained in:
Mattijs Janssens
2024-12-12 16:21:59 +00:00
parent ab30b0301c
commit aaaa80589f
3 changed files with 49 additions and 61 deletions

View File

@ -34,23 +34,8 @@ License
template<class T, class BaseType>
bool Foam::CompactIOField<T, BaseType>::readIOcontents(bool readOnProc)
{
if (readOpt() == IOobject::MUST_READ)
if (isReadRequired() || (isReadOptional() && headerOk()))
{
// Reading
}
else if (isReadOptional())
{
if (!headerOk())
{
readOnProc = false;
}
}
else
{
return false;
}
// Do reading
Istream& is = readStream(word::null, readOnProc);
@ -80,6 +65,9 @@ bool Foam::CompactIOField<T, BaseType>::readIOcontents(bool readOnProc)
return true;
}
return false;
}
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //

View File

@ -33,23 +33,8 @@ License
template<class Type>
bool Foam::IOField<Type>::readIOcontents(bool readOnProc)
{
if (isReadRequired())
if (isReadRequired() || (isReadOptional() && headerOk()))
{
// Reading
}
else if (isReadOptional())
{
if (!headerOk())
{
readOnProc = false;
}
}
else
{
return false;
}
// Do reading
Istream& is = readStream(typeName, readOnProc);
@ -61,6 +46,9 @@ bool Foam::IOField<Type>::readIOcontents(bool readOnProc)
return true;
}
return false;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020,2024 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -75,12 +75,15 @@ Foam::plenumPressureFvPatchScalarField::plenumPressureFvPatchScalarField
supplyTotalTemperature_(dict.get<scalar>("supplyTotalTemperature")),
plenumVolume_(dict.get<scalar>("plenumVolume")),
plenumDensity_(dict.get<scalar>("plenumDensity")),
plenumDensityOld_(1.0),
plenumTemperature_(dict.get<scalar>("plenumTemperature")),
plenumTemperatureOld_(300.0),
rho_(1.0),
hasRho_(false),
inletAreaRatio_(dict.get<scalar>("inletAreaRatio")),
inletDischargeCoefficient_(dict.get<scalar>("inletDischargeCoefficient")),
timeScale_(dict.getOrDefault<scalar>("timeScale", 0)),
timeIndex_(-1),
phiName_(dict.getOrDefault<word>("phi", "phi")),
UName_(dict.getOrDefault<word>("U", "U"))
{
@ -103,12 +106,15 @@ Foam::plenumPressureFvPatchScalarField::plenumPressureFvPatchScalarField
supplyTotalTemperature_(ptf.supplyTotalTemperature_),
plenumVolume_(ptf.plenumVolume_),
plenumDensity_(ptf.plenumDensity_),
plenumDensityOld_(ptf.plenumDensityOld_),
plenumTemperature_(ptf.plenumTemperature_),
plenumTemperatureOld_(ptf.plenumTemperatureOld_),
rho_(ptf.rho_),
hasRho_(ptf.hasRho_),
inletAreaRatio_(ptf.inletAreaRatio_),
inletDischargeCoefficient_(ptf.inletDischargeCoefficient_),
timeScale_(ptf.timeScale_),
timeIndex_(ptf.timeIndex_),
phiName_(ptf.phiName_),
UName_(ptf.UName_)
{}
@ -126,12 +132,15 @@ Foam::plenumPressureFvPatchScalarField::plenumPressureFvPatchScalarField
supplyTotalTemperature_(tppsf.supplyTotalTemperature_),
plenumVolume_(tppsf.plenumVolume_),
plenumDensity_(tppsf.plenumDensity_),
plenumDensityOld_(tppsf.plenumDensityOld_),
plenumTemperature_(tppsf.plenumTemperature_),
plenumTemperatureOld_(tppsf.plenumTemperatureOld_),
rho_(tppsf.rho_),
hasRho_(tppsf.hasRho_),
inletAreaRatio_(tppsf.inletAreaRatio_),
inletDischargeCoefficient_(tppsf.inletDischargeCoefficient_),
timeScale_(tppsf.timeScale_),
timeIndex_(tppsf.timeIndex_),
phiName_(tppsf.phiName_),
UName_(tppsf.UName_)
{}
@ -150,12 +159,15 @@ Foam::plenumPressureFvPatchScalarField::plenumPressureFvPatchScalarField
supplyTotalTemperature_(tppsf.supplyTotalTemperature_),
plenumVolume_(tppsf.plenumVolume_),
plenumDensity_(tppsf.plenumDensity_),
plenumDensityOld_(tppsf.plenumDensityOld_),
plenumTemperature_(tppsf.plenumTemperature_),
plenumTemperatureOld_(tppsf.plenumTemperatureOld_),
rho_(tppsf.rho_),
hasRho_(tppsf.hasRho_),
inletAreaRatio_(tppsf.inletAreaRatio_),
inletDischargeCoefficient_(tppsf.inletDischargeCoefficient_),
timeScale_(tppsf.timeScale_),
timeIndex_(tppsf.timeIndex_),
phiName_(tppsf.phiName_),
UName_(tppsf.UName_)
{}