pyro2 icon indicating copy to clipboard operation
pyro2 copied to clipboard

Add units

Open zingale opened this issue 7 years ago • 2 comments

We should attach units to quantities using the unyt library

zingale avatar Jul 06 '18 14:07 zingale

https://github.com/yt-project/unyt/issues/39

zingale avatar Jul 30 '18 18:07 zingale

@mojiastonybrook: Looking at https://github.com/python-hydro/pyro2/blob/units/mesh/array_indexer.py in https://github.com/python-hydro/pyro2/commit/35f74c4889d5556eb6bdeee00689ebd6bec7cf33, I've noticed a couple of things:

  • The copy function does not copy over the units. Compare the pyro version https://github.com/python-hydro/pyro2/blob/35f74c4889d5556eb6bdeee00689ebd6bec7cf33/mesh/array_indexer.py#L114-L116 vs the unyt version https://github.com/yt-project/unyt/blob/679a4473e8944a9a55f7ffc0a72f569e6c23d85e/unyt/array.py#L1683-L1717

  • When I tried running the smooth problem using the advection solver, I noticed that the code was failing when it tries to create new ArrayIndexer objects here https://github.com/python-hydro/pyro2/blob/35f74c4889d5556eb6bdeee00689ebd6bec7cf33/advection/advective_fluxes.py#L98-L99 F_xt and F_yt are defined here as the product of a scalar and an ArrayIndexer object, however they have not been correctly initialized with grids. It looks like unyt does some clever stuff with multiplication in https://github.com/yt-project/unyt/blob/679a4473e8944a9a55f7ffc0a72f569e6c23d85e/unyt/array.py#L1535-L1681 to ensure consistency of units, so we may need to create some wrapper for this that adds the grids back in. I managed to fix this by initializing the arrays first:

    F_xt = myg.scratch_array()
    F_yt = myg.scratch_array()
    F_xt[:,:] = u*a_x
    F_yt[:,:] = v*a_y

harpolea avatar Aug 10 '18 19:08 harpolea