Beispiel #1
0
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
Beispiel #2
0
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
Beispiel #3
0
def get_slip_to_disp_one_jacobi_step(m, cfg, H):
    base_cs = tct.continuity_constraints(m.pts, m.tris, m.get_start('fault'))
    base_cs.extend(tct.free_edge_constraints(m.tris))
    cs = base_cs + tct.all_bc_constraints(
        m.n_tris('surf'), m.n_tris(), np.zeros(m.n_dofs('fault'))
    )
    cm, _, rhs_mat = tct.build_constraint_matrix(cs, m.n_dofs())

    near = H.nearfield.full_scipy_mat_no_correction()
    diag = cm.T.dot(near.dot(cm)).diagonal()

    def f(disp, slip, old_slip):
        t = cfg['Timer']()
        c_rhs = rhs_mat.dot(np.concatenate((np.zeros(len(base_cs)), slip)))
        c_rhs_old = rhs_mat.dot(np.concatenate((np.zeros(len(base_cs)), old_slip)))
        t.report('constraints')

        start_val = np.concatenate((disp, slip))
        delta = cm.dot(
            (1.0 / diag) * (cm.T.dot(H.dot(start_val)))
        )
        out = start_val - delta - c_rhs_old + c_rhs
        t.report('jacobi step')
        return m.get_dofs(out, 'surf')
    return f
Beispiel #4
0
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
Beispiel #5
0
def get_slip_to_disp(m, cfg, H):
    base_cs = tct.continuity_constraints(m.pts, m.tris, m.get_start('fault'))
    base_cs.extend(tct.free_edge_constraints(m.tris))

    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 = -H.dot(c_rhs)
        out = tectosaur_topo.solve.iterative_solve(
            H, cm, rhs, lambda x: x, dict(solver_tol = 1e-4)
        )
        return out + c_rhs
    return f
Beispiel #6
0
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
Beispiel #7
0
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
Beispiel #8
0
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
Beispiel #9
0
#
# pt_slip = np.zeros((src_mesh[0].shape[0]))
# pt_slip[src_mesh[1]] = slip[:,:,0]
# levels = np.linspace(0, 1, 11)
# my_cmap = 'OrRd'
# plt.figure(figsize = (8,3.3))
# cntf = plt.tricontourf(src_mesh[0][:,0], src_mesh[0][:,2], src_mesh[1], pt_slip, levels = levels, cmap = my_cmap)
# plt.tricontour(src_mesh[0][:,0], src_mesh[0][:,2], src_mesh[1], pt_slip, levels = levels, linestyles='solid', colors='k', linewidths=0.5)
# plt.colorbar(cntf)
# plt.show()

# xs = np.linspace(-3, 3, 50)
# X, Y = np.meshgrid(xs, xs)
# Z = np.ones_like(X) * sep
# obs_pts = np.array([e.flatten() for e in [X, Y, Z]]).T.copy()
cs = tct.continuity_constraints(src_mesh[0], src_mesh[1], src_mesh[1].shape[0])
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)