Ejemplo n.º 1
0
    def run(self, w0, H):
        c = self.config

        # return dict
        result = self._empty_result

        # get timestep and nsteps for integration
        try:
            dt, nsteps = estimate_dt_n_steps(
                w0,
                H,
                n_periods=c.n_periods,
                n_steps_per_period=c.n_steps_per_period,
                func=np.nanmin,
                Integrator=gi.DOPRI853Integrator)
        except RuntimeError:
            result['error_code'] = 2
            return result
        except:
            result['error_code'] = 9
            return result

        # integrate orbit
        logger.debug("Integrating orbit with dt={0}, nsteps={1}".format(
            dt, nsteps))
        try:
            orbit = H.integrate_orbit(w0,
                                      dt=dt,
                                      n_steps=nsteps,
                                      Integrator=gi.DOPRI853Integrator,
                                      Integrator_kwargs=dict(atol=1E-11))
        except RuntimeError:  # ODE integration failed
            logger.warning("Orbit integration failed.")
            dEmax = 1E10
        else:
            logger.debug(
                'Orbit integrated successfully, checking energy conservation...'
            )

            # check energy conservation for the orbit
            E = orbit.energy()
            dEmax = np.max(np.abs((E[1:] - E[0]) / E[0]))
            logger.debug('max(∆E) = {0:.2e}'.format(dEmax))

        if dEmax > c.energy_tolerance:
            result['error_code'] = 4
            result['dE_max'] = dEmax
            return result

        # start finding the frequencies -- do first half then second half
        sf1 = SuperFreq(orbit.t[:nsteps // 2 + 1].value, p=c.hamming_p)
        sf2 = SuperFreq(orbit.t[nsteps // 2:].value, p=c.hamming_p)

        # classify orbit full orbit
        circ = orbit.circulation()
        is_tube = np.any(circ)

        # define slices for first and second parts
        sl1 = slice(None, nsteps // 2 + 1)
        sl2 = slice(nsteps // 2, None)

        if is_tube and not c.force_cartesian:
            # first need to flip coordinates so that circulation is around z axis
            new_orbit = orbit.align_circulation_with_z(circ)
            fs1 = orbit_to_poincare_polar(new_orbit[sl1])
            fs2 = orbit_to_poincare_polar(new_orbit[sl2])

        else:  # box
            ws = orbit.w()
            fs1 = [(ws[j, sl1] + 1j * ws[j + 3, sl1]) for j in range(3)]
            fs2 = [(ws[j, sl2] + 1j * ws[j + 3, sl2]) for j in range(3)]

        logger.debug("Running SuperFreq on the orbits")
        try:
            freqs1, d1, ixs1 = sf1.find_fundamental_frequencies(
                fs1, nintvec=c.n_intvec)
            freqs2, d2, ixs2 = sf2.find_fundamental_frequencies(
                fs2, nintvec=c.n_intvec)
        except:
            result['error_code'] = 5
            return result

        result['freqs'] = np.vstack((freqs1, freqs2))
        result['dE_max'] = dEmax
        result['is_tube'] = float(is_tube)
        result['dt'] = float(dt)
        result['nsteps'] = nsteps
        result['amps'] = np.vstack((d1['|A|'][ixs1], d2['|A|'][ixs2]))
        result['success'] = True
        result['error_code'] = 1
        return result
Ejemplo n.º 2
0
# -*- coding: utf-8 -*-
"""
Created on Sun May 17 15:31:44 2020

@author: BrianTCook
"""

import numpy as np
import glob
import matplotlib.pyplot as plt
from superfreq import SuperFreq, find_frequencies

datadir_AMUSE = '/Users/BrianTCook/Desktop/Thesis/second_project_gcs/Enbid-2.0/AMUSE_data/'

t = np.linspace(0., 100., 51)  #0 to 100 Myr only saving every 2 Myr
sf = SuperFreq(t)

logN_max = 6
simulation_tags = [2**i for i in range(1, logN_max + 1)]

plt.rc('text', usetex=True)
plt.rc('font', family='serif')

plt.figure()

nstars_clusterzero = 1096
nstars_clusterone = 300

end_index = nstars_clusterzero + nstars_clusterone

for i, tag in enumerate(simulation_tags):