Exemplo n.º 1
0
    def __init__(self, n_bath_modes, system_mass,
                 imag_harmonic_frequency_at_barrier,
                 reciprocal_barrier_height_above_well_bottom, bath_masses,
                 bath_frequencies, bath_coupling_constants):

        assert n_bath_modes >= 0
        assert system_mass >= 0.0
        assert abs(imag_harmonic_frequency_at_barrier) > 0.0
        assert reciprocal_barrier_height_above_well_bottom >= 0.0
        assert len(bath_masses) == n_bath_modes
        assert len(bath_frequencies) == n_bath_modes
        assert len(bath_coupling_constants) == n_bath_modes

        for f, g in zip(bath_frequencies[:-1], bath_frequencies[1:]):
            assert f < g

        self._m_s = system_mass  #system mass
        self._omega_b = imag_harmonic_frequency_at_barrier
        self._v_0_sh = reciprocal_barrier_height_above_well_bottom
        self._n = n_bath_modes
        self._c = bath_coupling_constants  #to the system s coordinate.
        self._w = bath_frequencies
        self._m = bath_masses
        self._lie = LieAlgebra(n_bath_modes + 1)

        #$a = (-1/2)m_s\omega_b^2.$
        self._a = -0.5 * self._m_s * (self._omega_b**2)
        #$b = \frac{m_s^2\omega_b^4}{16V_0}.$
        self._b = ((self._m_s**2) * (self._omega_b**4)) / (16.0 * self._v_0_sh)
Exemplo n.º 2
0
    def setUp(self):
        """Set up an example from Hill's equations."""

        x_2 = Powers((2, 0, 0, 0, 0, 0))
        px2 = Powers((0, 2, 0, 0, 0, 0))
        y_2 = Powers((0, 0, 2, 0, 0, 0))
        py2 = Powers((0, 0, 0, 2, 0, 0))
        z_2 = Powers((0, 0, 0, 0, 2, 0))
        pz2 = Powers((0, 0, 0, 0, 0, 2))
        xpy = Powers((1, 0, 0, 1, 0, 0))
        ypx = Powers((0, 1, 1, 0, 0, 0))
        terms = {
            px2: 0.5,
            py2: 0.5,
            pz2: 0.5,
            xpy: -1.0,
            ypx: 1.0,
            x_2: -4.0,
            y_2: 2.0,
            z_2: 2.0
        }
        assert len(terms) == 8

        self.h_2 = Polynomial(6, terms=terms)
        self.lie = LieAlgebra(3)
        self.diag = Diagonalizer(self.lie)
        self.eq_type = 'scc'
        e = []
        e.append(+sqrt(2.0 * sqrt(7.0) + 1.0))
        e.append(-e[-1])
        e.append(complex(0.0, +sqrt(2.0 * sqrt(7.0) - 1.0)))
        e.append(-e[-1])
        e.append(complex(0.0, +2.0))
        e.append(-e[-1])
        self.eig_vals = e
Exemplo n.º 3
0
    def test_cf_hamilton_linear_to_quadratic_matrix(self):
        """Compare the results of (1) asking directly for the linear
        matrix for a given Hamiltonian, and (2) forming Hamilton's
        equations and then linearizing them."""

        dof = 3
        terms = {
            Powers((2, 0, 0, 0, 0, 0)): -0.3,
            Powers((1, 1, 0, 0, 0, 0)): 0.33,
            Powers((0, 1, 0, 1, 1, 0)): 7.2,
            Powers((0, 1, 0, 0, 1, 0)): 7.12,
            Powers((0, 0, 3, 0, 1, 0)): -4.0
        }
        h = Polynomial(2 * dof, terms=terms)
        alg = LieAlgebra(dof)
        diag = Diagonalizer(alg)
        lin = diag.linear_matrix(h)
        rhs = diag.hamiltons_equations_rhs(h)
        rhs_lin = tuple([alg.isograde(h_term, 1) for h_term in rhs])
        for i, pol in enumerate(rhs_lin):
            for m, c in pol.powers_and_coefficients():
                mon = alg.monomial(m, c)
                self.assertEquals(alg.grade(mon), 1)
                for j, f in enumerate(m):
                    if f == 1:
                        self.assertEquals(lin[i, j], c)
Exemplo n.º 4
0
    def test_cf_hamilton_linear_to_quadratic_matrix(self):

        """Compare the results of (1) asking directly for the linear
        matrix for a given Hamiltonian, and (2) forming Hamilton's
        equations and then linearizing them."""
        
        dof = 3
        terms = {Powers((2, 0, 0, 0, 0, 0)): -0.3,
                 Powers((1, 1, 0, 0, 0, 0)): 0.33,
                 Powers((0, 1, 0, 1, 1, 0)): 7.2,
                 Powers((0, 1, 0, 0, 1, 0)): 7.12,
                 Powers((0, 0, 3, 0, 1, 0)): -4.0 }
        h = Polynomial(2*dof, terms=terms)
        alg = LieAlgebra(dof)
        diag = Diagonalizer(alg)
        lin = diag.linear_matrix(h)
        rhs = diag.hamiltons_equations_rhs(h)
        rhs_lin = tuple([alg.isograde(h_term, 1) for h_term in rhs])
        for i, pol in enumerate(rhs_lin):
            for m, c in pol.powers_and_coefficients():
                mon = alg.monomial(m, c)
                self.assertEquals(alg.grade(mon), 1)
                for j, f in enumerate(m):
                    if f==1:
                        self.assertEquals(lin[i, j], c)
Exemplo n.º 5
0
class Hill(NfExample):
    """

    Hill's equations for 3-DoF.

    """
    def __init__(self):
        dof = 3
        self.lie = LieAlgebra(dof)
        self.prefix = 'hill_l1_18'
        self.h_er = read_ma_poly(self.prefix + '_equi_to_tham.pol')
        terms = {
            Powers((2, 0, 0, 0, 0, 0)): -4.0,  #x^2
            Powers((0, 0, 2, 0, 0, 0)): +2.0,  #y^2
            Powers((0, 0, 0, 0, 2, 0)): +2.0,  #z^2
            Powers((0, 2, 0, 0, 0, 0)): +0.5,  #px^2
            Powers((0, 0, 0, 2, 0, 0)): +0.5,  #py^2
            Powers((0, 0, 0, 0, 0, 2)): +0.5,  #pz^2
            Powers((1, 0, 0, 1, 0, 0)): -1.0,  #xpy
            Powers((0, 1, 1, 0, 0, 0)): +1.0
        }  #ypx
        assert len(terms) == 8
        h_2 = self.lie.polynomial(terms)
        assert (h_2 == self.lie.isograde(self.h_er, 2))
        del h_2
 def __init__(self, max_grade):
     dof = 3
     self.alg = LieAlgebra(dof)
     self.h = self.alg.isograde(self.hill_about_l1(), 0, max_grade + 1)
     self.h_dc = self.diagonalize(self.alg, self.h)
     self.h_dr = self.h_dc.substitute(self.sub_r_into_c)
     self.k_dc = self.normalize_to_grade(max_grade)
     self.k_dr = self.k_dc.substitute(self.sub_r_into_c)
Exemplo n.º 7
0
 def __init__(self):
     dof = 1
     self.lie = LieAlgebra(dof)
     self.h_er = self.lie.polynomial({
         Powers((1, 1)): +1.0,
         Powers((3, 0)): -1.0,
         Powers((4, 0)): -1.0,
         Powers((5, 0)): -1.0
     })
Exemplo n.º 8
0
 def _create_nf(self):
     dof = 3
     steps = 2
     alg = LieAlgebra(dof)
     h = alg.zero()
     w = []
     h_db_name = os.path.join(test_dir, 'tmp/_test_h.db')
     k_db_name = os.path.join(test_dir, 'tmp/_test_k.db')
     self.freqs = [-1, +3J, +0.123456]
     h += alg.polynomial({Powers((1,1,0,0,0,0)): self.freqs[0],
                          Powers((0,0,1,1,0,0)): self.freqs[1],
                          Powers((0,0,0,0,1,1)): self.freqs[2]})
     h_2 = h
     state = (h_db_name, w, -1)
     normalizer = LieTriangle.LieTriangle(alg, h_2, state)
     return normalizer
Exemplo n.º 9
0
 def __init__(self):
     dof = 1
     self.lie = LieAlgebra(dof)
     self.h_er = self.lie.polynomial({Powers((1, 1)): +1.0,
                                      Powers((3, 0)): -1.0,
                                      Powers((4, 0)): -1.0,
                                      Powers((5, 0)): -1.0})
