def getAsubdiag(self, tInd): assert tInd >= 0 and tInd < self.nT eye = sp.eye(self.mesh.nF) dt = self.timeSteps[tInd] if self._makeASymmetric: return -1./dt * self.MfRho.T return -1./dt * eye
def getAsubdiag(self, tInd): dt = self.timeSteps[tInd] MfMui = self.MfMui Asubdiag = -1. / dt * sp.eye(self.mesh.nF) if self._makeASymmetric is True: return MfMui.T * Asubdiag return Asubdiag
def getAsubdiag(self, tInd): dt = self.timeSteps[tInd] MfMui = self.MfMui Asubdiag = - 1./dt * sp.eye(self.mesh.nF) if self._makeASymmetric is True: return MfMui.T * Asubdiag return Asubdiag
def getA(self, freq): """ :param float freq: Frequency :rtype: scipy.sparse.csr_matrix :return: A """ mui = self.MfMui sigI = self.MeSigmaI C = self.mesh.edgeCurl iomega = 1j * omega(freq) * sp.eye(self.mesh.nF) A = C*sigI*C.T*mui + iomega if self._makeASymmetric is True: return mui.T*A return A
def getAdiag(self, tInd): """ System matrix at a given time index """ assert tInd >= 0 and tInd < self.nT dt = self.timeSteps[tInd] C = self.mesh.edgeCurl MfRho = self.MfRho MeMuI = self.MeMuI eye = sp.eye(self.mesh.nF) A = C * (MeMuI * (C.T * MfRho)) + 1./dt * eye if self._makeASymmetric: return MfRho.T * A return A
def getA(self, freq): """ .. math :: \mathbf{A} = \mathbf{C} \mathbf{M^e_{\sigma}}^{-1} \mathbf{C}^T \mathbf{M_{\mu^{-1}}^f} + i \omega :param float freq: Frequency :rtype: scipy.sparse.csr_matrix :return: A """ MfMui = self.MfMui MeSigmaI = self.MeSigmaI(freq) C = self.mesh.edgeCurl iomega = 1j * omega(freq) * sp.eye(self.mesh.nF) A = C * (MeSigmaI * (C.T * MfMui)) + iomega if self._makeASymmetric is True: return MfMui.T * A return A
def getA(self, freq): """ .. math :: \mathbf{A} = \mathbf{C} \mathbf{M^e_{\sigma}}^{-1} \mathbf{C}^T \mathbf{M_{\mu^{-1}}^f} + i \omega :param float freq: Frequency :rtype: scipy.sparse.csr_matrix :return: A """ MfMui = self.MfMui MeSigmaI = self.MeSigmaI(freq) C = self.mesh.edgeCurl iomega = 1j * omega(freq) * sp.eye(self.mesh.nF) A = C * (MeSigmaI * (C.T * MfMui)) + iomega if self._makeASymmetric is True: return MfMui.T*A return A
def getA(self, freq): """ .. math :: \\mathbf{A} = \\mathbf{C} \\mathbf{M^e_{mu^{-1}}} \\mathbf{C}^T \\mathbf{M^f_{\\sigma^{-1}}} + i\\omega :param float freq: Frequency :rtype: scipy.sparse.csr_matrix :return: A """ MeMuI = self.MeMuI MfRho = self.MfRho C = self.mesh.edgeCurl iomega = 1j * omega(freq) * sp.eye(self.mesh.nF) A = C * MeMuI * C.T * MfRho + iomega if self._makeASymmetric is True: return MfRho.T*A return A
def getA(self, freq): """ Here, we form the operator \(\\mathbf{A}\) to solce .. math:: \\mathbf{A} = \\mathbf{C} \\mathbf{M^e_{mu^{-1}}} \\mathbf{C^T} \\mathbf{M^f_{\\sigma^{-1}}} + i\\omega :param float freq: Frequency :rtype: scipy.sparse.csr_matrix :return: A """ MeMuI = self.MeMuI MfSigi = self.MfSigmai C = self.mesh.edgeCurl iomega = 1j * omega(freq) * sp.eye(self.mesh.nF) A = C * MeMuI * C.T * MfSigi + iomega if self._makeASymmetric is True: return MfSigi.T*A return A
def getA(self, freq): """ System matrix .. math :: \\mathbf{A} = \\mathbf{C} \\mathbf{M^e_{\\mu^{-1}}} \\mathbf{C}^{\\top} \\mathbf{M^f_{\\sigma^{-1}}} + i\\omega :param float freq: Frequency :rtype: scipy.sparse.csr_matrix :return: A """ MeMuI = self.MeMuI MfRho = self.MfRho C = self.mesh.edgeCurl iomega = 1j * omega(freq) * sp.eye(self.mesh.nF) A = C * MeMuI * C.T * MfRho + iomega if self._makeASymmetric is True: return MfRho.T*A return A
def _fastInnerProductDeriv(self, projType, prop, invProp=False, invMat=False): """ :param str projType: 'E' or 'F' :param TensorType tensorType: type of the tensor :param bool invProp: inverts the material property :param bool invMat: inverts the matrix :rtype: function :return: dMdmu, the derivative of the inner product matrix """ assert projType in ['F', 'E'], ("projType must be 'F' for faces or 'E'" " for edges") tensorType = Utils.TensorType(self, prop) dMdprop = None if invMat or invProp: MI = self._fastInnerProduct(projType, prop, invProp=invProp, invMat=invMat) # number of elements we are averaging (equals dim for regular # meshes, but for cyl, where we use symmetry, it is 1 for edge # variables and 2 for face variables) if self._meshType == 'CYL': n_elements = np.sum(getattr(self, 'vn'+projType).nonzero()) else: n_elements = self.dim if tensorType == 0: # isotropic, constant Av = getattr(self, 'ave'+projType+'2CC') V = Utils.sdiag(self.vol) ones = sp.csr_matrix((np.ones(self.nC), (range(self.nC), np.zeros(self.nC))), shape=(self.nC, 1)) if not invMat and not invProp: dMdprop = n_elements * Av.T * V * ones elif invMat and invProp: dMdprop = n_elements * (Utils.sdiag(MI.diagonal()**2) * Av.T * V * ones * Utils.sdiag(1./prop**2)) elif invProp: dMdprop = n_elements * Av.T * V * Utils.sdiag(- 1./prop**2) elif invMat: dMdprop = n_elements * (Utils.sdiag(- MI.diagonal()**2) * Av.T * V) elif tensorType == 1: # isotropic, variable in space Av = getattr(self, 'ave'+projType+'2CC') V = Utils.sdiag(self.vol) if not invMat and not invProp: dMdprop = n_elements * Av.T * V elif invMat and invProp: dMdprop = n_elements * (Utils.sdiag(MI.diagonal()**2) * Av.T * V * Utils.sdiag(1./prop**2)) elif invProp: dMdprop = n_elements * Av.T * V * Utils.sdiag(-1./prop**2) elif invMat: dMdprop = n_elements * (Utils.sdiag(- MI.diagonal()**2) * Av.T * V) elif tensorType == 2: # anisotropic Av = getattr(self, 'ave'+projType+'2CCV') V = sp.kron(sp.identity(self.dim), Utils.sdiag(self.vol)) if self._meshType == 'CYL': Zero = sp.csr_matrix((self.nC, self.nC)) Eye = sp.eye(self.nC) if projType == 'E': P = sp.hstack([Zero, Eye, Zero]) # print P.todense() elif projType == 'F': P = sp.vstack([sp.hstack([Eye, Zero, Zero]), sp.hstack([Zero, Zero, Eye])]) # print P.todense() else: P = sp.eye(self.nC*self.dim) if not invMat and not invProp: dMdprop = Av.T * P * V elif invMat and invProp: dMdprop = (Utils.sdiag(MI.diagonal()**2) * Av.T * P * V * Utils.sdiag(1./prop**2)) elif invProp: dMdprop = Av.T * P * V * Utils.sdiag(-1./prop**2) elif invMat: dMdprop = Utils.sdiag(- MI.diagonal()**2) * Av.T * P * V if dMdprop is not None: def innerProductDeriv(v=None): if v is None: warnings.warn("Depreciation Warning: " "TensorMesh.innerProductDeriv." " You should be supplying a vector. " "Use: sdiag(u)*dMdprop", FutureWarning) return dMdprop return Utils.sdiag(v) * dMdprop return innerProductDeriv else: return None
def _fastInnerProductDeriv(self, projType, prop, invProp=False, invMat=False): """ :param str projType: 'E' or 'F' :param TensorType tensorType: type of the tensor :param bool invProp: inverts the material property :param bool invMat: inverts the matrix :rtype: function :return: dMdmu, the derivative of the inner product matrix """ assert projType in ["F", "E"], "projType must be 'F' for faces or 'E'" " for edges" tensorType = Utils.TensorType(self, prop) dMdprop = None if invMat or invProp: MI = self._fastInnerProduct(projType, prop, invProp=invProp, invMat=invMat) # number of elements we are averaging (equals dim for regular # meshes, but for cyl, where we use symmetry, it is 1 for edge # variables and 2 for face variables) if self._meshType == "CYL": n_elements = np.sum(getattr(self, "vn" + projType).nonzero()) else: n_elements = self.dim if tensorType == 0: # isotropic, constant Av = getattr(self, "ave" + projType + "2CC") V = Utils.sdiag(self.vol) ones = sp.csr_matrix((np.ones(self.nC), (range(self.nC), np.zeros(self.nC))), shape=(self.nC, 1)) if not invMat and not invProp: dMdprop = n_elements * Av.T * V * ones elif invMat and invProp: dMdprop = n_elements * ( Utils.sdiag(MI.diagonal() ** 2) * Av.T * V * ones * Utils.sdiag(1.0 / prop ** 2) ) elif invProp: dMdprop = n_elements * Av.T * V * Utils.sdiag(-1.0 / prop ** 2) elif invMat: dMdprop = n_elements * (Utils.sdiag(-MI.diagonal() ** 2) * Av.T * V) elif tensorType == 1: # isotropic, variable in space Av = getattr(self, "ave" + projType + "2CC") V = Utils.sdiag(self.vol) if not invMat and not invProp: dMdprop = n_elements * Av.T * V elif invMat and invProp: dMdprop = n_elements * (Utils.sdiag(MI.diagonal() ** 2) * Av.T * V * Utils.sdiag(1.0 / prop ** 2)) elif invProp: dMdprop = n_elements * Av.T * V * Utils.sdiag(-1.0 / prop ** 2) elif invMat: dMdprop = n_elements * (Utils.sdiag(-MI.diagonal() ** 2) * Av.T * V) elif tensorType == 2: # anisotropic Av = getattr(self, "ave" + projType + "2CCV") V = sp.kron(sp.identity(self.dim), Utils.sdiag(self.vol)) if self._meshType == "CYL": Zero = sp.csr_matrix((self.nC, self.nC)) Eye = sp.eye(self.nC) if projType == "E": P = sp.hstack([Zero, Eye, Zero]) # print(P.todense()) elif projType == "F": P = sp.vstack([sp.hstack([Eye, Zero, Zero]), sp.hstack([Zero, Zero, Eye])]) # print(P.todense()) else: P = sp.eye(self.nC * self.dim) if not invMat and not invProp: dMdprop = Av.T * P * V elif invMat and invProp: dMdprop = Utils.sdiag(MI.diagonal() ** 2) * Av.T * P * V * Utils.sdiag(1.0 / prop ** 2) elif invProp: dMdprop = Av.T * P * V * Utils.sdiag(-1.0 / prop ** 2) elif invMat: dMdprop = Utils.sdiag(-MI.diagonal() ** 2) * Av.T * P * V if dMdprop is not None: def innerProductDeriv(v=None): if v is None: warnings.warn( "Depreciation Warning: " "TensorMesh.innerProductDeriv." " You should be supplying a vector. " "Use: sdiag(u)*dMdprop", FutureWarning, ) return dMdprop return Utils.sdiag(v) * dMdprop return innerProductDeriv else: return None