ENH: more consistent use of endEntry (issue #3035)

- enables capturing of end entry as an event
This commit is contained in:
Mark Olesen
2023-12-04 11:30:00 +00:00
parent 2de1a26c7b
commit 09fdeaa38a
24 changed files with 145 additions and 115 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016 Shell Research Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -203,9 +203,9 @@ static inline scalar averageSurrounding
template<class Type>
static inline Ostream& putUniform(Ostream& os, const word& key, const Type& val)
{
os.writeKeyword(key)
<< word("uniform") << token::SPACE
<< val << token::END_STATEMENT << nl;
os.writeKeyword(key);
os << word("uniform") << token::SPACE << val;
os.endEntry();
return os;
}
@ -1153,7 +1153,7 @@ static void tail_field
// ground
{
os.beginBlock(pars.groundPatchName);
os.writeKeyword("type") << wall_bc << token::END_STATEMENT << nl;
os.writeEntry("type", wall_bc);
putUniform(os, "value", deflt);
os.endBlock();
}
@ -1170,7 +1170,7 @@ static void tail_field
// No wall functions for blockedFaces patch unless selected
if (pars.blockedFacesWallFn)
{
os.writeKeyword("type") << wall_bc << token::END_STATEMENT << nl;
os.writeEntry("type", wall_bc);
putUniform(os, "value", deflt);
}
else
@ -1184,7 +1184,7 @@ static void tail_field
{
os.beginBlock(patchName);
os.writeKeyword("type") << wall_bc << token::END_STATEMENT << nl;
os.writeEntry("type", wall_bc);
putUniform(os, "value", deflt);
os.endBlock();
@ -1192,7 +1192,7 @@ static void tail_field
else
{
os.beginBlock(word(patchName + "Wall"));
os.writeKeyword("type") << wall_bc << token::END_STATEMENT << nl;
os.writeEntry("type", wall_bc);
putUniform(os, "value", deflt);
os.endBlock();
@ -1266,7 +1266,7 @@ void write_scalarField
os << nl;
os.writeKeyword("internalField")
<< "nonuniform List<scalar>" << nl
<< word("nonuniform") << token::SPACE << word("List<scalar>") << nl
<< meshIndexing.nCells() << nl << token::BEGIN_LIST << nl;
for (label celli=0; celli < meshIndexing.nCells(); ++celli)
@ -1282,7 +1282,8 @@ void write_scalarField
os << limits.clamp(fld(cellIdx)) << nl;
}
os << token::END_LIST << token::END_STATEMENT << nl;
os << token::END_LIST;
os.endEntry();
os << nl;
os.beginBlock("boundaryField");
@ -1400,8 +1401,7 @@ void write_pU_fields
for (label patchi = 0; patchi < 3; ++patchi)
{
os.beginBlock(patches[patchi].patchName);
os.writeKeyword("type") << pars.UPatchBc.c_str()
<< token::END_STATEMENT << nl;
os.writeEntry("type", pars.UPatchBc.c_str());
os.endBlock();
}
@ -1543,7 +1543,7 @@ void write_symmTensorField
os << nl;
os.writeKeyword("internalField")
<< "nonuniform List<symmTensor>" << nl
<< word("nonuniform") << token::SPACE << word("List<symmTensor>") << nl
<< meshIndexing.nCells() << nl << token::BEGIN_LIST << nl;
for (label celli=0; celli < meshIndexing.nCells(); ++celli)
@ -1558,7 +1558,8 @@ void write_symmTensorField
os << fld(cellIdx) << nl;
}
os << token::END_LIST << token::END_STATEMENT << nl;
os << token::END_LIST;
os.endEntry();
os << nl;
os.beginBlock("boundaryField");
@ -1603,7 +1604,7 @@ void write_symmTensorFieldV
os << nl;
os.writeKeyword("internalField")
<< "nonuniform List<symmTensor>" << nl
<< word("nonuniform") << token::SPACE << word("List<symmTensor>") << nl
<< meshIndexing.nCells() << nl << token::BEGIN_LIST << nl;
symmTensor val(symmTensor::zero);
@ -1626,7 +1627,8 @@ void write_symmTensorFieldV
os << val << nl;
}
os << token::END_LIST << token::END_STATEMENT << nl;
os << token::END_LIST;
os.endEntry();
os << nl;
os.beginBlock("boundaryField");
@ -1878,7 +1880,9 @@ void write_blocked_face_list
}
}
os << token::END_LIST << token::END_STATEMENT << nl << nl;
os << token::END_LIST;
os.endEntry() << nl;
os.beginBlock("coupledFaces");
for (const PDRpatchDef& p : patches)
@ -1901,8 +1905,10 @@ void write_blocked_face_list
IOobject::writeEndDivider(os);
// Write panelList
OFstream(casepath / "panelList")()
<< panelNames << token::END_STATEMENT << nl;
OFstream os2(casepath / "panelList");
os2<< panelNames;
os2.endEntry();
}
}
@ -2000,7 +2006,7 @@ void write_blockedCellsSet
os << labelList();
}
os << token::END_STATEMENT << nl;
os.endEntry();
IOobject::writeEndDivider(os);
}