Exemplo n.º 10
0
    def setUp(self):

        """Set up an example from Hill's equations."""

        x_2 = Powers((2, 0, 0, 0, 0, 0))
        px2 = Powers((0, 2, 0, 0, 0, 0))
        y_2 = Powers((0, 0, 2, 0, 0, 0))
        py2 = Powers((0, 0, 0, 2, 0, 0))
        z_2 = Powers((0, 0, 0, 0, 2, 0))
        pz2 = Powers((0, 0, 0, 0, 0, 2))
        xpy = Powers((1, 0, 0, 1, 0, 0))
        ypx = Powers((0, 1, 1, 0, 0, 0))
        terms = {px2: 0.5, py2: 0.5, pz2: 0.5,
                 xpy: -1.0, ypx: 1.0,
                 x_2: -4.0, y_2: 2.0, z_2: 2.0}
        assert len(terms) == 8

        self.h_2 = Polynomial(6, terms=terms)
        self.lie = LieAlgebra(3)
        self.diag = Diagonalizer(self.lie)
        self.eq_type = 'scc'
        e = []
        e.append(+sqrt(2.0*sqrt(7.0)+1.0))
        e.append(-e[-1])
        e.append(complex(0.0, +sqrt(2.0*sqrt(7.0)-1.0)))
        e.append(-e[-1])
        e.append(complex(0.0, +2.0))
        e.append(-e[-1])
        self.eig_vals = e
Exemplo n.º 11
0
class EckartasMM(NfExample.NfExample):
    """

    EckartasMM semi-classical system equations for 3-DoF.

    """
    def __init__(self):
        name = "eckartasmm_equi_to_tham.pol"
        logger.info('reading')
        logger.info(name)
        # Get the executable path, not the run dir., and add ../../test
        exedir = sys.path[0]
        in_file = open(os.path.join(exedir, "../../test", name), 'r')
        p = read_ascii_polynomial(in_file,
                                  is_xxpp_format=False)
        in_file.close()
        logger.info('done')
        dof = 3
        self.lie = LieAlgebra(dof)
        self.h_er = p
        grade = 10
        self.prefix='EckartasMM--semi-classical'
        logfile_name = 'EckartasMM--semi-classical--grade-%d.log'%grade
        h_er_trunc = self.lie.isograde(self.h_er, 0, grade+1)
        self.nf = SemiclassicalNormalForm(self.lie, h_er_trunc)
        self.nf.set_tolerance(config["tolerance"])  
Exemplo n.º 12
0
    def __init__(self,
                 n_bath_modes,
                 system_mass,
                 imag_harmonic_frequency_at_barrier,
                 reciprocal_barrier_height_above_well_bottom,
                 bath_masses,
                 bath_frequencies,
                 bath_coupling_constants):

        assert n_bath_modes>=0
        assert system_mass >= 0.0
        assert abs(imag_harmonic_frequency_at_barrier) > 0.0
        assert reciprocal_barrier_height_above_well_bottom >= 0.0
        assert len(bath_masses) == n_bath_modes
        assert len(bath_frequencies) == n_bath_modes
        assert len(bath_coupling_constants) == n_bath_modes

        for f, g in zip(bath_frequencies[:-1], bath_frequencies[1:]):
            assert f < g

        self._m_s = system_mass #system mass
        self._omega_b = imag_harmonic_frequency_at_barrier
        self._v_0_sh = reciprocal_barrier_height_above_well_bottom
        self._n = n_bath_modes
        self._c = bath_coupling_constants #to the system s coordinate.
        self._w = bath_frequencies
        self._m = bath_masses
        self._lie = LieAlgebra(n_bath_modes+1)

        #$a = (-1/2)m_s\omega_b^2.$
        self._a = -0.5*self._m_s*(self._omega_b**2)
        #$b = \frac{m_s^2\omega_b^4}{16V_0}.$
        self._b = ((self._m_s**2) * (self._omega_b**4))/(16.0*self._v_0_sh)
Exemplo n.º 13
0
 def test_mutual_inverses(self):
     lie = LieAlgebra(6)
     diag = Diagonalizer(lie)
     pol = lie.zero()
     for i in xrange(6):
         pol += lie.q(i)
         pol += lie.p(i)
     eq_type = 'scccsc'
     comp = Complexifier(lie, eq_type)
     sub_c_into_r = comp.calc_sub_complex_into_real()
     sub_r_into_c = comp.calc_sub_real_into_complex()
     pol_c = pol.substitute(sub_c_into_r)
     pol_r = pol_c.substitute(sub_r_into_c)
     self.assert_(len(pol_r) == len(pol))
     for i in xrange(6):
         self.assert_((pol_r - pol).l_infinity_norm() < 1.0e-15)
         self.assert_((pol_r - pol).l_infinity_norm() < 1.0e-15)
 def __init__(self, max_grade):
     dof = 3
     self.alg = LieAlgebra(dof)
     self.h = self.alg.isograde(self.hill_about_l1(), 0, max_grade+1)
     self.h_dc = self.diagonalize(self.alg, self.h)
     self.h_dr = self.h_dc.substitute(self.sub_r_into_c)
     self.k_dc = self.normalize_to_grade(max_grade)
     self.k_dr = self.k_dc.substitute(self.sub_r_into_c)
Exemplo n.º 15
0
 def test_mutual_inverses(self):
     lie = LieAlgebra(6)
     diag = Diagonalizer(lie)
     pol = lie.zero()
     for i in xrange(6):
         pol += lie.q(i)
         pol += lie.p(i)
     eq_type = 'scccsc'
     comp = Complexifier(lie, eq_type)
     sub_c_into_r = comp.calc_sub_complex_into_real()
     sub_r_into_c = comp.calc_sub_real_into_complex()
     pol_c = pol.substitute(sub_c_into_r)
     pol_r = pol_c.substitute(sub_r_into_c)
     self.assert_(len(pol_r) == len(pol))
     for i in xrange(6):
         self.assert_((pol_r-pol).l_infinity_norm() < 1.0e-15)
         self.assert_((pol_r-pol).l_infinity_norm() < 1.0e-15)
Exemplo n.º 16
0
class AnotherSaddle(NfExample):
    def __init__(self):
        dof = 1
        self.lie = LieAlgebra(dof)
        self.h_er = self.lie.polynomial({Powers((1, 1)): +1.0,
                                         Powers((3, 0)): -1.0,
                                         Powers((4, 0)): -1.0,
                                         Powers((5, 0)): -1.0})
Exemplo n.º 17
0
class HillBase:
    
    def hill_about_l1(self):
        in_name = os.path.join(test_dir, 'ma-files/hill_l1_18_equi_to_tham.pol')
        in_file = open(in_name, 'r')
        h = read_ascii_polynomial(in_file, is_xxpp_format=1)
        in_file.close()
        terms = {Powers((2, 0, 0, 0, 0, 0)): -4.0, #x^2
                 Powers((0, 0, 2, 0, 0, 0)): +2.0, #y^2
                 Powers((0, 0, 0, 0, 2, 0)): +2.0, #z^2
                 Powers((0, 2, 0, 0, 0, 0)): +0.5, #px^2
                 Powers((0, 0, 0, 2, 0, 0)): +0.5, #py^2
                 Powers((0, 0, 0, 0, 0, 2)): +0.5, #pz^2
                 Powers((1, 0, 0, 1, 0, 0)): -1.0, #xpy
                 Powers((0, 1, 1, 0, 0, 0)): +1.0} #ypx
        assert len(terms) == 8
        dof = 3
        alg = LieAlgebra(dof)
        h_2 = alg.polynomial(terms)
        self.assert_(h_2 == alg.isograde(h, 2))
        return h

    def diagonalize(self, dof, h):
        tolerance = 5.0e-15

        lie = self.alg
        diag = Diagonalizer(lie)
        eig = diag.compute_eigen_system(h, tolerance=tolerance)
        diag.compute_diagonal_change()

        mat = diag.get_matrix_diag_to_equi()
        assert diag.matrix_is_symplectic(mat)
        
        sub_diag_into_equi = diag.matrix_as_vector_of_row_polynomials(mat)
        h_diag = h.substitute(sub_diag_into_equi)

        eq_type = eig.get_equilibrium_type()
        comp = Complexifier(lie, eq_type)
        self.sub_c_into_r = comp.calc_sub_complex_into_real()
        self.sub_r_into_c = comp.calc_sub_real_into_complex()
        h_comp = h_diag.substitute(self.sub_c_into_r)

        h_comp = h_comp.with_small_coeffs_removed(tolerance)
        self.assert_(lie.is_diagonal_polynomial(h_comp.homogeneous(2)))

        return h_comp

    def truncate_and_print_list_polynomials(self, hl, tolerance=1.0e-12):
        for p in hl:
            print p.with_small_coeffs_removed(tolerance)

    def setUp(self):
        self.dof = 3
        self.alg = LieAlgebra(self.dof) #classical
        self.h = self.alg.isograde(self.hill_about_l1(), 0, 6)
        self.h_dc = self.diagonalize(self.dof, self.h)
