Exemplo n.º 1
0
def updateCrossSections(cx, hydro, slopes, e_rad):

    # loop over cells
    for i in xrange(len(cx)):

        # get edge stuff
        state_avg = hydro[i]
        spec_heat = state_avg.spec_heat
        gamma = state_avg.gamma

        # compute edge quantities
        rho = computeEdgeDensities(i, state_avg, slopes)
        u = computeEdgeVelocities(i, state_avg, slopes)
        e = e_rad[i]

        # loop over edges and create state for each edge
        for edge in [0, 1]:

            # create edge state
            state = HydroState(rho=rho[edge],
                               u=u[edge],
                               e=e[edge],
                               spec_heat=spec_heat,
                               gamma=gamma)

            # update edge cross section
            cx[i][edge].updateCrossX(state)
Exemplo n.º 2
0
def computeAnalyticHydroSolution(mesh, t, rho, u, E, cv, gamma):

    hydro = list()
    for i in xrange(mesh.n_elems):

        # get cell center
        #  x_i = mesh.getElement(i).x_cent

        # evaluate functions at cell center
        #  rho_i = rho(x=x_i, t=t)
        #  u_i   =   u(x=x_i, t=t)
        #  E_i   =   E(x=x_i, t=t)
        x_l = mesh.getElement(i).xl
        x_r = mesh.getElement(i).xr
        rho_i = evalAverageSource(rho, x_l, x_r, t)
        u_i = evalAverageSource(u, x_l, x_r, t)
        E_i = evalAverageSource(E, x_l, x_r, t)

        # add hydro state for cell
        hydro.append(
            HydroState(rho=rho_i, u=u_i, E=E_i, spec_heat=cv, gamma=gamma))

    return hydro
