View Issue Details

IDProjectCategoryView StatusLast Update
0001653OpenFOAMBugpublic2015-05-05 19:33
Reporterdkxls Assigned Tohenry  
PriorityhighSeveritymajorReproducibilityhave not tried
Status resolvedResolutionfixed 
PlatformGNU/LinuxOSOpenSuSEOS Version13.2
Summary0001653: [fieldAverage]: totalTime/totalIter are not reset if resetOnOutput is true
DescriptionTo my understanding the resetOnOutput is used to obtain short-time averages, i.e. quantities are averaged between two output times.
Hence, the totalTime/totalIter should be reset together with the mean/prime2Mean fields after each output. The totalTime/totalIter are currently only set/reset on restart and not at output time.
Additional InformationThis seems to be handled correctly in version 2.1.x and the change happened in the 2.2.x source tree related to this bug:
http://www.openfoam.org/mantisbt/view.php?id=854
TagsNo tags attached.

Activities

henry

2015-04-08 17:38

manager   ~0004579

Can you provide a patch for this fix?

dkxls

2015-04-09 14:21

reporter   ~0004589

I uploaded 2 patches, the first one resets the counters when the mean/prime2Mean are written out. This should fix the original problem.

I also realised that in certain cases (i.e. a restarted run with resetOnOutput) the old field might be falsely read on initialization. The second patch provides a fix for that, though the code gets more and more cluttered.

The code compiles, but I haven't had time to test it (and I unfortunately won't have time to do that this week).

dkxls

2015-04-09 14:22

reporter  

0001-fieldAverage.C-Reset-totalIter_-totalTime_-if-resetO.patch (1,670 bytes)   
From 7c864a35e999176d406e9426239b979b8a642d9c Mon Sep 17 00:00:00 2001
From: Armin Wehrfritz <armin.wehrfritz@aalto.fi>
Date: Thu, 9 Apr 2015 15:37:20 +0300
Subject: [PATCH 1/2] fieldAverage.C - Reset totalIter_ & totalTime_ if
 resetOnOutput_

---
 .../field/fieldAverage/fieldAverage/fieldAverage.C            | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/postProcessing/functionObjects/field/fieldAverage/fieldAverage/fieldAverage.C b/src/postProcessing/functionObjects/field/fieldAverage/fieldAverage/fieldAverage.C
index 251b9d3..83c259e 100644
--- a/src/postProcessing/functionObjects/field/fieldAverage/fieldAverage/fieldAverage.C
+++ b/src/postProcessing/functionObjects/field/fieldAverage/fieldAverage/fieldAverage.C
@@ -195,7 +195,7 @@ void Foam::fieldAverage::readAveragingProperties()
     totalTime_.clear();
     totalTime_.setSize(faItems_.size(), obr_.time().deltaTValue());
 
-    if (resetOnRestart_)
+    if (resetOnRestart_ || resetOnOutput_)
     {
         Info<< "    Starting averaging at time " << obr_.time().timeName()
             << nl;
@@ -348,10 +348,13 @@ void Foam::fieldAverage::write()
             Info<< "    Restarting averaging at time " << obr_.time().timeName()
                 << nl << endl;
 
-            initialize();
+            totalIter_.clear();
+            totalIter_.setSize(faItems_.size(), 1);
+
+            totalTime_.clear();
+            totalTime_.setSize(faItems_.size(), obr_.time().deltaTValue());
 
-            // ensure first averaging works unconditionally
-            prevTimeIndex_ = -1;
+            initialize();
         }
 
         Info<< endl;
-- 
2.1.4

dkxls

2015-04-09 14:22

reporter  

0002-fieldAverageTemplates.C-NO_READ-for-mean-prime2Mean-.patch (4,255 bytes)   
From 9986ef70da49f0ca23ceaf763321e1a53030fc28 Mon Sep 17 00:00:00 2001
From: Armin Wehrfritz <armin.wehrfritz@aalto.fi>
Date: Thu, 9 Apr 2015 15:40:50 +0300
Subject: [PATCH 2/2] fieldAverageTemplates.C - NO_READ for mean & prime2Mean
 if resetOnOutput_

---
 .../fieldAverage/fieldAverageTemplates.C           | 99 ++++++++++++++++------
 1 file changed, 72 insertions(+), 27 deletions(-)