Exemplo n.º 18
0
 def hill_about_l1(self):
     in_name = os.path.join(test_dir, 'ma-files/hill_l1_18_equi_to_tham.pol')
     in_file = open(in_name, 'r')
     h = read_ascii_polynomial(in_file, is_xxpp_format=1)
     in_file.close()
     terms = {Powers((2, 0, 0, 0, 0, 0)): -4.0, #x^2
              Powers((0, 0, 2, 0, 0, 0)): +2.0, #y^2
              Powers((0, 0, 0, 0, 2, 0)): +2.0, #z^2
              Powers((0, 2, 0, 0, 0, 0)): +0.5, #px^2
              Powers((0, 0, 0, 2, 0, 0)): +0.5, #py^2
              Powers((0, 0, 0, 0, 0, 2)): +0.5, #pz^2
              Powers((1, 0, 0, 1, 0, 0)): -1.0, #xpy
              Powers((0, 1, 1, 0, 0, 0)): +1.0} #ypx
     assert len(terms) == 8
     dof = 3
     alg = LieAlgebra(dof)
     h_2 = alg.polynomial(terms)
     self.assert_(h_2 == alg.isograde(h, 2))
     return h
Exemplo n.º 19
0
class AnotherSaddle(NfExample):
    def __init__(self):
        dof = 1
        self.lie = LieAlgebra(dof)
        self.h_er = self.lie.polynomial({
            Powers((1, 1)): +1.0,
            Powers((3, 0)): -1.0,
            Powers((4, 0)): -1.0,
            Powers((5, 0)): -1.0
        })
Exemplo n.º 20
0
    def __init__(self, n_bath_modes, imag_harmonic_frequency_at_barrier,
                 reciprocal_barrier_height_above_well_bottom, damping_strength,
                 bath_cutoff_frequency, bath_masses, bath_frequencies,
                 bath_compound_coupling_constants):
        """

        Construct a mass-weighted system bath given the values of the
        parameters and the compound coupling constants.

        @param n_bath_modes: (non-negative int).
        @param imag_harmonic_frequency_at_barrier: (real; im part of pure im).
        @param reciprocal_barrier_height_above_well_bottom: (positive real).
        @param damping_strength: (real).
        @param bath_cutoff_frequency: (real, <<bath_frequencies[-1]).
        @param bath_masses: (seq of n_bath_modes positive reals).
        @param bath_frequencies: (increasing seq of n_bath_modes reals).
        @param bath_compound_coupling_constants: (seq of n_bath_modes reals).

        """

        #check inputs
        assert n_bath_modes >= 0
        assert abs(imag_harmonic_frequency_at_barrier) > 0.0
        assert reciprocal_barrier_height_above_well_bottom >= 0.0
        assert len(bath_masses) == n_bath_modes
        assert len(bath_frequencies) == n_bath_modes
        assert len(bath_compound_coupling_constants) == n_bath_modes

        #ensure that the bath frequencies are increasing
        for f, g in zip(bath_frequencies[:-1], bath_frequencies[1:]):
            assert f < g

        #store member variables
        self._n = n_bath_modes
        self._omega_b = imag_harmonic_frequency_at_barrier
        self._v_0_sh = reciprocal_barrier_height_above_well_bottom
        self._eta = damping_strength
        self._omega_c = bath_cutoff_frequency
        self._c_star = bath_compound_coupling_constants  #to system coord
        self._w = bath_omegas
        self._lie = LieAlgebra(n_bath_modes + 1)
Exemplo n.º 21
0
    def test_example_skew(self):
        """Multiply the skew-symmetric matrix by a specific vector."""

        dof = 3
        lie = LieAlgebra(dof)
        diag = Diagonalizer(lie)
        J = diag.skew_symmetric_matrix()
        x = (1, 2, 3, 4, 5, 6)
        y = matrixmultiply(J, x)
        # self.assertEquals(y, (2,-1,4,-3,6,-5))
        z = y == (2, -1, 4, -3, 6, -5)
        self.assertTrue(z.all())
Exemplo n.º 22
0
    def test_skew_symmetric_diagonal_2x_2(self):
        """Test the basic structure of the skew-symmetric matrix."""

        dof = 3
        lie = LieAlgebra(dof)
        diag = Diagonalizer(lie)
        J = diag.skew_symmetric_matrix()
        for qi in xrange(0, dof, 2):
            pi = qi + 1
            self.assertEquals(J[qi, qi], 0.0)
            self.assertEquals(J[qi, pi], +1.0)
            self.assertEquals(J[pi, qi], -1.0)
            self.assertEquals(J[pi, pi], 0.0)
Exemplo n.º 23
0
 def test_diag_in_norm(self):
     dof = 2
     steps = 5
     alg = LieAlgebra(dof)
     w_list = [2.0 * alg.one()] * (steps + 1)
     for index in xrange(alg.n_vars()):
         f_s = alg.coordinate_monomial(index) + 2.3 * alg.one()
         x_i_list = []
         x_ij_dict = {}
         changer = CoordinateChange(alg, w_list)
         changer.express_diag_in_norm(f_s, x_i_list, x_ij_dict, steps)
         id_s = alg.coordinate_monomial(index)
         self.assert_(len(x_i_list) >= 1)
         self.assert_(x_i_list[0] == id_s, x_i_list[0])
         for i in xrange(1, len(x_i_list)):
             self.assert_(x_i_list[i] == alg.zero())
Exemplo n.º 24
0
class Hill(NfExample):
    """

    Hill's equations for 3-DoF.

    """
    def __init__(self):
        dof = 3
        self.lie = LieAlgebra(dof)
        self.prefix = 'hill_l1_18'
        self.h_er = read_ma_poly(self.prefix+'_equi_to_tham.pol')
        terms = {Powers((2, 0, 0, 0, 0, 0)): -4.0, #x^2
                 Powers((0, 0, 2, 0, 0, 0)): +2.0, #y^2
                 Powers((0, 0, 0, 0, 2, 0)): +2.0, #z^2
                 Powers((0, 2, 0, 0, 0, 0)): +0.5, #px^2
                 Powers((0, 0, 0, 2, 0, 0)): +0.5, #py^2
                 Powers((0, 0, 0, 0, 0, 2)): +0.5, #pz^2
                 Powers((1, 0, 0, 1, 0, 0)): -1.0, #xpy
                 Powers((0, 1, 1, 0, 0, 0)): +1.0} #ypx
        assert len(terms) == 8
        h_2 = self.lie.polynomial(terms)
        assert (h_2 == self.lie.isograde(self.h_er, 2))
        del h_2
Exemplo n.º 25
0
 def test_matrix_as_polynomials(self):
     dof = 1
     mat = ((1, 2), (3, 4))
     alg = LieAlgebra(dof)
     diag = Diagonalizer(alg)
     vp = diag.matrix_as_vector_of_row_polynomials(mat)
     self.assert_(vp[0]((0.0, 0.0)) == 0.0)
     self.assert_(vp[0]((1.0, 0.0)) == 1.0)
     self.assert_(vp[0]((1.0, 1.0)) == 3.0)
     self.assert_(vp[0]((0.0, 1.0)) == 2.0)
     self.assert_(vp[1]((0.0, 0.0)) == 0.0)
     self.assert_(vp[1]((1.0, 0.0)) == 3.0)
     self.assert_(vp[1]((1.0, 1.0)) == 7.0)
     self.assert_(vp[1]((0.0, 1.0)) == 4.0)
Exemplo n.º 26
0
 def test_saddle(self):
     lie = LieAlgebra(1)
     diag = Diagonalizer(lie)
     q = lie.q
     p = lie.p
     orig = q(0) * p(0)
     eq_type = 's'
     comp = Complexifier(lie, eq_type)
     r2c = comp.calc_sub_complex_into_real()
     c2r = comp.calc_sub_real_into_complex()
     comp = orig.substitute(r2c)
     real = comp.substitute(c2r)
     diff = orig - real
     for m, c in diff.powers_and_coefficients():
         self.assert_(abs(c) < 1.0e-15)
Exemplo n.º 27
0
    def __init__(self,
                 n_bath_modes,
                 imag_harmonic_frequency_at_barrier,
                 reciprocal_barrier_height_above_well_bottom,
                 damping_strength,
                 bath_cutoff_frequency,
                 bath_masses,
                 bath_frequencies,
                 bath_compound_coupling_constants):
        """

        Construct a mass-weighted system bath given the values of the
        parameters and the compound coupling constants.

        @param n_bath_modes: (non-negative int).
        @param imag_harmonic_frequency_at_barrier: (real; im part of pure im).
        @param reciprocal_barrier_height_above_well_bottom: (positive real).
        @param damping_strength: (real).
        @param bath_cutoff_frequency: (real, <<bath_frequencies[-1]).
        @param bath_masses: (seq of n_bath_modes positive reals).
        @param bath_frequencies: (increasing seq of n_bath_modes reals).
        @param bath_compound_coupling_constants: (seq of n_bath_modes reals).

        """

        #check inputs
        assert n_bath_modes>=0
        assert abs(imag_harmonic_frequency_at_barrier) > 0.0
        assert reciprocal_barrier_height_above_well_bottom >= 0.0
        assert len(bath_masses) == n_bath_modes
        assert len(bath_frequencies) == n_bath_modes
        assert len(bath_compound_coupling_constants) == n_bath_modes

        #ensure that the bath frequencies are increasing
        for f, g in zip(bath_frequencies[:-1], bath_frequencies[1:]):
            assert f < g

        #store member variables
        self._n = n_bath_modes
        self._omega_b = imag_harmonic_frequency_at_barrier
        self._v_0_sh = reciprocal_barrier_height_above_well_bottom
        self._eta = damping_strength
        self._omega_c = bath_cutoff_frequency
        self._c_star = bath_compound_coupling_constants #to system coord
        self._w = bath_omegas
        self._lie = LieAlgebra(n_bath_modes+1)
