Ejemplo n.º 1
0
def main(prefix, start, startfile, initfunc, dx=30.0, steps=0, update_freq=0):
    #prefix = "data/almgsi_chgl_random_seed_strain_noise2/chgl"
    #prefix = "data/almgsi_chgl_3D_surface_3nm_64_strain_meV/chgl"
    #prefix = "data/almgsi_chgl_3D_MLdx1_1nm_64_strain_meV/chgl"
    #prefix = "/work/sophus/almgsi_chgl_3D_MLdx1_3nm_64_strain_meV/chgl"
    dim = 3
    L = 128
    num_gl_fields = 3
    M = 0.1 / dx**2
    alpha = 5.0
    dt = 0.003
    gl_damping = M / dx**2

    coeff, terms = get_polyterms(FNAME)

    poly = PyPolynomial(4)
    poly1 = PyPolynomial(1)

    with open(FNAME, 'r') as infile:
        info = json.load(infile)

    # kernel = PyGaussianKernel(info["kernel"]["std_dev"])
    # regressor = PyKernelRegressor(
    #     info["kernel_regressor"]["xmin"],
    #     info["kernel_regressor"]["xmax"])
    # regressor.set_kernel(kernel)
    # regressor.set_coeff(info["kernel_regressor"]["coeff"])
    grad_coeff = info["gradient_coeff"]

    for item in info["terms"]:
        c = item["coeff"]
        powers = item["powers"]
        poly.add_term(c, PyPolynomialTerm(powers))
        print(c, powers)

    N = len(info["conc_phase1"])
    for i, c in enumerate(info["conc_phase1"]):
        poly1.add_term(c, PyPolynomialTerm([N - i - 1]))

    alpha = grad_coeff[0] / dx**2
    b1 = grad_coeff[1] / dx**2
    b2 = grad_coeff[2] / dx**2
    #gradient_coeff = [[b2, b1, b2],
    #                  [b1, b2, b2],
    #                  [b2, b2, b1]]
    gradient_coeff = [[b1, b2, b1], [b2, b1, b1], [b1, b1, b2]]

    print(gradient_coeff)
    chgl = PyCHGLRealSpace(dim, L, prefix, num_gl_fields, M, alpha, dt,
                           gl_damping, gradient_coeff)

    # landau = PyTwoPhaseLandau()
    # landau.set_polynomial(poly)
    # landau.set_kernel_regressor(regressor)
    # landau.set_discontinuity(info["discontinuity_conc"], info["discontinuity_jump"])
    landau = PyQuadraticTwoPhasePoly()
    landau.set_poly_phase1(poly1)
    landau.set_poly_phase2(poly)

    chgl.set_free_energy_quadratic(landau)
    chgl.use_adaptive_stepping(1E-10, 1, 0.1)
    #chgl.set_field_update_rate(10)
    #chgl.set_strain_update_rate(100)
    chgl.build3D()
    add_strain(chgl)
    chgl.conserve_volume(1)

    if startfile is not None:
        chgl.from_file(prefix + startfile)
    else:
        if initfunc == "precipitate_square":
            chgl.from_npy_array(precipitates_square(L))
        elif initfunc == "matsuda":
            chgl.from_npy_array(create_matsuda(L))
        elif initfunc == 'prec_square_bck':
            chgl.from_npy_array(precipitate_square_bck(L))
        else:
            raise ValueError("Unknown init function!")

    chgl.run(steps, update_freq, start=start)
    chgl.save_free_energy_map(prefix + "_free_energy_map.grid")