Exemplo n.º 3
0
    def test_RadHydroShock(self):

        # create uniform mesh
        n_elems = 500
        width = 0.04
        x_start = -0.02
        mesh_center = x_start + 0.5 * width
        mesh = Mesh(n_elems, width, x_start=x_start)

        # slope limiter
        slope_limiter = "double-minmod"

        # gamma constant
        gam = 5.0 / 3.0

        # material 1 and 2 properties;
        T_ref = 0.1  #keV reference unshocked, upstream, ambient, equilibrium

        sig_a1 = 577.35
        sig_s1 = 0.0
        c_v1 = 0.14472799784454
        sig_a2 = sig_a1
        sig_s2 = sig_s1
        c_v2 = c_v1

        #Read in Jim's nondimensional results to set preshock and postshock dimensional
        mach_number = "1.2"  #Choices are 2.0, 1.2, 3.0, 5.0
        filename = 'analytic_shock_solutions/data_for_M%s.pickle' % mach_number
        f = open(filename, 'r')
        data = pickle.load(f)
        f.close()

        #compute scalings based on an assumed density and reference temperature
        dp = getDimensParams(T_ref=T_ref, rho_ref=1.0, C_v=c_v1, gamma=gam)

        print data

        #Scale non-dimensional values into dimensional results
        rho1 = data['Density'][0] * dp['rho']
        u1 = data['Speed'][0] * dp['a']  #velocity times reference sound speed
        Erad1 = data['Er'][0] * dp['Er']
        T1 = data['Tm'][0] * dp["Tm"]
        e1 = T1 * c_v1
        E1 = rho1 * (e1 + 0.5 * u1 * u1)

        # material 2 IC
        rho2 = data['Density'][-1] * dp['rho']
        u2 = data['Speed'][-1] * dp['a']  #velocity times reference sound speed
        Erad2 = data['Er'][-1] * dp['Er']
        T2 = data['Tm'][-1] * T_ref
        e2 = T2 * c_v2
        E2 = rho2 * (e2 + 0.5 * u2 * u2)

        print r"$\rho$ & %0.8e & %0.8e & g cm$^{-3}$ \\" % (rho1, rho2)
        print r"$u$ & %0.8e & %0.8e & cm sh$^{-1}$ \\" % (u1, u2)
        print r"$T$ & %0.8e & %0.8e & keV \\" % (T1, T2)
        print r"$E$ & %0.8e & %0.8e & Jks cm$^{-3}$\\" % (E1, E2)
        print r"$E_r$ & %0.8e & %0.8e & Jks cm$^{-3}$ \\" % (Erad1, Erad2)
        print r"$F_r$ & %0.8e & %0.8e & Jks cm$^{-2}$ s$^{-1}$ \\" % (0.0, 0.0)
        print r"vel", u1, "&", u2
        print "Temperature", T1, "&", T2
        print "momentum", rho1 * u1, "&", rho2 * u2
        print "E", E1, "&", E2
        print "E_r", Erad1, "&", Erad2
        print sig_a1, sig_s1
        exit()
        # material 1 IC

        # final time
        t_end = 0.8

        # temperature plot filename
        test_filename = "radshock_mach_" + re.search(
            "M(\d\.\d)", filename).group(1) + ".pdf"

        # compute radiation BC; assumes BC is independent of time
        c = GC.SPD_OF_LGT
        psi_left = 0.5 * c * Erad1
        psi_right = 0.5 * c * Erad2

        #Create BC object
        rad_BC = RadBC(mesh,
                       "dirichlet",
                       psi_left=psi_left,
                       psi_right=psi_right)

        # construct cross sections and hydro IC
        cross_sects = list()
        hydro_IC = list()
        psi_IC = list()

        for i in range(mesh.n_elems):

            if mesh.getElement(i).x_cent < mesh_center:  # material 1
                cross_sects.append(
                    (ConstantCrossSection(sig_s1, sig_s1 + sig_a1),
                     ConstantCrossSection(sig_s1, sig_s1 + sig_a1)))
                hydro_IC.append(
                    HydroState(u=u1, rho=rho1, e=e1, spec_heat=c_v1,
                               gamma=gam))

                psi_IC += [psi_left for dof in range(4)]

            else:  # material 2
                cross_sects.append(
                    (ConstantCrossSection(sig_s2, sig_a2 + sig_s2),
                     ConstantCrossSection(sig_s2, sig_a2 + sig_s2)))
                hydro_IC.append(
                    HydroState(u=u2, rho=rho2, e=e2, spec_heat=c_v2,
                               gamma=gam))

                psi_IC += [psi_right for dof in range(4)]

        #Convert pickle data to dimensional form
        data['Density'] *= dp['rho']
        data['Speed'] *= dp['a']
        data['Er'] *= dp['Er']
        data['Tm'] *= dp['Tm']
        x_anal = data['x']

        #If desired initialize the solutions to analytic result (ish)
        analytic_IC = False
        if analytic_IC:

            hydro_IC = list()
            psi_IC = list()

            for i in range(mesh.n_elems):

                #Determine which analytic x is closest to cell center
                xcent = mesh.getElement(i).x_cent
                min_dist = 9001.
                idx = -1
                for j in range(len(x_anal)):
                    if abs(xcent - x_anal[j]) < min_dist:
                        min_dist = abs(xcent - x_anal[j])
                        idx = j

                #Create state based on these values, noting that the pickle has already
                #been dimensionalized
                rho1 = data['Density'][idx]
                u1 = data['Speed'][idx]  #velocity times reference sound speed
                Erad1 = data['Er'][idx]
                T1 = data['Tm'][idx]
                e1 = T1 * c_v1
                E1 = rho1 * (e1 + 0.5 * u1 * u1)
                psi_left = 0.5 * c * Erad1

                hydro_IC.append(
                    HydroState(u=u1, rho=rho1, e=e1, spec_heat=c_v1,
                               gamma=gam))

                psi_IC += [psi_left for dof in range(4)]

        #Smooth out the middle solution optionally, shouldnt need this
        n_smoothed = 0
        state_l = hydro_IC[0]
        state_r = hydro_IC[-1]

        rho_l = state_l.rho
        rho_r = state_r.rho
        drho = rho_r - rho_l
        u_l = state_l.u
        u_r = state_r.u
        du = u_r - u_l
        e_l = state_l.e
        e_r = state_r.e
        de = e_r - e_l
        print "p", state_l.p, state_r.p
        print "mach number", state_l.u / state_l.getSoundSpeed(
        ), state_r.u / state_r.getSoundSpeed()

        #Scale
        idx = 0
        if n_smoothed > 0:
            for i in range(mesh.n_elems / 2 - n_smoothed / 2 - 1,
                           mesh.n_elems / 2 + n_smoothed / 2):

                rho = rho_l + drho * idx / n_smoothed
                u = rho_l * u_l / rho
                e = e_l + de * idx / n_smoothed

                idx += 1

                E = 0.5 * rho * u * u + rho * e
                hydro_IC[i].updateState(rho, rho * u, E)

        # plot hydro initial conditions
        plotHydroSolutions(mesh, hydro_IC)

        rad_IC = Radiation(psi_IC)

        # create hydro BC
        hydro_BC = HydroBC(bc_type='fixed',
                           mesh=mesh,
                           state_L=state_l,
                           state_R=state_r)
        #Forcing to reflective? Maybe this is the problem
        hydro_BC = HydroBC(mesh=mesh, bc_type='reflective')

        # transient options
        t_start = 0.0

        # if run standalone, then be verbose
        if __name__ == '__main__':
            verbosity = 2
        else:
            verbosity = 0

        # run the rad-hydro transient
        rad_new, hydro_new = runNonlinearTransient(mesh=mesh,
                                                   problem_type='rad_hydro',
                                                   dt_option='CFL',
                                                   CFL=0.6,
                                                   use_2_cycles=True,
                                                   t_start=t_start,
                                                   t_end=t_end,
                                                   rad_BC=rad_BC,
                                                   cross_sects=cross_sects,
                                                   rad_IC=rad_IC,
                                                   hydro_IC=hydro_IC,
                                                   hydro_BC=hydro_BC,
                                                   verbosity=verbosity,
                                                   slope_limiter=slope_limiter,
                                                   check_balance=False)

        # plot
        if __name__ == '__main__':

            # compute exact hydro solution
            hydro_exact = None

            # plot hydro solution
            plotHydroSolutions(mesh,
                               hydro_new,
                               exact=hydro_exact,
                               pickle_dic=data)

            # plot material and radiation temperatures
            Tr_exact, Tm_exact = plotTemperatures(mesh,
                                                  rad_new.E,
                                                  hydro_states=hydro_new,
                                                  print_values=True,
                                                  save=True,
                                                  filename=test_filename,
                                                  pickle_dic=data)

            # plot angular fluxes
            plotS2Erg(mesh, rad_new.psim, rad_new.psip)

            #Make a pickle to save the error tables
            pickname = "results/testJimsShock_M%s_%ielems.pickle" % (
                mach_number, n_elems)

            #Create dictionary of all the data
            big_dic = {}
            big_dic["hydro"] = hydro_new
            big_dic["hydro_exact"] = hydro_exact
            big_dic["rad"] = rad_new
            big_dic["Tr_exact"] = Tr_exact
            big_dic["Tm_exact"] = Tm_exact
            pickle.dump(big_dic, open(pickname, "w"))
