Skip to content

Commit 145c262

Browse files
committed
Make annulus kernel model more breakable
1 parent 728d7a2 commit 145c262

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

Jupyterbook/Notebooks/Examples-Stokes_Kernels/Ex_Stokes_Annulus_Kernels.py

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# extension: .py
66
# format_name: light
77
# format_version: '1.5'
8-
# jupytext_version: 1.16.0
8+
# jupytext_version: 1.16.4
99
# kernelspec:
1010
# display_name: Python 3 (ipykernel)
1111
# language: python
@@ -44,8 +44,8 @@
4444

4545
res = 0.05
4646
r_o = 1.0
47-
r_int = 0.8
48-
r_i = 0.5
47+
r_int = 0.2
48+
r_i = 0.1
4949

5050
free_slip_upper = True
5151
free_slip_lower = True
@@ -71,6 +71,8 @@
7171
filename="tmp_fixedstarsMesh.msh")
7272

7373

74+
meshball.view()
75+
7476
# +
7577
norm_v = uw.discretisation.MeshVariable("N", meshball, 2, degree=1, varsymbol=r"{\hat{n}}")
7678

@@ -125,8 +127,9 @@
125127

126128
stokes.constitutive_model = uw.constitutive_models.ViscousFlowModel
127129
stokes.constitutive_model.Parameters.viscosity = 1.0
128-
stokes.penalty = 0.0
129-
stokes.saddle_preconditioner = sympy.simplify(1 / (stokes.constitutive_model.viscosity + stokes.penalty))
130+
stokes.penalty = 1.0
131+
132+
stokes.tolerance = 1.0e-6
130133

131134
stokes.petsc_options.setValue("ksp_monitor", None)
132135
stokes.petsc_options.setValue("snes_monitor", None)
@@ -165,7 +168,7 @@
165168
I0.fn = v_theta_fn_xy.dot(v_theta_fn_xy)
166169
vnorm = I0.evaluate()
167170

168-
print(norm/vnorm, vnorm)
171+
# print(norm/vnorm, vnorm)
169172

170173
with meshball.access(v_soln):
171174
dv = uw.function.evaluate(norm * v_theta_fn_xy, v_soln.coords) / vnorm
@@ -178,7 +181,7 @@
178181

179182
pressure_solver = uw.systems.Projection(meshball, p_cont)
180183
pressure_solver.uw_function = p_soln.sym[0]
181-
pressure_solver.smoothing = 1.0e-3
184+
pressure_solver.smoothing = 1.0e-6
182185

183186
# +
184187
## Now solve with normals from nodal projection
@@ -187,7 +190,7 @@
187190

188191
stokes.bodyforce = sympy.Matrix([0,0])
189192
Gamma = meshball.Gamma / sympy.sqrt(meshball.Gamma.dot(meshball.Gamma))
190-
Gamma = norm_v.sym
193+
# Gamma = norm_v.sym
191194

192195
stokes.add_natural_bc(-t_init * unit_rvec, "Internal")
193196

@@ -201,7 +204,7 @@
201204
else:
202205
stokes.add_essential_bc((0.0,0.0), "Lower")
203206

204-
stokes.solve(zero_init_guess=False)
207+
stokes.solve(zero_init_guess=True)
205208

206209
# +
207210
# Null space evaluation
@@ -213,19 +216,27 @@
213216
dv = uw.function.evaluate(norm * v_theta_fn_xy, v_soln.coords) / vnorm
214217
v_soln.data[...] -= dv
215218

216-
print(norm/vnorm, vnorm)
219+
# print(norm/vnorm, vnorm)
217220
# -9.662093930530614e-09 0.024291704747453444
218221

219222
norm = I0.evaluate()
220223
# -
221224

222225
I0 = uw.maths.Integral(meshball, v_theta_fn_xy.dot(v_soln.sym))
223226
norm = I0.evaluate()
224-
print(norm/vnorm)
225227

228+
# +
226229
# Pressure at mesh nodes
227230
pressure_solver.solve()
228231

232+
pstats1 = p_cont.stats()
233+
pstats0 = p_soln.stats()
234+
235+
if uw.mpi.rank == 0:
236+
print(f"Pressure (C1): {pstats1}")
237+
print(f"Pressure (C0): {pstats0}")
238+
print(f"Velocity: {vnorm}")
239+
229240
# +
230241
# check the mesh if in a notebook / serial
231242

@@ -270,21 +281,25 @@
270281
pvmesh,
271282
cmap="coolwarm",
272283
edge_color="Grey",
273-
scalars="Vmag",
284+
scalars="P",
274285
show_edges=True,
275286
use_transparency=False,
276287
opacity=1.0,
277288
show_scalar_bar=True
278289
)
279290

280-
pl.add_arrows(velocity_points.points, velocity_points.point_data["V"], mag=3)
281-
pl.add_arrows(velocity_points.points, velocity_points.point_data["V0"], mag=3, color="Black")
291+
pl.add_arrows(velocity_points.points, velocity_points.point_data["V"], mag=4)
292+
pl.add_arrows(velocity_points.points, velocity_points.point_data["V0"], mag=4, color="Black")
282293
# pl.add_arrows(velocity_points.points, velocity_points.point_data["dV"], mag=100, color="Black")
283294
pl.add_mesh(pvstream, opacity=0.3, show_scalar_bar=False)
284295

285296

286297
pl.show(cpos="xy")
298+
299+
vsol_rms = np.sqrt(velocity_points.point_data["V"][:, 0] ** 2 + velocity_points.point_data["V"][:, 1] ** 2).mean()
300+
print(vsol_rms)
287301
# -
288302

289-
vsol_rms = np.sqrt(velocity_points.point_data["V"][:, 0] ** 2 + velocity_points.point_data["V"][:, 1] ** 2).mean()
290-
vsol_rms
303+
304+
305+

0 commit comments

Comments
 (0)