def invPropertyTensor(M, tensor, returnMatrix=False): propType = TensorType(M, tensor) if isScalar(tensor): T = 1./tensor elif propType < 3: # Isotropic or Diagonal T = 1./mkvc(tensor) # ensure it is a vector. elif M.dim == 2 and tensor.size == M.nC*3: # Fully anisotropic, 2D tensor = tensor.reshape((M.nC,3), order='F') B = inv2X2BlockDiagonal(tensor[:,0], tensor[:,2], tensor[:,2], tensor[:,1], returnMatrix=False) b11, b12, b21, b22 = B T = np.r_[b11, b22, b12] elif M.dim == 3 and tensor.size == M.nC*6: # Fully anisotropic, 3D tensor = tensor.reshape((M.nC,6), order='F') B = inv3X3BlockDiagonal(tensor[:,0], tensor[:,3], tensor[:,4], tensor[:,3], tensor[:,1], tensor[:,5], tensor[:,4], tensor[:,5], tensor[:,2], returnMatrix=False) b11, b12, b13, b21, b22, b23, b31, b32, b33 = B T = np.r_[b11, b22, b33, b12, b13, b23] else: raise Exception('Unexpected shape of tensor') if returnMatrix: return makePropertyTensor(M, T) return T
def makePropertyTensor(M, tensor): if tensor is None: # default is ones tensor = np.ones(M.nC) if isScalar(tensor): tensor = tensor * np.ones(M.nC) propType = TensorType(M, tensor) if propType == 1: # Isotropic! Sigma = sp.kron(sp.identity(M.dim), sdiag(mkvc(tensor))) elif propType == 2: # Diagonal tensor Sigma = sdiag(mkvc(tensor)) elif M.dim == 2 and tensor.size == M.nC * 3: # Fully anisotropic, 2D tensor = tensor.reshape((M.nC, 3), order='F') row1 = sp.hstack((sdiag(tensor[:, 0]), sdiag(tensor[:, 2]))) row2 = sp.hstack((sdiag(tensor[:, 2]), sdiag(tensor[:, 1]))) Sigma = sp.vstack((row1, row2)) elif M.dim == 3 and tensor.size == M.nC * 6: # Fully anisotropic, 3D tensor = tensor.reshape((M.nC, 6), order='F') row1 = sp.hstack( (sdiag(tensor[:, 0]), sdiag(tensor[:, 3]), sdiag(tensor[:, 4]))) row2 = sp.hstack( (sdiag(tensor[:, 3]), sdiag(tensor[:, 1]), sdiag(tensor[:, 5]))) row3 = sp.hstack( (sdiag(tensor[:, 4]), sdiag(tensor[:, 5]), sdiag(tensor[:, 2]))) Sigma = sp.vstack((row1, row2, row3)) else: raise Exception('Unexpected shape of tensor') return Sigma
def makePropertyTensor(M, tensor): if tensor is None: # default is ones tensor = np.ones(M.nC) if isScalar(tensor): tensor = tensor * np.ones(M.nC) propType = TensorType(M, tensor) if propType == 1: # Isotropic! Sigma = sp.kron(sp.identity(M.dim), sdiag(mkvc(tensor))) elif propType == 2: # Diagonal tensor Sigma = sdiag(mkvc(tensor)) elif M.dim == 2 and tensor.size == M.nC*3: # Fully anisotropic, 2D tensor = tensor.reshape((M.nC,3), order='F') row1 = sp.hstack((sdiag(tensor[:, 0]), sdiag(tensor[:, 2]))) row2 = sp.hstack((sdiag(tensor[:, 2]), sdiag(tensor[:, 1]))) Sigma = sp.vstack((row1, row2)) elif M.dim == 3 and tensor.size == M.nC*6: # Fully anisotropic, 3D tensor = tensor.reshape((M.nC,6), order='F') row1 = sp.hstack((sdiag(tensor[:, 0]), sdiag(tensor[:, 3]), sdiag(tensor[:, 4]))) row2 = sp.hstack((sdiag(tensor[:, 3]), sdiag(tensor[:, 1]), sdiag(tensor[:, 5]))) row3 = sp.hstack((sdiag(tensor[:, 4]), sdiag(tensor[:, 5]), sdiag(tensor[:, 2]))) Sigma = sp.vstack((row1, row2, row3)) else: raise Exception('Unexpected shape of tensor') return Sigma
def meshTensor(value): """ **meshTensor** takes a list of numbers and tuples that have the form:: mT = [ float, (cellSize, numCell), (cellSize, numCell, factor) ] For example, a time domain mesh code needs many time steps at one time:: [(1e-5, 30), (1e-4, 30), 1e-3] Means take 30 steps at 1e-5 and then 30 more at 1e-4, and then one step of 1e-3. Tensor meshes can also be created by increase factors:: [(10.0, 5, -1.3), (10.0, 50), (10.0, 5, 1.3)] When there is a third number in the tuple, it refers to the increase factor, if this number is negative this section of the tensor is flipped right-to-left. .. plot:: from SimPEG import Mesh tx = [(10.0,10,-1.3),(10.0,40),(10.0,10,1.3)] ty = [(10.0,10,-1.3),(10.0,40)] M = Mesh.TensorMesh([tx, ty]) M.plotGrid(showIt=True) """ if type(value) is not list: raise Exception('meshTensor must be a list of scalars and tuples.') proposed = [] for v in value: if isScalar(v): proposed += [float(v)] elif type(v) is tuple and len(v) == 2: proposed += [float(v[0])] * int(v[1]) elif type(v) is tuple and len(v) == 3: start = float(v[0]) num = int(v[1]) factor = float(v[2]) pad = ( (np.ones(num) * np.abs(factor))**(np.arange(num) + 1)) * start if factor < 0: pad = pad[::-1] proposed += pad.tolist() else: raise Exception( 'meshTensor must contain only scalars and len(2) or len(3) tuples.' ) return np.array(proposed)
def meshTensor(value): """ **meshTensor** takes a list of numbers and tuples that have the form:: mT = [ float, (cellSize, numCell), (cellSize, numCell, factor) ] For example, a time domain mesh code needs many time steps at one time:: [(1e-5, 30), (1e-4, 30), 1e-3] Means take 30 steps at 1e-5 and then 30 more at 1e-4, and then one step of 1e-3. Tensor meshes can also be created by increase factors:: [(10.0, 5, -1.3), (10.0, 50), (10.0, 5, 1.3)] When there is a third number in the tuple, it refers to the increase factor, if this number is negative this section of the tensor is flipped right-to-left. .. plot:: from SimPEG import Mesh tx = [(10.0,10,-1.3),(10.0,40),(10.0,10,1.3)] ty = [(10.0,10,-1.3),(10.0,40)] M = Mesh.TensorMesh([tx, ty]) M.plotGrid(showIt=True) """ if type(value) is not list: raise Exception('meshTensor must be a list of scalars and tuples.') proposed = [] for v in value: if isScalar(v): proposed += [float(v)] elif type(v) is tuple and len(v) == 2: proposed += [float(v[0])]*int(v[1]) elif type(v) is tuple and len(v) == 3: start = float(v[0]) num = int(v[1]) factor = float(v[2]) pad = ((np.ones(num)*np.abs(factor))**(np.arange(num)+1))*start if factor < 0: pad = pad[::-1] proposed += pad.tolist() else: raise Exception('meshTensor must contain only scalars and len(2) or len(3) tuples.') return np.array(proposed)
def __init__(self, M, tensor): if tensor is None: # default is ones self._tt = -1 self._tts = 'none' elif isScalar(tensor): self._tt = 0 self._tts = 'scalar' elif tensor.size == M.nC: self._tt = 1 self._tts = 'isotropic' elif ((M.dim == 2 and tensor.size == M.nC*2) or (M.dim == 3 and tensor.size == M.nC*3)): self._tt = 2 self._tts = 'anisotropic' elif ((M.dim == 2 and tensor.size == M.nC*3) or (M.dim == 3 and tensor.size == M.nC*6)): self._tt = 3 self._tts = 'tensor' else: raise Exception('Unexpected shape of tensor')
def __init__(self, M, tensor): if tensor is None: # default is ones self._tt = -1 self._tts = 'none' elif isScalar(tensor): self._tt = 0 self._tts = 'scalar' elif tensor.size == M.nC: self._tt = 1 self._tts = 'isotropic' elif ((M.dim == 2 and tensor.size == M.nC * 2) or (M.dim == 3 and tensor.size == M.nC * 3)): self._tt = 2 self._tts = 'anisotropic' elif ((M.dim == 2 and tensor.size == M.nC * 3) or (M.dim == 3 and tensor.size == M.nC * 6)): self._tt = 3 self._tts = 'tensor' else: raise Exception('Unexpected shape of tensor')
def invPropertyTensor(M, tensor, returnMatrix=False): propType = TensorType(M, tensor) if isScalar(tensor): T = 1. / tensor elif propType < 3: # Isotropic or Diagonal T = 1. / mkvc(tensor) # ensure it is a vector. elif M.dim == 2 and tensor.size == M.nC * 3: # Fully anisotropic, 2D tensor = tensor.reshape((M.nC, 3), order='F') B = inv2X2BlockDiagonal(tensor[:, 0], tensor[:, 2], tensor[:, 2], tensor[:, 1], returnMatrix=False) b11, b12, b21, b22 = B T = np.r_[b11, b22, b12] elif M.dim == 3 and tensor.size == M.nC * 6: # Fully anisotropic, 3D tensor = tensor.reshape((M.nC, 6), order='F') B = inv3X3BlockDiagonal(tensor[:, 0], tensor[:, 3], tensor[:, 4], tensor[:, 3], tensor[:, 1], tensor[:, 5], tensor[:, 4], tensor[:, 5], tensor[:, 2], returnMatrix=False) b11, b12, b13, b21, b22, b23, b31, b32, b33 = B T = np.r_[b11, b22, b33, b12, b13, b23] else: raise Exception('Unexpected shape of tensor') if returnMatrix: return makePropertyTensor(M, T) return T