示例#1
0
 def test_no_2(self):
     max_order = 5
     trapezoidal = RKimplicitTrapezoidal.phi()
     imp_midpoint = RKimplicitMidpoint.phi()
     half_imp_euler = stepsize_adjustment(RKimplicitEuler.phi(),
                                          Fraction(1, 2))
     #        half_exp_euler = stepsize_adjustment(RKeuler.phi(),\
     #                                             Fraction(1, 2))
     the_conjugate = conjugate_by_commutator(imp_midpoint, half_imp_euler)
     equal_up_to_order(trapezoidal, the_conjugate, max_order)
示例#2
0
    def test_composition(self):
        "It is known that the explicit and implicit Euler methods are adjoint.\
        Furthermore, the composition implicit o explicit = trapezoidal,\
        and explicit o implicit = implicit midpoint.\
        This verifies the coproduct."

        max_order = 5
        explicit_euler = RKeuler.phi()
        implicit_euler = RKimplicitEuler.phi()
        implicit_midpoint = RKimplicitMidpoint.phi()
        implicit_trapezoidal = RKimplicitTrapezoidal.phi()
        result1 = composition_ssa(explicit_euler, implicit_euler)
        tmp = equal_up_to_order(result1, implicit_trapezoidal, max_order)
        self.assertEqual(tmp, max_order)
        result2 = composition_ssa(implicit_euler, explicit_euler)
        tmp = equal_up_to_order(result2, implicit_midpoint, max_order)
        self.assertEqual(tmp, max_order)
示例#3
0
 def test_symplectic(self):
     max_order = 7
     euler = RKeuler.phi()
     self.assertEqual(symplectic_up_to_order(euler, max_order), 1)
     # ==order
     impl_euler = RKimplicitEuler.phi()
     self.assertEqual(symplectic_up_to_order(impl_euler, max_order), 1)
     # ==order
     midpoint = RKmidpoint.phi()
     self.assertEqual(symplectic_up_to_order(midpoint, max_order), 2)
     # ==order
     impl_midpoint = RKimplicitMidpoint.phi()
     self.assertEqual(symplectic_up_to_order(impl_midpoint, max_order),
                      max_order)
     # hamiltonian
     impl_trap = RKimplicitTrapezoidal.phi()
     self.assertEqual(symplectic_up_to_order(impl_trap, max_order), 2)
     # ==order
     runge1 = RKrunge1.phi()
     self.assertEqual(symplectic_up_to_order(runge1, max_order), 3)
     # == order + 1
     runge2 = RKrunge2.phi()
     self.assertEqual(symplectic_up_to_order(runge2, max_order), 2)
     # ==order
     rk4 = RK4.phi()
     self.assertEqual(symplectic_up_to_order(rk4, max_order), 4)
     # ==order
     rk38 = RK38rule.phi()
     self.assertEqual(symplectic_up_to_order(rk38, max_order), 4)
     # ==order
     lobattoIIIA4 = RKlobattoIIIA4.phi()
     self.assertEqual(symplectic_up_to_order(lobattoIIIA4, max_order), 4)
     # ==order
     lobattoIIIB4 = RKlobattoIIIB4.phi()
     self.assertEqual(symplectic_up_to_order(lobattoIIIB4, max_order), 4)
     # ==order
     cashKarp = RKcashKarp.phi()
     self.assertEqual(symplectic_up_to_order(cashKarp, max_order), 5)
     # ==order
     # exponential
     self.assertEqual(symplectic_up_to_order(exponential, max_order),
                      max_order)
示例#4
0
 def test_implicit_euler(self):
     a = RKimplicitEuler.phi()
     b = modified_equation(a)
     result = energy_preserving_upto_order(b)
     self.assertEqual(1, result)  # = order
示例#5
0
 def test_implicit_euler(self):
     a = RKimplicitEuler.phi()
     b = adjoint(a)
     result = equal_up_to_order(b, RKeuler.phi(), self.max_order)
     self.assertEqual(result, self.max_order)
