def test_sedov_timmes_vs_kamm(self):
        r"""Checks Timmes' against Kamm's Sedov solver. Expected to fail because
        Kamm solver does not return correct values at shock for this choice of
        parameters.
        """

        # construct spatial grid and choose time
        nmax = 11
        rmin = 0.95
        rmax = 1.05
        r = np.linspace(rmin, rmax, nmax)
        t = 1.
        solvertimmes = SedovTimmes(geometry=3, eblast=0.851072)
        solutiontimmes = solvertimmes(r, t)
        solverkamm = SedovKamm(geometry=3, eblast=0.851072)
        solutionkamm = solverkamm(r, t)
        tolerance = 4.e-4
        for i in range(nmax):
            self.assertAlmostEqual(solutiontimmes.density[i],
                                   solutionkamm.density[i],
                                   delta=tolerance)
            self.assertAlmostEqual(solutiontimmes.velocity[i],
                                   solutionkamm.velocity[i],
                                   delta=tolerance)
            self.assertAlmostEqual(solutiontimmes.pressure[i],
                                   solutionkamm.pressure[i],
                                   delta=tolerance)
    def test_interpolate(self):
        r"""Sedov test: interpolation to large number of points.
        """

        # construct spatial grid and choose time
        rmax = 1.2
        t = 1.
        solver = SedovTimmes(eblast=0.851072, gamma=1.4)
        #
        # Solve for small number of points
        r_small = np.linspace(0.0, rmax, 501)
        solution_small = solver(r_small, t)
        #
        # Solve for large number of points
        r_big = np.linspace(0.0, rmax, 6001)
        solution_big = solver(r_big, t)

        #  Interpolate small to big

        from scipy.interpolate import interp1d

        interpfcn = interp1d(r_small, solution_small.density)

        solution_big_interp = interpfcn(r_big)

        err = np.linalg.norm((solution_big_interp - solution_big.density), 1)

        self.assertTrue(err < 16.0)
示例#3
0
    def test_sedov_timmes_vs_kamm(self):
        r"""Checks Timmes' against Kamm's Sedov solver. 
        """

        # construct spatial grid and choose time
        nmax = 101
        rmin = 0.6
        rmax = 1.0
        r = np.linspace(rmin, rmax, nmax)
        t = 1.
        solvertimmes = SedovTimmes(geometry=3, eblast=0.851072)
        solutiontimmes = solvertimmes(r, t)
        solverkamm = SedovKamm(geometry=3, eblast=0.851072)
        solutionkamm = solverkamm(r, t)
        tolerance = 4.e-4
        for i in range(
                nmax - 1
        ):  # note: there is disagreement at nmax: 5.9999965521597574 != 0.0 for range(nmax)
            self.assertAlmostEqual(solutiontimmes.density[i],
                                   solutionkamm.density[i],
                                   delta=tolerance)
            self.assertAlmostEqual(solutiontimmes.velocity[i],
                                   solutionkamm.velocity[i],
                                   delta=tolerance)
            self.assertAlmostEqual(solutiontimmes.pressure[i],
                                   solutionkamm.pressure[i],
                                   delta=tolerance)
示例#4
0
    def test_shock_state(self):
        """Tests density, velocity, pressure, specific internal energy, and
        sound speed.
        """

        # construct spatial grid and choose time
        rmax = 1.2
        r = np.linspace(0.0, rmax, 101)
        t = 1.
        solver = SedovTimmes(eblast=0.851072, gamma=1.4)
        solution = solver(r, t)

        i = 84  # shock location
        self.assertAlmostEqual(solution.density[i - 1], 5.52681913398)
        self.assertAlmostEqual(solution.density[i], 1.0000000E+00)
        self.assertAlmostEqual(solution.velocity[i - 1], 0.330465254524)
        self.assertAlmostEqual(solution.velocity[i], 0.0)
        self.assertAlmostEqual(solution.pressure[i - 1], 0.127634037837)
        self.assertAlmostEqual(solution.pressure[i], 1.4E-22)
        self.assertAlmostEqual(solution.sie[i - 1], 0.0577339491049)
        self.assertAlmostEqual(solution.sie[i], 0.0)
        self.assertAlmostEqual(solution.sound[i - 1], 0.179808263155)
        self.assertAlmostEqual(solution.sound[i], 0.0)
