CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Running, Solving & CFD

patchIntegrate

Register Blogs Community New Posts Updated Threads Search

Like Tree12Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 19, 2017, 00:34
Default patchIntegrate
  #1
Member
 
Upuli
Join Date: Feb 2016
Posts: 68
Rep Power: 10
upuli is on a distinguished road
Dear friends
I want to get the flow rate at the Outlet. I found that this can be done by "patchIntegrate" (patchIntegrate <root> <case> <fieldname> <patchname>). function. But I am not clear on how to add this function in the case folder. I am very much thankful if someone can tell me the correct steps to include this function in ControlDict file.

thanks

rgds

Upuli
upuli is offline   Reply With Quote

Old   December 19, 2017, 04:50
Default
  #2
New Member
 
Dominik Münch
Join Date: Oct 2017
Posts: 3
Rep Power: 8
DominikM is on a distinguished road
Unfortunately I have no experience using this function but if you just want to know it you can use paraview and the integrateVariables filter.
DominikM is offline   Reply With Quote

Old   December 20, 2017, 06:12
Default
  #3
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,

Probably this works:

Code:
OutletFlowRate
{
    type            surfaceFieldValue;
    libs            ("libfieldFunctionObjects.so");

    log             true;
    writeControl    writeTime;
    writeFields     false;

    regionType      patch;
    name            Outlet;

    operation       areaIntegrate;

    fields
    (
        phi
    );
}
Your field may differ from the solver (also check the dimensions).

Regards,
Tom
tomf is offline   Reply With Quote

Old   December 20, 2017, 22:07
Default
  #4
Member
 
Upuli
Join Date: Feb 2016
Posts: 68
Rep Power: 10
upuli is on a distinguished road
Hi

Thank you very much. I used Toms code and it worked.

rgds

upuli
upuli is offline   Reply With Quote

Old   April 8, 2020, 02:23
Default
  #5
Member
 
Gui Miotto
Join Date: Feb 2020
Posts: 30
Rep Power: 6
miotto is on a distinguished road
Quote:
Originally Posted by tomf View Post
Hi,

Probably this works:

Code:
OutletFlowRate
{
    type            surfaceFieldValue;
    libs            ("libfieldFunctionObjects.so");

    log             true;
    writeControl    writeTime;
    writeFields     false;

    regionType      patch;
    name            Outlet;

    operation       areaIntegrate;

    fields
    (
        phi
    );
}
Your field may differ from the solver (also check the dimensions).

Regards,
Tom

Hi @tomf,
Is it possible to adapt this function to get the flow rate of a specific phase (say water) when using interFoam?
miotto is offline   Reply With Quote

Old   April 8, 2020, 03:23
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,

I guess something like this would work:

Code:
OutletFlowRate
{
    type            surfaceFieldValue;
    libs            ("libfieldFunctionObjects.so");

    log             true;
    writeControl    writeTime;
    writeFields     false;

    regionType      patch;
    name            Outlet;

    operation       weightedAreaIntegrate;

    fields
    (
        phi
    );
    weightField     alpha.water;// This should be modified to your phase variable name (see the output from interFoam)
}
You can find more information in the documentation. Note that the exact syntax may depend on the OpenFOAM version you are using and on the names of the variables of your solver, but the general idea is still similar.
miotto and fizsics like this.

Last edited by tomf; April 8, 2020 at 05:11. Reason: Error fixed as found by miotto in next post and clarification
tomf is offline   Reply With Quote

Old   April 8, 2020, 04:28
Default
  #7
Member
 
Gui Miotto
Join Date: Feb 2020
Posts: 30
Rep Power: 6
miotto is on a distinguished road
Thanks for the answer Tom. However I couldn't make it work.


If I use the function as you wrote, I will get an error because of the brackets around alpha.water


Code:
weightField     (alpha.water);
If I remove the brackets, then I can run the case. But running postProcess afterwards will give me an error.


Code:
Field alpha.water not found in database
Any ideas?
tomf likes this.
miotto is offline   Reply With Quote

Old   April 8, 2020, 05:10
Default
  #8
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
Not without more information. Like I said in the previous post, there may be other variables that you have and the syntax may vary. Good that you found out about the brackets. I will edit my post above for future reference.

