LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File openfoam-fieldAverage-Correct-handling-of-resetOnOutput.patch of Package openfoam22x (Project home:dkxls:cfd)

commit 4df8179f3290238ed6f09ff7aaea7970ac1c367d
Author: Henry <Henry>
Date:   Thu Apr 9 16:05:33 2015 +0100

    fieldAverage: Correct handling of resetOnOutput
    Resolves bug-report http://www.openfoam.org/mantisbt/view.php?id=1653
    Thanks to Armin Wehrfritz for proposed fixes

diff --git a/src/postProcessing/functionObjects/field/fieldAverage/fieldAverage/fieldAverage.C b/src/postProcessing/functionObjects/field/fieldAverage/fieldAverage/fieldAverage.C
index 251b9d3..62407d8 100644
--- a/src/postProcessing/functionObjects/field/fieldAverage/fieldAverage/fieldAverage.C
+++ b/src/postProcessing/functionObjects/field/fieldAverage/fieldAverage/fieldAverage.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
@@ -33,7 +33,7 @@ License
 
 namespace Foam
 {
-defineTypeNameAndDebug(fieldAverage, 0);
+    defineTypeNameAndDebug(fieldAverage, 0);
 }
 
 
@@ -50,6 +50,7 @@ void Foam::fieldAverage::resetFields()
                 obr_.checkOut(*obr_[faItems_[i].meanFieldName()]);
             }
         }
+
         if (faItems_[i].prime2Mean())
         {
             if (obr_.found(faItems_[i].prime2MeanFieldName()))
@@ -67,7 +68,6 @@ void Foam::fieldAverage::initialize()
 
     Info<< type() << " " << name_ << ":" << nl;
 
-
     // Add mean fields to the field lists
     forAll(faItems_, fieldI)
     {
@@ -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);
 
-            // ensure first averaging works unconditionally
-            prevTimeIndex_ = -1;
+            totalTime_.clear();
+            totalTime_.setSize(faItems_.size(), obr_.time().deltaTValue());
+
+            initialize();
         }
 
         Info<< endl;
diff --git a/src/postProcessing/functionObjects/field/fieldAverage/fieldAverage/fieldAverageTemplates.C b/src/postProcessing/functionObjects/field/fieldAverage/fieldAverage/fieldAverageTemplates.C
index 00b4c9e..62e7334 100644
--- a/src/postProcessing/functionObjects/field/fieldAverage/fieldAverage/fieldAverageTemplates.C
+++ b/src/postProcessing/functionObjects/field/fieldAverage/fieldAverage/fieldAverageTemplates.C
@@ -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
@@ -66,7 +66,9 @@ void Foam::fieldAverage::addMeanFieldType(const label fieldI)
                     meanFieldName,
                     obr_.time().timeName(obr_.time().startTime().value()),
                     obr_,
-                    IOobject::READ_IF_PRESENT,
+                    resetOnOutput_
+                  ? IOobject::NO_READ
+                  : IOobject::READ_IF_PRESENT,
                     IOobject::NO_WRITE
                 ),
                 1*baseField
@@ -124,6 +126,7 @@ void Foam::fieldAverage::addPrime2MeanFieldType(const label fieldI)
         const Type1& baseField = obr_.lookupObject<Type1>(fieldName);
         const Type1& meanField = obr_.lookupObject<Type1>(meanFieldName);
 
+        // Store on registry
         obr_.store
         (
             new Type2
@@ -133,7 +136,9 @@ void Foam::fieldAverage::addPrime2MeanFieldType(const label fieldI)
                     prime2MeanFieldName,
                     obr_.time().timeName(obr_.time().startTime().value()),
                     obr_,
-                    IOobject::READ_IF_PRESENT,
+                    resetOnOutput_
+                  ? IOobject::NO_READ
+                  : IOobject::READ_IF_PRESENT,
                     IOobject::NO_WRITE
                 ),
                 sqr(baseField) - sqr(meanField)