Exemple #1
0
    def generate_particles(self, xmin, xmax, dxl, dxr, m, pl, pr, h0,  bx,
                           gamma1, ul=0, ur=0, constants={}):
        xt1 = numpy.arange(xmin - bx + 0.5 * dxl, 0, dxl)
        xt2 = numpy.arange(0.5 * dxr, xmax + bx, dxr)
        xt = numpy.concatenate([xt1, xt2])
        leftb_indices = numpy.where(xt <= xmin)[0]
        left_indices = numpy.where((xt > xmin) & (xt < 0))[0]
        right_indices = numpy.where((xt >= 0) & (xt < xmax))[0]
        rightb_indices = numpy.where(xt >= xmax)[0]
        x1 = xt[left_indices]
        x2 = xt[right_indices]
        b1 = xt[leftb_indices]
        b2 = xt[rightb_indices]

        x = numpy.concatenate([x1, x2])
        b = numpy.concatenate([b1, b2])
        right_indices = numpy.where(x > 0.0)[0]

        rho = numpy.ones_like(x) * m / dxl
        rho[right_indices] = m / dxr

        p = numpy.ones_like(x) * pl
        p[right_indices] = pr

        u = numpy.ones_like(x) * ul
        u[right_indices] = ur

        h = numpy.ones_like(x) * h0
        m = numpy.ones_like(x) * m
        e = p / (gamma1 * rho)
        wij = numpy.ones_like(x)

        bwij = numpy.ones_like(b)
        brho = numpy.ones_like(b)
        bp = numpy.ones_like(b)
        be = bp / (gamma1 * brho)
        bm = numpy.ones_like(b) * dxl
        bh = numpy.ones_like(b) * 4 * h0
        bhtmp = numpy.ones_like(b)
        fluid = gpa(
            constants=constants, name='fluid', x=x, rho=rho, p=p,
            e=e, h=h, m=m, u=u, wij=wij, h0=h.copy()
        )

        boundary = gpa(
            constants=constants, name='boundary', x=b, rho=brho, p=bp,
            e=be, h=bh, m=bm, wij=bwij, h0=bh.copy(), htmp=bhtmp
        )

        self.scheme.setup_properties([fluid, boundary])
        print("1D Shocktube with %d particles" %
              (fluid.get_number_of_particles()))
        return [fluid, boundary]
Exemple #2
0
    def create_particles(self):
        x = numpy.arange(self.xmin + self.dx * 0.5, self.xmax, self.dx)
        rho = self.rho_0 + self.delta_rho *\
            numpy.sin(self.k * x)

        p = self.p_0 + self.c_0**2 *\
            self.delta_rho * numpy.sin(self.k * x)

        u = self.c_0 * self.delta_rho * numpy.sin(self.k * x) /\
            self.rho_0
        cs = numpy.sqrt(self.gamma * p / rho)
        h = numpy.ones_like(x) * self.dx * self.hdx
        m = numpy.ones_like(x) * self.dx * rho
        e = p / ((self.gamma - 1) * rho)
        fluid = gpa(name='fluid',
                    x=x,
                    p=p,
                    rho=rho,
                    u=u,
                    h=h,
                    m=m,
                    e=e,
                    cs=cs,
                    h0=h.copy())
        self.scheme.setup_properties([fluid])

        return [
            fluid,
        ]
Exemple #3
0
    def create_particles(self):
        self.dx = self.domain_length / self.n_particles
        x = numpy.arange(self.xmin + self.dx * 0.5, self.xmax, self.dx)

        p = numpy.ones_like(x) * self.p2

        left_indices = numpy.where(x < 0.1)[0]
        right_indices = numpy.where(x > 0.9)[0]

        p[left_indices] = self.p1
        p[right_indices] = self.p3

        h = self.hdx * self.dx
        m = self.dx * self.rho
        e = p / ((self.gamma - 1) * self.rho)

        cs = numpy.sqrt(self.gamma * p / self.rho)

        fluid = gpa(name='fluid',
                    x=x,
                    rho=self.rho,
                    p=p,
                    h=h,
                    m=m,
                    e=e,
                    cs=cs,
                    h0=h,
                    u=0)

        self.scheme.setup_properties([fluid])
        return [fluid]
    def get_results(self, array="fluid"):
        files = self.files
        nfiles = self.nfiles

        # compute the kinetic energy history for the array
        self.get_ke_history(array)

        # interpolate the u-velocity profile along the centerline
        y = np.linspace(0,1,101)
        x = np.ones_like(y) * 0.2
        h = np.ones_like(y) * 1.5 * 0.01

        dst = gpa('test', x=x, y=y, h=h)

        # take the last solution data
        fname = self.files[-1]
        data = utils.load(fname)
        self.pa = src = data['arrays'][array]

        interp = utils.SPHInterpolate(dim=2, dst=dst, src=src)
        self.ui = ui = interp.interpolate(src.u)
        self.y = y

        # exact parabolic profile for the u-velocity
        self.ye = y
        self.ue = self.Vmax*y/self.L
    def create_particles(self):
        # particle positions
        x = numpy.arange(xmin, xmax, dx)

        # diffusion coefficients
        D = numpy.ones_like(x)*Do

        # set density
        rho = numpy.ones_like(x)

        # set initial concentration
        cmax = 1
        b = 0
        sigma = 0.1
        c = cmax*numpy.exp(-(x-b)**2/(2.*sigma**2))

        # def initial accelerations
        ac = numpy.zeros_like(x)
        # copy initial condition
        co = numpy.copy(c)
        
        # const h and mass
        h = numpy.ones_like(x) * h0
        m = numpy.ones_like(x) * dx

        # generate fluid particle array
        fluid = gpa(name='fluid', x=x, rho=rho, c=c, h=h, D=D, m=m, h0=h.copy(),
                     ac=ac, co=c)

        # set output arrays
        fluid.add_output_arrays(['c'])
        
        print("1D Diffusion with %d particles"%(fluid.get_number_of_particles()))

        return [fluid,]
Exemple #6
0
def create_particles(**kwargs):
    global dx
    data = ud.uniform_distribution_cubic2D(dx, xmin, xmax, ymin, ymax)
    
    x = data[0]; y = data[1]
    dx = data[2]; dy = data[3]

    # volume estimate
    volume = dx*dy

    # indices on either side of the initial discontinuity
    right_indices = numpy.where( x > 0.0 )[0]

    # density is uniform
    rho = numpy.ones_like(x)
    
    # pl = 100.0, pr = 0.1
    p = numpy.ones_like(x) * 1000.0
    p[right_indices] = 0.01
    
    # const h and mass
    h = numpy.ones_like(x) * h0
    m = numpy.ones_like(x) * volume * rho

    # thermal energy from the ideal gas EOS
    e = p/(gamma1*rho)
    
    fluid = gpa(name='fluid', x=x, y=y, rho=rho, p=p, e=e, h=h, m=m, h0=h.copy())

    print "2D Shocktube with %d particles"%(fluid.get_number_of_particles())

    return [fluid,]
def create_particles(**kwargs):
    # particle positions
    x1 = numpy.arange( 0.5*dxl, 0.5, dxl )
    x2 = numpy.arange( 0.5 + 0.5*dxr, 1.0, dxr )
    x = numpy.concatenate( [x1, x2] )

    # indices on either side of the initial discontinuity
    right_indices = numpy.where( x > 0.5 )[0]

    # density
    rho = numpy.ones_like(x)
    rho[right_indices] = 0.125
    
    # pl = 1.0, pr = 0.1
    p = numpy.ones_like(x)
    p[right_indices] = 0.1
    
    # const h and mass
    h = numpy.ones_like(x) * h0
    m = numpy.ones_like(x) * dxl

    # thermal energy from the ideal gas EOS
    e = p/(gamma1*rho)

    # viscosity parameters
    alpha1 = numpy.ones_like(x) * a1
    alpha2 = numpy.ones_like(x) * a2

    fluid = gpa(name='fluid', x=x, rho=rho, p=p, e=e, h=h, m=m, h0=h.copy(), 
                alpha1=alpha1, alpha2=alpha2)

    print "1D Shocktube with %d particles"%(fluid.get_number_of_particles())

    return [fluid,]