Your variable may be called differently, probably you see in your log something like solving for alpha followed by some name of the phase. But that depends on your particular problem. Just fill in that name.

Regards,
Tom
miotto likes this.
tomf is offline   Reply With Quote

Old   April 8, 2020, 06:00
Default
  #9
Member
 
Gui Miotto
Join Date: Feb 2020
Posts: 30
Rep Power: 6
miotto is on a distinguished road
When I run a reconstructPar, I see these messages:


Code:
Reconstructing FV fields

    Reconstructing volScalarFields

        p
        p_rgh
        alpha.water

    Reconstructing volVectorFields

        U

    Reconstructing surfaceScalarFields

        phi
        alphaPhi0.water
So the names should be alright, right?
miotto is offline   Reply With Quote

Old   April 8, 2020, 06:54
Default
  #10
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
Ok, now I see, probably you need to run postProcess like this:

Code:
interFoam -postProcess
or maybe this may work:

Code:
postProcess -fields alpha.water
But this depends on your version and you have not specified that.
miotto likes this.
tomf is offline   Reply With Quote

Old   April 8, 2020, 07:23
Default
  #11
Member
 
Gui Miotto
Join Date: Feb 2020
Posts: 30
Rep Power: 6
miotto is on a distinguished road
What do I have up to now:

This is my function:
Code:
functions
{
    BottomFlowRate
    {
        type            surfaceFieldValue;
        libs            ("libfieldFunctionObjects.so");
        fields          (phi);
        writeFields     no;
        regionType      patch;
        name            bottom;
        operation       weightedAreaIntegrate;
        weightField     alpha.water;
    }
}
After running the case, I get inside the postProcessing a file called surfaceFieldValue.dat. It starts like this:

Code:
# Region type : patch bottom
# Faces  :    349
# Area   :    8.725000e-03
# Time            weightedAreaIntegrate(phi)
0.010000          0.000000e+00
0.016667          2.309574e-17
0.023333          3.659132e-15
0.030000          9.138343e-14
...
This time series has really the shape I was expecting. However, its value seems to be scaled by some factor couldn't yet figure out.

It should be something greater than 1 so I tried dividing it by the patch area (8.725000e-03). But the result doens't match.

So, what exactly AreaIntegrate(phi) calculates (considering here interFoam, an incompressible solver)?
miotto is offline   Reply With Quote

Old   April 8, 2020, 07:37
Default
  #12
Member
 
Gui Miotto
Join Date: Feb 2020
Posts: 30
Rep Power: 6
miotto is on a distinguished road
Hi Tom,


This here works without errors, thanks for pointing it out:


Code:
interFoam -postProcess

Nevertheless I'm even more puzzled by the numbers it outputs.


My OpenFOAM is version 7. Sorry for not mentioning it earlier.
miotto is offline   Reply With Quote

Old   April 8, 2020, 08:14
Default
  #13
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,066
Rep Power: 26
Yann will become famous soon enough
Hello miotto,

Phi is the flux at the faces, so this is basically the flowrate going through each faces. (volumetric flowrate for an incompressible solver, but you can verify by checking the dimensions of the phi files)

So to get the flowrate at your patch you just need to sum phi. In your case, I guess you can try using weightedSum with alpha.water as weightField.

Check the header of surfaceFieldValue.H for more information : https://github.com/OpenFOAM/OpenFOAM...ceFieldValue.H

I hope this helps,
Yann
john myce and miotto like this.
Yann is offline   Reply With Quote

Old   April 8, 2020, 10:37
Default
  #14
Member
 
Gui Miotto
Join Date: Feb 2020
Posts: 30
Rep Power: 6
miotto is on a distinguished road
Dear Yann and Tom,


Thank you very much. The thing is now working.
With weightedSum it works out of the box, but with weightedAreaIntegrate it works as well. You just have to correct the value with the average face area.


May I ask you guys one more before you leave? Is there a way to get the accumulated flow rate? In other words, can I create another function that is the time integral of this flow rate function?
miotto is offline   Reply With Quote

Old   April 8, 2020, 13:22
Default
  #15
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,

