Beispiel #1
0
    def post_loop(self, d_idx, d_gradv, d_invtt, d_divv):
        tt, invtt, idmat, gradv = declare('matrix(9)', 4)
        augtt = declare('matrix(18)')

        start_indx, row, col, rowcol, drowcol, dim = declare('int', 6)

        dim = self.dim
        start_indx = 9 * d_idx
        identity(idmat, 3)
        identity(tt, 3)

        for row in range(3):
            for col in range(3):
                rowcol = row * 3 + col
                drowcol = start_indx + rowcol
                gradv[rowcol] = d_gradv[drowcol]

        for row in range(dim):
            for col in range(dim):
                rowcol = row * 3 + col
                drowcol = start_indx + rowcol
                tt[rowcol] = d_invtt[drowcol]

        augmented_matrix(tt, idmat, 3, 3, 3, augtt)
        gj_solve(augtt, 3, 3, invtt)
        gradvls = declare('matrix(9)')
        mat_mult(gradv, invtt, 3, gradvls)

        for row in range(dim):
            d_divv[d_idx] += gradvls[row * 3 + row]
            for col in range(dim):
                rowcol = row * 3 + col
                drowcol = start_indx + rowcol
                d_gradv[drowcol] = gradvls[rowcol]
        def out_fill_ghosts(i, item, prev_item, periodic_in_x, periodic_in_y,
                            periodic_in_z, x, y, z, xmin, ymin, zmin, xmax,
                            ymax, zmax, cell_size, masks, indices):
            xleft, yleft, zleft = declare('int', 3)
            xright, yright, zright = declare('int', 3)

            xleft = 0
            yleft = 0
            zleft = 0

            xright = 0
            yright = 0
            zright = 0

            if periodic_in_x:
                if (x[i] - xmin) <= cell_size:
                    xright = 1
                if (xmax - x[i]) <= cell_size:
                    xleft = -1

            if periodic_in_y:
                if (y[i] - ymin) <= cell_size:
                    yright = 1
                if (ymax - y[i]) <= cell_size:
                    yleft = -1

            if periodic_in_z:
                if (z[i] - zmin) <= cell_size:
                    zright = 1
                if (zmax - z[i]) <= cell_size:
                    zleft = -1

            xp, yp, zp = declare('int', 3)
            idx, mask = declare('int', 2)

            idx = prev_item

            for xp in range(-1, 2):
                if xp != 0 and ((xleft == 0 and xright == 0) or
                                (xp != xleft and xp != xright)):
                    continue
                for yp in range(-1, 2):
                    if yp != 0 and ((yleft == 0 and yright == 0) or
                                    (yp != yleft and yp != yright)):
                        continue
                    for zp in range(-1, 2):
                        if zp != 0 and ((zleft == 0 and zright == 0) or
                                        (zp != zleft and zp != zright)):
                            continue
                        if xp == 0 and yp == 0 and zp == 0:
                            continue
                        mask = (xp + 1) * 9 + (yp + 1) * 3 + (zp + 1)
                        masks[idx] = mask
                        indices[idx] = i
                        idx += 1
        def inp_fill_ghosts(i, periodic_in_x, periodic_in_y, periodic_in_z, x,
                            y, z, xmin, ymin, zmin, xmax, ymax, zmax,
                            cell_size):
            x_copies, y_copies, z_copies = declare('int', 3)

            x_copies = 1
            y_copies = 1
            z_copies = 1

            if periodic_in_x:
                if (x[i] - xmin) <= cell_size:
                    x_copies += 1
                if (xmax - x[i]) <= cell_size:
                    x_copies += 1

            if periodic_in_y:
                if (y[i] - ymin) <= cell_size:
                    y_copies += 1
                if (ymax - y[i]) <= cell_size:
                    y_copies += 1

            if periodic_in_z:
                if (z[i] - zmin) <= cell_size:
                    z_copies += 1
                if (zmax - z[i]) <= cell_size:
                    z_copies += 1

            return x_copies * y_copies * z_copies - 1
