Пример #1
0
    def test__eq__(self):
        a = np.linspace(0, 1, 11)
        x = fields.Domain(a)
        y = fields.Domain(a)
        f0 = fields.Field1D('q0', x)
        f1 = fields.Field1D('q1', x)
        f2 = fields.Field1D('q2', y)

        assert (f0 == f0)
        assert (f0 != 0)
        assert (f0 == f1)
        assert (f0 != f2)

        data = np.asarray(range(len(x.xp)))
        f0.set_field(data)
        assert (f0 != f1)
        f1.set_field(data)
        assert (f0 == f1)

        bcp = fields.BoundaryCondition(name='periodic')
        f0.add_boundary_condition(bcp)
        assert (f0 != f1)
        f1.add_boundary_condition(bcp)
        assert (f0 == f1)

        return
Пример #2
0
    def test_init(self):
        bc = fields.BoundaryCondition()
        assert bc.name == None
        assert bc.indx == None
        assert bc.val == None

        bc = fields.BoundaryCondition(name='periodic')
        assert bc.name == 'periodic'
        assert bc.indx == None
        assert bc.val == None

        bc = fields.BoundaryCondition(name='periodic', indx=0, val=1)
        assert bc.name == 'periodic'
        assert bc.indx == 0
        assert bc.val == 1

        return
Пример #3
0
    def test_add_boundary_condition(self):
        mesh = np.linspace(-0.05, 1.05, 12)
        d = fields.Domain(mesh)
        f = fields.Field1D('x', d)

        bcp = fields.BoundaryCondition(name='periodic')
        bcd = fields.BoundaryCondition(name='dirichlet', indx=0, val=0)
        bcn = fields.BoundaryCondition(name='neumann', indx=-1, val=1)

        f.add_boundary_condition(bcp)
        assert bcp in f.bconds
        assert len(f.bconds) == 1

        f.add_boundary_condition(bcd)
        assert bcp not in f.bconds
        assert bcd in f.bconds
        assert len(f.bconds) == 1

        f.add_boundary_condition(bcn)
        assert bcn, bcd in f.bconds
        assert len(f.bconds) == 2

        bcn2 = fields.BoundaryCondition(name='neumann', indx=0, val=1)
        f.add_boundary_condition(bcn2)
        assert bcd not in f.bconds
        assert bcn2 in f.bconds

        f.add_boundary_condition(bcp)
        assert bcn, bcn2 not in f.bconds
        assert bcp in f.bconds

        bcn.indx = None
        f.add_boundary_condition(bcn)
        assert bcn not in f.bconds
        assert bcp in f.bconds

        bcn.indx = 3
        f.add_boundary_condition(bcn)
        assert bcn not in f.bconds
        assert bcp in f.bconds

        return
Пример #4
0
    def test_copy(self):
        mesh = np.linspace(-0.05, 1.05, 12)
        d = fields.Domain(mesh)
        f = fields.Field1D('x', d)

        data = np.asarray(range(len(f.val)))
        f.set_field(data)

        bcp = fields.BoundaryCondition(name='periodic')
        f.add_boundary_condition(bcp)

        g = f.copy()

        assert g is not f
        assert g.name == f.name
        assert g.mesh == f.mesh
        assert np.all(g.val == f.val)
        assert np.all(g.bconds == f.bconds)

        return
Пример #5
0
    def test__eg__(self):
        bc0 = fields.BoundaryCondition()
        bc1 = fields.BoundaryCondition()
        assert bc0 == bc0
        assert bc0 == bc1

        bc0 = fields.BoundaryCondition(name='periodic')
        assert bc0 != bc1
        bc1 = fields.BoundaryCondition(name='periodic')
        assert bc0 == bc1

        bc0 = fields.BoundaryCondition(name='periodic', indx=0)
        assert bc0 != bc1
        bc1 = fields.BoundaryCondition(name='periodic', indx=0)
        assert bc0 == bc1

        bc0 = fields.BoundaryCondition(name='periodic', indx=0, val=0)
        assert bc0 != bc1
        bc1 = fields.BoundaryCondition(name='periodic', indx=0, val=0)
        assert bc0 == bc1

        return