Exemplo n.º 4
0
    def test_RadHydroShock(self):

        # test case
        test_case = "marcho3"  # mach1.2 mach2 mach50

        # create uniform mesh
        n_elems = 1000
        width = 0.04
        x_start = -0.02
        mesh_center = x_start + 0.5 * width
        mesh = Mesh(n_elems, width, x_start=x_start)

        # slope limiter
        slope_limiter = "double-minmod"

        # gamma constant
        gam = 5.0 / 3.0

        # material 1 and 2 properties: Table 6.1
        sig_a1 = 390.71164263502122
        sig_s1 = 853.14410158161809 - sig_a1
        c_v1 = 0.12348
        sig_a2 = sig_a1
        sig_s2 = sig_s1
        c_v2 = c_v1

        if not (test_case == "mach2" or test_case == "marcho3"):

            raise NotImplementedError("All but mach2 and marcho3 shock may have wrong input"\
                    "values. Need to check Jarrod Ewards thesis, starting with Table 6.1")

        if test_case == "mach1.2":  # Mach 1.2 problem: Table 6.2

            # material 1 IC
            rho1 = 1.0
            E1 = 2.2226400000000000e-02
            u1 = 1.4055888445772469e-01
            e1 = E1 / rho1 - 0.5 * u1 * u1
            Erad_left = 1.372E-06

            # material 2 IC
            rho2 = 1.2973213452231311
            E2 = 2.6753570531538713e-002
            u2 = 1.0834546504247138e-001
            e2 = E2 / rho2 - 0.5 * u2 * u2
            Erad_right = 2.7955320762182542e-06

            # final time
            t_end = 0.5

            # temperature plot filename
            test_filename = "radshock_mach1.2.pdf"

            # temperature plot exact solution filename
            exact_solution_filename = "mach1.2_exact_solution.csv"

        elif test_case == "mach2":  # Mach 2 problem: Table 6.3

            # material 1 IC
            rho1 = 1.0
            E1 = 3.9788000000000004e-002
            u1 = 2.3426480742954117e-001
            e1 = E1 / rho1 - 0.5 * u1 * u1
            T1 = e1 / c_v1
            Erad_left = 1.372E-06

            # material 2 IC
            rho2 = 2.2860748989303659e+000
            E2 = 7.0649692950433357e-002
            u2 = 1.0247468599526272e-001
            e2 = E2 / rho2 - 0.5 * u2 * u2
            T2 = e2 / c_v2
            Erad_right = 2.5560936967521927e-005

            print "rho", rho1, rho2
            print "vel", u1, u2
            print "Temperature", T1, T2
            print "momentum", rho1 * u1, rho2 * u2
            print "E", E1, E2
            print "E_r", Erad_left, Erad_right
            print sig_a1, sig_s1

            # final time
            t_end = 1.0

            # temperature plot output filename
            test_filename = "radshock_mach2.pdf"

            # temperature plot exact solution filename
            exact_solution_filename = "marcho2_exact_solution.csv"

        elif test_case == "mach50":  # Mach 50 problem: Table 6.4

            raise NotImplementedError("Mach 50 test requires negativity monitoring," \
               + "which is not yet implemented.")

            # material 1 IC
            rho1 = 1.0
            E1 = 1.7162348000000001e+001
            u1 = 5.8566201857385289e+000
            e1 = E1 / rho1 - 0.5 * u1 * u1
            Erad_left = 1.372E-06

            # material 2 IC
            rho2 = 6.5189217901173153e+000
            E2 = 9.5144308747326214e+000
            u2 = 8.9840319830453630e-001
            e2 = E2 / rho2 - 0.5 * u2 * u2
            Erad_right = 7.3372623010289956e+001

            # final time
            t_end = 1.5

            # temperature plot filename
            test_filename = "radshock_mach50.pdf"

            # temperature plot exact solution filename
            exact_solution_filename = "mach50_exact_solution.csv"

        elif test_case == "marcho2":

            # material 1 IC
            rho1 = 1.0
            u1 = 0.23426480742954117
            T1 = 1.219999999999999973e-01
            e1 = T1 * c_v2
            E1 = 0.5 * rho1 * u1 * u1 + e1 * rho1
            Erad_left = 3.039477120074432e-06

            # material 2 IC
            rho2 = 2.286074898930029242
            u2 = 0.10247468599526272
            T2 = 2.534635394302977573e-01
            e2 = T2 * c_v2
            E2 = 0.5 * rho2 * u2 * u2 + e2 * rho2
            Erad_right = 5.662673693907908e-05

            print "rho", rho1, rho2
            print "vel", u1, u2
            print "Temperature", T1, T2
            print "momentum", rho1 * u1, rho2 * u2
            print "E", E1, E2
            print "E_r", Erad_left, Erad_right

            # final time
            t_end = 0.10

            # temperature plot filename
            test_filename = "radshock_mach50.pdf"

            # temperature plot exact solution filename
            exact_solution_filename = "marcho2_exact_solution.csv"

        elif test_case == "marcho1.05":

            # material 1 IC
            rho1 = 1.0
            u1 = 0.1228902
            T1 = 0.1
            e1 = T1 * c_v2
            E1 = 0.5 * rho1 * u1 * u1 + e1 * rho1
            Erad_left = 1.372E-06

            # material 2 IC
            rho2 = 1.0749588
            u2 = rho1 * u1 / rho2
            T2 = 0.1049454
            e2 = T2 * c_v2
            E2 = 0.5 * rho2 * u2 * u2 + e2 * rho2
            Erad_right = 1.664211799256650E-06

            print "rho", rho1, rho2
            print "vel", u1, u2
            print "Temperature", T1, T2
            print "momentum", rho1 * u1, rho2 * u2
            print "E", E1, E2
            print "E_r", Erad_left, Erad_right

            # final time
            t_end = 1.0

            # temperature plot filename
            test_filename = "radshock_mach50.pdf"

            # temperature plot exact solution filename
            exact_solution_filename = "marcho1.05_exact_solution.csv"
            exact_solution_filename = None

        elif test_case == "marcho3":

            #new c_v and pure absorber cross sections
            c_v1 = 0.221804
            c_v2 = c_v1
            sig_a1 = 577.3502692
            sig_s1 = 0.
            sig_a2 = sig_a1
            sig_s2 = sig_s1

            # material 1 IC
            rho1 = 1.0
            mom1 = 0.5192549757
            u1 = mom1 / rho1
            T1 = 0.1215601363
            e1 = T1 * c_v1
            E1 = 0.5 * rho1 * u1 * u1 + e1 * rho1
            Erad_left = 2.995841442e-06

            # material 2 IC
            rho2 = 3.002167609
            u2 = rho1 * u1 / rho2
            T2 = 0.4451426103
            e2 = T2 * c_v2
            E2 = 0.5 * rho2 * u2 * u2 + e2 * rho2
            Erad_right = 0.0005387047241

            print "rho", rho1, rho2
            print "vel", u1, u2
            print "Temperature", T1, T2
            print "momentum", rho1 * u1, rho2 * u2
            print "E", E1, E2
            print "E_r", Erad_left, Erad_right

            # final time
            t_end = 1.0

            # temperature plot filename
            test_filename = "radshock_marcho3.pdf"

            # temperature plot exact solution filename
            exact_solution_filename = None

        else:
            raise NotImplementedError("Invalid test case")

        # compute radiation BC; assumes BC is independent of time
        c = GC.SPD_OF_LGT
        psi_left = 0.5 * c * Erad_left
        psi_right = 0.5 * c * Erad_right

        #Create BC object
        rad_BC = RadBC(mesh,
                       "dirichlet",
                       psi_left=psi_left,
                       psi_right=psi_right)

        # construct cross sections and hydro IC
        cross_sects = list()
        hydro_IC = list()
        psi_IC = list()

        for i in range(mesh.n_elems):

            if mesh.getElement(i).x_cent < mesh_center:  # material 1
                cross_sects.append(
                    (ConstantCrossSection(sig_s1, sig_s1 + sig_a1),
                     ConstantCrossSection(sig_s1, sig_s1 + sig_a1)))
                hydro_IC.append(
                    HydroState(u=u1, rho=rho1, e=e1, spec_heat=c_v1,
                               gamma=gam))

                psi_IC += [psi_left for dof in range(4)]

            else:  # material 2
                cross_sects.append(
                    (ConstantCrossSection(sig_s2, sig_a2 + sig_s2),
                     ConstantCrossSection(sig_s2, sig_a2 + sig_s2)))
                hydro_IC.append(
                    HydroState(u=u2, rho=rho2, e=e2, spec_heat=c_v2,
                               gamma=gam))

                psi_IC += [psi_right for dof in range(4)]

        #Smooth out the middle solution optionally, shouldnt need this
        n_smoothed = 0
        state_l = hydro_IC[0]
        state_r = hydro_IC[-1]

        rho_l = state_l.rho
        rho_r = state_r.rho
        drho = rho_r - rho_l
        u_l = state_l.u
        u_r = state_r.u
        du = u_r - u_l
        e_l = state_l.e
        e_r = state_r.e
        de = e_r - e_l
        print "p", state_l.p, state_r.p
        print "mach number", state_l.u / state_l.getSoundSpeed(
        ), state_r.u / state_r.getSoundSpeed()

        #Scale
        idx = 0
        if n_smoothed > 0:
            for i in range(mesh.n_elems / 2 - n_smoothed / 2 - 1,
                           mesh.n_elems / 2 + n_smoothed / 2):

                rho = rho_l + drho * idx / n_smoothed
                u = rho_l * u_l / rho
                e = e_l + de * idx / n_smoothed

                idx += 1

                E = 0.5 * rho * u * u + rho * e
                hydro_IC[i].updateState(rho, rho * u, E)

        # plot hydro initial conditions
        plotHydroSolutions(mesh, hydro_IC)

        rad_IC = Radiation(psi_IC)

        # create hydro BC
        hydro_BC = HydroBC(bc_type='fixed',
                           mesh=mesh,
                           state_L=state_l,
                           state_R=state_r)
        hydro_BC = HydroBC(mesh=mesh, bc_type='reflective')

        # transient options
        t_start = 0.0

        # if run standalone, then be verbose
        if __name__ == '__main__':
            verbosity = 2
        else:
            verbosity = 0

        # run the rad-hydro transient
        rad_new, hydro_new = runNonlinearTransient(mesh=mesh,
                                                   problem_type='rad_hydro',
                                                   dt_option='CFL',
                                                   CFL=0.6,
                                                   use_2_cycles=True,
                                                   t_start=t_start,
                                                   t_end=t_end,
                                                   rad_BC=rad_BC,
                                                   cross_sects=cross_sects,
                                                   rad_IC=rad_IC,
                                                   hydro_IC=hydro_IC,
                                                   hydro_BC=hydro_BC,
                                                   verbosity=verbosity,
                                                   slope_limiter=slope_limiter,
                                                   check_balance=False)

        # plot
        if __name__ == '__main__':

            # compute exact hydro solution
            hydro_exact = None

            # plot hydro solution
            plotHydroSolutions(mesh, hydro_new, exact=hydro_exact)

            # plot material and radiation temperatures
            plotTemperatures(mesh,
                             rad_new.E,
                             hydro_states=hydro_new,
                             print_values=True,
                             save=True,
                             filename=test_filename,
                             exact_solution_filename=exact_solution_filename)

            # plot angular fluxes
            plotS2Erg(mesh, rad_new.psim, rad_new.psip)