View File

@ -251,7 +251,7 @@ void Foam::PackedList<Width>::writeEntry
os.writeKeyword(keyword);
}
writeEntry(os);
os << token::END_STATEMENT << endl;
os.endEntry();
}

View File

@ -73,7 +73,7 @@ void Foam::FixedList<T, N>::writeEntry
os.writeKeyword(keyword);
}
writeEntry(os);
os << token::END_STATEMENT << endl;
os.endEntry();
}

View File

@ -74,7 +74,7 @@ void Foam::UList<T>::writeEntry(const word& keyword, Ostream& os) const
os.writeKeyword(keyword);
}
writeEntry(os);
os << token::END_STATEMENT << endl;
os.endEntry();
}

View File

@ -309,7 +309,7 @@ void Foam::primitiveEntry::write(Ostream& os, const bool contentsOnly) const
if (!contentsOnly)
{
os << token::END_STATEMENT << endl;
os.endEntry();
}
}

View File

@ -544,6 +544,8 @@ void Foam::dimensioned<Type>::writeEntry
Ostream& os
) const
{
if (keyword.size())
{
os.writeKeyword(keyword);
if (keyword != name_)
@ -551,13 +553,20 @@ void Foam::dimensioned<Type>::writeEntry
// The name, only if different from keyword
os << name_ << token::SPACE;
}
}
else
{
// Use the name (no keyword provided)
os.writeKeyword(name_);
}
// The dimensions
scalar mult{1};
dimensions_.write(os, mult);
// The value
os << token::SPACE << value_/mult << token::END_STATEMENT << endl;
os << token::SPACE << value_/mult;
os.endEntry();
os.check(FUNCTION_NAME);
}

View File

@ -520,8 +520,8 @@ bool Foam::expressions::exprResult::writeEntryChecked
{
os.writeKeyword(keyword);
}
os << word("uniform") << token::SPACE
<< val << token::END_STATEMENT << nl;
os << word("uniform") << token::SPACE << val;
os.endEntry();
}
else
{
@ -540,8 +540,8 @@ bool Foam::expressions::exprResult::writeEntryChecked
{
os.writeKeyword(keyword);
}
os << word("uniform") << token::SPACE
<< fld.front() << token::END_STATEMENT << nl;
os << word("uniform") << token::SPACE << fld.front();
os.endEntry();
}
else
{

View File

@ -744,7 +744,7 @@ void Foam::Field<Type>::writeEntry(const word& keyword, Ostream& os) const
List<Type>::writeEntry(os);
}
os << token::END_STATEMENT << nl;
os.endEntry();
}

View File

