-
Notifications
You must be signed in to change notification settings - Fork 58
/
solver_1.py
53 lines (47 loc) · 2.4 KB
/
solver_1.py
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
#!/usr/bin/env python
#!/bin/env python
'''
This script simply executes a solver, and ensures the expected number of iterations are performed.
An exception is thrown otherwise.
'''
import underworld as uw
from underworld import function as fn
res=32
mesh = uw.mesh.FeMesh_Cartesian("Q1/DQ0", (res,res), (0.,0.), (1.,1.))
velocityField = uw.mesh.MeshVariable(mesh,2)
velocityField.data[:] = (0.,0.)
pressureField = uw.mesh.MeshVariable(mesh.subMesh,1)
pressureField.data[:] = 0.
# freeslip
IWalls = mesh.specialSets["MinI_VertexSet"] + mesh.specialSets["MaxI_VertexSet"]
JWalls = mesh.specialSets["MinJ_VertexSet"] + mesh.specialSets["MaxJ_VertexSet"]
freeslip = uw.conditions.DirichletCondition(velocityField, (IWalls, JWalls))
# We are going to make use of one of the existing analytic solutions so that we may easily
# obtain functions for a viscosity profile and forcing terms.
# Exact solution solCx with defaults
sol = fn.analytic.SolCx(eta_B=100000.)
stokesSystem = uw.systems.Stokes(velocityField,pressureField,sol.fn_viscosity,sol.fn_bodyforce,conditions=[freeslip,])
#Run the BSSCR Solver
# can optionally set penalty this way
solver=uw.systems.Solver(stokesSystem)
solver.options.A11.ksp_converged_reason=''
#solver.options.mg.pc_mg_type="additive"
#solver.options.mg.pc_mg_type="full"
#solver.options.mg.pc_mg_type="kaskade"
#solver.options.mg.pc_mg_type="multiplicative"
solver.options.mg_accel.mg_accelerating_smoothing=0
solver.options.mg_accel.mg_accelerating_smoothing_view=1
#solver.options.main.penalty=1000.0
#solver.options.main.help=''
solver.solve()
stats=solver.get_stats()
solver.print_stats()
if stats.pressure_its > 5:
raise RuntimeError("Test appears to require too many pressure iterations. Iteration count = {}.".format(stats.pressure_its))
if stats.velocity_presolve_its > 8:
raise RuntimeError("Test appears to require too many velocity pre solve iterations. Iteration count = {}.".format(stats.velocity_presolve_its))
if -1 != stats.velocity_pressuresolve_its: # -1 will be returned if this stat isn't supported.
if stats.velocity_pressuresolve_its > 30 :
raise RuntimeError("Test appears to require too many velocity pressure solve iterations. Iteration count = {}.".format(stats.velocity_pressuresolve_its))
if stats.velocity_backsolve_its > 8:
raise RuntimeError("Test appears to require too many velocity back solve iterations. Iteration count = {}.".format(stats.velocity_backsolve_its))