Leo [on bcc] and dedalus-users [in case anyone else is grappling with similar in the future],
I would suggest calculating averages via integration using our integration operators. That's much more robust, as you otherwise need to exercise real care when dealing with e.g., the chebshev polynomial grid.
Here's an example for calculating these sorts of things in a 2-D cartesian domain:
vol = Lx*Lz
integ = lambda A: de.Integrate(de.Integrate(A, 'x'), 'z')
avg = lambda A: integ(A)/vol
x_avg = lambda A: de.Integrate(A, 'x')/(Lx)
"avg" is the volume average, while "x_avg" calculates the average in the horizontal (here Fourier) direction.
What you extracted previously via the coefficients is the zero mode in fourier, but also the zero mode in chebyshev (assuming chebyshev vertical grid), and the quadrature weighting on chebyshev coefficients is different and difficult to turn into other relevant quantities like averages. The integral operators make this robust and straightforward.
--Ben
Hi Ben,
Thank you for your quick reply. I have implemented your suggestion in my script. Furthermore, I think it is more convenient for me if I replace the constant pressure gradient with a forcing induced by a constant flow rate. I am planning to do a flow rate which is dependent on the bulk velocity. I tried to calculate the bulk velocity by simply extracting the first Fourier coefficient (by a0=u['c'][0][0][0] (xbasis, 1st node, 1 coefficient). However, when manually calculating the average velocity the results differ. I am still unsure where this error comes from.
Best,
Leo