@@ -30,7 +30,7 @@ def solve_problem(n, n_ref, u_init=None, maxiter=1000, gtol=1e-15, ftol=-np.inf
30
30
31
31
# x0 should be a grid point
32
32
33
- beta = 0.0
33
+ beta = 0.001
34
34
lb = Expression ("-1" , degree = 0 )
35
35
ub = Expression ("1+0.1*sin(2*pi*x[0])" , degree = 0 )
36
36
@@ -45,7 +45,12 @@ def solve_problem(n, n_ref, u_init=None, maxiter=1000, gtol=1e-15, ftol=-np.inf
45
45
46
46
if u_init != None :
47
47
u = project (u_init , U )
48
-
48
+ u_vec = u .vector ()[:]
49
+ lb_vec = project (lb , U ).vector ()[:]
50
+ ub_vec = project (ub , U ).vector ()[:]
51
+ u_vec = np .clip (u_vec , lb_vec , ub_vec )
52
+ u .vector ()[:] = u_vec
53
+
49
54
V = FunctionSpace (mesh , "CG" , 1 )
50
55
y = Function (V )
51
56
w = TrialFunction (V )
@@ -57,7 +62,7 @@ def solve_problem(n, n_ref, u_init=None, maxiter=1000, gtol=1e-15, ftol=-np.inf
57
62
L = u * v * dx
58
63
A , b = assemble_system (a , L , bc )
59
64
60
- solver = LUSolver (A , "petsc " )
65
+ solver = KrylovSolver (A , "cg " )
61
66
solver .solve (y .vector (), b )
62
67
63
68
J = assemble (0.5 * inner (y - yd ,y - yd )* dx )
@@ -84,7 +89,7 @@ def solve_problem(n, n_ref, u_init=None, maxiter=1000, gtol=1e-15, ftol=-np.inf
84
89
def test_convergence_rate ():
85
90
"""Code verification for a one-dimensional boundary value problem.
86
91
87
- abs( dual_gap(u_h) ) should converge with rate h^2
92
+ dual_gap(u_h) should converge with rate h^2
88
93
"""
89
94
90
95
n_ref = 2 ** 16
@@ -112,13 +117,14 @@ def test_convergence_rate():
112
117
113
118
ndrop = 0
114
119
x_vec = ns
115
- y_vec = np . abs ( dual_gaps )
120
+ y_vec = dual_gaps
116
121
X = np .ones ((len (x_vec [ndrop ::]), 2 )); X [:, 1 ] = np .log (x_vec [ndrop ::]) # design matrix
117
122
x , residudals , rank , s = np .linalg .lstsq (X , np .log (y_vec [ndrop ::]), rcond = None )
118
123
119
124
rate = x [1 ]
120
125
constant = np .exp (x [0 ])
121
-
126
+ assert np .isclose (- rate , 1.0 , rtol = 0.0 , atol = 0.1 )
127
+
122
128
fig , ax = plt .subplots ()
123
129
ax .plot ([n for n in ns ], dual_gaps )
124
130
@@ -132,7 +138,7 @@ def test_convergence_rate():
132
138
fig .savefig ("convergence_rates_bilinear.png" )
133
139
134
140
135
- assert np .isclose (np .median (rates ), 2 .0 , rtol = 0.0 , atol = 0.1 )
141
+ assert np .isclose (np .median (rates ), 1 .0 , rtol = 0.0 , atol = 0.1 )
136
142
137
143
if __name__ == "__main__" :
138
144
0 commit comments