-
Notifications
You must be signed in to change notification settings - Fork 0
/
baseplate.py
78 lines (61 loc) · 2.01 KB
/
baseplate.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from firedrake import *
Ly = 1.0
Lx = 1.0
nw = 40
nl = 40
deg = 1
mesh = RectangleMesh(nl, nw, Lx, Ly)
X0 = mesh.coordinates
V = VectorFunctionSpace(mesh, "CG", deg, dim=3)
X03D = Function(V).interpolate(as_vector([X0[0],X0[1],0.]))
mesh = Mesh(X03D)
X0 = mesh.coordinates
V = VectorFunctionSpace(mesh, "CG", deg)
K = FunctionSpace(mesh, "CG", deg)
Rot = Constant(1.0/8)*2*pi*X0[0]/Lx
Xbcs = Function(V).interpolate(as_vector([X0[0],
0.5 + cos(Rot)*(X0[1]-0.5),
0.5 + sin(Rot)*(X0[1]-0.5)]))
Dt = 1.0e-5
dt = Constant(Dt)
Xn = Function(V).assign(Xbcs)
Xnp = Function(V).assign(Xbcs)
eta = TestFunction(V)
def grad2D(Z):
return as_tensor([[Z[0].dx(0), Z[0].dx(1)],
[Z[1].dx(0), Z[1].dx(1)],
[Z[2].dx(0), Z[2].dx(1)]])
J = grad2D(Xnp)
Jdag = inv(dot(J.T, J))*J.T
Jcross = cross(Xnp.dx(0),Xnp.dx(1))
detJ = inner(Jcross,Jcross)**0.5
F = (
inner(Xnp - Xn, eta)*detJ + dt*inner(dot(Jdag.T,grad2D(Xnp).T),
dot(Jdag.T,grad2D(eta).T)*detJ)
)*dx
bcs = [DirichletBC(V, Xbcs, (1,2))]
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('baseplateflow.pvd')
dX = Function(V)
mesh.coordinates.assign(Xnp)
file.write(Xnp)
mesh.coordinates.assign(X0)
while t < T - Dt/2:
print(t)
t += Dt
solver.solve()
mesh.coordinates.assign(Xnp)
file.write(Xnp)
mesh.coordinates.assign(X0)
Xn.assign(Xnp)