def solve_system(self, rhs, factor, u0, t):
        """
        Simple linear solver for (I-dtA)u = rhs using GMRES

        Args:
            rhs (dtype_f): right-hand side for the nonlinear system
            factor (float): abbrev. for the node-to-node stepsize (or any other factor required)
            u0 (dtype_u): initial guess for the iterative solver (not used here so far)
            t (float): current time (e.g. for time-dependent BCs)

        Returns:
            dtype_u: solution as mesh
        """

        b = rhs.values.flatten()
        cb = Callback()

        sol, info = gmres(self.Id - factor * self.M,
                          b,
                          x0=u0.values.flatten(),
                          tol=self.params.gmres_tol_limit,
                          restart=self.params.gmres_restart,
                          maxiter=self.params.gmres_maxiter,
                          callback=cb)
        # If this is a dummy call with factor==0.0, do not log because it should not be counted as a solver call
        if factor != 0.0:
            self.gmres_logger.add(cb.getcounter())
        me = self.dtype_u(self.init)
        me.values = unflatten(sol, 4, self.N[0], self.N[1])

        return me
Example #2
0
 def f_fast_solve(self, rhs, alpha, u0):
     cb = Callback()
     sol, info = gmres(self.problem.Id - alpha * self.problem.M,
                       rhs,
                       x0=u0,
                       tol=self.problem.params.gmres_tol_limit,
                       restart=self.problem.params.gmres_restart,
                       maxiter=self.problem.params.gmres_maxiter,
                       callback=cb)
     if alpha != 0.0:
         self.logger.add(cb.getcounter())
     return sol