Ejemplo n.º 1
0
    def grad(self, u):
        """Compute 2D gradient field of scalar u."""
        l = self.ldis

        ur = eldot(l.Dr, u)
        us = eldot(l.Ds, u)
        ux = self.rx * ur + self.sx * us
        uy = self.ry * ur + self.sy * us
        return ux, uy
Ejemplo n.º 2
0
    def grad(self, u):
        """Compute 2D gradient field of scalar u."""
        l = self.ldis

        ur = eldot(l.Dr, u)
        us = eldot(l.Ds, u)
        ux = self.rx*ur + self.sx*us
        uy = self.ry*ur + self.sy*us
        return ux, uy
Ejemplo n.º 3
0
def GeometricFactors3D(x, y, z, Dr, Ds, Dt):
    """Compute the metric elements for the local mappings of the elements
    Returns [rx, sx, tx, ry, sy, ty, rz, sz, tz, J].
    """
    # Calculate geometric factors
    xr = eldot(Dr, x)
    xs = eldot(Ds, x)
    xt = eldot(Dt, x)

    yr = eldot(Dr, y)
    ys = eldot(Ds, y)
    yt = eldot(Dt, y)

    zr = eldot(Dr, z)
    zs = eldot(Ds, z)
    zt = eldot(Dt, z)

    J = xr*(ys*zt-zs*yt) - yr*(xs*zt-zs*xt) + zr*(xs*yt-ys*xt)
    rx  =  (ys*zt - zs*yt)/J
    ry  = -(xs*zt - zs*xt)/J
    rz  =  (xs*yt - ys*xt)/J

    sx  = -(yr*zt - zr*yt)/J
    sy  =  (xr*zt - zr*xt)/J
    sz  = -(xr*yt - yr*xt)/J

    tx  =  (yr*zs - zr*ys)/J
    ty  = -(xr*zs - zr*xs)/J
    tz  =  (xr*ys - yr*xs)/J

    return rx, sx, tx, ry, sy, ty, rz, sz, tz, J
Ejemplo n.º 4
0
def GeometricFactors3D(x, y, z, Dr, Ds, Dt):
    """Compute the metric elements for the local mappings of the elements
    Returns [rx, sx, tx, ry, sy, ty, rz, sz, tz, J].
    """
    # Calculate geometric factors
    xr = eldot(Dr, x)
    xs = eldot(Ds, x)
    xt = eldot(Dt, x)

    yr = eldot(Dr, y)
    ys = eldot(Ds, y)
    yt = eldot(Dt, y)

    zr = eldot(Dr, z)
    zs = eldot(Ds, z)
    zt = eldot(Dt, z)

    J = xr * (ys * zt - zs * yt) - yr * (xs * zt - zs * xt) + zr * (xs * yt -
                                                                    ys * xt)
    rx = (ys * zt - zs * yt) / J
    ry = -(xs * zt - zs * xt) / J
    rz = (xs * yt - ys * xt) / J

    sx = -(yr * zt - zr * yt) / J
    sy = (xr * zt - zr * xt) / J
    sz = -(xr * yt - yr * xt) / J

    tx = (yr * zs - zr * ys) / J
    ty = -(xr * zs - zr * xs) / J
    tz = (xr * ys - yr * xs) / J

    return rx, sx, tx, ry, sy, ty, rz, sz, tz, J
Ejemplo n.º 5
0
    def gradient(self, u):
        """Compute 3D gradient field of scalar u."""
        l = self.ldis

        ur = eldot(l.Dr, u)
        us = eldot(l.Ds, u)
        ut = eldot(l.Dt, u)

        ux = self.rx*ur + self.sx*us + self.tx*ut
        uy = self.ry*ur + self.sy*us + self.ty*ut
        uz = self.rz*ur + self.sz*us + self.tz*ut

        return ux, uy, uz
