-
Notifications
You must be signed in to change notification settings - Fork 0
/
gradient_flow.py
54 lines (43 loc) · 1.35 KB
/
gradient_flow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from firedrake import *
Lx = 0.1
Ly = 10.
ref_level = 3
deg = 2
#mesh = UnitIcosahedralSphereMesh(ref_level, degree=deg)
mesh = UnitOctahedralSphereMesh(ref_level, degree=deg, hemisphere="north")
Xn = mesh.coordinates
V = VectorFunctionSpace(mesh, "CG", deg)
K = FunctionSpace(mesh, "CG", deg)
Xbcs = Function(V).assign(Xn)
mesh.init_cell_orientations(Xn)
nu = TestFunction(V)
Xnp = Function(V).assign(Xbcs)
eta = TestFunction(V)
nu = CellNormal(mesh)
Dt = 1.0e-5
dt = Constant(Dt)
F = (
inner(Xnp - Xn, eta) + dt*inner(grad(Xnp),grad(eta))
)*dx
bcs = [DirichletBC(V, Xbcs, "on_boundary")]
prob = NonlinearVariationalProblem(F, Xnp, bcs=bcs)
solver = NonlinearVariationalSolver(prob,
solver_parameters=
{'mat_type': 'aij',
'snes_converged_reason':True,
'ksp_converged_reason':True,
'snes_linesearch_type':'basic',
"snes_monitor":True,
'ksp_type': 'preonly',
'pc_type': 'lu'})
T = 0.5
t = 0.
file = File('curvatureflow.pvd')
Xnp.assign(Xn)
file.write(Xnp)
while t < T - Dt/2:
print(t)
t += Dt
solver.solve()
mesh.coordinates.assign(Xnp)
file.write(Xnp)