Exemplo n.º 28
0
def compare_files(n_vars, file_name1, file_name2, comment="", factor = 1.0):

    from LieAlgebra import LieAlgebra
    from SemiclassicalNormalForm import SemiclassicalNormalForm
    dof = n_vars / 2
    if n_vars % 2:
        lie = SemiclassicalLieAlgebra(dof)
    else:
        lie = LieAlgebra(dof)
    ring_io = PolynomialRingIO(lie)

    file_istr = open(file_name1, 'r')
    poly1=ring_io.read_sexp_polynomial(file_istr)

    file_istr = open(file_name2, 'r')
    poly2=ring_io.read_sexp_polynomial(file_istr)
    compare_poly(factor * poly1, poly2, comment=comment)
 def test_diag_in_norm(self):
     dof = 2
     steps = 5
     alg = LieAlgebra(dof)
     w_list = [2.0*alg.one()]*(steps+1)
     for index in xrange(alg.n_vars()):
         f_s = alg.coordinate_monomial(index)+2.3*alg.one()
         x_i_list = []
         x_ij_dict = {}
         changer = CoordinateChange(alg, w_list)
         changer.express_diag_in_norm(f_s, x_i_list, x_ij_dict, steps)
         id_s = alg.coordinate_monomial(index)
         self.assert_(len(x_i_list) >= 1)
         self.assert_(x_i_list[0] == id_s, x_i_list[0])
         for i in xrange(1, len(x_i_list)):
             self.assert_(x_i_list[i] == alg.zero())
Exemplo n.º 30
0
 def test_centre_saddle(self):
     lie = LieAlgebra(2)
     diag = Diagonalizer(lie)
     q = lie.q
     p = lie.p
     cent = (0.5 * q(0)**2) + (0.5 * p(0)**2)
     sadd = (1.0 * q(1)) * (1.0 * p(1))
     orig = cent + sadd
     self.assertEquals(len(orig), 3)
     eq_type = 'cs'
     comp = Complexifier(lie, eq_type)
     r2c = comp.calc_sub_complex_into_real()
     c2r = comp.calc_sub_real_into_complex()
     comp = orig.substitute(r2c)
     self.assertEquals(len(comp), 2)
     real = comp.substitute(c2r)
     diff = orig - real
     for m, c in diff.powers_and_coefficients():
         self.assert_(abs(c) < 1.0e-15)
Exemplo n.º 31
0
 def test_centre(self):
     lie = LieAlgebra(1)
     diag = Diagonalizer(lie)
     q = lie.q
     p = lie.p
     orig = (0.5 * q(0)**2) + (0.5 * p(0)**2)
     self.assertEquals(len(orig), 2)
     eq_type = 'c'
     comp = Complexifier(lie, eq_type)
     r2c = comp.calc_sub_complex_into_real()
     c2r = comp.calc_sub_real_into_complex()
     comp = orig.substitute(r2c)
     self.assertEquals(len(comp), 1)
     for m, c in comp.powers_and_coefficients():
         self.assert_(c.real == 0.0)
         self.assert_(m[0] == 1)
         self.assert_(m[1] == 1)
     real = comp.substitute(c2r)
     diff = orig - real
     for m, c in diff.powers_and_coefficients():
         self.assert_(abs(c) < 1.0e-15)
Exemplo n.º 32
0
    def test_eigensystem(self):
        """Multiply eigenvectors and the original matrix by the
        eigenvalues in order to check the integrity of the
        eigensystem."""

        dof = 3
        terms = {
            Powers((2, 0, 0, 0, 0, 0)): -0.3,
            Powers((1, 1, 0, 0, 0, 0)): 0.33,
            Powers((0, 0, 1, 0, 1, 0)): 7.2,
            Powers((0, 0, 0, 0, 0, 2)): 7.2,
            Powers((0, 0, 0, 1, 1, 0)): 7.12
        }
        g = Polynomial(2 * dof, terms=terms)
        alg = LieAlgebra(dof)
        diag = Diagonalizer(alg)
        lin = diag.linear_matrix(g)
        val_vec_pairs = diag.eigenvalue_eigenvector_pairs(g)
        for p in val_vec_pairs:
            prod_s = p.vec * p.val
            prod_v = matrixmultiply(lin, p.vec)
            for x in prod_s - prod_v:
                self.assert_(abs(x) < 1.0e-15)
Exemplo n.º 33
0
 def __init__(self):
     dof = 3
     self.lie = LieAlgebra(dof)
     self.prefix = 'rftbp_eros_eq1_10'
     self.h_er = read_ma_poly(self.prefix + '_equi_to_tham.pol')
Exemplo n.º 34
0
 def setUp(self):
     self.dof = 3
     self.alg = LieAlgebra(self.dof) #classical
     self.h = self.alg.isograde(self.hill_about_l1(), 0, 6)
     self.h_dc = self.diagonalize(self.dof, self.h)
Exemplo n.º 35
0
class SystemBath:
    """

    The original (_not_ mass-weighted) system bath.

    The system-bath model represents a 'system' part: a symmetric
    quartic double-well potential, coupled to a number of 'bath
    modes': harmonic oscillators.  The coupling is achieved via a
    bilinear coupling between the configuration space coordinate of
    the system and the conjugate momenta of each of the bath modes.
    The resulting Hamiltonian is a polynomial of degree 4 in the phase
    space coordinates.

    With this version, the client must specify all of the following:-

    @param n_bath_modes: (non-negative int).
    @param system_mass: (positive real).
    @param imag_harmonic_frequency_at_barrier: (real; imag part of pure imag).
    @param reciprocal_barrier_height_above_well_bottom: (positive real).
    @param bath_masses: (seq of n_bath_modes positive reals).
    @param bath_frequencies: (seq of n_bath_modes reals).
    @param bath_coupling_constants: (seq of n_bath_modes reals).

    """
    def __init__(self, n_bath_modes, system_mass,
                 imag_harmonic_frequency_at_barrier,
                 reciprocal_barrier_height_above_well_bottom, bath_masses,
                 bath_frequencies, bath_coupling_constants):

        assert n_bath_modes >= 0
        assert system_mass >= 0.0
        assert abs(imag_harmonic_frequency_at_barrier) > 0.0
        assert reciprocal_barrier_height_above_well_bottom >= 0.0
        assert len(bath_masses) == n_bath_modes
        assert len(bath_frequencies) == n_bath_modes
        assert len(bath_coupling_constants) == n_bath_modes

        for f, g in zip(bath_frequencies[:-1], bath_frequencies[1:]):
            assert f < g

        self._m_s = system_mass  #system mass
        self._omega_b = imag_harmonic_frequency_at_barrier
        self._v_0_sh = reciprocal_barrier_height_above_well_bottom
        self._n = n_bath_modes
        self._c = bath_coupling_constants  #to the system s coordinate.
        self._w = bath_frequencies
        self._m = bath_masses
        self._lie = LieAlgebra(n_bath_modes + 1)

        #$a = (-1/2)m_s\omega_b^2.$
        self._a = -0.5 * self._m_s * (self._omega_b**2)
        #$b = \frac{m_s^2\omega_b^4}{16V_0}.$
        self._b = ((self._m_s**2) * (self._omega_b**4)) / (16.0 * self._v_0_sh)

    def lie_algebra(self):
        """

        Return the Lie algebra on which the polynomials will be
        constructed.  For N bath modes, this has (N+1)-dof.

        """
        return self._lie

    def hamiltonian_real(self):
        """

        Calculate the real Hamiltonian for the system-bath model.

        """
        #Establish some convenient notation:
        n = self._n
        a = self._a
        b = self._b
        m_s = self._m_s
        c = self._c
        w = self._w
        m = self._m
        q_s = self._lie.q(0)
        p_s = self._lie.p(0)

        #Compute some constants:
        coeff_q_s = a
        for i in xrange(0, len(c)):
            coeff_q_s += (c[i]**2.0) / (2.0 * m[i] * (w[i]**2.0))
        coeff_p_s = 1.0 / (2.0 * m_s)

        coeff_q_bath = []
        coeff_p_bath = []
        for i in xrange(0, len(c)):
            coeff_q_bath.append(0.5 * m[i] * (w[i]**2.0))
            coeff_p_bath.append(1.0 / (2.0 * m[i]))

        #Sanity checks:
        assert n >= 0, 'Need zero or more bath modes.'
        assert len(c) == n, 'Need a coupling constant for each bath mode.'
        assert len(coeff_q_bath) == n, 'Need constant for each bath config.'
        assert len(coeff_p_bath) == n, 'Need constant for each bath momentum.'

        #System part:
        h_system = coeff_p_s * (p_s**2)
        h_system += coeff_q_s * (q_s**2)
        h_system += b * (q_s**4)

        #Bath part:
        h_bath = self._lie.zero()
        for i in xrange(len(c)):
            bath_dof = i + 1
            h_bath += coeff_q_bath[i] * (self._lie.q(bath_dof)**2)
            h_bath += coeff_p_bath[i] * (self._lie.p(bath_dof)**2)

        #Coupling part:
        h_coupling = self._lie.zero()
        for i, c_i in enumerate(c):
            bath_dof = i + 1
            h_coupling += -c_i * (self._lie.q(bath_dof) * q_s)

        #Complete Hamiltonian:
        h = h_system + h_bath + h_coupling

        #Sanity checks:
        assert h.degree() == 4
        assert h.n_vars() == 2 * n + 2
        assert len(h) == (3) + (2 * n) + (n)  #system+bath+coupling

        return h