Exemplo n.º 5
0
    def test_TRTBE(self):

        # create mesh
        n_elems = 200
        mesh = Mesh(n_elems, 1.)

        # time step size and transient start and end times
        dt = 0.001
        t_start = 0.0
        #t_end   = 0.01
        t_end = 0.1

        # initialize temperature
        T_init = 0.05
        T_l = 0.5
        T_r = 0.05

        # gamma constant
        gam = 1.4

        # material 1 properties and IC
        sig_s1 = 0.0
        sig_a1 = 0.2
        c_v1 = convSpecHeatErgsEvToJksKev(1.E+12)
        rho1 = 0.01
        e1 = T_init * c_v1

        # material 2 properties and IC
        sig_s2 = 0.0
        sig_a2 = 2000.
        c_v2 = c_v1
        rho2 = 10.
        e2 = T_init * c_v2

        # construct cross sections and hydro IC
        cross_sects = list()
        hydro_IC = list()
        for i in range(mesh.n_elems):

            if mesh.getElement(i).x_cent < 0.5:  # material 1
                cross_sects.append(
                    (ConstantCrossSection(sig_s1, sig_s1 + sig_a1),
                     ConstantCrossSection(sig_s1, sig_s1 + sig_a1)))
                hydro_IC.append(
                    HydroState(u=0, rho=rho1, e=e1, spec_heat=c_v1, gamma=gam))
            else:  # material 2
                cross_sects.append(
                    (ConstantCrossSection(sig_s2, sig_a2 + sig_s2),
                     ConstantCrossSection(sig_s2, sig_a2 + sig_s2)))
                hydro_IC.append(
                    HydroState(u=0, rho=rho2, e=e2, spec_heat=c_v2, gamma=gam))

        # create hydro BC
        hydro_BC = HydroBC(bc_type='reflective', mesh=mesh)

        # initialize radiation to equilibrium solution
        psi_left = computeEquivIntensity(T_l)
        psi_right = computeEquivIntensity(T_r)
        rad_IC = Radiation([psi_right for i in range(n_elems * 4)])
        rad_BC = RadBC(mesh,
                       "dirichlet",
                       psi_left=psi_left,
                       psi_right=psi_right)

        # time-stepper
        time_stepper = "BDF2"

        # if run standalone, then be verbose
        if __name__ == '__main__':
            verbosity = 2
        else:
            verbosity = 0

        # run transient
        rad_new, hydro_new = runNonlinearTransient(mesh=mesh,
                                                   time_stepper=time_stepper,
                                                   problem_type='rad_mat',
                                                   dt_option='constant',
                                                   dt_constant=dt,
                                                   t_start=t_start,
                                                   t_end=t_end,
                                                   rad_BC=rad_BC,
                                                   cross_sects=cross_sects,
                                                   rad_IC=rad_IC,
                                                   hydro_IC=hydro_IC,
                                                   hydro_BC=hydro_BC,
                                                   verbosity=verbosity,
                                                   check_balance=True)

        # plot solutions if run standalone
        if __name__ == "__main__":
            plotTemperatures(mesh,
                             rad_new.E,
                             hydro_states=hydro_new,
                             print_values=False)