Ejemplo n.º 6
0
    def gradient(self, u):
        """Compute 3D gradient field of scalar u."""
        l = self.ldis

        ur = eldot(l.Dr, u)
        us = eldot(l.Ds, u)
        ut = eldot(l.Dt, u)

        ux = self.rx * ur + self.sx * us + self.tx * ut
        uy = self.ry * ur + self.sy * us + self.ty * ut
        uz = self.rz * ur + self.sz * us + self.tz * ut

        return ux, uy, uz
Ejemplo n.º 7
0
def GeometricFactors2D(x, y, Dr, Ds):
    """Compute the metric elements for the local mappings of the elements
    Returns [rx, sx, ry, sy, J].
    """
    # Calculate geometric factors
    xr = eldot(Dr, x)
    xs = eldot(Ds, x)
    yr = eldot(Dr, y)
    ys = eldot(Ds, y)
    J = -xs * yr + xr * ys
    rx = ys / J
    sx = -yr / J
    ry = -xs / J
    sy = xr / J
    return rx, sx, ry, sy, J
Ejemplo n.º 8
0
def GeometricFactors2D(x, y, Dr, Ds):
    """Compute the metric elements for the local mappings of the elements
    Returns [rx, sx, ry, sy, J].
    """
    # Calculate geometric factors
    xr = eldot(Dr, x)
    xs = eldot(Ds, x)
    yr = eldot(Dr, y)
    ys = eldot(Ds, y)
    J = -xs*yr + xr*ys
    rx = ys/J
    sx =-yr/J
    ry =-xs/J
    sy = xr/J
    return rx, sx, ry, sy, J
Ejemplo n.º 9
0
def Normals2D(ldis, x, y, K):
    """Compute outward pointing normals at elements faces
    and surface Jacobians.
    """

    l = ldis
    xr = eldot(l.Dr, x)
    yr = eldot(l.Dr, y)
    xs = eldot(l.Ds, x)
    ys = eldot(l.Ds, y)
    J = xr * ys - xs * yr

    # interpolate geometric factors to face nodes
    fxr = xr[:, l.FmaskF]
    fxs = xs[:, l.FmaskF]
    fyr = yr[:, l.FmaskF]
    fys = ys[:, l.FmaskF]

    # build normals
    nx = np.zeros((K, l.Nafp))
    ny = np.zeros((K, l.Nafp))
    fid1 = np.arange(l.Nfp).reshape(1, l.Nfp)
    fid2 = fid1 + l.Nfp
    fid3 = fid2 + l.Nfp

    # face 1

    nx[:, fid1] = fyr[:, fid1]
    ny[:, fid1] = -fxr[:, fid1]

    # face 2
    nx[:, fid2] = fys[:, fid2] - fyr[:, fid2]
    ny[:, fid2] = -fxs[:, fid2] + fxr[:, fid2]

    # face 3
    nx[:, fid3] = -fys[:, fid3]
    ny[:, fid3] = fxs[:, fid3]

    # normalise
    sJ = np.sqrt(nx * nx + ny * ny)
    nx = nx / sJ
    ny = ny / sJ
    return nx, ny, sJ
