Beispiel #1
0
    def test_deriv_shape(self):
        quad = PyQuadraticTwoPhasePoly()

        poly2, coeff2, power2 = self._get_example_poly2D()
        quad.set_poly_phase2(poly2)

        x = [1.0, 4.0]

        # Derivative with respect to the first auxillary field
        deriv = quad.partial_deriv_shape_vec(x, 0)

        expected = 0.0
        for c, p in zip(coeff2, power2):
            if p[1] == 0:
                continue
            expected += c * (x[0]**p[0]) * p[1] * x[1]**(p[1] - 1)
        self.assertAlmostEqual(deriv, expected)
Beispiel #2
0
    def test_deriv_conc(self):
        quad = PyQuadraticTwoPhasePoly()

        poly1, coeff1, power1 = self._get_example_poly1D()
        poly2, coeff2, power2 = self._get_example_poly2D()

        quad.set_poly_phase1(poly1)
        quad.set_poly_phase2(poly2)

        x = [1.0, 2.0]
        deriv = quad.partial_deriv_conc_vec(x)

        expect1 = 0.0
        for c, p in zip(coeff1, power1):
            if p == 0:
                continue
            expect1 += p * c * x[0]**(p - 1)

        expect2 = 0.0
        # Conc derivative is with respect to the first
        for c, p in zip(coeff2, power2):
            if p[0] == 0:
                continue
            expect2 += c * p[0] * x[0]**(p[0] - 1) * x[1]**p[1]

        self.assertAlmostEqual(deriv, expect1 + expect2)
Beispiel #3
0
    def test_1D(self):
        poly = PyPolynomial(1)
        terms = [
            PyPolynomialTerm([2]),
            PyPolynomialTerm([1]),
            PyPolynomialTerm([0])
        ]
        coeff = [2.0, 1.0, -1.0]

        for c, t in zip(coeff, terms):
            poly.add_term(c, t)

        quad = PyQuadraticTwoPhasePoly()
        quad.set_poly_phase1(poly)
        quad.set_poly_phase2(poly)

        x = 2.5
        expected = coeff[0] * x**2 + coeff[1] * x + coeff[2]

        # Divide result by two, since we add the same polynomial
        # two places
        self.assertEqual(expected, 0.5 * quad.evaluate_vec([x]))
    def test_quadratic_two_phase(self):
        chgl = self.get_chgl3D()
        chgl.build3D()

        # Initialize a two phase landau polynomial
        landau = PyQuadraticTwoPhasePoly()

        # Initlaise 1D polynomial (concentration)
        poly1 = PyPolynomial(1)
        poly1.add_term(1.0, PyPolynomialTerm([2]))
        landau.set_poly_phase1(poly1)

        # Initialize 4D polynomial (concentration, shape1, shape2, shape3)
        poly2 = PyPolynomial(4)
        poly2.add_term(2.0, PyPolynomialTerm([1, 2, 0, 0]))
        landau.set_poly_phase2(poly2)
        chgl.set_free_energy_quadratic(landau)

        chgl.run(5, 1000)
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")
Beispiel #6
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")
Beispiel #7
0
    def test_error_raise(self):
        quad = PyQuadraticTwoPhasePoly()

        # Case 1: Raise because poly1 is not set
        with self.assertRaises(ValueError):
            quad.in_valid_state()

        poly = PyPolynomial(1)
        quad.set_poly_phase1(poly)

        # Case 2: Raise because poly2 is not set
        with self.assertRaises(ValueError):
            quad.in_valid_state()

        quad.set_poly_phase2(poly)
        quad.in_valid_state()