コード例 #1
0
ファイル: crksph.py プロジェクト: RobinHC/pysph
    def loop(self, d_idx, s_idx, d_au, d_av, d_aw, d_ae, s_au, s_av, s_aw,
             d_u0, d_v0, d_w0, s_u0, s_v0, s_w0, d_u, d_v, d_w, s_u, s_v, s_w,
             d_p, d_rho, s_p, s_rho):
        gamma = self.gamma
        d = declare('int')
        d = self.dim
        auij, delu = declare('matrix(3)', 2)
        auij[0] = d_au[d_idx] - s_au[s_idx]
        auij[1] = d_av[d_idx] - s_av[s_idx]
        auij[2] = d_aw[d_idx] - s_aw[s_idx]

        delu[0] = s_u0[s_idx] + s_u[s_idx] - d_u0[d_idx] - d_u[d_idx]
        delu[1] = s_v0[s_idx] + s_v[s_idx] - d_v0[d_idx] - d_v[d_idx]
        delu[2] = s_w0[s_idx] + s_w[s_idx] - d_w0[d_idx] - d_w[d_idx]

        aeij = dot(delu, auij, d)

        si = d_p[d_idx]/((d_rho[d_idx])**gamma)
        sj = s_p[s_idx]/((s_rho[s_idx])**gamma)
        smin = min(abs(si), abs(sj))
        smax = max(abs(si), abs(sj))

        fij = 0.5
        sdiff = si - sj
        if sdiff * aeij > 0:
            fij = smin/(smin + smax)
        elif sdiff * aeij < 0:
            fij = smax/(smin + smax)

        d_ae[d_idx] += 0.5*fij * aeij
コード例 #2
0
    def loop(self, d_idx, s_idx, d_au, d_av, d_aw, d_ae, s_au, s_av, s_aw,
             d_u0, d_v0, d_w0, s_u0, s_v0, s_w0, d_u, d_v, d_w, s_u, s_v, s_w,
             d_p, d_rho, s_p, s_rho, d_m, d_V, s_V, d_cs, s_cs, d_h, s_h, XIJ,
             d_gradv, s_gradv, EPS, DWIJ):
        Cl = self.cl
        Cq = self.cq
        eta_fold = self.eta_fold
        eta_crit = self.eta_crit

        mi = d_m[d_idx]
        Vi = 1.0 / d_V[d_idx]
        Vj = 1.0 / s_V[s_idx]

        pi = d_p[d_idx]
        pj = s_p[s_idx]

        rhoi = d_rho[d_idx]
        rhoj = s_rho[s_idx]

        ci = d_cs[d_idx]
        cj = s_cs[s_idx]

        hi = d_h[d_idx]
        hj = s_h[s_idx]

        alp, bet, i, d = declare('int', 4)
        uijhat, tmpdvxij = declare('matrix(3)', 2)

        d = self.dim

        tmpri = 0.0
        tmprj = 0.0
        for alp in range(d):
            for bet in range(d):
                tmpri += d_gradv[d * d * d_idx + d * alp +
                                 bet] * XIJ[alp] * XIJ[bet]
                tmprj += s_gradv[d * d * s_idx + d * alp +
                                 bet] * XIJ[alp] * XIJ[bet]
        rij = tmpri / tmprj

        tmprij = min(1, 4 * rij / ((1 + rij) * (1 + rij)))
        phiij = max(0, tmprij)

        tmpxij = dot(XIJ, XIJ, d)
        tmpxij2 = sqrt(tmpxij)
        etai_scalar = tmpxij2 / hi
        etaj_scalar = tmpxij2 / hj
        etaij = min(etai_scalar, etaj_scalar)

        if etaij < eta_crit:
            tmpphi = (etaij - eta_crit) / eta_fold
            phiij = phiij * exp(-tmpphi * tmpphi)

        for alp in range(d):
            s = 0.0
            for bet in range(d):
                s += (d_gradv[d * d * d_idx + d * alp + bet] +
                      s_gradv[d * d * s_idx + d * alp + bet]) * XIJ[bet]
            tmpdvxij[alp] = s

        uijhat[0] = d_u0[d_idx] - s_u0[s_idx] - 0.5 * phiij * tmpdvxij[0]
        uijhat[1] = d_v0[d_idx] - s_v0[s_idx] - 0.5 * phiij * tmpdvxij[1]
        uijhat[2] = d_w0[d_idx] - s_w0[s_idx] - 0.5 * phiij * tmpdvxij[2]

        tmpmui = dot(uijhat, XIJ, d) / (tmpxij / hi + EPS * hi)
        mui = min(0, tmpmui)

        tmpmuj = dot(uijhat, XIJ, d) / (tmpxij / hi + EPS * hj)
        muj = min(0, tmpmuj)

        Qi = rhoi * (-Cl * ci * mui + Cq * mui * mui)
        Qj = rhoj * (-Cl * cj * muj + Cq * muj * muj)

        fac = -(1.0 / mi) * Vi * Vj * (pi + pj + Qi + Qj)

        gamma = self.gamma
        d = self.dim
        auij, delu = declare('matrix(3)', 2)
        auij[0] = fac * DWIJ[0]
        auij[1] = fac * DWIJ[1]
        auij[2] = fac * DWIJ[2]

        delu[0] = s_u0[s_idx] + s_u[s_idx] - d_u0[d_idx] - d_u[d_idx]
        delu[1] = s_v0[s_idx] + s_v[s_idx] - d_v0[d_idx] - d_v[d_idx]
        delu[2] = s_w0[s_idx] + s_w[s_idx] - d_w0[d_idx] - d_w[d_idx]

        aeij = dot(delu, auij, d)

        si = d_p[d_idx] / ((d_rho[d_idx])**gamma)
        sj = s_p[s_idx] / ((s_rho[s_idx])**gamma)
        smin = min(abs(si), abs(sj))
        smax = max(abs(si), abs(sj))

        fij = 0.5
        sdiff = si - sj
        if sdiff * aeij > 0:
            fij = smin / (smin + smax)
        elif sdiff * aeij < 0:
            fij = smax / (smin + smax)

        d_ae[d_idx] += 0.5 * fij * aeij
