# -*- coding: utf-8 -*- # Copyright (C) 2006-2014 Garth N. Wells # # This file is part of DOLFIN. # # DOLFIN is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # DOLFIN is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with DOLFIN. If not, see . # # Modified by Anders Logg 2011 # Modified by Martin Alnæs 2014 # # The linearised bilinear form a(du, v) and linear form L(v) for # the Cahn-Hilliard equation. # # Compile this form with FFC: ffc -l dolfin -O -f split CahnHilliard2D.ufl from ufl_legacy import (Coefficient, derivative, diff, dot, dx, FiniteElement, grad, quadrilateral, split, TestFunctions, TrialFunction, variable) cell = quadrilateral P1 = FiniteElement("Lagrange", cell, 1) R = FiniteElement("Real", cell, 0) ME = P1*P1 du = TrialFunction(ME) q, v = TestFunctions(ME) u = Coefficient(ME) # current solution u0 = Coefficient(ME) # solution from previous converged step # Split mixed functions dc, dmu = split(du) c, mu = split(u) c0, mu0 = split(u0) lmbda = Coefficient(R) # surface energy parameter dt = Coefficient(R) # time step theta = Coefficient(R) # time stepping parameter # mu_(n+theta) mu_mid = (1-theta)*mu0 + theta*mu # Compute the chemical potential df/dc c = variable(c) f = 100*c**2*(1-c)**2 dfdc = diff(f, c) F0 = c*q*dx - c0*q*dx + dt*dot(grad(mu_mid), grad(q))*dx F1 = mu*v*dx - dfdc*v*dx - lmbda*dot(grad(c), grad(v))*dx F = F0 + F1 J = derivative(F, u, du)