This repository was archived by the owner on Jul 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChannel_2d_3d.jl
More file actions
182 lines (138 loc) · 5.16 KB
/
Channel_2d_3d.jl
File metadata and controls
182 lines (138 loc) · 5.16 KB
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
using Gridap
using LineSearches: BackTracking, Static, MoreThuente
"""
2D and 3D channel flow
laminar - vorticity ω extracted
I assume is stable because is 2D
In 3D, same (ν) -> strange results (no parabolic profile for u)
Periodic BC in x-normal faces
For D=3, 3d case, wrong velocity results - instability?
?Import GMSH mesh (there we have better control of the mesh) - but how to set periodic BC in msh file
"""
# Settings
periodic = false # If set to false, will put a uniform velocity u_in at the inlet
u_in = 1.0
ν = 0.0001472 # Kinematic vicosity
D=2; #add const, dimensions number 2 or 3
N=32; #add const, cells per dimensions
order = 1
u_0 = u_in
include("Channel_Mesh.jl")
model=mesh_channel(;D=D, N=N, printmodel=false, periodic)
body_force = periodic ? 0.00337204 : 0.0
@static if D==2
top = "tag_5"
bottom = "tag_6"
inlet = "tag_7"
outlet = "tag_8"
outlet_top = "tag_2" # top right corner, not adding corners results in a "jump" at the outlet
outlet_bottom = "tag_4" # bottom right corner
inlet_top = "tag_1"
inlet_bottom = "tag_3"
u_diri_tags=[top, bottom]
u_walls=VectorValue(0.0,0.0)
u_in_v = VectorValue(u_in, 0.0)
u_diri_values = [u_walls, u_walls]
p_diri_tags=String[]
p_diri_values=Float64[]
if !periodic
append!(u_diri_tags, [inlet, inlet_top, inlet_bottom, outlet_top, outlet_bottom])
append!(p_diri_tags, [outlet,outlet_top,outlet_bottom])
append!(u_diri_values, [u_in_v, u_in_v, u_in_v, u_walls, u_walls])
append!(p_diri_values, [0,0,0])
end
hf(x)=VectorValue(body_force, 0.0)
elseif D==3
top = ["tag_23", "tag_09", "tag_11"] # face right left
bottom = ["tag_24", "tag_10", "tag_12"]
inlet = "tag_05"
inlet_corners = ["tag_01", "tag_03", "tag_05", "tag_07"] #topleft bottomleft topright bottomright
inlet_sides = ["tag_13", "tag_15", "tag_17", "tag_19"] #left right top bottom
outlet = "tag_26"
outlet_corners = ["tag_02", "tag_04", "tag_06", "tag_08"] #topleft bottomleft topright bottomright
outlet_sides = ["tag_14", "tag_16", "tag_18", "tag_20"]
sides = ["tag_21", "tag_22"] # left right
u_diri_tags=append!(top, bottom)
u_walls=VectorValue(0, 0, 0)
u_in_v= VectorValue(u_in, 0, 0)
u_diri_values = [u_walls, u_walls, u_walls, u_walls, u_walls, u_walls]
p_diri_tags=String[]
p_diri_values=Float64[]
if !periodic
append!(u_diri_tags, [inlet], inlet_corners, inlet_sides, outlet_corners, outlet_sides)
append!(p_diri_tags, [outlet], outlet_corners, outlet_sides)
append!(u_diri_values, [u_in_v,
u_in_v, u_in_v, u_in_v, u_in_v,
u_in_v, u_in_v, u_in_v, u_in_v,
u_walls, u_walls, u_walls, u_walls,
u_walls, u_walls, u_walls, u_walls])
append!(p_diri_values, [0,0,0])
end
hf(x)=VectorValue(body_force, 0, 0)
end
reffeᵤ = ReferenceFE(lagrangian,VectorValue{D,Float64},order)
V = TestFESpace(model,reffeᵤ,conformity=:H1,dirichlet_tags=u_diri_tags)
reffeₚ = ReferenceFE(lagrangian,Float64, order)
if periodic
Q = TestFESpace(model, reffeₚ, conformity=:H1, constraint=:zeromean)
else
reffeₚ = ReferenceFE(lagrangian,Float64,order)
Q = TestFESpace(model, reffeₚ, conformity=:H1, dirichlet_tags=p_diri_tags)
end
U = TrialFESpace(V,u_diri_values)
if periodic
P = TrialFESpace(Q)
else
P = TrialFESpace(Q,p_diri_values)
end
Y = MultiFieldFESpace([V, Q])
X = MultiFieldFESpace([U, P])
degree = 2
Ω = Triangulation(model)
dΩ = Measure(Ω,degree)
# Momentum residual, without the viscous term
Rm(u,p) = u⋅∇(u) + ∇(p) - hf
# Continuity residual
Rc(u) = ∇⋅u
h = lazy_map(h->h^(1/D),get_cell_measure(Ω))
function τ(u,h)
τ₂ = h^2/(4*ν)
val(x) = x
val(x::Gridap.Fields.ForwardDiff.Dual) = x.value
u = val(norm(u))
if iszero(u)
return τ₂
end
τ₁ = h/(2*u)
return 1/(1/τ₁ + 1/τ₂)
end
τb(u,h) = (u⋅u)*τ(u,h)
var_equations((u,p),(v,q)) = ∫(
ν*∇(v)⊙∇(u) # Viscous term
+ v⊙Rm(u,p) # Other momentum terms
+ q*Rc(u) )dΩ
# Continuity
stab_equations((u,p),(v,q)) = ∫((τ∘(u,h)*(u⋅∇(v) + ∇(q)))⊙Rm(u,p) # First term: SUPG, second term: PSPG
+ τb∘(u,h)*(∇⋅v)⊙Rc(u) # Bulk viscosity. Try commenting out both stabilization terms to see what happens in periodic and non-periodic cases
)dΩ
res((u,p),(v,q)) = var_equations((u,p),(v,q)) + stab_equations((u,p),(v,q))
op = FEOperator(res,X,Y)
nls = NLSolver(show_trace=true, method=:newton, linesearch=MoreThuente(), iterations=30)
solver = FESolver(nls)
uh0 = interpolate_everywhere(u_in_v, U)
ph0 = interpolate_everywhere(0.0, P)
xh0 = interpolate_everywhere([uh0, ph0],MultiFieldFESpace([U,P]))
@time (uh, ph), _ = solve!(xh0,solver,op)
println("solve complete")
ω = ∇×uh;
writevtk(Ω,"results-channel-d$D",cellfields=["uh"=>uh,"ph"=>ph, "ω"=>ω])
using Plots
nn = 1000
ev_nodes = LinRange(-0.999, 0.999, nn)
y =1
vt(i) = VectorValue(y,i,0)
ve(v) = v[1]
vm = evaluate(uh, vt.(ev_nodes))
using Trapz
Um = 0.5 * trapz(ev_nodes, ve.(vm))
plot(ve.(vm), ev_nodes, seriestype = :scatter)