Ejemplo n.º 1
0
    def setUp(self):
        self.u = np.sin
        self.input = ph.Input(self.u)  # control input
        nodes, self.ini_funcs = cure_interval(LagrangeFirstOrder, (0, 1), node_count=3)
        register_base("ini_funcs", self.ini_funcs, overwrite=True)

        self.phi = ph.TestFunction("ini_funcs")  # eigenfunction or something else
        self.dphi = ph.TestFunction("ini_funcs", order=1)  # eigenfunction or something else
        self.dphi_at1 = ph.TestFunction("ini_funcs", order=1, location=1)  # eigenfunction or something else
        self.field_var = ph.FieldVariable("ini_funcs")
        self.field_var_at1 = ph.FieldVariable("ini_funcs", location=1)
Ejemplo n.º 2
0
    def setUp(self):
        self.input = ph.Input(np.sin)
        self.phi = np.array([cr.Function(lambda x: 2*x)])
        register_base("phi", self.phi, overwrite=True)
        self.test_func = ph.TestFunction("phi")

        nodes, self.ini_funcs = cure_interval(LagrangeFirstOrder, (0, 1), node_count=2)
        register_base("ini_funcs", self.ini_funcs, overwrite=True)
        self.xdt = ph.TemporalDerivedFieldVariable("ini_funcs", order=1)
        self.xdz_at1 = ph.SpatialDerivedFieldVariable("ini_funcs", order=1, location=1)

        self.prod = ph.Product(self.input, self.xdt)
Ejemplo n.º 3
0
    def setUp(self):
        self.input = ph.Input(np.sin)
        self.phi = np.array([cr.Function(lambda x: 2 * x)])
        register_base("phi", self.phi, overwrite=True)
        self.test_func = ph.TestFunction("phi")

        nodes, self.ini_funcs = cure_interval(LagrangeFirstOrder, (0, 1),
                                              node_count=2)
        register_base("ini_funcs", self.ini_funcs, overwrite=True)
        self.xdt = ph.TemporalDerivedFieldVariable("ini_funcs", order=1)
        self.xdz_at1 = ph.SpatialDerivedFieldVariable("ini_funcs",
                                                      order=1,
                                                      location=1)

        self.prod = ph.Product(self.input, self.xdt)
Ejemplo n.º 4
0
    def setUp(self):
        self.u = np.sin
        self.input = ph.Input(self.u)  # control input
        nodes, self.ini_funcs = cure_interval(LagrangeFirstOrder, (0, 1),
                                              node_count=3)
        register_base("ini_funcs", self.ini_funcs, overwrite=True)

        self.phi = ph.TestFunction(
            "ini_funcs")  # eigenfunction or something else
        self.dphi = ph.TestFunction("ini_funcs",
                                    order=1)  # eigenfunction or something else
        self.dphi_at1 = ph.TestFunction(
            "ini_funcs", order=1,
            location=1)  # eigenfunction or something else
        self.field_var = ph.FieldVariable("ini_funcs")
        self.field_var_at1 = ph.FieldVariable("ini_funcs", location=1)
Ejemplo n.º 5
0
    def setUp(self):
        self.input = ph.Input(np.sin)

        phi = cr.Function(np.sin)
        psi = cr.Function(np.cos)
        self.t_funcs = np.array([phi, psi])
        register_base("funcs", self.t_funcs, overwrite=True)
        self.test_funcs = ph.TestFunction("funcs")

        self.s_funcs = np.array([cr.Function(self.scale)])[[0, 0]]
        register_base("scale_funcs", self.s_funcs, overwrite=True)
        self.scale_funcs = ph.ScalarFunction("scale_funcs")

        nodes, self.ini_funcs = cure_interval(LagrangeFirstOrder, (0, 1), node_count=2)
        register_base("prod_ini_funcs", self.ini_funcs, overwrite=True)
        self.field_var = ph.FieldVariable("prod_ini_funcs")
        self.field_var_dz = ph.SpatialDerivedFieldVariable("prod_ini_funcs", 1)
Ejemplo n.º 6
0
    def setUp(self):
        self.input = ph.Input(np.sin)

        phi = cr.Function(np.sin)
        psi = cr.Function(np.cos)
        self.t_funcs = np.array([phi, psi])
        register_base("funcs", self.t_funcs, overwrite=True)
        self.test_funcs = ph.TestFunction("funcs")

        self.s_funcs = np.array([cr.Function(self.scale)])[[0, 0]]
        register_base("scale_funcs", self.s_funcs, overwrite=True)
        self.scale_funcs = ph.ScalarFunction("scale_funcs")

        nodes, self.ini_funcs = cure_interval(LagrangeFirstOrder, (0, 1),
                                              node_count=2)
        register_base("prod_ini_funcs", self.ini_funcs, overwrite=True)
        self.field_var = ph.FieldVariable("prod_ini_funcs")
        self.field_var_dz = ph.SpatialDerivedFieldVariable("prod_ini_funcs", 1)
