def build_and_solve_H_regularized(data): timer = Timer(output_fnc=logger.debug) cs = build_constraints(data.surface_tris, data.fault_tris, data.all_mesh[0], data.all_mesh[1], data.gauss_z) # For H, we need to constrain the edges of the surface to have 0 displacement. cs.extend(free_edge_constraints(data.surface_tris)) timer.report("Constraints") H_op = RegularizedSparseIntegralOp( 6, 6, 6, 2, 5, 2.5, 'elasticRH3', 'elasticRH3', data.k_params, data.all_mesh[0], data.all_mesh[1], data.float_type, # farfield_op_type = TriToTriDirectFarfieldOp farfield_op_type=FMMFarfieldOp(mac=2.5, pts_per_cell=100, order=2)) iop = SumOp([H_op]) timer.report("Integrals") soln = solve.iterative_solve(iop, cs, tol=1e-5) timer.report("Solve") return soln
def setup_edge_bcs(self): cs = free_edge_constraints(self.m.get_tris('fault')) cm, c_rhs, _ = build_constraint_matrix(cs, self.m.n_dofs('fault')) constrained_slip = np.ones(cm.shape[1]) self.ones_interior = cm.dot(constrained_slip) self.field_inslipdir_interior = self.ones_interior.copy() self.field_inslipdir = self.field_inslipdir_interior.copy() for d in range(3): val = self.cfg.get('slipdir', (1.0, 0.0, 0.0))[d] self.field_inslipdir_interior.reshape(-1, 3)[:, d] *= val self.field_inslipdir.reshape(-1, 3)[:, d] = val self.field_inslipdir_edges = (self.field_inslipdir - self.field_inslipdir_interior)
def build_continuity(m, cfg): cs = tct.continuity_constraints(m.pts, m.tris, m.tris.shape[0]) cs.extend(free_edge_constraints(m.get_tris('fault'))) cm, c_rhs, _ = build_constraint_matrix(cs, m.n_dofs('fault')) return cm
def regularized_tester(K, sep, continuity, mass_op_factor=0.0, which=None): if which is None: raise Exception('select some operators!') n_m = 30 full_K_name = f'elastic{K}3' full_RK_name = f'elasticR{K}3' m, surf1_idxs, surf2_idxs = make_meshes(n_m=n_m, sep=sep) if sep == 0.0: surf2_idxs = surf1_idxs near_threshold = 2.0 nq_near = 5 nq_far = 2 if any_nearfield(m[0], m[1], surf1_idxs, surf2_idxs, near_threshold): nearfield = True else: nearfield = False def sparse_unregularized(far_op, Kn): return SparseIntegralOp(6, nq_far, nq_near, near_threshold, Kn, [1.0, 0.25], m[0], m[1], np.float32, farfield_op_type=far_op, obs_subset=surf1_idxs, src_subset=surf2_idxs) def change_K_tri_tri(to): def f(*args, to=to): args = list(args) args[1] = to return TriToTriDirectFarfieldOp(*args) return f def add_sparse_reg(farfield_K, farfield_type): ops.append( SumOp([ RegularizedSparseIntegralOp(10, 10, 6, nq_far, nq_near, near_threshold, full_RK_name, farfield_K, [1.0, 0.25], m[0], m[1], np.float32, farfield_type, obs_subset=surf1_idxs, src_subset=surf2_idxs), MultOp(MassOp(3, m[0], m[1][surf1_idxs]), mass_op_factor) ])) ops = [sparse_unregularized(PtToPtDirectFarfieldOp, full_K_name)] if 'pt_to_pt_fmm' in which: ops.append( sparse_unregularized(PtToPtFMMFarfieldOp(150, 2.5, 5), full_K_name)) if 'tri_farfield_regularized' in which: ops.append( sparse_unregularized(change_K_tri_tri(full_RK_name), full_K_name)) if 'dense_regularized' in which: ops.append( SumOp([ RegularizedDenseIntegralOp(10, 10, 6, nq_far, nq_near, near_threshold, full_RK_name, full_RK_name, [1.0, 0.25], m[0], m[1], np.float32, obs_subset=surf1_idxs, src_subset=surf2_idxs), MultOp(MassOp(3, m[0], m[1][surf1_idxs]), mass_op_factor) ])) if 'sparse_regularized' in which: add_sparse_reg(full_RK_name, TriToTriDirectFarfieldOp) if 'sparse_regularized_fmm' in which: add_sparse_reg(full_K_name, PtToPtFMMFarfieldOp(150, 2.5, 5)) if 'sparse_regularized_but_unregularized_far': add_sparse_reg(full_K_name, change_K_tri_tri(full_K_name)) print('built ops') x = build_x_field(m, surf1_idxs, surf2_idxs) x_flat = x.flatten() outs = [o.dot(x_flat) for o in ops] if continuity: from tectosaur.constraint_builders import continuity_constraints, \ free_edge_constraints from tectosaur.constraints import build_constraint_matrix cs = continuity_constraints(m[1][surf1_idxs], np.array([])) cs.extend(free_edge_constraints(m[1][surf1_idxs])) cm, c_rhs = build_constraint_matrix(cs, outs[0].shape[0]) final_outs = [cm.T.dot(v) for v in outs] plot_outs = [cm.dot(v) for v in final_outs] else: plot_outs = outs final_outs = outs should_plot = True if should_plot: plot_fnc(m, surf1_idxs, surf2_idxs, x, plot_outs) for i in range(len(final_outs)): for j in range(i + 1, len(final_outs)): print(i, j, final_outs[i] / final_outs[j]) np.testing.assert_almost_equal(final_outs[i], final_outs[j], 6)