Exemplo n.º 6
0
def solveHydroProblem():

    # option to print solution
    print_solution = False

    #-------------------------------------------------------------------------------
    # Construct initial hydro states, probably create an initializer class
    #-------------------------------------------------------------------------------
    width = 1.0
    t_end = 0.05

    t = 0.0
    cfl = 0.5
    n = 500

    #Left and right BC and initial values
    gamma = 1.4 #gas constant
    p_left = 1.0
    u_left  = .750
    rho_left = 1.

    p_right = 0.1
    u_right = 0.0
    rho_right = 0.125

    #made up spec heat
    spec_heat = 1.0

    #Create a mesh, currently hardcoded
    mesh = Mesh(n, width)
    dx = mesh.getElement(0).dx

    if n % 2 != 0: #simple error raise, % has lots of diff meanings in python
        raise ValueError("Must be even number of cells")

    i_left = int(0.3*n)
    i_right = int(0.7*n)

    #Create cell centered variables
    states_a = [HydroState(u=u_left,p=p_left,gamma=gamma,rho=rho_left,
       spec_heat=spec_heat) for i in range(i_left)]
    states_a = states_a + [HydroState(u=u_right,p=p_right,gamma=gamma,
       spec_heat=spec_heat,rho=rho_right) for i in range(i_right)]

    # initialize BC object
    bc = HydroBC(bc_type='reflective', mesh=mesh)

    #-----------------------------------------------------------------
    # Solve Problem
    #----------------------------------------------------------------

    #loop over time steps
    time_index = 0
    while (t < t_end):

        # increment time index
        time_index += 1

        #Compute a new time step size based on CFL
        c = [sqrt(i.p*i.gamma/i.rho)+abs(i.u) for i in states_a]
        dt_vals = [cfl*(mesh.elements[i].dx)/c[i] for i in range(len(c))]
        dt = min(dt_vals)

        t += dt
        #shorten last step to be exact
        if (t > t_end):
            t -= dt
            dt = t_end - t + 0.000000001
            t += dt

        print("Time step %d: t = %f -> %f" % (time_index,t-dt,t))

        # update boundary values
        bc.update(states=states_a, t=t-dt)

        # compute slopes
        slopes = HydroSlopes(states_a, bc=bc)

        #Solve predictor step
        states_a = hydroPredictor(mesh, states_a, slopes, dt)

        # update boundary values
        bc.update(states=states_a, t=t-0.5*dt)

        #Solve corrector step
        states_a = hydroCorrector(mesh, states_a, dt, bc=bc)


    # plot solution
    plotHydroSolutions(mesh,states=states_a)

    # print solution
    if print_solution:
       for state in states_a:
          print state
