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

patchAverage on totalPressure (both functionObjects)

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

Like Tree3Likes
  • 2 Post By tomf
  • 1 Post By tomf

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 17, 2021, 15:48
Default patchAverage on totalPressure (both functionObjects)
  #1
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
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
   ....
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   February 18, 2021, 06:03
Default
  #2
Senior Member
 
Tom Fahner
Join Date: Mar 2009
Location: Breda, Netherlands
Posts: 634
Rep Power: 32
tomf will become famous soon enoughtomf will become famous soon enough
Send a message via MSN to tomf Send a message via Skype™ to tomf
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
Tobi and Hughtong like this.
tomf is offline   Reply With Quote

Old   January 10, 2022, 13:30
Default
  #3
New Member
 
Join Date: Sep 2020
Posts: 6
Rep Power: 5
furystep is on a distinguished road
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?
furystep is offline   Reply With Quote

Old   January 10, 2022, 16:27
Default
  #4
Senior Member
 
Tom Fahner
Join Date: Mar 2009
Location: Breda, Netherlands
Posts: 634
Rep Power: 32
tomf will become famous soon enoughtomf will become famous soon enough
Send a message via MSN to tomf Send a message via Skype™ to tomf
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 likes this.
tomf is offline   Reply With Quote

Old   January 11, 2022, 06:11
Default
  #5
New Member
 
Join Date: Sep 2020
Posts: 6
Rep Power: 5
furystep is on a distinguished road
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.
furystep is offline   Reply With Quote

Old   January 11, 2022, 06:32
Default
  #6
Senior Member
 
Tom Fahner
Join Date: Mar 2009
Location: Breda, Netherlands
Posts: 634
Rep Power: 32
tomf will become famous soon enoughtomf will become famous soon enough
Send a message via MSN to tomf Send a message via Skype™ to tomf
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)

Last edited by tomf; January 11, 2022 at 06:35. Reason: alignment
tomf is offline   Reply With Quote

Old   January 14, 2022, 12:13
Default
  #7
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
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.
__________________
Keep foaming,
Tobias Holzmann
Tobi 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
totalPressure (why flux direction dependend) Tobi OpenFOAM Running, Solving & CFD 3 October 17, 2019 23:27
About the totalPressure BC fmerk OpenFOAM Running, Solving & CFD 1 September 25, 2017 18:53
totalPressure boundary :Performance Curve (constant RPM) nash OpenFOAM Running, Solving & CFD 0 September 6, 2013 12:34
OpenFOAM v1.6 & OpenMPI & functionObjects bruce OpenFOAM Bugs 7 December 16, 2011 15:37
OpenFOAM v1.6 & OpenMPI & functionObjects bruce OpenFOAM Running, Solving & CFD 1 August 7, 2009 14:15


All times are GMT -4. The time now is 03:44.