yt-project / yt

Main yt repository
http://yt-project.org
Other
468 stars 280 forks source link

[AMRVAC] bug: downsampling AMR is broken #2479

Open neutrinoceros opened 4 years ago

neutrinoceros commented 4 years ago

Bug report

based off https://yt-project.org/docs/dev/cookbook/calculating_information.html#downsampling-an-amr-dataset

I noticed that this feature doesn't work as intended at least for AMRVAC data.

working example with a fake amr dataset

import yt

ds = yt.testing.fake_amr_ds(fields=["density"])
ds.print_stats()
p1 = yt.SlicePlot(ds, "z", "density")
p1.save("/tmp/fake_ds_raw")

ds.max_level = 1
p2 = yt.SlicePlot(ds, "z", "density")
p2.save("/tmp/fake_ds_dowsampled")

output

level   # grids        # cells       # cells^3
----------------------------------------------
  0      1           32768              32
  1      8           34304              33
  2      8          181888              57
  3      8          646968              87
  4     15          947856              99
----------------------------------------------
        40         1843784

t = 0.00000000e+00 = 0.00000000e+00 s = 0.00000000e+00 years

Smallest Cell:
    Width: 6.330e-28 Mpc
    Width: 6.330e-22 pc
    Width: 1.306e-16 AU
    Width: 1.953e-03 cm

fake_ds_raw_Slice_z_density fake_ds_dowsampled_Slice_z_density

broken example with AMRVAC

import yt

ds = yt.load("amrvac/bw_3d0000.dat")
ds.print_stats()
p1 = yt.SlicePlot(ds, "z", "density")
p1.save("/tmp/amrvac_ds_raw")

ds.max_level = 1
p2 = yt.SlicePlot(ds, "z", "density")
p2.save("/tmp/armvac_ds_downsampled")

output

level   # grids        # cells       # cells^3
----------------------------------------------
  1     56           28672              31
  2     64           32768              32
----------------------------------------------
       120           61440

t = 2.00000000e-02 = 1.71746294e-06 s = 5.44231165e-14 years

Smallest Cell:
    Width: 1.013e-26 Mpc
    Width: 1.013e-20 pc
    Width: 2.089e-15 AU
    Width: 3.125e-02 cm

amrvac_ds_raw_Slice_z_density armvac_ds_downsampled_Slice_z_density

matthewturk commented 4 years ago

Yup that looks broken to me, too. My suspicion is that it has something to do with missing non-leaf node data or the level 1 offset.

On Tue, Mar 10, 2020 at 8:32 AM Clément Robert notifications@github.com wrote:

Bug report

based off

https://yt-project.org/docs/dev/cookbook/calculating_information.html#downsampling-an-amr-dataset

I noticed that this feature doesn't work as intended at least for AMRVAC data.

working example with a fake amr dataset

import yt

ds = yt.testing.fake_amr_ds(fields=["density"]) ds.print_stats() ad = ds.all_data() p1 = yt.SlicePlot(ds, "z", "density") p1.save("/tmp/fake_ds_raw")

ds.max_level = 1 p2 = yt.SlicePlot(ds, "z", "density") p2.save("/tmp/fake_ds_dowsampled")

output

level # grids # cells # cells^3

0 1 32768 32 1 8 34304 33 2 8 181888 57 3 8 646968 87 4 15 947856 99

      40         1843784

t = 0.00000000e+00 = 0.00000000e+00 s = 0.00000000e+00 years

Smallest Cell: Width: 6.330e-28 Mpc Width: 6.330e-22 pc Width: 1.306e-16 AU Width: 1.953e-03 cm

[image: fake_ds_raw_Slice_z_density] https://user-images.githubusercontent.com/14075922/76317063-cf176c00-62db-11ea-9d1e-8a7c25ef0af1.png [image: fake_ds_dowsampled_Slice_z_density] https://user-images.githubusercontent.com/14075922/76317066-d0489900-62db-11ea-9640-fe94981bbf66.png

broken example with AMRVAC

import yt

ds = yt.load("amrvac/bw_3d0000.dat") ds.print_stats() ad = ds.all_data() p1 = yt.SlicePlot(ds, "z", "density") p1.save("/tmp/amrvac_ds_raw")

ds.max_level = 1 p2 = yt.SlicePlot(ds, "z", "density") p2.save("/tmp/armvac_ds_downsampled")

output

level # grids # cells # cells^3

1 56 28672 31 2 64 32768 32

     120           61440

t = 2.00000000e-02 = 1.71746294e-06 s = 5.44231165e-14 years

Smallest Cell: Width: 1.013e-26 Mpc Width: 1.013e-20 pc Width: 2.089e-15 AU Width: 3.125e-02 cm

[image: amrvac_ds_raw_Slice_z_density] https://user-images.githubusercontent.com/14075922/76317086-da6a9780-62db-11ea-8021-ac3d6952bcde.png [image: armvac_ds_downsampled_Slice_z_density] https://user-images.githubusercontent.com/14075922/76317088-db9bc480-62db-11ea-9198-1f95df7ae86b.png

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/yt-project/yt/issues/2479?email_source=notifications&email_token=AAAVXO4YIOJ6MSNIQK4GUOTRGY6PFA5CNFSM4LE672HKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IT4ORTQ, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAVXO2NGKOZV2FNE46VML3RGY6PFANCNFSM4LE672HA .

neutrinoceros commented 4 years ago

Sounds likely, as there's no non-leaf node at all in AMRVAC, and I don't think we currently mock anything of the sort.

neutrinoceros commented 4 years ago

I searched for differences between the fakedata example and the amrvac one. All I can say for now in the first case, the method get_global_startindex gets called while AMRVACGrid.get_global_start_index doesn't. I was originally thinking this method is broken but maybe it's more about why it's not getting called. I really don't know how to tackle this, it's even hard to know what portions of yt's core are calling each other.

n-claes commented 4 years ago

Well, AMRVAC only writes data from blocks at the bottom of their respective branch in the AMR tree to the datfile, so all nodes above are empty (for obvious data-storage reasons, the code rebuilds this if needed during a restart). So since a block does not have parents/children containing data (we also never set them in the frontend), I assume that's the reason why downsampling fails? Does yt use data from the parent nodes to downsample?