diff --git a/src/functionObjects/utilities/writeDictionary/writeDictionary.C b/src/functionObjects/utilities/writeDictionary/writeDictionary.C index 43531231e0..de17247d08 100644 --- a/src/functionObjects/utilities/writeDictionary/writeDictionary.C +++ b/src/functionObjects/utilities/writeDictionary/writeDictionary.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2013-2017 OpenFOAM Foundation @@ -51,10 +51,43 @@ namespace functionObjects // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // +void Foam::functionObjects::writeDictionary::writeHeader() +{ + if (firstChange_) + { + Info<< type() << " " << name() << " write:" << nl << endl; + + IOobject::writeDivider(Info); + Info<< endl; + firstChange_ = false; + } +} + + +void Foam::functionObjects::writeDictionary::checkDictionary +( + const dictionary& dict, + const label dicti +) +{ + if (dict.digest() != digests_[dicti]) + { + writeHeader(); + + digests_[dicti] = dict.digest(); + + Info<< dict.dictName() << dict << nl; + + IOobject::writeDivider(Info); + Info<< endl; + } +} + + bool Foam::functionObjects::writeDictionary::tryDirectory ( - const label dicti, - const word& location + const word& location, + const label dicti ) { IOobject dictIO @@ -69,17 +102,7 @@ bool Foam::functionObjects::writeDictionary::tryDirectory if (dictIO.typeHeaderOk(true)) { - IOdictionary dict(dictIO); - - if (dict.digest() != digests_[dicti]) - { - Info<< dict.dictName() << dict << nl; - - IOobject::writeDivider(Info); - Info<< endl; - - digests_[dicti] = dict.digest(); - } + checkDictionary(IOdictionary(dictIO), dicti); return true; } @@ -99,19 +122,14 @@ Foam::functionObjects::writeDictionary::writeDictionary : regionFunctionObject(name, runTime, dict), dictNames_(), - digests_() + digests_(), + firstChange_(true) { read(dict); execute(); } -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -Foam::functionObjects::writeDictionary::~writeDictionary() -{} - - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // bool Foam::functionObjects::writeDictionary::read(const dictionary& dict) @@ -150,47 +168,36 @@ bool Foam::functionObjects::writeDictionary::execute() bool Foam::functionObjects::writeDictionary::write() { - Info<< type() << " " << name() << " write:" << nl << endl; + firstChange_ = true; - IOobject::writeDivider(Info); - Info<< endl; - - forAll(dictNames_, i) + forAll(dictNames_, dicti) { const IOdictionary* dictptr = - obr_.lookupObjectPtr(dictNames_[i]); + obr_.lookupObjectPtr(dictNames_[dicti]); if (dictptr) { - const dictionary& dict = *dictptr; - - if (dict.digest() != digests_[i]) - { - digests_[i] = dict.digest(); - - Info<< dict.dictName() << dict << nl; - - IOobject::writeDivider(Info); - Info<< endl; - } + checkDictionary(*dictptr, dicti); } else { - bool processed = tryDirectory(i, obr_.time().timeName()); + bool processed = tryDirectory(obr_.time().timeName(), dicti); if (!processed) { - processed = tryDirectory(i, obr_.time().constant()); + processed = tryDirectory(obr_.time().constant(), dicti); } if (!processed) { - processed = tryDirectory(i, obr_.time().system()); + processed = tryDirectory(obr_.time().system(), dicti); } if (!processed) { - Info<< " Unable to locate dictionary " << dictNames_[i] + writeHeader(); + + Info<< " Unable to locate dictionary " << dictNames_[dicti] << nl << endl; IOobject::writeDivider(Info); diff --git a/src/functionObjects/utilities/writeDictionary/writeDictionary.H b/src/functionObjects/utilities/writeDictionary/writeDictionary.H index 66f44fd81d..c7e7d91a5c 100644 --- a/src/functionObjects/utilities/writeDictionary/writeDictionary.H +++ b/src/functionObjects/utilities/writeDictionary/writeDictionary.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2013-2016 OpenFOAM Foundation @@ -67,20 +67,21 @@ class writeDictionary //- List of changed dictionaries (only those registered to database) List digests_; + //- Flag to indicate the first time that a dictionary is been changed + //- (per call to execute) + bool firstChange_; + // Private Member Functions - //- Helper function to write the dictionary if found at location - bool tryDirectory - ( - const label dicti, - const word& location - ); + //- Write the output header + void writeHeader(); + //- Helper to check and write the dictionary if its sha1 has changed + void checkDictionary(const dictionary& dict, const label dicti); -private: - - // Private member functions + //- Helper to write the dictionary if found at location + bool tryDirectory(const word& location, const label dicti); //- No copy construct writeDictionary(const writeDictionary&) = delete; @@ -107,7 +108,7 @@ public: //- Destructor - virtual ~writeDictionary(); + virtual ~writeDictionary() = default; // Member Functions