From 9ab102bce36bcbd1eacfa12778880cbcd0fdee1d Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@Germany> Date: Wed, 8 Jun 2016 16:33:46 +0100 Subject: [PATCH] STYLE: reduce code duplication in Time.C --- src/OpenFOAM/db/Time/Time.C | 86 ++++++++++++------------------------- src/OpenFOAM/db/Time/Time.H | 5 ++- 2 files changed, 32 insertions(+), 59 deletions(-) diff --git a/src/OpenFOAM/db/Time/Time.C b/src/OpenFOAM/db/Time/Time.C index 4153ec823ae..59faf93c869 100644 --- a/src/OpenFOAM/db/Time/Time.C +++ b/src/OpenFOAM/db/Time/Time.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -333,6 +333,29 @@ void Foam::Time::setControls() } +void Foam::Time::setMonitoring() +{ + // Time objects not registered so do like objectRegistry::checkIn ourselves. + if (runTimeModifiable_) + { + monitorPtr_.reset + ( + new fileMonitor + ( + regIOobject::fileModificationChecking == inotify + || regIOobject::fileModificationChecking == inotifyMaster + ) + ); + + // Monitor all files that controlDict depends on + addWatches(controlDict_, controlDict_.files()); + } + + // Clear dependent files - not needed now + controlDict_.files().clear(); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::Time::Time @@ -401,25 +424,7 @@ Foam::Time::Time readOpt() = IOobject::MUST_READ_IF_MODIFIED; setControls(); - - // Time objects not registered so do like objectRegistry::checkIn ourselves. - if (runTimeModifiable_) - { - monitorPtr_.reset - ( - new fileMonitor - ( - regIOobject::fileModificationChecking == inotify - || regIOobject::fileModificationChecking == inotifyMaster - ) - ); - - // Monitor all files that controlDict depends on - addWatches(controlDict_, controlDict_.files()); - } - - // Clear dependent files - controlDict_.files().clear(); + setMonitoring(); } @@ -495,25 +500,7 @@ Foam::Time::Time readOpt() = IOobject::MUST_READ_IF_MODIFIED; setControls(); - - // Time objects not registered so do like objectRegistry::checkIn ourselves. - if (runTimeModifiable_) - { - monitorPtr_.reset - ( - new fileMonitor - ( - regIOobject::fileModificationChecking == inotify - || regIOobject::fileModificationChecking == inotifyMaster - ) - ); - - // Monitor all files that controlDict depends on - addWatches(controlDict_, controlDict_.files()); - } - - // Clear dependent files since not needed - controlDict_.files().clear(); + setMonitoring(); } @@ -588,25 +575,7 @@ Foam::Time::Time controlDict_.readOpt() = IOobject::MUST_READ_IF_MODIFIED; setControls(); - - // Time objects not registered so do like objectRegistry::checkIn ourselves. - if (runTimeModifiable_) - { - monitorPtr_.reset - ( - new fileMonitor - ( - regIOobject::fileModificationChecking == inotify - || regIOobject::fileModificationChecking == inotifyMaster - ) - ); - - // Monitor all files that controlDict depends on - addWatches(controlDict_, controlDict_.files()); - } - - // Clear dependent files since not needed - controlDict_.files().clear(); + setMonitoring(); } @@ -667,6 +636,7 @@ Foam::Time::Time functionObjects_(*this, enableFunctionObjects) { libs_.open(controlDict_, "libs"); + setMonitoring(); // for profiling etc } diff --git a/src/OpenFOAM/db/Time/Time.H b/src/OpenFOAM/db/Time/Time.H index cac8f2e02e8..24d7abee3f8 100644 --- a/src/OpenFOAM/db/Time/Time.H +++ b/src/OpenFOAM/db/Time/Time.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -181,6 +181,9 @@ protected: //- Set the controls from the current controlDict void setControls(); + //- Set file monitoring, profiling, etc + void setMonitoring(); + //- Read the control dictionary and set the write controls etc. virtual void readDict(); -- GitLab