示例#6
0
 def test_hamiltonian_2(self):
     max_order = 7
     euler = RKeuler.phi()
     self.assertEqual(hamiltonian_up_to_order(log(euler), max_order),
                      1)  # ==order
     self.assertEqual(
         subspace_hamiltonian_up_to_order(log(euler), max_order),
         1)  # ==order
     impl_euler = RKimplicitEuler.phi()
     self.assertEqual(hamiltonian_up_to_order(log(impl_euler), max_order),
                      1)  # ==order
     self.assertEqual(
         subspace_hamiltonian_up_to_order(log(impl_euler), max_order),
         1)  # ==order
     midpoint = RKmidpoint.phi()
     self.assertEqual(hamiltonian_up_to_order(log(midpoint), max_order),
                      2)  # ==order
     self.assertEqual(
         subspace_hamiltonian_up_to_order(log(midpoint), max_order),
         2)  # ==order
     impl_midpoint = RKimplicitMidpoint.phi()
     self.assertEqual(
         hamiltonian_up_to_order(log(impl_midpoint), max_order), max_order)
     # hamiltonian
     self.assertEqual(
         subspace_hamiltonian_up_to_order(log(impl_midpoint), max_order),
         max_order)
     # hamiltonian
     impl_trap = RKimplicitTrapezoidal.phi()
     self.assertEqual(hamiltonian_up_to_order(log(impl_trap), max_order),
                      2)  # ==order
     self.assertEqual(
         subspace_hamiltonian_up_to_order(log(impl_trap), max_order),
         2)  # ==order
     runge2 = RKrunge2.phi()
     self.assertEqual(hamiltonian_up_to_order(log(runge2), max_order),
                      2)  # ==order
     self.assertEqual(
         subspace_hamiltonian_up_to_order(log(runge2), max_order),
         2)  # ==order
     runge1 = RKrunge1.phi()
     self.assertEqual(hamiltonian_up_to_order(log(runge1), max_order),
                      3)  # ==order
     self.assertEqual(
         subspace_hamiltonian_up_to_order(log(runge1), max_order),
         3)  # ==order
     rk4 = RK4.phi()
     self.assertEqual(hamiltonian_up_to_order(log(rk4), max_order),
                      4)  # ==order
     self.assertEqual(subspace_hamiltonian_up_to_order(log(rk4), max_order),
                      4)  # ==order
     rk38 = RK38rule.phi()
     self.assertEqual(hamiltonian_up_to_order(log(rk38), max_order),
                      4)  # ==order
     self.assertEqual(subspace_hamiltonian_up_to_order(
         log(rk38), max_order), 4)  # ==order
     lobattoIIIA4 = RKlobattoIIIA4.phi()
     self.assertEqual(hamiltonian_up_to_order(log(lobattoIIIA4), max_order),
                      4)  # ==order
     self.assertEqual(
         subspace_hamiltonian_up_to_order(log(lobattoIIIA4), max_order),
         4)  # ==order
     lobattoIIIB4 = RKlobattoIIIB4.phi()
     self.assertEqual(hamiltonian_up_to_order(log(lobattoIIIB4), max_order),
                      4)  # ==order
     self.assertEqual(
         subspace_hamiltonian_up_to_order(log(lobattoIIIB4), max_order),
         4)  # ==order
     cashKarp = RKcashKarp.phi()
     self.assertEqual(hamiltonian_up_to_order(log(cashKarp), max_order),
                      5)  # ==order
     self.assertEqual(
         subspace_hamiltonian_up_to_order(log(cashKarp), max_order),
         5)  # ==order
     # exponential
     self.assertEqual(hamiltonian_up_to_order(log(exponential), max_order),
                      max_order)
     # hamiltonian
     self.assertEqual(
         subspace_hamiltonian_up_to_order(log(exponential), max_order),
         max_order)
     # hamiltonian
     runge1 = RKrunge1.phi()
     self.assertEqual(hamiltonian_up_to_order(log(runge1), max_order),
                      3)  # == order + 1
     self.assertEqual(
         subspace_hamiltonian_up_to_order(log(runge1), max_order),
         3)  # == order + 1