CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Pre-Processing (https://www.cfd-online.com/Forums/openfoam-pre-processing/)
-   -   patchAverage on totalPressure (both functionObjects) (https://www.cfd-online.com/Forums/openfoam-pre-processing/233941-patchaverage-totalpressure-both-functionobjects.html)

Tobi February 17, 2021 14:48

patchAverage on totalPressure (both functionObjects)
 
Hey all,


we all know that we can use the patchAverage to calculate an averaged field that is stored in the registry of the OpenFOAM such as p, U, k, etc. However, I am more interested in the total-pressure (contribution from the velocity). Hence, I am wondering if we can simply calculate the patch average value of an function object such as the totalPressure?

I don't want to save the totalPressure field on my hard disk and I want to calculate the data each iteration.


Any idea?




Code:

pressureField                                                             
    {                                                                         
        // Mandatory entries (unmodifiable)                                   
        type            pressure;                                             
        libs            (fieldFunctionObjects);                               
                                                                               
        // Mandatory entries (runtime modifiable)                             
        mode            total;                                                 
                                                                               
        // Optional entries (runtime modifiable)                               
        p              p;                                                     
        U              U;                                                     
        rho            rhoInf;                                               
        rhoInf          1.2; // enabled if rho=rhoInf                         
        pRef            0.0;                                                   
        hydroStaticMode none;                                                 
                                                                               
                                                                               
        writeControl    adjustableRunTime;                                     
        writeInterval  0.1;                                                   
    }     


  // Now calculate the patchAverage of that field on any patch
  ....


tomf February 18, 2021 05:03

Hi Tobi,

I have used this in the past for a total pressure difference. It did not write total(p) every timestep, but it did write the delta.

Both use executeControl timeStep as default. For your case you may need to adapt it a bit, but I hope the general idea is clear.

Code:

    totalPressure
    {
        type                pressure;
        writeControl        writeTime;
        mode                total;
        rho                rhoInf;
        rhoInf              1.2;
        pRef                0;
        libs                (fieldFunctionObjects);
    }
    deltaTotalPressure_inOutlet
    {
        type            fieldValueDelta;
        libs (fieldFunctionObjects);
        operation      subtract;
   
        region1
        {
            type            surfaceFieldValue;
            libs            (fieldFunctionObjects);
            log            false;
            writeControl    timeStep;
            writeFields    false;
            regionType      patch;
            name            tunnel_inlet;
            operation      areaAverage;
            fields          ( total(p) );
        }
   
        region2
        {
            type            surfaceFieldValue;
            libs            (fieldFunctionObjects);
            log            false;
            writeControl    timeStep;
            writeFields    false;
            regionType      patch;
            name            tunnel_outlet;
            operation      areaAverage;
            fields          ( total(p) );
        }       
    }

Cheers, Tom

furystep January 10, 2022 12:30

Hi guys, I tried the code but it doesn't work. I don't know where is the problem. This is the dictionary I called FOdeltaP

HTML Code:

totalPressure
{
        type                pressure;
        libs                ("libfieldFunctionObjects.so");

        mode                total;
        pRef                                0;
       
        /*p              p;
    U                      U;
    rho            1.0;*/
       
        calcTotal                        yes;
        calcCoeff                        no;
}

deltaTotalPressure_inOutlet
{
        type            fieldValueDelta;
        libs ("libfieldFunctionObjects.so");
        operation      subtract;

        region1
        {
                type            surfaceFieldValue;
                libs            ("libfieldFunctionObjects.so");
                log            false;
                writeControl    timeStep;
                writeFields    false;
                regionType      patch;
                name            inlet;
                operation      areaAverage;
                fields          ( total(p) );
        }

        region2
        {
                type            surfaceFieldValue;
                libs            ("libfieldFunctionObjects.so");
                log            false;
                writeControl    timeStep;
                writeFields    false;
                regionType      patch;
                name            outlet;
                operation      areaAverage;
                fields          ( total(p) );
        }       
}

I included this file in system/controlDict.functions and called the command:
HTML Code:

postProcess
.

The result is this error message:
HTML Code:

ime = 0

Reading fields:

Executing functionObjects
--> FOAM Warning :    functionObjects::pressure totalPressure cannot find required object p of type volScalarField
--> FOAM Warning :    functionObjects::pressure totalPressure failed to execute.
surfaceFieldValue deltaTotalPressure_inOutlet.region1 write:
    total faces  = 875
    total area    = 5.94739e-05

--> FOAM Warning :
    From Foam::label Foam::functionObjects::fieldValues::surfaceFieldValue::writeAll(const vectorField&, const Foam::Field<Type>&, const pointField&, const faceList&) [with WeightType = double; Foam::label = int; Foam::vectorField = Foam::Field<Foam::Vector<double> >; Foam::pointField = Foam::Field<Foam::Vector<double> >; Foam::faceList = Foam::List<Foam::face>]
    in file fieldValues/surfaceFieldValue/surfaceFieldValueTemplates.C at line 345
    Requested field total(p) not found in database and not processed

surfaceFieldValue deltaTotalPressure_inOutlet.region2 write:
    total faces  = 550
    total area    = 3.58576e-05

--> FOAM Warning :
    From Foam::label Foam::functionObjects::fieldValues::surfaceFieldValue::writeAll(const vectorField&, const Foam::Field<Type>&, const pointField&, const faceList&) [with WeightType = double; Foam::label = int; Foam::vectorField = Foam::Field<Foam::Vector<double> >; Foam::pointField = Foam::Field<Foam::Vector<double> >; Foam::faceList = Foam::List<Foam::face>]
    in file fieldValues/surfaceFieldValue/surfaceFieldValueTemplates.C at line 345
    Requested field total(p) not found in database and not processed

fieldValueDelta deltaTotalPressure_inOutlet write:
    none

Do you have any idea?

tomf January 10, 2022 15:27

Hi,

Maybe you can specify which fields to load when running postProcess:

Code:

postProcess -fields '(U p)'
Or use the postProcess option of the solver (for example with simpleFoam):

Code:

simpleFoam -postProcess
Which should load/read the fields that simpleFoam normally loads (depending on turbulence for instance).

Hope this helps,
Tom

furystep January 11, 2022 05:11

Hi, thank you for the fast response. It works!

Now I am trying to apply the same function object to a different field, "p_rgh". Every time I try calling this field:

HTML Code:

totalPressure
{
        type                  pressure;
        libs                  ("libfieldFunctionObjects.so");
        mode                total;
        p                      p_rgh;
        U                      U;
        rho                    rho;
}
deltaTotalPressure_inOutlet
{
        type            fieldValueDelta;
        libs                        ("libfieldFunctionObjects.so");
        operation      subtract;

        region1
        {
                type            surfaceFieldValue;
                libs            ("libfieldFunctionObjects.so");
                log            false;
                writeControl    timeStep;
                writeFields    false;
                regionType      patch;
                name            inlet;
                operation      areaAverage;
                fields          ( total(p_rgh) );
        }

        region2
        {
                type            surfaceFieldValue;
                libs            ("libfieldFunctionObjects.so");
                log            false;
                writeControl    timeStep;
                writeFields    false;
                regionType      patch;
                name            outlet;
                operation      areaAverage;
                fields          ( total(p_rgh) );
        }       
}


I am passing p_rgh in the calling command, but the error is the same.

tomf January 11, 2022 05:32

Hi,

Not sure if the new variable would still be called total(p) or now total(p_rgh). You may be able to give another name by using:

Code:

totalPressure
{
        type      pressure;
        libs      "libfieldFunctionObjects.so");
        mode      total;
        p          p_rgh;
        U          U;
        rho        rho;
        result    totPrgh;
}

Then you use totPrgh in the delta functionobject instead of total(p_rgh)

Tobi January 14, 2022 11:13

Good point using the keyword result. This name is used to construct the object inside the calc() function in the FO. However, the resultName_ by default is constructed by the resultName() function.



Code:


resultName_ = dict.getOrDefault<word>("result", resultName());


Code:

Foam::word Foam::functionObjects::pressure::resultName() const
 {
    word rName;
 
    if (mode_ & STATIC)
    {
        rName = "static(" + fieldName_ + ")";
    }
    else if (mode_ & TOTAL)
    {
        rName = "total(" + fieldName_ + ")";
    }
    else if (mode_ & ISENTROPIC)
    {
        rName = "isentropic(" + fieldName_ + ")";
    }
    else
    {
        FatalErrorInFunction
            << "Unhandled calculation mode " << modeNames[mode_]
            << abort(FatalError);
    }
 
    switch (hydrostaticMode_)
    {
        case NONE:
        {
            break;
        }
        case ADD:
        {
            rName = rName + "+rgh";
 
            break;
        }
        case SUBTRACT:
        {
            rName = rName + "-rgh";
 
            break;
        }
    }
 
    if (mode_ & COEFF)
    {
        rName += "_coeff";
    }
 
    return rName;
 }

If I got it correct, your field name can either be:
  • total(p_rgh)
  • total(p_rgh+rgh)
  • total(p_rgh-rgh)
And if for any reasons the coefficients are set the string _coeff is added.

So I guess with Tom's hint, you should be ready to go.


All times are GMT -4. The time now is 05:57.