CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   Mean value at each time step (http://www.cfd-online.com/Forums/openfoam/93962-mean-value-each-time-step.html)

morard November 1, 2011 05:06

Mean value at each time step
 
Hi,
I want to calculate budget terms of temperature variance and for that case I need mean value of velocity and temperature at each time step. For example, turbulent diffusion:

turbDiff1 = fvc::div((U-UM) * pow((T1-TM1),2.0));

where UM and TM1 are mean values calculated in fieldAverage function in controlDict. I have created fields UM and TM1 in createFields.H:

volVectorField UM
(
IOobject
(
"UMean",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);

volScalarField TM1
(
IOobject
(
"T1Mean",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);

So, they are created at the beginning of time loop and remain constant during runtime. Now, I want these values to be adjusted at each time step. Is it possible to pass these averaged values (UMean and T1Mean), calculated in function implemented in controlDict, to the solver? Any suggestion?

Regards,
Dejan

niklas November 1, 2011 05:21

you mean something like this?

Code:

scalar time = runTime.value();
scalar dt = runTime.deltaT().value();

if (time > startAveraging )
{
    if ( (time - dt) < startAveraging )
    {
        Uav = U;
    }
    else
    {
        Uav = ( Uav*(time-startAveraging) + U*dt ) / (time-startAveraging + dt);
    }
}

Up = U - Uav;


morard November 1, 2011 05:33

Yes, exactly this. I will put it into the solver right now:)

Thanks Niklas so much!

morard November 1, 2011 06:58

Hi Niklas again and sorry for interrupting. I was too fast. How can I specify startAveraging? Which function sends a signal that averaging is started?

Regards

niklas November 1, 2011 07:01

I did it like this for pimpleFoam. put this in the createFields.H-file

Code:

    scalar startAveraging
    (
        readScalar(mesh.solutionDict().subDict("PIMPLE").lookup("startAveraging"))
    );

startAveraging is the time-value

morard November 1, 2011 08:59

Hm, still I don't understand this, but I'll try to find out, somehow... It seams that I have to predefine startAveraging in fvSolution, but I want to start averaging at some point during run by adding function in controlDict. Than I should receive this info:

regIOobject::readIfModified() :
Reading object controlDict from file "/../system/controlDict"

and I want this time to be startAveraging.
Thanks for the reply.

niklas November 1, 2011 10:34

what do you mean with 'at some point during run'?

Is this a time you know when you start the simulation?

morard November 1, 2011 11:50

No, I don't know that time. I am just waiting for several flow-through times and than start averaging by putting ON for mean values in controlDict. Like this

functions
{
fieldAverage1
{
type fieldAverage;
functionObjectLibs ( "libfieldFunctionObjects.so" );
enabled true;
outputControl outputTime;
fields
(
U
{
mean on;
prime2Mean on;
base time;
}

p
{
mean on;
prime2Mean on;
base time;
}
);
}
}

And I want the time when I put ON to be the startAveraging time. I don't know if this is possible.

niklas November 1, 2011 13:20

You dont need the function objects, if you add that piece of code to the solver.

just set startTime to a something sufficiently high so you get rid of the startup influence.
Thats all you need.

If you use the function-objects you will start averaging from start and if you want
to start at a certain time you have to code that yourself.
should be pretty straightforward though.

alternatively you can restart the simulation once the flow is fully developed and set cleanRestart true;

this way you dont need to add any code to the solver either.
check
src/postProcessing/functionObjects/field/fieldAverage/fieldAverage/fieldAverage.C

if you want to see how it works.

morard November 2, 2011 04:05

Quote:

Originally Posted by niklas (Post 330332)
You dont need the function objects, if you add that piece of code to the solver.

just set startTime to a something sufficiently high so you get rid of the startup influence.
Thats all you need.

I'll do it on this way. Thanks once again.

owayz November 4, 2012 21:04

Hallo Dejan,
Just a small question. To calculate the u' v' and w', I should first get a statistically converged UMean and then subtract the instantaneous velocity field U from it to get u' v' and w'. Is it right?
This means that I should wait for statistically converged simulations before recording the fluctuating fields, is there any easy way out. Because in some cases it could take considerable amount to time to get a converged simulation.

Regards,
Awais

morard November 5, 2012 03:52

Hi Awais,

yes, that is the way how I did it. Well, I'm not sure if there is a faster option... Anyhow, those are statistical values and if you want good statistics, you haw to wait long. Check this code

prime2MeanField =
alpha*prime2MeanField
+ beta*sqr(baseField)
- sqr(meanField);

in fieldAverageTemplates.C. Try to implement it into your solver, maybe it works faster but, since I didn't try it, I'm really not sure..

owayz November 5, 2012 12:34

Thanks for your reply Dejan,
Actually I turn on the avraging and wait for statistical convergence. I have modified the solver adding something like:
Code:

UPrime = U - UMean
And then I get this data out and I don't know if there is any easier or Faster way.

Regards,
Awais

Z.Q. Niu June 6, 2014 06:47

Dear Niklas,
should the value of startAveraging be set in dictionary of transportProperties?

letzel June 6, 2014 07:01

The example by niklas expects startAveraging to be specified in file fvSolution in subdict PIMPLE.

If you prefer controlDict, use this code:
Code:

    scalar startAveraging
    (
        readScalar(runTime.controlDict().lookup("startAveraging"))
    );

Regards,
Marcus


All times are GMT -4. The time now is 11:27.