Exemplo n.º 36
0
 def __init__(self):
     dof = 1
     self.lie = LieAlgebra(dof)
     self.prefix = 'bad_1dof'
     self.h_er = read_ma_poly(self.prefix + '_equi_to_tham.pol')
Exemplo n.º 37
0
 def __init__(self):
     dof = 3
     self.lie = LieAlgebra(dof)
     self.prefix = 'rydberg_saddle_16'
     self.h_er = read_ma_poly(self.prefix + '_equi_to_tham.pol')
Exemplo n.º 38
0
    def read_normal_form_data(self,
                              dir_name,
                              order_f=None,
                              is_xxpp_format=False,
                              degree=None):
        """
        Read the NF data and reorder the variables xxpp to xpxp and
        the order of the NF planes as required for Mathematica data
        """
        def check_poly_degree(poly, name, degree):
            if degree:
                polyd = poly.degree()
                if polyd != degree:
                    print "poly %s is degree %d not degree %d" % (name, polyd,
                                                                  degree)

        def check_vec_degree(poly_vec, name, degree):
            for i in xrange(len(poly_vec)):
                check_poly_degree(poly_vec[i], name + "[%d]" % i, degree)

        def read_file_vec_polynomials(dir_name,
                                      file_name,
                                      is_xxpp_format,
                                      order=None,
                                      degree=degree):
            file_istr = open(os.path.join(dir_name, file_name), 'r')
            vec_poly = read_ascii_vec_polynomials(file_istr,
                                                  is_xxpp_format,
                                                  order=order)
            file_istr.close()
            check_vec_degree(vec_poly, file_name, degree)
            return vec_poly

        # see what we have
        file_istr = open(os.path.join(dir_name, "norm_to_ints.vec"), 'r')
        line = file_istr.next()
        n_vars = int(line)
        assert n_vars >= 0
        line = file_istr.next()
        n_ints = int(line)
        assert n_ints >= 0
        file_istr.close()
        self._n_vars = n_vars
        assert n_ints == n_vars / 2

        dof = n_ints
        #dof = p.n_vars() / 2
        lie = LieAlgebra(dof)

        #nf = NormalForm(lie, h_er)
        # TODO If there's nothing here then do a run to generate data

        #These are dim dof, is_xxpp_format doesn't apply
        file_istr = open(os.path.join(dir_name, "ints_to_freq.vec"), 'r')
        self.ints_to_freq = read_ascii_vec_polynomials(file_istr, False)
        file_istr.close()
        print 'Primary frequencies:', [
            poly((0.0, ) * n_ints) for poly in self.ints_to_freq
        ]
        my_order_f = [poly((0.0, ) * n_ints) for poly in self.ints_to_freq]
        # Don't do reordering for first NF only second with order_f set
        new_order = None
        # Find the order in which the supplied frequencies are found
        if order_f:
            degree = check_poly_degree(self.ints_to_freq[0],
                                       "the second normal form", degree)
            degree = 18
            new_order = []
            for i in xrange(n_ints):
                for j in xrange(n_ints):
                    if (abs(my_order_f[j] - order_f[i]) < 1.0e-4):
                        new_order.append(j)
            print "new_order", new_order
            assert len(new_order) == n_ints
            #RE-Read in new order, These are dim dof- no is_xxpp_format
            file_istr = open(os.path.join(dir_name, "ints_to_freq.vec"), 'r')
            self.ints_to_freq = read_ascii_vec_polynomials(file_istr,
                                                           False,
                                                           order=new_order)
            file_istr.close()
            print 'Primary frequencies:', [
                poly((0.0, ) * n_ints) for poly in self.ints_to_freq
            ]
        # equi_to_tham - equi coords are not reordered until diagonalised
        file_istr = open(os.path.join(dir_name, "equi_to_tham.pol"), 'r')
        self.equi_to_tham = read_ascii_polynomial(
            file_istr, is_xxpp_format=is_xxpp_format)
        file_istr.close()
        check_poly_degree(self.equi_to_tham, "equi_to_tham.pol", degree)
        self.equi_to_tvec = read_file_vec_polynomials(
            dir_name,
            "equi_to_tvec.vec",
            is_xxpp_format=is_xxpp_format,
            degree=degree - 1)
        # now reorder to the Mathematica order of the planes
        file_istr = open(os.path.join(dir_name, "ints_to_tham.pol"), 'r')
        self.ints_to_tham = read_ascii_polynomial(file_istr,
                                                  False,
                                                  order=new_order)
        file_istr.close()
        check_poly_degree(self.ints_to_tham, "ints_to_tham.pol", degree / 2)
        # The matrices are different they do the reordering on diag side
        file_istr = open(os.path.join(dir_name, "diag_to_equi.mat"), 'r')
        mat = read_ascii_matrix(file_istr, is_xxpp_format)
        file_istr.close()
        # reorder input variables
        if order_f:
            for i in xrange(len(mat)):
                mat[i] = reorder_dof(mat[i], new_order)
        assert n_vars == len(mat)
        assert n_vars == len(mat[1])
        self.diag_to_equi = mat
        file_istr = open(os.path.join(dir_name, "equi_to_diag.mat"), 'r')
        mat = read_ascii_matrix(file_istr, is_xxpp_format)
        file_istr.close()
        # reorder output variables
        if order_f:
            mat = reorder_dof(mat, new_order)
        assert n_vars == len(mat)
        assert n_vars == len(mat[1])
        self.equi_to_diag = mat
        # reorder all for norm_to_diag, diag_to_norm
        self.norm_to_diag = read_file_vec_polynomials(
            dir_name,
            "norm_to_diag.vec",
            is_xxpp_format=is_xxpp_format,
            order=new_order,
            degree=degree - 1)
        self.diag_to_norm = read_file_vec_polynomials(
            dir_name,
            "diag_to_norm.vec",
            is_xxpp_format=is_xxpp_format,
            order=new_order,
            degree=degree - 1)
        # norm_to_ints has is_xxpp_format on input vars but not o/p in r_a_v_p
        self.norm_to_ints = read_file_vec_polynomials(
            dir_name,
            "norm_to_ints.vec",
            is_xxpp_format=is_xxpp_format,
            order=new_order,
            degree=2)