Ejemplo n.º 10
0
def AcousticsRHS3D(discr, Ux, Uy, Uz, Pr):
    """Evaluate RHS flux in 3D Acoustics."""

    from pydgeon.tools import eldot

    d = discr
    l = discr.ldis

    # Define field differences at faces
    vmapM = d.vmapM.reshape(d.K, -1)
    vmapP = d.vmapP.reshape(d.K, -1)

    dUx = Ux.flat[vmapP] - Ux.flat[vmapM]
    dUy = Uy.flat[vmapP] - Uy.flat[vmapM]
    dUz = Uz.flat[vmapP] - Uz.flat[vmapM]
    dPr = Pr.flat[vmapP] - Pr.flat[vmapM]

    # Impose reflective boundary conditions (Uz+ = -Uz-)
    dUx.flat[d.mapB] = 0.0
    dUy.flat[d.mapB] = 0.0
    dUz.flat[d.mapB] = 0.0
    dPr.flat[d.mapB] = (-2.0)*Pr.flat[d.vmapB]

    # evaluate upwind fluxes
    #alpha = 1.0
    R = dPr - d.nx*dUx - d.ny*dUy - d.nz*dUz
    fluxUx = -d.nx*R
    fluxUy = -d.ny*R
    fluxUz = -d.nz*R
    fluxPr = R

    # local derivatives of fields
    dPrdx, dPrdy, dPrdz = d.gradient(Pr)
    divU = d.divergence(Ux, Uy, Uz)

    # compute right hand sides of the PDE's
    rhsUx = -dPrdx + eldot(l.LIFT, (d.Fscale*fluxUx))/2.0
    rhsUy = -dPrdx + eldot(l.LIFT, (d.Fscale*fluxUy))/2.0
    rhsUz = -dPrdz + eldot(l.LIFT, (d.Fscale*fluxUz))/2.0
    rhsPr = -divU + eldot(l.LIFT, (d.Fscale*fluxPr))/2.0

    return rhsUx, rhsUy, rhsUz, rhsPr
Ejemplo n.º 11
0
def AcousticsRHS3D(discr, Ux, Uy, Uz, Pr):
    """Evaluate RHS flux in 3D Acoustics."""

    from pydgeon.tools import eldot

    d = discr
    l = discr.ldis

    # Define field differences at faces
    vmapM = d.vmapM.reshape(d.K, -1)
    vmapP = d.vmapP.reshape(d.K, -1)

    dUx = Ux.flat[vmapP] - Ux.flat[vmapM]
    dUy = Uy.flat[vmapP] - Uy.flat[vmapM]
    dUz = Uz.flat[vmapP] - Uz.flat[vmapM]
    dPr = Pr.flat[vmapP] - Pr.flat[vmapM]

    # Impose reflective boundary conditions (Uz+ = -Uz-)
    dUx.flat[d.mapB] = 0.0
    dUy.flat[d.mapB] = 0.0
    dUz.flat[d.mapB] = 0.0
    dPr.flat[d.mapB] = (-2.0) * Pr.flat[d.vmapB]

    # evaluate upwind fluxes
    #alpha = 1.0
    R = dPr - d.nx * dUx - d.ny * dUy - d.nz * dUz
    fluxUx = -d.nx * R
    fluxUy = -d.ny * R
    fluxUz = -d.nz * R
    fluxPr = R

    # local derivatives of fields
    dPrdx, dPrdy, dPrdz = d.gradient(Pr)
    divU = d.divergence(Ux, Uy, Uz)

    # compute right hand sides of the PDE's
    rhsUx = -dPrdx + eldot(l.LIFT, (d.Fscale * fluxUx)) / 2.0
    rhsUy = -dPrdx + eldot(l.LIFT, (d.Fscale * fluxUy)) / 2.0
    rhsUz = -dPrdz + eldot(l.LIFT, (d.Fscale * fluxUz)) / 2.0
    rhsPr = -divU + eldot(l.LIFT, (d.Fscale * fluxPr)) / 2.0

    return rhsUx, rhsUy, rhsUz, rhsPr
Ejemplo n.º 12
0
def Normals2D(ldis, x, y, K):
    """Compute outward pointing normals at elements faces
    and surface Jacobians.
    """

    l = ldis
    xr = eldot(l.Dr, x)
    yr = eldot(l.Dr, y)
    xs = eldot(l.Ds, x)
    ys = eldot(l.Ds, y)
    #J = xr*ys-xs*yr

    # interpolate geometric factors to face nodes
    fxr = xr[:, l.FmaskF]; fxs = xs[:, l.FmaskF]
    fyr = yr[:, l.FmaskF]; fys = ys[:, l.FmaskF]

    # build normals
    nx = np.zeros((K, l.Nafp))
    ny = np.zeros((K, l.Nafp))
    fid1 = np.arange(l.Nfp).reshape(1, l.Nfp)
    fid2 = fid1+l.Nfp
    fid3 = fid2+l.Nfp

    # face 1
    nx[:, fid1] =  fyr[:, fid1]
    ny[:, fid1] = -fxr[:, fid1]

    # face 2
    nx[:, fid2] =  fys[:, fid2]-fyr[:, fid2]
    ny[:, fid2] = -fxs[:, fid2]+fxr[:, fid2]

    # face 3
    nx[:, fid3] = -fys[:, fid3]
    ny[:, fid3] =  fxs[:, fid3]

    # normalise
    sJ = np.sqrt(nx*nx+ny*ny)
    nx = nx/sJ
    ny = ny/sJ
    return nx, ny, sJ