Exemple #8
0
    def create_particles(self):
        x, y = numpy.mgrid[
            xmin:xmax:dx, ymin:ymax:dx]

        # positions
        x = x.ravel(); y = y.ravel()

        rho = numpy.ones_like(x) * rho0
        m = numpy.ones_like(x) * m0
        e = numpy.ones_like(x) * e0
        h = numpy.ones_like(x) * h0
        p = gamma1*rho*e

        u = numpy.ones_like(x)
        v = numpy.ones_like(x)

        sin, cos, arctan = numpy.sin, numpy.cos, numpy.arctan2
        for i in range(x.size):
            theta = arctan(y[i],x[i])
            u[i] = vr*cos(theta)
            v[i] = vr*sin(theta)

        fluid = gpa(name='fluid', x=x,y=y,m=m,rho=rho, h=h,u=u,v=v,p=p,e=e)
        self.scheme.setup_properties([fluid])

        print("Noh's problem with %d particles"%(fluid.get_number_of_particles()))

        return [fluid,]
    def get_results(self, array="fluid"):
        files = self.files
        nfiles = self.nfiles

        # compute the kinetic energy history for the array
        self.get_ke_history(array)

        # interpolated velocities
        dx = 0.01
        self._x = _x = np.linspace(0,1,101)
        xx, yy = np.meshgrid(_x, _x)
        xgrid = xx.ravel(); ygrid = yy.ravel()
        hgrid = np.ones_like(xgrid) * 1.3 * dx
        self.grid = grid = gpa('grid', x=xgrid, y=ygrid, h=hgrid)


        self.xx = xx; self.yy = yy

        # take the last solution data
        fname = self.files[-1]
        data = utils.load(fname)
        self.pa = src = data['arrays'][array]

        interp = utils.SPHInterpolate(dim=2, dst=grid, src=src)
        self.ui = ui = interp.interpolate(src.u)
        self.vi = vi = interp.interpolate(src.v)

        ui.shape = 101,101
        vi.shape = 101,101

        # velocity magnitude
        self.vmag = vmag = np.sqrt( ui**2 + vi**2 )
Exemple #10
0
    def create_particles(self):
        data = ud.uniform_distribution_cubic2D(self.dx, self.xmin, self.xmax,
                                               self.ymin, self.ymax)
        x = data[0]
        y = data[1]
        box_indices = numpy.where((x > 0.25) & (x < 0.75) & (y > 0.25)
                                  & (y < 0.75))[0]
        rho = numpy.ones_like(x) * self.rho0
        rho[box_indices] = self.rhoi
        e = self.p / ((self.gamma - 1) * rho)
        m = self.dx * self.dx * rho
        h = self.hdx * self.dx

        fluid = gpa(name='fluid',
                    x=x,
                    y=y,
                    p=self.p,
                    rho=rho,
                    e=e,
                    u=0.,
                    v=0.,
                    h=self.hdx * self.dx,
                    m=m,
                    h0=h)

        self.scheme.setup_properties([fluid])
        return [fluid]
Exemple #11
0
def create_particles(**kwargs):

    x, y = numpy.mgrid[
        xmin:xmax:dx, ymin:ymax:dx]

    # positions
    x = x.ravel(); y = y.ravel()

    rho = numpy.ones_like(x) * rho0
    m = numpy.ones_like(x) * m0
    e = numpy.ones_like(x) * e0
    h = numpy.ones_like(x) * h0
    p = gamma1*rho*e

    u = numpy.ones_like(x)
    v = numpy.ones_like(x)

    sin, cos, arctan = numpy.sin, numpy.cos, numpy.arctan2
    for i in range(x.size):
        theta = arctan(y[i],x[i])
        u[i] = vr*cos(theta)
        v[i] = vr*sin(theta)

    fluid = gpa(name='fluid', x=x,y=y,m=m,rho=rho, h=h,u=u,v=v,p=p,e=e)

    print "Noh's problem with %d particles"%(fluid.get_number_of_particles())

    return [fluid,]
    def create_particles(self):
        data = ud.uniform_distribution_cubic2D(self.dx, xmin, xmax, ymin, ymax)

        x = data[0].ravel()
        y = data[1].ravel()

        y1 = numpy.where((y >= 0) & (y < 0.25))[0]

        y2 = numpy.where((y >= 0.25) & (y < 0.5))[0]

        y3 = numpy.where((y >= 0.5) & (y < 0.75))[0]

        y4 = numpy.where((y >= 0.75) & (y < 1.0))[0]

        rho1 = rhoi_1 - rhoi_m * numpy.exp((y[y1] - 0.25) / delta)
        rho2 = rhoi_2 + rhoi_m * numpy.exp((0.25 - y[y2]) / delta)
        rho3 = rhoi_2 + rhoi_m * numpy.exp((y[y3] - 0.75) / delta)
        rho4 = rhoi_1 - rhoi_m * numpy.exp((0.75 - y[y4]) / delta)

        u1 = v_i1 - v_im * numpy.exp((y[y1] - 0.25) / delta)
        u2 = v_i2 + v_im * numpy.exp((0.25 - y[y2]) / delta)
        u3 = v_i2 + v_im * numpy.exp((y[y3] - 0.75) / delta)
        u4 = v_i1 - v_im * numpy.exp((0.75 - y[y4]) / delta)

        v = dely * numpy.sin(2 * numpy.pi * x / wavelen)

        p = 2.5

        rho = numpy.concatenate((rho1, rho2, rho3, rho4))

        u = numpy.concatenate((u1, u2, u3, u4))

        v = numpy.concatenate((v[y1], v[y2], v[y3], v[y4]))

        x = numpy.concatenate((x[y1], x[y2], x[y3], x[y4]))

        y = numpy.concatenate((y[y1], y[y2], y[y3], y[y4]))

        e = p / ((gamma - 1) * rho)

        m = self.dx * self.dx * rho

        h = self.dx * self.hdx

        fluid = gpa(name='fluid',
                    x=x,
                    y=y,
                    u=u,
                    v=v,
                    rho=rho,
                    p=p,
                    e=e,
                    m=m,
                    h=h,
                    h0=h)

        self.scheme.setup_properties([fluid])
        return [fluid]
Exemple #13
0
    def create_particles(self):
        global dx
        data = ud.uniform_distribution_cubic2D(dx, xmin, xmax, ymin, ymax)

        x = data[0]
        y = data[1]
        dx = data[2]
        dy = data[3]

        # volume estimate
        volume = dx * dy

        # indices on either side of the initial discontinuity
        right_indices = numpy.where(x > x0)[0]

        # density is uniform
        rho = numpy.ones_like(x) * self.rhol
        rho[right_indices] = self.rhor

        # pl = 100.0, pr = 0.1
        p = numpy.ones_like(x) * self.pl
        p[right_indices] = self.pr

        # const h and mass
        h = numpy.ones_like(x) * self.hdx * self.dx
        m = numpy.ones_like(x) * volume * rho

        # ul = ur = 0
        u = numpy.ones_like(x) * self.ul
        u[right_indices] = self.ur

        # vl = vr = 0
        v = numpy.ones_like(x) * self.vl
        v[right_indices] = self.vr

        # thermal energy from the ideal gas EOS
        e = p / (gamma1 * rho)

        fluid = gpa(name='fluid',
                    x=x,
                    y=y,
                    rho=rho,
                    p=p,
                    e=e,
                    h=h,
                    m=m,
                    h0=h.copy(),
                    u=u,
                    v=v)
        self.scheme.setup_properties([fluid])

        print("2D Shocktube with %d particles" %
              (fluid.get_number_of_particles()))

        return [
            fluid,
        ]