Nice to know that it works. For the cumulative flow rate I think you need to use a separate script, at least that is what I typically do. I do not know about such a function directly.

Cheers,
Tom
miotto likes this.
tomf is offline   Reply With Quote

Old   April 8, 2020, 17:03
Post
  #16
Member
 
Gui Miotto
Join Date: Feb 2020
Posts: 30
Rep Power: 6
miotto is on a distinguished road
Got it, Tom.


So let me summarize what I've done, for those that may be having the same problem.


So, if you are working with interFoam and want to calculate the flow rate of a specific phase crossing a patch, here is what you can do.


Add the following function to your controlDict:


Code:
functions
{
   //
   // your other functions, if any, will probably go here
   //

    BottomFlowRate  // pick your name
    {
         type            surfaceFieldValue;
         libs             ("libfieldFunctionObjects.so");
         fields          (phi);
         writeFields no;
         regionType patch;
         name          bottom;  // put the name of your patch/outlet here
         operation    weightedSum;
         weightField alpha.water;
    }
}
This function will give you the volumetric flow rate of water crossing the patch. Why volumetric? Because interFoam is a incompressible solver and the flux is volumetric for this kind of solver.


Now, after running the case, a file with the flow rate at each time step will be created inside the folder postProcessing. That's it.


But, if you need the cumulative flow rate (i.e. the total volume that crossed the patch) you probably have to handle this externally. For instance, I wrote this in Python:


Code:
import numpy as np
from scipy.integrate import cumtrapz
import matplotlib.pyplot as plt

filedata = np.loadtxt('postProcessing/BottomFlowRate/0.000000/surfaceFieldValue.dat')
time, flowrate = filedata[:, 0], filedata[:, 1]
cum_flowrate = cumtrapz(flowrate, time)

plt.plot(time[1:], cum_flowrate)
plt.show()
Just make sure to adjust the file path accordinly.


I'm using OpenFOAM 7. Not sure if all this is valid for other versions.

Thanks Tom and Yan for all the support.

Signing off.
tomf, Yann, john myce and 1 others like this.
miotto is offline   Reply With Quote

Old   November 6, 2020, 09:55
Default
  #17
New Member
 
Join Date: May 2018
Location: Vienna, Austria
Posts: 14
Rep Power: 7
evamaria is on a distinguished road
I think the following should do the job automatically, at least in OpenFOAM-8:


Code:
outletFlowRate
{
    type                surfaceFieldValue;
    libs                  ("libfieldFunctionObjects.so");
    fields               (phi.slag);
    writeFields       no;
   regionType        patch;
   name                outlet;
   operation          weightedAreaIntegrate;
   weightField       alpha.slag;

}
- sorry this is wrong. it only integrates over the area of the patch and does not accumulate over time.

Last edited by evamaria; November 11, 2020 at 08:31.
evamaria is offline   Reply With Quote

Old   August 30, 2021, 09:17
Default
  #18
Member
 
Join Date: Apr 2014
Location: N/A
Posts: 47
Rep Power: 12
FluentStarter is on a distinguished road
Hei miotto,

thanks for posting you solution. Do you know if there is a possibility of weighting this value with a product of to scalars? In my simulation (reactingFoam) I would be interested in weighting it with rho*CO2 so density times the mass fraction of CO2 to get the mass flow of CO2 over the boundary.
FluentStarter is offline   Reply With Quote

Old   August 30, 2021, 09:31
Default
  #19
Member
 
Gui Miotto
Join Date: Feb 2020
Posts: 30
Rep Power: 6
miotto is on a distinguished road
Quote:
Originally Posted by FluentStarter View Post
Hei miotto,

thanks for posting you solution. Do you know if there is a possibility of weighting this value with a product of to scalars? In my simulation (reactingFoam) I would be interested in weighting it with rho*CO2 so density times the mass fraction of CO2 to get the mass flow of CO2 over the boundary.

Hey, @FluentStarter, I don't know how to do that. I've never worked with reactingFoam. But what I would try to do instead, is to work with mass flow rates, instead of volumetric flow rates. In this way you don't need to weight by the density, right? Then the solution I posted here should probably work for you. Just substitute the alpha.water by CO2.
miotto is offline   Reply With Quote

