コード例 #1
0
def test_neighbours_multiple():
    """
           .+-------+-------+
         .'  6    .'  7   .'|
       .+-------+-------+'  |
     .'       .'      .'|   |
    +-------+-------+'  |   +
    |       |       |   | .'|
    |   4   |   5   |   +'  |
    |       |       | .'| 3 |
    +-------+-------+'  |   +
    |       |       |   | .'
    |   0   |   1   |   +'
    |       |       | .'
    +-------+-------+'

    """
    mesh = CuboidMesh(2, 2, 2, 2, 2, 2)
    print(mesh.neighbours)
    assert to_sets(mesh.neighbours) == [
        {1, 2, 4},
        {0, 3, 5},  # for cells 0, 1
        {0, 3, 6},
        {1, 2, 7},  # for cells 2, 3
        {0, 5, 6},
        {1, 4, 7},  # for cells 4, 5
        {4, 2, 7},
        {5, 6, 3}
    ]  # for cells 6, 7
コード例 #2
0
def test_neighbours_x():
    """
       .+---+---+
     .'  .'   .'|
    +---+---+'  |
    |   |   |   |
    | 0 | 1 |   +
    |   |   | .'
    +---+---+'

    """
    mesh = CuboidMesh(1, 1, 1, 2, 1, 1)
    assert to_sets(mesh.neighbours) == [{1}, {0}]
コード例 #3
0
def test_neighbours_z():
    """
       .+---0---+
     .'       .'|
    +-------+'  +
    |   1   | .'|
    +-------+'  +
    |   0   | .'
    +-------+'

    """
    mesh = CuboidMesh(1, 1, 1, 1, 1, 2)
    assert to_sets(mesh.neighbours) == [{1}, {0}]
コード例 #4
0
def test_coordinates_z():
    """
       .+-------+
     .'       .'|
    +-------+'  +        Dimensions 1 x 1 x 2.
    |       | .'|        Cells 1 x 1 x 2.
    +-------+'  +
    |       | .'
    +-------+'

    """
    mesh = CuboidMesh(1, 1, 1, 1, 1, 2)
    assert allclose(mesh.coordinates,
                    np.array(((0.5, 0.5, 0.5), (0.5, 0.5, 1.5))))
コード例 #5
0
def test_coordinates_y():
    """
       .+-------+
     .+-------+'|
    +-------+'| |        Dimensions 1 x 2 x 1.
    |       | | |        Cells 1 x 2 x 1.
    |       | | +
    |       | +'
    +-------+'

    """
    mesh = CuboidMesh(1, 1, 1, 1, 2, 1)
    assert allclose(mesh.coordinates,
                    np.array(((0.5, 0.5, 0.5), (0.5, 1.5, 0.5))))
コード例 #6
0
def test_neighbours_y_periodic():
    """
       .+-------+
     .+-------+'|
    +-------+'| |
    |       | |1|
    |       |0| +
    |       | +'
    +-------+'

    """
    mesh = CuboidMesh(1, 1, 1, 1, 2, 1, periodicity=(False, True, False))
    assert allclose(mesh.neighbours,
                    np.array(((-1, -1, 1, 1, -1, -1), (-1, -1, 0, 0, -1, -1))))
コード例 #7
0
def test_coordinates_x():
    """
       .+---+---+
     .'  .'   .'|
    +---+---+'  |        Dimensions 2 x 1 x 1.
    |   |   |   |        Cells 2 x 1 x 1.
    |   |   |   +
    |   |   | .'
    +---+---+'

    """
    mesh = CuboidMesh(1, 1, 1, 2, 1, 1)
    assert allclose(mesh.coordinates,
                    np.array(((0.5, 0.5, 0.5), (1.5, 0.5, 0.5))))
コード例 #8
0
def test_neighbours_z_periodic():
    """
       .+---0---+
     .'       .'|
    +-------+'  +
    |   1   | .'|
    +-------+'  +
    |   0   | .'
    +-------+'

    """
    mesh = CuboidMesh(1, 1, 1, 1, 1, 2, periodicity=(False, False, True))
    assert allclose(mesh.neighbours,
                    np.array(((-1, -1, -1, -1, 1, 1), (-1, -1, -1, -1, 0, 0))))
