# Mean value at each time step

 Register Blogs Members List Search Today's Posts Mark Forums Read

 November 1, 2011, 05:06 Mean value at each time step #1 Member   Dejan Morar Join Date: Nov 2010 Posts: 78 Rep Power: 7 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

 November 1, 2011, 05:21 #2 Super Moderator     Niklas Nordin Join Date: Mar 2009 Location: Stockholm, Sweden Posts: 693 Rep Power: 19 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, mm.abdollahzadeh, bmikuz and 1 others like this.

 November 1, 2011, 05:33 #3 Member   Dejan Morar Join Date: Nov 2010 Posts: 78 Rep Power: 7 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: 7 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: 19 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.

 November 1, 2011, 08:59 #6 Member   Dejan Morar Join Date: Nov 2010 Posts: 78 Rep Power: 7 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: 19 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: 7 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.

 November 1, 2011, 13:20 #9 Super Moderator     Niklas Nordin Join Date: Mar 2009 Location: Stockholm, Sweden Posts: 693 Rep Power: 19 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.

November 2, 2011, 04:05
#10
Member

Dejan Morar
Join Date: Nov 2010
Posts: 78
Rep Power: 7
Quote:
 Originally Posted by niklas 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.

 November 4, 2012, 21:04 #11 Senior Member   Awais Ali Join Date: Feb 2010 Location: Germany Posts: 125 Rep Power: 8 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: 7 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   Awais Ali Join Date: Feb 2010 Location: Germany Posts: 125 Rep Power: 8 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.

 June 6, 2014, 06:47 #14 Member   Niu Join Date: Apr 2014 Posts: 42 Rep Power: 3 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: 4 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.

 Thread Tools Display Modes Linear Mode

 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 OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post msrinath80 OpenFOAM Running, Solving & CFD 18 March 3, 2015 06:36 miliante OpenFOAM Running, Solving & CFD 132 October 7, 2012 22:50 cyberbrain OpenFOAM 4 March 16, 2011 10:20 zhajingjing OpenFOAM 0 April 28, 2010 04:35 meangreen Main CFD Forum 5 August 27, 2009 12:32

All times are GMT -4. The time now is 00:53.