Ejemplo n.º 1
0
def get_potential2(params, syst_pars):
    V_r = params["V_r"]
    V_l = params["V_l"]
    x0 = params["x0"]
    sigma = params["sigma"]
    V_bottom = lambda x, V_0: (  # noqa: E731
        common.gaussian(x, V_0, x0, sigma) if x > x0 else V_0)
    V_top = lambda x: (  # noqa: E731
        V_r + common.gaussian(x, V_l - V_r, x0, sigma) if x > x0 else V_l)
    z0 = -syst_pars["r1"]
    z1 = syst_pars["r1"]
    return lambda x, z, V_0: (V_bottom(x, V_0) * (z1 - z) + V_top(x) *
                              (z - z0)) / (z1 - z0)
def es_mutate_steps(steps, p):
    steps_size = len(steps)
    new_steps = []
    t1 = np.sqrt(2 * steps_size) ** -1 
    t2 = np.sqrt(2 * np.sqrt(steps_size)) ** -1 
    for idx,step in enumerate(steps):
        new_step = step * np.exp( (t1 * common.gaussian(0,1))
                                 + (t2 * common.gaussian(0,1)) )

        sigma = new_step * p
        if sigma > 2:
            sigma = sigma % 2
        sigma = 1 - sigma
        new_steps.append(sigma)
    return new_steps
Ejemplo n.º 3
0
def es_mutate_steps(steps, p):
    steps_size = len(steps)
    new_steps = []
    t1 = np.sqrt(2 * steps_size)**-1
    t2 = np.sqrt(2 * np.sqrt(steps_size))**-1
    for idx, step in enumerate(steps):
        new_step = step * np.exp((t1 * common.gaussian(0, 1)) +
                                 (t2 * common.gaussian(0, 1)))

        sigma = new_step * p
        if sigma > 2:
            sigma = sigma % 2
        sigma = 1 - sigma
        new_steps.append(sigma)
    return new_steps
Ejemplo n.º 4
0
def main():
    # abc = remove_duplicate_pts(common.rect_to_tri_mesh(*common.twist_mesh(10)))

    pts, rects = getattr(common, which + '_mesh')(n)
    pts, tris = common.rect_to_tri_mesh(pts, rects)
    pts, tris = remove_duplicate_pts((pts, tris))
    # pts, tris = refine((pts, tris))
    # pts, tris = refine_to_size((pts, tris), 0.02)[0]
    # np.save('mesh.npy', (pts, tris))
    # plt.triplot(pts[:,0], pts[:,2], tris)
    # plt.show()
    # plt.triplot(pts[:,0], pts[:,1], tris)
    # plt.show()

    n_tris = tris.shape[0]
    tri_pts = pts[tris].reshape((-1, 3))
    dist = np.linalg.norm(tri_pts - gauss_center, axis=1)
    strike_slip = common.gaussian(*gauss_params, dist)
    slip = np.zeros((strike_slip.shape[0], 3))
    slip[:, 0] = strike_slip

    common_tectosaur.plot_tectosaur((pts, tris), slip[:, 0].reshape(-1, 3),
                                    'inputslip', folder)

    slip_to_traction = common_tectosaur.get_slip_to_traction(
        (pts, tris), common_tectosaur.tectosaur_cfg)
    traction = slip_to_traction(slip)

    sxy = traction.reshape(-1, 3, 3)[:, :, 0]
    syz = traction.reshape(-1, 3, 3)[:, :, 2]
    common_tectosaur.plot_tectosaur((pts, tris), sxy, 'sxy', folder)
    common_tectosaur.plot_tectosaur((pts, tris), syz, 'syz', folder)
    os.system(f'google-chrome {folder}/*.pdf')
Ejemplo n.º 5
0
def get_slip_field(pts, tris):
    n_tris = tris.shape[0]
    tri_pts = pts[tris].reshape((-1, 3))
    dist = np.linalg.norm(tri_pts - gauss_center, axis=1)
    strike_slip = common.gaussian(*gauss_params, dist)
    slip = np.zeros((strike_slip.shape[0], 3))
    slip[:, 0] = strike_slip
    return slip.flatten()