@ -139,7 +139,8 @@ bool Foam::UniformDimensionedField<Type>::writeData(Ostream& os) const
// The dimensions
scalar multiplier(1);
os.writeKeyword("dimensions");
this->dimensions().write(os, multiplier) << token::END_STATEMENT << nl;
this->dimensions().write(os, multiplier);
os.endEntry();
// The value
os.writeEntry("value", this->value()/multiplier) << nl;

View File

@ -139,8 +139,8 @@ void Foam::patchIdentifier::write(Ostream& os) const
if (!inGroups_.empty())
{
os.writeKeyword("inGroups");
// Flat output of list
inGroups_.writeList(os, 0) << token::END_STATEMENT << nl;
inGroups_.writeList(os, 0); // Flat output
os.endEntry();
}
}

View File

@ -138,8 +138,8 @@ void Foam::zoneIdentifier::write(Ostream& os) const
if (!inGroups_.empty())
{
os.writeKeyword("inGroups");
// Flat output of list
inGroups_.writeList(os, 0) << token::END_STATEMENT << nl;
inGroups_.writeList(os, 0); // Flat output
os.endEntry();
}
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2022 OpenCFD Ltd.
Copyright (C) 2022-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -68,7 +68,8 @@ static void writeMaps(Ostream& os, const word& key, const labelListList& maps)
else
{
os << indent << key;
printMaps(os, maps) << token::END_STATEMENT << nl;
printMaps(os, maps);
os.endEntry();
}
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020-2022 OpenCFD Ltd.
Copyright (C) 2020-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -459,22 +459,19 @@ void Foam::layerAdditionRemoval::write(Ostream& os) const
void Foam::layerAdditionRemoval::writeDict(Ostream& os) const
{
os << nl << name() << nl << token::BEGIN_BLOCK << nl
<< " type " << type()
<< token::END_STATEMENT << nl
<< " faceZoneName " << faceZoneID_.name()
<< token::END_STATEMENT << nl
<< " minLayerThickness " << minLayerThickness_
<< token::END_STATEMENT << nl
<< " maxLayerThickness " << maxLayerThickness_
<< token::END_STATEMENT << nl
<< " thicknessFromVolume " << thicknessFromVolume_
<< token::END_STATEMENT << nl
<< " oldLayerThickness " << oldLayerThickness_
<< token::END_STATEMENT << nl
<< " active " << active()
<< token::END_STATEMENT << nl
<< token::END_BLOCK << endl;
os << nl;
os.beginBlock(name());
os.writeEntry("type", type());
os.writeEntry("faceZoneName", faceZoneID_.name());
os.writeEntry("minLayerThickness", minLayerThickness_);
os.writeEntry("maxLayerThickness", maxLayerThickness_);
os.writeEntry("thicknessFromVolume", thicknessFromVolume_);
os.writeEntry("oldLayerThickness", oldLayerThickness_);
os.writeEntry("active", active());
os.endBlock();
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020-2022 OpenCFD Ltd.
Copyright (C) 2020-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -749,11 +749,9 @@ void Foam::slidingInterface::write(Ostream& os) const
// To write out all those tolerances
#undef WRITE_NON_DEFAULT
#define WRITE_NON_DEFAULT(name) \
if ( name ## _ != name ## Default_ )\
{ \
os << " " #name " " << name ## _ << token::END_STATEMENT << nl; \
}
if ( name ## _ != name ## Default_ ) os.writeEntry( #name , name ## _ );
void Foam::slidingInterface::writeDict(Ostream& os) const
@ -795,6 +793,8 @@ void Foam::slidingInterface::writeDict(Ostream& os) const
WRITE_NON_DEFAULT(edgeCoPlanarTol)
WRITE_NON_DEFAULT(edgeEndCutoffTol)
#undef WRITE_NON_DEFAULT
os.endBlock();
}

View File

@ -72,11 +72,12 @@ Foam::enginePiston::enginePiston
void Foam::enginePiston::writeDict(Ostream& os) const
{
os << nl << token::BEGIN_BLOCK
<< "patch " << patchID_.name() << token::END_STATEMENT << nl
<< "minLayer " << minLayer_ << token::END_STATEMENT << nl
<< "maxLayer " << maxLayer_ << token::END_STATEMENT << nl
<< token::END_BLOCK << endl;
os << nl;
os.beginBlock();
os.writeEntry("patch", patchID_.name());
os.writeEntry("minLayer", minLayer_);
os.writeEntry("maxLayer", maxLayer_);
os.endBlock();
}

View File

@ -242,34 +242,35 @@ Foam::labelList Foam::engineValve::movingPatchIDs() const
void Foam::engineValve::writeDict(Ostream& os) const
{
os << nl << name() << nl << token::BEGIN_BLOCK;
os << nl;
os.beginBlock(name());
if (csysPtr_)
{
csysPtr_->writeEntry(os);
}
os << "bottomPatch " << bottomPatch_.name() << token::END_STATEMENT << nl
<< "poppetPatch " << poppetPatch_.name() << token::END_STATEMENT << nl
<< "stemPatch " << stemPatch_.name() << token::END_STATEMENT << nl
<< "curtainInPortPatch " << curtainInPortPatch_.name()
<< token::END_STATEMENT << nl
<< "curtainInCylinderPatch " << curtainInCylinderPatch_.name()
<< token::END_STATEMENT << nl
<< "detachInCylinderPatch " << detachInCylinderPatch_.name()
<< token::END_STATEMENT << nl
<< "detachInPortPatch " << detachInPortPatch_.name()
<< token::END_STATEMENT << nl
<< "detachFaces " << detachFaces_ << token::END_STATEMENT << nl
<< "liftProfile " << nl << token::BEGIN_BLOCK
<< liftProfile_ << token::END_BLOCK << token::END_STATEMENT << nl
<< "minLift " << minLift_ << token::END_STATEMENT << nl
<< "minTopLayer " << minTopLayer_ << token::END_STATEMENT << nl
<< "maxTopLayer " << maxTopLayer_ << token::END_STATEMENT << nl
<< "minBottomLayer " << minBottomLayer_ << token::END_STATEMENT << nl
<< "maxBottomLayer " << maxBottomLayer_ << token::END_STATEMENT << nl
<< "diameter " << diameter_ << token::END_STATEMENT << nl
<< token::END_BLOCK << endl;
os.writeEntry("bottomPatch", bottomPatch_.name());
os.writeEntry("poppetPatch", poppetPatch_.name());
os.writeEntry("stemPatch", stemPatch_.name());
os.writeEntry("curtainInPortPatch", curtainInPortPatch_.name());
os.writeEntry("curtainInCylinderPatch", curtainInCylinderPatch_.name());
os.writeEntry("detachInCylinderPatch", detachInCylinderPatch_.name());
os.writeEntry("detachInPortPatch", detachInPortPatch_.name());
os.writeEntry("detachFaces", detachFaces_);
os << "liftProfile" << nl << token::BEGIN_LIST
<< liftProfile_ << token::END_LIST;
os.endEntry();
os.writeEntry("minLift", minLift_);
os.writeEntry("minTopLayer", minTopLayer_);
os.writeEntry("maxTopLayer", maxTopLayer_);
os.writeEntry("minBottomLayer", minBottomLayer_);
os.writeEntry("maxBottomLayer", maxBottomLayer_);
os.writeEntry("diameter", diameter_);
os.endBlock();
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2022 OpenCFD Ltd.
Copyright (C) 2016-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -109,7 +109,8 @@ static void writeList(Ostream& os, const string& header, const UList<T>& list)
}
// Write end delimiter
os << token::END_LIST << token::END_STATEMENT << nl << nl;
os << token::END_LIST;
os.endEntry() << nl;
}
//! \endcond

View File

@ -573,7 +573,8 @@ Foam::Ostream& Foam::PDRblock::blockMeshDict
}
}
endIndentList(os) << token::END_STATEMENT << nl;
endIndentList(os);
os.endEntry();
}
@ -658,7 +659,8 @@ Foam::Ostream& Foam::PDRblock::blockMeshDict
}
}
endIndentList(os) << token::END_STATEMENT << nl;
endIndentList(os);
os.endEntry();
}
@ -686,7 +688,8 @@ Foam::Ostream& Foam::PDRblock::blockMeshDict
}
}
endIndentList(os) << token::END_STATEMENT << nl;
endIndentList(os);
os.endEntry();
}
@ -707,7 +710,8 @@ Foam::Ostream& Foam::PDRblock::blockMeshDict
}
}
endIndentList(os) << token::END_STATEMENT << nl;
endIndentList(os);
os.endEntry();
}
@ -733,7 +737,8 @@ Foam::Ostream& Foam::PDRblock::blockMeshDict
);
}
endIndentList(os) << token::END_STATEMENT << nl;
endIndentList(os);
os.endEntry();
os.endBlock();
}
@ -755,11 +760,14 @@ Foam::Ostream& Foam::PDRblock::blockMeshDict
);
}
endIndentList(os) << token::END_STATEMENT << nl;
endIndentList(os);
os.endEntry();
os.endBlock();
}
endIndentList(os) << token::END_STATEMENT << nl;
endIndentList(os);
os.endEntry();
}

