/
test110_debug.py
43 lines (35 loc) · 984 Bytes
/
test110_debug.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
#!/usr/bin/env python
from ufl import *
set_level(DEBUG)
#kind of element
gdim = 2
cell = tetrahedron if gdim == 3 else triangle
# Function Space for Velocity U and Pressure V
U = VectorElement("CG", cell, 2)
V = FiniteElement("CG", cell, 1)
# Mixed Function Space
W = U*V
# (initial guess) Function for solution
w = Coefficient(W)
# (right hand side) Function
f = Coefficient(U);
# split into parts, w_u is desired solution
(w_u,w_p) = (as_vector(tuple([w[i] for i in range(gdim)])), w[gdim])
# TestFunction
(psi_u,psi_p) = TestFunctions(W)
# user defined viscosity
# NU = Constant(cell)
# Weak Formulation
# nonlinear termin (+)
# laplace (+)
# pressure (+)
# solenoidal (+)
# rhs
F = inner(psi_u,dot(grad(w_u),w_u))*dx + \
inner(grad(psi_u),grad(w_u))*dx + \
-1*div(psi_u)*w_p*dx + \
-1*psi_p*div(w_u)*dx + \
dot(psi_u,f)*dx
# Derivative
dw = TrialFunction(W)
J = derivative(F, w, dw)