Beispiel #4
0
    def loop(self, d_idx, d_invtt, s_m, s_idx, VIJ, DWI, XIJ, d_gradv, d_grada,
             d_au, s_au, d_av, s_av, d_aw, s_aw):
        start_indx, row, col, drowcol, dim = declare('int', 5)
        dim = self.dim
        start_indx = d_idx * 9

        aij = declare('matrix(3)')

        aij[0] = d_au[d_idx] - s_au[s_idx]
        aij[1] = d_av[d_idx] - s_av[s_idx]
        aij[2] = d_aw[d_idx] - s_aw[s_idx]

        for row in range(dim):
            for col in range(dim):
                drowcol = start_indx + row * 3 + col
                d_invtt[drowcol] -= s_m[s_idx] * XIJ[row] * DWI[col]
                d_gradv[drowcol] -= s_m[s_idx] * VIJ[row] * DWI[col]
                d_grada[drowcol] -= s_m[s_idx] * aij[row] * DWI[col]
Beispiel #5
0
 def loop(self, d_idx, d_invtt, s_m, s_idx, VIJ, DWI, XIJ, d_gradv):
     start_indx, row, col, drowcol, dim = declare('int', 5)
     dim = self.dim
     start_indx = d_idx * 9
     for row in range(dim):
         for col in range(dim):
             drowcol = start_indx + row * 3 + col
             d_invtt[drowcol] -= s_m[s_idx] * XIJ[row] * DWI[col]
             d_gradv[drowcol] -= s_m[s_idx] * VIJ[row] * DWI[col]
Beispiel #6
0
    def initialize(self, d_gradv, d_idx, d_invtt, d_divv):
        start_indx, i, dim = declare('int', 3)
        start_indx = 9 * d_idx

        for i in range(9):
            d_gradv[start_indx + i] = 0.0
            d_invtt[start_indx + i] = 0.0

        d_divv[d_idx] = 0.0
Beispiel #7
0
 def initialize(self, d_idx, d_orig_idx, d_p, d_tag, d_h, d_rho, d_dndh,
                d_psumdh, d_n):
     idx = declare('int')
     if d_tag[d_idx] == 2:
         idx = d_orig_idx[d_idx]
         d_p[d_idx] = d_p[idx]
         d_h[d_idx] = d_h[idx]
         d_rho[d_idx] = d_rho[idx]
         d_dndh[d_idx] = d_dndh[idx]
         d_psumdh[d_idx] = d_psumdh[idx]
         d_n[d_idx] = d_n[idx]
Beispiel #8
0
    def loop_all(self, d_idx, d_x, d_y, d_z, s_x, s_y, s_z, d_u, d_v, d_w, s_u,
                 s_v, s_w, d_cs, s_cs, d_vsig, NBRS, N_NBRS):
        i = declare('int')
        s_idx = declare('long')
        xij = declare('matrix(3)')
        vij = declare('matrix(3)')
        vijdotxij = 0.0
        cij = 0.0

        for i in range(N_NBRS):
            s_idx = NBRS[i]
            xij[0] = d_x[d_idx] - s_x[s_idx]
            xij[1] = d_y[d_idx] - s_y[s_idx]
            xij[2] = d_z[d_idx] - s_z[s_idx]

            vij[0] = d_u[d_idx] - s_u[s_idx]
            vij[1] = d_v[d_idx] - s_v[s_idx]
            vij[2] = d_w[d_idx] - s_w[s_idx]

            vijdotxij = vij[0] * xij[0] + vij[1] * xij[1] + vij[2] * xij[2]
            cij = 0.5 * (d_cs[d_idx] + s_cs[s_idx])

            d_vsig[d_idx] = max(d_vsig[d_idx], cij - min(0, vijdotxij))
        def translate(i, x, y, z, tag, xtranslate, ytranslate, ztranslate,
                      masks):
            xmask, ymask, zmask, mask = declare('int', 4)
            mask = masks[i]

            zmask = mask % 3
            mask /= 3
            ymask = mask % 3
            mask /= 3
            xmask = mask % 3

            x[i] = x[i] + (xmask - 1) * xtranslate
            y[i] = y[i] + (ymask - 1) * ytranslate
            z[i] = z[i] + (zmask - 1) * ztranslate

            tag[i] = 2
