Skip to content

Commit cada87e

Browse files
committed
modify rhs of sheet1 exercise 1.3 (prev. exercise 2.2)
1 parent 31a2c12 commit cada87e

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

exercises/poisson_2d_I.ipynb

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"\\end{align*}\n",
2222
"for the specific choice\n",
2323
"\\begin{align*}\n",
24-
" f(x, y) = 8\\pi^2\\sin(2\\pi x)\\sin(2\\pi y)\n",
24+
" f(x, y) = [ (-x^4 + x^3 + (-y^2 + \\pi^2)x^2 + (y^2 - 4y - \\pi^2)x + 2y - 2) \\sin(\\pi y) + (2\\pi x^2(1-x)) \\cos(\\pi y)] e^{xy}\n",
2525
"\\end{align*}\n",
2626
"\n",
2727
"## The Variational Formulation\n",
@@ -63,12 +63,12 @@
6363
"phi, psi = elements_of(V, names='phi, psi')\n",
6464
"\n",
6565
"# bilinear form\n",
66-
"a = BilinearForm((phi, psi), integral(domain, dot(grad(phi), grad(psi))))\n",
66+
"a = BilinearForm((phi, psi), integral(domain, phi*psi))\n",
6767
"\n",
6868
"# linear form\n",
69-
"from sympy import pi, sin\n",
69+
"from sympy import pi, sin, cos, exp\n",
7070
"x,y = domain.coordinates\n",
71-
"f = 8 * (pi**2) * sin(2 * pi * x) * sin(2 * pi * y)\n",
71+
"f = ( (-x**4 + x**3 + (-y**2 + pi**2)*x**2 + (y**2 - 4*y - pi**2)*x + 2*y - 2) * sin(pi*y) + (2*pi*x**2*(1-x)) * cos(pi*y) ) * exp(x*y)\n",
7272
"\n",
7373
"l = LinearForm(psi, integral(domain, f*psi))"
7474
]
@@ -167,12 +167,18 @@
167167
"metadata": {},
168168
"outputs": [],
169169
"source": [
170-
"from psydac.linalg.solvers import inverse\n",
170+
"import time\n",
171+
"\n",
172+
"from psydac.linalg.solvers import inverse\n",
171173
"\n",
172174
"tol = 1e-12\n",
173175
"maxiter = 1000\n",
174176
"\n",
175-
"phi_h = inverse(A_bc, 'cg', tol=tol, maxiter=maxiter) @ f_bc"
177+
"A_bc_inv = inverse(A_bc, 'cg', tol=tol, maxiter=maxiter)\n",
178+
"\n",
179+
"t0 = time.time()\n",
180+
"phi_h = A_bc_inv @ f_bc\n",
181+
"t1 = time.time()"
176182
]
177183
},
178184
{
@@ -186,7 +192,7 @@
186192
"In this example, the analytical solution is given by\n",
187193
"\n",
188194
"$$\n",
189-
"phi_{ex}(x, y) = \\sin(2\\pi x)\\sin(2\\pi y)\n",
195+
"phi_{ex}(x, y) = x(x-1)\\sin(\\pi y)e^{xy}\n",
190196
"$$"
191197
]
192198
},
@@ -207,7 +213,7 @@
207213
"\n",
208214
"from sympde.expr import Norm, SemiNorm\n",
209215
"\n",
210-
"phi_ex = sin(2*pi*x) * sin(2*pi*y)\n",
216+
"phi_ex = x*(x-1)*sin(pi*y)*exp(x*y)\n",
211217
"phi_h_FemField = FemField(V_h, phi_h)\n",
212218
"\n",
213219
"error = phi_ex - phi\n",
@@ -219,10 +225,7 @@
219225
"l2norm_h = discretize(l2norm, domain_h, V_h, backend=backend)\n",
220226
"\n",
221227
"# assemble the norm\n",
222-
"l2_error = l2norm_h.assemble(phi=phi_h_FemField)\n",
223-
"\n",
224-
"# print the result\n",
225-
"print(l2_error)"
228+
"l2_error = l2norm_h.assemble(phi=phi_h_FemField)"
226229
]
227230
},
228231
{
@@ -245,10 +248,7 @@
245248
"h1norm_h = discretize(h1norm, domain_h, V_h)\n",
246249
"\n",
247250
"# assemble the norm\n",
248-
"h1_error = h1norm_h.assemble(phi=phi_h_FemField)\n",
249-
"\n",
250-
"# print the result\n",
251-
"print(h1_error)"
251+
"h1semi_error = h1norm_h.assemble(phi=phi_h_FemField)"
252252
]
253253
},
254254
{
@@ -274,7 +274,14 @@
274274
"h1_error = h1norm_h.assemble(phi=phi_h_FemField)\n",
275275
"\n",
276276
"# print the result\n",
277-
"print(h1_error)"
277+
"print( '> Grid :: [{ne1},{ne2}]'.format( ne1=ncells[0], ne2=ncells[1]) )\n",
278+
"print( '> Degree :: [{p1},{p2}]' .format( p1=degree[0], p2=degree[1] ) )\n",
279+
"print( '> CG info :: ',A_bc_inv.get_info() )\n",
280+
"print( '> L2 error :: {:.2e}'.format( l2_error ) )\n",
281+
"print( '> H1-Semi error :: {:.2e}'.format( h1semi_error ) )\n",
282+
"print( '> H1 error :: {:.2e}'.format( h1_error ) )\n",
283+
"print( '' )\n",
284+
"print( '> Solution time :: {:.3g}'.format( t1-t0 ) )"
278285
]
279286
},
280287
{

0 commit comments

Comments
 (0)