コード例 #1
0
    def test_invPropertyTensor2D(self):
        M = discretize.TensorMesh([6, 6])
        a1 = np.random.rand(M.nC)
        a2 = np.random.rand(M.nC)
        a3 = np.random.rand(M.nC)
        prop1 = a1
        prop2 = np.c_[a1, a2]
        prop3 = np.c_[a1, a2, a3]

        for prop in [4, prop1, prop2, prop3]:
            b = invPropertyTensor(M, prop)
            A = makePropertyTensor(M, prop)
            B1 = makePropertyTensor(M, b)
            B2 = invPropertyTensor(M, prop, returnMatrix=True)

            Z = B1 * A - sp.identity(M.nC * 2)
            self.assertTrue(np.linalg.norm(Z.todense().ravel(), 2) < TOL)
            Z = B2 * A - sp.identity(M.nC * 2)
            self.assertTrue(np.linalg.norm(Z.todense().ravel(), 2) < TOL)
コード例 #2
0
ファイル: InnerProducts.py プロジェクト: zwq1230/discretize
    def _getInnerProduct(self, projType, prop=None, invProp=False, invMat=False, doFast=True):
        """get the inner product matrix

        Parameters
        ----------

        str : projType
            'F' for faces 'E' for edges

        numpy.ndarray : prop
            material property (tensor properties are possible) at each cell center (nC, (1, 3, or 6))

        bool : invProp
            inverts the material property

        bool : invMat
            inverts the matrix

        bool : doFast
            do a faster implementation if available.


        Returns
        -------

        scipy.sparse.csr_matrix
            M, the inner product matrix (nE, nE)

        """
        assert projType in ['F', 'E'], "projType must be 'F' for faces or 'E' for edges"

        fast = None
        if hasattr(self, '_fastInnerProduct') and doFast:
            fast = self._fastInnerProduct(projType, prop=prop, invProp=invProp, invMat=invMat)
        if fast is not None:
            return fast

        if invProp:
            prop = invPropertyTensor(self, prop)

        tensorType = TensorType(self, prop)

        Mu = makePropertyTensor(self, prop)
        Ps = self._getInnerProductProjectionMatrices(projType, tensorType)
        A = np.sum([P.T * Mu * P for P in Ps])

        if invMat and tensorType < 3:
            A = sdInv(A)
        elif invMat and tensorType == 3:
            raise Exception('Solver needed to invert A.')

        return A