Esempio n. 1
0
 def solve(self):
     residual = self.problem.residual_vector_eval
     initial_guess_vector = self.problem.solution.vector()
     jacobian = _Jacobian(self.problem.jacobian_matrix_eval)
     try:
         solution_vector, info = nonlin_solve(
             residual,
             initial_guess_vector,
             jacobian=jacobian,
             verbose=self._report,
             f_tol=self._absolute_tolerance,
             f_rtol=self._relative_tolerance,
             x_rtol=self._solution_tolerance,
             maxiter=self._maximum_iterations,
             line_search=self._line_search,
             callback=self._monitor,
             full_output=True,
             raise_exception=False)
         if self._report:
             if info["success"]:
                 print("scipy solver converged in " + str(info["nit"]) +
                       " iterations.")
             else:
                 print("scipy solver diverged in " + str(info["nit"]) +
                       " iterations.")
         self.problem.solution.vector()[:] = solution_vector
     except ArithmeticError as error:
         if self._report:
             print("scipy solver diverged due to arithmetic error " +
                   str(error))
     self.monitor(self.problem.solution)
Esempio n. 2
0
    def _check(self, jac, N, maxiter, complex=False, **kw):
        np.random.seed(123)

        A = np.random.randn(N, N)
        if complex:
            A = A + 1j * np.random.randn(N, N)
        b = np.random.randn(N)
        if complex:
            b = b + 1j * np.random.randn(N)

        def func(x):
            return dot(A, x) - b

        sol = nonlin.nonlin_solve(func, np.zeros(N), jac, maxiter=maxiter, f_tol=1e-6, line_search=None, verbose=0)
        assert_(np.allclose(dot(A, sol), b, atol=1e-6))
Esempio n. 3
0
    def _check(self, jac, N, maxiter, complex=False, **kw):
        np.random.seed(123)

        A = np.random.randn(N, N)
        if complex:
            A = A + 1j*np.random.randn(N, N)
        b = np.random.randn(N)
        if complex:
            b = b + 1j*np.random.randn(N)

        def func(x):
            return dot(A, x) - b

        sol = nonlin.nonlin_solve(func, b*0, jac, maxiter=maxiter,
                                  f_tol=1e-6, line_search=None, verbose=0)
        assert_(np.allclose(dot(A, sol), b, atol=1e-6))