def get_traction_to_slip(m, cfg, H): t = cfg['Timer']() csS = tct.continuity_constraints(m.pts, m.tris, m.get_start('fault')) csF = tct.continuity_constraints(m.pts, m.get_tris('fault'), m.get_end('fault')) cs = tct.build_composite_constraints((csS, 0), (csF, m.n_dofs('surf'))) cs.extend(tct.free_edge_constraints(m.tris)) cm, c_rhs, _ = tct.build_constraint_matrix(cs, m.n_dofs()) cm = cm.tocsr() cmT = cm.T.tocsr() t.report('t2s -- build constraints') traction_mass_op = tct.MassOp(cfg['tectosaur_cfg']['quad_mass_order'], m.pts, m.tris) np.testing.assert_almost_equal(c_rhs, 0.0) t.report('t2s -- build massop') def prec(x): return x def f(traction): rhs = -traction_mass_op.dot(traction / cfg['sm']) out = iterative_solve(H, cm, rhs, prec, dict(solver_tol=1e-4)) return out f.H = H f.cm = cm f.traction_mass_op = traction_mass_op return f
def setup_slip_traction(m, cfg): setup_logging(cfg) cm = build_continuity(m, cfg) H = build_elastic_op(m, cfg, 'H') traction_mass_op = tct.MassOp(cfg['tectosaur_cfg']['quad_mass_order'], m.pts, m.tris) return H, traction_mass_op, cm
def get_traction_to_slip(m, cfg, H): t = cfg['Timer']() csS = tct.continuity_constraints(m.pts, m.tris, m.get_start('fault')) csF = tct.continuity_constraints(m.pts, m.get_tris('fault'), m.get_end('fault')) cs = tct.build_composite_constraints((csS, 0), (csF, m.n_dofs('surf'))) cs.extend(tct.free_edge_constraints(m.tris)) cm, c_rhs, _ = tct.build_constraint_matrix(cs, m.n_dofs()) cm = cm.tocsr() cmT = cm.T.tocsr() t.report('t2s -- build constraints') traction_mass_op = tct.MassOp(cfg['tectosaur_cfg']['quad_mass_order'], m.pts, m.tris) np.testing.assert_almost_equal(c_rhs, 0.0) t.report('t2s -- build massop') # nearfield_H = H.nearfield.full_scipy_mat_no_correction() # diag_H = nearfield_H.diagonal() # def prec(x): # return cm.T.dot(cm.dot(x) / diag_H) # nearfield_H = H.nearfield.full_scipy_mat_no_correction() # constrained_nearfield_H = cmT.dot(nearfield_H.dot(cm)) # t.report('t2s -- constrained nearfield') # spilu = scipy.sparse.linalg.spilu(constrained_nearfield_H) # t.report('t2s -- spilu') # def prec(x): # return spilu.solve(x) # U = build_elastic_op(m, cfg, 'U') # nearfield_U = U.nearfield.full_scipy_mat_no_correction() # diag_U = nearfield_U.diagonal() # def prec(x): # return cmT.dot(U.dot(cm.dot(x))) def prec(x): return x def f(traction): rhs = -traction_mass_op.dot(traction / cfg['sm']) out = tectosaur_topo.solve.iterative_solve( H, cm, rhs, prec, dict(solver_tol = 1e-4) ) return out f.H = H f.cm = cm f.traction_mass_op = traction_mass_op return f
def get_slip_to_disp(m, cfg, T): base_cs = tct.continuity_constraints(m.pts, m.tris, m.get_start('fault')) # base_cs.extend(tct.free_edge_constraints(m.tris)) mass_op = tct.MultOp(tct.MassOp(3, m.pts, m.tris), 0.5) iop = tct.SumOp([T, mass_op]) def f(slip): cs = base_cs + tct.all_bc_constraints(m.n_tris('surf'), m.n_tris(), slip) cm, c_rhs, _ = tct.build_constraint_matrix(cs, m.n_dofs()) rhs = -iop.dot(c_rhs) out = iterative_solve(iop, cm, rhs, lambda x: x, dict(solver_tol=1e-6)) return out + c_rhs return f
def get_disp_slip_to_traction(m, cfg, H): csS = tct.all_bc_constraints(0, m.n_tris('surf'), np.zeros(m.n_dofs('surf'))) csS.extend(tct.free_edge_constraints(m.get_tris('surf'))) csF = tct.continuity_constraints(m.pts, m.get_tris('fault'), m.get_end('fault')) csF.extend(tct.free_edge_constraints(m.get_tris('fault'))) cs = tct.build_composite_constraints((csS, 0), (csF, m.n_dofs('surf'))) cm, c_rhs, _ = tct.build_constraint_matrix(cs, m.n_dofs()) traction_mass_op = tct.MassOp(cfg['tectosaur_cfg']['quad_mass_order'], m.pts, m.tris) constrained_traction_mass_op = cm.T.dot(traction_mass_op.mat.dot(cm)) def f(disp_slip): np.testing.assert_almost_equal(c_rhs, 0.0) def callback(x): callback.iter += 1 print(callback.iter) callback.iter = 0 rhs = -H.dot(disp_slip) constrained_rhs = cm.T.dot(rhs) soln = cg(constrained_traction_mass_op, constrained_rhs)#, callback = callback) out = cfg['sm'] * cm.dot(soln[0]) return out return f
def get_disp_slip_to_traction(m, cfg, H): csTS = tct.continuity_constraints(m.pts, m.get_tris('surf'), int(1e9)) # csTS = tct.all_bc_constraints(0, m.n_tris('surf'), np.zeros(m.n_dofs('surf'))) csTF = tct.continuity_constraints(m.pts, m.get_tris('fault'), int(1e9)) csT = tct.build_composite_constraints((csTS, 0), (csTF, m.n_dofs('surf'))) csT.extend(tct.free_edge_constraints(m.tris)) cmT, c_rhsT, _ = tct.build_constraint_matrix(csT, m.n_dofs()) np.testing.assert_almost_equal(c_rhsT, 0.0) cmU = cmT traction_mass_op = tct.MassOp(cfg['tectosaur_cfg']['quad_mass_order'], m.pts, m.tris) constrained_traction_mass_op = cmU.T.dot(traction_mass_op.mat.dot(cmT)) def f(disp_slip): t = cfg['Timer']() def callback(x): callback.iter += 1 print(callback.iter) callback.iter = 0 rhs = -cmU.T.dot(H.dot(disp_slip.flatten())) t.report('rhs') soln = cg(constrained_traction_mass_op, rhs) #soln = lsmr(constrained_traction_mass_op, rhs)#, callback = callback) t.report('lsmr') out = cfg['sm'] * (cmT.dot(soln[0]) + c_rhsT) t.report('out') return out return f
def test_topo_bug(): n_fault = 51 fault_L = 4000 fault_W = 4000 fault_m = tct.make_rect(n_fault, n_fault, [[-fault_L, 0, 0], [-fault_L, 0, -2 * fault_W], [fault_L, 0, -2 * fault_W], [fault_L, 0, 0]]) n_surf = 101 surf_L = 8000 surf_W = 8000 surf_m = tct.make_rect(n_surf, n_surf, [[-surf_L, surf_W, 0], [-surf_L, -surf_W, 0], [surf_L, -surf_W, 0], [surf_L, surf_W, 0]]) n_tris = fault_m[1].shape[0] m = tct.CombinedMesh.from_named_pieces([('surf', surf_m), ('fault', fault_m)]) qd_cfg = dict( # Material properties sm=2e10, # Shear modulus (Pa) pr=0.25, # Poisson ratio density=2670, # rock density (kg/m^3) # Frictional properties Dc=0.012, # state evolution length scale (m) f0=0.6, # baseline coefficient of friction V0=1e-6, # when V = V0, f = f0, V is (m/s) a=np.ones(n_tris * 3) * 0.010, b=np.ones(n_tris * 3) * 0.015, # Boundary conditions plate_rate=1e-9, # (m/s), equivalent to ~31.5 mm/yr slipdir=(1.0, 0.0, 0.0), # This is only necessary because this is a full space model and there's no concept of depth or gravity additional_normal_stress=50e6, # numerical preferences only_x=True, # slip/velocity/traction in the y,z directions are set = 0 timestep_tol=1e-3, # error tolerance for the RK45 time stepper tectosaur_cfg=dict(quad_coincident_order=8, quad_edgeadj_order=8, quad_vertadj_order=8, quad_mass_order=5, quad_far_order=3, quad_near_order=5, quad_near_threshold=2.5, float_type=np.float32, use_fmm=False, fmm_order=150, fmm_mac=3.0, pts_per_cell=450, log_level='DEBUG')) model = TopoModel(m, qd_cfg) # print_length_scales(model) cm, c_rhs = surf_fault_continuity(m, False) traction_mass_op = tct.MassOp( model.cfg['tectosaur_cfg']['quad_mass_order'], m.pts, m.tris) constrained_traction_mass_op = cm.T.dot(traction_mass_op.mat.dot(cm)) disp_slip = np.zeros(model.H().shape[1]) import ipdb ipdb.set_trace() rhs = -model.H().dot(disp_slip) constrained_rhs = cm.T.dot(rhs) def callback(x): callback.iter += 1 print(callback.iter) callback.iter = 0 soln = cg(constrained_traction_mass_op, constrained_rhs)
cs.extend(tct.free_edge_constraints(src_mesh[1])) cm, c_rhs, _ = tct.build_constraint_matrix(cs, src_mesh[1].shape[0] * 9) H = tct.RegularizedSparseIntegralOp( 6, 6, 6, 2, 5, 2.5, 'elasticRH3', 'elasticRH3', [1.0, 0.25], src_mesh[0], src_mesh[1], np.float32, farfield_op_type=tct.TriToTriDirectFarfieldOp) traction_mass_op = tct.MassOp(4, src_mesh[0], src_mesh[1]) constrained_traction_mass_op = cm.T.dot(traction_mass_op.mat.dot(cm)) rhs = -H.dot(slip.flatten()) soln = cg(constrained_traction_mass_op, cm.T.dot(rhs)) out = cm.dot(soln[0]) def plot_fnc(triang, f): levels = np.linspace(np.min(f) - 1e-12, np.max(f) + 1e-12, 21) cntf = plt.tricontourf(triang, f, levels=levels, cmap='RdBu') plt.tricontour(triang, f, levels=levels, linestyles='solid', colors='k', linewidths=0.5)