Exemple #14
0
def create_particles(empty=False, **kwargs):
    ns = 13987
    dx = dy = dz = 0.0225
    #h0 = 0.9 * np.sqrt(3 * dx**2)
    h0 = hdx * dx

    import os
    path = os.path.dirname(os.path.abspath(__file__))

    ipart = os.path.join(path, 'IPART.txt.gz')
    ipart = np.loadtxt(ipart)

    x = ipart[:, 0]; y = ipart[:, 1]; z = ipart[:, 2]
    u = ipart[:, 3]; v = ipart[:, 4]; w = ipart[:, 5]
    rho = ipart[:, 6]; p = ipart[:, 7]; m = ipart[:, 8]

    # the fluid particles
    xf = x[ns:]; yf = y[ns:]; zf = z[ns:]
    rhof = rho[ns:]; pf = p[ns:]; mf = m[ns:]

    hf = np.ones_like(xf) * h0

    fluid = gpa(name='fluid', x=xf, y=yf, z=zf,
                rho=rhof, p=pf, m=mf, h=hf)

    # the solid particles
    xs = x[:ns]; ys = y[:ns]; zs = z[:ns]
    rhos = rho[:ns]; ps = p[:ns]; ms = m[:ns]

    hs = np.ones_like(xs) * h0

    solid = gpa(name='boundary', x=xs, y=ys, z=zs,
                rho=rhos, p=ps, m=ms, h=hs)

    particles = [fluid, solid]

    # add requisite variables
    for pa in particles:
        for name in ('arho', 'au', 'av', 'aw', 'ax', 'ay', 'az',
                     'rho0', 'u0', 'v0', 'w0', 'x0', 'y0', 'z0'):
            pa.add_property(name)

    return particles
    def setUp(self):
        # create a single particle particle array
        x = numpy.array( [0.] )
        y = numpy.array( [0.] )

        additional_props = ['ax', 'ay', 'az', 'u0', 'v0', 'w0', 
                            'x0', 'y0', 'z0']
                          
        # create the particle array
        self.pa = pa = gpa(additional_props, name='square', x=x, y=y)
        
        self._set_stepper()
Exemple #16
0
    def create_particles(self):
        """Create the Rectangular patch of fluid."""
        x, y = mgrid[-2:2+1e-4:dx, -0.5:0.5+1e-4:dx]
        x = x.ravel()
        y = y.ravel()

        m = ones_like(x) * dx * dx * rho_w
        h = ones_like(x) * h0

        rho = ones_like(x) * rho_w
        rho0 = ones_like(x) * rho_w
        rho_prev_iter = ones_like(x) #This was zeros_like and hence creating lot of problems when dividing with rho_residual!!!
        rho_residual= zeros_like(x)
        positive_rho_residual = zeros_like(x)
        summation_rho = zeros_like(x)

        dw = ones_like(x) * d
        cs = ones_like(x) * sqrt(9.8*d)
        p = ones_like(x) * 0.5 * rho_w * g * d**2
        alpha = ones_like(x)
        exp_lambda = zeros_like(x)

        tv = zeros_like(x)
        tu = zeros_like(x)

        u = zeros_like(x)
        uh = zeros_like(x)
        u_prev_iter = zeros_like(x)
        v = zeros_like(x)
        vh = zeros_like(x)
        v_prev_iter = zeros_like(x)

        dt_cfl = ones_like(x)

        au = zeros_like(x)
        av = zeros_like(x)

        pa = gpa(x=x, y=y, m=m, rho0=rho0, rho=rho, exp_lambda=exp_lambda,
                rho_prev_iter=rho_prev_iter, rho_residual=rho_residual,
                positive_rho_residual=positive_rho_residual, cs=cs,
                summation_rho=summation_rho, alpha=alpha, h=h, u=u, v=v, uh=uh,
                vh=vh, u_prev_iter=u_prev_iter, v_prev_iter=v_prev_iter, au=au,
                av=av, tv=tv, tu=tu, p=p, dw=dw, dt_cfl=dt_cfl, name='fluid')

        props = ['u', 'v', 'm', 'tu', 'tv', 'dw', 'au', 'av', 'h', 'rho', 'p']
        pa.add_output_arrays(props)
        print ( "Rectangular Dam break :: %d particles"
                %(pa.get_number_of_particles()) )

        return [pa]
Exemple #17
0
    def create_particles(self):
        global dx
        data = ud.uniform_distribution_cubic2D(self.dx, xmin, xmax, ymin, ymax)

        x = data[0].ravel()
        y = data[1].ravel()
        dx = data[2]

        volume = dx * dx

        rho = 1 + 0.2 * numpy.sin(numpy.pi * (x + y))

        p = numpy.ones_like(x) * self.p

        # const h and mass
        h = numpy.ones_like(x) * self.hdx * dx
        m = numpy.ones_like(x) * volume * rho

        # u = 1
        u = numpy.ones_like(x) * self.u

        # v = -1
        v = numpy.ones_like(x) * self.v

        # thermal energy from the ideal gas EOS
        e = p / (gamma1 * rho)

        fluid = gpa(name='fluid',
                    x=x,
                    y=y,
                    rho=rho,
                    p=p,
                    e=e,
                    h=h,
                    m=m,
                    h0=h.copy(),
                    u=u,
                    v=v)
        self.scheme.setup_properties([fluid])

        print("2D Accuracy Test with %d particles" %
              (fluid.get_number_of_particles()))

        return [
            fluid,
        ]
Exemple #18
0
    def create_particles(self):
        x = numpy.linspace(self.xmin, self.xmax, self.n_particles)
        rho = 2 + numpy.sin(2 * numpy.pi * x) * self.delta_rho

        p = numpy.ones_like(x)

        u = 1 + 0.1 * numpy.sin(2 * numpy.pi * x)

        cs = numpy.sqrt(self.gamma * p / rho)
        h = numpy.ones_like(x) * self.dx * self.hdx
        m = numpy.ones_like(x) * self.dx * rho
        e = p / ((self.gamma - 1) * rho)

        fluid = gpa(name='fluid', x=x, p=p, rho=rho, u=u, h=h, m=m, e=e, cs=cs)

        self.scheme.setup_properties([fluid])

        return [
            fluid,
        ]
Exemple #19
0
    def create_particles(self):
        fpath = os.path.join(
            os.path.dirname(__file__), 'ndspmhd-sedov-initial-conditions.npz'
        )
        data = numpy.load(fpath)
        x = data['x']
        y = data['y']
        rho = data['rho']
        p = data['p']
        e = data['e']
        h = data['h']
        m = data['m']

        fluid = gpa(name='fluid', x=x, y=y, rho=rho, p=p, e=e, h=h, m=m)
        self.scheme.setup_properties([fluid])

        # set the initial smoothing length proportional to the particle
        # volume
        fluid.h[:] = kernel_factor * (fluid.m/fluid.rho)**(1./dim)

        print("Sedov's point explosion with %d particles"%(fluid.get_number_of_particles()))

        return [fluid,]
    def create_particles(self):
        # particle positions

        x, y = numpy.mgrid[xmin:xmax:dx, ymin:ymax:dy]
	x = x.ravel()
	y = y.ravel()
        # diffusion coefficients
        D = numpy.ones_like(x)*Do

        # set density
        rho = numpy.ones_like(x)

        # set initial concentration
        cmax = 1
        b = numpy.zeros_like(x)
        sigma = 0.1
        c = cmax*numpy.exp((-(x-b)**2-(y-b)**2)/(2.*sigma**2))

        # def initial accelerations
        ac = numpy.zeros_like(x)
        # copy initial condition
        co = numpy.copy(c)
        
        # const h and mass
        h = numpy.ones_like(x) * h0
        m = numpy.ones_like(x) * (dx**2)
	
        # generate fluid particle array
        fluid = gpa(name='fluid', x=x, y=y, rho=rho, c=c, h=h, D=D, m=m, h0=h.copy(), ac=ac, co=c)

	print "troll"
        # set output arrays
        fluid.add_output_arrays(['c'])
        
        print("1D Diffusion with %d particles"%(fluid.get_number_of_particles()))

        return [fluid,]