Beispiel #10
0
    def post_loop(self, d_h, d_idx, d_cs, d_divv, d_gradv, d_alpha):
        curlv = declare('matrix(3)')

        curlv[0] = (d_gradv[9 * d_idx + 3 * 2 + 1] -
                    d_gradv[9 * d_idx + 3 * 1 + 2])
        curlv[1] = (d_gradv[9 * d_idx + 3 * 0 + 2] -
                    d_gradv[9 * d_idx + 3 * 2 + 0])
        curlv[2] = (d_gradv[9 * d_idx + 3 * 1 + 0] -
                    d_gradv[9 * d_idx + 3 * 0 + 1])

        abscurlv = sqrt(curlv[0] * curlv[0] +
                        curlv[1] * curlv[1] +
                        curlv[2] * curlv[2])

        absdivv = abs(d_divv[d_idx])

        fhi = d_h[d_idx] * self.fkern

        d_alpha[d_idx] = self.alphaav * absdivv / (
                absdivv + abscurlv + 0.0001 * d_cs[d_idx] / fhi)
Beispiel #11
0
    def loop(self, d_idx, s_idx, d_m, s_m, d_p, s_p, d_cs, s_cs, d_au, d_av,
             d_aw, d_ae, XIJ, VIJ, DWI, DWJ, d_alpha, s_alpha, RIJ, d_h,
             d_dndh, d_n, s_h, s_dndh, s_n, d_e, s_e, d_dpsumdh, s_dpsumdh,
             RHOIJ1):

        dim = self.dim
        gammam1 = self.gammam1
        avi = declare("matrix(3)")

        # averaged sound speed
        cij = 0.5 * (d_cs[d_idx] + s_cs[s_idx])

        mj = s_m[s_idx]
        vijdotxij = (VIJ[0] * XIJ[0] + VIJ[1] * XIJ[1] + VIJ[2] * XIJ[2])

        if RIJ < 1e-8:
            vs = 2 * cij
            muij = 0.0
            Fij = 0.0
        else:
            vs = 2 * cij - 3 * vijdotxij / RIJ
            muij = vijdotxij / RIJ
            Fij = 0.5 * (XIJ[0] * (DWI[0] + DWJ[0]) + XIJ[1] *
                         (DWI[1] + DWJ[1]) + XIJ[2] * (DWI[2] + DWJ[2])) / RIJ

        # Artificial viscosity
        if vijdotxij <= 0.0:
            alphaij = 0.5 * (d_alpha[d_idx] + s_alpha[s_idx])
            oby2rhoij = RHOIJ1 / 2.0
            common = (alphaij * muij * (cij - self.betab * muij) * mj *
                      oby2rhoij)

            avi[0] = common * (DWI[0] + DWJ[0])
            avi[1] = common * (DWI[1] + DWJ[1])
            avi[2] = common * (DWI[2] + DWJ[2])

            # viscous contribution to velocity
            d_au[d_idx] += avi[0]
            d_av[d_idx] += avi[1]
            d_aw[d_idx] += avi[2]

            # viscous contribution to the thermal energy
            d_ae[d_idx] -= 0.5 * (VIJ[0] * avi[0] + VIJ[1] * avi[1] +
                                  VIJ[2] * avi[2])

            # artificial conductivity
            eij = d_e[d_idx] - s_e[s_idx]
            Lij = abs(d_p[d_idx] - s_p[s_idx]) / (d_p[d_idx] + s_p[s_idx])
            d_ae[d_idx] += (self.alphac * mj * alphaij * vs * eij * Lij * Fij *
                            oby2rhoij)

        # grad-h correction terms.
        hibynidim = d_h[d_idx] / (d_n[d_idx] * dim)
        inbrkti = 1 + d_dndh[d_idx] * hibynidim
        inprthsi = d_dpsumdh[d_idx] * hibynidim / (gammam1 * s_m[s_idx] *
                                                   d_e[d_idx])
        fij = 1 - inprthsi / inbrkti

        hjbynjdim = s_h[s_idx] / (s_n[s_idx] * dim)
        inbrktj = 1 + s_dndh[s_idx] * hjbynjdim
        inprthsj = s_dpsumdh[s_idx] * hjbynjdim / (gammam1 * d_m[d_idx] *
                                                   s_e[s_idx])
        fji = 1 - inprthsj / inbrktj

        # accelerations for velocity
        gammam1sq = gammam1 * gammam1
        comm = gammam1sq * mj * d_e[d_idx] * s_e[s_idx]
        commi = comm * fij / d_p[d_idx]
        commj = comm * fji / s_p[s_idx]

        d_au[d_idx] -= commi * DWI[0] + commj * DWJ[0]
        d_av[d_idx] -= commi * DWI[1] + commj * DWJ[1]
        d_aw[d_idx] -= commi * DWI[2] + commj * DWJ[2]

        # accelerations for the thermal energy
        vijdotdwi = VIJ[0] * DWI[0] + VIJ[1] * DWI[1] + VIJ[2] * DWI[2]
        d_ae[d_idx] += commi * vijdotdwi
