
[Sponsors] 
November 1, 2011, 05:06 
Mean value at each time step

#1 
Member
Dejan Morar
Join Date: Nov 2010
Posts: 78
Rep Power: 8 
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((UUM) * pow((T1TM1),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 

November 1, 2011, 05:21 

#2 
Super Moderator
Niklas Nordin
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 693
Rep Power: 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*(timestartAveraging) + U*dt ) / (timestartAveraging + dt); } } Up = U  Uav; 

November 1, 2011, 05:33 

#3 
Member
Dejan Morar
Join Date: Nov 2010
Posts: 78
Rep Power: 8 
Yes, exactly this. I will put it into the solver right now
Thanks Niklas so much! 

November 1, 2011, 06:58 

#4 
Member
Dejan Morar
Join Date: Nov 2010
Posts: 78
Rep Power: 8 
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 

November 1, 2011, 07:01 

#5 
Super Moderator
Niklas Nordin
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 693
Rep Power: 21 
I did it like this for pimpleFoam. put this in the createFields.Hfile
Code:
scalar startAveraging ( readScalar(mesh.solutionDict().subDict("PIMPLE").lookup("startAveraging")) ); 

November 1, 2011, 08:59 

#6 
Member
Dejan Morar
Join Date: Nov 2010
Posts: 78
Rep Power: 8 
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. 

November 1, 2011, 10:34 

#7 
Super Moderator
Niklas Nordin
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 693
Rep Power: 21 
what do you mean with 'at some point during run'?
Is this a time you know when you start the simulation? 

November 1, 2011, 11:50 

#8 
Member
Dejan Morar
Join Date: Nov 2010
Posts: 78
Rep Power: 8 
No, I don't know that time. I am just waiting for several flowthrough 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. 

November 1, 2011, 13:20 

#9 
Super Moderator
Niklas Nordin
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 693
Rep Power: 21 
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 functionobjects 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. 

November 2, 2011, 04:05 

#10 
Member
Dejan Morar
Join Date: Nov 2010
Posts: 78
Rep Power: 8 

November 4, 2012, 21:04 

#11 
Senior Member

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 

November 5, 2012, 03:52 

#12 
Member
Dejan Morar
Join Date: Nov 2010
Posts: 78
Rep Power: 8 
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.. 

November 5, 2012, 12:34 

#13 
Senior Member

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 Regards, Awais 

June 6, 2014, 06:47 

#14 
Member
Niu
Join Date: Apr 2014
Posts: 42
Rep Power: 4 
Dear Niklas,
should the value of startAveraging be set in dictionary of transportProperties? 

June 6, 2014, 07:01 

#15 
Member
Marcus Letzel
Join Date: Sep 2012
Location: Aurich
Posts: 35
Rep Power: 5 
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")) ); Marcus 

Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Superlinear speedup in OpenFOAM 13  msrinath80  OpenFOAM Running, Solving & CFD  18  March 3, 2015 06: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 10:20 
calculation diverge after continue to run  zhajingjing  OpenFOAM  0  April 28, 2010 04:35 
HELP! time step too small?  meangreen  Main CFD Forum  5  August 27, 2009 12:32 