Exemple #21
0
def ndspmhd2pysph(fname, dim=2, read_type=False):
    """Read output data file from NDSPMHD

    Parameters:
    
    fname : str
        NDSPMHD data filename

    dim : int
        Problem dimension

    read_type : bint
        Flag to read the `type` property for particles

    Returns the ParticleArray representation of the data that can be
    used in PySPH.

    """
    f = FortranFile(fname)

    # get the header length
    header_length = f._header_length
    endian = f.ENDIAN
    
    # get the length of the record to be read
    length = f._read_check()

    # now read the individual entries:

    # current time : double
    t = f._read_exactly(8)
    t = struct.unpack(endian+"1d", t)[0]

    # number of particles and number printed : int
    npart = f._read_exactly(4)
    nprint = f._read_exactly(4)

    npart = struct.unpack(endian+"1i", npart)[0]
    nprint = struct.unpack(endian+"1i", nprint)[0]

    # gamma and hfact : double
    gamma = f._read_exactly(8)
    hfact = f._read_exactly(8)

    gamma = struct.unpack(endian+"1d", gamma)[0]
    hfact = struct.unpack(endian+"1d", hfact)[0]

    # ndim, ndimV : int
    ndim = f._read_exactly(4)
    ndimV = f._read_exactly(4)

    # ncollumns, iformat, ibound : int
    nc = f._read_exactly(4)
    ifmt = f._read_exactly(4)
    ib1 = f._read_exactly(4)
    ib2 = f._read_exactly(4)

    nc = struct.unpack(endian+"1i", nc)[0]

    # xmin, xmax : double
    xmin1 = f._read_exactly(8)
    xmin2 = f._read_exactly(8)
    xmax1 = f._read_exactly(8)
    xmax2 = f._read_exactly(8)

    # n : int
    n = f._read_exactly(4)
    n = struct.unpack(endian+"1i", n)[0]

    # geometry type
    geom = f._read_exactly(n)

    # end reading this header
    f._read_check()

    # Now go on to the arrays. Remember, there are 16 entries
    # correcponding to the columns

    x = f.readReals(prec="d")
    y = f.readReals(prec="d")
    u = f.readReals(prec="d")
    v = f.readReals(prec="d")
    w = f.readReals(prec="d")

    h = f.readReals(prec="d")
    rho = f.readReals(prec="d")
    e = f.readReals(prec="d")
    m = f.readReals(prec="d")

    alpha1 = f.readReals(prec="d")
    alpha2 = f.readReals(prec="d")

    p = f.readReals(prec="d")
    drhobdtbrho = f.readReals("d")
    gradh = f.readReals("d")

    au = f.readReals("d")
    av = f.readReals("d")
    aw = f.readReals("d")

    # By default, NDSPMHD does not output the type array. You need to
    # add this to the output routine if you want it.
    if read_type:
        type = f.readInts(prec="i")

    # now create the particle array
    pa = gpa(name='fluid', x=x, y=y, m=m, h=h, rho=rho, e=e, p=p, 
             u=u, v=v, w=w, au=au, av=av, aw=aw, div=drhobdtbrho)

    return pa
    def create_particles(self):
        """Create the triangular patch of fluid."""
        r1 = [2, 2]
        r2 = [2, -2]
        x = zeros(0)
        y = zeros(0)
        while r1[0] > 0:
            r = linspace(r1[-1], r2[-1], (r1[-1]-r2[-1])*25 + 3)
            x = concatenate((x, (ones(len(r))*r1[0])), axis=0)
            y = concatenate((y, r))
            r1[0] -= dx
            r2[0] -= dx
            r1[1] = r1[0]
            r2[1] = -r1[0]

        x = concatenate((zeros(1), x))
        y = concatenate((zeros(1), y))

        m = ones_like(x) * dx * dx * rho_w
        h = ones_like(x) * h0

        rho = ones_like(x) * rho_w
        rho0 = ones_like(x) * rho_w
        rho_prev_iter = ones_like(x)
        rho_residual= zeros_like(x)
        positive_rho_residual = zeros_like(x)
        summation_rho = zeros_like(x)

        dw = ones_like(x) * d
        cs = ones_like(x) * sqrt(9.8*d)
        p = ones_like(x) * 0.5 * rho_w * g * d**2
        A = m / rho
        alpha = ones_like(x)
        exp_lambda = zeros_like(x)

        tv = zeros_like(x)
        tu = zeros_like(x)

        u = zeros_like(x)
        u_prev_iter = zeros_like(x)
        v = zeros_like(x)
        v_prev_iter = zeros_like(x)

        dt_cfl = zeros_like(x)

        au = zeros_like(x)
        av = zeros_like(x)

        pa = gpa(x=x, y=y, m=m, rho0=rho0, rho=rho, exp_lambda=exp_lambda,
                rho_prev_iter=rho_prev_iter, rho_residual=rho_residual,
                positive_rho_residual=positive_rho_residual,
                summation_rho=summation_rho, alpha=alpha, h=h, u=u, v=v,
                u_prev_iter=u_prev_iter, v_prev_iter=v_prev_iter, au=au, av=av,
                A=A, cs=cs, dt_cfl=dt_cfl, tv=tv, tu=tu, p=p, dw=dw,
                name='fluid')

        props = ['u', 'v', 'm', 'tu', 'tv', 'dw', 'au', 'av', 'h', 'rho', 'p']
        pa.add_output_arrays(props)
        print ( "Triangular Dam break :: %d particles"
                %(pa.get_number_of_particles()) )

        return [pa]
Exemple #23
0
    def create_particles(self):
        # create all the particles
        _x = np.arange(-ghost_extent, length_x + ghost_extent, dx)
        _y = np.arange(-ghost_extent, length_y, dx)
        x, y = np.meshgrid(_x, _y)
        x = x.ravel()
        y = y.ravel()

        # sort out the fluid and the solid
        fluid_indices = []
        air_indices = []
        for i in range(x.size):
            if ((x[i] > 0.0) and (x[i] < length_x)):
                if (y[i] > 0.0):
                    if (y[i] < liquid_height):
                        fluid_indices.append(i)
                    elif (y[i] < liquid_height + air_height):
                        air_indices.append(i)

        # create the arrays
        solid = gpa(name='solid', x=x, y=y)

        # remove the fluid particles from the solid
        fluid = solid.extract_particles(fluid_indices)
        fluid.set_name('fluid')
        indices_to_remove = fluid_indices + air_indices
        solid.remove_particles(indices_to_remove)

        # remove the lid to generate an open tank

        # actually, i am skipping this
        ''' print("Hydrostatic tank :: nfluid = %d, nsolid = %d, dt = %g"%(
            fluid.get_number_of_particles(),
            solid.get_number_of_particles(), dt)) '''

        ###### ADD PARTICLE PROPS FOR MULTI-PHASE SPH ######

        # particle volume
        fluid.add_property('V')
        solid.add_property('V')

        # material stuff I am working on
        fluid.add_property('material_amount')
        fluid.add_property('material_velocity')
        solid.add_property('material_amount')
        solid.add_property('material_velocity')

        # kernel sum term for boundary particles
        solid.add_property('wij')

        # advection velocities and accelerations
        for name in ('auhat', 'avhat', 'awhat'):
            fluid.add_property(name)

        ##### INITIALIZE PARTICLE PROPS #####
        fluid.rho[:] = rho0
        solid.rho[:] = rho0

        fluid.rho0[:] = rho0
        solid.rho0[:] = rho0

        # mass is set to get the reference density of rho0
        volume = dx * dx

        # volume is set as dx^2
        fluid.V[:] = 1. / volume
        solid.V[:] = 1. / volume

        fluid.m[:] = volume * rho0
        solid.m[:] = volume * rho0

        # smoothing lengths
        fluid.h[:] = hdx * dx
        solid.h[:] = hdx * dx

        # Giving fluid particles properties 'material_amount' and 'material_velocity'
        fluid.material_amount[:] = 5.0
        fluid.material_amount[50] = 50
        fluid.material_velocity[:] = 0.0
        solid.material_amount[:] = 50.0
        solid.material_velocity[:] = 0.0

        properties_to_save = [
            'pid', 'tag', 'material_velocity', 'gid', 'material_amount', 'rho',
            'V', 'h', 'm', 'p', 'u', 'w', 'v', 'y', 'x', 'div', 'z'
        ]

        solid.set_output_arrays(properties_to_save)
        fluid.set_output_arrays(properties_to_save)

        #print('fluid material amount: ', fluid.material_amount, 'fluid props', fluid.properties.keys())

        # return the particle list
        return [fluid, solid]
