updates to face innerProducts

Increase Speed
Add derivatives
Add tests
This commit is contained in:
rowanc1
2014-02-28 15:21:39 -08:00
parent 1e5053085d
commit b5c7b11265
5 changed files with 160 additions and 2 deletions
+44
View File
@@ -39,6 +39,7 @@ class TensorMesh(BaseRectangularMesh, TensorView, DiffOperators, InnerProducts):
def __init__(self, h_in, x0=None):
assert type(h_in) is list, 'h_in must be a list'
assert len(h_in) in [1,2,3], 'h_in must be of dimension 1, 2, or 3'
h = range(len(h_in))
for i, h_i in enumerate(h_in):
if type(h_i) in [int, long, float]:
@@ -491,6 +492,49 @@ class TensorMesh(BaseRectangularMesh, TensorView, DiffOperators, InnerProducts):
indzu = (self.gridCC[:,2]==max(self.gridCC[:,2]))
return indxd, indxu, indyd, indyu, indzd, indzu
def _fastFaceInnerProduct(self, materialProperty=None, invertProperty=False):
"""
Fast version of getFaceInnerProduct.
This does not handle the case of a full tensor materialProperty.
:param numpy.array materialProperty: material property (tensor properties are possible) at each cell center (nC, (1, 3, or 6))
:param bool returnP: returns the projection matrices
:param bool invertProperty: inverts the material property
:rtype: scipy.csr_matrix
:return: M, the inner product matrix (nF, nF)
"""
if materialProperty is None:
materialProperty = np.ones(self.nC)
if materialProperty.size == self.nC:
if invertProperty:
materialProperty = 1./materialProperty
Av = self.aveF2CC
V = Utils.sdiag(self.vol)
return self.dim * Utils.sdiag(Av.T * V * materialProperty)
if materialProperty.size == self.nC*self.dim:
if invertProperty:
materialProperty = 1./materialProperty
Av = self.aveF2CCV
V = sp.kron(sp.identity(self.dim), Utils.sdiag(self.vol))
return Utils.sdiag(Av.T * V * Utils.mkvc(materialProperty))
def _fastFaceInnerProductDeriv(self, materialProperty=None):
"""
:param numpy.array materialProperty: material property (tensor properties are possible) at each cell center (nC, (1, 3, or 6))
:rtype: scipy.csr_matrix
:return: M, the inner product matrix (nF, nF)
"""
if materialProperty is None or materialProperty.size == self.nC:
Av = self.aveF2CC
return self.dim * Av.T * Utils.sdiag(self.vol)
if materialProperty.size == self.nC*self.dim: # anisotropic
Av = self.aveF2CCV
V = sp.kron(sp.identity(self.dim), Utils.sdiag(self.vol))
return Av.T * V
if __name__ == '__main__':
print('Welcome to tensor mesh!')