Exemplo n.º 1
0
 def test_derivative(self):
     coeff = [4.0, 3.0, 2.0, 1.0]
     cahn = CahnHilliard(degree=3, coeff=coeff)
     cython_cahn = PyCahnHilliard(coeff)
     x_values = [2.0, 3.0, -1.0]
     for x in x_values:
         self.assertAlmostEqual(cahn.deriv(x), cython_cahn.deriv(x))
Exemplo n.º 2
0
def main(conc):
    prefix = "/work/sophus/cahn_hilliard_phase_separation3D/ch_{}_".format(
        int(100 * conc))
    dim = 3
    dx = 10.0  # Step size in angstrom
    L = 128
    num_gl_fields = 0
    M = 0.1
    alpha = 5.0
    dt = 0.5
    gl_damping = M
    gradient_coeff = []

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

    alpha = info["alpha"] / dx**2
    cahn_free = PyCahnHilliard(info["poly"], bounds=[-0.05, 1.05], penalty=0.0)
    sim = PyCahnHilliardPhaseField(3, L, prefix, cahn_free, M, dt, alpha)

    #sim.from_npy_array(random_init(L, conc))
    sim.set_adaptive(1E-10, 0.05)
    #sim.build3D()
    sim.from_file(prefix + "00000160000.grid")

    sim.run(100000, 10000, start=160000)
Exemplo n.º 3
0
    def test_regularization_consistentcy(self):
        coeff = [4.0, 3.0, 2.0, 1.0]
        cahn = CahnHilliard(degree=3,
                            coeff=coeff,
                            bounds=[0.0, 1.0],
                            penalty=10.0,
                            range_frac=0.1)
        cython_cahn = PyCahnHilliard(coeff,
                                     penalty=10.0,
                                     bounds=[0.0, 1.0],
                                     range_scale=0.1)

        x_values = [-0.1, 1.1, -0.5]
        for x in x_values:
            self.assertAlmostEqual(cahn.deriv(x), cython_cahn.deriv(x))

        for x in x_values:
            self.assertAlmostEqual(cahn.evaluate(x), cython_cahn.evaluate(x))
    def test_run_without_errors(self):
        coeff = [5.0, 4.0, 3.0, 2.0, 1.0]
        free = PyCahnHilliard(coeff)

        # Initialize a small 2D calculation
        L = 64
        M = 1.0
        dt = 0.01
        alpha = 1.0
        sim = PyCahnHilliardPhaseField(2, L, "cahnhill", free, M, dt, alpha)
        sim.run(100, 20)
    def test_numpy_init(self):
        coeff = [5.0, 4.0, 3.0, 2.0, 1.0]
        free = PyCahnHilliard(coeff)

        L = 64
        M = 1.0
        dt = 0.01
        alpha = 1.0
        sim = PyCahnHilliardPhaseField(2, L, "cahnhill", free, M, dt, alpha)

        array = np.random.rand(L, L)
        sim.from_npy_array(array)
        from_sim = sim.to_npy_array()
        self.assertTrue(np.allclose(from_sim, array))

        array2 = np.random.rand(L)
        with self.assertRaises(ValueError):
            sim.from_npy_array(array2)

        array3 = np.random.rand(2 * L, L)
        with self.assertRaises(ValueError):
            sim.from_npy_array(array3)