Example #1
0
def perform_condensation(full_problem, reduced_problem, dim):
    """
    Obtain reduced matrix and rhs.
    """
    A = full_problem.lhs
    rhs = full_problem.rhs
    to_be_eliminated = SC.dofs_of_dimension(full_problem.grid(), A, dim)
    a_reduced, rhs_reduced, _, _, _ = SC.eliminate_dofs(
        A, rhs, to_be_eliminated)

    reduced_problem.lhs = a_reduced
    reduced_problem.rhs = rhs_reduced
Example #2
0
    def solve(self, max_direct=40000, callback=False, **kwargs):
        """
        This is an adaption of the elliptic solver to the Schur complement
        elimination. The only change can be found in the if self.el statement.
        """
        # Discretize
        tic = time.time()
        logger.info("Discretize")
        self.lhs, self.rhs = self.reassemble()
        if self.el:
            to_be_eliminated = SC.dofs_of_dimension(other.grid(), other.lhs,
                                                    eldim)
            self.lhs, self.rhs, _, _, _ = SC.eliminate_dofs(
                other.lhs, other.rhs, to_be_eliminated)

        logger.info("Done. Elapsed time " + str(time.time() - tic))

        # Solve
        tic = time.time()
        ls = LSFactory()
        if self.rhs.size < max_direct:
            logger.info("Solve linear system using direct solver")
            self.x = ls.direct(self.lhs, self.rhs)
        else:
            logger.info("Solve linear system using GMRES")
            precond = self._setup_preconditioner()
            #            precond = ls.ilu(self.lhs)
            slv = ls.gmres(self.lhs)
            self.x, info = slv(
                self.rhs,
                M=precond,
                callback=callback,
                maxiter=10000,
                restart=1500,
                tol=1e-8,
            )
            if info == 0:
                logger.info("GMRES succeeded.")
            else:
                logger.error("GMRES failed with status " + str(info))

        logger.info("Done. Elapsed time " + str(time.time() - tic))
        return self.x