View Issue Details

IDProjectCategoryView StatusLast Update
0002459OpenFOAMBugpublic2017-03-20 17:31
Reportermichael2015 Assigned Tohenry  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Summary0002459: fieldAverage function object is wrongly initialized for variable time step sizes
DescriptionFor a variable time step size the totalTime is initialized with the first time step size deltaT.

I guess it happens in the function
void Foam::functionObjects::fieldAverage::readAveragingProperties()
 {
     totalTime_.setSize(faItems_.size(), obr_.time().deltaTValue());


I set the timeStart in the controlDict to 87.

For my case the deltaT value at timeStart was quite different from the initial time step size (a factor 10 heigher).

So the averaged velocity computed at the first averaging step was not equal to the velocity at the time of the first averaging step.

since the factors in fieldAverageTemplates.C

       scalar dt = obr_.time().deltaTValue();
         scalar Dt = totalTime_[fieldi];

where not the same at the very first averaging step.

When I initialized the totalTime_[fieldi] list with the deltaT value at the averaging start the very first mean velocity was equal to the current velocity.
 
TagsNo tags attached.

Activities

henry

2017-03-09 16:43

manager   ~0007873

It is not clear from your description where you set totalTime_[fieldi], how does it interact with restart for which totalTime_ is read from dictionary?

michael2015

2017-03-09 16:51

reporter   ~0007874

The inialize function looks like this:

void Foam::fieldAverage::initialize()
{
    resetFields();

    Info<< type() << " " << name_ << ":" << nl;


    // Add mean fields to the field lists
    forAll(faItems_, fieldI)
    {
        addMeanField<scalar>(fieldI);
        addMeanField<vector>(fieldI);
        addMeanField<sphericalTensor>(fieldI);
        addMeanField<symmTensor>(fieldI);
        addMeanField<tensor>(fieldI);
    }

    // Add prime-squared mean fields to the field lists
    forAll(faItems_, fieldI)
    {
        addPrime2MeanField<scalar, scalar>(fieldI);
        addPrime2MeanField<vector, symmTensor>(fieldI);
    }

    forAll(faItems_, fieldI)
    {
        if (!faItems_[fieldI].active())
        {
            WarningIn("void Foam::fieldAverage::initialize()")
                << "Field " << faItems_[fieldI].fieldName()
                << " not found in database for averaging";
        }
    }

    // intialize also total time and set it the current deltaT
    forAll(faItems_, fieldI)
    {

      totalTime_[fieldI] = obr_.time().deltaTValue();
      
    }

    // ensure first averaging works unconditionally
    prevTimeIndex_ = -1;

    Info<< endl;

    initialised_ = true;
}

michael2015

2017-03-09 16:53

reporter   ~0007875

the totalTime_[fieldI] should be initialized with the current obr_.time().deltaTValue() value. otherwise the averaging could be wrong

henry

2017-03-09 16:59

manager   ~0007877

Your proposal overrides the values set by readAveragingProperties() called by read(), setting the appropriate values when you restart the run. Have you tried restarting a case and checked that the averaging restarts?

michael2015

2017-03-09 17:11

reporter   ~0007881

you're right. when the properties are read the totalTime is overwritten.

What do you suggest?

michael2015

2017-03-09 17:20

reporter   ~0007882

an option would be to initialize the toalTime only if the properties are not read.

henry

2017-03-09 17:41

manager   ~0007884

I am testing a possible solution to this problem at the moment, I will push into OpenFOAM-dev when the tests are complete.

henry

2017-03-09 17:47

manager   ~0007885

Resolved in OpenFOAM-dev by commit ed488cb83e3c869ea660c6f35809e6208339211d

Could you test this fix and let me know if it is OK for cases. If all is well I will apply the same change to OpenFOAM-4.x.

michael2015

2017-03-20 16:55

reporter   ~0007950

I tested the initialization and it worked fine.

henry

2017-03-20 17:31

manager   ~0007951

Resolved in OpenFOAM-4.x by commit 38af843e10baafffd239ac134b6fb38de293c1c3

Resolved in OpenFOAM-dev by commit ed488cb83e3c869ea660c6f35809e6208339211d

Issue History

Date Modified Username Field Change
2017-02-13 18:09 michael2015 New Issue
2017-03-09 16:43 henry Note Added: 0007873
2017-03-09 16:51 michael2015 Note Added: 0007874
2017-03-09 16:53 michael2015 Note Added: 0007875
2017-03-09 16:59 henry Note Added: 0007877
2017-03-09 17:11 michael2015 Note Added: 0007881
2017-03-09 17:20 michael2015 Note Added: 0007882
2017-03-09 17:41 henry Note Added: 0007884
2017-03-09 17:47 henry Note Added: 0007885
2017-03-20 16:55 michael2015 Note Added: 0007950
2017-03-20 17:31 henry Assigned To => henry
2017-03-20 17:31 henry Status new => resolved
2017-03-20 17:31 henry Resolution open => fixed
2017-03-20 17:31 henry Fixed in Version => 4.x
2017-03-20 17:31 henry Note Added: 0007951