-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransforming.lua
265 lines (202 loc) · 6.93 KB
/
transforming.lua
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
util.transforming = util.transforming or {}
util.transforming.CreateTransformingSmoother = function(approxSpace, VelCmp, type)
local type = type or "FE"
local rightTrafoDisc = DomainDiscretization(approxSpace)
for i = 1, #VelCmp do
print (VelCmp[i])
local vIdent = DirichletBoundary()
vIdent:add(ConstUserNumber(0), VelCmp[i], "Inner,Boundary,PressureNode")
rightTrafoDisc:add(vIdent)
end
local pLaplace = ConvectionDiffusionFE("p", "Inner")
pLaplace:set_diffusion(1.0)
pLaplace:set_mass_scale(0.0)
rightTrafoDisc:add(pLaplace)
-- C) Boundary
-- TODO: ???
-- D) Solver
local ilu = ILU()
--ilu:set_sort_type(0) -- sort: u1, ..., un, v1, ..., vn, p1, .., pn
--ilu:set_debug(dbgWriter)
--local ilut = ILUT()
--ilu:set_sort_type(0) -- sort: u1, ..., un, v1, ..., vn, p1, .., pn
--ilut:set_debug(dbgWriter)
local sgs = SymmetricGaussSeidel()
sgs:set_damp(1.0)
local jac = Jacobi(0.6)
trafoSmoother = AssembledTransformingSmoother2dCPU1(sgs, rightTrafoDisc)
return trafoSmoother
end
--[[
Creates a Wittum-type transforming smoother:
A) transformedDisc:
-\vec \delta \vec u = 0
\nabla \cdot u - \beta p =0
where $beta Id\approx div [-(\vec \delta)^{-1} grad p]$.
B) rightTransformDisc:
u + \nabla p = 0
p = p (pIdent)
--]]
function CreateTransformingSmoother1(approxSpace, VelCmp, beta)
local rightTrafoDisc = DomainDiscretization(approxSpace)
local divLinker = ScaleAddLinkerVectorVector2d()
local unitVecs = {ConstUserVector(0.0), ConstUserVector(0.0)}
unitVecs[1]:set_entry(1.0, 0.0)
unitVecs[2]:set_entry(0.0, 1.0)
-- A) transformedDisc
local transformedDisc = DomainDiscretization(approxSpace);
for i = 1, #VelCmp do
print (VelCmp[i])
local tmp = ConvectionDiffusion(VelCmp[i], "Inner", type)
tmp:set_diffusion(1.0)
tmp:set_reaction_rate(0.0)
divLinker:add(unitVecs[i], tmp:gradient())
transformedDisc:add(tmp)
end
local div = ConvectionDiffusion("p", "Inner", type)
div:set_diffusion(0.0)
--div:set_vector_source()
div:set_source(divLinker)
div:set_reaction_rate(beta)
transformedDisc:add(div)
transformedDisc:add(BndDisc)
-- B) rightTransformDisc
local rightTrafoDisc = DomainDiscretization(approxSpace)
for i = 1, #VelCmp do
local tmp = ConvectionDiffusion(VelCmp[i], "Inner", type)
tmp:set_diffusion(0)
tmp:set_reaction_rate(1)
tmp:set_reaction(GridFunctionGradientComponentData(u, "p", i))
rightTrafoDisc:add(tmp)
end
pIdent = DirichletBoundary()
pIdent:add(ConstUserNumber(0), "p", "Inner,Boundary")
rightTrafoDisc:add(pIdent)
-- C) Boundary
-- TODO: ???
-- D) Solver
local ilu = ILU()
ilu:set_sort_type(3)
ilu:set_debug(dbgWriter)
trafoSmoother = AssembledTransformingSmoother2dCPU1(transformedDisc, ilu, rightTrafoDisc)
return trafoSmoother
end
--[[
-- This is (supposed to be) Brandt Dinar DGS
-- (Boundary conditions are not 100% clear...)
rightTrafoDisc = DomainDiscretization(approxSpace)
pLaplace = ConvectionDiffusion("p", "Inner", type)
pLaplace:set_diffusion(1)
rightTrafoDisc:add(pLaplace)
OutletDisc = DirichletBoundary()
OutletDisc:add(0.0, "p", "Inlet, Outlet, UpperWall, LowerWall")
rightTrafoDisc:add(OutletDisc)
for i = 1, #VelCmp do
local tmp = ConvectionDiffusion(VelCmp[i], "Inner", type)
tmp:set_diffusion(0)
tmp:set_reaction_rate(1)
tmp:set_reaction(GridFunctionGradientComponentData(u, "p", i))
rightTrafoDisc:add(tmp)
end
tmp = DirichletBoundary()
tmp:add(0.0, "u", "Inlet, Outlet, UpperWall, LowerWall")
tmp:add(0.0, "v", "Inlet, Outlet, UpperWall, LowerWall")
rightTrafoDisc:add(tmp)
TrafoSystenDisc = DomainDiscretization(approxSpace)
for i = 1, #VelCmp do
local tmp = ConvectionDiffusion(VelCmp[i], "Inner", type)
tmp:set_diffusion(Viscosity)
TrafoSystenDisc:add(tmp)
end
tmp = ConvectionDiffusion("p", "Inner", type)
tmp:set_diffusion(1)
TrafoSystenDisc:add(tmp)
tmp = DirichletBoundary()
tmp:add(0.0, "u", "Inlet, Outlet, UpperWall, LowerWall")
tmp:add(0.0, "v", "Inlet, Outlet, UpperWall, LowerWall")
TrafoSystenDisc:add(tmp)
trafoSmoother = AssembledTransformingSmoother(rightTrafoDisc, TrafoSystemDisc, Jacobi())
trafoSmoother:set_debug(GridFunctionDebugWriter(approxSpace))
trafoSmoother:set_damp(1)
--]]
--[[
Creates a Wittum-type transforming smoother:
A) transformedDisc (solve!):
-\vec \delta \vec u = 0
- \nabla \cdot u + Q_l p = 0
where $beta Id\approx div [-(\vec \delta)^{-1} grad p]$.
B) rightTransformDisc (apply!):
u:= u + \nabla p
p:= Q^p_l p
--]]
function CreateTransformingSmoother2(approxSpace, VelCmp, beta)
local rightTrafoDisc = DomainDiscretization(approxSpace)
local divLinker = ScaleAddLinkerVectorVector2d()
local unitVecs = {ConstUserVector(0.0), ConstUserVector(0.0)}
unitVecs[1]:set_entry(1.0, 0.0)
unitVecs[2]:set_entry(0.0, 1.0)
-- A) transformedDisc
local transformedDisc = DomainDiscretization(approxSpace);
for i = 1, #VelCmp do
print (VelCmp[i])
local tmp = ConvectionDiffusion(VelCmp[i], "Inner", type)
tmp:set_diffusion(1)
tmp:set_reaction_rate(0.0)
divLinker:add(unitVecs[i], tmp:gradient())
transformedDisc:add(tmp)
end
local div = ConvectionDiffusion("p", "Inner", type)
div:set_diffusion(1.0)
div:set_source(divLinker)
transformedDisc:add(div)
transformedDisc:add(BndDisc)
-- B) rightTransformDisc
local rightTrafoDisc = DomainDiscretization(approxSpace)
for i = 1, #VelCmp do
local tmp = ConvectionDiffusion(VelCmp[i], "Inner", type)
tmp:set_diffusion(0)
tmp:set_reaction_rate(1)
tmp:set_reaction(GridFunctionGradientComponentData(u, "p", i))
rightTrafoDisc:add(tmp)
end
pIdent = DirichletBoundary()
pIdent:add(ConstUserNumber(0), "p", "Inner,Boundary")
rightTrafoDisc:add(pIdent)
-- C) Boundary
-- TODO: ???
-- D) Solver
local ilu = ILU()
ilu:set_sort_type(3)
ilu:set_debug(dbgWriter)
trafoSmoother = AssembledTransformingSmoother2dCPU1(transformedDisc, ilu, rightTrafoDisc)
return trafoSmoother
end
--[[
Schur complement transforming smother
--]]
function CreateBlockTrafoSmoother0(approxSpace, originalDisc, beta)
-- assemble mass matrix (identity)
local schurComplementDisc = DomainDiscretization(approxSpace)
local discP = ConvectionDiffusion("p", "Inner", type)
discP:set_diffusion(0.0)
discP:set_reaction_rate(beta)
schurComplementDisc:add(discP)
--schurComplementDisc:add(BndDisc)
--schurComplementDisc:add(FixPressureDisc)
local trafoSmoother = BlockTransformingSmoother2dCPU1(originalDisc, schurComplementDisc, ILU(), Jacobi(0.66))
trafoSmoother:set_type(0);
return trafoSmoother
end
function CreateBlockTrafoSmoother1(approxSpace, originalDisc, beta)
-- assemble Laplacian
local schurComplementDisc = DomainDiscretization(approxSpace)
local discP = ConvectionDiffusion("p", "Inner", type)
discP:set_diffusion(beta)
discP:set_reaction_rate(0.0)
schurComplementDisc:add(discP)
--schurComplementDisc:add(BndDisc)
--schurComplementDisc:add(FixPressureDisc)
local trafoSmoother = BlockTransformingSmoother2dCPU1(originalDisc, schurComplementDisc, ILUT())
trafoSmoother:set_type(1);
return trafoSmoother
end