def boxarr(): """BoxArray for MultiFab creation""" #bx = amrex.Box.new((0, 0, 0), (63, 63, 63)) bx = amrex.Box(amrex.IntVect(0, 0, 0), amrex.IntVect(63, 63, 63)) ba = amrex.BoxArray(bx) ba.max_size(32) return ba
def test_rounding(): # floor vlower = amrex.IntVect([1 + ii for ii in range(amrex.Config.spacedim)]) vupper = amrex.IntVect([2 + ii for ii in range(amrex.Config.spacedim)]) v2 = amrex.RealVect([1.5 + ii for ii in range(amrex.Config.spacedim)]) v3 = amrex.RealVect([1.49 + ii for ii in range(amrex.Config.spacedim)]) assert (v2.floor() == vlower) assert (v3.ceil() == vupper) assert (v2.round() == vupper) assert (v3.round() == vlower)
def test_iv_3d1(): obj = amrex.IntVect(1, 2, 3) # Check indexing assert (obj[0] == 1) assert (obj[1] == 2) assert (obj[2] == 3) assert (obj[-1] == 3) assert (obj[-2] == 2) assert (obj[-3] == 1) with pytest.raises(IndexError): obj[-4] with pytest.raises(IndexError): obj[3] # Check properties assert (obj.max == 3) assert (obj.min == 1) assert (obj.sum == 6) # Check assignment obj[0] = 2 obj[1] = 3 obj[2] = 4 assert (obj[0] == 2) assert (obj[1] == 3) assert (obj[2] == 4)
def test_iv_1d(): obj = amrex.IntVect(1) assert (obj[0] == 1) assert (obj[-1] == 1) with pytest.raises(IndexError): obj[-2] with pytest.raises(IndexError): obj[1]
def test_iv_3d2(): obj = amrex.IntVect(3) assert (obj[0] == 3) assert (obj[1] == 3) assert (obj[2] == 3) assert (obj[-1] == 3) assert (obj[-2] == 3) assert (obj[-3] == 3) with pytest.raises(IndexError): obj[-4] with pytest.raises(IndexError): obj[3] obj = amrex.IntVect([2, 3, 4]) assert (obj[0] == 2) assert (obj[1] == 3) assert (obj[2] == 4)
def test_iv_conversions(): obj = amrex.IntVect.max_vector().numpy() assert (isinstance(obj, np.ndarray)) assert (obj.dtype == np.int32) # check that memory is not collected too early iv = amrex.IntVect(2) obj = iv.numpy() del iv assert (obj[0] == 2)
def test_iv_2d(): obj = amrex.IntVect(1, 2) assert (obj[0] == 1) assert (obj[1] == 2) assert (obj[-1] == 3) assert (obj[-2] == 2) with pytest.raises(IndexError): obj[-3] with pytest.raises(IndexError): obj[2]
def test_iv_ops(): gold = amrex.IntVect(2) one = amrex.IntVect.unit_vector() two = one + one assert (two == gold) assert (two != amrex.IntVect.zero_vector()) assert (two > one) assert (two >= gold) assert (one < two) assert (one <= one) assert (not (one > two)) zero = one - one assert (zero == amrex.IntVect.zero_vector()) mtwo = one * gold assert (two == mtwo) four = amrex.IntVect(4) dtwo = four / gold assert (dtwo == mtwo)
def test_periodicity_3d(): iv = amrex.IntVect(1, 0, 1) obj = amrex.Periodicity(iv) assert (obj.is_any_periodic) assert (obj.is_all_periodic == False) assert (obj.is_periodic(0)) assert (obj.is_periodic(1) == False) assert (obj.is_periodic(2)) assert (obj.is_periodic[2]) bx = obj.domain print(bx) v_iv = ob.shift_IntVect print(v_iv)
def test_rv_3d2(): # rv = amrex.RealVect(0.5,0.4,0.2) rv2 = amrex.RealVect(amrex.IntVect(1, 2, 3)) # assert(rv[1] == 0.4) assert (rv2[2] == 3)
def box(): #return amrex.Box((0, 0, 0), (127, 127, 127)) return amrex.Box(amrex.IntVect(0, 0, 0), amrex.IntVect(127, 127, 127))
def test_length(box): print(box.length()) assert (box.length() == amrex.IntVect(128, 128, 128))