CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Access UMean at runtime (https://www.cfd-online.com/Forums/openfoam-programming-development/98740-access-umean-runtime.html)

deji March 17, 2012 17:14

Access UMean at runtime
 
Good day to all. Is it possible to access UMean at runtime? I need it to perform compute the u'? Or can I just access u' at runtime? Thanks.

morard March 19, 2012 12:53

Hi deji,

in absence of better idea, I did it on the following way: I calculate UMean in the solver on the same way as it would be calculated by the averaging function written in controlDict (check fieldAverageTemplates.C)

alpha = ( time-startStatistics - dt ) / ( time-startStatistics );
beta = dt / ( time-startStatistics);

UM = alpha*UM + beta*U;

If you know how to access UMean directly, please let me know.

Regards,
Dejan

deji March 19, 2012 13:10

Thank you Dejan, I will certainly take a look at the code.

Cheers,
Deji

ykanani April 25, 2016 19:20

Quote:

Originally Posted by deji (Post 350017)
Good day to all. Is it possible to access UMean at runtime? I need it to perform compute the u'? Or can I just access u' at runtime? Thanks.

I know this is a very old thread, however as I found a good solution to it, I wanted to share:
for accessing UMean or any other Mean values in your solver, first add this in your Creatfields.H
Code:

    Info<< "Reading field UMean\n" << endl;
    volVectorField UMean
    (
        IOobject
        (
            "UMean",
            runTime.timeName(),
            mesh,
            IOobject::READ_IF_PRESENT,
            IOobject::AUTO_WRITE
        ),
        mesh
    );

Then add this line at the end of the time loop of the solver (before runtime.write)

Code:

      const GeometricField<vector, fvPatchField, volMesh>& UMean_ =
        U.db().objectRegistry::
        lookupObject<GeometricField<vector, fvPatchField, volMesh> >
        (
            "UMean"
        );

UMean_ is the updated UMean (just one iteration lag) and the good thing is that you don't have to start your simulation with averaging. it can be started at any time you want.

Also you will need to add UMean file to your 0 directory.


for checking if this is working or not, you can add this line to print Umean_[0] (first value of UMean) and compare it with the saved UMean file in the time directory.
Info << "UMean_[0] = " << UMean_[0] << endl;


All times are GMT -4. The time now is 20:29.