コード例 #1
0
    def _edgeCurlStencil(self):
        assert self.dim > 1, "Edge Curl only programed for 2 or 3D."

        # Compute divergence operator on faces
        if self.dim == 2:
            n = self.vnC  # The number of cell centers in each direction

            D21 = sp.kron(ddx(n[1]), speye(n[0]))
            D12 = sp.kron(speye(n[1]), ddx(n[0]))
            C = sp.hstack((-D21, D12), format="csr")
            return C

        elif self.dim == 3:

            # D32 = kron3(ddx(n[2]), speye(n[1]), speye(n[0]+1))
            # D23 = kron3(speye(n[2]), ddx(n[1]), speye(n[0]+1))
            # D31 = kron3(ddx(n[2]), speye(n[1]+1), speye(n[0]))
            # D13 = kron3(speye(n[2]), speye(n[1]+1), ddx(n[0]))
            # D21 = kron3(speye(n[2]+1), ddx(n[1]), speye(n[0]))
            # D12 = kron3(speye(n[2]+1), speye(n[1]), ddx(n[0]))

            # O1 = spzeros(np.shape(D32)[0], np.shape(D31)[1])
            # O2 = spzeros(np.shape(D31)[0], np.shape(D32)[1])
            # O3 = spzeros(np.shape(D21)[0], np.shape(D13)[1])

            # C = sp.vstack((sp.hstack((O1, -D32, D23)),
            #                sp.hstack((D31, O2, -D13)),
            #                sp.hstack((-D21, D12, O3))), format="csr")

            C = sp.vstack((self._edgeCurlStencilx, self._edgeCurlStencily,
                           self._edgeCurlStencilz),
                          format="csr")

            return C
コード例 #2
0
    def _edgeCurlStencilz(self):
        n = self.vnC  # The number of cell centers in each direction

        D21 = kron3(speye(n[2] + 1), ddx(n[1]), speye(n[0]))
        D12 = kron3(speye(n[2] + 1), speye(n[1]), ddx(n[0]))
        # O3 = spzeros(np.shape(D21)[0], np.shape(D13)[1])
        O3 = spzeros(n[0] * n[1] * (n[2] + 1), (n[0] + 1) * (n[1] + 1) * n[2])

        return sp.hstack((-D21, D12, O3))
コード例 #3
0
    def _edgeCurlStencilx(self):
        n = self.vnC  # The number of cell centers in each direction

        D32 = kron3(ddx(n[2]), speye(n[1]), speye(n[0] + 1))
        D23 = kron3(speye(n[2]), ddx(n[1]), speye(n[0] + 1))
        # O1 = spzeros(np.shape(D32)[0], np.shape(D31)[1])
        O1 = spzeros((n[0] + 1) * n[1] * n[2], n[0] * (n[1] + 1) * (n[2] + 1))

        return sp.hstack((O1, -D32, D23))
コード例 #4
0
    def _edgeCurlStencily(self):
        n = self.vnC  # The number of cell centers in each direction

        D31 = kron3(ddx(n[2]), speye(n[1] + 1), speye(n[0]))
        D13 = kron3(speye(n[2]), speye(n[1] + 1), ddx(n[0]))
        # O2 = spzeros(np.shape(D31)[0], np.shape(D32)[1])
        O2 = spzeros(n[0] * (n[1] + 1) * n[2], (n[0] + 1) * n[1] * (n[2] + 1))

        return sp.hstack((D31, O2, -D13))
コード例 #5
0
 def _nodalGradStencily(self):
     """
     Stencil for the nodal grad in the y-direction (nodes to y-edges)
     """
     if self.dim == 1:
         return None
     elif self.dim == 2:
         Gy = sp.kron(ddx(self.nCy), speye(self.nNx))
     elif self.dim == 3:
         Gy = kron3(speye(self.nNz), ddx(self.nCy), speye(self.nNx))
     return Gy
コード例 #6
0
 def _nodalGradStencilx(self):
     """
     Stencil for the nodal grad in the x-direction (nodes to x-edges)
     """
     if self.dim == 1:
         Gx = ddx(self.nCx)
     elif self.dim == 2:
         Gx = sp.kron(speye(self.nNy), ddx(self.nCx))
     elif self.dim == 3:
         Gx = kron3(speye(self.nNz), speye(self.nNy), ddx(self.nCx))
     return Gx
コード例 #7
0
 def _faceDivStencily(self):
     """
     Face divergence operator in the y-direction (y-faces to cell centers)
     """
     if self.dim == 1:
         return None
     elif self.dim == 2:
         Dy = sp.kron(ddx(self.nCy), speye(self.nCx))
     elif self.dim == 3:
         Dy = kron3(speye(self.nCz), ddx(self.nCy), speye(self.nCx))
     return Dy
コード例 #8
0
 def _faceDivStencilx(self):
     """
     Face divergence operator in the x-direction (x-faces to cell centers)
     """
     if self.dim == 1:
         Dx = ddx(self.nCx)
     elif self.dim == 2:
         Dx = sp.kron(speye(self.nCy), ddx(self.nCx))
     elif self.dim == 3:
         Dx = kron3(speye(self.nCz), speye(self.nCy), ddx(self.nCx))
     return Dx
コード例 #9
0
    def _nodalLaplacianStencilz(self):
        warnings.warn('Laplacian has not been tested rigorously.')

        if self.dim == 1 or self.dim == 2:
            return None

        Dz = ddx(self.nCz)
        Lz = -Dz.T * Dz
        return kron3(Lz, speye(self.nNy), speye(self.nNx))
コード例 #10
0
 def _nodalGradStencilz(self):
     """
     Stencil for the nodal grad in the z-direction (nodes to z- edges)
     """
     if self.dim == 1 or self.dim == 2:
         return None
     else:
         Gz = kron3(ddx(self.nCz), speye(self.nNy), speye(self.nNx))
     return Gz
コード例 #11
0
 def _faceDivStencilz(self):
     """
     Face divergence operator in the z-direction (z-faces to cell centers)
     """
     if self.dim == 1 or self.dim == 2:
         return None
     elif self.dim == 3:
         Dz = kron3(ddx(self.nCz), speye(self.nCy), speye(self.nCx))
     return Dz
コード例 #12
0
    def _nodalLaplacianStencilx(self):
        warnings.warn('Laplacian has not been tested rigorously.')

        Dx = ddx(self.nCx)
        Lx = -Dx.T * Dx

        if self.dim == 2:
            Lx = sp.kron(speye(self.nNy), Lx)
        elif self.dim == 3:
            Lx = kron3(speye(self.nNz), speye(self.nNy), Lx)
        return Lx
コード例 #13
0
    def _nodalLaplacianStencily(self):
        warnings.warn('Laplacian has not been tested rigorously.')

        if self.dim == 1:
            return None

        Dy = ddx(self.nCy)
        Ly = -Dy.T * Dy

        if self.dim == 2:
            Ly = sp.kron(Ly, speye(self.nNx))
        elif self.dim == 3:
            Ly = kron3(speye(self.nNz), Ly, speye(self.nNx))
        return Ly