Exemple #24
0
    def create_particles(self):
        # create the particle arrays
        x_bowl, y_bowl, x_spoon, y_spoon, x_tahini, y_tahini = create_particles_xy(
        )

        bowl = gpa(name='bowl', x=x_bowl, y=y_bowl)

        tahini = gpa(name='tahini', x=x_tahini, y=y_tahini)

        spoon = gpa(name='spoon', x=x_spoon, y=y_spoon)

        print("Tahini bowl :: ntahini = %d, nbowl=%d, dt = %g" %
              (tahini.get_number_of_particles(),
               bowl.get_number_of_particles(), dt))

        ###### ADD PARTICLE PROPS FOR MULTI-PHASE SPH ######

        # particle volume
        tahini.add_property('V')
        bowl.add_property('V')
        spoon.add_property('V')

        # kernel sum term for boundary particles
        bowl.add_property('wij')
        spoon.add_property('wij')

        # advection velocities and accelerations
        for name in ('auhat', 'avhat', 'awhat'):
            tahini.add_property(name)

        ##### INITIALIZE PARTICLE PROPS #####
        tahini.rho[:] = rho0
        bowl.rho[:] = rho0
        spoon.rho[:] = rho0

        # mass is set to get the reference density of rho0
        volume = dx * dx

        # volume is set as dx^2
        tahini.V[:] = 1. / volume
        bowl.V[:] = 1. / volume
        spoon.V[:] = 1. / volume

        tahini.m[:] = volume * rho0
        bowl.m[:] = volume * rho0
        spoon.m[:] = volume * rho0  #* 1e-3

        # smoothing lengths
        tahini.h[:] = hdx * dx
        bowl.h[:] = hdx * dx
        spoon.h[:] = hdx * dx

        ##### INITIALIZE TAHINI/WATER PROPS #####

        tahini.add_property('h2o_amount')
        #tahini.h2o_amount[:] = np.random.normal(0.5, 0.05, n)
        tahini.add_property('h2o_velocity')

        # lean and mean
        tahini.set_output_arrays(['h2o_amount', 'x', 'y', 'z', 'u', 'w', 'v'])
        bowl.set_output_arrays(['gid', 'x', 'y', 'z', 'u', 'w', 'v'])
        spoon.set_output_arrays(['gid', 'x', 'y', 'z', 'u', 'w', 'v'])

        # return the particle list
        return [tahini, bowl, spoon]
Exemple #25
0
    def create_particles(self):
        """Create the circular patch of fluid."""
        x = zeros(0)
        y = zeros(0)
        m = zeros(0)

        # Create circular patch in a radial grid
        rad = 0.0
        for j in range(1, n+1):
                npnts = 4 * j
                dtheta = (2*pi) / npnts

                theta = arange(0, 2*pi-1e-10, dtheta)
                rad = rad + dr

                _x = rad * cos(theta)
                _y = rad * sin(theta)

                x = concatenate( (x, _x) )
                y = concatenate( (y, _y) )

        m = ones_like(x) * 0.025/16. * 0.025 * rho_w * .25
        h = ones_like(x) * hdx * dx

        rho = ones_like(x) * rho_w
        rho0 = ones_like(x) * rho_w
        rho_prev_iter = ones_like(x)
        rho_residual= zeros_like(x)
        positive_rho_residual = zeros_like(x)
        summation_rho = zeros_like(x)

        dw = ones_like(x) * d
        cs = ones_like(x) * sqrt(9.8*d)
        p = ones_like(x) * 0.5 * rho_w * g * d**2
        A = m / rho
        alpha = ones_like(x)
        exp_lambda = zeros_like(x)


        tv = zeros_like(x)
        tu = zeros_like(x)

        u = zeros_like(x)
        u_prev_iter = zeros_like(x)
        v = zeros_like(x)
        v_prev_iter = zeros_like(x)

        dt_cfl = zeros_like(x)

        au = zeros_like(x)
        av = zeros_like(x)

        pa = gpa(x=x, y=y, m=m, rho0=rho0, rho=rho, exp_lambda=exp_lambda,
                rho_prev_iter=rho_prev_iter, rho_residual=rho_residual,
                positive_rho_residual=positive_rho_residual,
                summation_rho=summation_rho, alpha=alpha, h=h, u=u, v=v,
                u_prev_iter=u_prev_iter, v_prev_iter=v_prev_iter, au=au, av=av,
                A=A, cs=cs, dt_cfl=dt_cfl, tv=tv, tu=tu, p=p, dw=dw,
                name='fluid')

        props = ['u', 'v', 'tu', 'tv', 'dw', 'au', 'av', 'h', 'rho', 'p']
        pa.add_output_arrays(props)
        print ( "Cylindrical Dam break :: %d particles"
                %(pa.get_number_of_particles()) )

        return [pa]
Exemple #26
0
    def create_particles(self):
        # create all the particles
        _x = np.arange(-ghost_extent, Lx + ghost_extent, dx)
        _y = np.arange(-ghost_extent, Ly, dx)
        x, y = np.meshgrid(_x, _y)
        x = x.ravel()
        y = y.ravel()

        # sort out the fluid and the solid
        indices = []
        for i in range(x.size):
            if ((x[i] > 0.0) and (x[i] < Lx)):
                if ((y[i] > 0.0) and (y[i] < H)):
                    indices.append(i)

        # create the arrays
        solid = gpa(name='solid', x=x, y=y)

        # remove the fluid particles from the solid
        fluid = solid.extract_particles(indices)
        fluid.set_name('fluid')
        solid.remove_particles(indices)

        # remove the lid to generate an open tank
        indices = []
        for i in range(solid.get_number_of_particles()):
            if solid.y[i] > 0.9:
                if (0 < solid.x[i] < Lx):
                    indices.append(i)
        solid.remove_particles(indices)

        print("Hydrostatic tank :: nfluid = %d, nsolid=%d, dt = %g" % (
            fluid.get_number_of_particles(),
            solid.get_number_of_particles(), dt))

        ###### ADD PARTICLE PROPS FOR MULTI-PHASE SPH ######

        # particle volume
        fluid.add_property('V')
        solid.add_property('V')

        # kernel sum term for boundary particles
        solid.add_property('wij')

        # advection velocities and accelerations
        for name in ('auhat', 'avhat', 'awhat'):
            fluid.add_property(name)

        ##### INITIALIZE PARTICLE PROPS #####
        fluid.rho[:] = rho0
        solid.rho[:] = rho0

        fluid.rho0[:] = rho0
        solid.rho0[:] = rho0

        # mass is set to get the reference density of rho0
        volume = dx * dx

        # volume is set as dx^2
        fluid.V[:] = 1. / volume
        solid.V[:] = 1. / volume

        fluid.m[:] = volume * rho0
        solid.m[:] = volume * rho0

        # smoothing lengths
        fluid.h[:] = hdx * dx
        solid.h[:] = hdx * dx

        # return the particle list
        return [fluid, solid]