コード例 #3
0
    def loop(self, d_idx, s_idx, d_m, s_m, d_rho, s_rho, d_p, s_p, d_cs, s_cs,
             d_u, d_v, d_w, s_u, s_v, s_w, d_gradv, s_gradv, d_h, s_h, s_ai,
             s_bi, s_gradai, s_gradbi, d_au, d_av, d_aw, d_V, s_V, XIJ, VIJ,
             DWIJ, EPS, HIJ, WIJ, DWI, DWJ):
        Cl = self.cl
        Cq = self.cq
        eta_fold = self.eta_fold
        eta_crit = self.eta_crit

        mi = d_m[d_idx]
        Vi = 1.0 / d_V[d_idx]
        Vj = 1.0 / s_V[s_idx]

        pi = d_p[d_idx]
        pj = s_p[s_idx]

        rhoi = d_rho[d_idx]
        rhoj = s_rho[s_idx]

        ci = d_cs[d_idx]
        cj = s_cs[s_idx]

        hi = d_h[d_idx]
        hj = s_h[s_idx]

        alp, bet, i, d = declare('int', 4)
        uijhat, tmpdvxij = declare('matrix(3)', 2)

        d = self.dim

        tmpri = 0.0
        tmprj = 0.0
        for alp in range(d):
            for bet in range(d):
                tmpri += d_gradv[d * d * d_idx + d * alp +
                                 bet] * XIJ[alp] * XIJ[bet]
                tmprj += s_gradv[d * d * s_idx + d * alp +
                                 bet] * XIJ[alp] * XIJ[bet]
        rij = tmpri / tmprj

        tmprij = min(1, 4 * rij / ((1 + rij) * (1 + rij)))
        phiij = max(0, tmprij)

        tmpxij = dot(XIJ, XIJ, d)
        tmpxij2 = sqrt(tmpxij)
        etai_scalar = tmpxij2 / hi
        etaj_scalar = tmpxij2 / hj
        etaij = min(etai_scalar, etaj_scalar)

        if etaij < eta_crit:
            tmpphi = (etaij - eta_crit) / eta_fold
            phiij = phiij * exp(-tmpphi * tmpphi)

        for alp in range(d):
            s = 0.0
            for bet in range(d):
                s += (d_gradv[d * d * d_idx + d * alp + bet] +
                      s_gradv[d * d * s_idx + d * alp + bet]) * XIJ[bet]
            tmpdvxij[alp] = s

        uijhat[0] = d_u[d_idx] - s_u[s_idx] - 0.5 * phiij * tmpdvxij[0]
        uijhat[1] = d_v[d_idx] - s_v[s_idx] - 0.5 * phiij * tmpdvxij[1]
        uijhat[2] = d_w[d_idx] - s_w[s_idx] - 0.5 * phiij * tmpdvxij[2]

        tmpmui = dot(uijhat, XIJ, d) / (tmpxij / hi + EPS * hi)
        mui = min(0, tmpmui)

        tmpmuj = dot(uijhat, XIJ, d) / (tmpxij / hi + EPS * hj)
        muj = min(0, tmpmuj)

        Qi = rhoi * (-Cl * ci * mui + Cq * mui * mui)
        Qj = rhoj * (-Cl * cj * muj + Cq * muj * muj)

        fac = -(1.0 / mi) * Vi * Vj * (pi + pj + Qi + Qj)
        d_au[d_idx] += fac * DWIJ[0]
        d_av[d_idx] += fac * DWIJ[1]
        d_aw[d_idx] += fac * DWIJ[2]