Ejemplo n.º 2
0
def main(prefix,
         start,
         startfile,
         initfunc,
         dx=30.0,
         dt=0.3,
         steps=0,
         update_freq=0,
         prec_x0=20,
         prec_x1=50,
         a=1,
         b=1):
    #prefix = "data/almgsi_chgl_random_seed_strain_noise2/chgl"
    #prefix = "data/almgsi_chgl_3D_surface_3nm_64_strain_meV/chgl"
    #prefix = "data/almgsi_chgl_3D_MLdx1_1nm_64_strain_meV/chgl"
    #prefix = "/work/sophus/almgsi_chgl_3D_MLdx1_3nm_64_strain_meV/chgl"
    dim = 2
    L = 1024
    num_gl_fields = 2
    M = 0.1  #/dx**2
    alpha = 5.0
    gl_damping = M  #/dx**2

    coeff, terms = get_polyterms(FNAME)

    poly = PyPolynomial(3)
    poly1 = PyPolynomial(1)

    with open(FNAME, 'r') as infile:
        info = json.load(infile)

    # kernel = PyGaussianKernel(info["kernel"]["std_dev"])
    # regressor = PyKernelRegressor(
    #     info["kernel_regressor"]["xmin"],
    #     info["kernel_regressor"]["xmax"])
    # regressor.set_kernel(kernel)
    # regressor.set_coeff(info["kernel_regressor"]["coeff"])
    grad_coeff = info["gradient_coeff"]
    conc_scale = 1.0
    for item in info["terms"]:
        c = item["coeff"] * conc_scale
        powers = item["powers"]
        if powers[-1] > 0:
            continue
        poly.add_term(c, PyPolynomialTerm(powers[:-1]))
        print(c, powers)

    N = len(info["conc_phase1"])
    for i, c in enumerate(info["conc_phase1"]):
        poly1.add_term(c * conc_scale, PyPolynomialTerm([N - i - 1]))

    alpha = grad_coeff[0] / dx**2
    b1 = grad_coeff[1] / dx**2
    b2 = grad_coeff[2] / dx**2
    #gradient_coeff = [[b2, b1],
    #                  [b1, b2]]
    gradient_coeff = [[b1, b2], [b2, b1]]

    print(gradient_coeff)
    chgl = PyCHGL(dim, L, prefix, num_gl_fields, M, alpha, dt, gl_damping,
                  gradient_coeff)

    # landau = PyTwoPhaseLandau()
    # landau.set_polynomial(poly)
    # landau.set_kernel_regressor(regressor)
    # landau.set_discontinuity(info["discontinuity_conc"], info["discontinuity_jump"])
    landau = PyQuadraticTwoPhasePoly()
    landau.set_poly_phase1(poly1)
    landau.set_poly_phase2(poly)

    chgl.set_free_energy_quadratic(landau)
    chgl.use_adaptive_stepping(1E-10, 1, 0.05)
    omega_cut = 0.2 * np.pi
    roll_off = 0.3
    #chgl.set_raised_cosine_filter(omega_cut, roll_off)
    chgl.set_vandeven_filter(3)
    #chgl.set_gaussian_filter(omega_cut)
    #chgl.set_vandeven_filter(2)
    #chgl.use_HeLiuTang_stabilizer(500)
    #chgl.set_field_update_rate(100)
    #chgl.set_strain_update_rate(1000)
    #chgl.build2D()
    add_strain(chgl)
    chgl.set_conc_type_allen_cahn()
    chgl.conserve_volume(0)
    chgl.conserve_volume(1)
    chgl.conserve_volume(2)

    if startfile is not None:
        chgl.from_file(prefix + startfile)
    else:
        if initfunc == "precipitate_square":
            chgl.from_npy_array(
                precipitates_square(L, start=prec_x0, end=prec_x1))
        elif initfunc == "matsuda":
            chgl.from_npy_array(create_matsuda(L))
        elif initfunc == 'prec_square_bck':
            chgl.from_npy_array(precipitate_square_bck(L))
        elif initfunc == 'random':
            chgl.from_npy_array(random_orientation(L))
        elif initfunc == 'ellipse':
            chgl.from_npy_array(ellipse(L, a, b))
        else:
            raise ValueError("Unknown init function!")

    chgl.run(steps, update_freq, start=start)
    chgl.save_free_energy_map(prefix + "_free_energy_map.grid")