Beispiel #1
0
    def test_project_tensors(self):
        from sfepy.discrete import FieldVariable
        from sfepy.discrete.projections import project_by_component

        ok = True

        u = FieldVariable('u',
                          'parameter',
                          self.field,
                          primary_var_name='(set-to-None)')
        u.set_constant(1.0)

        component = FieldVariable('component',
                                  'parameter',
                                  self.field,
                                  primary_var_name='(set-to-None)')

        nls_options = {'eps_a': 1e-16, 'i_max': 1}

        u_qp = u.evaluate()
        u2 = FieldVariable('u2',
                           'parameter',
                           self.field,
                           primary_var_name='(set-to-None)')
        project_by_component(u2,
                             u_qp,
                             component,
                             self.field.approx_order,
                             nls_options=nls_options)

        _ok = self.compare_vectors(u(), u2())
        ok = ok and _ok

        gu_qp = u.evaluate(mode='grad')

        gfield = Field.from_args('gu',
                                 nm.float64,
                                 2,
                                 self.field.region,
                                 approx_order=self.field.approx_order)
        gu = FieldVariable('gu',
                           'parameter',
                           gfield,
                           primary_var_name='(set-to-None)')

        project_by_component(gu,
                             gu_qp,
                             component,
                             gfield.approx_order,
                             nls_options=nls_options)

        _ok = self.compare_vectors(gu(), nm.zeros_like(gu()))
        ok = ok and _ok

        return ok
Beispiel #2
0
    def test_project_tensors(self):
        from sfepy.discrete import FieldVariable
        from sfepy.discrete.projections import project_by_component

        ok = True

        u = FieldVariable('u', 'parameter', self.field,
                          primary_var_name='(set-to-None)')
        u.set_constant(1.0)

        component = FieldVariable('component', 'parameter', self.field,
                                  primary_var_name='(set-to-None)')

        nls_options = {'eps_a' : 1e-16, 'i_max' : 1}

        u_qp = u.evaluate()
        u2 = FieldVariable('u2', 'parameter', self.field,
                           primary_var_name='(set-to-None)')
        project_by_component(u2, u_qp, component, self.field.approx_order,
                             nls_options=nls_options)

        _ok = self.compare_vectors(u(), u2())
        ok = ok and _ok

        gu_qp = u.evaluate(mode='grad')

        gfield = Field.from_args('gu', nm.float64, 2, self.field.region,
                                 approx_order=self.field.approx_order)
        gu = FieldVariable('gu', 'parameter', gfield,
                           primary_var_name='(set-to-None)')

        project_by_component(gu, gu_qp, component, gfield.approx_order,
                             nls_options=nls_options)

        _ok = self.compare_vectors(gu(), nm.zeros_like(gu()))
        ok = ok and _ok

        return ok
Beispiel #3
0
    def test_variables(self):
        from sfepy.discrete import FieldVariable, Integral

        ok = True

        u = FieldVariable('u',
                          'parameter',
                          self.field,
                          primary_var_name='(set-to-None)')
        u.set_constant(1.0)
        vec = u()  # Nodal values.

        _ok = nm.allclose(vec, 1.0)
        self.report('set constant:', _ok)
        ok = _ok and ok

        def fun(coors):
            val = nm.empty_like(coors)
            val[:, 0] = 2 * coors[:, 1] - coors[:, 0]
            val[:, 1] = coors[:, 0] + 3 * coors[:, 1]
            return val

        u.set_from_function(fun)

        coors = u.field.get_coor()
        eu = u.evaluate_at(coors)

        _ok = nm.allclose(eu, fun(coors), rtol=0.0, atol=1e-13)
        self.report('set from function:', _ok)
        ok = _ok and ok

        integral = Integral('i', order=2)
        gu_qp = u.evaluate(mode='grad', integral=integral)

        # du_i/dx_j, i = column, j = row.
        gu = nm.array([[-1., 1.], [2., 3.]])
        _ok = nm.allclose(gu_qp, gu[None, None, ...], rtol=0.0, atol=1e-13)
        self.report('set from function - gradient:', _ok)
        ok = _ok and ok

        u_qp = gu_qp[..., :, :1]
        u.set_from_qp(u_qp, integral)
        vu = u()

        _ok = (nm.allclose(vu[::2], -1, rtol=0.0, atol=1e-13)
               and nm.allclose(vu[1::2], 2, rtol=0.0, atol=1e-13))
        self.report('set from qp:', _ok)
        ok = _ok and ok

        return ok
Beispiel #4
0
    def test_variables(self):
        from sfepy.discrete import FieldVariable, Integral

        ok = True

        u = FieldVariable('u', 'parameter', self.field,
                          primary_var_name='(set-to-None)')
        u.set_constant(1.0)
        vec = u() # Nodal values.

        _ok = nm.allclose(vec, 1.0)
        self.report('set constant:', _ok)
        ok = _ok and ok

        def fun(coors):
            val = nm.empty_like(coors)
            val[:, 0] = 2 * coors[:, 1] - coors[:, 0]
            val[:, 1] = coors[:, 0] + 3 * coors[:, 1]
            return val
        u.set_from_function(fun)

        coors = u.field.get_coor()
        eu = u.evaluate_at(coors)

        _ok = nm.allclose(eu, fun(coors), rtol=0.0, atol=1e-13)
        self.report('set from function:', _ok)
        ok = _ok and ok

        integral = Integral('i', order=2)
        gu_qp = u.evaluate(mode='grad', integral=integral)

        # du_i/dx_j, i = column, j = row.
        gu = nm.array([[-1.,  1.],
                       [ 2.,  3.]])
        _ok = nm.allclose(gu_qp, gu[None, None, ...], rtol=0.0, atol=1e-13)
        self.report('set from function - gradient:', _ok)
        ok = _ok and ok

        u_qp = gu_qp[..., :, :1]
        u.set_from_qp(u_qp, integral)
        vu = u()

        _ok = (nm.allclose(vu[::2], -1, rtol=0.0, atol=1e-13) and
               nm.allclose(vu[1::2], 2, rtol=0.0, atol=1e-13))
        self.report('set from qp:', _ok)
        ok = _ok and ok

        return ok