Example #1
0
 def from_named_pieces(named_pieces):
     names = [np[0] for np in named_pieces]
     pieces = [np[1] for np in named_pieces]
     pts, tris = concat(*pieces)
     sizes = [p[1].shape[0] for p in pieces]
     bounds = [0] + list(itertools.accumulate(sizes))
     return CombinedMesh(names, pts, tris, bounds)
Example #2
0
def benchmark():
    tct.logger.setLevel(logging.INFO)
    m = 1
    n = 50
    K = 'elasticRH3'
    m1 = mesh_gen.make_rect(n, n, [[-1, 0, 1], [-1, 0, -1], [1, 0, -1], [1, 0, 1]])
    m2 = mesh_gen.make_rect(n, n, [[-3, 0, 1], [-3, 0, -1], [-2, 0, -1], [-2, 0, 1]])
    x = np.random.rand(m2[1].shape[0] * 9)

    t = Timer()
    new_pts, new_tris = concat(m1, m2)
    n_obs_tris = m1[1].shape[0]
    sparse_op = RegularizedSparseIntegralOp(
        8,8,8,2,5,2.5,K,K,[1.0, 0.25],new_pts,new_tris,
        np.float32,TriToTriDirectFarfieldOp,
        obs_subset = np.arange(0,n_obs_tris),
        src_subset = np.arange(n_obs_tris,new_tris.shape[0])
    )
    t.report('assemble matrix free')
    for i in range(m):
        y1 = sparse_op.dot(x)
    t.report('matrix free mv x10')

    fmm = FMMFarfieldOp(mac = 4.5, pts_per_cell = 300)(
        2, K, [1.0, 0.25], new_pts, new_tris, np.float32,
        obs_subset = np.arange(0,n_obs_tris),
        src_subset = np.arange(n_obs_tris,new_tris.shape[0])
    )
    report_interactions(fmm.fmm_obj)
    t.report('setup fmm')

    y2 = fmm.dot(x)
    t.report('fmm mv x10')

    print(y1, y2)
Example #3
0
def make_meshes(surf_w, fault_L, top_depth, n_surf, n_fault):
    t = Timer(output_fnc=logger.debug)
    surface = make_free_surface(surf_w, n_surf)
    t.report('make free surface')
    fault = make_fault(fault_L, top_depth, n_fault)
    t.report('make fault')
    all_mesh = mesh_modify.concat(surface, fault)
    t.report('concat meshes')
    surface_tris = all_mesh[1][:surface[1].shape[0]]
    fault_tris = all_mesh[1][surface[1].shape[0]:]
    return all_mesh, surface_tris, fault_tris
Example #4
0
def fmm_tester(K_name, far_only=False, one_cell=False):
    np.random.seed(123987)
    for order in [8]:  #range(2, 13):
        float_type = np.float64
        quad_order = 2
        K_params = np.array([1.0, 0.25])

        n = 20
        offset = 0.0
        if far_only:
            offset = 6.0
        if far_only and one_cell:
            offset = 9.0
        corners = [[-1.0, -1.0, 0], [-1.0, 1.0, 0], [1.0, 1.0, 0],
                   [1.0, -1.0, 0]]
        m_src = tct.make_rect(n, n, corners)
        v = np.random.rand(m_src[1].shape[0] * 9).astype(float_type)

        m_obs = tct.make_rect(n, n, corners)
        m_obs[0][:, 0] += offset

        full_m = concat(m_src, m_obs)
        src_subset = np.arange(0, m_src[1].shape[0])
        obs_subset = np.arange(0, m_obs[1].shape[0]) + m_src[1].shape[0]
        op = tct.TriToTriDirectFarfieldOp(quad_order, K_name, K_params,
                                          full_m[0], full_m[1], float_type,
                                          obs_subset, src_subset)
        y1 = op.dot(v)

        max_pts_per_cell = 2
        if one_cell:
            max_pts_per_cell = int(1e9)
        fmm = TSFMM(m_obs,
                    m_src,
                    params=K_params,
                    order=order,
                    quad_order=quad_order,
                    float_type=float_type,
                    K_name=K_name,
                    mac=2.5,
                    max_pts_per_cell=max_pts_per_cell,
                    n_workers_per_block=128)
        if far_only:
            assert (fmm.interactions.p2p.src_n_idxs.shape[0] == 0)
        report_interactions(fmm)

        y2 = fmm.dot(v)
        print(order, np.linalg.norm((y1 - y2)) / np.linalg.norm(y1))
    print(y1, y2)
    np.testing.assert_almost_equal(y1, y2, 5)