Exemplo n.º 39
0
class SystemBath:
    """

    The original (_not_ mass-weighted) system bath.

    The system-bath model represents a 'system' part: a symmetric
    quartic double-well potential, coupled to a number of 'bath
    modes': harmonic oscillators.  The coupling is achieved via a
    bilinear coupling between the configuration space coordinate of
    the system and the conjugate momenta of each of the bath modes.
    The resulting Hamiltonian is a polynomial of degree 4 in the phase
    space coordinates.

    With this version, the client must specify all of the following:-

    @param n_bath_modes: (non-negative int).
    @param system_mass: (positive real).
    @param imag_harmonic_frequency_at_barrier: (real; imag part of pure imag).
    @param reciprocal_barrier_height_above_well_bottom: (positive real).
    @param bath_masses: (seq of n_bath_modes positive reals).
    @param bath_frequencies: (seq of n_bath_modes reals).
    @param bath_coupling_constants: (seq of n_bath_modes reals).

    """

    def __init__(self,
                 n_bath_modes,
                 system_mass,
                 imag_harmonic_frequency_at_barrier,
                 reciprocal_barrier_height_above_well_bottom,
                 bath_masses,
                 bath_frequencies,
                 bath_coupling_constants):

        assert n_bath_modes>=0
        assert system_mass >= 0.0
        assert abs(imag_harmonic_frequency_at_barrier) > 0.0
        assert reciprocal_barrier_height_above_well_bottom >= 0.0
        assert len(bath_masses) == n_bath_modes
        assert len(bath_frequencies) == n_bath_modes
        assert len(bath_coupling_constants) == n_bath_modes

        for f, g in zip(bath_frequencies[:-1], bath_frequencies[1:]):
            assert f < g

        self._m_s = system_mass #system mass
        self._omega_b = imag_harmonic_frequency_at_barrier
        self._v_0_sh = reciprocal_barrier_height_above_well_bottom
        self._n = n_bath_modes
        self._c = bath_coupling_constants #to the system s coordinate.
        self._w = bath_frequencies
        self._m = bath_masses
        self._lie = LieAlgebra(n_bath_modes+1)

        #$a = (-1/2)m_s\omega_b^2.$
        self._a = -0.5*self._m_s*(self._omega_b**2)
        #$b = \frac{m_s^2\omega_b^4}{16V_0}.$
        self._b = ((self._m_s**2) * (self._omega_b**4))/(16.0*self._v_0_sh)

    def lie_algebra(self):
        """

        Return the Lie algebra on which the polynomials will be
        constructed.  For N bath modes, this has (N+1)-dof.

        """
        return self._lie

    def hamiltonian_real(self):
        """

        Calculate the real Hamiltonian for the system-bath model.

        """
        #Establish some convenient notation:
        n = self._n
        a = self._a
        b = self._b
        m_s = self._m_s
        c = self._c
        w = self._w
        m = self._m
        q_s = self._lie.q(0)
        p_s = self._lie.p(0)

        #Compute some constants:
        coeff_q_s = a
        for i in xrange(0, len(c)):
            coeff_q_s += (c[i]**2.0)/(2.0 * m[i] * (w[i]**2.0))
        coeff_p_s = 1.0/(2.0 * m_s)

        coeff_q_bath = []
        coeff_p_bath = []
        for i in xrange(0, len(c)):
            coeff_q_bath.append(0.5 * m[i] * (w[i]**2.0))
            coeff_p_bath.append(1.0/(2.0 * m[i]))

        #Sanity checks:
        assert n >= 0, 'Need zero or more bath modes.'
        assert len(c) == n, 'Need a coupling constant for each bath mode.'
        assert len(coeff_q_bath) == n, 'Need constant for each bath config.'
        assert len(coeff_p_bath) == n, 'Need constant for each bath momentum.'

        #System part:
        h_system = coeff_p_s * (p_s**2)
        h_system += coeff_q_s * (q_s**2)
        h_system += b * (q_s**4)

        #Bath part:
        h_bath = self._lie.zero()
        for i in xrange(len(c)):
            bath_dof = i+1
            h_bath += coeff_q_bath[i] * (self._lie.q(bath_dof)**2)
            h_bath += coeff_p_bath[i] * (self._lie.p(bath_dof)**2)

        #Coupling part:
        h_coupling = self._lie.zero()
        for i, c_i in enumerate(c):
            bath_dof = i+1
            h_coupling += -c_i * (self._lie.q(bath_dof) * q_s)

        #Complete Hamiltonian:
        h = h_system + h_bath + h_coupling

        #Sanity checks:
        assert h.degree() == 4
        assert h.n_vars() == 2*n+2
        assert len(h) == (3) + (2*n) + (n) #system+bath+coupling
        
        return h
Exemplo n.º 40
0
class MassWeightedSystemBath:
    """

    The system-bath model represents a 'system' part (a symmetric
    quartic double-well potential) coupled to a number of 'bath
    modes' (harmonic oscillators).  The coupling is achieved via a
    bilinear coupling between the configuration space coordinate of
    the system and the conjugate momenta of each of the bath modes.
    The resulting Hamiltonian is a polynomial of degree 4 in the phase
    space coordinates.

    """

    def __init__(self,
                 n_bath_modes,
                 imag_harmonic_frequency_at_barrier,
                 reciprocal_barrier_height_above_well_bottom,
                 damping_strength,
                 bath_cutoff_frequency,
                 bath_masses,
                 bath_frequencies,
                 bath_compound_coupling_constants):
        """

        Construct a mass-weighted system bath given the values of the
        parameters and the compound coupling constants.

        @param n_bath_modes: (non-negative int).
        @param imag_harmonic_frequency_at_barrier: (real; im part of pure im).
        @param reciprocal_barrier_height_above_well_bottom: (positive real).
        @param damping_strength: (real).
        @param bath_cutoff_frequency: (real, <<bath_frequencies[-1]).
        @param bath_masses: (seq of n_bath_modes positive reals).
        @param bath_frequencies: (increasing seq of n_bath_modes reals).
        @param bath_compound_coupling_constants: (seq of n_bath_modes reals).

        """

        #check inputs
        assert n_bath_modes>=0
        assert abs(imag_harmonic_frequency_at_barrier) > 0.0
        assert reciprocal_barrier_height_above_well_bottom >= 0.0
        assert len(bath_masses) == n_bath_modes
        assert len(bath_frequencies) == n_bath_modes
        assert len(bath_compound_coupling_constants) == n_bath_modes

        #ensure that the bath frequencies are increasing
        for f, g in zip(bath_frequencies[:-1], bath_frequencies[1:]):
            assert f < g

        #store member variables
        self._n = n_bath_modes
        self._omega_b = imag_harmonic_frequency_at_barrier
        self._v_0_sh = reciprocal_barrier_height_above_well_bottom
        self._eta = damping_strength
        self._omega_c = bath_cutoff_frequency
        self._c_star = bath_compound_coupling_constants #to system coord
        self._w = bath_omegas
        self._lie = LieAlgebra(n_bath_modes+1)

    def compute_compound_constants(n_bath_modes,
                                   damping_strength,
                                   bath_cutoff_frequency,
                                   bath_frequencies):
        """

        Compute the compound coupling constants.

        @param n_bath_modes: (non-negative int).
        @param damping_strength: (real).
        @param bath_cutoff_frequency: (real, <<bath_frequencies[-1]).
        @param bath_frequencies: (seq of n_bath_modes reals increasing).

        @return: bath_compound_coupling_constants (seq of n_bath_modes reals).

        """

        #check inputs
        assert n_bath_modes>=0
        assert len(bath_frequencies) == n_bath_modes
        for f, g in zip(bath_frequencies[:-1], bath_frequencies[1:]):
            assert f < g
        assert bath_frequencies[-1] > bath_cutoff_frequency

        #accumulate compound frequencies
        c_star = []
        omega_c = bath_cutoff_frequency
        eta = damping_strength
        for jm1, omega_j in enumerate(bath_frequencies):
            c = (-2.0/(pi*(jm1+1.0)))*eta*omega_c
            d = ((omega_j+omega_c)*exp(-omega_j/omega_c) - omega_c)
            c_star.append(c*d)
        return c_star
    compute_compound_constants = staticmethod(compute_compound_constants)

    def bath_spectral_density_function(self, omega):
        """

        The bath is defined in terms of a continuous spectral density
        function, which has the Ohmic form with an exponential cutoff.

        For infinite bath cutoff frequency, $\omega_c$, the bath is
        strictly Ohmic, i.e., the friction kernel becomes a delta
        function in the time domain, and the classical dynamics of the
        system coordinate are described by the ordinary Langevin
        equation.  In that case, $eta$ (the damping strength) is the
        classically measurable friction coefficient.

        However, for finite values of the bath cutoff frequency, the
        friction kernel is nonlocal, which introduces memory effects
        into the Generalized Langevin Equation (GLE).

        """
        return self.eta * omega * exp(-omega/self._omega_c)

    def hamiltonian_real(self):
        """

        Calculate the real Hamiltonian for the system-bath model.

        """
        #establish some convenient notation:
        n = self._n
        w = self._w
        c_star = self._c_star

        #sanity checks:
        assert n >= 0, 'Need zero or more bath modes.'
        assert len(c_star) == n, 'Need a coupling constant for each bath mode.'

        #system coefficients:
        a = -0.5*(self._omega_b**2)
        b = (self._omega_b**4)/(16.0*self._v_0_sh)
        coeff_q_s = a
        for i in xrange(0, len(c_star)):
            coeff_q_s += c_star[i]/(2.0 * (w[i]))
        coeff_p_s = 1.0/2.0

        #system part:
        q_s = self._lie.q(0)
        p_s = self._lie.p(0)
        h_system = coeff_p_s * (p_s**2)
        h_system += coeff_q_s * (q_s**2)
        h_system += b * (q_s**4)

        #bath coefficients:
        coeff_q_bath = []
        coeff_p_bath = []
        for i in xrange(0, len(c_star)):
            coeff_q_bath.append(0.5 * (w[i]**2.0))
            coeff_p_bath.append(1.0/2.0)

        #sanity checks:
        assert len(coeff_q_bath) == n, 'Need constant for each bath config.'
        assert len(coeff_p_bath) == n, 'Need constant for each bath momentum.'

        #bath part:
        h_bath = self._lie.zero()
        for i in xrange(len(c_star)):
            bath_dof = i+1
            h_bath += coeff_q_bath[i] * (self._lie.q(bath_dof)**2)
            h_bath += coeff_p_bath[i] * (self._lie.p(bath_dof)**2)

        #coupling part:
        h_coupling = self._lie.zero()
        for i, c_i in enumerate(c_star):
            bath_dof = i+1
            h_coupling += -sqrt(c_i*w[i]) * (self._lie.q(bath_dof)*q_s)

        #complete Hamiltonian:
        h = h_system + h_bath + h_coupling

        #sanity checks:
        assert h.degree() == 4
        assert h.n_vars() == 2*n+2
        assert len(h) == (3) + (2*n) + (n) #system+bath+coupling
        
        return h
