From 7fe531bde5dace6af46a4436fe69d87cf3490c02 Mon Sep 17 00:00:00 2001
From: Andrew Heather <a.heather@opencfd.co.uk>
Date: Tue, 1 Dec 2015 15:22:13 +0000
Subject: [PATCH] ENH: OutputFilter function object updates from internal
 development line

---
 .../OutputFilterFunctionObject.C              | 25 ++++++++++++++++---
 .../OutputFilterFunctionObject.H              | 11 +++++++-
 2 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/src/OpenFOAM/db/functionObjects/OutputFilterFunctionObject/OutputFilterFunctionObject.C b/src/OpenFOAM/db/functionObjects/OutputFilterFunctionObject/OutputFilterFunctionObject.C
index 100e88f27f1..9590eb153c5 100644
--- a/src/OpenFOAM/db/functionObjects/OutputFilterFunctionObject/OutputFilterFunctionObject.C
+++ b/src/OpenFOAM/db/functionObjects/OutputFilterFunctionObject/OutputFilterFunctionObject.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011-2014 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2015 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -47,10 +47,14 @@ void Foam::OutputFilterFunctionObject<OutputFilter>::readDict()
 template<class OutputFilter>
 bool Foam::OutputFilterFunctionObject<OutputFilter>::active() const
 {
+    // The logic here mimics that of Time itself and uses 0.5*deltaT
+    // as the tolerance to account for numerical precision errors
+    // (see e.g. Time::run()) since the current time might be e.g.
+    // 0.3000000000001 instead of exactly 0.3.
     return
         enabled_
-     && time_.value() >= timeStart_
-     && time_.value() <= timeEnd_;
+     && time_.value() >= (timeStart_ - 0.5*time_.deltaTValue())
+     && time_.value() <= (timeEnd_ + 0.5*time_.deltaTValue());
 }
 
 
@@ -179,6 +183,13 @@ bool Foam::OutputFilterFunctionObject<OutputFilter>::execute
             destroyFilter();
         }
     }
+    else if (enabled_ && time_.value() > timeEnd_)
+    {
+        // End early if the time is controlled by the user timeEnd entry
+        end();
+
+        enabled_ = false;
+    }
 
     return true;
 }
@@ -196,7 +207,10 @@ bool Foam::OutputFilterFunctionObject<OutputFilter>::end()
 
         ptr_->end();
 
-        if (outputControl_.output())
+        // Only write if
+        // - time within timeStart_ and timeEnd_
+        // - it is an output time
+        if (active() && outputControl_.output())
         {
             ptr_->write();
         }
@@ -236,6 +250,9 @@ bool Foam::OutputFilterFunctionObject<OutputFilter>::adjustTimeStep()
         const label  outputTimeIndex = outputControl_.outputTimeLastDump();
         const scalar writeInterval = outputControl_.writeInterval();
 
+        // Logic mimics that of Time::adjustDeltaT() except we only allow
+        // making the time step lower.
+
         scalar timeToNextWrite = max
         (
             0.0,
diff --git a/src/OpenFOAM/db/functionObjects/OutputFilterFunctionObject/OutputFilterFunctionObject.H b/src/OpenFOAM/db/functionObjects/OutputFilterFunctionObject/OutputFilterFunctionObject.H
index 6e874dc52af..3b54ebc779e 100644
--- a/src/OpenFOAM/db/functionObjects/OutputFilterFunctionObject/OutputFilterFunctionObject.H
+++ b/src/OpenFOAM/db/functionObjects/OutputFilterFunctionObject/OutputFilterFunctionObject.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011-2013 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2015 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -34,6 +34,15 @@ Note
     writeInterval to be degrees crank angle, but the functionObject
     execution \a interval would still be in timestep.
 
+    The function object can be limited to operate within a time range using
+    the timeStart and timEnd options.  All objects are read (and the
+    OutputFilter allocated) on construction.  However, if a timeEnd is
+    supplied, the object will call the 'end' function of the filter
+    at the timeEnd time and destroy the filter.
+    Any other callback (execute(), write(), timeSet() etc) will only operate
+    if within the timeStart, timeEnd time range. Note that the time range
+    uses 0.5 * deltaT as a comparison tolerance to account for precision errors.
+
 SourceFiles
     OutputFilterFunctionObject.C
 
-- 
GitLab