Exemple #27
0
    def create_particles(self):

        # create mixture particle
        materials = MixtureParticle(baseProperties={'rho0': rho1, 'p0': p1})
        materials.addMaterial('water', {'_frac': 0.8, 'm': 0.10})
        materials.addMaterial('oil', {'_frac': 0.2, 'm': 0.09})

        print(materials.getMaterialList())

        print('FULL PARTICLE PROPERTIES:',
              materials.generateFullParticleProperties())

        materials.addMaterialProperties('oil', {'rho': .008})
        materials.addMaterialDriftVelocities(dim=2)

        print(materials.getMaterialList())

        print(materials.generateFullParticleProperties())

        # create all the particles
        _x = np.arange(-ghost_extent, length_x + ghost_extent, dx)
        _y = np.arange(-ghost_extent, length_y, dx)
        x, y = np.meshgrid(_x, _y)
        x = x.ravel()
        y = y.ravel()

        # sort out the fluid and the solid
        fluid_indices = []
        air_indices = []
        for i in range(x.size):
            if ((x[i] > 0.0) and (x[i] < length_x)):
                if (y[i] > 0.0):
                    if (y[i] < liquid_height):
                        fluid_indices.append(i)
                    elif (y[i] < liquid_height + air_height):
                        air_indices.append(i)

        # create the arrays
        solid = gpa(name='solid', x=x, y=y)

        # remove the fluid particles from the solid
        fluid = solid.extract_particles(fluid_indices)
        fluid.set_name('fluid')
        print('len', fluid.get_number_of_particles())

        # make half of the fluid particles water and the other half oil
        water_indicies = []
        oil_indicies = []
        for i in range(fluid.get_number_of_particles()):
            if (i < fluid.get_number_of_particles() / 2.0):
                oil_indicies.append(i)
            else:
                water_indicies.append(i)

        water = fluid.extract_particles(water_indicies)
        water.set_name('fluid1')
        oil = fluid.extract_particles(oil_indicies)
        oil.set_name('fluid2')

        fluid.remove_particles(fluid_indices)

        indices_to_remove = fluid_indices + air_indices
        solid.remove_particles(indices_to_remove)

        # remove the lid to generate an open tank

        # actually, i am skipping this
        ''' print("Hydrostatic tank :: nfluid = %d, nsolid = %d, dt = %g"%(
            fluid.get_number_of_particles(),
            solid.get_number_of_particles(), dt)) '''

        ###### ADD PARTICLE PROPS FOR MULTI-PHASE SPH ######

        # particle volume
        water.add_property('V')
        oil.add_property('V')
        solid.add_property('V')

        # kernel sum term for boundary particles
        solid.add_property('wij')

        # advection velocities and accelerations
        for name in ('auhat', 'avhat', 'awhat'):
            water.add_property(name)
            oil.add_property(name)

        # water.copy_over_properties(materials.generateFullParticleProperties())
        # oil.copy_over_properties(materials.generateFullParticleProperties())

        ##### INITIALIZE PARTICLE PROPS #####
        waterRho = rho1
        water.rho[:] = waterRho
        water.rho0[:] = waterRho

        oilRho = rho2
        oil.rho[:] = oilRho
        oil.rho0[:] = oilRho

        solidRho = rho1
        solid.rho[:] = solidRho
        solid.rho0[:] = solidRho

        self.scheme.setup_properties([solid, water, oil])

        for propertyName in materials.generateFullParticleProperties():
            water.add_property(
                propertyName,
                type='double',
                default=materials.getPropertyValue(propertyName))
            oil.add_property(propertyName,
                             type='double',
                             default=materials.getPropertyValue(propertyName))

        # fix this
        waterRho = rho1
        water.rho[:] = waterRho
        water.rho0[:] = waterRho

        oilRho = rho2
        oil.rho[:] = oilRho
        oil.rho0[:] = oilRho

        solidRho = rho1
        solid.rho[:] = solidRho
        # solid.rho0[:] = solidRho

        print('water default', water.default_values)
        print('oil default', oil.default_values)

        # mass is set to get the reference density of rho0
        volume = dx * dx

        VTarget = 1. / volume

        waterMass = volume * waterRho
        oilMass = volume * oilRho
        solidMass = volume * solidRho

        water.m[:] = waterMass
        oil.m[:] = oilMass
        solid.m[:] = solidMass

        print('volume', volume, 'VTarget', VTarget, 'waterRho', waterRho,
              'waterMass', waterMass, 'water.V', waterRho / waterMass)
        print('volume', volume, 'VTarget', VTarget, 'oilRho', oilRho,
              'oilMass', oilMass, 'oil.V', oilRho / oilMass)

        # volume is set to density/mass
        water.V[:] = waterRho / waterMass
        oil.V[:] = oilRho / oilMass
        solid.V[:] = solidRho / solidMass

        # smoothing lengths
        water.h[:] = hdx * dx
        oil.h[:] = hdx * dx
        solid.h[:] = hdx * dx

        properties_to_save = [
            'pid', 'tag', 'gid', 'rho', 'V', 'h', 'm', 'p', 'u', 'w', 'v', 'y',
            'x', 'z'
        ]

        for propertyName in materials.generateFullParticleProperties():
            properties_to_save.append(propertyName)

        print('properties to save', properties_to_save)

        water.align_particles()
        oil.align_particles()

        water.set_output_arrays(properties_to_save)
        oil.set_output_arrays(properties_to_save)

        #print('fluid material amount: ', fluid.material_amount, 'fluid props', fluid.properties.keys())

        # return the particle list

        return [water, oil, solid]
Exemple #28
0
    def create_particles_constant_volume(self):
        dx = self.dx
        dx2 = dx * 0.5
        vol = dx * dx

        xmin = config.xmin
        ymin = config.ymin
        xmax = config.xmax
        ymax = config.ymax
        xmid = config.xmid
        ymid = config.ymid

        rho1, u1, v1, p1 = config.rho1, config.u1, config.v1, config.p1
        rho2, u2, v2, p2 = config.rho2, config.u2, config.v2, config.p2
        rho3, u3, v3, p3 = config.rho3, config.u3, config.v3, config.p3
        rho4, u4, v4, p4 = config.rho4, config.u4, config.v4, config.p4
        x, y = numpy.mgrid[xmin + dx2:xmax:dx, ymin + dx2:ymax:dx]

        x = x.ravel()
        y = y.ravel()

        u = numpy.zeros_like(x)
        v = numpy.zeros_like(x)

        # density and mass
        rho = numpy.ones_like(x)
        p = numpy.ones_like(x)

        for i in range(x.size):
            if x[i] <= xmid:
                if y[i] <= ymid:  # w3
                    rho[i] = rho3
                    p[i] = p3
                    u[i] = u3
                    v[i] = v3
                else:  # w2
                    rho[i] = rho2
                    p[i] = p2
                    u[i] = u2
                    v[i] = v2
            else:
                if y[i] <= ymid:  # w4
                    rho[i] = rho4
                    p[i] = p4
                    u[i] = u4
                    v[i] = v4
                else:  # w1
                    rho[i] = rho1
                    p[i] = p1
                    u[i] = u1
                    v[i] = v1

        # thermal energy
        e = p / (gamma1 * rho)

        # mass
        m = vol * rho

        # smoothing length
        h = kernel_factor * (m / rho)**(1. / dim)

        # create the particle array
        pa = gpa(name='fluid',
                 x=x,
                 y=y,
                 m=m,
                 rho=rho,
                 h=h,
                 u=u,
                 v=v,
                 p=p,
                 e=e,
                 h0=h.copy())

        return pa
Exemple #29
0
    def create_particles_constant_mass(self):
        dx = self.dx

        xmin = config.xmin
        ymin = config.ymin
        xmax = config.xmax
        ymax = config.ymax
        xmid = config.xmid
        ymid = config.ymid

        rho_max = config.rho_max
        nb4 = self.nx / 4
        dx0 = (xmax - xmid) / nb4
        vol0 = dx0 * dx0
        m0 = rho_max * vol0

        # first quadrant
        vol1 = config.rho_max / config.rho1 * vol0
        dx = numpy.sqrt(vol1)
        dxb2 = 0.5 * dx
        x1, y1 = numpy.mgrid[xmid + dxb2:xmax:dx, ymid + dxb2:ymax:dx]
        x1 = x1.ravel()
        y1 = y1.ravel()

        u1 = numpy.ones_like(x1) * config.u1
        v1 = numpy.zeros_like(x1) * config.v1
        rho1 = numpy.ones_like(x1) * config.rho1
        p1 = numpy.ones_like(x1) * config.p1
        m1 = numpy.ones_like(x1) * m0
        h1 = numpy.ones_like(x1) * kernel_factor * (m1 / rho1)**(0.5)

        # second quadrant
        vol2 = config.rho_max / config.rho2 * vol0
        dx = numpy.sqrt(vol2)
        dxb2 = 0.5 * dx
        x2, y2 = numpy.mgrid[xmid - dxb2:xmin:-dx, ymid + dxb2:ymax:dx]
        x2 = x2.ravel()
        y2 = y2.ravel()
        u2 = numpy.ones_like(x2) * config.u2
        v2 = numpy.ones_like(x2) * config.v2
        rho2 = numpy.ones_like(x2) * config.rho2
        p2 = numpy.ones_like(x2) * config.p2
        m2 = numpy.ones_like(x2) * m0
        h2 = numpy.ones_like(x2) * kernel_factor * (m2 / rho2)**(0.5)

        # third quadrant
        vol3 = config.rho_max / config.rho3 * vol0
        dx = numpy.sqrt(vol3)
        dxb2 = 0.5 * dx
        x3, y3 = numpy.mgrid[xmid - dxb2:xmin:-dx, ymid - dxb2:ymin:-dx]
        x3 = x3.ravel()
        y3 = y3.ravel()

        u3 = numpy.ones_like(x3) * config.u3
        v3 = numpy.ones_like(x3) * config.v3
        rho3 = numpy.ones_like(x3) * config.rho3
        p3 = numpy.ones_like(x3) * config.p3
        m3 = numpy.ones_like(x3) * m0
        h3 = numpy.ones_like(x3) * kernel_factor * (m3 / rho3)**(0.5)

        # fourth quadrant
        vol4 = config.rho_max / config.rho4 * vol0
        dx = numpy.sqrt(vol4)
        dxb2 = 0.5 * dx
        x4, y4 = numpy.mgrid[xmid + dxb2:xmax:dx, ymid - dxb2:ymin:-dx]
        x4 = x4.ravel()
        y4 = y4.ravel()

        u4 = numpy.ones_like(x4) * config.u4
        v4 = numpy.ones_like(x4) * config.v4
        rho4 = numpy.ones_like(x4) * config.rho4
        p4 = numpy.ones_like(x4) * config.p4
        m4 = numpy.ones_like(x4) * m0
        h4 = numpy.ones_like(x4) * kernel_factor * (m4 / rho4)**(0.5)

        # concatenate the arrays
        x = numpy.concatenate([x1, x2, x3, x4])
        y = numpy.concatenate([y1, y2, y3, y4])
        p = numpy.concatenate([p1, p2, p3, p4])
        u = numpy.concatenate([u1, u2, u3, u4])
        v = numpy.concatenate([v1, v2, v3, v4])
        h = numpy.concatenate([h1, h2, h3, h4])
        m = numpy.concatenate([m1, m2, m3, m4])
        rho = numpy.concatenate([rho1, rho2, rho3, rho4])

        # derived variables
        e = p / ((gamma - 1.0) * rho)

        # create the particle array
        pa = gpa(name='fluid',
                 x=x,
                 y=y,
                 m=m,
                 rho=rho,
                 h=h,
                 u=u,
                 v=v,
                 p=p,
                 e=e,
                 h0=h.copy())

        return pa