class Hill:
    def __init__(self, max_grade):
        dof = 3
        self.alg = LieAlgebra(dof)
        self.h = self.alg.isograde(self.hill_about_l1(), 0, max_grade + 1)
        self.h_dc = self.diagonalize(self.alg, self.h)
        self.h_dr = self.h_dc.substitute(self.sub_r_into_c)
        self.k_dc = self.normalize_to_grade(max_grade)
        self.k_dr = self.k_dc.substitute(self.sub_r_into_c)

    def hill_about_l1(self):
        #print 'reading hill hamiltonian for test...'
        in_name = '../../test/ma-files/hill_l1_18_equi_to_tham.pol'
        in_file = open(in_name, 'r')
        h = read_ascii_polynomial(in_file, is_xxpp_format=1)
        in_file.close()
        #print 'done'
        terms = {
            Powers((2, 0, 0, 0, 0, 0)): -4.0,  #x^2
            Powers((0, 0, 2, 0, 0, 0)): +2.0,  #y^2
            Powers((0, 0, 0, 0, 2, 0)): +2.0,  #z^2
            Powers((0, 2, 0, 0, 0, 0)): +0.5,  #px^2
            Powers((0, 0, 0, 2, 0, 0)): +0.5,  #py^2
            Powers((0, 0, 0, 0, 0, 2)): +0.5,  #pz^2
            Powers((1, 0, 0, 1, 0, 0)): -1.0,  #xpy
            Powers((0, 1, 1, 0, 0, 0)): +1.0
        }  #ypx
        assert len(terms) == 8
        h_2 = self.alg.polynomial(terms)
        assert (h_2 == self.alg.isograde(h, 2))
        return h

    def diagonalize(self, dof, h):
        tolerance = 5.0e-15

        self.diag = Diagonalizer(self.alg)
        self.eig = self.diag.compute_eigen_system(h, tolerance)
        self.diag.compute_diagonal_change()

        mat = self.diag.get_matrix_diag_to_equi()
        assert self.diag.matrix_is_symplectic(mat)

        sub_diag_into_equi = self.diag.matrix_as_vector_of_row_polynomials(mat)
        h_diag = h.substitute(sub_diag_into_equi)

        self.eq_type = self.eig.get_equilibrium_type()
        self.comp = Complexifier(self.alg, self.eq_type)
        self.sub_c_into_r = self.comp.calc_sub_complex_into_real()
        self.sub_r_into_c = self.comp.calc_sub_real_into_complex()
        h_comp = h_diag.substitute(self.sub_c_into_r)

        h_comp = h_comp.with_small_coeffs_removed(tolerance)
        assert (self.alg.is_diagonal_polynomial(self.alg.isograde(h_comp, 2)))

        return h_comp

    def normalize_to_grade(self, max_grade):
        steps = max_grade
        h_dc = self.alg.isograde(self.h_dc, 2, max_grade + 1)
        h_dc_2 = self.alg.isograde(h_dc, 2)
        k_comp = self.alg.zero()
        w_comp = self.alg.zero()
        #the following is not very efficient for separating grades!
        h_list = [self.alg.isograde(h_dc, i + 2) for i in xrange(0, steps + 1)]
        nf = LieTriangle(self.alg, h_dc_2)
        for i in xrange(0, steps + 1):
            h_term = h_list[i]
            k_term, w_term = nf.compute_normal_form_and_generating_function(
                h_term)
            k_comp += k_term
            w_comp += w_term

        #print k_comp
        k_real = k_comp.substitute(self.sub_r_into_c)
        assert (k_real.imag().l_infinity_norm() < 1.0e-14)
        k_real = k_real.real()

        return k_comp
Exemplo n.º 42
0
 def __init__(self):
     dof = 3
     self.lie = LieAlgebra(dof)
     self.prefix = 'crtbp_sun_neptune_l1_14'
     self.h_er = read_ma_poly(self.prefix + '_equi_to_tham.pol')
Exemplo n.º 43
0
def compare_normal_form(dir_name1, dir_name2, grade=4):
    def compare_matrix(dia, mat1, mat2, comment):
        print dia.matrix_norm(array(mat1, Float) - array(mat2, Float)), comment

    print "Comparing data in Normal form files upto grade %d" % (grade)
    print
    print "Reading python data"

    first = NormalFormData(dir_name1, is_xxpp_format=True, degree=grade)

    ring = PolynomialRing(first.equi_to_tham.n_vars())

    print
    print "Comparing python data with cpp files upto grade %d" % (grade)
    print "l_infinity_norm \t l1_norm \t\t polynomials"
    ringIO = PolynomialRingIO(ring)
    file_istr = open("hill_l1_18--norm_to_diag.vpol", 'r')
    pv_norm_to_diag = ringIO.read_sexp_vector_of_polynomials(file_istr)
    compare_poly_vec(first.norm_to_diag,
                     pv_norm_to_diag,
                     "norm_to_diag",
                     grade=grade - 1)
    file_istr = open("hill_l1_18--diag_to_norm.vpol", 'r')
    pv_diag_to_norm = ringIO.read_sexp_vector_of_polynomials(file_istr)
    compare_poly_vec(first.diag_to_norm,
                     pv_diag_to_norm,
                     "diag_to_norm",
                     grade=grade - 1)
    print
    print "Reading mathematica data"
    n_ints = len(first.ints_to_freq)
    # get the frequencies to find the order of the planes
    order_f = [poly((0.0, ) * n_ints) for poly in first.ints_to_freq]
    second = NormalFormData(dir_name2,
                            order_f=order_f,
                            is_xxpp_format=True,
                            degree=grade)

    from Diagonal import Diagonalizer
    lie = LieAlgebra(n_ints)
    dia = Diagonalizer(lie)
    grade_ints = grade / 2
    dia.matrix_is_symplectic(array(first.diag_to_equi, Float))
    dia.matrix_is_symplectic(array(second.diag_to_equi, Float))
    dia.matrix_is_symplectic(array(first.equi_to_diag, Float))
    dia.matrix_is_symplectic(array(second.equi_to_diag, Float))

    # For the case develloped, Hill, there is a 45deg rotation between the
    # diagonalised coordinates in each of the centre planes. Thus:
    # These matrices are different
    #compare_matrix(dia, first.diag_to_equi, second.diag_to_equi, "diag_to_equi")
    #compare_matrix(dia, first.equi_to_diag, second.equi_to_diag, "equi_to_diag")
    # We neeed to convert between the diagonal planes and back to
    # compare the nonlinear normalisation plolynomials
    # second.diag_to_first.diag = first.diag_in_terms_of_second.diag =
    fd_in_sd = dia.matrix_as_vector_of_row_polynomials(
        matrixmultiply(array(first.equi_to_diag, Float),
                       array(second.diag_to_equi, Float)))
    sd_in_fd = dia.matrix_as_vector_of_row_polynomials(
        matrixmultiply(array(second.equi_to_diag, Float),
                       array(first.diag_to_equi, Float)))

    print
    print "Comparing mathematica data with cpp files upto grade %d" % (grade -
                                                                       1)
    compare_poly_vec(pv_norm_to_diag,
                     poly_vec_substitute(
                         fd_in_sd,
                         poly_vec_substitute(
                             poly_vec_isograde(second.norm_to_diag, grade - 1),
                             sd_in_fd)),
                     "norm_to_diag",
                     grade=grade - 1)
    print "Comparing mathematica data with cpp files upto grade %d" % (grade -
                                                                       1)
    compare_poly_vec(pv_diag_to_norm,
                     poly_vec_substitute(
                         fd_in_sd,
                         poly_vec_substitute(
                             poly_vec_isograde(second.diag_to_norm, grade - 1),
                             sd_in_fd)),
                     "diag_to_norm",
                     grade=grade - 1)

    print
    print "Comparing mathematica data with python upto grade %d" % (grade)

    compare_poly(first.equi_to_tham,
                 second.equi_to_tham,
                 "equi_to_tham",
                 grade=grade)
    compare_poly_vec(first.ints_to_freq,
                     second.ints_to_freq,
                     "ints_to_freq",
                     grade=grade_ints - 1)
    ring_ints = PolynomialRing(second.ints_to_tham.n_vars())
    poly_2 = ring_ints.isograde(second.ints_to_tham, 0, up_to=grade_ints + 1)
    compare_poly(first.ints_to_tham, poly_2, "ints_to_tham")
    compare_poly_vec(first.norm_to_ints,
                     second.norm_to_ints,
                     "norm_to_ints",
                     grade=grade)

    second.diag_to_norm = poly_vec_isograde(second.diag_to_norm, grade)
    second.norm_to_diag = poly_vec_isograde(second.norm_to_diag, grade)
    compare_poly_vec(first.norm_to_diag,
                     poly_vec_substitute(
                         fd_in_sd,
                         poly_vec_substitute(second.norm_to_diag, sd_in_fd)),
                     "norm_to_diag",
                     grade=grade - 1)
    compare_poly_vec(first.diag_to_norm,
                     poly_vec_substitute(
                         fd_in_sd,
                         poly_vec_substitute(second.diag_to_norm, sd_in_fd)),
                     "diag_to_norm",
                     grade=grade - 1)
    compare_poly_vec(first.diag_to_norm,
                     second.diag_to_norm,
                     "diag_to_norm",
                     grade=grade - 1)
    compare_poly_vec(first.diag_to_norm,
                     poly_vec_substitute(
                         fd_in_sd,
                         poly_vec_substitute(second.diag_to_norm, sd_in_fd)),
                     "diag_to_norm",
                     grade=grade)
    compare_poly_vec(first.equi_to_tvec,
                     second.equi_to_tvec,
                     "equi_to_tvec",
                     grade=grade - 1)