Exemplo n.º 7
0
    def test_TRTBE(self):

        # create mesh
        n_elems = 200
        mesh = Mesh(n_elems, 2.)

        # time step size and transient start and end times
        dt = 0.001
        t_start = 0.
        t_end = 5.0

        # initialize temperature
        T_init = 2.5E-05
        T_l = 0.150
        T_r = T_init

        # gamma constant
        gam = 1.4

        # material 1 properties and IC
        sig_s1 = 0.0
        sig_a1 = 0.001
        c_v1 = convSpecHeatErgsEvToJksKev(1.3784E+11)
        rho1 = 1.0
        e1 = T_init * c_v1

        # construct cross sections and hydro IC
        cross_sects = list()
        hydro_IC = list()
        for i in range(mesh.n_elems):

            hydro_IC.append(
                HydroState(u=0, rho=rho1, e=e1, spec_heat=c_v1, gamma=gam))
            cross_sects.append((InvCubedCrossX(sig_s1,
                                               hydro_IC[-1],
                                               scale_coeff=0.001),
                                InvCubedCrossX(sig_s1,
                                               hydro_IC[-1],
                                               scale_coeff=0.001)))

        # create hydro BC
        hydro_BC = HydroBC(bc_type='reflective', mesh=mesh)

        # initialize radiation to equilibrium solution
        psi_left = computeEquivIntensity(T_l)
        psi_right = computeEquivIntensity(T_r)
        rad_IC = Radiation([psi_right for i in range(n_elems * 4)])

        # time-stepper
        time_stepper = "CN"

        # if run standalone, then be verbose
        if __name__ == '__main__':
            verbosity = 2
        else:
            verbosity = 0

        # run transient
        rad_new, hydro_new = runNonlinearTransient(mesh=mesh,
                                                   time_stepper=time_stepper,
                                                   problem_type='rad_mat',
                                                   dt_option='constant',
                                                   dt_constant=dt,
                                                   t_start=t_start,
                                                   t_end=t_end,
                                                   psi_left=psi_left,
                                                   psi_right=psi_right,
                                                   cross_sects=cross_sects,
                                                   rad_IC=rad_IC,
                                                   hydro_IC=hydro_IC,
                                                   hydro_BC=hydro_BC,
                                                   verbosity=verbosity,
                                                   check_balance=True)

        # plot solutions if run standalone
        if __name__ == "__main__":
            plotTemperatures(mesh,
                             rad_new.E,
                             hydro_states=hydro_new,
                             print_values=True)
