|
[Sponsors] |
September 3, 2012, 18:22 |
Volume Average for magnitude U
|
#1 | |
Senior Member
|
Hi,
I am using simpleFunctionObject to average some fields in volume. I can do this for simple filelds like T. for instance I add the following code into controlDict file: Quote:
How can I do that? any suggestions? |
||
September 3, 2012, 18:42 |
|
#2 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
Code:
functions { velAverage { type swakExpression; functionObjectLibs ( "libsimpleSwakFunctionObjects.so" ); verbose true; variables ( "totalV=sum(vol());" ); expression "vol()*mag(U)/totalV"; accumulations ( sum ); } ); An alternative would be to construct a separate field: Code:
functions { makeMagU { type expressionField; functionObjectLibs ( "libswakFunctionObjects.so" ); autowrite false; fieldName magU; expression "mag(U)"; } temp_average { type volumeAverage; functionObjectLibs ( "libsimpleFunctionObjects.so" ); verbose true; fields (magU); } } |
||
September 4, 2012, 03:07 |
|
#3 | ||
Senior Member
|
Hi Bernhard and thanks for your useful answer. there is problem I have while running my case. When I use your second code in controlDict File, I get the following error message in openFOAM:
Quote:
Quote:
|
|||
September 4, 2012, 07:08 |
|
#4 | ||
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Sorry. I should have said that I wrote the examples without testing them:
Quote:
ls $FOAM_USER_LIBBIN/libswakFunctionObjects.so if it really exists. Quote:
valueType internalField; BTW: this is generally applicable for working with OpenFOAM: if it is complaining about a missing entry then add that entry (in this case valueType) and then use the "banana trick": http://openfoamwiki.net/index.php/Op...de/Use_bananas |
|||
September 4, 2012, 09:07 |
|
#5 | ||
Senior Member
|
Quote:
Quote:
|
|||
September 4, 2012, 11:32 |
|
#6 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
Good |
||
September 4, 2012, 14:00 |
|
#7 | |
Senior Member
|
Quote:
I have attached the log file of recompilation. |
||
September 4, 2012, 14:33 |
|
#8 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
Also go to Libraries/Allwmake and in the first line replace /bin/sh with /bin/bash |
||
September 4, 2012, 15:00 |
|
#9 | |
Senior Member
|
Quote:
Bernhard is there any way to define a new volume to calculate averages in this specified volume? |
||
September 4, 2012, 15:18 |
|
#10 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
Specification of zones and set is either done in the mesh generator or with the topoSet (or the setSet)-utility. But the usage of those has nothing to do with swak4Foam (except that swak provides topoSources based on expressions) |
||
September 4, 2012, 15:39 |
|
#11 | |
Senior Member
|
Quote:
|
||
September 4, 2012, 15:52 |
|
#12 |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
||
September 4, 2012, 16:27 |
|
#13 |
Senior Member
|
||
October 17, 2012, 12:46 |
|
#14 |
Member
Simon Arne
Join Date: May 2012
Posts: 42
Rep Power: 14 |
Hey,
I am sorry to bring this up again, but I experience problems with the described way of calculating the average mag(U) over a plane. I have a simple pipe (flow is 12m/s with air, laminar, no turb model yet) and added the following to my controlDict: Code:
functions { makeMagU { type expressionField; functionObjectLibs ( "libswakFunctionObjects.so" ); autowrite false; fieldName magU; expression "mag(U)"; } makerho { type expressionField; functionObjectLibs ( "libswakFunctionObjects.so" ); autowrite false; fieldName rho; expression "1.199"; } messung_40d { type faceSource; functionObjectLibs ("libfieldFunctionObjects.so"); enabled true; outputControl outputTime; // Output to log&file (true) or to file only log true; // Output field values as well valueOutput true; //true; // Type of source: patch/faceZone/sampledSurface source sampledSurface; sampledSurfaceDict { type cuttingPlane; planeType pointAndNormal; pointAndNormalDict { basePoint (0.185 0 0); normalVector (1 0 0); } source cells; // sample cells or boundaryFaces interpolate true; } // Operation: areaAverage/sum/weightedAverage ... operation areaAverage; fields ( p U magU ); } messung_48d { type faceSource; functionObjectLibs ("libfieldFunctionObjects.so"); enabled true; outputControl outputTime; // Output to log&file (true) or to file only log true; // Output field values as well valueOutput true; //true; // Type of source: patch/faceZone/sampledSurface source sampledSurface; sampledSurfaceDict { type cuttingPlane; planeType pointAndNormal; pointAndNormalDict { basePoint (0.281 0 0); normalVector (1 0 0); } source cells; // sample cells or boundaryFaces interpolate true; } // Operation: areaAverage/sum/weightedAverage ... operation areaAverage; fields ( p U magU ); } } Code:
# Source : sampledSurface sampledSurface # Faces : 204 # Time sum(magSf) areaAverage(p) areaAverage(U) areaAverage(magU) 100 0.000104042 -0.511471 (14.8039 0.00143989 0.0096608) 14.804 200 0.000104042 -1.07848 (15.1898 -0.002704 0.00862669) 15.1898 300 0.000104042 -1.10052 (15.2711 -0.002448 0.00478738) 15.2711 400 0.000104042 -1.13157 (15.2688 -0.00338944 0.00642759) 15.2688 500 0.000104042 -1.05324 (15.2643 -0.00676656 0.00863005) 15.2643 600 0.000104042 -1.30854 (15.2804 -0.00189827 0.00590263) 15.2804 700 0.000104042 -1.30885 (15.2774 -0.00181508 0.00626128) 15.2774 800 0.000104042 -1.29363 (15.2785 -0.00386213 0.00488485) 15.2785 900 0.000104042 -1.29393 (15.278 -0.00271772 0.00544641) 15.2781 1000 0.000104042 -1.28934 (15.2778 -0.00274002 0.00545235) 15.2781 What did I do wrong here? I thought my lines to the control dict would just create a field mag(U) out of the calculated U vector field and then place a slice through it and calculate an average. Is it possible that the SWAK-code leaves out cells with a mag(U) value of 0 for some reason? My mesh is pretty rough, so a high percentage of the cells actually has the wall boundary condition of U = (0 0 0). I found out that my average values for pressure seem to be perfectly fine (SWAK sampling and manual paraView pp lead to the exact same numbers)! So its only a mag(U) thing here... Last edited by simpomann; October 17, 2012 at 13:24. |
|
October 17, 2012, 13:52 |
|
#15 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
What you can do to check is: - set autowrite for magU to true and check it in Paraview - emulate the area-weighted average in with a swakExpression on the same sampledSurface (I think the expression would be "mag(U)*area()/sum(area())" with an accumulation sum)
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
||
October 17, 2012, 16:54 |
|
#16 |
Member
Simon Arne
Join Date: May 2012
Posts: 42
Rep Power: 14 |
Hey,
Great thanks for your quick reply! I checked the magU field, slicing and integrating it in a paraView leads to 12.05 m/s, so the field data actually seems to be ok! The problem seems to be the sampled Surface (as you suggested). But is it a user fault or a bug? I tested the same function object in different cases, the results for velocity were always a bit higher than expected and they differ from those obtained in paraView up to 20%. The results from paraView always seem more accurate to me (considering my expectations/boundary etc). As it is working out for the pressure field perfectly, I would say the sampled Surface is defined and adressed correctly, there must be something in the way this deals with the mag(U) field. Because I am only a user (and student), I lack the knowledge to understand the problem. I try to make use of your second advice but i struggle with the code. I put an update here asap. # "keyword weightField is undefined" , lets see if I can find out where I have to initialise this one # okay, i think i figured out the place for the code #okay i was wrong! Last edited by simpomann; October 18, 2012 at 06:44. |
|
October 17, 2012, 18:37 |
|
#17 | ||
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
If the problem is in the sampledSurface-code then it will affect swak too. If it is in the faceSource-code ... not Quote:
Code:
createPlane { type createSampledSurface; outputControl timeStep; outputInterval 1; surfaceName plane; surface { <insert your sampled surface definition here> } } magUAverage { type swakExpression; valueType surface; surfaceName plane; verbose true; expression "mag(U)*area()/sum(area())"; accumulations ( sum ); } Clearer?
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
|||
October 17, 2012, 19:13 |
|
#18 |
Member
Simon Arne
Join Date: May 2012
Posts: 42
Rep Power: 14 |
Big thanks,
with this code I can observe the mag(U) value on a self defined plane for each time step! Wonderful! This was very helpful. Unluckily the behaviour is the same like the other function object Greetings, Simon Last edited by simpomann; October 17, 2012 at 19:59. |
|
October 18, 2012, 06:35 |
|
#19 |
Member
Simon Arne
Join Date: May 2012
Posts: 42
Rep Power: 14 |
So I tried with your work around as well:
Code:
# Time sum 1 12.0545 2 12.2684 3 12.4398 4 12.7395 5 12.8805 .... 45 14.2587 46 14.2731 47 14.2887 48 14.3114 49 14.3319 50 14.3429 With every timestep the difference between the actual field values and the processed average becomes bigger. I use Ubuntu 12.04, OF 210 and compiled SWAK 1 month ago so it should be up to date i guess, although I dont know exactly how can i verify this. |
|
October 18, 2012, 06:56 |
|
#20 | ||
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
If you feel like giving back it would be nice if you consider adding this as a little recipie on the openfoamwiki.net (either on the swak-page or linked from it) Quote:
- check if the area of the surface is as expected (calculate "area()" with an accumulation "sum" on the surface). But that would be too easy - use the sample-utilitiy to write VTKs of the surface and check in Paraview whether the values there are the same as the ones you get when cutting the volume data in paraview
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
|||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Other] mesh airfoil NACA0012 | anand_30 | OpenFOAM Meshing & Mesh Conversion | 13 | March 7, 2022 18:22 |
how to set periodic boundary conditions | Ganesh | FLUENT | 15 | November 18, 2020 07:09 |
On the damBreak4phaseFine cases | paean | OpenFOAM Running, Solving & CFD | 0 | November 14, 2008 22:14 |
fluent add additional zones for the mesh file | SSL | FLUENT | 2 | January 26, 2008 12:55 |
[blockMesh] Axisymmetrical mesh | Rasmus Gjesing (Gjesing) | OpenFOAM Meshing & Mesh Conversion | 10 | April 2, 2007 15:00 |