class Hill:
    
    def __init__(self, max_grade):
        dof = 3
        self.alg = LieAlgebra(dof)
        self.h = self.alg.isograde(self.hill_about_l1(), 0, max_grade+1)
        self.h_dc = self.diagonalize(self.alg, self.h)
        self.h_dr = self.h_dc.substitute(self.sub_r_into_c)
        self.k_dc = self.normalize_to_grade(max_grade)
        self.k_dr = self.k_dc.substitute(self.sub_r_into_c)

    def hill_about_l1(self):
        #print 'reading hill hamiltonian for test...'
        in_name = '../../test/ma-files/hill_l1_18_equi_to_tham.pol'
        in_file = open(in_name, 'r')
        h = read_ascii_polynomial(in_file, is_xxpp_format=1)
        in_file.close()
        #print 'done'
        terms = {Powers((2, 0, 0, 0, 0, 0)): -4.0, #x^2
                 Powers((0, 0, 2, 0, 0, 0)): +2.0, #y^2
                 Powers((0, 0, 0, 0, 2, 0)): +2.0, #z^2
                 Powers((0, 2, 0, 0, 0, 0)): +0.5, #px^2
                 Powers((0, 0, 0, 2, 0, 0)): +0.5, #py^2
                 Powers((0, 0, 0, 0, 0, 2)): +0.5, #pz^2
                 Powers((1, 0, 0, 1, 0, 0)): -1.0, #xpy
                 Powers((0, 1, 1, 0, 0, 0)): +1.0} #ypx
        assert len(terms) == 8
        h_2 = self.alg.polynomial(terms)
        assert (h_2 == self.alg.isograde(h, 2))
        return h

    def diagonalize(self, dof, h):
        tolerance = 5.0e-15

        self.diag = Diagonalizer(self.alg)
        self.eig = self.diag.compute_eigen_system(h, tolerance)
        self.diag.compute_diagonal_change()

        mat = self.diag.get_matrix_diag_to_equi()
        assert self.diag.matrix_is_symplectic(mat)
        
        sub_diag_into_equi = self.diag.matrix_as_vector_of_row_polynomials(mat)
        h_diag = h.substitute(sub_diag_into_equi)

        self.eq_type = self.eig.get_equilibrium_type()
        self.comp = Complexifier(self.alg, self.eq_type)
        self.sub_c_into_r = self.comp.calc_sub_complex_into_real()
        self.sub_r_into_c = self.comp.calc_sub_real_into_complex()
        h_comp = h_diag.substitute(self.sub_c_into_r)

        h_comp = h_comp.with_small_coeffs_removed(tolerance)
        assert (self.alg.is_diagonal_polynomial(self.alg.isograde(h_comp, 2)))

        return h_comp

    def normalize_to_grade(self, max_grade):
        steps = max_grade
        h_dc = self.alg.isograde(self.h_dc, 2, max_grade+1)
        h_dc_2 = self.alg.isograde(h_dc, 2)
        k_comp = self.alg.zero()
        w_comp = self.alg.zero()
        #the following is not very efficient for separating grades!
        h_list = [self.alg.isograde(h_dc, i + 2) for i in xrange(0, steps + 1)]
        nf = LieTriangle(self.alg, h_dc_2)
        for i in xrange(0, steps + 1):
            h_term = h_list[i]
            k_term, w_term = nf.compute_normal_form_and_generating_function(h_term)
            k_comp += k_term
            w_comp += w_term

        #print k_comp
        k_real = k_comp.substitute(self.sub_r_into_c)
        assert (k_real.imag().l_infinity_norm() < 1.0e-14)
        k_real = k_real.real()

        return k_comp
Exemplo n.º 45
0
class CanonicalChange(unittest.TestCase):

    def setUp(self):

        """Set up an example from Hill's equations."""

        x_2 = Powers((2, 0, 0, 0, 0, 0))
        px2 = Powers((0, 2, 0, 0, 0, 0))
        y_2 = Powers((0, 0, 2, 0, 0, 0))
        py2 = Powers((0, 0, 0, 2, 0, 0))
        z_2 = Powers((0, 0, 0, 0, 2, 0))
        pz2 = Powers((0, 0, 0, 0, 0, 2))
        xpy = Powers((1, 0, 0, 1, 0, 0))
        ypx = Powers((0, 1, 1, 0, 0, 0))
        terms = {px2: 0.5, py2: 0.5, pz2: 0.5,
                 xpy: -1.0, ypx: 1.0,
                 x_2: -4.0, y_2: 2.0, z_2: 2.0}
        assert len(terms) == 8

        self.h_2 = Polynomial(6, terms=terms)
        self.lie = LieAlgebra(3)
        self.diag = Diagonalizer(self.lie)
        self.eq_type = 'scc'
        e = []
        e.append(+sqrt(2.0*sqrt(7.0)+1.0))
        e.append(-e[-1])
        e.append(complex(0.0, +sqrt(2.0*sqrt(7.0)-1.0)))
        e.append(-e[-1])
        e.append(complex(0.0, +2.0))
        e.append(-e[-1])
        self.eig_vals = e

    def test_basic_matrix(self):

        """This test is rather monolithic, but at least it implements
        a concrete example that we can compare with our earlier
        computations.  It also tests the mutual-inverse character of
        the equi-to-diag and diag-to-equi transformations."""

        tolerance = 5.0e-15
        eig = self.diag.compute_eigen_system(self.h_2, tolerance)
        self.diag.compute_diagonal_change()

        eq_type = eig.get_equilibrium_type()
        self.assertEquals(eq_type, self.eq_type)

        eigs = [pair.val for pair in eig.get_raw_eigen_value_vector_pairs()]
        for actual, expected in zip(eigs, self.eig_vals):
            self.assert_(abs(actual-expected) < tolerance, (actual, expected))

        mat = self.diag.get_matrix_diag_to_equi()
        assert self.diag.matrix_is_symplectic(mat)

        sub_diag_into_equi = self.diag.matrix_as_vector_of_row_polynomials(mat)
        mat_inv = LinearAlgebra.inverse(MLab.array(mat))
        sub_equi_into_diag = self.diag.matrix_as_vector_of_row_polynomials(mat_inv)
        h_diag_2 = self.h_2.substitute(sub_diag_into_equi)
        h_2_inv = h_diag_2.substitute(sub_equi_into_diag)
        self.assert_(h_2_inv) #non-zero
        self.assert_(not h_2_inv.is_constant())
        self.assert_(self.lie.is_isograde(h_2_inv, 2))
        self.assert_((self.h_2-h_2_inv).l1_norm() < 1.0e-14)
        comp = Complexifier(self.diag.get_lie_algebra(), eq_type)
        sub_complex_into_real = comp.calc_sub_complex_into_real()
        h_comp_2 = h_diag_2.substitute(sub_complex_into_real)
        h_comp_2 = h_comp_2.with_small_coeffs_removed(tolerance)
        self.assert_(self.lie.is_diagonal_polynomial(h_comp_2))