Ejemplo n.º 7
0
    def shape_generator(self, cls, der_order):
        """
        verify the correct connection with visual feedback
        """

        dz = pi.Domain((0, 1), step=.001)
        dt = pi.Domain((0, 0), num=1)

        nodes, funcs = pi.cure_interval(cls, dz.bounds, node_count=11)
        pi.register_base("test", funcs, overwrite=True)

        # approx_func = pi.Function(np.cos, domain=dz.bounds,
        #                           derivative_handles=[lambda z: -np.sin(z), lambda z: -np.cos(z)])
        approx_func = pi.Function(lambda z: np.sin(3*z), domain=dz.bounds,
                                  derivative_handles=[lambda z: 3*np.cos(3*z), lambda z: -9*np.sin(3*z)])

        weights = approx_func(nodes)

        hull = pi.evaluate_approximation("test", np.atleast_2d(weights),
                                         temp_domain=dt, spat_domain=dz, spat_order=der_order)

        if show_plots:
            # plot shapefunctions
            c_map = pi.visualization.create_colormap(len(funcs))
            pw = pg.plot(title="{}-Test".format(cls.__name__))
            pw.addLegend()
            pw.showGrid(x=True, y=True, alpha=0.5)

            [pw.addItem(pg.PlotDataItem(np.array(dz),
                                        weights[idx]*func.derive(der_order)(dz),
                                        pen=pg.mkPen(color=c_map[idx]),
                                        name="{}.{}".format(cls.__name__, idx)))
             for idx, func in enumerate(funcs)]

            # plot hull curve
            pw.addItem(pg.PlotDataItem(np.array(hull.input_data[1]), hull.output_data[0, :],
                                       pen=pg.mkPen(width=2), name="hull-curve"))
            # plot original function
            pw.addItem(pg.PlotDataItem(np.array(dz), approx_func.derive(der_order)(dz),
                                       pen=pg.mkPen(color="m", width=2, style=pg.QtCore.Qt.DashLine), name="original"))
            pg.QtCore.QCoreApplication.instance().exec_()

        return np.sum(np.abs(hull.output_data[0, :] - approx_func.derive(der_order)(dz)))
Ejemplo n.º 8
0
 def setUp(self):
     nodes, ini_funcs = cure_interval(LagrangeFirstOrder, (0, 1),
                                      node_count=2)
     register_base("test_funcs", ini_funcs, overwrite=True)
Ejemplo n.º 9
0
    def shape_generator(self, cls, der_order):
        """
        verify the correct connection with visual feedback
        """

        dz = pi.Domain((0, 1), step=.001)
        dt = pi.Domain((0, 0), num=1)

        nodes, funcs = pi.cure_interval(cls, dz.bounds, node_count=11)
        pi.register_base("test", funcs, overwrite=True)

        # approx_func = pi.Function(np.cos, domain=dz.bounds,
        #                           derivative_handles=[lambda z: -np.sin(z), lambda z: -np.cos(z)])
        approx_func = pi.Function(lambda z: np.sin(3 * z),
                                  domain=dz.bounds,
                                  derivative_handles=[
                                      lambda z: 3 * np.cos(3 * z),
                                      lambda z: -9 * np.sin(3 * z)
                                  ])

        weights = approx_func(nodes)

        hull = pi.evaluate_approximation("test",
                                         np.atleast_2d(weights),
                                         temp_domain=dt,
                                         spat_domain=dz,
                                         spat_order=der_order)

        if show_plots:
            # plot shapefunctions
            c_map = pi.visualization.create_colormap(len(funcs))
            pw = pg.plot(title="{}-Test".format(cls.__name__))
            pw.addLegend()
            pw.showGrid(x=True, y=True, alpha=0.5)

            [
                pw.addItem(
                    pg.PlotDataItem(np.array(dz),
                                    weights[idx] * func.derive(der_order)(dz),
                                    pen=pg.mkPen(color=c_map[idx]),
                                    name="{}.{}".format(cls.__name__, idx)))
                for idx, func in enumerate(funcs)
            ]

            # plot hull curve
            pw.addItem(
                pg.PlotDataItem(np.array(hull.input_data[1]),
                                hull.output_data[0, :],
                                pen=pg.mkPen(width=2),
                                name="hull-curve"))
            # plot original function
            pw.addItem(
                pg.PlotDataItem(np.array(dz),
                                approx_func.derive(der_order)(dz),
                                pen=pg.mkPen(color="m",
                                             width=2,
                                             style=pg.QtCore.Qt.DashLine),
                                name="original"))
            pg.QtCore.QCoreApplication.instance().exec_()

        return np.sum(
            np.abs(hull.output_data[0, :] - approx_func.derive(der_order)(dz)))
Ejemplo n.º 10
0
 def setUp(self):
     nodes, ini_funcs = cure_interval(LagrangeFirstOrder, (0, 1), node_count=2)
     register_base("test_funcs", ini_funcs, overwrite=True)