Beispiel #12
0
    def post_loop(self, d_idx, d_gradv, d_invtt, d_divv, d_grada, d_adivv,
                  d_ss, d_trssdsst):
        tt = declare('matrix(9)')
        invtt = declare('matrix(9)')
        augtt = declare('matrix(18)')
        idmat = declare('matrix(9)')
        gradv = declare('matrix(9)')
        grada = declare('matrix(9)')

        start_indx, row, col, rowcol, drowcol, dim, colrow = declare('int', 7)
        ltstart_indx, dltrowcol = declare('int', 2)
        dim = self.dim
        start_indx = 9 * d_idx
        identity(idmat, 3)
        identity(tt, 3)

        for row in range(3):
            for col in range(3):
                rowcol = row * 3 + col
                drowcol = start_indx + rowcol
                gradv[rowcol] = d_gradv[drowcol]
                grada[rowcol] = d_grada[drowcol]

        for row in range(dim):
            for col in range(dim):
                rowcol = row * 3 + col
                drowcol = start_indx + rowcol
                tt[rowcol] = d_invtt[drowcol]

        augmented_matrix(tt, idmat, 3, 3, 3, augtt)
        gj_solve(augtt, 3, 3, invtt)
        gradvls = declare('matrix(9)')
        gradals = declare('matrix(9)')
        mat_mult(gradv, invtt, 3, gradvls)
        mat_mult(grada, invtt, 3, gradals)

        for row in range(dim):
            d_divv[d_idx] += gradvls[row * 3 + row]
            d_adivv[d_idx] += gradals[row * 3 + row]
            for col in range(dim):
                rowcol = row * 3 + col
                colrow = row + col * 3
                drowcol = start_indx + rowcol
                d_gradv[drowcol] = gradvls[rowcol]
                d_grada[drowcol] = gradals[rowcol]
                d_adivv[d_idx] -= gradals[rowcol] * gradals[colrow]

        # Traceless Symmetric Strain Rate
        divvbydim = d_divv[d_idx] / dim
        start_indx = d_idx * 9
        ltstart_indx = d_idx * 6
        for row in range(dim):
            col = row
            rowcol = start_indx + row * 3 + col
            dltrowcol = ltstart_indx + (row * (row + 1)) / 2 + col
            d_ss[dltrowcol] = d_gradv[rowcol] - divvbydim

        for row in range(1, dim):
            for col in range(row):
                rowcol = row * 3 + col
                colrow = row + col * 3
                dltrowcol = ltstart_indx + (row * (row + 1)) / 2 + col
                d_ss[dltrowcol] = 0.5 * (gradvls[rowcol] + gradvls[colrow])

        # Trace ( S dot transpose(S) )
        for row in range(dim):
            for col in range(dim):
                dltrowcol = ltstart_indx + (row * (row + 1)) / 2 + col
                d_trssdsst[d_idx] += d_ss[dltrowcol] * d_ss[dltrowcol]
