# Make basic mesh h = np.ones(10) mesh = TensorMesh([h, h, h]) sig = np.random.rand(mesh.nC) # isotropic Sig = np.random.rand(mesh.nC, 6) # anisotropic # Inner product matricies Mc = sdiag(mesh.vol * sig) # Inner product matrix (centers) # Mn = mesh.getNodalInnerProduct(sig) # Inner product matrix (nodes) (*functionality pending*) Me = mesh.getEdgeInnerProduct(sig) # Inner product matrix (edges) Mf = mesh.getFaceInnerProduct(sig) # Inner product matrix for tensor (faces) # Differential operators Gne = mesh.nodalGrad # Nodes to edges gradient mesh.setCellGradBC(['neumann', 'dirichlet', 'neumann']) # Set boundary conditions Gcf = mesh.cellGrad # Cells to faces gradient D = mesh.faceDiv # Faces to centers divergence Cef = mesh.edgeCurl # Edges to faces curl Cfe = mesh.edgeCurl.T # Faces to edges curl # EXAMPLE: (u, sig*Curl*v) fig = plt.figure(figsize=(9, 5)) ax1 = fig.add_subplot(121) ax1.spy(Mf * Cef, markersize=0.5) ax1.set_title('Me(sig)*Cef (Isotropic)', pad=10) Mf_tensor = mesh.getFaceInnerProduct(Sig) # inner product matrix for tensor ax2 = fig.add_subplot(122) ax2.spy(Mf_tensor * Cef, markersize=0.5)
k = (xycc[:, 0] == 0) & (xycc[:, 1] == -15) # source at (0, -15) q = np.zeros(mesh.nC) q[k] = 1 # Define diffusivity within each cell a = mkvc(8.0 * np.ones(mesh.nC)) # Define the matrix M Afc = mesh.dim * mesh.aveF2CC # modified averaging operator to sum dot product Mf_inv = mesh.getFaceInnerProduct(invMat=True) Mc = sdiag(mesh.vol) Mc_inv = sdiag(1 / mesh.vol) Mf_alpha_inv = mesh.getFaceInnerProduct(a, invProp=True, invMat=True) mesh.setCellGradBC(["neumann", "neumann"]) # Set Neumann BC G = mesh.cellGrad D = mesh.faceDiv M = -D * Mf_alpha_inv * G * Mc + Afc * sdiag(u) * Mf_inv * G * Mc # Set time stepping, initial conditions and final matricies dt = 0.02 # Step width p = np.zeros(mesh.nC) # Initial conditions p(t=0)=0 I = sdiag(np.ones(mesh.nC)) # Identity matrix B = I + dt * M s = Mc_inv * q Binv = SolverLU(B)
# Make basic mesh h = np.ones(10) mesh = TensorMesh([h, h, h]) sig = np.random.rand(mesh.nC) # isotropic Sig = np.random.rand(mesh.nC, 6) # anisotropic # Inner product matricies Mc = sdiag(mesh.vol * sig) # Inner product matrix (centers) # Mn = mesh.getNodalInnerProduct(sig) # Inner product matrix (nodes) (*functionality pending*) Me = mesh.getEdgeInnerProduct(sig) # Inner product matrix (edges) Mf = mesh.getFaceInnerProduct(sig) # Inner product matrix for tensor (faces) # Differential operators Gne = mesh.nodalGrad # Nodes to edges gradient mesh.setCellGradBC(["neumann", "dirichlet", "neumann"]) # Set boundary conditions Gcf = mesh.cellGrad # Cells to faces gradient D = mesh.faceDiv # Faces to centers divergence Cef = mesh.edgeCurl # Edges to faces curl Cfe = mesh.edgeCurl.T # Faces to edges curl # EXAMPLE: (u, sig*Curl*v) fig = plt.figure(figsize=(9, 5)) ax1 = fig.add_subplot(121) ax1.spy(Mf * Cef, markersize=0.5) ax1.set_title("Me(sig)*Cef (Isotropic)", pad=10) Mf_tensor = mesh.getFaceInnerProduct(Sig) # inner product matrix for tensor ax2 = fig.add_subplot(122) ax2.spy(Mf_tensor * Cef, markersize=0.5)
k = (xycc[:, 0] == 0) & (xycc[:, 1] == -15) # source at (0, -15) q = np.zeros(mesh.nC) q[k] = 1 # Define diffusivity within each cell a = mkvc(8. * np.ones(mesh.nC)) # Define the matrix M Afc = mesh.dim * mesh.aveF2CC # modified averaging operator to sum dot product Mf_inv = mesh.getFaceInnerProduct(invMat=True) Mc = sdiag(mesh.vol) Mc_inv = sdiag(1 / mesh.vol) Mf_alpha_inv = mesh.getFaceInnerProduct(a, invProp=True, invMat=True) mesh.setCellGradBC(['neumann', 'neumann']) # Set Neumann BC G = mesh.cellGrad D = mesh.faceDiv M = -D * Mf_alpha_inv * G * Mc + Afc * sdiag(u) * Mf_inv * G * Mc # Set time stepping, initial conditions and final matricies dt = 0.02 # Step width p = np.zeros(mesh.nC) # Initial conditions p(t=0)=0 I = sdiag(np.ones(mesh.nC)) # Identity matrix B = I + dt * M s = Mc_inv * q Binv = SolverLU(B)