Ejemplo n.º 6
0
def main():
    pts, rects = common.planar_mesh(n)
    pts, tris = common.build_weird_tri_mesh(pts, rects)
    if rotate:
        pts = pts.dot(np.array([[0, 0, -1], [0, 1, 0], [1, 0, 0]]))

    n_tris = tris.shape[0]
    n_rects = rects.shape[0]
    assert(3 * n_rects == n_tris)
    tri_pts = pts[tris]
    rect_pts = pts[rects]
    tri_centers = np.mean(tri_pts, axis = 1)
    tri_dist = np.linalg.norm(tri_centers, axis = 1)
    rect_centers = np.mean(rect_pts, axis = 1)
    rect_dist = np.linalg.norm(rect_centers, axis = 1)

    # plt.figure(figsize = (15,15))
    # plt.triplot(pts[:,0], pts[:,2], tris)
    # plt.plot(rect_centers[:,0], rect_centers[:,2], '*')
    # plt.savefig(os.path.join(folder,'rect_setup.pdf'))


    if tri_srces:
        strike_slip = common.gaussian(*gauss_params, tri_dist)
        slip_tris = np.zeros((strike_slip.shape[0], 3))
        slip_tris[:,0] = strike_slip
    else:
        strike_slip = common.gaussian(*gauss_params, rect_dist)
        slip = np.zeros((strike_slip.shape[0], 3))
        slip[:,0] = strike_slip
        slip_tris = common.dofs_to_tris(slip)

    # common.plot_tris((pts, tris), slip_tris[:,0], 'inputslip', folder)

    strain, stress = common.eval_tris(rect_centers, tri_pts, slip_tris, sm, nu)

    stress_tris = common.dofs_to_tris(stress)
    common.plot_tris((pts, tris), stress_tris[:,3], 'rectsxy', folder)
    common.plot_tris((pts, tris), stress_tris[:,5], 'rectsyz', folder)
    plt.show()
def es_mutate_individual(individual, steps, minmax):
    data = individual[0]
    new_data = []

    mutated_idx = random.randint(0,len(data))

    for idx,value in enumerate(data):
        if mutated_idx == idx:
            new_value = value + (steps[idx] * common.gaussian(0,1))
        else:
            new_value = value
        new_data.append(common.round(new_value))

    return (new_data, steps)
Ejemplo n.º 8
0
def es_mutate_individual(individual, steps, minmax):
    data = individual[0]
    new_data = []

    mutated_idx = random.randint(0, len(data))

    for idx, value in enumerate(data):
        if mutated_idx == idx:
            new_value = value + (steps[idx] * common.gaussian(0, 1))
        else:
            new_value = value
        new_data.append(common.round(new_value))

    return (new_data, steps)
Ejemplo n.º 9
0
def es_mutate_population(population, steps, minmax):
    data = population[0]
    new_data = []

    #mutation_idx = random.randint(0, len(population))
    
    for idx,value in enumerate(data):
        new_value = value + (steps[idx] * common.gaussian(0,1))
        # Make sure mutated value no over passes max limit
        # We're not using negative values
        new_value = new_value % minmax[1]
        new_data.append(common.round(abs(new_value)))

    return (new_data, steps)
Ejemplo n.º 10
0
def es_mutate_population(population, steps, minmax):
    data = population[0]
    new_data = []

    #mutation_idx = random.randint(0, len(population))

    for idx, value in enumerate(data):
        new_value = value + (steps[idx] * common.gaussian(0, 1))
        # Make sure mutated value no over passes max limit
        # We're not using negative values
        new_value = new_value % minmax[1]
        new_data.append(common.round(abs(new_value)))

    return (new_data, steps)
