mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
BUG: READ_IF_PRESENT: return false if not read. Fixes #3193
This commit is contained in:
@ -34,50 +34,38 @@ License
|
|||||||
template<class T, class BaseType>
|
template<class T, class BaseType>
|
||||||
bool Foam::CompactIOField<T, BaseType>::readIOcontents(bool readOnProc)
|
bool Foam::CompactIOField<T, BaseType>::readIOcontents(bool readOnProc)
|
||||||
{
|
{
|
||||||
if (readOpt() == IOobject::MUST_READ)
|
if (isReadRequired() || (isReadOptional() && headerOk()))
|
||||||
{
|
{
|
||||||
// Reading
|
// Do reading
|
||||||
}
|
Istream& is = readStream(word::null, readOnProc);
|
||||||
else if (isReadOptional())
|
|
||||||
{
|
if (readOnProc)
|
||||||
if (!headerOk())
|
|
||||||
{
|
{
|
||||||
readOnProc = false;
|
if (headerClassName() == IOField<T>::typeName)
|
||||||
|
{
|
||||||
|
is >> static_cast<Field<T>&>(*this);
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
else if (headerClassName() == typeName)
|
||||||
|
{
|
||||||
|
is >> *this;
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FatalIOErrorInFunction(is)
|
||||||
|
<< "Unexpected class name " << headerClassName()
|
||||||
|
<< " expected " << typeName
|
||||||
|
<< " or " << IOField<T>::typeName << nl
|
||||||
|
<< " while reading object " << name()
|
||||||
|
<< exit(FatalIOError);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
return true;
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
// Do reading
|
|
||||||
Istream& is = readStream(word::null, readOnProc);
|
|
||||||
|
|
||||||
if (readOnProc)
|
|
||||||
{
|
|
||||||
if (headerClassName() == IOField<T>::typeName)
|
|
||||||
{
|
|
||||||
is >> static_cast<Field<T>&>(*this);
|
|
||||||
close();
|
|
||||||
}
|
|
||||||
else if (headerClassName() == typeName)
|
|
||||||
{
|
|
||||||
is >> *this;
|
|
||||||
close();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
FatalIOErrorInFunction(is)
|
|
||||||
<< "Unexpected class name " << headerClassName()
|
|
||||||
<< " expected " << typeName
|
|
||||||
<< " or " << IOField<T>::typeName << nl
|
|
||||||
<< " while reading object " << name()
|
|
||||||
<< exit(FatalIOError);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -33,32 +33,20 @@ License
|
|||||||
template<class Type>
|
template<class Type>
|
||||||
bool Foam::IOField<Type>::readIOcontents(bool readOnProc)
|
bool Foam::IOField<Type>::readIOcontents(bool readOnProc)
|
||||||
{
|
{
|
||||||
if (isReadRequired())
|
if (isReadRequired() || (isReadOptional() && headerOk()))
|
||||||
{
|
{
|
||||||
// Reading
|
// Do reading
|
||||||
}
|
Istream& is = readStream(typeName, readOnProc);
|
||||||
else if (isReadOptional())
|
|
||||||
{
|
if (readOnProc)
|
||||||
if (!headerOk())
|
|
||||||
{
|
{
|
||||||
readOnProc = false;
|
is >> *this;
|
||||||
}
|
}
|
||||||
}
|
close();
|
||||||
else
|
return true;
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
// Do reading
|
|
||||||
Istream& is = readStream(typeName, readOnProc);
|
|
||||||
|
|
||||||
if (readOnProc)
|
|
||||||
{
|
|
||||||
is >> *this;
|
|
||||||
}
|
|
||||||
close();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2016-2017 OpenFOAM Foundation
|
Copyright (C) 2016-2017 OpenFOAM Foundation
|
||||||
Copyright (C) 2020 OpenCFD Ltd.
|
Copyright (C) 2020,2024 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -75,12 +75,15 @@ Foam::plenumPressureFvPatchScalarField::plenumPressureFvPatchScalarField
|
|||||||
supplyTotalTemperature_(dict.get<scalar>("supplyTotalTemperature")),
|
supplyTotalTemperature_(dict.get<scalar>("supplyTotalTemperature")),
|
||||||
plenumVolume_(dict.get<scalar>("plenumVolume")),
|
plenumVolume_(dict.get<scalar>("plenumVolume")),
|
||||||
plenumDensity_(dict.get<scalar>("plenumDensity")),
|
plenumDensity_(dict.get<scalar>("plenumDensity")),
|
||||||
|
plenumDensityOld_(1.0),
|
||||||
plenumTemperature_(dict.get<scalar>("plenumTemperature")),
|
plenumTemperature_(dict.get<scalar>("plenumTemperature")),
|
||||||
|
plenumTemperatureOld_(300.0),
|
||||||
rho_(1.0),
|
rho_(1.0),
|
||||||
hasRho_(false),
|
hasRho_(false),
|
||||||
inletAreaRatio_(dict.get<scalar>("inletAreaRatio")),
|
inletAreaRatio_(dict.get<scalar>("inletAreaRatio")),
|
||||||
inletDischargeCoefficient_(dict.get<scalar>("inletDischargeCoefficient")),
|
inletDischargeCoefficient_(dict.get<scalar>("inletDischargeCoefficient")),
|
||||||
timeScale_(dict.getOrDefault<scalar>("timeScale", 0)),
|
timeScale_(dict.getOrDefault<scalar>("timeScale", 0)),
|
||||||
|
timeIndex_(-1),
|
||||||
phiName_(dict.getOrDefault<word>("phi", "phi")),
|
phiName_(dict.getOrDefault<word>("phi", "phi")),
|
||||||
UName_(dict.getOrDefault<word>("U", "U"))
|
UName_(dict.getOrDefault<word>("U", "U"))
|
||||||
{
|
{
|
||||||
@ -103,12 +106,15 @@ Foam::plenumPressureFvPatchScalarField::plenumPressureFvPatchScalarField
|
|||||||
supplyTotalTemperature_(ptf.supplyTotalTemperature_),
|
supplyTotalTemperature_(ptf.supplyTotalTemperature_),
|
||||||
plenumVolume_(ptf.plenumVolume_),
|
plenumVolume_(ptf.plenumVolume_),
|
||||||
plenumDensity_(ptf.plenumDensity_),
|
plenumDensity_(ptf.plenumDensity_),
|
||||||
|
plenumDensityOld_(ptf.plenumDensityOld_),
|
||||||
plenumTemperature_(ptf.plenumTemperature_),
|
plenumTemperature_(ptf.plenumTemperature_),
|
||||||
|
plenumTemperatureOld_(ptf.plenumTemperatureOld_),
|
||||||
rho_(ptf.rho_),
|
rho_(ptf.rho_),
|
||||||
hasRho_(ptf.hasRho_),
|
hasRho_(ptf.hasRho_),
|
||||||
inletAreaRatio_(ptf.inletAreaRatio_),
|
inletAreaRatio_(ptf.inletAreaRatio_),
|
||||||
inletDischargeCoefficient_(ptf.inletDischargeCoefficient_),
|
inletDischargeCoefficient_(ptf.inletDischargeCoefficient_),
|
||||||
timeScale_(ptf.timeScale_),
|
timeScale_(ptf.timeScale_),
|
||||||
|
timeIndex_(ptf.timeIndex_),
|
||||||
phiName_(ptf.phiName_),
|
phiName_(ptf.phiName_),
|
||||||
UName_(ptf.UName_)
|
UName_(ptf.UName_)
|
||||||
{}
|
{}
|
||||||
@ -126,12 +132,15 @@ Foam::plenumPressureFvPatchScalarField::plenumPressureFvPatchScalarField
|
|||||||
supplyTotalTemperature_(tppsf.supplyTotalTemperature_),
|
supplyTotalTemperature_(tppsf.supplyTotalTemperature_),
|
||||||
plenumVolume_(tppsf.plenumVolume_),
|
plenumVolume_(tppsf.plenumVolume_),
|
||||||
plenumDensity_(tppsf.plenumDensity_),
|
plenumDensity_(tppsf.plenumDensity_),
|
||||||
|
plenumDensityOld_(tppsf.plenumDensityOld_),
|
||||||
plenumTemperature_(tppsf.plenumTemperature_),
|
plenumTemperature_(tppsf.plenumTemperature_),
|
||||||
|
plenumTemperatureOld_(tppsf.plenumTemperatureOld_),
|
||||||
rho_(tppsf.rho_),
|
rho_(tppsf.rho_),
|
||||||
hasRho_(tppsf.hasRho_),
|
hasRho_(tppsf.hasRho_),
|
||||||
inletAreaRatio_(tppsf.inletAreaRatio_),
|
inletAreaRatio_(tppsf.inletAreaRatio_),
|
||||||
inletDischargeCoefficient_(tppsf.inletDischargeCoefficient_),
|
inletDischargeCoefficient_(tppsf.inletDischargeCoefficient_),
|
||||||
timeScale_(tppsf.timeScale_),
|
timeScale_(tppsf.timeScale_),
|
||||||
|
timeIndex_(tppsf.timeIndex_),
|
||||||
phiName_(tppsf.phiName_),
|
phiName_(tppsf.phiName_),
|
||||||
UName_(tppsf.UName_)
|
UName_(tppsf.UName_)
|
||||||
{}
|
{}
|
||||||
@ -150,12 +159,15 @@ Foam::plenumPressureFvPatchScalarField::plenumPressureFvPatchScalarField
|
|||||||
supplyTotalTemperature_(tppsf.supplyTotalTemperature_),
|
supplyTotalTemperature_(tppsf.supplyTotalTemperature_),
|
||||||
plenumVolume_(tppsf.plenumVolume_),
|
plenumVolume_(tppsf.plenumVolume_),
|
||||||
plenumDensity_(tppsf.plenumDensity_),
|
plenumDensity_(tppsf.plenumDensity_),
|
||||||
|
plenumDensityOld_(tppsf.plenumDensityOld_),
|
||||||
plenumTemperature_(tppsf.plenumTemperature_),
|
plenumTemperature_(tppsf.plenumTemperature_),
|
||||||
|
plenumTemperatureOld_(tppsf.plenumTemperatureOld_),
|
||||||
rho_(tppsf.rho_),
|
rho_(tppsf.rho_),
|
||||||
hasRho_(tppsf.hasRho_),
|
hasRho_(tppsf.hasRho_),
|
||||||
inletAreaRatio_(tppsf.inletAreaRatio_),
|
inletAreaRatio_(tppsf.inletAreaRatio_),
|
||||||
inletDischargeCoefficient_(tppsf.inletDischargeCoefficient_),
|
inletDischargeCoefficient_(tppsf.inletDischargeCoefficient_),
|
||||||
timeScale_(tppsf.timeScale_),
|
timeScale_(tppsf.timeScale_),
|
||||||
|
timeIndex_(tppsf.timeIndex_),
|
||||||
phiName_(tppsf.phiName_),
|
phiName_(tppsf.phiName_),
|
||||||
UName_(tppsf.UName_)
|
UName_(tppsf.UName_)
|
||||||
{}
|
{}
|
||||||
|
|||||||
Reference in New Issue
Block a user