Esempio n. 1
0
def init_data(myd, rp):
    """ initialize the tophat advection problem """

    msg.bold("initializing the tophat advection problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(myd, patch.CellCenterData2d):
        print("ERROR: patch invalid in tophat.py")
        print(myd.__class__)
        sys.exit()

    dens = myd.get_var("density")

    xmin = myd.grid.xmin
    xmax = myd.grid.xmax

    ymin = myd.grid.ymin
    ymax = myd.grid.ymax

    xctr = 0.5*(xmin + xmax)
    yctr = 0.5*(ymin + ymax)

    dens[:, :] = 0.0

    R = 0.1

    inside = (myd.grid.x2d - xctr)**2 + (myd.grid.y2d - yctr)**2 < R**2

    dens[inside] = 1.0
Esempio n. 2
0
def init_data(my_data, rp):
    """ initialize the tophat advection problem """

    msg.bold("initializing the tophat advection problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print("ERROR: patch invalid in tophat.py")
        print(my_data.__class__)
        sys.exit()

    dens = my_data.get_var("density")

    xmin = my_data.grid.xmin
    xmax = my_data.grid.xmax

    ymin = my_data.grid.ymin
    ymax = my_data.grid.ymax

    xctr = 0.5*(xmin + xmax)
    yctr = 0.5*(ymin + ymax)

    dens[:,:] = 0.0

    for i in range(my_data.grid.ilo, my_data.grid.ihi+1):
        for j in range(my_data.grid.jlo, my_data.grid.jhi+1):

            if (numpy.sqrt((my_data.grid.x[i]-xctr)**2 +
                           (my_data.grid.y[j]-yctr)**2) < 0.1):
                dens[i,j] = 1.0
Esempio n. 3
0
def init_data(my_data, rp):
    """ initialize the incompressible Taylor-Green flow problem """

    msg.bold("initializing the incompressible Taylor-Green flow problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print(my_data.__class__)
        msg.fail("ERROR: patch invalid in tg.py")

    # get the velocities
    u = my_data.get_var("x-velocity")
    v = my_data.get_var("y-velocity")

    myg = my_data.grid

    if (myg.xmin != 0 or myg.xmax != 1 or myg.ymin != 0 or myg.ymax != 1):
        msg.fail("ERROR: domain should be a unit square")

    y_half = 0.5 * (myg.ymin + myg.ymax)

    idx = myg.y2d <= myg.ymin + .02

    u[idx] = np.sin(2.0 * math.pi * myg.x2d[idx]) * np.cos(
        2.0 * math.pi * myg.y2d[idx])

    v[:, :] = -np.cos(2.0 * math.pi * myg.y2d) * np.sin(
        2.0 * math.pi * myg.x2d)
Esempio n. 4
0
File: rt.py Progetto: zingale/pyro2
def init_data(my_data, rp):
    """ initialize the rt problem """

    msg.bold("initializing the rt problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print("ERROR: patch invalid in rt.py")
        print(my_data.__class__)
        sys.exit()

    # get the density, momenta, and energy as separate variables
    dens = my_data.get_var("density")
    xmom = my_data.get_var("x-momentum")
    ymom = my_data.get_var("y-momentum")
    ener = my_data.get_var("energy")

    gamma = rp.get_param("eos.gamma")

    grav = rp.get_param("compressible.grav")

    dens1 = rp.get_param("rt.dens1")
    dens2 = rp.get_param("rt.dens2")
    p0 = rp.get_param("rt.p0")
    amp = rp.get_param("rt.amp")
    sigma = rp.get_param("rt.sigma")

    # initialize the components, remember, that ener here is
    # rho*eint + 0.5*rho*v**2, where eint is the specific
    # internal energy (erg/g)
    xmom[:, :] = 0.0
    ymom[:, :] = 0.0
    dens[:, :] = 0.0

    # set the density to be stratified in the y-direction
    myg = my_data.grid

    ycenter = 0.5*(myg.ymin + myg.ymax)

    p = myg.scratch_array()

    j = myg.jlo
    while j <= myg.jhi:
        if (myg.y[j] < ycenter):
            dens[:, j] = dens1
            p[:, j] = p0 + dens1*grav*myg.y[j]

        else:
            dens[:, j] = dens2
            p[:, j] = p0 + dens1*grav*ycenter + dens2*grav*(myg.y[j] - ycenter)

        j += 1

    ymom[:, :] = amp*np.cos(2.0*np.pi*myg.x2d/(myg.xmax-myg.xmin))*np.exp(-(myg.y2d-ycenter)**2/sigma**2)

    ymom *= dens

    # set the energy (P = cs2*dens)
    ener[:, :] = p[:, :]/(gamma - 1.0) + \
        0.5*(xmom[:, :]**2 + ymom[:, :]**2)/dens[:, :]
Esempio n. 5
0
def init_data(my_data, rp):
    """ initialize the tophat advection problem """

    msg.bold("initializing the tophat advection problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print("ERROR: patch invalid in tophat.py")
        print(my_data.__class__)
        sys.exit()

    dens = my_data.get_var("density")

    xmin = my_data.grid.xmin
    xmax = my_data.grid.xmax

    ymin = my_data.grid.ymin
    ymax = my_data.grid.ymax

    xctr = 0.5 * (xmin + xmax)
    yctr = 0.5 * (ymin + ymax)

    dens[:, :] = 0.0

    for i in range(my_data.grid.ilo, my_data.grid.ihi + 1):
        for j in range(my_data.grid.jlo, my_data.grid.jhi + 1):

            if (numpy.sqrt((my_data.grid.x[i] - xctr)**2 +
                           (my_data.grid.y[j] - yctr)**2) < 0.1):
                dens[i, j] = 1.0
Esempio n. 6
0
def init_data(my_data, rp):
    """ initialize the smooth advection problem """

    msg.bold("initializing the smooth advection problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print(my_data.__class__)
        msg.fail("ERROR: patch invalid in slotted.py")

    dens = my_data.get_var("density")

    xmin = my_data.grid.xmin
    xmax = my_data.grid.xmax

    ymin = my_data.grid.ymin
    ymax = my_data.grid.ymax

    xctr = 0.5*(xmin + xmax)
    yctr = 0.5*(ymin + ymax)

    dens[:, :] = 1.0 + np.exp(-60.0*((my_data.grid.x2d-xctr)**2 +
                                        (my_data.grid.y2d-yctr)**2))

    u = my_data.get_var("x-velocity")
    v = my_data.get_var("y-velocity")

    u[:, :] = rp.get_param("advection.u")
    v[:, :] = rp.get_param("advection.v")
Esempio n. 7
0
def initData(my_data):
    """ initialize the smooth advection problem """

    msg.bold("initializing the smooth advection problem...")

    rp = my_data.rp

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print "ERROR: patch invalid in smooth.py"
        print my_data.__class__
        sys.exit()

    dens = my_data.get_var("density")

    xmin = my_data.grid.xmin
    xmax = my_data.grid.xmax

    ymin = my_data.grid.ymin
    ymax = my_data.grid.ymax

    xctr = 0.5 * (xmin + xmax)
    yctr = 0.5 * (ymin + ymax)

    i = my_data.grid.ilo
    while i <= my_data.grid.ihi:

        j = my_data.grid.jlo
        while j <= my_data.grid.jhi:

            dens[i,j] = 1.0 + numpy.exp(-60.0*((my_data.grid.x[i]-xctr)**2 + \
                                               (my_data.grid.y[j]-yctr)**2))

            j += 1
        i += 1
Esempio n. 8
0
    def __init__(self, solver_name):
        """
        Constructor

        Parameters
        ----------
        solver_name : str
            Name of solver to use
        """

        msg.bold('pyro ...')

        if solver_name not in valid_solvers:
            msg.fail("ERROR: %s is not a valid solver" % solver_name)

        self.pyro_home = os.path.dirname(os.path.realpath(__file__)) + '/'

        # import desired solver under "solver" namespace
        self.solver = importlib.import_module(solver_name)
        self.solver_name = solver_name

        # -------------------------------------------------------------------------
        # runtime parameters
        # -------------------------------------------------------------------------

        # parameter defaults
        self.rp = runparams.RuntimeParameters()
        self.rp.load_params(self.pyro_home + "_defaults")
        self.rp.load_params(self.pyro_home + solver_name + "/_defaults")

        self.tc = profile.TimerCollection()

        self.is_initialized = False
Esempio n. 9
0
    def __init__(self, solver_name):
        """
        Constructor

        Parameters
        ----------
        solver_name : str
            Name of solver to use
        """

        msg.bold('pyro ...')

        if solver_name not in valid_solvers:
            msg.fail("ERROR: %s is not a valid solver" % solver_name)

        self.pyro_home = os.path.dirname(os.path.realpath(__file__)) + '/'

        # import desired solver under "solver" namespace
        self.solver = importlib.import_module(solver_name)
        self.solver_name = solver_name

        # -------------------------------------------------------------------------
        # runtime parameters
        # -------------------------------------------------------------------------

        # parameter defaults
        self.rp = runparams.RuntimeParameters()
        self.rp.load_params(self.pyro_home + "_defaults")
        self.rp.load_params(self.pyro_home + solver_name + "/_defaults")

        self.tc = profile.TimerCollection()

        self.is_initialized = False
Esempio n. 10
0
def init_data(myd, rp):
    """ initialize the tophat advection problem """

    msg.bold("initializing the tophat advection problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(myd, patch.CellCenterData2d):
        print("ERROR: patch invalid in tophat.py")
        print(myd.__class__)
        sys.exit()

    dens = myd.get_var("density")

    xmin = myd.grid.xmin
    xmax = myd.grid.xmax

    ymin = myd.grid.ymin
    ymax = myd.grid.ymax

    xctr = 0.5 * (xmin + xmax)
    yctr = 0.5 * (ymin + ymax)

    dens[:, :] = 0.0

    R = 0.1

    inside = (myd.grid.x2d - xctr)**2 + (myd.grid.y2d - yctr)**2 < R**2

    dens[inside] = 1.0
Esempio n. 11
0
def init_data(my_data, rp):
    """ initialize the smooth advection problem """

    msg.bold("initializing the smooth advection problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print("ERROR: patch invalid in smooth.py")
        print(my_data.__class__)
        sys.exit()

    dens = my_data.get_var("density")

    xmin = my_data.grid.xmin
    xmax = my_data.grid.xmax

    ymin = my_data.grid.ymin
    ymax = my_data.grid.ymax

    xctr = 0.5*(xmin + xmax)
    yctr = 0.5*(ymin + ymax)
    
    i = my_data.grid.ilo
    while i <= my_data.grid.ihi:

        j = my_data.grid.jlo
        while j <= my_data.grid.jhi:

            dens[i,j] = 1.0 + numpy.exp(-60.0*((my_data.grid.x[i]-xctr)**2 + \
                                               (my_data.grid.y[j]-yctr)**2))
                    
            j += 1
        i += 1
Esempio n. 12
0
def init_data(my_data, rp):
    """ initialize the Kelvin-Helmholtz problem """

    msg.bold("initializing the sedov problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print(my_data.__class__)
        msg.fail("ERROR: patch invalid in sedov.py")

    # get the density, momenta, and energy as separate variables
    dens = my_data.get_var("density")
    xmom = my_data.get_var("x-momentum")
    ymom = my_data.get_var("y-momentum")
    ener = my_data.get_var("energy")

    # initialize the components, remember, that ener here is rho*eint
    # + 0.5*rho*v**2, where eint is the specific internal energy
    # (erg/g)
    dens[:, :] = 1.0
    xmom[:, :] = 0.0
    ymom[:, :] = 0.0

    rho_1 = rp.get_param("kh.rho_1")
    v_1 = rp.get_param("kh.v_1")
    rho_2 = rp.get_param("kh.rho_2")
    v_2 = rp.get_param("kh.v_2")

    gamma = rp.get_param("eos.gamma")

    xmin = rp.get_param("mesh.xmin")
    xmax = rp.get_param("mesh.xmax")

    ymin = rp.get_param("mesh.ymin")
    ymax = rp.get_param("mesh.ymax")

    yctr = 0.5 * (ymin + ymax)

    L_x = xmax - xmin

    myg = my_data.grid

    idx_l = myg.y2d < yctr + 0.01 * np.sin(10.0 * np.pi * myg.x2d / L_x)
    idx_h = myg.y2d >= yctr + 0.01 * np.sin(10.0 * np.pi * myg.x2d / L_x)

    # lower half
    dens[idx_l] = rho_1
    xmom[idx_l] = rho_1 * v_1
    ymom[idx_l] = 0.0

    # upper half
    dens[idx_h] = rho_2
    xmom[idx_h] = rho_2 * v_2
    ymom[idx_h] = 0.0

    p = 1.0
    ener[:, :] = p / (gamma - 1.0) + 0.5 * (xmom[:, :]**2 +
                                            ymom[:, :]**2) / dens[:, :]
Esempio n. 13
0
def init_data(my_data, rp):
    """ initialize the HSE problem """

    msg.bold("initializing the HSE problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print("ERROR: patch invalid in hse.py")
        print(my_data.__class__)
        sys.exit()

    # get the density, momenta, and energy as separate variables
    dens = my_data.get_var("density")
    xmom = my_data.get_var("x-momentum")
    ymom = my_data.get_var("y-momentum")
    ener = my_data.get_var("energy")

    gamma = rp.get_param("eos.gamma")

    grav = rp.get_param("compressible.grav")

    dens0 = rp.get_param("hse.dens0")
    print("dens0 = ", dens0)
    H = rp.get_param("hse.h")

    # isothermal sound speed (squared)
    cs2 = H * abs(grav)

    # initialize the components, remember, that ener here is
    # rho*eint + 0.5*rho*v**2, where eint is the specific
    # internal energy (erg/g)
    xmom[:, :] = 0.0
    ymom[:, :] = 0.0
    dens[:, :] = 0.0

    # set the density to be stratified in the y-direction
    myg = my_data.grid

    p = myg.scratch_array()

    for j in range(myg.jlo, myg.jhi + 1):
        dens[:, j] = dens0 * np.exp(-myg.y[j] / H)
        if j == myg.jlo:
            p[:, j] = dens[:, j] * cs2
        else:
            p[:,
              j] = p[:, j -
                     1] + 0.5 * myg.dy * (dens[:, j] + dens[:, j - 1]) * grav

    # # set the energy
    # ener[:, :] = p[:, :]/(gamma - 1.0) + \
    #     0.5*(xmom[:, :]**2 + ymom[:, :]**2)/dens[:, :]

    # W = 1
    rhoh = eos.rhoh_from_rho_p(gamma, dens, p)
    ener[:, :] = rhoh - p - dens
Esempio n. 14
0
def init_data(my_data, rp):
    """ initialize a smooth advection problem for testing convergence """

    msg.bold("initializing the advect problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print("ERROR: patch invalid in advect.py")
        print(my_data.__class__)
        sys.exit()

    # get the density, momenta, and energy as separate variables
    dens = my_data.get_var("density")
    xmom = my_data.get_var("x-momentum")
    ymom = my_data.get_var("y-momentum")
    ener = my_data.get_var("energy")

    # initialize the components, remember, that ener here is rho*eint
    # + 0.5*rho*v**2, where eint is the specific internal energy
    # (erg/g)
    dens[:, :] = 0.2
    xmom[:, :] = 0.0
    ymom[:, :] = 0.0

    gamma = rp.get_param("eos.gamma")

    xmin = rp.get_param("mesh.xmin")
    xmax = rp.get_param("mesh.xmax")

    ymin = rp.get_param("mesh.ymin")
    ymax = rp.get_param("mesh.ymax")

    xctr = 0.5 * (xmin + xmax)
    yctr = 0.5 * (ymin + ymax)

    # this is identical to the advection/smooth problem
    dens[:, :] = 0.2 * (1 + np.exp(-60.0 * ((my_data.grid.x2d - xctr)**2 +
                                            (my_data.grid.y2d - yctr)**2)))

    # velocity is diagonal
    u = 0.4
    v = 0.4

    # pressure is constant
    p = 0.2

    rhoh = eos.rhoh_from_rho_p(gamma, dens, p)

    W = 1. / np.sqrt(1 - u**2 - v**2)
    dens[:, :] *= W
    xmom[:, :] = rhoh[:, :] * u * W**2
    ymom[:, :] = rhoh[:, :] * v * W**2

    ener[:, :] = rhoh[:, :] * W**2 - p - dens[:, :]
Esempio n. 15
0
def initData(my_data):
    """ initialize the incompressible shear problem """

    msg.bold("initializing the incompressible shear problem...")

    rp = my_data.rp

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print my_data.__class__
        msg.fail("ERROR: patch invalid in shear.py")


    # get the necessary runtime parameters
    rho_s = rp.get_param("shear.rho_s")
    delta_s = rp.get_param("shear.delta_s")

    
    # get the velocities
    u = my_data.get_var("x-velocity")
    v = my_data.get_var("y-velocity")

    myg = my_data.grid

    if (myg.xmin != 0 or myg.xmax != 1 or
        myg.ymin != 0 or myg.ymax != 1):
        msg.fail("ERROR: domain should be a unit square")
        
    y_half = 0.5*(myg.ymin + myg.ymax)

    print 'y_half = ', y_half
    print 'delta_s = ', delta_s
    print 'rho_s = ', rho_s
    
    # there is probably an easier way to do this without loops, but
    # for now, we will just do an explicit loop.
    i = myg.ilo
    while i <= myg.ihi:

        j = myg.jlo
        while j <= myg.jhi:

            if (myg.y[j] <= y_half):
                u[i,j] = numpy.tanh(rho_s*(myg.y[j] - 0.25))
            else:
                u[i,j] = numpy.tanh(rho_s*(0.75 - myg.y[j]))
            
            v[i,j] = delta_s*numpy.sin(2.0*math.pi*myg.x[i])
            
            j += 1
        i += 1
        
    
    print "extrema: ", numpy.min(u.flat), numpy.max(u.flat)
def init_data(myd, rp):
    """initialize the acoustic_pulse problem.  This comes from
    McCourquodale & Coella 2011"""

    msg.bold("initializing the acoustic pulse problem...")

    # make sure that we are passed a valid patch object
    # if not isinstance(myd, fv.FV2d):
    #     print("ERROR: patch invalid in acoustic_pulse.py")
    #     print(myd.__class__)
    #     sys.exit()

    # get the density, momenta, and energy as separate variables
    dens = myd.get_var("density")
    xmom = myd.get_var("x-momentum")
    ymom = myd.get_var("y-momentum")
    ener = myd.get_var("energy")

    # initialize the components, remember, that ener here is rho*eint
    # + 0.5*rho*v**2, where eint is the specific internal energy
    # (erg/g)
    xmom[:, :] = 0.0
    ymom[:, :] = 0.0

    gamma = rp.get_param("eos.gamma")

    rho0 = rp.get_param("acoustic_pulse.rho0")
    drho0 = rp.get_param("acoustic_pulse.drho0")

    xmin = rp.get_param("mesh.xmin")
    xmax = rp.get_param("mesh.xmax")

    ymin = rp.get_param("mesh.ymin")
    ymax = rp.get_param("mesh.ymax")

    xctr = 0.5 * (xmin + xmax)
    yctr = 0.5 * (ymin + ymax)

    dist = np.sqrt((myd.grid.x2d - xctr)**2 + (myd.grid.y2d - yctr)**2)

    dens[:, :] = rho0
    idx = dist <= 0.5
    dens[idx] = rho0 + drho0 * np.exp(-16 * dist[idx]**2) * np.cos(
        np.pi * dist[idx])**6

    p = (dens / rho0)**gamma
    ener[:, :] = p / (gamma - 1)

    rhoh = eos.rhoh_from_rho_p(gamma, dens, p)

    ener[:, :] = rhoh[:, :] - p - dens[:, :]
Esempio n. 17
0
File: hse.py Progetto: zingale/pyro2
def init_data(my_data, rp):
    """ initialize the HSE problem """

    msg.bold("initializing the HSE problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print("ERROR: patch invalid in hse.py")
        print(my_data.__class__)
        sys.exit()

    # get the density, momenta, and energy as separate variables
    dens = my_data.get_var("density")
    xmom = my_data.get_var("x-momentum")
    ymom = my_data.get_var("y-momentum")
    ener = my_data.get_var("energy")

    gamma = rp.get_param("eos.gamma")

    grav = rp.get_param("compressible.grav")

    dens0 = rp.get_param("hse.dens0")
    print("dens0 = ", dens0)
    H = rp.get_param("hse.h")

    # isothermal sound speed (squared)
    cs2 = H*abs(grav)

    # initialize the components, remember, that ener here is
    # rho*eint + 0.5*rho*v**2, where eint is the specific
    # internal energy (erg/g)
    xmom[:, :] = 0.0
    ymom[:, :] = 0.0
    dens[:, :] = 0.0

    # set the density to be stratified in the y-direction
    myg = my_data.grid

    p = myg.scratch_array()

    for j in range(myg.jlo, myg.jhi+1):
        dens[:, j] = dens0*np.exp(-myg.y[j]/H)
        if j == myg.jlo:
            p[:, j] = dens[:, j]*cs2
        else:
            p[:, j] = p[:, j-1] + 0.5*myg.dy*(dens[:, j] + dens[:, j-1])*grav

    # set the energy
    ener[:, :] = p[:, :]/(gamma - 1.0) + \
        0.5*(xmom[:, :]**2 + ymom[:, :]**2)/dens[:, :]
Esempio n. 18
0
def init_data(my_data, rp):
    """ initialize a smooth advection problem for testing convergence """

    msg.bold("initializing the advect problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print("ERROR: patch invalid in advect.py")
        print(my_data.__class__)
        sys.exit()

    # get the density, momenta, and energy as separate variables
    dens = my_data.get_var("density")
    xmom = my_data.get_var("x-momentum")
    ymom = my_data.get_var("y-momentum")
    ener = my_data.get_var("energy")

    # initialize the components, remember, that ener here is rho*eint
    # + 0.5*rho*v**2, where eint is the specific internal energy
    # (erg/g)
    dens.d[:,:] = 1.0
    xmom.d[:,:] = 0.0
    ymom.d[:,:] = 0.0


    gamma = rp.get_param("eos.gamma")

    xmin = rp.get_param("mesh.xmin")
    xmax = rp.get_param("mesh.xmax")

    ymin = rp.get_param("mesh.ymin")
    ymax = rp.get_param("mesh.ymax")

    xctr = 0.5*(xmin + xmax)
    yctr = 0.5*(ymin + ymax)

    # this is identical to the advection/smooth problem
    dens.d[:,:] = 1.0 + np.exp(-60.0*((my_data.grid.x2d-xctr)**2 + 
                                      (my_data.grid.y2d-yctr)**2))


    # velocity is diagonal
    u = 1.0
    v = 1.0
    xmom.d[:,:] = dens.d[:,:]*u
    ymom.d[:,:] = dens.d[:,:]*v

    # pressure is constant
    p = 1.0
    ener.d[:,:] = p/(gamma - 1.0) + 0.5*(xmom.d[:,:]**2 + ymom.d[:,:]**2)/dens.d[:,:]
Esempio n. 19
0
def initData(my_data):
    """ initialize the incompressible shear problem """

    msg.bold("initializing the incompressible shear problem...")

    rp = my_data.rp

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print my_data.__class__
        msg.fail("ERROR: patch invalid in shear.py")

    # get the necessary runtime parameters
    rho_s = rp.get_param("shear.rho_s")
    delta_s = rp.get_param("shear.delta_s")

    # get the velocities
    u = my_data.get_var("x-velocity")
    v = my_data.get_var("y-velocity")

    myg = my_data.grid

    if (myg.xmin != 0 or myg.xmax != 1 or myg.ymin != 0 or myg.ymax != 1):
        msg.fail("ERROR: domain should be a unit square")

    y_half = 0.5 * (myg.ymin + myg.ymax)

    print 'y_half = ', y_half
    print 'delta_s = ', delta_s
    print 'rho_s = ', rho_s

    # there is probably an easier way to do this without loops, but
    # for now, we will just do an explicit loop.
    i = myg.ilo
    while i <= myg.ihi:

        j = myg.jlo
        while j <= myg.jhi:

            if (myg.y[j] <= y_half):
                u[i, j] = numpy.tanh(rho_s * (myg.y[j] - 0.25))
            else:
                u[i, j] = numpy.tanh(rho_s * (0.75 - myg.y[j]))

            v[i, j] = delta_s * numpy.sin(2.0 * math.pi * myg.x[i])

            j += 1
        i += 1

    print "extrema: ", numpy.min(u.flat), numpy.max(u.flat)
Esempio n. 20
0
def init_data(my_data, rp):
    """ initialize the incompressible shear problem """

    msg.bold("initializing the incompressible shear problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print(my_data.__class__)
        msg.fail("ERROR: patch invalid in shear.py")

    # get the necessary runtime parameters
    eps = rp.get_param("vortex.eps")

    print('eps = ', eps)

    # get the velocities
    u = my_data.get_var("x-velocity")
    v = my_data.get_var("y-velocity")

    myg = my_data.grid

    u.d[:,:] = -np.sin(math.pi*myg.y2d)
    v.d[:,:] = np.sin(math.pi*myg.x2d)
    #u.d[:,:] = -np.sin(2.0*math.pi*myg.x2d)*np.cos(2.0*math.pi*myg.y2d)*ran
    #v.d[:,:] = np.cos(2.0*math.pi*myg.x2d)*np.sin(2.0*math.pi*myg.y2d)*ran

    if eps != 0.0:
    #perturbed velocity1 at (0,0)
      r2 = myg.x2d**2+myg.y2d**2
      dvx1l = -eps**3*myg.y2d/r2*(1-np.exp(-r2/eps**2))
      dvy1l = eps**3*myg.x2d/r2*(1-np.exp(-r2/eps**2))

    #perturbed velocity1 at (2pi,0)
      r2 = (myg.x2d - 2.0)**2+myg.y2d**2
      dvx1r = -eps**3*myg.y2d/r2*(1-np.exp(-r2/eps**2))
      dvy1r = eps**3*(myg.x2d-2.0)/r2*(1-np.exp(-r2/eps**2))


    #perturbed velocity2 at (pi,0)
      r2 = (myg.x2d - 1.0)**2+myg.y2d**2
      dvx2 = eps**3*myg.y2d/r2*(1-np.exp(-r2/eps**2))
      dvy2 = -eps**3*(myg.x2d-1.0)/r2*(1-np.exp(-r2/eps**2))

      u.d[:,:] = u.d[:,:] + dvx1l + dvx1r + dvx2
      v.d[:,:] = v.d[:,:] + dvy1l + dvy1r + dvy2

    print("extrema: ", u.min(), u.max())
Esempio n. 21
0
def init_data(myd, rp):
    """initialize the acoustic_pulse problem.  This comes from
    McCourquodale & Coella 2011"""

    msg.bold("initializing the acoustic pulse problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(myd, fv.FV2d):
        print("ERROR: patch invalid in acoustic_pulse.py")
        print(myd.__class__)
        sys.exit()

    # get the density, momenta, and energy as separate variables
    dens = myd.get_var("density")
    xmom = myd.get_var("x-momentum")
    ymom = myd.get_var("y-momentum")
    ener = myd.get_var("energy")

    # initialize the components, remember, that ener here is rho*eint
    # + 0.5*rho*v**2, where eint is the specific internal energy
    # (erg/g)
    xmom[:, :] = 0.0
    ymom[:, :] = 0.0

    gamma = rp.get_param("eos.gamma")

    rho0 = rp.get_param("acoustic_pulse.rho0")
    drho0 = rp.get_param("acoustic_pulse.drho0")

    xmin = rp.get_param("mesh.xmin")
    xmax = rp.get_param("mesh.xmax")

    ymin = rp.get_param("mesh.ymin")
    ymax = rp.get_param("mesh.ymax")

    xctr = 0.5*(xmin + xmax)
    yctr = 0.5*(ymin + ymax)

    dist = np.sqrt((myd.grid.x2d - xctr)**2 +
                   (myd.grid.y2d - yctr)**2)

    dens[:, :] = rho0
    idx = dist <= 0.5
    dens[idx] = rho0 + drho0*np.exp(-16*dist[idx]**2) * np.cos(np.pi*dist[idx])**6

    p = (dens/rho0)**gamma
    ener[:, :] = p/(gamma - 1)
Esempio n. 22
0
def init_data(my_data, rp):
    """ initialize a smooth advection problem for testing convergence """

    msg.bold("initializing the advect problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print("ERROR: patch invalid in advect.py")
        print(my_data.__class__)
        sys.exit()

    # get the hity, momenta, and energy as separate variables
    h = my_data.get_var("height")
    xmom = my_data.get_var("x-momentum")
    ymom = my_data.get_var("y-momentum")
    X = my_data.get_var("fuel")

    # initialize the components, remember, that ener here is rho*eint
    # + 0.5*rho*v**2, where eint is the specific internal energy
    # (erg/g)
    h[:, :] = 1.0
    xmom[:, :] = 0.0
    ymom[:, :] = 0.0

    xmin = rp.get_param("mesh.xmin")
    xmax = rp.get_param("mesh.xmax")

    ymin = rp.get_param("mesh.ymin")
    ymax = rp.get_param("mesh.ymax")

    xctr = 0.5 * (xmin + xmax)
    yctr = 0.5 * (ymin + ymax)

    # this is identical to the advection/smooth problem
    h[:, :] = 1.0 + np.exp(-60.0 * ((my_data.grid.x2d - xctr)**2 +
                                    (my_data.grid.y2d - yctr)**2))

    # velocity is diagonal
    u = 1.0
    v = 1.0
    xmom[:, :] = h[:, :] * u
    ymom[:, :] = h[:, :] * v

    X[:, :] = h**2 / np.max(h)
Esempio n. 23
0
def init_data(my_data, rp):
    """ initialize the slotted advection problem """
    msg.bold("initializing the slotted advection problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print(my_data.__class__)
        msg.fail("ERROR: patch invalid in slotted.py")

    offset = rp.get_param("slotted.offset")
    omega = rp.get_param("slotted.omega")

    myg = my_data.grid

    xctr_dens = 0.5*(myg.xmin + myg.xmax)
    yctr_dens = 0.5*(myg.ymin + myg.ymax) + offset

    # setting initial condition for density
    dens = my_data.get_var("density")
    dens[:, :] = 0.0

    R = 0.15
    slot_width = 0.05

    inside = (myg.x2d - xctr_dens)**2 + (myg.y2d - yctr_dens)**2 < R**2

    slot_x = np.logical_and(myg.x2d > (xctr_dens - slot_width*0.5),
                            myg.x2d < (xctr_dens + slot_width*0.5))
    slot_y = np.logical_and(myg.y2d > (yctr_dens - R),
                            myg.y2d < (yctr_dens))
    slot = np.logical_and(slot_x, slot_y)

    dens[inside] = 1.0
    dens[slot] = 0.0

    # setting initial condition for velocity
    u = my_data.get_var("x-velocity")
    v = my_data.get_var("y-velocity")

    u[:, :] = omega*(myg.y2d - xctr_dens)
    v[:, :] = -omega*(myg.x2d - (yctr_dens-offset))

    print("extrema: ", np.amax(u), np.amin(u))
Esempio n. 24
0
def init_data(my_data, rp):
    """ initialize the smooth advection problem """

    msg.bold("initializing the smooth advection 1d problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData1d):
        print("ERROR: patch invalid in smooth.py")
        print(my_data.__class__)
        sys.exit()

    dens = my_data.get_var("density")

    xmin = my_data.grid.xmin
    xmax = my_data.grid.xmax

    xctr = 0.5 * (xmin + xmax)

    dens[:] = 1.0 + numpy.exp(-60.0 * ((my_data.grid.x - xctr)**2))
Esempio n. 25
0
def init_data(my_data, rp):
    """ initialize the slotted advection problem """
    msg.bold("initializing the slotted advection problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print(my_data.__class__)
        msg.fail("ERROR: patch invalid in slotted.py")

    offset = rp.get_param("slotted.offset")
    omega = rp.get_param("slotted.omega")

    myg = my_data.grid

    xctr_dens = 0.5 * (myg.xmin + myg.xmax)
    yctr_dens = 0.5 * (myg.ymin + myg.ymax) + offset

    # setting initial condition for density
    dens = my_data.get_var("density")
    dens[:, :] = 0.0

    R = 0.15
    slot_width = 0.05

    inside = (myg.x2d - xctr_dens)**2 + (myg.y2d - yctr_dens)**2 < R**2

    slot_x = np.logical_and(myg.x2d > (xctr_dens - slot_width * 0.5), myg.x2d <
                            (xctr_dens + slot_width * 0.5))
    slot_y = np.logical_and(myg.y2d > (yctr_dens - R), myg.y2d < (yctr_dens))
    slot = np.logical_and(slot_x, slot_y)

    dens[inside] = 1.0
    dens[slot] = 0.0

    # setting initial condition for velocity
    u = my_data.get_var("x-velocity")
    v = my_data.get_var("y-velocity")

    u[:, :] = omega * (myg.y2d - xctr_dens)
    v[:, :] = -omega * (myg.x2d - (yctr_dens - offset))

    print("extrema: ", np.amax(u), np.amin(u))
Esempio n. 26
0
def init_data(myd, rp):
    """initialize the acoustic_pulse problem.  This comes from
    McCourquodale & Coella 2011"""

    msg.bold("initializing the acoustic pulse problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(myd, patch.CellCenterData2d):
        print("ERROR: patch invalid in acoustic_pulse.py")
        print(myd.__class__)
        sys.exit()

    # get the height, momenta as separate variables
    h = myd.get_var("height")
    xmom = myd.get_var("x-momentum")
    ymom = myd.get_var("y-momentum")
    X = myd.get_var("fuel")

    # initialize the components
    xmom[:, :] = 0.0
    ymom[:, :] = 0.0

    h0 = rp.get_param("acoustic_pulse.h0")
    dh0 = rp.get_param("acoustic_pulse.dh0")

    xmin = rp.get_param("mesh.xmin")
    xmax = rp.get_param("mesh.xmax")

    ymin = rp.get_param("mesh.ymin")
    ymax = rp.get_param("mesh.ymax")

    xctr = 0.5*(xmin + xmax)
    yctr = 0.5*(ymin + ymax)

    dist = np.sqrt((myd.grid.x2d - xctr)**2 +
                   (myd.grid.y2d - yctr)**2)

    h[:, :] = h0
    idx = dist <= 0.5
    h[idx] = h0 + dh0*np.exp(-16*dist[idx]**2) * np.cos(np.pi*dist[idx])**6

    X[:, :] = h[:, :]**2 / np.max(h)
Esempio n. 27
0
def init_data(my_data, rp):
    """ initialize the incompressible shear problem """

    msg.bold("initializing the incompressible shear problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print(my_data.__class__)
        msg.fail("ERROR: patch invalid in shear.py")


    # get the necessary runtime parameters
    rho_s = rp.get_param("shear.rho_s")
    delta_s = rp.get_param("shear.delta_s")


    # get the velocities
    u = my_data.get_var("x-velocity")
    v = my_data.get_var("y-velocity")

    myg = my_data.grid

    if (myg.xmin != 0 or myg.xmax != 1 or
        myg.ymin != 0 or myg.ymax != 1):
        msg.fail("ERROR: domain should be a unit square")

    y_half = 0.5*(myg.ymin + myg.ymax)

    print('y_half = ', y_half)
    print('delta_s = ', delta_s)
    print('rho_s = ', rho_s)

    idx = myg.y2d <= y_half
    u.d[idx] = np.tanh(rho_s*(myg.y2d[idx] - 0.25))

    idx = myg.y2d > y_half
    u.d[idx] = np.tanh(rho_s*(0.75 - myg.y2d[idx]))

    v.d[:,:] = delta_s*np.sin(2.0*math.pi*myg.x2d)

    print("extrema: ", u.min(), u.max())
Esempio n. 28
0
def initData(my_data):
    """ initialize the Gaussian diffusion problem """

    msg.bold("initializing the Gaussian diffusion problem...")

    rp = my_data.rp

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print "ERROR: patch invalid in diffuse.py"
        print my_data.__class__
        sys.exit()

    phi = my_data.get_var("phi")

    xmin = my_data.grid.xmin
    xmax = my_data.grid.xmax

    ymin = my_data.grid.ymin
    ymax = my_data.grid.ymax

    xctr = 0.5 * (xmin + xmax)
    yctr = 0.5 * (ymin + ymax)

    k = rp.get_param("diffusion.k")
    t_0 = rp.get_param("gaussian.t_0")
    phi_max = rp.get_param("gaussian.phi_max")
    phi_0 = rp.get_param("gaussian.phi_0")

    dist = numpy.sqrt((my_data.grid.x2d - xctr)**2 +
                      (my_data.grid.y2d - yctr)**2)

    phi[:, :] = phi_analytic(dist, 0.0, t_0, k, phi_0, phi_max)

    # for later interpretation / analysis, store some auxillary data
    my_data.set_aux("k", k)
    my_data.set_aux("t_0", t_0)
    my_data.set_aux("phi_0", phi_0)
    my_data.set_aux("phi_max", phi_max)
Esempio n. 29
0
def init_data(my_data, rp):
    """ initialize the incompressible converge problem """

    msg.bold("initializing the incompressible converge problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print(my_data.__class__)
        msg.fail("ERROR: patch invalid in converge.py")

    # get the velocities
    u = my_data.get_var("x-velocity")
    v = my_data.get_var("y-velocity")

    myg = my_data.grid

    if (myg.xmin != 0 or myg.xmax != 1 or
        myg.ymin != 0 or myg.ymax != 1):
        msg.fail("ERROR: domain should be a unit square")

    u[:, :] = 1.0 - 2.0*np.cos(2.0*math.pi*myg.x2d)*np.sin(2.0*math.pi*myg.y2d)
    v[:, :] = 1.0 + 2.0*np.sin(2.0*math.pi*myg.x2d)*np.cos(2.0*math.pi*myg.y2d)
Esempio n. 30
0
def initData(my_data):
    """ initialize the Gaussian diffusion problem """

    msg.bold("initializing the Gaussian diffusion problem...")

    rp = my_data.rp

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print "ERROR: patch invalid in diffuse.py"
        print my_data.__class__
        sys.exit()

    phi = my_data.get_var("phi")

    xmin = my_data.grid.xmin
    xmax = my_data.grid.xmax

    ymin = my_data.grid.ymin
    ymax = my_data.grid.ymax

    xctr = 0.5*(xmin + xmax)
    yctr = 0.5*(ymin + ymax)
    
    k = rp.get_param("diffusion.k")
    t_0 = rp.get_param("gaussian.t_0")
    phi_max = rp.get_param("gaussian.phi_max")
    phi_0   = rp.get_param("gaussian.phi_0")

    dist = numpy.sqrt((my_data.grid.x2d - xctr)**2 +
                      (my_data.grid.y2d - yctr)**2)
    
    phi[:,:] = phi_analytic(dist, 0.0, t_0, k, phi_0, phi_max)

    # for later interpretation / analysis, store some auxillary data
    my_data.set_aux("k", k)
    my_data.set_aux("t_0", t_0)
    my_data.set_aux("phi_0", phi_0)
    my_data.set_aux("phi_max", phi_max)
Esempio n. 31
0
def init_data(my_data, rp):
    """ initialize the incompressible converge problem """

    msg.bold("initializing the incompressible converge problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print(my_data.__class__)
        msg.fail("ERROR: patch invalid in converge.py")

    # get the velocities
    u = my_data.get_var("x-velocity")
    v = my_data.get_var("y-velocity")

    myg = my_data.grid

    if (myg.xmin != 0 or myg.xmax != 1 or
        myg.ymin != 0 or myg.ymax != 1):
        msg.fail("ERROR: domain should be a unit square")

    u[:, :] = 1.0 - 2.0*np.cos(2.0*math.pi*myg.x2d)*np.sin(2.0*math.pi*myg.y2d)
    v[:, :] = 1.0 + 2.0*np.sin(2.0*math.pi*myg.x2d)*np.cos(2.0*math.pi*myg.y2d)
def init_data(my_data, rp):
    """ initialize the smooth advection problem """

    msg.bold("initializing the smooth FV advection problem...")

    # make sure that we are passed a valid patch object
    #if not isinstance(my_data, patch.FV2d):
    #    print("ERROR: patch invalid in smooth.py")
    #    print(my_data.__class__)
    #    sys.exit()

    xmin = my_data.grid.xmin
    xmax = my_data.grid.xmax

    ymin = my_data.grid.ymin
    ymax = my_data.grid.ymax

    xctr = 0.5 * (xmin + xmax)
    yctr = 0.5 * (ymin + ymax)

    # we need to initialize the cell-averages, so we will create
    # a finer grid, initialize it, and then average down
    mgf = my_data.grid.fine_like(4)

    # since restrict operates in the data class, we need to
    # create a FV2d object here
    fine_data = fv.FV2d(mgf)
    fine_data.register_var("density", my_data.BCs["density"])
    fine_data.create()

    dens_fine = fine_data.get_var("density")

    dens_fine[:, :] = 1.0 + numpy.exp(-60.0 * ((mgf.x2d - xctr)**2 +
                                               (mgf.y2d - yctr)**2))

    dens = my_data.get_var("density")
    dens[:, :] = fine_data.restrict("density", N=4)
Esempio n. 33
0
def init_data(my_data, rp):
    """ initialize the smooth advection problem """

    msg.bold("initializing the smooth FV advection problem...")

    # make sure that we are passed a valid patch object
    # if not isinstance(my_data, patch.FV2d):
    #    print("ERROR: patch invalid in smooth.py")
    #    print(my_data.__class__)
    #    sys.exit()

    xmin = my_data.grid.xmin
    xmax = my_data.grid.xmax

    ymin = my_data.grid.ymin
    ymax = my_data.grid.ymax

    xctr = 0.5*(xmin + xmax)
    yctr = 0.5*(ymin + ymax)

    # we need to initialize the cell-averages, so we will create
    # a finer grid, initialize it, and then average down
    mgf = my_data.grid.fine_like(4)

    # since restrict operates in the data class, we need to
    # create a FV2d object here
    fine_data = fv.FV2d(mgf)
    fine_data.register_var("density", my_data.BCs["density"])
    fine_data.create()

    dens_fine = fine_data.get_var("density")

    dens_fine[:, :] = 1.0 + numpy.exp(-60.0*((mgf.x2d-xctr)**2 +
                                             (mgf.y2d-yctr)**2))

    dens = my_data.get_var("density")
    dens[:, :] = fine_data.restrict("density", N=4)
Esempio n. 34
0
def init_data(my_data, rp):
    """ initialize the quadrant problem """

    msg.bold("initializing the quadrant problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print("ERROR: patch invalid in quad.py")
        print(my_data.__class__)
        sys.exit()

    # get the density, momenta, and energy as separate variables
    dens = my_data.get_var("density")
    xmom = my_data.get_var("x-momentum")
    ymom = my_data.get_var("y-momentum")
    ener = my_data.get_var("energy")

    # initialize the components, remember, that ener here is
    # rho*eint + 0.5*rho*v**2, where eint is the specific
    # internal energy (erg/g)
    r1 = rp.get_param("quadrant.rho1")
    u1 = rp.get_param("quadrant.u1")
    v1 = rp.get_param("quadrant.v1")
    p1 = rp.get_param("quadrant.p1")

    r2 = rp.get_param("quadrant.rho2")
    u2 = rp.get_param("quadrant.u2")
    v2 = rp.get_param("quadrant.v2")
    p2 = rp.get_param("quadrant.p2")

    r3 = rp.get_param("quadrant.rho3")
    u3 = rp.get_param("quadrant.u3")
    v3 = rp.get_param("quadrant.v3")
    p3 = rp.get_param("quadrant.p3")

    r4 = rp.get_param("quadrant.rho4")
    u4 = rp.get_param("quadrant.u4")
    v4 = rp.get_param("quadrant.v4")
    p4 = rp.get_param("quadrant.p4")

    cx = rp.get_param("quadrant.cx")
    cy = rp.get_param("quadrant.cy")
    
    gamma = rp.get_param("eos.gamma")
    
    # there is probably an easier way to do this, but for now, we
    # will just do an explicit loop.  Also, we really want to set
    # the pressue and get the internal energy from that, and then
    # compute the total energy (which is what we store).  For now
    # we will just fake this
    
    myg = my_data.grid

    iq1 = np.logical_and(myg.x2d >= cx, myg.y2d >= cy)
    iq2 = np.logical_and(myg.x2d < cx,  myg.y2d >= cy)
    iq3 = np.logical_and(myg.x2d < cx,  myg.y2d < cy)
    iq4 = np.logical_and(myg.x2d >= cx, myg.y2d < cy)    
    
    # quadrant 1
    dens.d[iq1] = r1
    xmom.d[iq1] = r1*u1
    ymom.d[iq1] = r1*v1
    ener.d[iq1] = p1/(gamma - 1.0) + 0.5*r1*(u1*u1 + v1*v1)
                
    # quadrant 2
    dens.d[iq2] = r2
    xmom.d[iq2] = r2*u2
    ymom.d[iq2] = r2*v2
    ener.d[iq2] = p2/(gamma - 1.0) + 0.5*r2*(u2*u2 + v2*v2)

    # quadrant 3
    dens.d[iq3] = r3
    xmom.d[iq3] = r3*u3
    ymom.d[iq3] = r3*v3
    ener.d[iq3] = p3/(gamma - 1.0) + 0.5*r3*(u3*u3 + v3*v3)

    # quadrant 4
    dens.d[iq4] = r4
    xmom.d[iq4] = r4*u4
    ymom.d[iq4] = r4*v4
    ener.d[iq4] = p4/(gamma - 1.0) + 0.5*r4*(u4*u4 + v4*v4)
Esempio n. 35
0
def init_data(my_data, base, rp):
    """ initialize the bubble problem """

    msg.bold("initializing the bubble problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print("ERROR: patch invalid in bubble.py")
        print(my_data.__class__)
        sys.exit()

    # get the density and velocities
    dens = my_data.get_var("density")
    xvel = my_data.get_var("x-velocity")
    yvel = my_data.get_var("y-velocity")
    eint = my_data.get_var("eint")

    grav = rp.get_param("lm-atmosphere.grav")

    gamma = rp.get_param("eos.gamma")

    scale_height = rp.get_param("bubble.scale_height")
    dens_base = rp.get_param("bubble.dens_base")
    dens_cutoff = rp.get_param("bubble.dens_cutoff")

    x_pert = rp.get_param("bubble.x_pert")
    y_pert = rp.get_param("bubble.y_pert")
    r_pert = rp.get_param("bubble.r_pert")
    pert_amplitude_factor = rp.get_param("bubble.pert_amplitude_factor")

    # initialize the components -- we'll get a pressure too
    # but that is used only to initialize the base state
    xvel[:, :] = 0.0
    yvel[:, :] = 0.0
    dens[:, :] = dens_cutoff

    # set the density to be stratified in the y-direction
    myg = my_data.grid
    pres = myg.scratch_array()

    j = myg.jlo
    for j in range(myg.jlo, myg.jhi + 1):
        dens[:, j] = max(dens_base * numpy.exp(-myg.y[j] / scale_height),
                         dens_cutoff)

    cs2 = scale_height * abs(grav)

    # set the pressure (P = cs2*dens)
    pres = cs2 * dens
    eint[:, :] = pres / (gamma - 1.0) / dens

    # boost the specific internal energy, keeping the pressure
    # constant, by dropping the density
    r = numpy.sqrt((myg.x2d - x_pert)**2 + (myg.y2d - y_pert)**2)

    idx = r <= r_pert
    eint[idx] = eint[idx] * pert_amplitude_factor
    dens[idx] = pres[idx] / (eint[idx] * (gamma - 1.0))

    # do the base state
    base["rho0"].d[:] = numpy.mean(dens, axis=0)
    base["p0"].d[:] = numpy.mean(pres, axis=0)

    # redo the pressure via HSE
    for j in range(myg.jlo + 1, myg.jhi):
        base["p0"].d[j] = base["p0"].d[j - 1] + 0.5 * myg.dy * (
            base["rho0"].d[j] + base["rho0"].d[j - 1]) * grav
Esempio n. 36
0
File: kh.py Progetto: zingale/pyro2
def init_data(my_data, rp):
    """ initialize the Kelvin-Helmholtz problem """

    msg.bold("initializing the Kelvin-Helmholtz problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print(my_data.__class__)
        msg.fail("ERROR: patch invalid in kh.py")

    # get the heightity, momenta, and energy as separate variables
    height = my_data.get_var("height")
    xmom = my_data.get_var("x-momentum")
    ymom = my_data.get_var("y-momentum")
    X = my_data.get_var("fuel")

    # initialize the components, remember, that ener here is h*eint
    # + 0.5*h*v**2, where eint is the specific internal energy
    # (erg/g)
    height[:, :] = 1.0
    xmom[:, :] = 0.0
    ymom[:, :] = 0.0

    h_1 = rp.get_param("kh.h_1")
    v_1 = rp.get_param("kh.v_1")
    h_2 = rp.get_param("kh.h_2")
    v_2 = rp.get_param("kh.v_2")

    myg = my_data.grid

    dy = 0.025
    w0 = 0.01
    vm = 0.5*(v_1 - v_2)
    hm = 0.5*(h_1 - h_2)

    idx1 = myg.y2d < 0.25
    idx2 = np.logical_and(myg.y2d >= 0.25, myg.y2d < 0.5)
    idx3 = np.logical_and(myg.y2d >= 0.5, myg.y2d < 0.75)
    idx4 = myg.y2d >= 0.75

    # we will initialize momemum as velocity for now

    # lower quarter
    height[idx1] = h_1 - hm*np.exp((myg.y2d[idx1] - 0.25)/dy)
    xmom[idx1] = v_1 - vm*np.exp((myg.y2d[idx1] - 0.25)/dy)
    X[idx1] = 1 - 0.5*np.exp((myg.y2d[idx1] - 0.25)/dy)

    # second quarter
    height[idx2] = h_2 + hm*np.exp((0.25 - myg.y2d[idx2])/dy)
    xmom[idx2] = v_2 + vm*np.exp((0.25 - myg.y2d[idx2])/dy)
    X[idx2] = 0.5*np.exp((0.25 - myg.y2d[idx2])/dy)

    # third quarter
    height[idx3] = h_2 + hm*np.exp((myg.y2d[idx3] - 0.75)/dy)
    xmom[idx3] = v_2 + vm*np.exp((myg.y2d[idx3] - 0.75)/dy)
    X[idx3] = 0.5*np.exp((myg.y2d[idx3] - 0.75)/dy)

    # fourth quarter
    height[idx4] = h_1 - hm*np.exp((0.75 - myg.y2d[idx4])/dy)
    xmom[idx4] = v_1 - vm*np.exp((0.75 - myg.y2d[idx4])/dy)
    X[idx4] = 1 - 0.5*np.exp((0.75 - myg.y2d[idx4])/dy)

    # upper half
    xmom[:, :] *= height
    ymom[:, :] = height * w0 * np.sin(4*np.pi*myg.x2d)
    X[:, :] *= height
Esempio n. 37
0
def init_data(my_data, rp):
    """ initialize the double Mach reflection problem """

    msg.bold("initializing the double Mach reflection problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print("ERROR: patch invalid in ramp.py")
        print(my_data.__class__)
        sys.exit()

    # get the density, momenta, and energy as separate variables
    dens = my_data.get_var("density")
    xmom = my_data.get_var("x-momentum")
    ymom = my_data.get_var("y-momentum")
    ener = my_data.get_var("energy")

    # initialize the components, remember, that ener here is
    # rho*eint + 0.5*rho*v**2, where eint is the specific
    # internal energy (erg/g)

    r_l = rp.get_param("ramp.rhol")
    u_l = rp.get_param("ramp.ul")
    v_l = rp.get_param("ramp.vl")
    p_l = rp.get_param("ramp.pl")

    r_r = rp.get_param("ramp.rhor")
    u_r = rp.get_param("ramp.ur")
    v_r = rp.get_param("ramp.vr")
    p_r = rp.get_param("ramp.pr")

    gamma = rp.get_param("eos.gamma")

    energy_l = p_l / (gamma - 1.0) + 0.5 * r_l * (u_l * u_l + v_l * v_l)
    energy_r = p_r / (gamma - 1.0) + 0.5 * r_r * (u_r * u_r + v_r * v_r)

    # there is probably an easier way to do this, but for now, we
    # will just do an explicit loop.  Also, we really want to set
    # the pressue and get the internal energy from that, and then
    # compute the total energy (which is what we store).  For now
    # we will just fake this

    myg = my_data.grid
    dens[:, :] = 1.4

    for j in range(myg.jlo, myg.jhi + 1):
        cy_up = myg.y[j] + 0.5 * myg.dy * math.sqrt(3)
        cy_down = myg.y[j] - 0.5 * myg.dy * math.sqrt(3)
        cy = np.array([cy_down, cy_up])

        for i in range(myg.ilo, myg.ihi + 1):
            dens[i, j] = 0.0
            xmom[i, j] = 0.0
            ymom[i, j] = 0.0
            ener[i, j] = 0.0

            sf_up = math.tan(math.pi / 3.0) * (
                myg.x[i] + 0.5 * myg.dx * math.sqrt(3) - 1.0 / 6.0)
            sf_down = math.tan(math.pi / 3.0) * (
                myg.x[i] - 0.5 * myg.dx * math.sqrt(3) - 1.0 / 6.0)
            sf = np.array([sf_down, sf_up])  # initial shock front

            for y in cy:
                for shockfront in sf:
                    if y >= shockfront:
                        dens[i, j] = dens[i, j] + 0.25 * r_l
                        xmom[i, j] = xmom[i, j] + 0.25 * r_l * u_l
                        ymom[i, j] = ymom[i, j] + 0.25 * r_l * v_l
                        ener[i, j] = ener[i, j] + 0.25 * energy_l
                    else:
                        dens[i, j] = dens[i, j] + 0.25 * r_r
                        xmom[i, j] = xmom[i, j] + 0.25 * r_r * u_r
                        ymom[i, j] = ymom[i, j] + 0.25 * r_r * v_r
                        ener[i, j] = ener[i, j] + 0.25 * energy_r
Esempio n. 38
0
def init_data(my_data, rp):
    """ initialize the bubble problem """

    msg.bold("initializing the bubble problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print("ERROR: patch invalid in bubble.py")
        print(my_data.__class__)
        sys.exit()

    # get the density, momenta, and energy as separate variables
    dens = my_data.get_var("density")
    xmom = my_data.get_var("x-momentum")
    ymom = my_data.get_var("y-momentum")
    ener = my_data.get_var("energy")

    gamma = rp.get_param("eos.gamma")

    grav = rp.get_param("compressible.grav")

    scale_height = rp.get_param("bubble.scale_height")
    dens_base = rp.get_param("bubble.dens_base")
    dens_cutoff = rp.get_param("bubble.dens_cutoff")

    x_pert = rp.get_param("bubble.x_pert")
    y_pert = rp.get_param("bubble.y_pert")
    r_pert = rp.get_param("bubble.r_pert")
    pert_amplitude_factor = rp.get_param("bubble.pert_amplitude_factor")

    # initialize the components, remember, that ener here is
    # rho*eint + 0.5*rho*v**2, where eint is the specific
    # internal energy (erg/g)
    xmom[:,:] = 0.0
    ymom[:,:] = 0.0
    dens[:,:] = dens_cutoff

    # set the density to be stratified in the y-direction
    myg = my_data.grid

    p = myg.scratch_array()

    cs2 = scale_height*abs(grav)

    for j in range(myg.jlo, myg.jhi+1):
        dens[:,j] = max(dens_base*np.exp(-myg.y[j]/scale_height),
                        dens_cutoff)
        if j == myg.jlo:
            p[:,j] = dens[:,j]*cs2
        else:
            p[:,j] = p[:,j-1] + 0.5*myg.dy*(dens[:,j] + dens[:,j-1])*grav


    # set the energy (P = cs2*dens)
    ener[:,:] = p[:,:]/(gamma - 1.0) + \
                0.5*(xmom[:,:]**2 + ymom[:,:]**2)/dens[:,:]


    r = np.sqrt((myg.x2d - x_pert)**2  + (myg.y2d - y_pert)**2)
    idx = r <= r_pert

    # boost the specific internal energy, keeping the pressure
    # constant, by dropping the density
    eint = (ener[idx] - 0.5*(xmom[idx]**2 - ymom[idx]**2)/dens[idx])/dens[idx]

    pres = dens[idx]*eint*(gamma - 1.0)

    eint = eint*pert_amplitude_factor
    dens[idx] = pres/(eint*(gamma - 1.0))

    ener[idx] = dens[idx]*eint + 0.5*(xmom[idx]**2 + ymom[idx]**2)/dens[idx]
Esempio n. 39
0
def init_data(my_data, rp):
    """ initialize the sedov problem """

    msg.bold("initializing the logo problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print("ERROR: patch invalid in sedov.py")
        print(my_data.__class__)
        sys.exit()

    # create the logo
    myg = my_data.grid

    fig = plt.figure(2, (0.64, 0.64), dpi=100 * myg.nx / 64)
    fig.add_subplot(111)

    fig.text(0.5,
             0.5,
             "pyro",
             transform=fig.transFigure,
             fontsize="16",
             horizontalalignment="center",
             verticalalignment="center")

    plt.axis("off")

    fig.canvas.draw()
    data = np.fromstring(fig.canvas.tostring_rgb(), dtype=np.uint8, sep='')
    data = data.reshape(fig.canvas.get_width_height()[::-1] + (3, ))

    logo = np.rot90(np.rot90(np.rot90((256 - data[:, :, 1]) / 255.0)))

    # get the height, momenta as separate variables
    h = my_data.get_var("height")
    xmom = my_data.get_var("x-momentum")
    ymom = my_data.get_var("y-momentum")
    X = my_data.get_var("fuel")

    myg = my_data.grid

    # initialize the components
    h[:, :] = 1.0
    xmom[:, :] = 0.0
    ymom[:, :] = 0.0

    # set the height in the logo zones to be really large
    logo_h = 2

    h.v()[:, :] = logo[:, :] * logo_h

    X.v()[:, :] = logo[:, :]

    corner_height = 2

    # explosion
    h[myg.ilo, myg.jlo] = corner_height
    h[myg.ilo, myg.jhi] = corner_height
    h[myg.ihi, myg.jlo] = corner_height
    h[myg.ihi, myg.jhi] = corner_height

    v = 1

    xmom[myg.ilo, myg.jlo] = v
    xmom[myg.ilo, myg.jhi] = v
    xmom[myg.ihi, myg.jlo] = -v
    xmom[myg.ihi, myg.jhi] = -v

    ymom[myg.ilo, myg.jlo] = v
    ymom[myg.ilo, myg.jhi] = -v
    ymom[myg.ihi, myg.jlo] = v
    ymom[myg.ihi, myg.jhi] = -v

    X[:, :] *= h
Esempio n. 40
0
def init_data(my_data, rp):
    """ initialize the quadrant problem """

    msg.bold("initializing the quadrant problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print("ERROR: patch invalid in quad.py")
        print(my_data.__class__)
        sys.exit()

    # get the density, momenta, and energy as separate variables
    dens = my_data.get_var("density")
    xmom = my_data.get_var("x-momentum")
    ymom = my_data.get_var("y-momentum")
    ener = my_data.get_var("energy")

    # initialize the components, remember, that ener here is
    # rho*eint + 0.5*rho*v**2, where eint is the specific
    # internal energy (erg/g)
    r1 = rp.get_param("quadrant.rho1")
    u1 = rp.get_param("quadrant.u1")
    v1 = rp.get_param("quadrant.v1")
    p1 = rp.get_param("quadrant.p1")

    r2 = rp.get_param("quadrant.rho2")
    u2 = rp.get_param("quadrant.u2")
    v2 = rp.get_param("quadrant.v2")
    p2 = rp.get_param("quadrant.p2")

    r3 = rp.get_param("quadrant.rho3")
    u3 = rp.get_param("quadrant.u3")
    v3 = rp.get_param("quadrant.v3")
    p3 = rp.get_param("quadrant.p3")

    r4 = rp.get_param("quadrant.rho4")
    u4 = rp.get_param("quadrant.u4")
    v4 = rp.get_param("quadrant.v4")
    p4 = rp.get_param("quadrant.p4")

    cx = rp.get_param("quadrant.cx")
    cy = rp.get_param("quadrant.cy")

    gamma = rp.get_param("eos.gamma")

    # there is probably an easier way to do this, but for now, we
    # will just do an explicit loop.  Also, we really want to set
    # the pressue and get the internal energy from that, and then
    # compute the total energy (which is what we store).  For now
    # we will just fake this

    myg = my_data.grid

    iq1 = np.logical_and(myg.x2d >= cx, myg.y2d >= cy)
    iq2 = np.logical_and(myg.x2d < cx, myg.y2d >= cy)
    iq3 = np.logical_and(myg.x2d < cx, myg.y2d < cy)
    iq4 = np.logical_and(myg.x2d >= cx, myg.y2d < cy)

    # quadrant 1
    dens.d[iq1] = r1
    xmom.d[iq1] = r1 * u1
    ymom.d[iq1] = r1 * v1
    ener.d[iq1] = p1 / (gamma - 1.0) + 0.5 * r1 * (u1 * u1 + v1 * v1)

    # quadrant 2
    dens.d[iq2] = r2
    xmom.d[iq2] = r2 * u2
    ymom.d[iq2] = r2 * v2
    ener.d[iq2] = p2 / (gamma - 1.0) + 0.5 * r2 * (u2 * u2 + v2 * v2)

    # quadrant 3
    dens.d[iq3] = r3
    xmom.d[iq3] = r3 * u3
    ymom.d[iq3] = r3 * v3
    ener.d[iq3] = p3 / (gamma - 1.0) + 0.5 * r3 * (u3 * u3 + v3 * v3)

    # quadrant 4
    dens.d[iq4] = r4
    xmom.d[iq4] = r4 * u4
    ymom.d[iq4] = r4 * v4
    ener.d[iq4] = p4 / (gamma - 1.0) + 0.5 * r4 * (u4 * u4 + v4 * v4)
Esempio n. 41
0
def init_data(my_data, rp):
    """ initialize the sedov problem """

    msg.bold("initializing the sedov problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print("ERROR: patch invalid in sedov.py")
        print(my_data.__class__)
        sys.exit()

    # get the density, momenta, and energy as separate variables
    dens = my_data.get_var("density")
    xmom = my_data.get_var("x-momentum")
    ymom = my_data.get_var("y-momentum")
    ener = my_data.get_var("energy")

    # initialize the components, remember, that ener here is rho*eint
    # + 0.5*rho*v**2, where eint is the specific internal energy
    # (erg/g)
    dens[:, :] = 1.0
    xmom[:, :] = 0.0
    ymom[:, :] = 0.0

    E_sedov = 1.0

    r_init = rp.get_param("sedov.r_init")

    gamma = rp.get_param("eos.gamma")
    pi = math.pi

    xmin = rp.get_param("mesh.xmin")
    xmax = rp.get_param("mesh.xmax")

    ymin = rp.get_param("mesh.ymin")
    ymax = rp.get_param("mesh.ymax")

    xctr = 0.5*(xmin + xmax)
    yctr = 0.5*(ymin + ymax)

    # initialize the pressure by putting the explosion energy into a
    # volume of constant pressure.  Then compute the energy in a zone
    # from this.
    nsub = 4

    dist = np.sqrt((my_data.grid.x2d - xctr)**2 +
                   (my_data.grid.y2d - yctr)**2)

    p = 1.e-5
    ener[:, :] = p/(gamma - 1.0)

    for i, j in np.transpose(np.nonzero(dist < 2.0*r_init)):

        pzone = 0.0

        for ii in range(nsub):
            for jj in range(nsub):

                xsub = my_data.grid.xl[i] + (my_data.grid.dx/nsub)*(ii + 0.5)
                ysub = my_data.grid.yl[j] + (my_data.grid.dy/nsub)*(jj + 0.5)

                dist = np.sqrt((xsub - xctr)**2 +
                               (ysub - yctr)**2)

                if dist <= r_init:
                    p = (gamma - 1.0)*E_sedov/(pi*r_init*r_init)
                else:
                    p = 1.e-5

                pzone += p

        p = pzone/(nsub*nsub)

        ener[i, j] = p/(gamma - 1.0)
Esempio n. 42
0
def init_data(my_data, rp):
    """ initialize the sod problem """

    msg.bold("initializing the sod problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print("ERROR: patch invalid in sod.py")
        print(my_data.__class__)
        sys.exit()


    # get the sod parameters
    dens_left = rp.get_param("sod.dens_left")
    dens_right = rp.get_param("sod.dens_right")

    u_left = rp.get_param("sod.u_left")
    u_right = rp.get_param("sod.u_right")

    p_left = rp.get_param("sod.p_left")
    p_right = rp.get_param("sod.p_right")
    

    # get the density, momenta, and energy as separate variables
    dens = my_data.get_var("density")
    xmom = my_data.get_var("x-momentum")
    ymom = my_data.get_var("y-momentum")
    ener = my_data.get_var("energy")

    # initialize the components, remember, that ener here is rho*eint
    # + 0.5*rho*v**2, where eint is the specific internal energy
    # (erg/g)
    xmin = rp.get_param("mesh.xmin")
    xmax = rp.get_param("mesh.xmax")

    ymin = rp.get_param("mesh.ymin")
    ymax = rp.get_param("mesh.ymax")

    gamma = rp.get_param("eos.gamma")

    direction = rp.get_param("sod.direction")
    
    xctr = 0.5*(xmin + xmax)
    yctr = 0.5*(ymin + ymax)

    myg = my_data.grid
    
    if direction == "x":

        # left
        idxl = myg.x2d <= xctr

        dens.d[idxl] = dens_left
        xmom.d[idxl] = dens_left*u_left
        ymom.d[idxl] = 0.0
        ener.d[idxl] = p_left/(gamma - 1.0) + 0.5*xmom.d[idxl]*u_left

        # right
        idxr = myg.x2d > xctr
                
        dens.d[idxr] = dens_right
        xmom.d[idxr] = dens_right*u_right
        ymom.d[idxr] = 0.0
        ener.d[idxr] = p_right/(gamma - 1.0) + 0.5*xmom.d[idxr]*u_right

    else:

        # bottom
        idxb = myg.y2d <= yctr

        dens.d[idxb] = dens_left
        xmom.d[idxb] = 0.0
        ymom.d[idxb] = dens_left*u_left
        ener.d[idxb] = p_left/(gamma - 1.0) + 0.5*ymom.d[idxb]*u_left
                
        # top
        idxt = myg.y2d > yctr
        
        dens.d[idxt] = dens_right
        xmom.d[idxt] = 0.0
        ymom.d[idxt] = dens_right*u_right
        ener.d[idxt] = p_right/(gamma - 1.0) + 0.5*ymom.d[idxt]*u_right
Esempio n. 43
0
def init_data(my_data, base, rp):
    """ initialize the bubble problem """

    msg.bold("initializing the bubble problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print("ERROR: patch invalid in bubble.py")
        print(my_data.__class__)
        sys.exit()

    # get the density and velocities
    dens = my_data.get_var("density")
    xvel = my_data.get_var("x-velocity")
    yvel = my_data.get_var("y-velocity")
    eint = my_data.get_var("eint")

    grav = rp.get_param("lm-atmosphere.grav")

    gamma = rp.get_param("eos.gamma")

    scale_height = rp.get_param("bubble.scale_height")
    dens_base = rp.get_param("bubble.dens_base")
    dens_cutoff = rp.get_param("bubble.dens_cutoff")

    x_pert = rp.get_param("bubble.x_pert")
    y_pert = rp.get_param("bubble.y_pert")
    r_pert = rp.get_param("bubble.r_pert")
    pert_amplitude_factor = rp.get_param("bubble.pert_amplitude_factor")

    # initialize the components -- we'll get a pressure too
    # but that is used only to initialize the base state
    xvel[:,:] = 0.0
    yvel[:,:] = 0.0
    dens[:,:] = dens_cutoff

    # set the density to be stratified in the y-direction
    myg = my_data.grid
    pres = myg.scratch_array()

    j = myg.jlo
    while j <= myg.jhi:
        dens[:,j] = max(dens_base*numpy.exp(-myg.y[j]/scale_height),
                        dens_cutoff)
        j += 1

    cs2 = scale_height*abs(grav)

    # set the pressure (P = cs2*dens)
    pres = cs2*dens[:,:]

    
    i = myg.ilo
    while i <= myg.ihi:

        j = myg.jlo
        while j <= myg.jhi:

            r = numpy.sqrt((myg.x[i] - x_pert)**2  + (myg.y[j] - y_pert)**2)

            if (r <= r_pert):
                # boost the specific internal energy, keeping the pressure
                # constant, by dropping the density
                eint[i,j] = pres[i,j]/(gamma - 1.0)/dens[i,j]
                eint[i,j] = eint[i,j]*pert_amplitude_factor

                dens[i,j] = pres[i,j]/(eint[i,j]*(gamma - 1.0))

            j += 1
        i += 1
        
    

    # do the base state
    base["rho0"] = numpy.mean(dens, axis=0)
    base["p0"] = numpy.mean(pres, axis=0)

    # redo the pressure via HSE
    j = myg.jlo+1
    while j <= myg.jhi:
        base["p0"][j] = base["p0"][j-1] + 0.5*myg.dy*(base["rho0"][j] + base["rho0"][j-1])*grav
        j += 1
Esempio n. 44
0
File: kh.py Progetto: nykon/pyro2
def init_data(my_data, rp):
    """ initialize the Kelvin-Helmholtz problem """

    msg.bold("initializing the sedov problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print(my_data.__class__)
        msg.fail("ERROR: patch invalid in sedov.py")

    # get the density, momenta, and energy as separate variables
    dens = my_data.get_var("density")
    xmom = my_data.get_var("x-momentum")
    ymom = my_data.get_var("y-momentum")
    ener = my_data.get_var("energy")

    # initialize the components, remember, that ener here is rho*eint
    # + 0.5*rho*v**2, where eint is the specific internal energy
    # (erg/g)
    dens[:, :] = 1.0
    xmom[:, :] = 0.0
    ymom[:, :] = 0.0

    E_sedov = 1.0

    rho_1 = rp.get_param("kh.rho_1")
    v_1 = rp.get_param("kh.v_1")
    rho_2 = rp.get_param("kh.rho_2")
    v_2 = rp.get_param("kh.v_2")

    gamma = rp.get_param("eos.gamma")

    xmin = rp.get_param("mesh.xmin")
    xmax = rp.get_param("mesh.xmax")

    ymin = rp.get_param("mesh.ymin")
    ymax = rp.get_param("mesh.ymax")

    xctr = 0.5 * (xmin + xmax)
    yctr = 0.5 * (ymin + ymax)

    L_x = xmax - xmin

    # initialize the pressure by putting the explosion energy into a
    # volume of constant pressure.  Then compute the energy in a zone
    # from this.
    nsub = 4

    i = my_data.grid.ilo
    while i <= my_data.grid.ihi:

        j = my_data.grid.jlo
        while j <= my_data.grid.jhi:

            if my_data.grid.y[j] < yctr + 0.01 * math.sin(10.0 * math.pi * my_data.grid.x[i] / L_x):

                # lower half
                dens[i, j] = rho_1
                xmom[i, j] = rho_1 * v_1
                ymom[i, j] = 0.0

            else:

                # upper half
                dens[i, j] = rho_2
                xmom[i, j] = rho_2 * v_2
                ymom[i, j] = 0.0

            p = 1.0
            ener[i, j] = p / (gamma - 1.0) + 0.5 * (xmom[i, j] ** 2 + ymom[i, j] ** 2) / dens[i, j]

            j += 1
        i += 1
def initData(myPatch):
    """ initialize the Rayleigh-Taylor instability problem """

    msg.bold("initializing the Rayleigh-Taylor instability problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(myPatch, patch.ccData2d):
        print "ERROR: patch invalid in raytay.py"
        print myPatch.__class__
        sys.exit()

    # get the density, momenta, and energy as separate variables
    dens = myPatch.getVarPtr("density")
    xmom = myPatch.getVarPtr("x-momentum")
    ymom = myPatch.getVarPtr("y-momentum")
    ener = myPatch.getVarPtr("energy")

    # get the other input parameters for the problem
    gamma = runparams.getParam("eos.gamma")
    grav = runparams.getParam("compressible.grav")
    dens_up = runparams.getParam("raytay.dens_up")
    dens_down = runparams.getParam("raytay.dens_down")
    A = runparams.getParam("raytay.pert_amplitude_factor")
    p0 = runparams.getParam("raytay.pressure_bottom")
    sigma = runparams.getParam("raytay.sigma")


    # get the grid parameters    
    xmin = runparams.getParam("mesh.xmin")
    xmax = runparams.getParam("mesh.xmax")
    ymin = runparams.getParam("mesh.ymin")
    ymax = runparams.getParam("mesh.ymax")   
    
    yctr = 0.5*(ymin + ymax)


    # initialize the components, remember, that ener here is
    # rho*eint + 0.5*rho*v**2, where eint is the specific
    # internal energy (erg/g)
    xmom[:,:] = 0.0
    ymom[:,:] = 0.0
    dens[:,:] = 0.0
    
    Lx = xmax - xmin

    # set the density and energy to be stratified in the y-direction
    myg = myPatch.grid

    j = myg.jlo
    while j <= myg.jhi:
        if myg.y[j] < yctr :
            dens[:,j] = dens_down
            pres = dens_down*grav*myg.y[j] + p0 
            ener[:,j] = pres/(gamma - 1.0) #+ 0.5*(xmom[:,j]**2 + ymom[:,j]**2)/dens_down
        else:
            dens[:,j] = dens_up
            pres = p0 + dens_down*grav*yctr + dens_up*grav*(myg.y[j] - yctr)
            ener[:,j] = pres/(gamma - 1.0) #+ 0.5*(xmom[:,j]**2 + ymom[:,j]**2)/dens_up
        j += 1


    i = myg.ilo
    while i <= myg.ihi:

        j = myg.jlo
        while j <= myg.jhi:

            v_pert = A*numpy.sin(2.0*numpy.pi*myg.x[i]/Lx)*numpy.exp( - (( myg.y[j]-yctr)/sigma)**2 ) 
            
            # momentum
            ymom[i,j] = dens[i,j]*v_pert

            # internal energy
            ener[i,j] += 0.5*(xmom[i,j]**2 - ymom[i,j]**2)/dens[i,j]
                                
            j += 1
        i += 1
Esempio n. 46
0
def init_data(my_data, rp):
    """ initialize the sedov problem """

    msg.bold("initializing the sedov problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print("ERROR: patch invalid in sedov.py")
        print(my_data.__class__)
        sys.exit()

    # get the density, momenta, and energy as separate variables
    dens = my_data.get_var("density")
    xmom = my_data.get_var("x-momentum")
    ymom = my_data.get_var("y-momentum")
    ener = my_data.get_var("energy")

    # initialize the components, remember, that ener here is rho*eint
    # + 0.5*rho*v**2, where eint is the specific internal energy
    # (erg/g)
    dens[:, :] = 1.0
    xmom[:, :] = 0.0
    ymom[:, :] = 0.0

    E_sedov = 1.0

    r_init = rp.get_param("sedov.r_init")

    gamma = rp.get_param("eos.gamma")
    pi = math.pi

    xmin = rp.get_param("mesh.xmin")
    xmax = rp.get_param("mesh.xmax")

    ymin = rp.get_param("mesh.ymin")
    ymax = rp.get_param("mesh.ymax")

    xctr = 0.5 * (xmin + xmax)
    yctr = 0.5 * (ymin + ymax)

    # initialize the pressure by putting the explosion energy into a
    # volume of constant pressure.  Then compute the energy in a zone
    # from this.
    nsub = rp.get_param("sedov.nsub")

    dist = np.sqrt((my_data.grid.x2d - xctr)**2 + (my_data.grid.y2d - yctr)**2)

    p = 1.e-5
    ener[:, :] = p / (gamma - 1.0)

    for i, j in np.transpose(np.nonzero(dist < 2.0 * r_init)):

        xsub = my_data.grid.xl[i] + (my_data.grid.dx /
                                     nsub) * (np.arange(nsub) + 0.5)
        ysub = my_data.grid.yl[j] + (my_data.grid.dy /
                                     nsub) * (np.arange(nsub) + 0.5)

        xx, yy = np.meshgrid(xsub, ysub, indexing="ij")

        dist = np.sqrt((xx - xctr)**2 + (yy - yctr)**2)

        n_in_pert = np.count_nonzero(dist <= r_init)

        p = n_in_pert*(gamma - 1.0)*E_sedov/(pi*r_init*r_init) + \
            (nsub*nsub - n_in_pert)*1.e-5

        p = p / (nsub * nsub)

        ener[i, j] = p / (gamma - 1.0)
Esempio n. 47
0
def init_data(my_data, rp):
    """ initialize the vortex problem """

    msg.bold("initializing the vortex problem...")
    
    
    
    
    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print("ERROR: patch invalid in vortex.py")
        print(my_data.__class__)
        sys.exit()

    # get the density, momenta, and energy as separate variables
    dens = my_data.get_var("density")
    xmom = my_data.get_var("x-momentum")
    ymom = my_data.get_var("y-momentum")
    ener = my_data.get_var("energy")

    gamma = rp.get_param("eos.gamma")

    p0 = rp.get_param("vortex.p0")
    t_r = rp.get_param("vortex.t_r")
    mach = rp.get_param("vortex.mach")


    # initialize the components, remember, that ener here is
    # rho*eint + 0.5*rho*v**2, where eint is the specific
    # internal energy (erg/g)
    xmom.d[:,:] = 0.0
    ymom.d[:,:] = 0.0
    dens.d[:,:] = 0.0

    # set the density to be stratified in the y-direction
    myg = my_data.grid

    x_c = 0.5*(myg.xmin + myg.xmax)
    y_c = 0.5*(myg.ymin + myg.ymax)

    p = myg.scratch_array()

    dens.d[:,:] = 1.0
    
    nsub = 4
    
    j = myg.jlo
    while j <= myg.jhi:
        i = myg.ilo
        while i <= myg.ihi:

            uzone = 0.0
            vzone = 0.0
            pzone = 0.0

            for ii in range(nsub):
                for jj in range(nsub):
                    
                    xsub = my_data.grid.xl[i] + (my_data.grid.dx/nsub)*(ii + 0.5)
                    ysub = my_data.grid.yl[j] + (my_data.grid.dy/nsub)*(jj + 0.5)

            #initialize vortex problem
                    r=np.sqrt((xsub-x_c)**2 + (ysub-y_c)**2)
           
           
            # phi_hat = -np.sin(phi)*x_hat+cos(phi)*y_hat    
   
                    q_r=(0.4*np.pi)/t_r       
    
                    if r< 0.2:
                        u_phi = 5*r
                    elif r < 0.4:
                        u_phi = 2.0-5.0*r
                    else:
                        u_phi = 0

                    u = -q_r*u_phi*((myg.y[j]-y_c)/r)
                    v = q_r*u_phi*((myg.x[i]-x_c)/r)
                    
                    uzone += u
                    vzone += v


            
                    p_0 = (dens.d[i,j]/(gamma*(mach)**2)-(1.0/2.0)) #u_phimax is 1
  
                    if r<0.2:
                        p_r = p_0+(25.0/2)*(r**2)
                    elif r < 0.4:
                        p_r = p_0 + (25.0/2)*(r**2) + 4*(1.0-5.0*r-math.log(0.2)+math.log(r))
                    else:
                        p_r = p_0 - 2.0 + 4.0*math.log(2.0)
            
                    pzone += p_r

            u = uzone/(nsub*nsub)
            v = vzone/(nsub*nsub)

            xmom.d[i,j] = dens.d[i,j]*u
            ymom.d[i,j] = dens.d[i,j]*v


            p.d[i,j] = pzone/(nsub*nsub)

            i += 1
        j += 1


    # set the energy (P = cs2*dens)
    ener.d[:,:] = p.d[:,:]/(gamma - 1.0) + \
        0.5*(xmom.d[:,:]**2 + ymom.d[:,:]**2)/dens.d[:,:]
Esempio n. 48
0
def doit(solver_name, problem_name, param_file,
         other_commands=None,
         comp_bench=False, make_bench=False):

    msg.bold('pyro ...')

    tc = profile.TimerCollection()

    tm_main = tc.timer("main")
    tm_main.begin()

    # import desired solver under "solver" namespace
    solver = importlib.import_module(solver_name)

    #-------------------------------------------------------------------------
    # runtime parameters
    #-------------------------------------------------------------------------

    # parameter defaults
    rp = runparams.RuntimeParameters()
    rp.load_params("_defaults")
    rp.load_params(solver_name + "/_defaults")

    # problem-specific runtime parameters
    rp.load_params(solver_name + "/problems/_" + problem_name + ".defaults")

    # now read in the inputs file
    if not os.path.isfile(param_file):
        # check if the param file lives in the solver's problems directory
        param_file = solver_name + "/problems/" + param_file
        if not os.path.isfile(param_file):
            msg.fail("ERROR: inputs file does not exist")

    rp.load_params(param_file, no_new=1)

    # and any commandline overrides
    if not other_commands == None:
        rp.command_line_params(other_commands)

    # write out the inputs.auto
    rp.print_paramfile()


    #-------------------------------------------------------------------------
    # initialization
    #-------------------------------------------------------------------------

    # initialize the Simulation object -- this will hold the grid and
    # data and know about the runtime parameters and which problem we
    # are running
    sim = solver.Simulation(solver_name, problem_name, rp, timers=tc)

    sim.initialize()
    sim.preevolve()


    #-------------------------------------------------------------------------
    # evolve
    #-------------------------------------------------------------------------
    init_tstep_factor = rp.get_param("driver.init_tstep_factor")
    max_dt_change = rp.get_param("driver.max_dt_change")
    fix_dt = rp.get_param("driver.fix_dt")

    verbose = rp.get_param("driver.verbose")

    plt.ion()

    sim.cc_data.t = 0.0

    # output the 0th data
    basename = rp.get_param("io.basename")
    sim.cc_data.write("{}{:04d}".format(basename, sim.n))

    dovis = rp.get_param("vis.dovis")
    if dovis:
        plt.figure(num=1, figsize=(8,6), dpi=100, facecolor='w')
        sim.dovis()

    while not sim.finished():

        # fill boundary conditions
        sim.cc_data.fill_BC_all()

        # get the timestep
        if fix_dt > 0.0:
            sim.dt = fix_dt
        else:
            sim.compute_timestep()
            if sim.n == 0:
                sim.dt = init_tstep_factor*sim.dt
            else:
                sim.dt = min(max_dt_change*dt_old, sim.dt)
            dt_old = sim.dt

        if sim.cc_data.t + sim.dt > sim.tmax:
            sim.dt = sim.tmax - sim.cc_data.t

        # evolve for a single timestep
        sim.evolve()

        if verbose > 0: print("%5d %10.5f %10.5f" % (sim.n, sim.cc_data.t, sim.dt))

        # output
        if sim.do_output():
            if verbose > 0: msg.warning("outputting...")
            basename = rp.get_param("io.basename")
            sim.cc_data.write("{}{:04d}".format(basename, sim.n))

        # visualization
        if dovis:
            tm_vis = tc.timer("vis")
            tm_vis.begin()

            sim.dovis()
            store = rp.get_param("vis.store_images")

            if store == 1:
                basename = rp.get_param("io.basename")
                plt.savefig("{}{:04d}.png".format(basename, sim.n))

            tm_vis.end()

    tm_main.end()


    #-------------------------------------------------------------------------
    # benchmarks (for regression testing)
    #-------------------------------------------------------------------------
    # are we comparing to a benchmark?
    if comp_bench:
        compare_file = solver_name + "/tests/" + basename + "%4.4d" % (sim.n)
        msg.warning("comparing to: %s " % (compare_file) )
        try: bench_grid, bench_data = patch.read(compare_file)
        except:
            msg.warning("ERROR openning compare file")
            return "ERROR openning compare file"


        result = compare.compare(sim.cc_data.grid, sim.cc_data, bench_grid, bench_data)

        if result == 0:
            msg.success("results match benchmark\n")
        else:
            msg.warning("ERROR: " + compare.errors[result] + "\n")


    # are we storing a benchmark?
    if make_bench:
        if not os.path.isdir(solver_name + "/tests/"):
            try: os.mkdir(solver_name + "/tests/")
            except:
                msg.fail("ERROR: unable to create the solver's tests/ directory")

        bench_file = solver_name + "/tests/" + basename + "%4.4d" % (sim.n)
        msg.warning("storing new benchmark: {}\n".format(bench_file))
        sim.cc_data.write(bench_file)


    #-------------------------------------------------------------------------
    # final reports
    #-------------------------------------------------------------------------
    if verbose > 0: rp.print_unused_params()
    if verbose > 0: tc.report()

    sim.finalize()

    if comp_bench:
        return result
    else:
        return None
Esempio n. 49
0
def initData(myPatch):
    """ initialize the quadrant problem """

    msg.bold("initializing the quadrant problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(myPatch, patch.ccData2d):
        print "ERROR: patch invalid in quad.py"
        print myPatch.__class__
        sys.exit()

    # get the density, momenta, and energy as separate variables
    dens = myPatch.getVarPtr("density")
    xmom = myPatch.getVarPtr("x-momentum")
    ymom = myPatch.getVarPtr("y-momentum")
    ener = myPatch.getVarPtr("energy")

    # initialize the components, remember, that ener here is
    # rho*eint + 0.5*rho*v**2, where eint is the specific
    # internal energy (erg/g)
    r1 = runparams.getParam("quadrant.rho1")
    u1 = runparams.getParam("quadrant.u1")
    v1 = runparams.getParam("quadrant.v1")
    p1 = runparams.getParam("quadrant.p1")

    r2 = runparams.getParam("quadrant.rho2")
    u2 = runparams.getParam("quadrant.u2")
    v2 = runparams.getParam("quadrant.v2")
    p2 = runparams.getParam("quadrant.p2")

    r3 = runparams.getParam("quadrant.rho3")
    u3 = runparams.getParam("quadrant.u3")
    v3 = runparams.getParam("quadrant.v3")
    p3 = runparams.getParam("quadrant.p3")

    r4 = runparams.getParam("quadrant.rho4")
    u4 = runparams.getParam("quadrant.u4")
    v4 = runparams.getParam("quadrant.v4")
    p4 = runparams.getParam("quadrant.p4")

    cx = runparams.getParam("quadrant.cx")
    cy = runparams.getParam("quadrant.cy")
    
    gamma = runparams.getParam("eos.gamma")
    
    xmin = runparams.getParam("mesh.xmin")
    xmax = runparams.getParam("mesh.xmax")

    ymin = runparams.getParam("mesh.ymin")
    ymax = runparams.getParam("mesh.ymax")


    # there is probably an easier way to do this, but for now, we
    # will just do an explicit loop.  Also, we really want to set
    # the pressue and get the internal energy from that, and then
    # compute the total energy (which is what we store).  For now
    # we will just fake this
    
    myg = myPatch.grid

    i = myg.ilo
    while i <= myg.ihi:

        j = myg.jlo
        while j <= myg.jhi:

            if (myg.x[i] >= cx and myg.y[j] >= cy):

                # quadrant 1
                dens[i,j] = r1
                xmom[i,j] = r1*u1
                ymom[i,j] = r1*v1
                ener[i,j] = p1/(gamma - 1.0) + 0.5*r1*(u1*u1 + v1*v1)
                
            elif (myg.x[i] < cx and myg.y[j] >= cy):

                # quadrant 2
                dens[i,j] = r2
                xmom[i,j] = r2*u2
                ymom[i,j] = r2*v2
                ener[i,j] = p2/(gamma - 1.0) + 0.5*r2*(u2*u2 + v2*v2)

            elif (myg.x[i] < cx and myg.y[j] < cy):

                # quadrant 3
                dens[i,j] = r3
                xmom[i,j] = r3*u3
                ymom[i,j] = r3*v3
                ener[i,j] = p3/(gamma - 1.0) + 0.5*r3*(u3*u3 + v3*v3)

            elif (myg.x[i] >= cx and myg.y[j] < cy):

                # quadrant 4
                dens[i,j] = r4
                xmom[i,j] = r4*u4
                ymom[i,j] = r4*v4
                ener[i,j] = p4/(gamma - 1.0) + 0.5*r4*(u4*u4 + v4*v4)

            j += 1
        i += 1
Esempio n. 50
0
                               to the stored benchmark for this problem
                               (looking in the solver's tests/ sub-
                               directory).

      [runtime parameters] override any of the runtime defaults of
      parameters specified in the inputs file.  For instance, to turn
      off runtime visualization, add:

         vis.dovis=0

      to the end of the commandline.

      """


msg.bold('pyro ...')

tc = profile.TimerCollection()

tm_main = tc.timer("main")
tm_main.begin()

#-----------------------------------------------------------------------------
# command line arguments / solver setup
#-----------------------------------------------------------------------------

# parse the runtime arguments.  We specify a solver (which we import
# locally under the namespace 'solver', the problem name, and the
# input file name

if len(sys.argv) == 1:
Esempio n. 51
0
def doit(solver_name, problem_name, param_file,
         other_commands=None,
         comp_bench=False, reset_bench_on_fail=False, make_bench=False):
    """The main driver to run pyro"""

    msg.bold('pyro ...')

    tc = profile.TimerCollection()

    tm_main = tc.timer("main")
    tm_main.begin()

    # import desired solver under "solver" namespace
    solver = importlib.import_module(solver_name)

    #-------------------------------------------------------------------------
    # runtime parameters
    #-------------------------------------------------------------------------

    # parameter defaults
    rp = runparams.RuntimeParameters()
    rp.load_params("_defaults")
    rp.load_params(solver_name + "/_defaults")

    # problem-specific runtime parameters
    rp.load_params(solver_name + "/problems/_" + problem_name + ".defaults")

    # now read in the inputs file
    if not os.path.isfile(param_file):
        # check if the param file lives in the solver's problems directory
        param_file = solver_name + "/problems/" + param_file
        if not os.path.isfile(param_file):
            msg.fail("ERROR: inputs file does not exist")

    rp.load_params(param_file, no_new=1)

    # and any commandline overrides
    if other_commands is not None:
        rp.command_line_params(other_commands)

    # write out the inputs.auto
    rp.print_paramfile()


    #-------------------------------------------------------------------------
    # initialization
    #-------------------------------------------------------------------------

    # initialize the Simulation object -- this will hold the grid and
    # data and know about the runtime parameters and which problem we
    # are running
    sim = solver.Simulation(solver_name, problem_name, rp, timers=tc)

    sim.initialize()
    sim.preevolve()


    #-------------------------------------------------------------------------
    # evolve
    #-------------------------------------------------------------------------
    verbose = rp.get_param("driver.verbose")

    plt.ion()

    sim.cc_data.t = 0.0

    # output the 0th data
    basename = rp.get_param("io.basename")
    sim.write("{}{:04d}".format(basename, sim.n))

    dovis = rp.get_param("vis.dovis")
    if dovis:
        plt.figure(num=1, figsize=(8, 6), dpi=100, facecolor='w')
        sim.dovis()

    while not sim.finished():

        # fill boundary conditions
        sim.cc_data.fill_BC_all()

        # get the timestep
        sim.compute_timestep()

        # evolve for a single timestep
        sim.evolve()

        if verbose > 0:
            print("%5d %10.5f %10.5f" % (sim.n, sim.cc_data.t, sim.dt))

        # output
        if sim.do_output():
            if verbose > 0:
                msg.warning("outputting...")
            basename = rp.get_param("io.basename")
            sim.write("{}{:04d}".format(basename, sim.n))

        # visualization
        if dovis:
            tm_vis = tc.timer("vis")
            tm_vis.begin()

            sim.dovis()
            store = rp.get_param("vis.store_images")

            if store == 1:
                basename = rp.get_param("io.basename")
                plt.savefig("{}{:04d}.png".format(basename, sim.n))

            tm_vis.end()

    # final output
    if verbose > 0:
        msg.warning("outputting...")
    basename = rp.get_param("io.basename")
    sim.write("{}{:04d}".format(basename, sim.n))

    tm_main.end()


    #-------------------------------------------------------------------------
    # benchmarks (for regression testing)
    #-------------------------------------------------------------------------
    result = 0
    # are we comparing to a benchmark?
    if comp_bench:
        compare_file = "{}/tests/{}{:04d}".format(
            solver_name, basename, sim.n)
        msg.warning("comparing to: {} ".format(compare_file))
        try:
            sim_bench = io.read(compare_file)
        except:
            msg.warning("ERROR openning compare file")
            return "ERROR openning compare file"


        result = compare.compare(sim.cc_data, sim_bench.cc_data)

        if result == 0:
            msg.success("results match benchmark\n")
        else:
            msg.warning("ERROR: " + compare.errors[result] + "\n")


    # are we storing a benchmark?
    if make_bench or (result != 0 and reset_bench_on_fail):
        if not os.path.isdir(solver_name + "/tests/"):
            try:
                os.mkdir(solver_name + "/tests/")
            except:
                msg.fail("ERROR: unable to create the solver's tests/ directory")

        bench_file = solver_name + "/tests/" + basename + "%4.4d" % (sim.n)
        msg.warning("storing new benchmark: {}\n".format(bench_file))
        sim.write(bench_file)


    #-------------------------------------------------------------------------
    # final reports
    #-------------------------------------------------------------------------
    if verbose > 0:
        rp.print_unused_params()
        tc.report()

    sim.finalize()

    if comp_bench:
        return result
Esempio n. 52
0
def init_data(my_data, rp):
    """ initialize the bubble problem """

    msg.bold("initializing the bubble problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print("ERROR: patch invalid in bubble.py")
        print(my_data.__class__)
        sys.exit()

    # get the density, momenta, and energy as separate variables
    dens = my_data.get_var("density")
    xmom = my_data.get_var("x-momentum")
    ymom = my_data.get_var("y-momentum")
    ener = my_data.get_var("energy")

    gamma = rp.get_param("eos.gamma")

    grav = rp.get_param("compressible.grav")

    scale_height = rp.get_param("bubble.scale_height")
    dens_base = rp.get_param("bubble.dens_base")
    dens_cutoff = rp.get_param("bubble.dens_cutoff")

    x_pert = rp.get_param("bubble.x_pert")
    y_pert = rp.get_param("bubble.y_pert")
    r_pert = rp.get_param("bubble.r_pert")
    pert_amplitude_factor = rp.get_param("bubble.pert_amplitude_factor")

    # initialize the components, remember, that ener here is
    # rho*eint + 0.5*rho*v**2, where eint is the specific
    # internal energy (erg/g)
    xmom[:, :] = 0.0
    ymom[:, :] = 0.0
    dens[:, :] = dens_cutoff

    # set the density to be stratified in the y-direction
    myg = my_data.grid

    p = myg.scratch_array()

    cs2 = scale_height*abs(grav)

    for j in range(myg.jlo, myg.jhi+1):
        dens[:, j] = max(dens_base*np.exp(-myg.y[j]/scale_height),
                        dens_cutoff)
        if j == myg.jlo:
            p[:, j] = dens[:, j]*cs2
        else:
            p[:, j] = p[:, j-1] + 0.5*myg.dy*(dens[:, j] + dens[:, j-1])*grav

    # set the energy (P = cs2*dens)
    ener[:, :] = p[:, :]/(gamma - 1.0) + \
                0.5*(xmom[:, :]**2 + ymom[:, :]**2)/dens[:, :]

    r = np.sqrt((myg.x2d - x_pert)**2 + (myg.y2d - y_pert)**2)
    idx = r <= r_pert

    # boost the specific internal energy, keeping the pressure
    # constant, by dropping the density
    eint = (ener[idx] - 0.5*(xmom[idx]**2 - ymom[idx]**2)/dens[idx])/dens[idx]

    pres = dens[idx]*eint*(gamma - 1.0)

    eint = eint*pert_amplitude_factor
    dens[idx] = pres/(eint*(gamma - 1.0))

    ener[idx] = dens[idx]*eint + 0.5*(xmom[idx]**2 + ymom[idx]**2)/dens[idx]
Esempio n. 53
0
def init_data(my_data, rp):
    """ initialize the sedov problem """

    msg.bold("initializing the logo problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print("ERROR: patch invalid in sedov.py")
        print(my_data.__class__)
        sys.exit()

    # create the logo
    myg = my_data.grid

    fig = plt.figure(2, (0.64, 0.64), dpi=100 * myg.nx / 64)
    fig.add_subplot(111)

    fig.text(0.5,
             0.5,
             "pyro",
             transform=fig.transFigure,
             fontsize="16",
             horizontalalignment="center",
             verticalalignment="center")

    plt.axis("off")

    fig.canvas.draw()
    data = np.fromstring(fig.canvas.tostring_rgb(), dtype=np.uint8, sep='')
    data = data.reshape(fig.canvas.get_width_height()[::-1] + (3, ))

    logo = np.rot90(np.rot90(np.rot90((256 - data[:, :, 1]) / 255.0)))

    # get the density, momenta, and energy as separate variables
    dens = my_data.get_var("density")
    xmom = my_data.get_var("x-momentum")
    ymom = my_data.get_var("y-momentum")
    ener = my_data.get_var("energy")

    myg = my_data.grid

    # initialize the components, remember, that ener here is rho*eint
    # + 0.5*rho*v**2, where eint is the specific internal energy
    # (erg/g)
    xmom[:, :] = 0.0
    ymom[:, :] = 0.0

    # set the density in the logo zones to be really large
    logo_dens = 0.1

    dens[:, :] = logo_dens * (0.5 + logo[0, 0])

    dens.v()[:, :] = (0.5 + logo[:, :]) * logo_dens

    # pressure equilibrium
    gamma = rp.get_param("eos.gamma")

    p_ambient = 1.e-1
    p = myg.scratch_array(nvar=1)
    p[:, :] = p_ambient * (0.8 + logo[0, 0])
    p.v()[:, :] *= (0.8 + logo[:, :])
    # ener[:, :] = p/(gamma - 1.0)
    # ener.v()[:, :] *= (0.2 + logo[:, :])
    rhoh = eos.rhoh_from_rho_p(gamma, dens, p)

    u = xmom / dens
    v = ymom / dens
    W = 1. / np.sqrt(1 - u**2 - v**2)
    dens[:, :] *= W
    xmom[:, :] = rhoh[:, :] * u * W**2
    ymom[:, :] = rhoh[:, :] * v * W**2

    ener[:, :] = rhoh[:, :] * W**2 - p - dens[:, :]
Esempio n. 54
0
def initData(myPatch):
    """ initialize the Rayleigh-Taylor instability problem """

    msg.bold("initializing the Rayleigh-Taylor instability problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(myPatch, patch.ccData2d):
        print "ERROR: patch invalid in raytay.py"
        print myPatch.__class__
        sys.exit()

    # get the density, momenta, and energy as separate variables
    dens = myPatch.getVarPtr("density")
    xmom = myPatch.getVarPtr("x-momentum")
    ymom = myPatch.getVarPtr("y-momentum")
    ener = myPatch.getVarPtr("energy")

    # get the other input parameters for the problem
    gamma = runparams.getParam("eos.gamma")
    grav = runparams.getParam("compressible.grav")
    dens_up = runparams.getParam("raytay.dens_up")
    dens_down = runparams.getParam("raytay.dens_down")
    A = runparams.getParam("raytay.pert_amplitude_factor")
    p0 = runparams.getParam("raytay.pressure_bottom")
    sigma = runparams.getParam("raytay.sigma")

    # get the grid parameters
    xmin = runparams.getParam("mesh.xmin")
    xmax = runparams.getParam("mesh.xmax")
    ymin = runparams.getParam("mesh.ymin")
    ymax = runparams.getParam("mesh.ymax")

    yctr = 0.5 * (ymin + ymax)

    # initialize the components, remember, that ener here is
    # rho*eint + 0.5*rho*v**2, where eint is the specific
    # internal energy (erg/g)
    xmom[:, :] = 0.0
    ymom[:, :] = 0.0
    dens[:, :] = 0.0

    Lx = xmax - xmin

    # set the density and energy to be stratified in the y-direction
    myg = myPatch.grid

    j = myg.jlo
    while j <= myg.jhi:
        if myg.y[j] < yctr:
            dens[:, j] = dens_down
            pres = dens_down * grav * myg.y[j] + p0
            ener[:, j] = pres / (
                gamma - 1.0)  #+ 0.5*(xmom[:,j]**2 + ymom[:,j]**2)/dens_down
        else:
            dens[:, j] = dens_up
            pres = p0 + dens_down * grav * yctr + dens_up * grav * (myg.y[j] -
                                                                    yctr)
            ener[:, j] = pres / (
                gamma - 1.0)  #+ 0.5*(xmom[:,j]**2 + ymom[:,j]**2)/dens_up
        j += 1

    i = myg.ilo
    while i <= myg.ihi:

        j = myg.jlo
        while j <= myg.jhi:

            v_pert = A * numpy.sin(
                2.0 * numpy.pi * myg.x[i] / Lx) * numpy.exp(-(
                    (myg.y[j] - yctr) / sigma)**2)

            # momentum
            ymom[i, j] = dens[i, j] * v_pert

            # internal energy
            ener[i, j] += 0.5 * (xmom[i, j]**2 - ymom[i, j]**2) / dens[i, j]

            j += 1
        i += 1
Esempio n. 55
0
def initData(myPatch):
    """ initialize the bubble problem """

    msg.bold("initializing the bubble problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(myPatch, patch.ccData2d):
        print "ERROR: patch invalid in bubble.py"
        print myPatch.__class__
        sys.exit()

    # get the density, momenta, and energy as separate variables
    dens = myPatch.getVarPtr("density")
    xmom = myPatch.getVarPtr("x-momentum")
    ymom = myPatch.getVarPtr("y-momentum")
    ener = myPatch.getVarPtr("energy")

    gamma = runparams.getParam("eos.gamma")

    grav = runparams.getParam("compressible.grav")

    scale_height = runparams.getParam("bubble.scale_height")
    dens_base = runparams.getParam("bubble.dens_base")
    dens_cutoff = runparams.getParam("bubble.dens_cutoff")

    x_pert = runparams.getParam("bubble.x_pert")
    y_pert = runparams.getParam("bubble.y_pert")
    r_pert = runparams.getParam("bubble.r_pert")
    pert_amplitude_factor = runparams.getParam("bubble.pert_amplitude_factor")

    # initialize the components, remember, that ener here is
    # rho*eint + 0.5*rho*v**2, where eint is the specific
    # internal energy (erg/g)
    xmom[:, :] = 0.0
    ymom[:, :] = 0.0
    dens[:, :] = dens_cutoff

    # set the density to be stratified in the y-direction
    myg = myPatch.grid

    j = myg.jlo
    while j <= myg.jhi:
        dens[:, j] = max(dens_base * numpy.exp(-myg.y[j] / scale_height),
                         dens_cutoff)
        j += 1

    cs2 = scale_height * abs(grav)

    # set the energy (P = cs2*dens)
    ener[:,:] = cs2*dens[:,:]/(gamma - 1.0) + \
                0.5*(xmom[:,:]**2 + ymom[:,:]**2)/dens[:,:]

    i = myg.ilo
    while i <= myg.ihi:

        j = myg.jlo
        while j <= myg.jhi:

            r = numpy.sqrt((myg.x[i] - x_pert)**2 + (myg.y[j] - y_pert)**2)

            if (r <= r_pert):
                # boost the specific internal energy, keeping the pressure
                # constant, by dropping the density
                eint = (ener[i, j] - 0.5 *
                        (xmom[i, j]**2 - ymom[i, j]**2) / dens[i, j]) / dens[i,
                                                                             j]

                pres = dens[i, j] * eint * (gamma - 1.0)

                eint = eint * pert_amplitude_factor
                dens[i, j] = pres / (eint * (gamma - 1.0))

                ener[i,j] = dens[i,j]*eint + \
                    0.5*(xmom[i,j]**2 + ymom[i,j]**2)/dens[i,j]

            j += 1
        i += 1
Esempio n. 56
0
File: sod.py Progetto: jzuhone/pyro2
def initData(my_data):
    """ initialize the sod problem """

    msg.bold("initializing the sod problem...")

    rp = my_data.rp

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print "ERROR: patch invalid in sod.py"
        print my_data.__class__
        sys.exit()


    # get the sod parameters
    dens_left = rp.get_param("sod.dens_left")
    dens_right = rp.get_param("sod.dens_right")

    u_left = rp.get_param("sod.u_left")
    u_right = rp.get_param("sod.u_right")

    p_left = rp.get_param("sod.p_left")
    p_right = rp.get_param("sod.p_right")
    

    # get the density, momenta, and energy as separate variables
    dens = my_data.get_var("density")
    xmom = my_data.get_var("x-momentum")
    ymom = my_data.get_var("y-momentum")
    ener = my_data.get_var("energy")

    # initialize the components, remember, that ener here is rho*eint
    # + 0.5*rho*v**2, where eint is the specific internal energy
    # (erg/g)
    xmin = rp.get_param("mesh.xmin")
    xmax = rp.get_param("mesh.xmax")

    ymin = rp.get_param("mesh.ymin")
    ymax = rp.get_param("mesh.ymax")

    gamma = rp.get_param("eos.gamma")

    direction = rp.get_param("sod.direction")
    
    xctr = 0.5*(xmin + xmax)
    yctr = 0.5*(ymin + ymax)

    myg = my_data.grid
    
    # there is probably an easier way to do this, but for now, we
    # will just do an explicit loop.  Also, we really want to set
    # the pressue and get the internal energy from that, and then
    # compute the total energy (which is what we store).  For now
    # we will just fake this.
    if direction == "x":

        i = myg.ilo
        while i <= myg.ihi:

            j = myg.jlo
            while j <= myg.jhi:

                if myg.x[i] <= xctr:
                    dens[i,j] = dens_left
                    xmom[i,j] = dens_left*u_left
                    ymom[i,j] = 0.0
                    ener[i,j] = p_left/(gamma - 1.0) + 0.5*xmom[i,j]*u_left
                
                else:
                    dens[i,j] = dens_right
                    xmom[i,j] = dens_right*u_right
                    ymom[i,j] = 0.0
                    ener[i,j] = p_right/(gamma - 1.0) + 0.5*xmom[i,j]*u_right
                    
                j += 1
            i += 1

    else:
        i = myg.ilo
        while i <= myg.ihi:

            j = myg.jlo
            while j <= myg.jhi:

                if myg.y[j] <= yctr:
                    dens[i,j] = dens_left
                    xmom[i,j] = 0.0
                    ymom[i,j] = dens_left*u_left
                    ener[i,j] = p_left/(gamma - 1.0) + 0.5*ymom[i,j]*u_left
                
                else:
                    dens[i,j] = dens_right
                    xmom[i,j] = 0.0
                    ymom[i,j] = dens_right*u_right
                    ener[i,j] = p_right/(gamma - 1.0) + 0.5*ymom[i,j]*u_right
                    
                j += 1
            i += 1
Esempio n. 57
0
def initData(my_data):
    """ initialize the bubble problem """

    msg.bold("initializing the bubble problem...")

    rp = my_data.rp

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print "ERROR: patch invalid in bubble.py"
        print my_data.__class__
        sys.exit()

    # get the density, momenta, and energy as separate variables
    dens = my_data.get_var("density")
    xmom = my_data.get_var("x-momentum")
    ymom = my_data.get_var("y-momentum")
    ener = my_data.get_var("energy")

    gamma = rp.get_param("eos.gamma")

    grav = rp.get_param("compressible.grav")

    scale_height = rp.get_param("bubble.scale_height")
    dens_base = rp.get_param("bubble.dens_base")
    dens_cutoff = rp.get_param("bubble.dens_cutoff")

    x_pert = rp.get_param("bubble.x_pert")
    y_pert = rp.get_param("bubble.y_pert")
    r_pert = rp.get_param("bubble.r_pert")
    pert_amplitude_factor = rp.get_param("bubble.pert_amplitude_factor")

    # initialize the components, remember, that ener here is
    # rho*eint + 0.5*rho*v**2, where eint is the specific
    # internal energy (erg/g)
    xmom[:,:] = 0.0
    ymom[:,:] = 0.0
    dens[:,:] = dens_cutoff

    # set the density to be stratified in the y-direction
    myg = my_data.grid

    j = myg.jlo
    while j <= myg.jhi:
        dens[:,j] = max(dens_base*numpy.exp(-myg.y[j]/scale_height),
                        dens_cutoff)
        j += 1

    cs2 = scale_height*abs(grav)

    # set the energy (P = cs2*dens)
    ener[:,:] = cs2*dens[:,:]/(gamma - 1.0) + \
                0.5*(xmom[:,:]**2 + ymom[:,:]**2)/dens[:,:]


    
    i = myg.ilo
    while i <= myg.ihi:

        j = myg.jlo
        while j <= myg.jhi:

            r = numpy.sqrt((myg.x[i] - x_pert)**2  + (myg.y[j] - y_pert)**2)

            if (r <= r_pert):
                # boost the specific internal energy, keeping the pressure
                # constant, by dropping the density
                eint = (ener[i,j] - 
                        0.5*(xmom[i,j]**2 - ymom[i,j]**2)/dens[i,j])/dens[i,j]

                pres = dens[i,j]*eint*(gamma - 1.0)

                eint = eint*pert_amplitude_factor
                dens[i,j] = pres/(eint*(gamma - 1.0))

                ener[i,j] = dens[i,j]*eint + \
                    0.5*(xmom[i,j]**2 + ymom[i,j]**2)/dens[i,j]

            j += 1
        i += 1
Esempio n. 58
0
def init_data(my_data, rp):
    """ initialize the Kelvin-Helmholtz problem """

    msg.bold("initializing the sedov problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print(my_data.__class__)
        msg.fail("ERROR: patch invalid in sedov.py")

    # get the density, momenta, and energy as separate variables
    dens = my_data.get_var("density")
    xmom = my_data.get_var("x-momentum")
    ymom = my_data.get_var("y-momentum")
    ener = my_data.get_var("energy")

    # initialize the components, remember, that ener here is rho*eint
    # + 0.5*rho*v**2, where eint is the specific internal energy
    # (erg/g)
    dens[:, :] = 1.0
    xmom[:, :] = 0.0
    ymom[:, :] = 0.0

    rho_1 = rp.get_param("kh.rho_1")
    v_1 = rp.get_param("kh.v_1")
    rho_2 = rp.get_param("kh.rho_2")
    v_2 = rp.get_param("kh.v_2")

    gamma = rp.get_param("eos.gamma")

    myg = my_data.grid

    dy = 0.025
    w0 = 0.01
    vm = 0.5 * (v_1 - v_2)
    rhom = 0.5 * (rho_1 - rho_2)

    idx1 = myg.y2d < 0.25
    idx2 = np.logical_and(myg.y2d >= 0.25, myg.y2d < 0.5)
    idx3 = np.logical_and(myg.y2d >= 0.5, myg.y2d < 0.75)
    idx4 = myg.y2d >= 0.75

    # we will initialize momemum as velocity for now

    # lower quarter
    dens[idx1] = rho_1 - rhom * np.exp((myg.y2d[idx1] - 0.25) / dy)
    xmom[idx1] = v_1 - vm * np.exp((myg.y2d[idx1] - 0.25) / dy)

    # second quarter
    dens[idx2] = rho_2 + rhom * np.exp((0.25 - myg.y2d[idx2]) / dy)
    xmom[idx2] = v_2 + vm * np.exp((0.25 - myg.y2d[idx2]) / dy)

    # third quarter
    dens[idx3] = rho_2 + rhom * np.exp((myg.y2d[idx3] - 0.75) / dy)
    xmom[idx3] = v_2 + vm * np.exp((myg.y2d[idx3] - 0.75) / dy)

    # fourth quarter
    dens[idx4] = rho_1 - rhom * np.exp((0.75 - myg.y2d[idx4]) / dy)
    xmom[idx4] = v_1 - vm * np.exp((0.75 - myg.y2d[idx4]) / dy)

    # upper half
    xmom[:, :] *= dens
    ymom[:, :] = dens * w0 * np.sin(4 * np.pi * myg.x2d)

    p = 2.5
    ener[:, :] = p / (gamma - 1.0) + 0.5 * (xmom[:, :]**2 +
                                            ymom[:, :]**2) / dens[:, :]
Esempio n. 59
0
def init_data(my_data, rp):
    """ initialize the Kelvin-Helmholtz problem """

    msg.bold("initializing the sedov problem...")

    # make sure that we are passed a valid patch object
    if not isinstance(my_data, patch.CellCenterData2d):
        print(my_data.__class__)
        msg.fail("ERROR: patch invalid in sedov.py")


    # get the density, momenta, and energy as separate variables
    dens = my_data.get_var("density")
    xmom = my_data.get_var("x-momentum")
    ymom = my_data.get_var("y-momentum")
    ener = my_data.get_var("energy")

    # initialize the components, remember, that ener here is rho*eint
    # + 0.5*rho*v**2, where eint is the specific internal energy
    # (erg/g)
    dens[:,:] = 1.0
    xmom[:,:] = 0.0
    ymom[:,:] = 0.0

    rho_1 = rp.get_param("kh.rho_1")
    v_1   = rp.get_param("kh.v_1")
    rho_2 = rp.get_param("kh.rho_2")
    v_2   = rp.get_param("kh.v_2")

    gamma = rp.get_param("eos.gamma")

    xmin = rp.get_param("mesh.xmin")
    xmax = rp.get_param("mesh.xmax")

    ymin = rp.get_param("mesh.ymin")
    ymax = rp.get_param("mesh.ymax")

    yctr = 0.5*(ymin + ymax)

    L_x = xmax - xmin

    myg = my_data.grid
    
    for i in range(myg.ilo, myg.ihi+1):
        for j in range(myg.jlo, myg.jhi+1):

            if myg.y[j] < yctr + 0.01*math.sin(10.0*math.pi*myg.x[i]/L_x):

                # lower half
                dens[i,j] = rho_1
                xmom[i,j] = rho_1*v_1
                ymom[i,j] = 0.0
                
            else:

                # upper half
                dens[i,j] = rho_2
                xmom[i,j] = rho_2*v_2
                ymom[i,j] = 0.0

            p = 1.0
            ener[i,j] = p/(gamma - 1.0) + \
                        0.5*(xmom[i,j]**2 + ymom[i,j]**2)/dens[i,j]