-
Notifications
You must be signed in to change notification settings - Fork 2
/
DarcyHDGTests.jl
181 lines (147 loc) · 4.38 KB
/
DarcyHDGTests.jl
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
module DarcyHDGTests
using Test
using Gridap
using FillArrays
using Gridap.Geometry
using GridapHybrid
u(x) = VectorValue(1+x[1],1+x[2])
Gridap.divergence(::typeof(u)) = (x) -> 2
p(x) = -3.14
∇p(x) = VectorValue(0,0)
Gridap.∇(::typeof(p)) = ∇p
f(x) = u(x) + ∇p(x)
# Normal component of u(x) on Neumann boundary
function g(x)
tol=1.0e-14
if (abs(x[2])<tol)
return -x[2] #-x[1]-x[2]
elseif (abs(x[2]-1.0)<tol)
return x[2] # x[1]+x[2]
end
Gridap.Helpers.@check false
end
function solve_darcy_lhdg(model,order)
# Geometry
D = num_cell_dims(model)
Ω = Triangulation(ReferenceFE{D},model)
Γ = Triangulation(ReferenceFE{D-1},model)
∂K = GridapHybrid.Skeleton(model)
# Reference FEs
order = 1
reffeᵤ = ReferenceFE(lagrangian,VectorValue{D,Float64},order;space=:P)
reffeₚ = ReferenceFE(lagrangian,Float64,order-1;space=:P)
reffeₗ = ReferenceFE(lagrangian,Float64,order;space=:P)
# Define test FESpaces
V = TestFESpace(Ω , reffeᵤ; conformity=:L2)
Q = TestFESpace(Ω , reffeₚ; conformity=:L2)
M = TestFESpace(Γ,
reffeₗ;
conformity=:L2,
dirichlet_tags=collect(5:8))
Y = MultiFieldFESpace([V,Q,M])
# Define trial FEspaces
U = TrialFESpace(V)
P = TrialFESpace(Q)
L = TrialFESpace(M,p)
X = MultiFieldFESpace([U, P, L])
# FE formulation params
τ = 1.0 # HDG stab parameter
degree = 2*(order+1)
dΩ = Measure(Ω,degree)
n = get_cell_normal_vector(∂K)
nₒ = get_cell_owner_normal_vector(∂K)
d∂K = Measure(∂K,degree)
yh = get_fe_basis(Y)
xh = get_trial_fe_basis(X)
(uh,ph,lh) = xh
(vh,qh,mh) = yh
# Left-to-right evaluation of ∫(τ*(mh*(ph*(n⋅nₒ))))d∂K
# Works
op1 = (n⋅nₒ)
op2 = τ*mh
op3 = ph*op1
op4 = op2*op3
# Right-to-left evaluation
# Works
op1=ph*(n⋅nₒ)
mh*op1
τ*(mh*(ph*(n⋅nₒ)))
lh*(n⋅nₒ)
# Left-to-right evaluation
# Works
τ*mh*lh*(n⋅nₒ)
# Right-to-left evaluation
# Works
τ*(mh*(lh*(n⋅nₒ)))
# Evaluation of ∫(qh*(uh⋅n+τ*(ph-lh)*n⋅no))*d∂K
# qh*(uh⋅n)
# Works
qh*(uh⋅n)
(qh*uh)⋅n
# τ*(qh*(ph*(n⋅nₒ)))
# Right-to-left
# Works
op1=ph*(n⋅nₒ)
op2=qh*op1
op3=τ*op2
# Left-to-right
# τ*qh*ph*(n⋅nₒ)
op1=τ*qh
op2=op1*ph
op3=op2*(n⋅nₒ)
# τ*(qh*(lh*(n⋅nₒ)))
# Right-to-left
# Works
op1=lh*(n⋅nₒ)
op2=qh*op1
op3=τ*op2
# Left-to-right
# Works
op1=τ*qh
op2=op1*lh
op3=op2*(n⋅nₒ)
∫(mh*(uh⋅n))d∂K
a((uh,ph,lh),(vh,qh,mh)) = ∫( vh⋅uh - (∇⋅vh)*ph - ∇(qh)⋅uh )dΩ +
∫((vh⋅n)*lh)d∂K +
#∫(qh*(uh⋅n+τ*(ph-lh)*n⋅no))*d∂K
∫(qh*(uh⋅n))d∂K +
∫(τ*qh*ph*(n⋅nₒ))d∂K -
∫(τ*qh*lh*(n⋅nₒ))d∂K +
#∫(mh*(uh⋅n+τ*(ph-lh)*n⋅no))*d∂K
∫(mh*(uh⋅n))d∂K +
∫(τ*mh*ph*(n⋅nₒ))d∂K -
∫(τ*mh*lh*(n⋅nₒ))d∂K
l((vh,qh,mh)) = ∫( vh⋅f + qh*(∇⋅u))*dΩ
op=HybridAffineFEOperator((u,v)->(a(u,v),l(v)), X, Y, [1,2], [3])
xh=solve(op)
uh,_=xh
e = u -uh
@test sqrt(sum(∫(e⋅e)dΩ)) < 1.0e-12
residual((uh,ph,lh),(vh,qh,mh))=a((uh,ph,lh),(vh,qh,mh))-l((vh,qh,mh))
op = FEOperator(residual, X, Y)
nls = NLSolver(show_trace=true, method=:newton)
solver = FESolver(nls)
xh0 = FEFunction(X,zeros(num_free_dofs(X)))
xh, = solve!(xh0,solver,op)
uh,_=xh
e = u -uh
@test sqrt(sum(∫(e⋅e)dΩ)) < 1.0e-12
op = HybridFEOperator(residual, X, Y, [1,2], [3])
nls = NLSolver(show_trace=true, method=:newton)
solver = FESolver(nls)
xh0 = FEFunction(X,zeros(num_free_dofs(X)))
xh, = solve!(xh0,solver,op)
uh,_=xh
e = u -uh
@test sqrt(sum(∫(e⋅e)dΩ)) < 1.0e-12
end
partition = (0,1,0,1)
cells = (2,2)
model = CartesianDiscreteModel(partition,cells)
order=1
solve_darcy_lhdg(model,order)
cells = (2,2)
model = simplexify(CartesianDiscreteModel(partition,cells))
order=1
solve_darcy_lhdg(model,order)
end # module