Hi Mike and Matt,
Thank you! Both those solutions look great.
I like Mike's a lot for its transparency, but possibly Matt's might end up making slightly neater code.
One question, Matt:
Okay, sorry for being dense. But basically what I'm getting is that you want the functionality of covering grids, but you want to be able to restrict the grids from going above some level L, right?
Or below. I just want cells on one level only.
And for the Level 1 case you mention above, do you want contributions from Level 0? (That's not so hard to do.)
No. So I want an array that contains only cells from level 1, with no contributions from 0 or 2.
To do this with a covering grid you could pre-allocate:
Li = 0 Lo = 3
cg = pf.h.covering_grid(Li, [0, 0, 0], pf.domain_dimensions * pf.refine_by**Li) output = np.empty(pf.domain_dimensions * pf.refine_by**Lo) nd = pf.refine_by**(Lo-li) for i in range(nd): for j in range(nd): for k in range(nd): output[i::nd,j::nd,k::nd] = cg[field]
Ah ok! So this is the same as Mike's method in that a covering_grid is created at the resolution of the cell size on the specified level, and then the array values are multiplied to give the correct number for a higher resolution? (Which works fine for the basic quantities; density, energy and velocity but won't for cell mass -- which is totally fine).
My only question is:
If I do this for level (e.g.) 2 and level 2 doesn't cover the whole domain -- what does the covering grid do when there are no level 2 cells over a region of space?