CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (https://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   Monitor Total Pressure in a running simulation using functionobjects (https://www.cfd-online.com/Forums/openfoam-post-processing/125232-monitor-total-pressure-running-simulation-using-functionobjects.html)

CFD-Cat October 22, 2013 04:00

Monitor Total Pressure in a running simulation using functionobjects
 
Hi,
I'm new to Open Foam, so probably the solution of my problem will be really simple for other user but I couldn't find anything about this in the forum.
I'm running a simulation of something similar to a pipe in simpleFoam ( OpenFoam 2.2.0). I'd like to monitor the areaAverage of the total pressure on the outlet boundary as a parameter to judge when the simulation reaches a good convergence. I'm doing the same for the massflowrate with a functionobject and it works fine but when I try to do it using the new pressureTools I got this warning:


Code:

--> FOAM Warning : 
    From function probes::read()
    in file patch/patchFieldFunctionObject/patchFieldFunctionObject.C at line 100
    Unknown field total(p) when reading dictionary ".TotalPressureAveOutlet"
    Can only probe registered volScalar, volVector, volSphericalTensor, volSymmTensor and volTensor fields

The simulation runs fine and it saves a folder total(p) every iterations but it doesn't calculate the areaAverage at Outlet.



this is my control dictionary function:

Code:

functions
(

  myFunctionObject    // user-defined name of function object entry
    {
        type            pressureTools;
        functionObjectLibs ("libutilityFunctionObjects.so");
    rhoRef 997;
    pRef  101300;       
    //region          defaultRegion;     
        enabled        yes;
        //timeStart      0;
        //timeEnd        10;       
        outputControl timeStep;//outputTime;//
        outputInterval 1; // 5000;
        calcTotal  yes;
        calcCoeff  no;
    }
reloadTotalP
      {
          type        readFields;
          functionObjectLibs ("libfieldFunctionObjects.so");
          //region          defaultRegion;
          enabled        yes;
          //timeStart      0;
          //timeEnd        10;
          outputControl timeStep;//outputTime;//
          outputInterval 1; // 5000;
          fields
          (
              "total(p)"
          );
      }
 
TotalPressureAveOutlet
{
type patchAverage;
functionObjectLibs ("libsimpleFunctionObjects.so");
verbose true;
patches (outlet);
factor 1;
fields (
total(p)
);
outputControl  timeStep;
outputInterval  1;
outputControlMode timestep;
}

Thank you in advance for your help!



Ale

CFD-Cat October 24, 2013 12:15

anybody can help me?

Did I do something wrong?

wyldckat October 26, 2013 07:39

Greetings CFD-Cat,

Mmm... this looks sort-of familiar... OK, 2 details:
  1. In this part of the code:
    Code:

    TotalPressureAveOutlet
    {
    type patchAverage;
    functionObjectLibs ("libsimpleFunctionObjects.so");
    verbose true;
    patches (outlet);
    factor 1;
    fields (
    total(p)
    );
    outputControl  timeStep;
    outputInterval  1;
    outputControlMode timestep;
    }

    You should use quotes:
    Code:

    fields (
    "total(p)"
    );

    This is to avoid any other kind of interpretation.
  2. Secondly, the file name depends on several factors, as described on the Doxygen documentation: http://foam.sourceforge.net/docs/cpp...4.html#details
More specifically, I wrote about this here: http://www.cfd-online.com/Forums/ope...tml#post430031 post #4


Beyond this, I need an example case to test this for myself.

Best regards,
Bruno

CFD-Cat October 28, 2013 05:21

I added the quote but it gives the same error. :-(

wyldckat November 2, 2013 12:20

Hi CFD-Cat,

I finally managed to have a look into the case you sent me and it was fortunately rather simple!
A bit of a introduction - the idea behind "()" and "{}" is this:
  • The brackets "{}" are for gathering blocks of options, such as this:
    Code:

    {
    a 123;
    b 4564;
    c "word";
    }

  • The parenthesis "()" are for lists of values, such as:
    • Code:

      (1 2 3)
    • Code:

      ((0 1 2) (3 4 5))
      Which is the same as:
      Code:

      ((0 1 2) (3 4 5))
    • And the ultimate kind of list:
      Code:

      (
      {
      a 123;
      b 4564;
      c "word";
      }

      {
      a 534;
      b 57467;
      c "another word";
      }
      )

The reason why this didn't work:
Code:

functions
(

[...]

);

Is because lists with parenthesis cannot have a name or title. This is why "functions" should be a block list of blocks:
Code:

functions
{

[...]

};

Best regards,
Bruno

wyldckat November 9, 2013 14:43

Hi CFD-Cat,

To answer the question you've asked via private message, the full "functions" entry should look something like this:
Code:

functions
{

    myFunctionObject    // user-defined name of function object entry
    {
        type            pressureTools;
        functionObjectLibs ("libutilityFunctionObjects.so");
        rhoRef 997;
        pRef  101300;       
        //region          defaultRegion;     
        enabled        yes;
        //timeStart      0;
        //timeEnd        10;       
        outputControl timeStep;//outputTime;//
        outputInterval 1; // 5000;
        calcTotal  yes;
        calcCoeff  no;
    }

    reloadTotalP
    {
        type        readFields;
        functionObjectLibs ("libfieldFunctionObjects.so");
        //region          defaultRegion;
        enabled        yes;
        //timeStart      0;
        //timeEnd        10;
        outputControl timeStep;//outputTime;//
        outputInterval 1; // 5000;
        fields
        (
          "total(p)"
        );
    }

    TotalPressureAveOutlet
    {
        type patchAverage;
        functionObjectLibs ("libsimpleFunctionObjects.so");
        verbose true;
        patches (outlet);
        factor 1;
        fields (
          "total(p)"
        );
        outputControl  timeStep;
        outputInterval  1;
        outputControlMode timestep;
    }

    massflow
    {
        type patchMassFlow;
        functionObjectLibs ("libsimpleFunctionObjects.so");
        verbose true;
        patches (outlet);
        factor 997;
        outputControl  timeStep;
        outputInterval  1;
        outputControlMode timestep;
    }
}

Notice that brackets "{}" are used for the "functions" block, and not parenthesis "()".

Best regards,
Bruno

CFD-Cat March 14, 2014 13:23

Hi,
I'm sorry to restart this old discussion but since when I installed OF2.2.2 instead of OF2.2.0 I'm facing a new problem with pressureTools function object.

I can't understand the reason why when i try to calculate the total(p) the output reports only the BC like if no internal field has been calculated. It I try to calculate the static(p) I got the same problem, while for the total(p)_coeff I got a field distribution(maybe wrong) even setting the pInf =0.

Code:

/*--------------------------------*- C++ -*----------------------------------*\
| =========                |                                                |
| \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox          |
|  \\    /  O peration    | Version:  2.2.2                                |
|  \\  /    A nd          | Web:      www.OpenFOAM.org                      |
|    \\/    M anipulation  |                                                |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version    2.0;
    format      ascii;
    class      volScalarField;
    location    "160";
    object      total(p);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [1 -1 -2 0 0 0 0];

internalField  uniform 0;

boundaryField
{
    wall_sx
    {
        type            calculated;
        value          uniform 0;
    }
    floor
    {
        type            calculated;
        value          uniform 0;
    }
    wall_rear
    {
        type            calculated;
        value          uniform 0;
    }
    wall2
    {
        type            symmetryPlane;
    }
    inlet
    {
        type            calculated;
        value          uniform 0;
    }
    wall1
    {
        type            calculated;
        value          uniform 0;
    }
    wall_dx
    {
        type            calculated;
        value          uniform 0;
    }
    outlet
    {
        type            calculated;
        value          uniform 0;
    }
}


// ************************************************************************* //

I check if someone else found a similar problem but I wasn't able to find anything useful.

Except for this sentence that sincerely I don't understand completely:

"Where the function generates a field, e.g. wallShearStress, pressureTools, yPlusRAS, etc., the field is now stored on the mesh database so that it is available for further post-processing. " from http://www.openfoam.org/version2.2.2/

wyldckat March 15, 2014 02:51

Hi CFD-Cat,

I need more information in order to be able to help you, namely:
  1. How exactly did you configure the function objects section at "controlDict"?
  2. What type of simulation are you performing?
  3. Are you able to reproduce the error with a tutorial from OpenFOAM?
Best regards,
Bruno

CFD-Cat March 15, 2014 06:48

I'm out of office. On monday I'll try the tutorial and I'll send you the file.thank you for your help

CFD-Cat March 17, 2014 04:46

Hi wyldckat,

I reproduced it with the tutorial Tjunction. This is my controlDict

Code:

/*--------------------------------*- C++ -*----------------------------------*\
| =========                |                                                |
| \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox          |
|  \\    /  O peration    | Version:  2.2.2                                |
|  \\  /    A nd          | Web:      www.OpenFOAM.org                      |
|    \\/    M anipulation  |                                                |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version    2.0;
    format      ascii;
    class      dictionary;
    location    "system";
    object      controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

libs
(
    "libOpenFOAM.so"
    "libincompressibleTurbulenceModel.so"
    "libincompressibleRASModels.so"
);

application    pimpleFoam;

startFrom      startTime;

startTime      0;

stopAt          endTime;

endTime        1.5;

deltaT          0.001;

writeControl    adjustableRunTime;

writeInterval  0.1;

purgeWrite      0;

writeFormat    ascii;

writePrecision  6;

writeCompression uncompressed;

timeFormat      general;

timePrecision  6;

runTimeModifiable true;

adjustTimeStep  yes;

maxCo          5;

functions
{
    probes
    {
        // Where to load it from
        functionObjectLibs ( "libsampling.so" );

        type            probes;

        // Name of the directory for probe data
        name            probes;

        // Write at same frequency as fields
        outputControl  outputTime;
        outputInterval  1;

        // Fields to be probed
        fields
        (
            p U
        );

        probeLocations
        (
            ( 1e-06 0 0.01 )        // at inlet
            ( 0.21 -0.20999 0.01 )  // at outlet1
            ( 0.21 0.20999 0.01 )  // at outlet2
            ( 0.21 0 0.01 )        // at central block
        );
    }
}

// ************************************************************************* //
functions
{
pressure    // user-defined name of function object entry
    {
        type            pressureTools;
        functionObjectLibs ("libutilityFunctionObjects.so");
        rhoRef 997;
        pRef  0;               
        //region          defaultRegion;     
        enabled        yes;
        timeStart      0;
        //timeEnd        10;       
        outputControl outputTime;
        //outputControl timeStep;//outputTime;
        //outputInterval 1; // 5000;
        calcTotal  yes;
        calcCoeff  no;
  }

pressurecoeff    // user-defined name of function object entry
    {
        type            pressureTools;
        functionObjectLibs ("libutilityFunctionObjects.so");
        rhoRef 997;
        pRef  0;               
        //region          defaultRegion;     
        enabled        yes;
        timeStart      0;
        //timeEnd        10;       
        outputControl outputTime;
        //outputControl timeStep;//outputTime;
        //outputInterval 1; // 5000;
        calcTotal  yes;
        calcCoeff  yes;
        pInf 0;
        UInf (1 1 1);
        rhoInf 997;
  }


reloadtotalP
      {
          type        readFields;
          functionObjectLibs ("libfieldFunctionObjects.so");
          //region          defaultRegion;
          enabled        yes;
          //timeStart      0;
          //timeEnd        10;
          outputControl outputTime;
          //outputControl timeStep;//outputTime;//
          //outputInterval 1; // 5000;
          outputControlMode timeStep;
          fields
          (
              "total(p)"
          );
      }

outlet-total-pressure
    {
        type            faceSource;
        functionObjectLibs ("libfieldFunctionObjects.so");
        enabled        true;
        outputControl outputTime;
        //outputControl timeStep;
        //outputInterval  1;
        outputControlMode timeStep;
        log            true;
        valueOutput    false;
        source          patch;
        sourceName      outlet2;
        operation      areaAverage;
        //weightField        phi;       
        fields
        (
            "total(p)"
        );
    }
};

and this is the output :

Code:

/*--------------------------------*- C++ -*----------------------------------*\
| =========                |                                                |
| \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox          |
|  \\    /  O peration    | Version:  2.2.2                                |
|  \\  /    A nd          | Web:      www.OpenFOAM.org                      |
|    \\/    M anipulation  |                                                |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version    2.0;
    format      ascii;
    class      volScalarField;
    location    "0.2";
    object      total(p);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [1 -1 -2 0 0 0 0];

internalField  uniform 0;

boundaryField
{
    inlet
    {
        type            calculated;
        value          uniform 0;
    }
    outlet1
    {
        type            calculated;
        value          uniform 0;
    }
    outlet2
    {
        type            calculated;
        value          uniform 0;
    }
    defaultFaces
    {
        type            calculated;
        value          uniform 0;
    }
}


// ************************************************************************* //

while the total(p)_coeff is like this:

Code:

/*--------------------------------*- C++ -*----------------------------------*\
| =========                |                                                |
| \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox          |
|  \\    /  O peration    | Version:  2.2.2                                |
|  \\  /    A nd          | Web:      www.OpenFOAM.org                      |
|    \\/    M anipulation  |                                                |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version    2.0;
    format      ascii;
    class      volScalarField;
    location    "0.2";
    object      total(p)_coeff;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 0 0 0 0 0 0];

internalField  nonuniform List<scalar>
3875
(
10.639
10.4919
10.4483
10.3811
10.313
10.2384
10.1689
10.0984
.......
)
;

boundaryField
{
    inlet
    {
        type            calculated;
        value          nonuniform List<scalar>
25
(
10.6671
10.667
10.667
10.667
10.667
10.667

....
...

I run my case with simpleFoam too and I got the same result.

Best regards,

Ale

wyldckat March 23, 2014 15:21

Hi Ale,

I finally managed to look into this. This should work:
Code:

pressure    // user-defined name of function object entry
    {
        type            pressureTools;
        functionObjectLibs ("libutilityFunctionObjects.so");
        rhoName    rhoInf;
        rhoInf 997;
        pRef  0;         
  //region          defaultRegion;     
        enabled        yes;
        timeStart      0;
        //timeEnd        10;       
        outputControl outputTime;
  //outputControl timeStep;//outputTime;
        //outputInterval 1; // 5000;
        calcTotal  yes;
        calcCoeff  no;
  }

The missing details were these:
Code:

        rhoName    rhoInf;
        rhoInf 997;

"rhoRef" doesn't exist, it's "rhoInf" that should be used. And we have to indicated that the name of the field to be used for "rho" is "rhoInf", so that it knows that it should use the constant value, as there is no "rho" field.

Although a bit cryptic, this can be spotted if we look at the source code: https://github.com/OpenFOAM/OpenFOAM...reTools.C#L263
Quote:

Originally Posted by src/postProcessing/functionObjects/utilities/pressureTools/pressureTools.C
Code:

void Foam::pressureTools::read(const dictionary& dict)
{
    if (active_)
    {
        dict.readIfPresent("pName", pName_);
        dict.readIfPresent("UName", UName_);
        dict.readIfPresent("rhoName", rhoName_);

        if (rhoName_ == "rhoInf")
        {
            dict.lookup("rhoInf") >> rhoInf_;
        }

        dict.lookup("calcTotal") >> calcTotal_;
        if (calcTotal_)
        {
            dict.lookup("pRef") >> pRef_;
        }

        dict.lookup("calcCoeff") >> calcCoeff_;
        if (calcCoeff_)
        {
            dict.lookup("pInf") >> pInf_;
            dict.lookup("UInf") >> UInf_;
            dict.lookup("rhoInf") >> rhoInf_;
        }
    }
}


Best regards,
Bruno

CFD-Cat March 24, 2014 08:10

Thank you very much Bruno. Now it works! I really appreciate your help.

I didn't check it because in OF2.2.0 it works fine without

Code:

rhoName    rhoInf;

AqeelAhmed168 February 23, 2019 17:12

Monitor Total Pressure in a running simulation using functionobjects
 
For people looking for the same functionality in OpenFOAM version 6

Code:

functions
{

    totalPressureCalc
    {
        type              pressure;
        functionObjectlib ("libfieldFunctionObjects.so");
        rhoName          rhoInf;
        rhoInf            1000;
        pRef              0;
        enabled          yes;
        executeControl    timeStep;
        executeInterval  1;
        writeControl      writeTime;
        writeInterval    1;
        calcTotal        yes;
        calcCoeff        no;
    }
   
    reloadTotalP
    {
        type              readFields;
        functionObjectlib ("libfieldFunctionObjects.so");
        enabled          yes;
        executeControl    timeStep;
        executeInterval  1;
        writeControl      writeTime;
        writeInterval    1;
        fields
        (
            "total(p)"
        );
    }
   
    totalPressureAvgInlet
    {
        enabled        yes;
        type            surfaceFieldValue;
        surfaceFormat  false;
        libs            ("libfieldFunctionObjects.so");
        writeControl    timeStep;
        writeInterval  1;
        log            true;
        writeFields    false;
        regionType      patch;
        name            inlet;
        operation      areaAverage; //- options: sum, areaIntegrate
        mode            magnitude;
        fields
        (
            "total(p)"
        );
    }
   
}


bastil March 10, 2020 04:06

Does anybody know how to do that in OpenFOAM-1906 and 1912? Does not seem to accept "pressure" as a function type. "unknown function type pressure"

Solved: needed to add "libfieldFunctionObjects.so" in the libs-section on top of "controlDict" to make it work.


All times are GMT -4. The time now is 04:40.