示例#1
0
    def prolong(self, G):
        """
        Prolongation implementation

        Args:
            G: the coarse level data (easier to access than via the coarse attribute)
        """
        if isinstance(G, mesh):
            F = mesh(self.fine_prob.init, val=0.0)
            tmpG = np.fft.rfft(G.values)
            tmpF = np.zeros(self.fine_prob.init // 2 + 1, dtype=np.complex128)
            halfG = int(self.coarse_prob.init / 2)
            tmpF[0:halfG] = tmpG[0:halfG]
            tmpF[-1] = tmpG[-1]
            F.values[:] = np.fft.irfft(tmpF) * self.ratio
        elif isinstance(G, rhs_imex_mesh):
            F = rhs_imex_mesh(G)
            tmpG_impl = np.fft.rfft(G.impl.values)
            tmpF_impl = np.zeros(self.fine_prob.init // 2 + 1,
                                 dtype=np.complex128)
            halfG = int(self.coarse_prob.init / 2)
            tmpF_impl[0:halfG] = tmpG_impl[0:halfG]
            tmpF_impl[-1] = tmpG_impl[-1]
            F.impl.values[:] = np.fft.irfft(tmpF_impl) * self.ratio
            tmpG_expl = np.fft.rfft(G.expl.values)
            tmpF_expl = np.zeros(self.fine_prob.init // 2 + 1,
                                 dtype=np.complex128)
            halfG = int(self.coarse_prob.init / 2)
            tmpF_expl[0:halfG] = tmpG_expl[0:halfG]
            tmpF_expl[-1] = tmpG_expl[-1]
            F.expl.values[:] = np.fft.irfft(tmpF_expl) * self.ratio
        else:
            raise TransferError('Unknown data type, got %s' % type(G))
        return F
示例#2
0
    def prolong(self, G):
        """
        Prolongation implementation

        Args:
            G: the coarse level data (easier to access than via the coarse attribute)
        """
        if isinstance(G, mesh):
            F = mesh(self.fine_prob.init)
            tmpG = self.fft_object_coarse(G.values) / (
                self.coarse_prob.init[0] * self.coarse_prob.init[1])
            tmpF = np.zeros(self.fine_prob.init, dtype=np.complex128)
            halfG = int(self.coarse_prob.init[0] / 2)
            tmpF[0:halfG, 0:halfG] = tmpG[0:halfG, 0:halfG]
            tmpF[self.fine_prob.init[0] - halfG:, 0:halfG] = tmpG[halfG:,
                                                                  0:halfG]
            tmpF[0:halfG, self.fine_prob.init[0] - halfG:] = tmpG[0:halfG,
                                                                  halfG:]
            tmpF[self.fine_prob.init[0] - halfG:,
                 self.fine_prob.init[0] - halfG:] = tmpG[halfG:, halfG:]
            F.values[:] = np.real(
                self.ifft_object_fine(tmpF, normalise_idft=False))
        elif isinstance(G, rhs_imex_mesh):
            F = rhs_imex_mesh(G)
            tmpG_impl = self.fft_object_coarse(G.impl.values) / (
                self.coarse_prob.init[0] * self.coarse_prob.init[1])
            tmpF_impl = np.zeros(self.fine_prob.init, dtype=np.complex128)
            halfG = int(self.coarse_prob.init[0] / 2)
            tmpF_impl[0:halfG, 0:halfG] = tmpG_impl[0:halfG, 0:halfG]
            tmpF_impl[self.fine_prob.init[0] - halfG:,
                      0:halfG] = tmpG_impl[halfG:, 0:halfG]
            tmpF_impl[0:halfG,
                      self.fine_prob.init[0] - halfG:] = tmpG_impl[0:halfG,
                                                                   halfG:]
            tmpF_impl[self.fine_prob.init[0] - halfG:,
                      self.fine_prob.init[0] - halfG:] = tmpG_impl[halfG:,
                                                                   halfG:]
            F.impl.values[:] = np.real(
                self.ifft_object_fine(tmpF_impl, normalise_idft=False))
            tmpG_expl = self.fft_object_coarse(G.expl.values) / (
                self.coarse_prob.init[0] * self.coarse_prob.init[1])
            tmpF_expl = np.zeros(self.fine_prob.init, dtype=np.complex128)
            halfG = int(self.coarse_prob.init[0] / 2)
            tmpF_expl[0:halfG, 0:halfG] = tmpG_expl[0:halfG, 0:halfG]
            tmpF_expl[self.fine_prob.init[0] - halfG:,
                      0:halfG] = tmpG_expl[halfG:, 0:halfG]
            tmpF_expl[0:halfG,
                      self.fine_prob.init[0] - halfG:] = tmpG_expl[0:halfG,
                                                                   halfG:]
            tmpF_expl[self.fine_prob.init[0] - halfG:,
                      self.fine_prob.init[0] - halfG:] = tmpG_expl[halfG:,
                                                                   halfG:]
            F.expl.values[:] = np.real(
                self.ifft_object_fine(tmpF_expl, normalise_idft=False))
        else:
            raise TransferError('Unknown data type, got %s' % type(G))
        return F
示例#3
0
    def prolong(self, G):
        """
        Prolongation implementation

        Args:
            G: the coarse level data (easier to access than via the coarse attribute)
        """
        if isinstance(G, mesh):
            F = mesh(G)
        elif isinstance(G, rhs_imex_mesh):
            F = rhs_imex_mesh(G)
        else:
            raise TransferError('Unknown data type, got %s' % type(G))
        return F
示例#4
0
    def restrict(self, F):
        """
        Restriction implementation

        Args:
            F: the fine level data (easier to access than via the fine attribute)
        """
        if isinstance(F, mesh):
            G = mesh(F)
        elif isinstance(F, rhs_imex_mesh):
            G = rhs_imex_mesh(F)
        else:
            raise TransferError('Unknown data type, got %s' % type(F))
        return G
示例#5
0
    def eval_f(self, u, t):
        """
        Routine to evaluate both parts of the RHS

        Args:
            u: current values
            t: current time

        Returns:
            the RHS divided into two parts
        """

        f = rhs_imex_mesh(self.nvars)
        f.impl = self.__eval_fimpl(u, t)
        f.expl = self.__eval_fexpl(u, t)
        return f
示例#6
0
    def restrict(self, F):
        """
        Restriction implementation

        Args:
            F: the fine level data (easier to access than via the fine attribute)
        """
        if isinstance(F, mesh):
            G = mesh(self.coarse_prob.init, val=0.0)
            G.values = F.values[::self.ratio]
        elif isinstance(F, rhs_imex_mesh):
            G = rhs_imex_mesh(self.coarse_prob.init, val=0.0)
            G.impl.values = F.impl.values[::self.ratio]
            G.expl.values = F.expl.values[::self.ratio]
        else:
            raise TransferError('Unknown data type, got %s' % type(F))
        return G