Example #5
0
def op(obs_m, src_m, K, nq = 2):
    new_pts, new_tris = concat(obs_m, src_m)
    n_obs_tris = obs_m[1].shape[0]
    obs_tris = new_tris[:n_obs_tris]
    src_tris = new_tris[n_obs_tris:]
    save = False
    if save:
        np.save('ptspts.npy', [new_pts, obs_tris, src_tris, nq])
    mat = farfield_tris(
        K, [1.0, 0.25], new_pts, obs_tris, src_tris, nq, np.float32
    )
    nrows = mat.shape[0] * 9
    ncols = mat.shape[3] * 9
    return mat.reshape((nrows, ncols))
Example #6
0
def make_meshes(n_m = 8, sep = 2, w = 1, n_m2 = None):
    if n_m2 is None:
        n_m2 = n_m

    m1 = make_rect(n_m, n_m, [
        [-w, 0, w], [-w, 0, -w],
        [w, 0, -w], [w, 0, w]
    ])
    m2 = make_rect(n_m2, n_m2, [
        [-w, sep, w], [-w, sep, -w],
        [w, sep, -w], [w, sep, w]
    ])
    m = concat(m1, m2)
    surf1_idxs = np.arange(m1[1].shape[0])
    surf2_idxs = (surf1_idxs[-1] + 1) + surf1_idxs
    return m, surf1_idxs, surf2_idxs
Example #7
0
def build_c2e(tree, check_r, equiv_r, cfg):
    t = Timer()

    assembler = FarfieldTriMatrix(cfg.K.name, cfg.params, 4, np.float64)
    check_surf = inscribe_surf(Ball(center = (0,0,0), R = 1), check_r, cfg.surf)
    equiv_surf = inscribe_surf(Ball(center = (0,0,0), R = 1), equiv_r, cfg.surf)

    new_pts, new_tris = concat(check_surf, equiv_surf)
    n_check_tris = check_surf[1].shape[0]
    check_tris = new_tris[:n_check_tris]
    equiv_tris = new_tris[n_check_tris:]

    mat = assembler.assemble(new_pts, check_tris, equiv_tris)

    nrows = mat.shape[0] * 9
    ncols = mat.shape[3] * 9
    equiv_to_check = mat.reshape((nrows, ncols))
    t.report('build e2cs')

    U, eig, VT = np.linalg.svd(equiv_to_check)
    out = (U.T.copy(), eig.copy(), VT.T.copy())
    t.report('svd')
    return out
Example #8
0
def test_remove_duplicates():
    surface1 = make_rect(2, 2, [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]])
    surface2 = make_rect(2, 2, [[0, 0, 0], [-1, 0, 0], [-1, 1, 0], [0, 1, 0]])
    m_f = concat(surface1, surface2)
    assert (m_f[0].shape[0] == 6)
    assert (m_f[1].shape[0] == 4)
Example #9
0
import numpy as np
import matplotlib.pyplot as plt
import tectosaur.mesh.mesh_gen as mesh_gen
import tectosaur.mesh.modify as mesh_modify
from tectosaur.ops.dense_integral_op import DenseIntegralOp
from tectosaur.ops.mass_op import MassOp

n, w = 10, 10.0
surf = mesh_gen.make_rect(n, n,
                          [[-w, -w, 0], [-w, w, 0], [w, w, 0], [w, -w, 0]])
n_fault, L, top_depth = 9, 1.0, -1.0
fault = mesh_gen.make_rect(n_fault, n_fault,
                           [[-L, 0, top_depth], [-L, 0, top_depth - 1],
                            [L, 0, top_depth - 1], [L, 0, top_depth]])
all_mesh = mesh_modify.concat(surf, fault)
surface_subset = np.arange(surf[1].shape[0])
fault_subset = np.arange(surf[1].shape[0], all_mesh[1].shape[0])
all_set = np.arange(all_mesh[1].shape[0])

A_set, B_set = all_set, all_set  #fault_subset
pairs = [('elasticU3', 'elasticU3', False), ('elasticT3', 'elasticA3', True),
         ('elasticH3', 'elasticH3', False)]
for K1, K2, M in pairs:
    opA = DenseIntegralOp(7,
                          4,
                          3,
                          2.0,
                          K1, [1.0, 0.25],
                          all_mesh[0],
                          all_mesh[1],
                          np.float32,