Ejemplo n.º 11
0
def main():
    pts, rects = common.bend_mesh(n)
    m = common.rect_to_tri_mesh(pts, rects)

    n_tris = m[1].shape[0]
    tri_pts = m[0][m[1]]
    tri_centers = np.mean(tri_pts, axis = 1)

    dist = np.linalg.norm(tri_centers - gauss_center, axis = 1)
    strike_slip = common.gaussian(*gauss_params, dist)
    slip = np.zeros((strike_slip.shape[0], 3))
    slip[:,0] = strike_slip

    strain, stress = common.eval_tris(tri_centers, tri_pts, slip, sm, nu)

    common.plot_tris(m, stress[:,3], 'trisxy', folder)
    common.plot_tris(m, stress[:,5], 'trisyz', folder)
Ejemplo n.º 12
0
def main():
    pts, rects = common.bend_mesh(n)
    pts, tris = common.build_weird_tri_mesh(pts, rects)

    n_tris = tris.shape[0]
    n_rects = rects.shape[0]
    assert (3 * n_rects == n_tris)
    tri_pts = pts[tris]
    rect_pts = pts[rects]
    tri_centers = np.mean(tri_pts, axis=1)
    tri_dist = np.linalg.norm(tri_centers - gauss_center, axis=1)
    rect_centers = np.mean(rect_pts, axis=1)
    rect_dist = np.linalg.norm(rect_centers - gauss_center, axis=1)

    slip = np.zeros((rect_centers.shape[0], 3))
    slip[:, 0] = common.gaussian(*gauss_params, rect_dist)

    def xyz_to_tde(vec, rect_pts):
        rect_normals = normals(rect_pts)
        dip_vec = np.zeros_like(rect_normals)
        dip_vec[:, 2] = 1.0
        strike_vec = np.cross(rect_normals, dip_vec)

        def proj(V, b):
            numer = np.sum(V * b, axis=1)[:, np.newaxis] * b
            denom = np.linalg.norm(b, axis=1)[:, np.newaxis]**2
            return numer / denom

        out = np.empty_like(vec)
        out[:, 0] = np.linalg.norm(proj(vec, strike_vec), axis=1)
        out[:, 1] = np.linalg.norm(proj(vec, dip_vec), axis=1)
        out[:, 2] = np.linalg.norm(proj(vec, rect_normals), axis=1)
        return out

    slip_tde = xyz_to_tde(slip, rect_pts)
    slip_tris = common.dofs_to_tris(slip_tde)

    strain, stress = common.eval_tris(rect_centers, tri_pts, slip_tris, sm, nu)

    stress_tris = common.dofs_to_tris(stress)
    common.plot_tris((pts, tris), stress_tris[:, 3], 'rectsxy', folder)
    common.plot_tris((pts, tris), stress_tris[:, 5], 'rectsyz', folder)
Ejemplo n.º 13
0
def main():
    pts, rects = common.planar_mesh(n)
    m = common.rect_to_tri_mesh(pts, rects)

    n_tris = m[1].shape[0]
    tri_pts = m[0][m[1]]
    tri_centers = np.mean(tri_pts, axis=1)

    plt.figure(figsize=(15, 15))
    plt.triplot(m[0][:, 0], m[0][:, 2], m[1])
    plt.plot(tri_centers[:, 0], tri_centers[:, 2], '*')
    plt.savefig(os.path.join(folder, 'tri_setup.pdf'))
    # plt.show()

    dist = np.linalg.norm(tri_centers, axis=1)
    strike_slip = common.gaussian(*gauss_params, dist)
    slip = np.zeros((strike_slip.shape[0], 3))
    slip[:, 0] = strike_slip

    strain, stress = common.eval_tris(tri_centers, tri_pts, slip, sm, nu)

    common.plot_tris(m, stress[:, 3], 'trisxy', folder)
    common.plot_tris(m, stress[:, 5], 'trisyz', folder)
 def input_process_fn(_x):
     return gaussian(_x,
                     is_training=True,
                     mean=0,
                     stddev=normilize(noise, 255))
Ejemplo n.º 15
0
def V_barrier(x, V_barrier_height, V_barrier_mu, V_barrier_sigma):
    return common.gaussian(x=x,
                           a=V_barrier_height,
                           mu=V_barrier_mu,
                           sigma=V_barrier_sigma)
def add_noise(imgs, noise):
    noise = common.normalize(noise)
    return common.gaussian(imgs, is_training=True, mean=0, stddev=noise)