|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +import numpy |
| 4 | +import pytest |
| 5 | + |
| 6 | +import amrex.space3d as amr |
| 7 | + |
| 8 | + |
| 9 | +@pytest.mark.skipif(not amr.Config.have_eb, reason="Requires -DAMReX_EB=ON") |
| 10 | +def test_makeEBFabFactory(): |
| 11 | + n_cell = 64 |
| 12 | + max_grid_size = 16 |
| 13 | + |
| 14 | + # Build Geometry |
| 15 | + domain = amr.Box( |
| 16 | + amr.IntVect(0, 0, 0), amr.IntVect(n_cell - 1, n_cell - 1, n_cell - 1) |
| 17 | + ) |
| 18 | + real_box = amr.RealBox([0.0, 0.0, 0.0], [1.0, 1.0, 1.0]) |
| 19 | + coord = 0 # Cartesian |
| 20 | + is_per = [1, 1, 1] # is periodic? |
| 21 | + geom = amr.Geometry(domain, real_box, coord, is_per) |
| 22 | + |
| 23 | + # EB parameters |
| 24 | + pp = amr.ParmParse("eb2") |
| 25 | + pp.add("geom_type", "sphere") |
| 26 | + pp.addarr("sphere_center", [0.5, 0.5, 0.5]) |
| 27 | + rsphere = 0.25 |
| 28 | + pp.add("sphere_radius", rsphere) |
| 29 | + pp.add("sphere_has_fluid_inside", 1) |
| 30 | + |
| 31 | + # EB generation |
| 32 | + eb_requried_level = 0 |
| 33 | + eb_max_level = 2 |
| 34 | + amr.EB2_Build(geom, eb_requried_level, eb_max_level) |
| 35 | + |
| 36 | + # Build BoxArray |
| 37 | + ba = amr.BoxArray(domain) |
| 38 | + ba.max_size(max_grid_size) |
| 39 | + |
| 40 | + # Build DistributionMapping |
| 41 | + dm = amr.DistributionMapping(ba) |
| 42 | + |
| 43 | + # Make EB Factory |
| 44 | + ng = amr.Vector_int([1, 1, 1]) |
| 45 | + factory = amr.makeEBFabFactory(geom, ba, dm, ng, amr.EBSupport.full) |
| 46 | + |
| 47 | + # Get EB data |
| 48 | + vfrac = factory.getVolFrac() |
| 49 | + |
| 50 | + dx = geom.data().CellSize() |
| 51 | + total_vol = vfrac.sum() * dx[0] * dx[1] * dx[2] |
| 52 | + sphere_vol = 4.0 / 3.0 * numpy.pi * rsphere**3 |
| 53 | + assert abs(sphere_vol - total_vol) / sphere_vol < 2.0e-3 |
0 commit comments