Пример #1
0
    def test_solve(self):
        "Test that solver runs."
        self.setUp()

        # Create solver and solve
        solver = MonodomainSolver(self.mesh,
                                  self.time,
                                  self.M_i,
                                  I_s=self.stimulus)
        solutions = solver.solve((self.t0, self.t0 + 2 * self.dt), self.dt)
        for (interval, fields) in solutions:
            (v_, vur) = fields
Пример #2
0
    def test_compare_direct_iterative(self):
        "Test that direct and iterative solution give comparable results."
        self.setUp()

        # Create solver and solve
        params = MonodomainSolver.default_parameters()
        params["linear_solver_type"] = "direct"
        solver = MonodomainSolver(self.mesh,
                                  self.time,
                                  self.M_i,
                                  I_s=self.stimulus,
                                  params=params)
        solutions = solver.solve((self.t0, self.t0 + 3 * self.dt), self.dt)
        for (interval, fields) in solutions:
            (v_, v) = fields
            a = v.vector().norm("l2")

        # Create solver and solve using iterative means
        params = MonodomainSolver.default_parameters()
        params["linear_solver_type"] = "iterative"
        params["krylov_solver"]["monitor_convergence"] = True
        solver = MonodomainSolver(self.mesh,
                                  self.time,
                                  self.M_i,
                                  I_s=self.stimulus,
                                  params=params)
        solutions = solver.solve((self.t0, self.t0 + 3 * self.dt), self.dt)
        for (interval, fields) in solutions:
            (v_, v) = fields
            b = v.vector().norm("l2")

        print "lu gives ", a
        print "krylov gives ", b
        assert_almost_equal(a, b, 1e-4)
Пример #3
0
    def test_compare_with_basic_solve(self):
        """Test that solver with direct linear algebra gives same
        results as basic monodomain solver."""
        self.setUp()

        # Create solver and solve
        params = MonodomainSolver.default_parameters()
        params["linear_solver_type"] = "direct"
        solver = MonodomainSolver(self.mesh,
                                  self.time,
                                  self.M_i,
                                  I_s=self.stimulus,
                                  params=params)
        solutions = solver.solve((self.t0, self.t0 + 2 * self.dt), self.dt)
        for (interval, fields) in solutions:
            (v_, vur) = fields
        monodomain_result = vur.vector().norm("l2")

        # Create other solver and solve
        solver = BasicMonodomainSolver(self.mesh,
                                       self.time,
                                       self.M_i,
                                       I_s=self.stimulus)
        solutions = solver.solve((self.t0, self.t0 + 2 * self.dt), self.dt)
        for (interval, fields) in solutions:
            (v_, vur) = fields
        basic_monodomain_result = vur.vector().norm("l2")

        print "monodomain_result = ", monodomain_result
        print "basic_monodomain_result = ", basic_monodomain_result
        assert_almost_equal(monodomain_result, basic_monodomain_result, 1e-13)