Jonathan Feinberg. Marie Rognes. 20th June, 2013. Simula Research .... Define spatial discretization (Taylor--Hood). V = VectorFunctionSpace(mesh, "CG", 2).
Flexible Finite Element Methods for Geodynamics Using the FEniCS Framework
Stuart Clark Lyudmyla Vynnytska Jonathan Feinberg Marie Rognes Simula Research Laboratory
F + + +
= (2.0*eta*inner(sym(grad(u)), sym(grad(v)))*dx div(v)*p*dx div(u)*q*dx inner(f, v)*dx)
20th June, 2013
1. Simple Beginnings
2. Complex Advection-Diffusion
3. Adjoint
4. Stochastic
First step: to derive the varational form
from dolfin import * class InitialConditions(Expression): def eval(self, values, x): values = "0.5*(1.0 - x[1]*x[1]) + 0.01*cos(pi*x[0])*sin(pi*x[1])" class Source(Expression): def __init__(self,time): t = time def eval(self,values,x): dx = x[0] - 0.25 dy = x[1] - 0.5 values[0] = "10*cos(t*DOLFIN_PI)*exp(-2*(dx*dx + dy*dy))“ mesh = UnitSquare(32,32) V = FunctionSpace(mesh,'CG',2) def left_boundary(x,on_boundary): return on_boundary and x[0] def right_boundary(x,on_boundary): return on_boundary and x[0] def top_boundary(x,on_boundary): return on_boundary and x[1] def bottom_boundary(x,on_boundary): return on_boundary and x[1]
> 0.45 and x[0] < 0.55 and x[1] < DOLFIN_EPS > 1.0 - DOLFIN_EPS > 1.0 - DOLFIN_EPS < DOLFIN_EPS
u = TrialFunction(V) v = TestFunction(V) # Rheological Parameter c = Constant(1.00) # Time Step dt = 0.01 # Maximal Time T = 5.00 u0_expr = "0.0"; u0 = Expression(u0_expr) u0_ = Function(V) u0_ = interpolate(u0, V) u_1_expr = "0.00001"; u_1 = Expression(u_1_expr) u_1_ = Function(V) u_1_ = interpolate(u_1, V)
Initialise previous 2 timesteps
k = Constant(dt) t = dt # f # g
Interior Source term = Constant(0.0) Neumann Boundary Condition = Constant(0.0)
F = u*v*dx - 2*u0_*v*dx + u_1_*v*dx + pow(k,2)*pow(c,2)*inner(grad(u),grad(v))*dx -g*v*ds + f*v*dx a,L = lhs(F),rhs(F)
Explicit Backward Euler
# Dirichlet Boundary Condition bc0 = Expression("cos(t*pi)",t=0.0) bcleft = DirichletBC(V,bc0,left_boundary) u = Function(V) while t < T + DOLFIN_EPS: bc0.t = t solve(a == L,u,bcs=[bcleft]) u_1_.assign(u0_) u0_.assign(u) plot (u, title="Displacement",scalarbar = True,rescale=True,axes="True")
Mantle Convection (Advection-Diffusion + Stokes Flow) Frame title closely resembles the equations with FEniCS
while (t