|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +import numpy as np |
| 4 | +import pytest |
| 5 | + |
| 6 | +import amrex.space3d as amr |
| 7 | + |
| 8 | + |
| 9 | +@pytest.mark.skipif(amr.Config.spacedim != 1, reason="Requires AMREX_SPACEDIM = 1") |
| 10 | +def test_indextype_1d(): |
| 11 | + obj = amr.IndexType(amr.IndexType.CellIndex.NODE) |
| 12 | + assert obj.node_centered() |
| 13 | + assert not obj.cell_centered() |
| 14 | + with pytest.raises(IndexError): |
| 15 | + obj[-2] |
| 16 | + with pytest.raises(IndexError): |
| 17 | + obj[1] |
| 18 | + |
| 19 | + |
| 20 | +@pytest.mark.skipif(amr.Config.spacedim != 2, reason="Requires AMREX_SPACEDIM = 2") |
| 21 | +def test_indextype_2d(): |
| 22 | + obj = amr.IndexType(amr.IndexType.CellIndex.NODE, amr.IndexType.CellIndex.CELL) |
| 23 | + assert obj.node_centered(0) |
| 24 | + assert obj.cell_centered(1) |
| 25 | + assert obj.node_centered(-2) |
| 26 | + assert obj.cell_centered(-1) |
| 27 | + |
| 28 | + with pytest.raises(IndexError): |
| 29 | + obj[-3] |
| 30 | + with pytest.raises(IndexError): |
| 31 | + obj[2] |
| 32 | + |
| 33 | + |
| 34 | +@pytest.mark.skipif(amr.Config.spacedim != 3, reason="Requires AMREX_SPACEDIM = 3") |
| 35 | +def test_indextype_3d(): |
| 36 | + obj = amr.IndexType(amr.IndexType.CellIndex.NODE, amr.IndexType.CellIndex.CELL, amr.IndexType.CellIndex.NODE) |
| 37 | + |
| 38 | + # Check indexing |
| 39 | + assert obj.node_centered(0) |
| 40 | + assert obj.cell_centered(1) |
| 41 | + assert obj.node_centered(2) |
| 42 | + assert obj.node_centered(-3) |
| 43 | + assert obj.cell_centered(-2) |
| 44 | + assert obj.node_centered(-1) |
| 45 | + with pytest.raises(IndexError): |
| 46 | + obj[-4] |
| 47 | + with pytest.raises(IndexError): |
| 48 | + obj[3] |
| 49 | + |
| 50 | + # Check methods |
| 51 | + obj.set(1) |
| 52 | + assert obj.node_centered() |
| 53 | + obj.unset(1) |
| 54 | + assert not obj.node_centered() |
| 55 | + |
| 56 | + |
| 57 | +def test_indextype_static(): |
| 58 | + cell = amr.IndexType.cell_type(); |
| 59 | + for i in range(amr.Config.spacedim): |
| 60 | + assert not cell[i] |
| 61 | + |
| 62 | + node = amr.IndexType.node_type(); |
| 63 | + for i in range(amr.Config.spacedim): |
| 64 | + assert node[i] |
| 65 | + |
| 66 | + assert cell == amr.IndexType.cell_type() |
| 67 | + assert node == amr.IndexType.node_type() |
| 68 | + assert cell < node |
| 69 | + |
| 70 | + |
| 71 | +def test_indextype_conversions(): |
| 72 | + node = amr.IndexType.node_type(); |
| 73 | + assert node.ix_type() == amr.IntVect(1) |
| 74 | + assert node.to_IntVect() == amr.IntVect(1) |
0 commit comments