Exemplo n.º 1
0
    def interpolation(self, u: VectorHeat1D) -> VectorHeat1D:
        """
        Interpolate input vector u using linear interpolation.

        Note: In the 1d heat equation example, we consider homogeneous Dirichlet BCs in space.
              The Heat1D vector class only stores interior points.
        :param u: approximate solution vector
        :return: input solution vector u interpolated to a fine grid
        """
        # Get values at interior points
        sol = u.get_values()

        # Create array for interpolated values
        ret_array = np.zeros(int(len(sol) * 2 + 1))

        # Linear interpolation
        for i in range(len(sol)):
            ret_array[i * 2] += 1 / 2 * sol[i]
            ret_array[i * 2 + 1] += sol[i]
            ret_array[i * 2 + 2] += 1 / 2 * sol[i]

        # Create and return a VectorHeat1D object with interpolated values
        ret = VectorHeat1D(len(ret_array))
        ret.set_values(ret_array)
        return ret
Exemplo n.º 2
0
    def restriction(self, u: VectorHeat1D) -> VectorHeat1D:
        """
        Restrict input vector u using standard full weighting restriction.

        Note: In the 1d heat equation example, we consider homogeneous Dirichlet BCs in space.
              The Heat1D vector class only stores interior points.
        :param u: approximate solution vector
        :return: input solution vector u restricted to a coarse grid
        """
        # Get values at interior points
        sol = u.get_values()

        # Create array for restricted values
        ret_array = np.zeros(int((len(sol) - 1) / 2))

        # Full weighting restriction
        for i in range(len(ret_array)):
            ret_array[i] = sol[2 * i] * 1 / 4 + sol[2 * i + 1] * 1 / 2 + sol[
                2 * i + 2] * 1 / 4

        # Create and return a VectorHeat1D object with the restricted values
        ret = VectorHeat1D(len(ret_array))
        ret.set_values(ret_array)
        return ret