Ejemplo n.º 13
0
def MaxwellRHS2D(discr, Hx, Hy, Ez):
    """Evaluate RHS flux in 2D Maxwell TM form."""

    from pydgeon.tools import eldot

    d = discr
    l = discr.ldis

    # Define field differences at faces
    vmapM = d.vmapM.reshape(d.K, -1)
    vmapP = d.vmapP.reshape(d.K, -1)

    dHx = Hx.flat[vmapM] - Hx.flat[vmapP]
    dHy = Hy.flat[vmapM] - Hy.flat[vmapP]
    dEz = Ez.flat[vmapM] - Ez.flat[vmapP]

    # Impose reflective boundary conditions (Ez+ = -Ez-)
    dHx.flat[d.mapB] = 0
    dHy.flat[d.mapB] = 0
    dEz.flat[d.mapB] = 2 * Ez.flat[d.vmapB]

    # evaluate upwind fluxes
    alpha = 1.0
    ndotdH = d.nx * dHx + d.ny * dHy
    fluxHx = d.ny * dEz + alpha * (ndotdH * d.nx - dHx)
    fluxHy = -d.nx * dEz + alpha * (ndotdH * d.ny - dHy)
    fluxEz = -d.nx * dHy + d.ny * dHx - alpha * dEz

    # local derivatives of fields
    Ezx, Ezy = d.grad(Ez)
    CuHx, CuHy, CuHz = d.curl(Hx, Hy, 0)

    # compute right hand sides of the PDE's
    rhsHx = -Ezy + eldot(l.LIFT, (d.Fscale * fluxHx)) / 2.0
    rhsHy = Ezx + eldot(l.LIFT, (d.Fscale * fluxHy)) / 2.0
    rhsEz = CuHz + eldot(l.LIFT, (d.Fscale * fluxEz)) / 2.0
    return rhsHx, rhsHy, rhsEz
Ejemplo n.º 14
0
def MaxwellRHS2D(discr, Hx, Hy, Ez):
    """Evaluate RHS flux in 2D Maxwell TM form."""

    from pydgeon.tools import eldot

    d = discr
    l = discr.ldis

    # Define field differences at faces
    vmapM = d.vmapM.reshape(d.K, -1)
    vmapP = d.vmapP.reshape(d.K, -1)

    dHx = Hx.flat[vmapM]-Hx.flat[vmapP]
    dHy = Hy.flat[vmapM]-Hy.flat[vmapP]
    dEz = Ez.flat[vmapM]-Ez.flat[vmapP]

    # Impose reflective boundary conditions (Ez+ = -Ez-)
    dHx.flat[d.mapB] = 0
    dHy.flat[d.mapB] = 0
    dEz.flat[d.mapB] = 2*Ez.flat[d.vmapB]

    # evaluate upwind fluxes
    alpha  = 1.0
    ndotdH =  d.nx*dHx + d.ny*dHy
    fluxHx =  d.ny*dEz + alpha*(ndotdH*d.nx-dHx)
    fluxHy = -d.nx*dEz + alpha*(ndotdH*d.ny-dHy)
    fluxEz = -d.nx*dHy + d.ny*dHx - alpha*dEz

    # local derivatives of fields
    Ezx, Ezy = d.grad(Ez)
    CuHx, CuHy, CuHz = d.curl(Hx, Hy,0)

    # compute right hand sides of the PDE's
    rhsHx = -Ezy  + eldot(l.LIFT, (d.Fscale*fluxHx))/2.0
    rhsHy =  Ezx  + eldot(l.LIFT, (d.Fscale*fluxHy))/2.0
    rhsEz =  CuHz + eldot(l.LIFT, (d.Fscale*fluxEz))/2.0
    return rhsHx, rhsHy, rhsEz
