|
[Sponsors] |
December 19, 2017, 01:34 |
patchIntegrate
|
#1 |
Member
Upuli
Join Date: Feb 2016
Posts: 68
Rep Power: 10 |
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 |
|
December 19, 2017, 05:50 |
|
#2 |
New Member
Dominik Münch
Join Date: Oct 2017
Posts: 3
Rep Power: 9 |
Unfortunately I have no experience using this function but if you just want to know it you can use paraview and the integrateVariables filter.
|
|
December 20, 2017, 07:12 |
|
#3 |
Senior Member
|
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 ); } Regards, Tom |
|
December 20, 2017, 23:07 |
|
#4 |
Member
Upuli
Join Date: Feb 2016
Posts: 68
Rep Power: 10 |
Hi
Thank you very much. I used Toms code and it worked. rgds upuli |
|
April 8, 2020, 03:23 |
|
#5 | |
Member
Gui Miotto
Join Date: Feb 2020
Posts: 30
Rep Power: 6 |
Quote:
Hi @tomf, Is it possible to adapt this function to get the flow rate of a specific phase (say water) when using interFoam? |
||
April 8, 2020, 04:23 |
|
#6 |
Senior Member
|
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) } Last edited by tomf; April 8, 2020 at 06:11. Reason: Error fixed as found by miotto in next post and clarification |
|
April 8, 2020, 05:28 |
|
#7 |
Member
Gui Miotto
Join Date: Feb 2020
Posts: 30
Rep Power: 6 |
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); Code:
Field alpha.water not found in database |
|
April 8, 2020, 06:10 |
|
#8 |
Senior Member
|
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 |
|
April 8, 2020, 07:00 |
|
#9 |
Member
Gui Miotto
Join Date: Feb 2020
Posts: 30
Rep Power: 6 |
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 |
|
April 8, 2020, 07:54 |
|
#10 |
Senior Member
|
Ok, now I see, probably you need to run postProcess like this:
Code:
interFoam -postProcess Code:
postProcess -fields alpha.water |
|
April 8, 2020, 08:23 |
|
#11 |
Member
Gui Miotto
Join Date: Feb 2020
Posts: 30
Rep Power: 6 |
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; } } 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 ... 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)? |
|
April 8, 2020, 08:37 |
|
#12 |
Member
Gui Miotto
Join Date: Feb 2020
Posts: 30
Rep Power: 6 |
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. |
|
April 8, 2020, 09:14 |
|
#13 |
Senior Member
Yann
Join Date: Apr 2012
Location: France
Posts: 1,236
Rep Power: 29 |
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 |
|
April 8, 2020, 11:37 |
|
#14 |
Member
Gui Miotto
Join Date: Feb 2020
Posts: 30
Rep Power: 6 |
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? |
|
April 8, 2020, 14:22 |
|
#15 |
Senior Member
|
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 |
|
April 8, 2020, 18:03 |
|
#16 |
Member
Gui Miotto
Join Date: Feb 2020
Posts: 30
Rep Power: 6 |
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; } } 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() 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. |
|
November 6, 2020, 10:55 |
|
#17 |
New Member
Join Date: May 2018
Location: Vienna, Austria
Posts: 14
Rep Power: 8 |
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; } Last edited by evamaria; November 11, 2020 at 09:31. |
|
August 30, 2021, 10:17 |
|
#18 |
Member
Join Date: Apr 2014
Location: N/A
Posts: 50
Rep Power: 12 |
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. |
|
August 30, 2021, 10:31 |
|
#19 | |
Member
Gui Miotto
Join Date: Feb 2020
Posts: 30
Rep Power: 6 |
Quote:
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. |
||
August 31, 2021, 03:44 |
|
#20 |
Member
Join Date: Apr 2014
Location: N/A
Posts: 50
Rep Power: 12 |
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; } } 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 05:02. Reason: Wrote code and continued finding something that could answer |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Runtime using of patchIntegrate Untiity | harsha_kulkarni | OpenFOAM Programming & Development | 5 | August 24, 2015 15:53 |
Interpreting PatchIntegrate Data | Gabbee90 | OpenFOAM Post-Processing | 1 | December 5, 2014 16:45 |
patchIntegrate results? | MarEMotion | OpenFOAM Post-Processing | 1 | December 5, 2014 16:36 |
patchIntegrate suggestion | rcastilla | OpenFOAM Post-Processing | 0 | February 20, 2014 05:46 |
forces function VS patchIntegrate | andrea.pasquali | OpenFOAM | 13 | August 18, 2011 17:41 |