| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# Copyright (C) 2006-2014 Garth N. Wells |
| 3 |
# |
| 4 |
# This file is part of DOLFIN. |
| 5 |
# |
| 6 |
# DOLFIN is free software: you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU Lesser General Public License as published by |
| 8 |
# the Free Software Foundation, either version 3 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
# |
| 11 |
# DOLFIN is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU Lesser General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU Lesser General Public License |
| 17 |
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
# |
| 19 |
# Modified by Anders Logg 2011 |
| 20 |
# Modified by Martin Alnæs 2014 |
| 21 |
# |
| 22 |
# The linearised bilinear form a(du, v) and linear form L(v) for |
| 23 |
# the Cahn-Hilliard equation. |
| 24 |
# |
| 25 |
# Compile this form with FFC: ffc -l dolfin -O -f split CahnHilliard3D.ufl |
| 26 |
|
| 27 |
from ufl_legacy import (Coefficient, derivative, diff, dot, dx, |
| 28 |
FiniteElement, grad, split, tetrahedron, |
| 29 |
TestFunctions, TrialFunction, variable) |
| 30 |
|
| 31 |
cell = tetrahedron |
| 32 |
|
| 33 |
P1 = FiniteElement("Lagrange", cell, 1) |
| 34 |
R = FiniteElement("Real", cell, 0) |
| 35 |
ME = P1*P1 |
| 36 |
|
| 37 |
du = TrialFunction(ME) |
| 38 |
q, v = TestFunctions(ME) |
| 39 |
|
| 40 |
u = Coefficient(ME) # current solution |
| 41 |
u0 = Coefficient(ME) # solution from previous converged step |
| 42 |
|
| 43 |
# Split mixed functions |
| 44 |
dc, dmu = split(du) |
| 45 |
c, mu = split(u) |
| 46 |
c0, mu0 = split(u0) |
| 47 |
|
| 48 |
lmbda = Coefficient(R) # surface energy parameter |
| 49 |
dt = Coefficient(R) # time step |
| 50 |
theta = Coefficient(R) # time stepping parameter |
| 51 |
|
| 52 |
# mu_(n+theta) |
| 53 |
mu_mid = (1-theta)*mu0 + theta*mu |
| 54 |
|
| 55 |
# Compute the chemical potential df/dc |
| 56 |
c = variable(c) |
| 57 |
f = 100*c**2*(1-c)**2 |
| 58 |
dfdc = diff(f, c) |
| 59 |
|
| 60 |
F0 = c*q*dx - c0*q*dx + dt*dot(grad(mu_mid), grad(q))*dx |
| 61 |
F1 = mu*v*dx - dfdc*v*dx - lmbda*dot(grad(c), grad(v))*dx |
| 62 |
F = F0 + F1 |
| 63 |
|
| 64 |
J = derivative(F, u, du) |