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

[swak4Foam] problems with averaging a new field

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 27, 2016, 08:22
Default problems with averaging a new field
  #1
New Member
 
Francesco Garita
Join Date: Oct 2016
Location: Italy
Posts: 8
Rep Power: 10
fgarita is on a distinguished road
Hi everybody,

I am finding some problems with Swak4Foam. In particular, the situation is the following: I want to create a new field (called epsilon) by using an expressionField, which calls for UMean, produced by a fieldAverage; then I want to average this new field epsilon, but I get an error if I write epsilon within the fieldAverage.

What I managed to figure out is that the problem comes from the fact that OpenFOAM does not know how to initialize this new field (it only knows how to initialize UMean, pMean, etc.). The solutions I found are basically 2:

1) Do the following steps in sequence:
- Make a check to see whether UMean is present; if it is, then ask Swak4Foam to create the field epsilon;
- Let the solver run for some timestep (in order epsilon to be created);
- Include epsilon within the fieldAverage.
As you can see, this solution is very annoying because you have to wait that epsilon is created and then you have to include manually this new field within the fieldAverage. Furthermore, this will cause the total averaging time of epsilon to be shorter than the total averaging time of UMean, and this is definitely undesired.

2) Another option to solve the problem is the following:
- Make a check to see whether UMean is present; if it is, then ask Swak4Foam to create the field epsilon;
- Make a second check to see whether epsilon is present; if it is, then ask Swak4Foam to make a second fieldAverage where only epsilon is present.
This solution works pretty well as epsilonMean is created for the first time when UMean is created for the first time, thus solving the problem of having two different total averaging times. Also, it does not require you to wait epsilon to be created in order to start averaging it. However, this solution has its own drawback represented by the fact that when a second fieldAverage is created, then the fieldAverageProperties file writes only the information related to the second field average. Somebody may think that if the information on UMean, pMean, etc. included in the fieldAverageProperties file are not present anymore, then the solver does not compute a correct average of UMean, pMean, etc. but I did make many checks and fortunately this seems not to be the case because, even though those information are not present anymore in the fieldAverageProperties file, OpenFOAM keeps those information in its registers anyway, therefore UMean, pMean, etc. should be calculated correctly in my opinion.

The reasons why I am writing this post are 2: first I would like somebody to confirm that UMean, pMean are indeed calculated correctly, and second I would be grateful if you could suggest me some more efficient way to do what I need to do, without losing the information on UMean, pMean, etc. present in the fieldAverageProperties file.

Thanks to anybody that will reply to this post.
Francesco

P.S. If you wish, you can go through the functions I included in my ControlDict in the second case:
Code:
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;
                }
                               
            );
    }

    UMeanCheck
    {
            type executeIfObjectExists;
            objectName UMean; 
            checkType true;   
            objectType volVectorField;     
            objectShouldExist true; 
            readDuringConstruction false;           
            functions {                   
                doCalc  { 
                             type expressionField;
                             fieldName "epsilon";
                             expression "nu*(grad(U) && grad(U))-2*nu*(grad(UMean) && grad(U))+nu*(grad(UMean) && grad(UMean))";
                             autowrite true;
                             outputControlMode timeStep;
                             outputInterval 1;
                         }
                       }
     }

    epsilonCheck
    {
            type executeIfObjectExists;
            objectName epsilon; 
            checkType true;   
            objectType volScalarField;     
            objectShouldExist true; 
            readDuringConstruction false;           
            functions {                   
                    doCalc{ 
                            type            fieldAverage;
                            functionObjectLibs ( "libfieldFunctionObjects.so" );
                            enabled         true;
                            outputControl   outputTime;
                            fields
                            (
                                epsilon
                                {
                                    mean        on;
                                    prime2Mean  off;
                                    base        time;
                                }
                               
                            );
                          }
                     }
    }
}
fgarita is offline   Reply With Quote

Old   October 28, 2016, 04:27
Default
  #2
Senior Member
 
floquation's Avatar
 
Kevin van As
Join Date: Sep 2014
Location: TU Delft, The Netherlands
Posts: 252
Rep Power: 21
floquation will become famous soon enough
I don't know the answer, but I have two quick suggestions that you might like to try:

  1. At some point in time, I decided that I need the following function as very first in everything I do. I'm not sure why anymore, but it had to do with things not being initialized when I needed them, which seems related to your problem. Then again, if I Google, it seems related to the mesh. Try it anyway:
    Code:
    functions
    (
        doInit {
            type initSwakFunctionObject;
        }
    
        (...)
    
    );
  2. Perhaps the "executeIfStartTime" FO might be useful. Whenever I need to "get a calculation started", I use this to set initial values to global variables, as in the following snippet. I reckon it may very well be used to initialize your fields as well.
    I'll copy a full example of what I have used in one case:
    Code:
    initPosStarter{
        type executeIfStartTime;
        outputControlMode timeStep;
        outputInterval 1;
        readDuringConstruction false; // Must be false for "executeIfStartTime"-FO
        runIfStartTime yes;
        functions {
            setStartTime
            {
                type calculateGlobalVariables;
                valueType internalField;
                toGlobalNamespace globals;
                toGlobalVariables ( startTime );
                variables ( "startTime=time();" );
                noReset true; // Maintain this variable forever
            }
    
            calcInitPos
            {
              type calculateGlobalVariables;
              valueType surface;
              surfaceName interface;
              surface
              {
                type isoSurfaceCell;
                isoField alpha1;
                isoValue 0.5;
                interpolate false;
                regularise false; // do not simplify
              }
    
              noReset true; // Maintain this variable forever
    
              toGlobalNamespace interface; //write to this one
              toGlobalVariables (
                position0
                position
              );
    
              variables (
                "position=average(pos());"
                "position0=position;"
              );
            }
        }
    }


Good luck!
floquation is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
CyclicAMI: Problems with pressure field Thoma OpenFOAM Running, Solving & CFD 13 June 28, 2014 09:34
Averaging Field data over several Iterations lin123 STAR-CCM+ 1 April 14, 2010 04:32
averaging selected field - multiphase RBJ OpenFOAM Post-Processing 1 December 29, 2009 07:50
Field averaging in a certain time interval misakagan OpenFOAM Running, Solving & CFD 1 December 11, 2009 06:39
Problem with rhoSimpleFoam matteo_gautero OpenFOAM Running, Solving & CFD 0 February 28, 2008 07:51


All times are GMT -4. The time now is 18:35.