Ejemplo n.º 15
0
    def divergence(self, ux, uy, uz):
        """Compute 3D curl-operator in (x, y, z) ."""
        l = self.ldis
        d = self

        duxdr = eldot(l.Dr, ux)
        duxds = eldot(l.Ds, ux)
        duxdt = eldot(l.Dt, ux)

        duydr = eldot(l.Dr, uy)
        duyds = eldot(l.Ds, uy)
        duydt = eldot(l.Dt, uy)

        duzdr = eldot(l.Dr, uz)
        duzds = eldot(l.Ds, uz)
        duzdt = eldot(l.Dt, uz)

        duxdx = d.rx*duxdr + d.sx*duxds + d.tx*duxdt
        duydy = d.ry*duydr + d.sy*duyds + d.ty*duydt
        duzdz = d.rz*duzdr + d.sz*duzds + d.tz*duzdt

        divU = duxdx+duydy+duzdz

        return divU
Ejemplo n.º 16
0
    def divergence(self, ux, uy, uz):
        """Compute 3D curl-operator in (x, y, z) ."""
        l = self.ldis
        d = self

        duxdr = eldot(l.Dr, ux)
        duxds = eldot(l.Ds, ux)
        duxdt = eldot(l.Dt, ux)

        duydr = eldot(l.Dr, uy)
        duyds = eldot(l.Ds, uy)
        duydt = eldot(l.Dt, uy)

        duzdr = eldot(l.Dr, uz)
        duzds = eldot(l.Ds, uz)
        duzdt = eldot(l.Dt, uz)

        duxdx = d.rx * duxdr + d.sx * duxds + d.tx * duxdt
        duydy = d.ry * duydr + d.sy * duyds + d.ty * duydt
        duzdz = d.rz * duzdr + d.sz * duzds + d.tz * duzdt

        divU = duxdx + duydy + duzdz

        return divU
Ejemplo n.º 17
0
    def curl(self, ux, uy, uz):
        """Compute 2D curl-operator in (x, y) plane."""
        l = self.ldis
        d = self

        uxr = eldot(l.Dr, ux)
        uxs = eldot(l.Ds, ux)
        uyr = eldot(l.Dr, uy)
        uys = eldot(l.Ds, uy)
        vz =  d.rx*uyr + d.sx*uys - d.ry*uxr - d.sy*uxs
        vx = 0; vy = 0

        if uz != 0:
            uzr = eldot(l.Dr, uz)
            uzs = eldot(l.Ds, uz)
            vx =  d.ry*uzr + d.sy*uzs
            vy = -d.rx*uzr - d.sx*uzs

        return vx, vy, vz
Ejemplo n.º 18
0
    def curl(self, ux, uy, uz):
        """Compute 2D curl-operator in (x, y) plane."""
        l = self.ldis
        d = self

        uxr = eldot(l.Dr, ux)
        uxs = eldot(l.Ds, ux)
        uyr = eldot(l.Dr, uy)
        uys = eldot(l.Ds, uy)
        vz = d.rx * uyr + d.sx * uys - d.ry * uxr - d.sy * uxs
        vx = 0
        vy = 0

        if uz != 0:
            uzr = eldot(l.Dr, uz)
            uzs = eldot(l.Ds, uz)
            vx = d.ry * uzr + d.sy * uzs
            vy = -d.rx * uzr - d.sx * uzs

        return vx, vy, vz