CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM (
-   -   Split Mesh (

lindner September 13, 2010 11:42

Split Mesh
I need to get the weighted average value of a variable in two different zones. How can i split the mesh like zone1 (upper part) and zone2 (lower part) to get these results?

The actual code that im using is:
scalar averageT = T.weightedAverage(mesh.V()).value();

but as you can see it gets the whole mesh values.

Is it possible to specify like mesh.V(zone1) and mesh.V(zone2) ?
If its possible how can i divide the mesh? im using blockMesh with several blocks.

Any other suggestion on how to collect these results?


l_r_mcglashan September 13, 2010 13:31

1 Attachment(s)
You could look at using cellSet and something like boxToCell. I had to do something similar recently to calculate the weighted average of a variable within a certain area of the mesh.

I've attached the files if you're interested.

lindner September 14, 2010 05:58

Hi Laurence!
Thank you for the fast answer and the calculator!
I compiled it and it seems to be working, but my output is like this:


Create time

Create mesh for time = 0

Time = 0
Reading holdupCalculationDict
Time = 500
Reading holdupCalculationDict
Time = 1000
Reading holdupCalculationDict

ExecutionTime = 9.08 s  ClockTime = 10 s


Nothing is generated or changed. Should I do some preparation on my mesh before or just the holdupCalculation file in the /system is enough?


l_r_mcglashan September 14, 2010 06:18

1 Attachment(s)
I've quickly made it more general to average any variable (see attached).

You'll have to change the name of the variable in holdupCalculation and the dimensions of the box you're averaging the variable in. The variable must be in the time folders for anything to be output.

If you want a shape other than a box you'll have to alter the code slightly.

lindner September 14, 2010 07:40

Now it worked perfectly! You did a great job with this code.
Thank you a lot Laurence.


l_r_mcglashan September 14, 2010 08:01

No problem, be careful with it. It's a good idea to work out a rough estimate for the average to make sure it's calculating it correctly.

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