CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Running, Solving & CFD (
-   -   How to get cumulative summation of one field (

lin May 15, 2009 06:18

How to get cumulative summation of one field

I have a question whether I could do cumulative summation in openfoam.For example

original field

1 2 3
4 5 6
7 8 9

after the cumulative summation,I want to get

1 2 3
5 7 9
12 15 18

Is it possible?Anybody could give me a hint.Thanks.

su_junwei May 15, 2009 07:12

Hi hua

Declare a field variable sum with zeros as its initial values, and add the fieldvariable you want to cumulate



lin May 15, 2009 08:58

Hi, Junwei

Thanks for your reply.but I do not get the point.Your method is ok for summing different variables,but what I want is to sum the different part of the same variable.

For example.Take one scalar filed. A
The surface layer values are a1 a2 a3 ...
The layer next to the surface layer b1 b2 b3 ....
and next c1 c2 c3 ...

All are in one volscalarfield.I want to get

a1 a2 a3 ....
a1+b1 a2+b2 a3+b3 ....
a1+b1+c1 a2+b2+c2 a3+b3+c3

lin May 15, 2009 09:00

Or I could change my question and pose one related.

If I have a volscalarfiled,How could I get different layers of the field.

su_junwei May 16, 2009 04:28

Hi Hua

I think a possible way is that
Get the locations of the points in different layers, and using interpolation to get the values you want to sum, and do the following operation.


lin May 16, 2009 08:42

Thanks Junwei.

Yes,I know the principle how to do it.But I do not know exactly how to get it.

I have seen some posts introducing how to get one exact grid data,but as to how to get the data in one grid layer,I'm still confused how to get it.

This addition is quite simple for some codes those use subscript to identify the grid,in which I could simply do A[i,j,k]+A[i,j,k-1]+A[i,j,k-2].... but in OF,I do not know how to.

su_junwei May 16, 2009 15:18

Hi lin

the class "probes" may give you some hits.
this class is located at
src sampling probes


lin May 17, 2009 09:52

Thanks for your hints,Junwei.

I will try to get it. One more thing,I guess there maybe some misunderstanding. The new field I want to get is still for other calculation in OF,not for post processing.

All times are GMT -4. The time now is 01:00.