Old   August 31, 2021, 02:44
Default
  #20
Member
 
Join Date: Apr 2014
Location: N/A
Posts: 47
Rep Power: 12
FluentStarter is on a distinguished road
That was a quick response.

Well I am aiming for the mass flow rate. I can't follow you why just weighting it by CO2 would give me the mass flow?

To get the mass flux the relevant variables are A (area of outlet), u (velocity normal to outlet), rho (density of the fluid) and CO2 (mass fraction of the species i evaluate).

So ideally I would write:
Code:
functions
{
    BottomFlowRate
    {
        type            surfaceFieldValue;
        libs            ("libfieldFunctionObjects.so");
        fields          (U);
        writeFields     no;
        regionType      patch;
        name            bottom;
        operation       weightedAreaIntegrate;
        weightField     rho*CO2;
    }
}
But as I can not multiply in the weightFIeld this does not work. Does a function for multiplying scalars exist? I only found one for add.....

EDIT: So I searched a bit through the forum and found the possibility to code a function (integrate multiplication of fields)


I tried to modify it a bit and use it:
Code:
functions
{
    velocity_components
    {
        // Mandatory entries (unmodifiable)
        type            components;
        libs            (fieldFunctionObjects);

        // Mandatory (inherited) entry (runtime modifiable)
        field           U;

    enabled         true;
    log             false;

    executeControl  timeStep;
    executeInterval 1;
    writeControl    timeStep;
    writeInterval   1000;
    };
       rhofunc
       {
          type                 writeObjects;
          libs            ("libutilityFunctionObjects.so");
          writeControl        timeStep;
          writeInterval       1000;
          objects
          ("rho");
       }
    rhoCO2
    {
        functionObjectLibs ("libutilityFunctionObjects.so");
        type            coded;
        name            rhoCO2;
        writeFields     no;
        codeWrite
            #{
            if (!mesh().foundObject<volScalarField>("rhCO2")) 
                     {
                        volScalarField*  pzmon = new volScalarField
                            (
                                IOobject
                                    (   
                                    "rhCO2",
                                    mesh().time().timeName(),
                                    mesh(),
                                    IOobject::NO_READ,
                                    IOobject::AUTO_WRITE
                                    ),
                                mesh(), 
                                dimMass/dimVolume
                            );

                        pzmon->store();
                     }

               volScalarField& rhCO2 = 
                        mesh().lookupObjectRef<volScalarField>("rhCO2");
                rhCO2 = 
                        mesh().lookupObject<volScalarField>("rho") * 
                        mesh().lookupObject<volScalarField>("CO2");

        //rhCO2.write();
    #};
}

    CO2FlowRateoutlet
    {
        type            surfaceFieldValue;
        libs            ("libfieldFunctionObjects.so");
        fields          ("Uz");
        writeFields     no;
        regionType      patch;
        name            outlet;
        operation       weightedAreaIntegrate;
        weightField     rhCO2;
    };
        CO2FlowRateinlet
    {
        type            surfaceFieldValue;
        libs            ("libfieldFunctionObjects.so");
        fields          ("Uz");
        writeFields     no;
        regionType      patch;
        name            inletPilot;
        operation       weightedAreaIntegrate;
        weightField     rhCO2;
    };
}

It works now and after some time the mass flows through both the inlet and outlet for CO2 become the same (I run the case without chemistry).

Last edited by FluentStarter; September 1, 2021 at 04:02. Reason: Wrote code and continued finding something that could answer
FluentStarter is offline   Reply With Quote

Reply


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
Runtime using of patchIntegrate Untiity harsha_kulkarni OpenFOAM Programming & Development 5 August 24, 2015 14:53
Interpreting PatchIntegrate Data Gabbee90 OpenFOAM Post-Processing 1 December 5, 2014 15:45
patchIntegrate results? MarEMotion OpenFOAM Post-Processing 1 December 5, 2014 15:36
patchIntegrate suggestion rcastilla OpenFOAM Post-Processing 0 February 20, 2014 04:46
forces function VS patchIntegrate andrea.pasquali OpenFOAM 13 August 18, 2011 16:41


All times are GMT -4. The time now is 13:26.