CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM

Mean value at each time step

Register Blogs Community New Posts Updated Threads Search

Like Tree9Likes
  • 6 Post By niklas
  • 1 Post By niklas
  • 1 Post By owayz
  • 1 Post By letzel

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 1, 2011, 04:06
Default Mean value at each time step
  #1
Member
 
Dejan Morar
Join Date: Nov 2010
Posts: 78
Rep Power: 16
morard is on a distinguished road
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
morard is offline   Reply With Quote

Old   November 1, 2011, 04:21
Default
  #2
Super Moderator
 
niklas's Avatar
 
Niklas Nordin
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 693
Rep Power: 29
niklas will become famous soon enoughniklas will become famous soon enough
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;
niklas is offline   Reply With Quote

Old   November 1, 2011, 04:33
Default
  #3
Member
 
Dejan Morar
Join Date: Nov 2010
Posts: 78
Rep Power: 16
morard is on a distinguished road
Yes, exactly this. I will put it into the solver right now

Thanks Niklas so much!
morard is offline   Reply With Quote

Old   November 1, 2011, 05:58
Default
  #4
Member
 
Dejan Morar
Join Date: Nov 2010
Posts: 78
Rep Power: 16
morard is on a distinguished road
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
morard is offline   Reply With Quote

Old   November 1, 2011, 06:01
Default
  #5
Super Moderator
 
niklas's Avatar
 
Niklas Nordin
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 693
Rep Power: 29
niklas will become famous soon enoughniklas will become famous soon enough
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
mm.abdollahzadeh likes this.
niklas is offline   Reply With Quote

Old   November 1, 2011, 07:59
Default
  #6
Member
 
Dejan Morar
Join Date: Nov 2010
Posts: 78
Rep Power: 16
morard is on a distinguished road
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.
morard is offline   Reply With Quote

Old   November 1, 2011, 09:34
Default
  #7
Super Moderator
 
niklas's Avatar
 
Niklas Nordin
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 693
Rep Power: 29
niklas will become famous soon enoughniklas will become famous soon enough
what do you mean with 'at some point during run'?

Is this a time you know when you start the simulation?
niklas is offline   Reply With Quote

Old   November 1, 2011, 10:50
Default
  #8
Member
 
Dejan Morar
Join Date: Nov 2010
Posts: 78
Rep Power: 16
morard is on a distinguished road
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.
morard is offline   Reply With Quote

Old   November 1, 2011, 12:20
Default
  #9
Super Moderator
 
niklas's Avatar
 
Niklas Nordin
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 693
Rep Power: 29
niklas will become famous soon enoughniklas will become famous soon enough
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.
niklas is offline   Reply With Quote

Old   November 2, 2011, 03:05
Default
  #10
Member
 
Dejan Morar
Join Date: Nov 2010
Posts: 78
Rep Power: 16
morard is on a distinguished road
Quote:
Originally Posted by niklas View Post
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.
morard is offline   Reply With Quote

Old   November 4, 2012, 20:04
Default
  #11
Senior Member
 
Awais Ali
Join Date: Feb 2010
Location: Germany
Posts: 128
Rep Power: 17
owayz is on a distinguished road
Send a message via MSN to owayz
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
owayz is offline   Reply With Quote

Old   November 5, 2012, 02:52
Default
  #12
Member
 
Dejan Morar
Join Date: Nov 2010
Posts: 78
Rep Power: 16
morard is on a distinguished road
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..
morard is offline   Reply With Quote

Old   November 5, 2012, 11:34
Default
  #13
Senior Member
 
Awais Ali
Join Date: Feb 2010
Location: Germany
Posts: 128
Rep Power: 17
owayz is on a distinguished road
Send a message via MSN to owayz
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
babakflame likes this.
owayz is offline   Reply With Quote

Old   June 6, 2014, 06:47
Default
  #14
Member
 
Niu
Join Date: Apr 2014
Posts: 55
Rep Power: 12
Z.Q. Niu is on a distinguished road
Dear Niklas,
should the value of startAveraging be set in dictionary of transportProperties?
Z.Q. Niu is offline   Reply With Quote

Old   June 6, 2014, 07:01
Default
  #15
Member
 
Marcus Letzel
Join Date: Sep 2012
Location: Bremen
Posts: 35
Rep Power: 13
letzel is on a distinguished road
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
bmikuz likes this.
letzel is offline   Reply With Quote

Old   October 7, 2021, 22:22
Default
  #16
Member
 
ESI
Join Date: Sep 2017
Posts: 46
Rep Power: 8
ht2017 is on a distinguished road
Quote:
Originally Posted by morard View Post
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
sorry, I know this post for a long time. Did you can do it ? could you share how to do it? thank you
ht2017 is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
HELP! time step too small? meangreen Main CFD Forum 6 May 31, 2018 10:41
Superlinear speedup in OpenFOAM 13 msrinath80 OpenFOAM Running, Solving & CFD 18 March 3, 2015 05:36
Hydrostatic Pressure and Gravity miliante OpenFOAM Running, Solving & CFD 132 October 7, 2012 22:50
Full pipe 3D using icoFoam cyberbrain OpenFOAM 4 March 16, 2011 09:20
calculation diverge after continue to run zhajingjing OpenFOAM 0 April 28, 2010 04:35


All times are GMT -4. The time now is 16:03.