コード例 #4
0
    def loop_all(self, d_idx, d_x, d_y, d_z, d_h, s_x, s_y, s_z, s_h, s_m,
                 s_rho, SPH_KERNEL, NBRS, N_NBRS, d_ai, d_gradai, d_bi, s_V,
                 d_gradbi):
        x = d_x[d_idx]
        y = d_y[d_idx]
        z = d_z[d_idx]
        h = d_h[d_idx]
        i, j, k, s_idx, d, d2 = declare('int', 6)
        alp, bet, gam, phi, psi = declare('int', 5)
        xij = declare('matrix(3)')
        dwij = declare('matrix(3)')
        d = self.dim
        d2 = d * d

        m0 = 0.0
        m1 = declare('matrix(3)')
        m2 = declare('matrix(9)')
        temp_vec = declare('matrix(3)')
        temp_aug_m2 = declare('matrix(18)')
        m2inv = declare('matrix(9)')
        grad_m0 = declare('matrix(3)')
        grad_m1 = declare('matrix(9)')
        grad_m2 = declare('matrix(27)')
        ai = 0.0
        bi = declare('matrix(3)')
        grad_ai = declare('matrix(3)')
        grad_bi = declare('matrix(9)')

        for i in range(3):
            m1[i] = 0.0
            grad_m0[i] = 0.0
            bi[i] = 0.0
            grad_ai[i] = 0.0
            for j in range(3):
                m2[3 * i + j] = 0.0
                grad_m1[3 * i + j] = 0.0
                grad_bi[3 * i + j] = 0.0
                for k in range(3):
                    grad_m2[9 * i + 3 * j + k] = 0.0
        for i in range(N_NBRS):
            s_idx = NBRS[i]
            xij[0] = x - s_x[s_idx]
            xij[1] = y - s_y[s_idx]
            xij[2] = z - s_z[s_idx]
            hij = (h + s_h[s_idx]) * 0.5
            rij = sqrt(xij[0] * xij[0] + xij[1] * xij[1] + xij[2] * xij[2])
            wij = SPH_KERNEL.kernel(xij, rij, hij)
            SPH_KERNEL.gradient(xij, rij, hij, dwij)
            V = 1.0 / s_V[s_idx]

            m0 += V * wij
            for alp in range(d):
                m1[alp] += V * wij * xij[alp]
                for bet in range(d):
                    m2[d * alp + bet] += V * wij * xij[alp] * xij[bet]
            for gam in range(d):
                grad_m0[gam] += V * dwij[gam]
                for alp in range(d):
                    fac = 1.0 if alp == gam else 0.0
                    temp = (xij[alp] * dwij[gam] + fac * wij)
                    grad_m1[d * gam + alp] += V * temp
                    for bet in range(d):
                        fac2 = 1.0 if bet == gam else 0.0
                        temp = xij[alp] * fac2 + xij[bet] * fac
                        temp2 = (xij[alp] * xij[bet] * dwij[gam] + temp * wij)
                        grad_m2[d2 * gam + d * alp + bet] += V * temp2

        identity(m2inv, d)
        augmented_matrix(m2, m2inv, d, d, d, temp_aug_m2)

        # If is_singular > 0 then matrix was singular
        is_singular = gj_solve(temp_aug_m2, d, d, m2inv)

        if is_singular > 0.0:
            # Cannot do much if the matrix is singular.  Perhaps later
            # we can tag such particles to see if the user can do something.
            pass
        else:
            mat_vec_mult(m2inv, m1, d, temp_vec)

            # Eq. 12.
            ai = 1.0 / (m0 - dot(temp_vec, m1, d))
            # Eq. 13.
            mat_vec_mult(m2inv, m1, d, bi)
            for gam in range(d):
                bi[gam] = -bi[gam]

            # Eq. 14. and 15.
            for gam in range(d):
                temp1 = grad_m0[gam]
                for alp in range(d):
                    temp2 = 0.0
                    for bet in range(d):
                        temp1 -= m2inv[d * alp + bet] * (
                            m1[bet] * grad_m1[d * gam + alp] +
                            m1[alp] * grad_m1[d * gam + bet])
                        temp2 -= (m2inv[d * alp + bet] *
                                  grad_m1[d * gam + bet])
                        for phi in range(d):
                            for psi in range(d):
                                temp1 += (m2inv[d * alp + phi] *
                                          m2inv[d * psi + bet] *
                                          grad_m2[d2 * gam + d * phi + psi] *
                                          m1[bet] * m1[alp])
                                temp2 += (m2inv[d * alp + phi] *
                                          m2inv[d * psi + bet] *
                                          grad_m2[d2 * gam + d * phi + psi] *
                                          m1[bet])
                    grad_bi[d * gam + alp] = temp2
                grad_ai[gam] = -ai * ai * temp1

        if N_NBRS < 2 or is_singular > 0.0:
            d_ai[d_idx] = 1.0
            for i in range(d):
                d_gradai[d * d_idx + i] = 0.0
                d_bi[d * d_idx + i] = 0.0
                for j in range(d):
                    d_gradbi[d2 * d_idx + d * i + j] = 0.0
        else:
            d_ai[d_idx] = ai
            for i in range(d):
                d_gradai[d * d_idx + i] = grad_ai[i]
                d_bi[d * d_idx + i] = bi[i]
                for j in range(d):
                    d_gradbi[d2 * d_idx + d * i + j] = grad_bi[d * i + j]