class TestSedovTimmesShock(unittest.TestCase):
    """Tests Timmes Sedov for correct pre and post shock values.
    """
    # construct spatial grid and choose time
    rmax = 1.2
    r = np.linspace(0.0, rmax, 121)
    t = 1.
    solver = SedovTimmes(eblast=0.851072, gamma=1.4)
    solution = solver(r, t)

    ishock = 100  # shock location

    # analytic solution pre-shock (initial conditions)

    analytic_preshock = {
        'position': r[ishock + 1],
        'density': 1.0,
        'specific_internal_energy': 0.0,
        'pressure': 0.0,
        'velocity': 0.0,
        'sound_speed': 0.0
    }

    # analytic solution  at the shock, from Kamm & Timmes 2007,
    # equations 13-18 (to 6 significant figures)

    analytic_postshock = {
        'position': 1.0,
        'density': 6.0,
        'specific_internal_energy': 5.5555e-2,
        'pressure': 1.33333e-1,
        'velocity': 3.33333e-1,
        'sound_speed': 1.76383e-1
    }

    def test_preshock_state(self):
        """Tests density, velocity, pressure, specific internal energy, and
        sound speed immediately before the shock.
        """

        for ikey in self.analytic_preshock.keys():
            self.assertAlmostEqual(self.solution[ikey][self.ishock + 1],
                                   self.analytic_preshock[ikey],
                                   places=5)

    def test_postshock_state(self):
        """Tests density, velocity, pressure, specific internal energy, and
        sound speed immediately after the shock.
        """

        for ikey in self.analytic_postshock.keys():
            self.assertAlmostEqual(self.solution[ikey][self.ishock],
                                   self.analytic_postshock[ikey],
                                   places=5)

    def test_interpolate(self):
        r"""Sedov test: interpolation to large number of points.
        """

        # construct spatial grid and choose time
        rmax = 1.2
        t = 1.
        solver = SedovTimmes(eblast=0.851072, gamma=1.4)
        #
        # Solve for small number of points
        r_small = np.linspace(0.0, rmax, 501)
        solution_small = solver(r_small, t)
        #
        # Solve for large number of points
        r_big = np.linspace(0.0, rmax, 6001)
        solution_big = solver(r_big, t)

        #  Interpolate small to big

        from scipy.interpolate import interp1d

        interpfcn = interp1d(r_small, solution_small.density)

        solution_big_interp = interpfcn(r_big)

        err = np.linalg.norm((solution_big_interp - solution_big.density), 1)

        self.assertTrue(err < 16.0)

    def test_geometry_assignment(self):
        r"""Sedov test: geometry assignment.
        """
        self.assertRaises(ValueError, SedovTimmes, geometry=-1)
示例#6
0
plt.xlabel('Position (cm)')
plt.ylabel('Pressure (erg/cc)')
plt.grid(True)
plt.gca().legend().set_visible(False)

plt.tight_layout()
fig.subplots_adjust(top=0.85)  # Makes room for suptitle
#plt.savefig('fig08doebling.pdf')

if timmes_import:

    #
    # Figure 8timmes: Standard test cases, Timmes Solver
    #

    solver_timmes_pla = SedovTimmes(geometry=1, eblast=0.0673185, gamma=1.4)
    solution_timmes_pla = solver_timmes_pla(r=rvec, t=t)

    solver_timmes_cyl = SedovTimmes(geometry=2, eblast=0.311357, gamma=1.4)
    solution_timmes_cyl = solver_timmes_cyl(r=rvec, t=t)

    solver_timmes_sph = SedovTimmes(geometry=3, eblast=0.851072, gamma=1.4)
    solution_timmes_sph = solver_timmes_sph(r=rvec, t=t)

    fig = plt.figure(figsize=(10, 10))
    plt.suptitle(
        '''Sedov solutions for $\gamma=1.4$, standard cases, Timmes solver.
        Compare to Fig. 8 from Kamm & Timmes 2007''')

    plt.subplot(221)
    solution_timmes_pla.plot('density')