Beispiel #13
0
    def loop(self, d_idx, s_idx, d_m, s_m, d_p, s_p, d_cs, s_cs, d_rho, s_rho,
             d_au, d_av, d_aw, d_ae, XIJ, VIJ, DWI, DWJ, HIJ, d_alpha, s_alpha,
             R2IJ, RHOIJ1, d_h, d_dndh, d_n, d_drhosumdh, s_h, s_dndh, s_n,
             s_drhosumdh):
        avi = declare("matrix(3)")
        dim = self.dim

        # particle pressure
        p_i = d_p[d_idx]
        pj = s_p[s_idx]

        # p_i/rhoi**2
        rhoi2 = d_rho[d_idx] * d_rho[d_idx]
        pibrhoi2 = p_i / rhoi2

        # pj/rhoj**2
        rhoj2 = s_rho[s_idx] * s_rho[s_idx]
        pjbrhoj2 = pj / rhoj2

        # averaged sound speed
        cij = 0.5 * (d_cs[d_idx] + s_cs[s_idx])

        mj = s_m[s_idx]
        hij = self.fkern * HIJ
        vijdotxij = (VIJ[0] * XIJ[0] + VIJ[1] * XIJ[1] + VIJ[2] * XIJ[2])

        # Artificial viscosity
        if vijdotxij <= 0.0:
            # viscosity
            alpha = 0.5 * (d_alpha[d_idx] + s_alpha[s_idx])
            muij = hij * vijdotxij / (R2IJ + 0.0001 * hij * hij)
            common = alpha * muij * (cij - self.beta * muij) * mj * RHOIJ1 / 2

            avi[0] = common * (DWI[0] + DWJ[0])
            avi[1] = common * (DWI[1] + DWJ[1])
            avi[2] = common * (DWI[2] + DWJ[2])

            # viscous contribution to velocity
            d_au[d_idx] += avi[0]
            d_av[d_idx] += avi[1]
            d_aw[d_idx] += avi[2]

            # viscous contribution to the thermal energy
            d_ae[d_idx] -= 0.5 * (VIJ[0] * avi[0] +
                                  VIJ[1] * avi[1] +
                                  VIJ[2] * avi[2])

        # grad-h correction terms.
        hibynidim = d_h[d_idx] / (d_n[d_idx] * dim)
        inbrkti = 1 + d_dndh[d_idx] * hibynidim
        inprthsi = d_drhosumdh[d_idx] * hibynidim
        fij = 1 - inprthsi / (s_m[s_idx] * inbrkti)

        hjbynjdim = s_h[s_idx] / (s_n[s_idx] * dim)
        inbrktj = 1 + s_dndh[s_idx] * hjbynjdim
        inprthsj = s_drhosumdh[s_idx] * hjbynjdim
        fji = 1 - inprthsj / (d_m[d_idx] * inbrktj)

        # accelerations for velocity
        comi = mj * pibrhoi2 * fij
        comj = mj * pjbrhoj2 * fji

        d_au[d_idx] -= comi * DWI[0] + comj * DWJ[0]
        d_av[d_idx] -= comi * DWI[1] + comj * DWJ[1]
        d_aw[d_idx] -= comi * DWI[2] + comj * DWJ[2]

        # accelerations for the thermal energy
        vijdotdwi = VIJ[0] * DWI[0] + VIJ[1] * DWI[1] + VIJ[2] * DWI[2]
        d_ae[d_idx] += comi * vijdotdwi