Exemple #30
0
def sphysics2pysph(partfile, indat='INDAT', dim=3, vtk=True):
    """Load an SPHysics part file and input data

    Parameters:

    partfile : str
        SPHysics part file (eq IPART, PART_00032, etc)

    indat : str
        SPHysics input data file

    dim : int
        Dimension for SPHysics files

    vtk : bint
        Flag to dump VTK output

    Notes:

    The dimension is very important as the SPHysics particle data is
    different in the 2D and 3D cases.

    """
    data = numpy.loadtxt(partfile)

    # sanity check on the input file and problem dimension
    ncols = data.shape[-1]
    if ((ncols == 9) and (dim == 2)):
        raise RuntimeError('Possiblly inconsistent dim and SPHysics part file')

    input_data = numpy.loadtxt(indat)

    partbase = basename(partfile)

    if partbase.startswith('IPART'):
        fileno = 0
    else:
        fileno = int(partbase.split('_')[-1])

    # number of fluid and total number of particles. This is very
    # dangerous and relies on the SPHysics manual (pg. 38)
    dx = float(input_data[21])
    dy = float(input_data[22])
    dz = float(input_data[23])
    h = float(input_data[24])

    np = int(input_data[25])
    nb = int(input_data[26])
    nbf = int(input_data[27])

    # now load the individual arrays
    if dim == 3:
        x = data[:, 0]
        y = data[:, 1]
        z = data[:, 2]
        u = data[:, 3]
        v = data[:, 4]
        w = data[:, 5]

        rho = data[:, 6]
        p = data[:, 7]
        m = data[:, 8]

    else:
        x = data[:, 0]
        z = data[:, 1]
        u = data[:, 2]
        w = data[:, 3]

        rho = data[:, 4]
        p = data[:, 5]
        m = data[:, 6]

    # smoothing lengths
    h = numpy.ones_like(x) * h

    # now create the PySPH arrays
    fluid = gpa(name='fluid',
                x=x[nb:],
                y=y[nb:],
                z=z[nb:],
                u=u[nb:],
                v=v[nb:],
                w=w[nb:],
                rho=rho[nb:],
                p=p[nb:],
                m=m[nb:],
                h=h[nb:])

    solid = gpa(name='boundary',
                x=x[:nb],
                y=y[:nb],
                z=z[:nb],
                u=u[:nb],
                v=v[:nb],
                w=w[:nb],
                rho=rho[:nb],
                p=p[:nb],
                m=m[:nb],
                h=h[:nb])

    # PySPH arrays
    arrays = [fluid, solid]

    # Dump out vtk files for Paraview viewing
    if vtk:
        from .pprocess import PySPH2VTK
        props = ['u', 'v', 'w', 'rho', 'p', 'vmag', 'tag']
        pysph2vtk = PySPH2VTK(arrays, fileno=fileno)

        pysph2vtk.write_vtk('fluid', props)
        pysph2vtk.write_vtk('boundary', props)

    # return the list of arrays
    return arrays
def create_particles(**kwargs):
    # create all the particles
    _x = np.arange( -ghost_extent, Lx + ghost_extent, dx )
    _y = np.arange( -ghost_extent, Ly, dx )
    x, y = np.meshgrid(_x, _y); x = x.ravel(); y = y.ravel()

    # sort out the fluid and the solid
    indices = []
    for i in range(x.size):
        if ( (x[i] > 0.0) and (x[i] < Lx) ):
            if ( (y[i] > 0.0) and (y[i] < H) ):
                indices.append(i)

    # create the arrays
    solid = gpa(name='solid', x=x, y=y)

    # remove the fluid particles from the solid
    fluid = solid.extract_particles(indices); fluid.set_name('fluid')
    solid.remove_particles(indices)

    # remove the lid to generate an open tank
    indices = []
    for i in range(solid.get_number_of_particles()):
        if solid.y[i] > 0.9:
            if (0 < solid.x[i] < Lx):
                indices.append(i)
    solid.remove_particles(indices)

    print "Hydrostatic tank :: nfluid = %d, nsolid=%d, dt = %g"%(
        fluid.get_number_of_particles(),
        solid.get_number_of_particles(), dt)

    ###### ADD PARTICLE PROPS FOR MULTI-PHASE SPH ######

    # particle volume
    fluid.add_property('V')
    solid.add_property('V' )

    # kernel sum term for boundary particles
    solid.add_property('wij')

    # advection velocities and accelerations
    for name in ('auhat', 'avhat', 'awhat'):
        fluid.add_property(name)

    ##### INITIALIZE PARTICLE PROPS #####
    fluid.rho[:] = rho0
    solid.rho[:] = rho0

    fluid.rho0[:] = rho0
    solid.rho0[:] = rho0

    # mass is set to get the reference density of rho0
    volume = dx * dx

    # volume is set as dx^2
    fluid.V[:] = 1./volume
    solid.V[:] = 1./volume

    fluid.m[:] = volume * rho0
    solid.m[:] = volume * rho0

    # smoothing lengths
    fluid.h[:] = hdx * dx
    solid.h[:] = hdx * dx

    # return the particle list
    return [fluid, solid]
Exemple #32
0
    def create_particles(self):
        side = 0.1

        _x = np.arange(Lx * 0.5 - side, Lx * 0.5 + side, dx)
        _y = np.arange(0.8, 0.8 + side * 2, dx)
        x, y = np.meshgrid(_x, _y)
        x = x.ravel()
        y = y.ravel()
        x += 0.25
        m = np.ones_like(x) * dx * dx * rho_block
        h = np.ones_like(x) * hdx * dx
        rho = np.ones_like(x) * rho_block
        block = get_particle_array_rigid_body(name='block',
                                              x=x,
                                              y=y,
                                              h=h,
                                              m=m,
                                              rho=rho)
        block.total_mass[0] = np.sum(m)
        block.vc[0] = 1.0

        # create all the particles
        _x = np.arange(-ghost_extent, Lx + ghost_extent, dx)
        _y = np.arange(-ghost_extent, Ly, dx)
        x, y = np.meshgrid(_x, _y)
        x = x.ravel()
        y = y.ravel()

        # sort out the fluid and the solid
        indices = []
        for i in range(x.size):
            if ((x[i] > 0.0) and (x[i] < Lx)):
                if ((y[i] > 0.0) and (y[i] < H)):
                    indices.append(i)

        # create the arrays
        solid = gpa(name='solid', x=x, y=y)

        # remove the fluid particles from the solid
        fluid = solid.extract_particles(indices)
        fluid.set_name('fluid')
        solid.remove_particles(indices)

        # remove the lid to generate an open tank
        indices = []
        for i in range(solid.get_number_of_particles()):
            if solid.y[i] > H:
                if (0 < solid.x[i] < Lx):
                    indices.append(i)
        solid.remove_particles(indices)

        print("Hydrostatic tank :: nfluid = %d, nsolid=%d, dt = %g" %
              (fluid.get_number_of_particles(),
               solid.get_number_of_particles(), dt))

        ###### ADD PARTICLE PROPS SPH ######

        for prop in ('arho', 'cs', 'V', 'fx', 'fy', 'fz'):
            solid.add_property(prop)
            block.add_property(prop)

        ##### INITIALIZE PARTICLE PROPS #####
        fluid.rho[:] = rho0
        solid.rho[:] = rho0

        fluid.rho0[:] = rho0
        solid.rho0[:] = rho0

        # mass is set to get the reference density of rho0
        volume = dx * dx

        fluid.m[:] = volume * rho0
        solid.m[:] = volume * rho0

        # smoothing lengths
        fluid.h[:] = hdx * dx
        solid.h[:] = hdx * dx

        # return the particle list
        return [fluid, solid, block]
