-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathelder_bq.lua
More file actions
248 lines (195 loc) · 8.6 KB
/
elder_bq.lua
File metadata and controls
248 lines (195 loc) · 8.6 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
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
----------------------------------------------------------
--
-- Lua-script for simulation of the Elder problem (with boussinesq approximation)
--
-- Author: Ekaterina Vasilyeva
--
-- Originally implemented for AMFS 2021
--
-- Based on Examples/elder_adapt.lua
----------------------------------------------------------
ug_load_script ("ug_util.lua")
ug_load_script ("util/load_balancing_util.lua")
------------------------------------------------------------------------------------------
-- Geometry and time interval
------------------------------------------------------------------------------------------
dim = 2
gridName = "grids/elder_quads_8x2_bnd.ugx"
numRefs = 5 -- number of refinements of the initial grid
numPreRefs = 1 -- this grid level is considered as the most coarse one for the numerics
endTime = 10 * 365 * 24 * 60 * 60 -- [s] = 10 years
dt = 10 * 24 * 60 * 60 -- [s] = 10 days
upwind = "partial" -- upwind type for the transport equation: "no", "full" or "partial"
vtk_file_name = "Elder_Bq_GL" .. numRefs -- VTK output file name base
------------------------------------------------------------------------------------------
-- Geological parameters, initial and boundary conditions
------------------------------------------------------------------------------------------
Porosity = 0.1
MolecularDiffusion = 3.565e-6
Permeability = 4.845e-13
Viscosity = 1e-3
function PressureStart(x, y, t, si)
return 9810 * (150 - y)
end
------------------------------------------------------------------------------------------
-- Dirichlet boundary conditions for the salt on the top boundary
------------------------------------------------------------------------------------------
function ConcentrationDirichletBnd(x, y, t)
if x > 150 and x < 450 then
return true, 1.0
end
return false, 0.0
end
------------------------------------------------------------------------------------------
-- Initialize ug4; use the block algebra for the pairs (c, p) (2 components per block)
------------------------------------------------------------------------------------------
InitUG(dim, AlgebraType("CPU", 2));
--------------------------------------------------------------------------------
-- Setup Domain and Approximation Space
--------------------------------------------------------------------------------
-- create the domain, load the grid and refine it
dom = util.CreateDomain(gridName, numPreRefs, {"Inner", "LeftRightBnd", "BottomBnd", "TopBnd","TopCorners"})
balancer.RefineAndRebalanceDomain(dom, numRefs - numPreRefs)
print("Domain info:")
print(dom:domain_info():to_string())
-- set up approximation space
approxSpace = ApproximationSpace(dom)
approxSpace:add_fct("c", "Lagrange", 1)
approxSpace:add_fct("p", "Lagrange", 1)
approxSpace:init_levels()
approxSpace:init_top_surface()
print("Approximation space:")
--approxSpace:print_layout_statistic() -- makes sense only for parallel runs
approxSpace:print_statistic()
-- Order the DoFs:
OrderLex (approxSpace, "y")
--------------------------------------------------------------------------------
-- Setup the spatial FV Discretization
--------------------------------------------------------------------------------
Gravity = ConstUserVector(0.0)
Gravity:set_entry(1, -9.81)
-- create dirichlet boundary for concentration
dirichletBND = DirichletBoundary()
dirichletBND:add("ConcentrationDirichletBnd", "c", "TopBnd")
dirichletBND:add(0, "c", "BottomBnd")
-- TopCorners
dirichletBND:add(0, "p", "TopCorners")
-- density
function DensityFct(c) return 1000 + 200 * c end
function DDensityFct_c(c) return 200 end
Density = LuaUserFunctionNumber("DensityFct", 1);
Density:set_deriv(0, "DDensityFct_c");
-- Darcy Velocity (as a linker)
DarcyVelocity = DarcyVelocityLinker();
DarcyVelocity:set_permeability(Permeability)
DarcyVelocity:set_viscosity(Viscosity)
DarcyVelocity:set_density(Density)
DarcyVelocity:set_gravity(Gravity)
-- flow equation
FlowEq = ConvectionDiffusionFV1("p", "Inner")
FlowEq:set_mass_scale(0.0)
FlowEq:set_flux(DarcyVelocity)
-- transport equation
TransportEq = ConvectionDiffusionFV1("c", "Inner")
TransportEq:set_upwind(UpwindFV1(upwind))
TransportEq:set_mass_scale(Porosity)
TransportEq:set_velocity(DarcyVelocity)
TransportEq:set_diffusion(Porosity * MolecularDiffusion)
-- associate the density with the unknown of the transport equation (i.e. c)
Density:set_input(0, TransportEq:value())
-- associate the Darcy velocity with the unknown of the flow equation (i.e. p)
DarcyVelocity:set_pressure_gradient(FlowEq:gradient())
-- set up the global discretization
domainDisc = DomainDiscretization(approxSpace)
domainDisc:add(TransportEq)
domainDisc:add(FlowEq)
domainDisc:add(dirichletBND)
--------------------------------------------------------------------------------
-- Set up the solver
--------------------------------------------------------------------------------
util.solver.defaults.approxSpace = approxSpace
solverDesc = {
type = "newton",
lineSearch = {
type = "standard",-- ["standard", "none"]
maxSteps = 8, -- maximum number of line search steps
lambdaStart = 1, -- start value for scaling parameter
lambdaReduce = 0.5, -- reduction factor for scaling parameter
acceptBest = true, -- check for best solution if true
checkAll = false -- check all maxSteps steps if true
},
convCheck = {
type = "standard",
iterations = 30, -- maximum number of iterations
absolute = 5e-6, -- absolut value of defect to be reached; usually 1e-7 - 1e-9
reduction = 1e-10, -- reduction factor of defect to be reached; usually 1e-6 - 1e-8
verbose = true -- print convergence rates if true
},
linSolver =
{
type = "bicgstab",
precond = {
type = "gmg", -- preconditioner ["gmg", "ilu", "ilut", "jac", "gs", "sgs"]
smoother = "ilu", -- pre- and postsmoother, only for gmg ["ilu", "ilut", "jac", "gs", "sgs"]
cycle = "V", -- gmg-cycle ["V", "F", "W"]
preSmooth = 2, -- number presmoothing steps
postSmooth = 2, -- number postsmoothing steps
rap = false, -- comutes RAP-product instead of assembling if true
baseLevel = numPreRefs,-- gmg - coarsest level
baseSolver = "lu",
},
convCheck = {
type = "standard",
iterations = 100, -- number of iterations
absolute = 1e-8, -- absolut value of defact to be reached; usually 1e-8 - 1e-10 (may not be larger than in newton section)
reduction = 1e-5, -- reduction factor of defect to be reached
verbose = true, -- print convergence rates if true
}
}
}
solver = util.solver.CreateSolver(solverDesc)
-----------------------------------------------------------------------------------------
-- Ploter for the results
------------------------------------------------------------------------------------------
out = VTKOutput()
out:clear_selection()
out:select_nodal("c", "c")
out:select_nodal("p", "p")
out:select(DarcyVelocity, "q")
------------------------------------------------------------------------------------------
-- Set up and apply the time stepping scheme
------------------------------------------------------------------------------------------
-- Set up the time discretization and the time stepping scheme
timeDisc = ThetaTimeStep(domainDisc, 1.0) -- Implicit Euler: 1.0
timeIntegrator = SimpleTimeIntegrator(timeDisc)
timeIntegrator:set_solver(solver)
timeIntegrator:attach_observer(VTKOutputObserver(vtk_file_name, out))
timeIntegrator:set_time_step(dt)
------------------------------------------------------------------------------------------
-- Prepare the initial guess for the pressure
------------------------------------------------------------------------------------------
-- grid function for the solution
u = GridFunction(approxSpace)
-- Set the initial condition
Interpolate("PressureStart", u, "p")
Interpolate(0, u, "c")
-- Fix the mass fraction and solve the linear problem for the pressure
fixer = DirichletBoundary()
domainDisc:add(fixer)
fixer:invert_subset_selection()
fixer:add("c", "")
solver:init(AssembledOperator(domainDisc))
solver:prepare(u)
-- apply the solver for the stationary pressure problem
if not solver:apply(u) then
print("===> THE PREPARATION PHASE FAILED! <===")
exit()
end
domainDisc:remove (fixer)
------------------------------------------------------------------------------------------
-- Compute the time steps
------------------------------------------------------------------------------------------
timeIntegrator:apply(u, endTime, u, 0.0)
------------------------------------------------------------------------------------------
-- End of File
------------------------------------------------------------------------------------------