View File

@ -243,14 +243,14 @@ void Foam::PDRblock::gridControl::writeDict
const scalarList& knots = *this;
os << indent << "points "
<< flatOutput(knots) << token::END_STATEMENT << nl;
os << indent << "points " << flatOutput(knots);
os.endEntry();
os << indent << "nCells "
<< flatOutput(divisions_) << token::END_STATEMENT << nl;
os << indent << "nCells " << flatOutput(divisions_);
os.endEntry();
os << indent << "ratios "
<< flatOutput(expansion_) << token::END_STATEMENT << nl;
os << indent << "ratios " << flatOutput(expansion_);
os.endEntry();
if (cmpt < vector::nComponents)
{

View File

@ -42,7 +42,8 @@ inline Ostream& operator<<
)
{
OStringStream reaction;
os << r.solidReactionStr(reaction) << token::END_STATEMENT <<nl;
os << r.solidReactionStr(reaction);
os.endEntry();
return os;
}

View File

@ -105,7 +105,8 @@ bool Foam::surfaceTensionModels::constant::writeData(Ostream& os) const
{
if (surfaceTensionModel::writeData(os))
{
os << sigma_ << token::END_STATEMENT << nl;
os << sigma_;
os.endEntry();
return os.good();
}

View File

@ -125,7 +125,8 @@ bool Foam::surfaceTensionModels::temperatureDependent::writeData
{
if (surfaceTensionModel::writeData(os))
{
os << sigma_() << token::END_STATEMENT << nl;
os << sigma_();
os.endEntry();
return os.good();
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020-2021 OpenCFD Ltd.
Copyright (C) 2020-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -469,7 +469,7 @@ int main(int argc, char *argv[])
os.writeEntry("degrees", "false");
os << nl;
os << "response" << nl;
os << '(' << nl;
os << token::BEGIN_LIST << nl;
}
else
{
@ -511,7 +511,8 @@ int main(int argc, char *argv[])
{
auto& os = *osPtr;
os << ')' << token::END_STATEMENT << nl;
os << token::END_LIST;
os.endEntry();
IOobject::writeEndDivider(os);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020-2021 OpenCFD Ltd.
Copyright (C) 2020-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -516,7 +516,7 @@ int main(int argc, char *argv[])
os.writeEntry("degrees", "false");
os << nl;
os << "response" << nl;
os << '(' << nl;
os << token::BEGIN_LIST << nl;
}
else
{
@ -558,7 +558,8 @@ int main(int argc, char *argv[])
{
auto& os = *osPtr;
os << ')' << token::END_STATEMENT << nl;
os << token::END_LIST;
os.endEntry();
IOobject::writeEndDivider(os);