Exemple #33
0
def ndspmhd2pysph(fname, dim=2, read_type=False):
    """Read output data file from NDSPMHD

    Parameters:
    
    fname : str
        NDSPMHD data filename

    dim : int
        Problem dimension

    read_type : bint
        Flag to read the `type` property for particles

    Returns the ParticleArray representation of the data that can be
    used in PySPH.

    """
    f = FortranFile(fname)

    # get the header length
    header_length = f._header_length
    endian = f.ENDIAN
    
    # get the length of the record to be read
    length = f._read_check()

    # now read the individual entries:

    # current time : double
    t = f._read_exactly(8)
    t = struct.unpack(endian+"1d", t)[0]

    # number of particles and number printed : int
    npart = f._read_exactly(4)
    nprint = f._read_exactly(4)

    npart = struct.unpack(endian+"1i", npart)[0]
    nprint = struct.unpack(endian+"1i", nprint)[0]

    # gamma and hfact : double
    gamma = f._read_exactly(8)
    hfact = f._read_exactly(8)

    gamma = struct.unpack(endian+"1d", gamma)[0]
    hfact = struct.unpack(endian+"1d", hfact)[0]

    # ndim, ndimV : int
    ndim = f._read_exactly(4)
    ndimV = f._read_exactly(4)

    # ncollumns, iformat, ibound : int
    nc = f._read_exactly(4)
    ifmt = f._read_exactly(4)
    ib1 = f._read_exactly(4)
    ib2 = f._read_exactly(4)

    nc = struct.unpack(endian+"1i", nc)[0]

    # xmin, xmax : double
    xmin1 = f._read_exactly(8)
    xmin2 = f._read_exactly(8)
    xmax1 = f._read_exactly(8)
    xmax2 = f._read_exactly(8)

    # n : int
    n = f._read_exactly(4)
    n = struct.unpack(endian+"1i", n)[0]

    # geometry type
    geom = f._read_exactly(n)

    # end reading this header
    f._read_check()

    # Now go on to the arrays. Remember, there are 16 entries
    # correcponding to the columns

    x = f.readReals(prec="d")
    y = f.readReals(prec="d")
    u = f.readReals(prec="d")
    v = f.readReals(prec="d")
    w = f.readReals(prec="d")

    h = f.readReals(prec="d")
    rho = f.readReals(prec="d")
    e = f.readReals(prec="d")
    m = f.readReals(prec="d")

    alpha1 = f.readReals(prec="d")
    alpha2 = f.readReals(prec="d")

    p = f.readReals(prec="d")
    drhobdtbrho = f.readReals("d")
    gradh = f.readReals("d")

    au = f.readReals("d")
    av = f.readReals("d")
    aw = f.readReals("d")

    # By default, NDSPMHD does not output the type array. You need to
    # add this to the output routine if you want it.
    if read_type:
        type = f.readInts(prec="i")

    # now create the particle array
    pa = gpa(name='fluid', x=x, y=y, m=m, h=h, rho=rho, e=e, p=p, 
             u=u, v=v, w=w, au=au, av=av, aw=aw, div=drhobdtbrho)

    return pa
    def create_particles(self):
        x, y = mgrid[0:1400 + 1e-4:dx, 0:1400 + 1e-4:dx]
        x = x.ravel()
        y = y.ravel()

        idx_inner_pa_to_split = []
        for idx, (x_i, y_i) in enumerate(zip(x, y)):
            if 300 <= x_i <= 1100 and 300 <= y_i <= 1100:
                idx_inner_pa_to_split.append(idx)
        idx_inner_pa_to_split = numpy.array(idx_inner_pa_to_split)

        m = ones_like(x) * dx * dx * rho_w
        h = ones_like(x) * h0

        rho = ones_like(x) * rho_w
        rho0 = ones_like(x) * rho_w
        rho_prev_iter = zeros_like(x)
        rho_residual = zeros_like(x)
        positive_rho_residual = zeros_like(x)
        summation_rho = zeros_like(x)

        A = m / rho
        A[idx_inner_pa_to_split] = 3000

        dw = ones_like(x) * d
        p = ones_like(x) * 0.5 * rho_w * g * d**2

        pa_to_split = zeros_like(x)
        parent_idx = zeros_like(x)
        alpha = zeros_like(x)
        psi = zeros_like(x)
        cs = ones_like(x)
        dt_cfl = ones_like(x)

        tv = zeros_like(x)
        tu = zeros_like(x)

        u = zeros_like(x)
        u_prev_iter = zeros_like(x)
        v = zeros_like(x)
        v_prev_iter = zeros_like(x)

        au = zeros_like(x)
        av = zeros_like(x)

        consts = {'tmp_comp': [0.0, 0.0]}

        pa = gpa(x=x,
                 y=y,
                 m=m,
                 rho0=rho0,
                 rho=rho,
                 alpha=alpha,
                 rho_prev_iter=rho_prev_iter,
                 psi=psi,
                 h=h,
                 u=u,
                 v=v,
                 u_prev_iter=u_prev_iter,
                 v_prev_iter=v_prev_iter,
                 au=au,
                 av=av,
                 A=A,
                 cs=cs,
                 dt_cfl=dt_cfl,
                 tv=tv,
                 tu=tu,
                 p=p,
                 dw=dw,
                 parent_idx=parent_idx,
                 pa_to_split=pa_to_split,
                 name='fluid',
                 constants=consts)

        props = ['m', 'h', 'rho', 'p', 'A', 'pa_to_split']
        pa.add_output_arrays(props)
        compute_initial_props([pa])
        return [pa]
Exemple #35
0
    def create_particles(self):
        """Create the Rectangular patch of fluid."""
        x, y = mgrid[-1000:1000+1e-4:dx, -500:500+1e-4:dx]
        x = x.ravel()
        y = y.ravel()

        m = ones_like(x) * dx * dx * rho_w * d
        h = ones_like(x) * h0

        rho = ones_like(x) * rho_w
        rho0 = ones_like(x) * rho_w
        rho_prev_iter = ones_like(x) * rho_w

        A = m / rho

        dw = ones_like(x) * d
        cs = ones_like(x) * sqrt(9.8*d)
        p = ones_like(x) * 0.5 * rho_w * g * d**2
        alpha = ones_like(x)

        pa_to_split = zeros_like(x)
        sum_Ak = zeros_like(x)
        psi = zeros_like(x)

        tv = zeros_like(x)
        tu = zeros_like(x)

        u = zeros_like(x)
        u_parent = zeros_like(x)
        uh = zeros_like(x)
        u_prev_iter = zeros_like(x)
        v = zeros_like(x)
        v_parent = zeros_like(x)
        vh = zeros_like(x)
        v_prev_iter = zeros_like(x)

        dt_cfl = ones_like(x)

        au = zeros_like(x)
        av = zeros_like(x)

        Sfx = zeros_like(x)
        Sfy = zeros_like(x)

        consts = {'tmp_comp': [0.0, 0.0]}

        pa = gpa(x=x, y=y, m=m, rho0=rho0, rho=rho, A=A, psi=psi, cs=cs,
                 alpha=alpha, h=h, u=u, v=v, uh=uh, vh=vh, Sfx=Sfx, Sfy=Sfy,
                 u_prev_iter=u_prev_iter, sum_Ak=sum_Ak, u_parent=u_parent,
                 v_parent=v_parent, pa_to_split=pa_to_split, dt_cfl=dt_cfl,
                 v_prev_iter=v_prev_iter, au=au, av=av, tv=tv, tu=tu, p=p,
                 rho_prev_iter=rho_prev_iter, dw=dw, name='fluid',
                 constants=consts)

        pa.add_property('parent_idx', type='int')

        props = ['parent_idx', 'A', 'u', 'v', 'm', 'tu', 'tv', 'dw', 'au',
                'av', 'h', 'rho', 'p', 'pa_to_split']
        pa.add_output_arrays(props)

        compute_initial_props([pa])
        return [pa]