Пример #1
0
    def test_it(self):
        actuation_type = 'dirichlet'
        bound_cond_type = 'dirichlet'
        param = [1., -2., -1., None, None]
        adjoint_param = ef.get_adjoint_rad_evp_param(param)
        a2, a1, a0, _, _ = param

        l = 1.
        spatial_disc = 10
        dz = sim.Domain(bounds=(0, l), num=spatial_disc)

        T = 1.
        temporal_disc = 1e2
        dt = sim.Domain(bounds=(0, T), num=temporal_disc)

        omega = np.array([(i+1)*np.pi/l for i in xrange(spatial_disc)])
        eig_values = a0 - a2*omega**2 - a1**2/4./a2
        norm_fak = np.ones(omega.shape)*np.sqrt(2)
        eig_funcs = np.array([ef.SecondOrderDirichletEigenfunction(omega[i], param, dz.bounds, norm_fak[i])
                              for i in range(spatial_disc)])
        register_base("eig_funcs", eig_funcs, overwrite=True)
        adjoint_eig_funcs = np.array([ef.SecondOrderDirichletEigenfunction(omega[i],
                                                                           adjoint_param,
                                                                           dz.bounds,
                                                                           norm_fak[i]) for i in range(spatial_disc)])
        register_base("adjoint_eig_funcs", adjoint_eig_funcs, overwrite=True)

        # derive initial field variable x(z,0) and weights
        start_state = cr.Function(lambda z: 0., domain=(0, l))
        initial_weights = cr.project_on_base(start_state, adjoint_eig_funcs)

        # init trajectory
        u = tr.RadTrajectory(l, T, param, bound_cond_type, actuation_type)

        # determine (A,B) with weak-formulation (pyinduct)

        # derive sate-space system
        rad_pde = ut.get_parabolic_dirichlet_weak_form("eig_funcs", "adjoint_eig_funcs", u, param, dz.bounds)
        cf = sim.parse_weak_formulation(rad_pde)
        ss_weak = cf.convert_to_state_space()

        # determine (A,B) with modal-transfomation
        A = np.diag(eig_values)
        B = -a2*np.array([adjoint_eig_funcs[i].derive()(l) for i in xrange(spatial_disc)])
        ss_modal = sim.StateSpace("eig_funcs", A, B)

        # TODO: resolve the big tolerance (rtol=3e-01) between ss_modal.A and ss_weak.A
        # check if ss_modal.(A,B) is close to ss_weak.(A,B)
        self.assertTrue(np.allclose(np.sort(np.linalg.eigvals(ss_weak.A)), np.sort(np.linalg.eigvals(ss_modal.A)),
                                    rtol=3e-1, atol=0.))
        self.assertTrue(np.allclose(np.array([i[0] for i in ss_weak.B]), ss_modal.B))

        # display results
        if show_plots:
            t, q = sim.simulate_state_space(ss_modal, u, initial_weights, dt)
            eval_d = ut.evaluate_approximation("eig_funcs", q, t, dz, spat_order=1)
            win2 = vis.PgSurfacePlot(eval_d)
            app.exec_()
Пример #2
0
        def test_dd():
            # trajectory
            bound_cond_type = 'dirichlet'
            actuation_type = 'dirichlet'
            u = tr.RadTrajectory(l, T, param, bound_cond_type, actuation_type)

            # derive state-space system
            rad_pde = ut.get_parabolic_dirichlet_weak_form("init_funcs_2", "init_funcs_2", u, param, dz.bounds)
            cf = sim.parse_weak_formulation(rad_pde)
            ss = cf.convert_to_state_space()

            # simulate system
            t, q = sim.simulate_state_space(ss, cf.input_function, np.zeros(ini_funcs_2.shape), dt)

            return t, q
Пример #3
0
        def test_dd():
            # trajectory
            bound_cond_type = 'dirichlet'
            actuation_type = 'dirichlet'
            u = tr.RadTrajectory(l, T, param, bound_cond_type, actuation_type)

            # derive state-space system
            rad_pde = ut.get_parabolic_dirichlet_weak_form(
                "init_funcs_2", "init_funcs_2", u, param, dz.bounds)
            cf = sim.parse_weak_formulation(rad_pde)
            ss = cf.convert_to_state_space()

            # simulate system
            t, q = sim.simulate_state_space(ss, np.zeros(ini_funcs_2.shape),
                                            dt)

            return t, q
Пример #4
0
    def test_it(self):
        actuation_type = 'dirichlet'
        bound_cond_type = 'dirichlet'
        param = [1., -2., -1., None, None]
        adjoint_param = ef.get_adjoint_rad_evp_param(param)
        a2, a1, a0, _, _ = param

        l = 1.
        spatial_disc = 10
        dz = sim.Domain(bounds=(0, l), num=spatial_disc)

        T = 1.
        temporal_disc = 1e2
        dt = sim.Domain(bounds=(0, T), num=temporal_disc)

        omega = np.array([(i + 1) * np.pi / l for i in range(spatial_disc)])
        eig_values = a0 - a2 * omega**2 - a1**2 / 4. / a2
        norm_fak = np.ones(omega.shape) * np.sqrt(2)
        eig_funcs = np.array([
            ef.SecondOrderDirichletEigenfunction(omega[i], param, dz.bounds,
                                                 norm_fak[i])
            for i in range(spatial_disc)
        ])
        register_base("eig_funcs", eig_funcs, overwrite=True)
        adjoint_eig_funcs = np.array([
            ef.SecondOrderDirichletEigenfunction(omega[i], adjoint_param,
                                                 dz.bounds, norm_fak[i])
            for i in range(spatial_disc)
        ])
        register_base("adjoint_eig_funcs", adjoint_eig_funcs, overwrite=True)

        # derive initial field variable x(z,0) and weights
        start_state = cr.Function(lambda z: 0., domain=(0, l))
        initial_weights = cr.project_on_base(start_state, adjoint_eig_funcs)

        # init trajectory
        u = tr.RadTrajectory(l, T, param, bound_cond_type, actuation_type)

        # determine (A,B) with weak-formulation (pyinduct)

        # derive sate-space system
        rad_pde = ut.get_parabolic_dirichlet_weak_form("eig_funcs",
                                                       "adjoint_eig_funcs", u,
                                                       param, dz.bounds)
        cf = sim.parse_weak_formulation(rad_pde)
        ss_weak = cf.convert_to_state_space()

        # determine (A,B) with modal-transfomation
        A = np.diag(eig_values)
        B = -a2 * np.array(
            [adjoint_eig_funcs[i].derive()(l) for i in range(spatial_disc)])
        ss_modal = sim.StateSpace("eig_funcs", A, B, input_handle=u)

        # TODO: resolve the big tolerance (rtol=3e-01) between ss_modal.A and ss_weak.A
        # check if ss_modal.(A,B) is close to ss_weak.(A,B)
        self.assertTrue(
            np.allclose(np.sort(np.linalg.eigvals(ss_weak.A[1])),
                        np.sort(np.linalg.eigvals(ss_modal.A[1])),
                        rtol=3e-1,
                        atol=0.))
        self.assertTrue(
            np.allclose(np.array([i[0] for i in ss_weak.B[1]]), ss_modal.B[1]))

        # display results
        if show_plots:
            t, q = sim.simulate_state_space(ss_modal, initial_weights, dt)
            eval_d = sim.evaluate_approximation("eig_funcs",
                                                q,
                                                t,
                                                dz,
                                                spat_order=1)
            win2 = vis.PgSurfacePlot(eval_d)
            app.exec_()