コード例 #9
0
def test_neighbours_x_periodic():
    """
       .+---+---+
     .'  .'   .'|
    +---+---+'  |
    |   |   |   |
    | 0 | 1 |   +
    |   |   | .'
    +---+---+'

    """
    mesh = CuboidMesh(1, 1, 1, 2, 1, 1, periodicity=(True, False, False))
    # over under behind in-front right left
    assert allclose(mesh.neighbours,
                    np.array(((1, 1, -1, -1, -1, -1), (0, 0, -1, -1, -1, -1))))
コード例 #10
0
def test_neighbours_x_periodic_all():
    """
       .+---+---+
     .'  .'   .'|
    +---+---+'  |
    |   |   |   |
    | 0 | 1 |   +
    |   |   | .'
    +---+---+'

    """
    mesh = CuboidMesh(1, 1, 1, 2, 1, 1, periodicity=(True, True, True))
    #assert allclose(mesh.neighbours, np.array(((1, 1, -1, -1, -1, -1), (0, 0, -1, -1, -1, -1))))
    assert allclose(mesh.neighbours,
                    np.array(((1, 1, 0, 0, 0, 0), (0, 0, 1, 1, 1, 1))))
コード例 #11
0
def test_next_neighbours_x_periodic():
    """
       .+---+---+---+
     .'  .'   .'  .'|
    +---+---+---+'  |
    |   |   |   |   | 
    | 0 | 1 | 2 |   +
    |   |   |   | .'
    +---+---+---+'

    """
    mesh = CuboidMesh(nx=3, ny=1, nz=1, periodicity=(True, False, False))
    #print(mesh.next_neighbours)
    assert allclose(
        mesh.next_neighbours,
        np.array(((1, 2, -1, -1, -1, -1), (2, 0, -1, -1, -1, -1),
                  (0, 1, -1, -1, -1, -1))))
コード例 #12
0
ファイル: field_test.py プロジェクト: takluyver/fidimag
def test_initialise_vector():
    mesh = CuboidMesh(1, 1, 1, 1, 1, 1)
    v = vector_field(mesh, lambda r: 2 * r)
    assert np.allclose(v, np.array((1, 1, 1)))
コード例 #13
0
def test_vector_field_shape():
    mesh = CuboidMesh(1, 1, 1, 2, 3, 4)
    expected_nb_cells = 2 * 3 * 4
    expected_shape_for_vector_field = (expected_nb_cells, 3)
    assert mesh.vector_shape() == expected_shape_for_vector_field
    m = np.zeros(mesh.vector_shape())  # usage example
コード例 #14
0
def test_iterate_over_cells_and_neighbours():
    mesh = CuboidMesh(1, 1, 1, 2, 2, 2)
    for c_i in mesh.cells():
        print("I am cell #{}.".format(c_i))
        for c_j in mesh.neighbours[c_i]:
            print("\tAnd I am its neighbour, cell #{}!".format(c_j))
コード例 #15
0
def test_iterate_over_cells():
    mesh = CuboidMesh(1, 1, 1, 2, 2, 2)
    for c_i in mesh.cells():
        print("This is cell #{}, I have neighbours {}.".format(
            c_i, mesh.neighbours[c_i]))
コード例 #16
0
ファイル: field_test.py プロジェクト: takluyver/fidimag
def test_initialise_scalar():
    mesh = CuboidMesh(1, 1, 1, 1, 1, 1)
    f = scalar_field(mesh, lambda r: r[0] + r[1] + r[2])
    assert np.allclose(f, np.array((1.5)))
コード例 #17
0
ファイル: skyrmion.py プロジェクト: writergirish/fidimag
from fidimag.atomistic import Sim
from fidimag.common.cuboid_mesh import CuboidMesh
from fidimag.atomistic import UniformExchange, Zeeman
import fidimag.common.constant as const

mesh = CuboidMesh(nx=1, ny=1, dx=1, dy=1)

sim = Sim(mesh, name='relax_sk')
sim.gamma = const.gamma
sim.set_m((1, 0, 0))
sim.add(Zeeman((0, 0, 25.)))

sim.run_until(1e-11)
sim.set_tols(rtol=1e-10, atol=1e-12)
sim.run_until(2e-11)
コード例 #18
0
def test_check_size():
    mesh = CuboidMesh(1, 1, 1, 2, 3, 4)
    assert 1 == mesh.check_size(system_memory_fake_for_testing=0)