Exemplo n.º 8
0
   def test_Hydro(self):

      # create mesh
      n_elems = 100
      width = 1.0
      mesh = Mesh(n_elems,width)
      x_diaphragm = 0.3

      # time step size and transient start and end times
      CFL     = 0.5
      t_start = 0.0
      t_end   = 0.2

      # slope limiter
      slope_limiter = "vanleer"

      # constant properties
      sig_s = 1.0 # arbitrary
      sig_a = 0.0 # set to zero to ensure no emission
      sig_t = sig_s + sig_a
      c_v   = 3.0 # arbitrary
      gam = 1.4

      # hydro IC values for left half of domain
      rhoL = 1.0
      uL   = 0.75
      pL   = 1.0

      # hydro IC values for right half of domain
      rhoR = 0.125
      uR   = 0.0
      pR   = 0.1

      # compute left and right internal energies
      eL = pL/(rhoL*(gam - 1.0))
      eR = pR/(rhoR*(gam - 1.0))

      # construct cross sections and hydro IC
      cross_sects = list()
      hydro_IC = list()
      for i in range(mesh.n_elems):  

         # cross section is constant
         cross_sects.append( (ConstantCrossSection(sig_s, sig_t),
                              ConstantCrossSection(sig_s, sig_t)) )
      
         # IC for left half of domain
         if mesh.getElement(i).x_cent < x_diaphragm:
            hydro_IC.append(
               HydroState(u=uL,rho=rhoL,e=eL,gamma=gam,spec_heat=c_v) )

         # IC for right half of domain
         else:
            hydro_IC.append(
               HydroState(u=uR,rho=rhoR,e=eR,gamma=gam,spec_heat=c_v) )

      # create hydro BC
      hydro_BC = HydroBC(bc_type='reflective', mesh=mesh)
  
      # initialize radiation to zero solution to give pure hydrodynamics
      rad_IC    = Radiation([0.0 for i in range(n_elems*4)])
      psi_left  = 0.0
      psi_right = 0.0
      rad_BC    = RadBC(mesh, "dirichlet", psi_left=psi_left, psi_right=psi_right)

      # if run standalone, then be verbose
      if __name__ == '__main__':
         verbosity = 2
      else:
         verbosity = 0

      # run transient
      rad_new, hydro_new = runNonlinearTransient(
         mesh         = mesh,
         time_stepper = 'BE',
         problem_type = 'rad_hydro',
         dt_option    = 'CFL',
         CFL          = 0.5,
         use_2_cycles = True,
         t_start      = t_start,
         t_end        = t_end,
         rad_BC       = rad_BC,
         cross_sects  = cross_sects,
         rad_IC       = rad_IC,
         hydro_IC     = hydro_IC,
         hydro_BC     = hydro_BC,
         slope_limiter = slope_limiter,
         verbosity    = verbosity,
         check_balance= True)



      # plot solutions if run standalone
      if __name__ == "__main__":

         # get exact solutions
         #get the exact values
         f = open('exact_testHydro.txt', 'r')
         x_e = []
         u_e = []
         p_e = []
         rho_e = []
         e_e = []
         for line in f:
             if len(line.split())==1:
                 t = line.split()
             else:
                 data = line.split()
                 x_e.append(float(data[0]))
                 u_e.append(float(data[1]))
                 p_e.append(float(data[2]))
                 rho_e.append(float(data[4]))
                 e_e.append(float(data[3]))

         hydro_exact = []
         for i in range(len(x_e)):
            hydro_exact.append(HydroState(u=u_e[i],rho=rho_e[i],e=e_e[i],gamma=gam,spec_heat=c_v) )

         plotHydroSolutions(mesh, hydro_new,x_exact=x_e,exact=hydro_exact)