diff --git a/src/postProcessing/functionObjects/field/fieldAverage/fieldAverage/fieldAverageTemplates.C b/src/postProcessing/functionObjects/field/fieldAverage/fieldAverage/fieldAverageTemplates.C
index 00b4c9e..788f3fb 100644
--- a/src/postProcessing/functionObjects/field/fieldAverage/fieldAverage/fieldAverageTemplates.C
+++ b/src/postProcessing/functionObjects/field/fieldAverage/fieldAverage/fieldAverageTemplates.C
@@ -56,22 +56,44 @@ void Foam::fieldAverage::addMeanFieldType(const label fieldI)
     {
         const Type& baseField = obr_.lookupObject<Type>(fieldName);
 
-        // Store on registry
-        obr_.store
-        (
-            new Type
+        if (resetOnOutput_)
+        {
+            // Store on registry
+            obr_.store
             (
-                IOobject
+                new Type
                 (
-                    meanFieldName,
-                    obr_.time().timeName(obr_.time().startTime().value()),
-                    obr_,
-                    IOobject::READ_IF_PRESENT,
-                    IOobject::NO_WRITE
-                ),
-                1*baseField
-            )
-        );
+                    IOobject
+                    (
+                        meanFieldName,
+                        obr_.time().timeName(),
+                        obr_,
+                        IOobject::NO_READ,
+                        IOobject::NO_WRITE
+                    ),
+                    1*baseField
+                )
+            );
+        }
+        else
+        {
+            // Store on registry
+            obr_.store
+            (
+                new Type
+                (
+                    IOobject
+                    (
+                        meanFieldName,
+                        obr_.time().timeName(obr_.time().startTime().value()),
+                        obr_,
+                        IOobject::READ_IF_PRESENT,
+                        IOobject::NO_WRITE
+                    ),
+                    1*baseField
+                )
+            );
+        }
     }
 }
 
@@ -124,21 +146,44 @@ void Foam::fieldAverage::addPrime2MeanFieldType(const label fieldI)
         const Type1& baseField = obr_.lookupObject<Type1>(fieldName);
         const Type1& meanField = obr_.lookupObject<Type1>(meanFieldName);
 
-        obr_.store
-        (
-            new Type2
+        if (resetOnOutput_)
+        {
+            // Store on registry
+            obr_.store
             (
-                IOobject
+                new Type2
                 (
-                    prime2MeanFieldName,
-                    obr_.time().timeName(obr_.time().startTime().value()),
-                    obr_,
-                    IOobject::READ_IF_PRESENT,
-                    IOobject::NO_WRITE
-                ),
-                sqr(baseField) - sqr(meanField)
-            )
-        );
+                    IOobject
+                    (
+                        prime2MeanFieldName,
+                        obr_.time().timeName(),
+                        obr_,
+                        IOobject::NO_READ,
+                        IOobject::NO_WRITE
+                    ),
+                    sqr(baseField) - sqr(meanField)
+                )
+            );
+        }
+        else
+        {
+            // Store on registry
+            obr_.store
+            (
+                new Type2
+                (
+                    IOobject
+                    (
+                        prime2MeanFieldName,
+                        obr_.time().timeName(obr_.time().startTime().value()),
+                        obr_,
+                        IOobject::READ_IF_PRESENT,
+                        IOobject::NO_WRITE
+                    ),
+                    sqr(baseField) - sqr(meanField)
+                )
+            );
+        }
     }
 }
 
-- 
2.1.4

henry

2015-04-09 14:56

manager   ~0004591

Thanks for the patches. I propose to apply them to OpenFOAM-dev for testing and if all is well they could also be made to OpenFOAM-2.3.x

henry

2015-04-09 16:09

manager   ~0004594

The first patch is fine but the second can be simplified using the ?: ternary operator to avoid code duplication without:

commit 4df8179f3290238ed6f09ff7aaea7970ac1c367d

Please let me know if there are any issues with these changes.

dkxls

2015-04-09 17:15

reporter   ~0004595

Indeed much more elegant with the ternary operator!

I will report back in case there are any issues.

dkxls

2015-05-05 17:36

reporter   ~0004712

I have tested the changes above for several cases and everything appears to work correctly.
I suggest to add the corrections also to OpenFOAM-2.3.x.

henry

2015-05-05 19:33

manager   ~0004719

Resolved by commit e0b2369cc0aa99ffc7ca025fdb6a303a77bf5e83

Issue History

Date Modified Username Field Change
2015-04-08 17:21 dkxls New Issue
2015-04-08 17:38 henry Note Added: 0004579
2015-04-09 14:21 dkxls Note Added: 0004589
2015-04-09 14:22 dkxls File Added: 0001-fieldAverage.C-Reset-totalIter_-totalTime_-if-resetO.patch
2015-04-09 14:22 dkxls File Added: 0002-fieldAverageTemplates.C-NO_READ-for-mean-prime2Mean-.patch
2015-04-09 14:56 henry Note Added: 0004591
2015-04-09 16:09 henry Note Added: 0004594
2015-04-09 17:15 dkxls Note Added: 0004595
2015-05-05 17:36 dkxls Note Added: 0004712
2015-05-05 19:33 henry Note Added: 0004719
2015-05-05 19:33 henry Status new => resolved
2015-05-05 19:33 henry Resolution open => fixed
2015-05-05 19:33 henry Assigned To => henry