-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path2_finite_elements.html
More file actions
611 lines (587 loc) · 48.4 KB
/
Copy path2_finite_elements.html
File metadata and controls
611 lines (587 loc) · 48.4 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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
<!DOCTYPE html>
<html lang="en" data-content_root="./">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<title>2. Constructing finite elements — Finite element course 2026.0 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=03e43079" />
<link rel="stylesheet" type="text/css" href="_static/fenics.css?v=7793b76c" />
<link rel="stylesheet" type="text/css" href="_static/proof.css" />
<link rel="stylesheet" type="text/css" href="_static/sphinx-design.min.css?v=95c83b7e" />
<script src="_static/documentation_options.js?v=9c5a5fc5"></script>
<script src="_static/doctools.js?v=9a2dae69"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/proof.js"></script>
<script src="_static/design-tabs.js?v=36754332"></script>
<script async="async" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="3. Meshes" href="3_meshes.html" />
<link rel="prev" title="1. Numerical quadrature" href="1_quadrature.html" />
<!--[if lte IE 6]>
<link rel="stylesheet" href="_static/ie6.css" type="text/css" media="screen" charset="utf-8" />
<![endif]-->
<link rel="stylesheet" href="_static/featured.css">
<link rel="shortcut icon" href="_static/icon.ico" />
</head><body>
<div class="wrapper">
<a href="index.html"><img src="_static/banner.svg" width="900px" alt="FInAT Project Banner" /></a>
<div id="access">
<div class="menu">
<ul>
<li class="page_item"><a href="https://github.com/finite-element/finite-element-course" title="GitHub">GitHub</a></li>
</ul>
</div><!-- .menu -->
</div><!-- #access -->
</div><!-- #wrapper -->
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="constructing-finite-elements">
<span id="secfinitelement"></span><h1><span class="section-number">2. </span>Constructing finite elements<a class="headerlink" href="#constructing-finite-elements" title="Link to this heading">¶</a></h1>
<details class="sd-sphinx-override sd-dropdown sd-card sd-mb-3">
<summary class="sd-summary-title sd-card-header">
<span class="sd-summary-text">A video recording of the following material is available here.</span><span class="sd-summary-state-marker sd-summary-chevron-right"><svg version="1.1" width="1.5em" height="1.5em" class="sd-octicon sd-octicon-chevron-right" viewBox="0 0 24 24" aria-hidden="true"><path d="M8.72 18.78a.75.75 0 0 1 0-1.06L14.44 12 8.72 6.28a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018l6.25 6.25a.75.75 0 0 1 0 1.06l-6.25 6.25a.75.75 0 0 1-1.06 0Z"></path></svg></span></summary><div class="sd-summary-content sd-card-body docutils">
<div class="vimeo docutils container">
<iframe src="https://player.vimeo.com/video/495194208"
frameborder="0" allow="autoplay; fullscreen"
allowfullscreen></iframe></div>
<p class="sd-card-text">Imperial students can also <a class="reference external" href="https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=2de78b50-5995-43b4-aef5-ac9f00e100b9">watch this video on Panopto</a></p>
</div>
</details><p>At the core of the finite element method is the representation of
finite-dimensional function spaces over elements. This concept was
formalised by <span id="id1">[<a class="reference internal" href="zbibliography.html#id4" title="Philippe G Ciarlet. The finite element method for elliptic problems. Elsevier, 2002. doi:10.1137/1.9780898719208.">Cia02</a>]</span>:</p>
<div class="proof proof-type-definition" id="id5">
<span id="def-ciarlet"></span>
<div class="proof-title">
<span class="proof-type">Definition 2.43</span>
</div><div class="proof-content">
<p>A <em>finite element</em> is a triple <span class="math notranslate nohighlight">\((K, P, N)\)</span> in which <span class="math notranslate nohighlight">\(K\)</span> is a cell,
<span class="math notranslate nohighlight">\(P\)</span> is a space of functions <span class="math notranslate nohighlight">\(K\rightarrow\mathbb{R}^n\)</span> and <span class="math notranslate nohighlight">\(N\)</span>, the
set of <em>nodes</em>, is a basis for <span class="math notranslate nohighlight">\(P^*\)</span>, the <a class="reference external" href="http://mathworld.wolfram.com/DualVectorSpace.html">dual space</a> to <span class="math notranslate nohighlight">\(P\)</span>.</p>
</div></div><p>Note that this definition includes a basis for <span class="math notranslate nohighlight">\(P^*\)</span>, but not a
basis for <span class="math notranslate nohighlight">\(P\)</span>. It turns out to be most convenient to specify the set
of nodes for an element, and then derive an appropriate basis for
<span class="math notranslate nohighlight">\(P\)</span> from that. In particular:</p>
<div class="proof proof-type-definition" id="id6">
<span id="nodalbasis"></span>
<div class="proof-title">
<span class="proof-type">Definition 2.44</span>
</div><div class="proof-content">
<p>Let <span class="math notranslate nohighlight">\(N = \{\phi^*_j\}\)</span> be a basis for <span class="math notranslate nohighlight">\(P^*\)</span>. A <em>nodal
basis</em>, <span class="math notranslate nohighlight">\(\{\phi_i\}\)</span> for <span class="math notranslate nohighlight">\(P\)</span> is a basis for <span class="math notranslate nohighlight">\(P\)</span>
with the property that <span class="math notranslate nohighlight">\(\phi^*_j(\phi_i) = \delta_{ij}\)</span>.</p>
</div></div><section id="a-worked-example">
<h2><span class="section-number">2.1. </span>A worked example<a class="headerlink" href="#a-worked-example" title="Link to this heading">¶</a></h2>
<details class="sd-sphinx-override sd-dropdown sd-card sd-mb-3">
<summary class="sd-summary-title sd-card-header">
<span class="sd-summary-text">A video recording of the following material is available here.</span><span class="sd-summary-state-marker sd-summary-chevron-right"><svg version="1.1" width="1.5em" height="1.5em" class="sd-octicon sd-octicon-chevron-right" viewBox="0 0 24 24" aria-hidden="true"><path d="M8.72 18.78a.75.75 0 0 1 0-1.06L14.44 12 8.72 6.28a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018l6.25 6.25a.75.75 0 0 1 0 1.06l-6.25 6.25a.75.75 0 0 1-1.06 0Z"></path></svg></span></summary><div class="sd-summary-content sd-card-body docutils">
<div class="vimeo docutils container">
<iframe src="https://player.vimeo.com/video/495194350"
frameborder="0" allow="autoplay; fullscreen"
allowfullscreen></iframe></div>
<p class="sd-card-text">Imperial students can also <a class="reference external" href="https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=7b99c0c7-a6df-4b3d-b574-ac9f00e0075c">watch this video on Panopto</a></p>
</div>
</details><p>To illustrate the construction of a nodal basis, let’s consider the
linear polynomials on a triangle. We first need to define our
reference cell. The obvious choice is the triangle with vertices
<span class="math notranslate nohighlight">\(\{(0,0), (1,0), (0,1)\}\)</span></p>
<p>Functions in this space have the form <span class="math notranslate nohighlight">\(a + bx + cy\)</span>. So the
function space has three unknown parameters, and its basis (and dual
basis) will therefore have three members. In order to ensure the correct
continuity between elements, the dual basis we need to use is the
evaluation of the function at each of the cell vertices. That is:</p>
<div class="math notranslate nohighlight" id="equation-2-finite-elements-0">
<span class="eqno">(2.1)<a class="headerlink" href="#equation-2-finite-elements-0" title="Link to this equation">¶</a></span>\[ \begin{align}\begin{aligned}\phi^*_0(f) = f\left((0,0)\right)\\\phi^*_1(f) = f\left((1,0)\right)\\\phi^*_2(f) = f\left((0,1)\right)\end{aligned}\end{align} \]</div>
<p>We know that <span class="math notranslate nohighlight">\(\phi_i((x,y))\)</span> has the form <span class="math notranslate nohighlight">\(a_i + b_ix + c_iy\)</span> so now we can
use the definition of the nodal basis to determine the unknown
coefficients:</p>
<div class="math notranslate nohighlight" id="equation-2-finite-elements-1">
<span class="eqno">(2.2)<a class="headerlink" href="#equation-2-finite-elements-1" title="Link to this equation">¶</a></span>\[\begin{split}\begin{pmatrix}
\phi^*_0(\phi_i)\\
\phi^*_1(\phi_i)\\
\phi^*_2(\phi_i)
\end{pmatrix}
=
\begin{pmatrix}
\delta_{i,0}\\
\delta_{i,1}\\
\delta_{i,2}
\end{pmatrix}\end{split}\]</div>
<p>So for <span class="math notranslate nohighlight">\(\phi_0\)</span> we have:</p>
<div class="math notranslate nohighlight" id="equation-phimat">
<span class="eqno">(2.3)<a class="headerlink" href="#equation-phimat" title="Link to this equation">¶</a></span>\[\begin{split}\begin{pmatrix}
\phi^*_0(\phi_0)\\
\phi^*_1(\phi_0)\\
\phi^*_2(\phi_0)
\end{pmatrix}
=
\begin{pmatrix}
\phi_0((0,0))\\
\phi_0((1,0))\\
\phi_0((0,1))\\
\end{pmatrix}
=
\begin{pmatrix}
a_0 + b_0(0) + c_0(0)\\
a_0 + b_0(1) + c_0(0)\\
a_0 + b_0(0) + c_0(1)\\
\end{pmatrix}
=
\begin{bmatrix}
1 & 0 & 0\\
1 & 1 & 0\\
1 & 0 & 1\\
\end{bmatrix}
\begin{bmatrix}
a_0\\
b_0\\
c_0\\
\end{bmatrix}
=
\begin{bmatrix}
1 \\
0 \\
0
\end{bmatrix}\end{split}\]</div>
<p>Which has solution <span class="math notranslate nohighlight">\(\phi_0 = 1 - x - y\)</span>. We can write the equations
for all the basis functions at once as a single matrix equation:</p>
<div class="math notranslate nohighlight" id="equation-phimat2">
<span class="eqno">(2.4)<a class="headerlink" href="#equation-phimat2" title="Link to this equation">¶</a></span>\[\begin{split}\begin{bmatrix}
1 & 0 & 0\\
1 & 1 & 0\\
1 & 0 & 1\\
\end{bmatrix}
\begin{bmatrix}
a_0 & a_1 & a_2\\
b_0 & b_1 & b_2\\
c_0 & c_1 & c_2\\
\end{bmatrix}
=
\begin{bmatrix}
1 & 0 & 0\\
0 & 1 & 0\\
0 & 0 & 1
\end{bmatrix}\end{split}\]</div>
<p>By which we establish that the full basis is given by:</p>
<div class="math notranslate nohighlight" id="equation-2-finite-elements-2">
<span class="eqno">(2.5)<a class="headerlink" href="#equation-2-finite-elements-2" title="Link to this equation">¶</a></span>\[ \begin{align}\begin{aligned}\phi_0 = 1 - x - y\\\phi_1 = x\\\phi_2 = y\end{aligned}\end{align} \]</div>
</section>
<section id="types-of-node">
<h2><span class="section-number">2.2. </span>Types of node<a class="headerlink" href="#types-of-node" title="Link to this heading">¶</a></h2>
<p>We have just encountered nodes given by the evaluation of the function
at a given point. Other forms of functional are also suitable for use
as finite element nodes. Examples include the integral of the function
over the cell or some sub-entity and the evaluation of the gradient
of the function at some point. For some vector-valued function spaces,
the nodes may be given by the evaluation of the components of the
function normal or tangent to the boundary of the cell at some point.</p>
<p>In this course we will only consider point evaluation nodes. The implementation of several other forms of node are covered in <span id="id2">[<a class="reference internal" href="zbibliography.html#id2" title="R.C. Kirby. Algorithm 839: fiat, a new paradigm for computing finite element basis functions. ACM Transactions on Mathematical Software (TOMS), 30(4):502–516, 2004. doi:10.1145/1039813.1039820.">Kir04</a>]</span>.</p>
</section>
<section id="the-lagrange-element-nodes">
<h2><span class="section-number">2.3. </span>The Lagrange element nodes<a class="headerlink" href="#the-lagrange-element-nodes" title="Link to this heading">¶</a></h2>
<p>The number of coefficients of a degree <span class="math notranslate nohighlight">\(p\)</span> polynomial in <span class="math notranslate nohighlight">\(d\)</span>
dimensions is given by the combination <span class="math notranslate nohighlight">\(\binom{p+d}{d}\)</span>. The
simplest set of nodes which we can employ is simply to place these
nodes in a regular grid over the reference cell. Given the classical
relationship between binomial coefficients and <a class="reference external" href="http://mathworld.wolfram.com/PascalsTriangle.html">Pascal’s triangle</a> (and between
trinomial coefficients and Pascal’s pyramid), it is unsurprising that
this produces the correct number of nodes.</p>
<p>The set of equally spaced points of degree <span class="math notranslate nohighlight">\(p\)</span> on the triangle is:</p>
<div class="math notranslate nohighlight" id="equation-lattice">
<span class="eqno">(2.6)<a class="headerlink" href="#equation-lattice" title="Link to this equation">¶</a></span>\[\left\{\left(\frac{i}{p}, \frac{j}{p}\right)\middle| 0 \leq i+j \leq p\right\}\]</div>
<p>The finite elements with this set of nodes are called the <em>equispaced
Lagrange</em> elements and are the most commonly used elements for
relatively low order computations.</p>
<p>While this is the simplest node ordering to construct, when we come to
build finite element spaces over a whole computational mesh in
<a class="reference internal" href="4_function_spaces.html#secfunctionspaces"><span class="std std-numref">Section 4</span></a>, it will be much more straightforward if the nodes
are numbered in topological order. That is to say, the lowest numbered nodes
are those associated with the vertices, followed by those associated with the
edges and finally, in two dimensions, those associated with the cell. For
reasons that will become apparent when we consider the continuity of finite
element spaces, the nodes associated with the edges need to be in edge
orientation order. That is to say, the node number increases as one moves along
the edge in the direction of the arrow. In two dimensions, the ordering of
nodes in the cell interior is arbitrary.</p>
<figure class="align-default" id="id7">
<span id="figlagrange-nodes"></span><a class="reference internal image-reference" href="_images/lagrange_nodes.svg"><img alt="_images/lagrange_nodes.svg" src="_images/lagrange_nodes.svg" style="width: 70%;" />
</a>
<figcaption>
<p><span class="caption-number">Fig. 2.1 </span><span class="caption-text">The numbering of nodes for the degree 1, 2, and 3 equispaced Lagrange
elements on triangles. Black nodes are associated with vertices, red nodes
with edges and blue nodes with the cell (face). Note that the numbering of
nodes on edges follows the numbering of the edges in
<a class="reference internal" href="1_quadrature.html#figreferenceentities"><span class="std std-numref">Fig. 1.5</span></a>.</span><a class="headerlink" href="#id7" title="Link to this image">¶</a></p>
</figcaption>
</figure>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>At higher order the equispaced Lagrange basis is poorly conditioned
and creates unwanted oscillations in the solutions. However for
this course Lagrange elements will be sufficient.</p>
</div>
<div class="proof proof-type-exercise" id="id8">
<span id="ex-lagrange-points"></span>
<div class="proof-title">
<span class="proof-type">Exercise 2.45</span>
</div><div class="proof-content">
<p>Implement
<a class="reference internal" href="fe_utils.html#fe_utils.finite_elements.lagrange_points" title="fe_utils.finite_elements.lagrange_points"><code class="xref py py-func docutils literal notranslate"><span class="pre">lagrange_points()</span></code></a>. Make sure your
algorithm also works for one-dimensional elements. Some basic tests
for your code are to be found in
<code class="docutils literal notranslate"><span class="pre">test/test_02_lagrange_points.py</span></code>. You can also test your lagrange
points on the triangle by running:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">plot_lagrange_points</span> <span class="n">degree</span>
</pre></div>
</div>
<p>Where <code class="xref py py-data docutils literal notranslate"><span class="pre">degree</span></code> is the degree of the points to plot.</p>
</div></div><div class="admonition note">
<p class="admonition-title">Note</p>
<p>It should not be necessary to special-case your code for different
dimensions of cell: the same code should produce the points on the interval
and the triangle.</p>
</div>
</section>
<section id="solving-for-basis-functions">
<span id="sec-vandermonde"></span><h2><span class="section-number">2.4. </span>Solving for basis functions<a class="headerlink" href="#solving-for-basis-functions" title="Link to this heading">¶</a></h2>
<details class="sd-sphinx-override sd-dropdown sd-card sd-mb-3">
<summary class="sd-summary-title sd-card-header">
<span class="sd-summary-text">A video recording of the following material is available here.</span><span class="sd-summary-state-marker sd-summary-chevron-right"><svg version="1.1" width="1.5em" height="1.5em" class="sd-octicon sd-octicon-chevron-right" viewBox="0 0 24 24" aria-hidden="true"><path d="M8.72 18.78a.75.75 0 0 1 0-1.06L14.44 12 8.72 6.28a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018l6.25 6.25a.75.75 0 0 1 0 1.06l-6.25 6.25a.75.75 0 0 1-1.06 0Z"></path></svg></span></summary><div class="sd-summary-content sd-card-body docutils">
<div class="vimeo docutils container">
<iframe src="https://player.vimeo.com/video/495194663"
frameborder="0" allow="autoplay; fullscreen"
allowfullscreen></iframe></div>
<p class="sd-card-text">Imperial students can also <a class="reference external" href="https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=0a419515-add2-4ea0-a39c-ac9f00e007ff">watch this video on Panopto</a></p>
</div>
</details><p>The matrix in <a class="reference internal" href="#equation-phimat">(2.3)</a> is a <em>generalised Vandermonde</em> <a class="footnote-reference brackets" href="#vandermonde" id="id3" role="doc-noteref"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></a>
matrix . Given a list of points <span class="math notranslate nohighlight">\((x_i,y_i) \in \mathbb{R}^2, 0\leq i< m\)</span>
the corresponding degree <span class="math notranslate nohighlight">\(n\)</span> generalised Vandermonde matrix is given by:</p>
<div class="math notranslate nohighlight" id="equation-vandermonde">
<span class="eqno">(2.7)<a class="headerlink" href="#equation-vandermonde" title="Link to this equation">¶</a></span>\[\begin{split}\mathrm{V} =
\begin{bmatrix}
1 & x_0 & y_0 & x_0^2 & x_0y_0 & y_0^2 & \ldots & x_0^n & x_0^{n-1}y_0 & \ldots & x_0y_0^{n-1} & y_0^n \\
1 & x_1 & y_1 & x_1^2 & x_1y_1 & y_1^2 & \ldots & x_1^n & x_1^{n-1}y_1 & \ldots & x_1y_1^{n-1} & y_1^n \\
\vdots \\
1 & x_m & y_m & x_m^2 & x_my_m & y_m^2 & \ldots & x_m^n & x_m^{n-1}y_m & \ldots & x_my_m^{n-1} & y_m^n \\
\end{bmatrix}\end{split}\]</div>
<p>If we construct the Vandermonde matrix for the nodes of a finite
element, then the equation for the complete set of basis function
polynomial coefficients is:</p>
<div class="math notranslate nohighlight" id="equation-vdm-equation">
<span class="eqno">(2.8)<a class="headerlink" href="#equation-vdm-equation" title="Link to this equation">¶</a></span>\[\mathrm{V}\mathrm{C} = \mathrm{I}\]</div>
<p>where the <span class="math notranslate nohighlight">\(j\)</span>-th column of <span class="math notranslate nohighlight">\(C\)</span> contains the polynomial coefficients of
the basis function corresponding to the <span class="math notranslate nohighlight">\(j\)</span>-th node. For
<a class="reference internal" href="#equation-vdm-equation">(2.8)</a> to be well-posed, there must be a number of nodes
equal to the number of coefficients of a degree <span class="math notranslate nohighlight">\(n\)</span> polynomial. If
this is the case, then it follows immediately that:</p>
<div class="math notranslate nohighlight" id="equation-coef-definition">
<span class="eqno">(2.9)<a class="headerlink" href="#equation-coef-definition" title="Link to this equation">¶</a></span>\[\mathrm{C} = \mathrm{V}^{-1}\]</div>
<p>The same process applies to the construction of basis functions for
elements in one or three dimensions, except that the Vandermonde
matrix must be modified to exclude powers of <span class="math notranslate nohighlight">\(y\)</span> (in one dimension) or
to include powers of <span class="math notranslate nohighlight">\(z\)</span>.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Here we employ a monomial basis to represent polynomial spaces: any
polynomial is given as a linear sum of monomials such as <span class="math notranslate nohighlight">\(x\)</span>, <span class="math notranslate nohighlight">\(xy\)</span>
or <span class="math notranslate nohighlight">\(x^2\)</span>. This basis becomes increasingly ill-conditioned at higher
order, so it may be advantageous to employ a different basis in the
construction of the Vandermonde matrix. See <span id="id4">[<a class="reference internal" href="zbibliography.html#id2" title="R.C. Kirby. Algorithm 839: fiat, a new paradigm for computing finite element basis functions. ACM Transactions on Mathematical Software (TOMS), 30(4):502–516, 2004. doi:10.1145/1039813.1039820.">Kir04</a>]</span> for an
example.</p>
</div>
<div class="proof proof-type-exercise" id="id9">
<span id="ex-vandermonde"></span>
<div class="proof-title">
<span class="proof-type">Exercise 2.46</span>
</div><div class="proof-content">
<p>Use <a class="reference internal" href="#equation-vandermonde">(2.7)</a> to implement
<a class="reference internal" href="fe_utils.html#fe_utils.finite_elements.vandermonde_matrix" title="fe_utils.finite_elements.vandermonde_matrix"><code class="xref py py-func docutils literal notranslate"><span class="pre">vandermonde_matrix()</span></code></a>. Think
carefully about how to loop over each row to construct the correct
powers of <span class="math notranslate nohighlight">\(x\)</span> and <span class="math notranslate nohighlight">\(y\)</span>. For the purposes of this exercise you should
ignore the <code class="docutils literal notranslate"><span class="pre">grad</span></code> argument.</p>
<p>Tests for this function are in <code class="docutils literal notranslate"><span class="pre">test/test_03_vandermonde_matrix.py</span></code></p>
</div></div><div class="admonition hint">
<p class="admonition-title">Hint</p>
<p>You can use numpy array operations to construct whole columns of
the matrix at once.</p>
</div>
</section>
<section id="implementing-finite-elements-in-python">
<h2><span class="section-number">2.5. </span>Implementing finite elements in Python<a class="headerlink" href="#implementing-finite-elements-in-python" title="Link to this heading">¶</a></h2>
<details class="sd-sphinx-override sd-dropdown sd-card sd-mb-3">
<summary class="sd-summary-title sd-card-header">
<span class="sd-summary-text">A video recording of the following material is available here.</span><span class="sd-summary-state-marker sd-summary-chevron-right"><svg version="1.1" width="1.5em" height="1.5em" class="sd-octicon sd-octicon-chevron-right" viewBox="0 0 24 24" aria-hidden="true"><path d="M8.72 18.78a.75.75 0 0 1 0-1.06L14.44 12 8.72 6.28a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018l6.25 6.25a.75.75 0 0 1 0 1.06l-6.25 6.25a.75.75 0 0 1-1.06 0Z"></path></svg></span></summary><div class="sd-summary-content sd-card-body docutils">
<div class="vimeo docutils container">
<iframe src="https://player.vimeo.com/video/495194889"
frameborder="0" allow="autoplay; fullscreen"
allowfullscreen></iframe></div>
<p class="sd-card-text">Imperial students can also <a class="reference external" href="https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=9e0ed94f-2a1f-4b7d-8be6-ac9f00e007ce">watch this video on Panopto</a></p>
</div>
</details><p>The <a class="reference internal" href="#def-ciarlet"><span class="std std-ref">Ciarlet triple</span></a> <span class="math notranslate nohighlight">\((K, P, N)\)</span> also provides a
good abstraction for the implementation of software objects
corresponding to finite elements. In our case <span class="math notranslate nohighlight">\(K\)</span> will be a
<a class="reference internal" href="fe_utils.html#fe_utils.reference_elements.ReferenceCell" title="fe_utils.reference_elements.ReferenceCell"><code class="xref py py-class docutils literal notranslate"><span class="pre">ReferenceCell</span></code></a>. In this course we
will only implement finite element spaces consisting of complete
polynomial spaces so we will specify <span class="math notranslate nohighlight">\(P\)</span> by providing the maximum
degree of the polynomials in the space. Since we will only deal with
point evaluation nodes, we can represent <span class="math notranslate nohighlight">\(N\)</span> by a series of points at
which the evaluation should occur.</p>
<div class="proof proof-type-exercise" id="id10">
<span id="ex-finite-element"></span>
<div class="proof-title">
<span class="proof-type">Exercise 2.47</span>
</div><div class="proof-content">
<p>Implement the rest of the
<a class="reference internal" href="fe_utils.html#fe_utils.finite_elements.FiniteElement" title="fe_utils.finite_elements.FiniteElement"><code class="xref py py-class docutils literal notranslate"><span class="pre">FiniteElement</span></code></a> <code class="xref py py-meth docutils literal notranslate"><span class="pre">__init__()</span></code>
method. You should construct a Vandermonde matrix for the nodes and
invert it to create the basis function coefs. Store these as
<code class="docutils literal notranslate"><span class="pre">self.basis_coefs</span></code>.</p>
<p>Some basic tests of your implementation are in
<code class="docutils literal notranslate"><span class="pre">test/test_04_init_finite_element.py</span></code>.</p>
</div></div><div class="admonition hint">
<p class="admonition-title">Hint</p>
<p>The <a class="reference external" href="https://numpy.org/doc/stable/reference/generated/numpy.linalg.inv.html#numpy.linalg.inv" title="(in NumPy v2.4)"><code class="xref py py-func docutils literal notranslate"><span class="pre">numpy.linalg.inv()</span></code></a> function may be
used to invert the matrix.</p>
</div>
</section>
<section id="implementing-the-lagrange-elements">
<h2><span class="section-number">2.6. </span>Implementing the Lagrange Elements<a class="headerlink" href="#implementing-the-lagrange-elements" title="Link to this heading">¶</a></h2>
<details class="sd-sphinx-override sd-dropdown sd-card sd-mb-3">
<summary class="sd-summary-title sd-card-header">
<span class="sd-summary-text">A video recording of the following material is available here.</span><span class="sd-summary-state-marker sd-summary-chevron-right"><svg version="1.1" width="1.5em" height="1.5em" class="sd-octicon sd-octicon-chevron-right" viewBox="0 0 24 24" aria-hidden="true"><path d="M8.72 18.78a.75.75 0 0 1 0-1.06L14.44 12 8.72 6.28a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018l6.25 6.25a.75.75 0 0 1 0 1.06l-6.25 6.25a.75.75 0 0 1-1.06 0Z"></path></svg></span></summary><div class="sd-summary-content sd-card-body docutils">
<div class="vimeo docutils container">
<iframe src="https://player.vimeo.com/video/495195941"
frameborder="0" allow="autoplay; fullscreen"
allowfullscreen></iframe></div>
<p class="sd-card-text">Imperial students can also <a class="reference external" href="https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=d78e85a7-fa59-433c-ac4c-ac9f00e02668">watch this video on Panopto</a></p>
</div>
</details><p>The <a class="reference internal" href="fe_utils.html#fe_utils.finite_elements.FiniteElement" title="fe_utils.finite_elements.FiniteElement"><code class="xref py py-class docutils literal notranslate"><span class="pre">FiniteElement</span></code></a> class implements
a general finite element object assuming we have provided the cell,
polynomial, degree and nodes. The
<a class="reference internal" href="fe_utils.html#fe_utils.finite_elements.LagrangeElement" title="fe_utils.finite_elements.LagrangeElement"><code class="xref py py-class docutils literal notranslate"><span class="pre">LagrangeElement</span></code></a> class is a
<a class="reference external" href="https://docs.python.org/3/tutorial/classes.html#inheritance">subclass</a> of
<a class="reference internal" href="fe_utils.html#fe_utils.finite_elements.FiniteElement" title="fe_utils.finite_elements.FiniteElement"><code class="xref py py-class docutils literal notranslate"><span class="pre">FiniteElement</span></code></a> which will implement
the particular case of the equispaced Lagrange elements.</p>
<div class="proof proof-type-exercise" id="id11">
<span id="ex-lagrange-element"></span>
<div class="proof-title">
<span class="proof-type">Exercise 2.48</span>
</div><div class="proof-content">
<p>Implement the <code class="xref py py-meth docutils literal notranslate"><span class="pre">__init__()</span></code> method of
<a class="reference internal" href="fe_utils.html#fe_utils.finite_elements.LagrangeElement" title="fe_utils.finite_elements.LagrangeElement"><code class="xref py py-class docutils literal notranslate"><span class="pre">LagrangeElement</span></code></a>. Use
<a class="reference internal" href="fe_utils.html#fe_utils.finite_elements.lagrange_points" title="fe_utils.finite_elements.lagrange_points"><code class="xref py py-func docutils literal notranslate"><span class="pre">lagrange_points()</span></code></a> to obtain the
nodes. For the purpose of this exercise, you may ignore the
<code class="docutils literal notranslate"><span class="pre">entity_nodes</span></code> argument.</p>
<p><strong>After</strong> you have implemented
<a class="reference internal" href="fe_utils.html#fe_utils.finite_elements.FiniteElement.tabulate" title="fe_utils.finite_elements.FiniteElement.tabulate"><code class="xref py py-meth docutils literal notranslate"><span class="pre">tabulate()</span></code></a> in the
next exercise, you can use
<code class="docutils literal notranslate"><span class="pre">plot_lagrange_basis_functions</span></code> to visualise your
Lagrange basis functions.</p>
</div></div></section>
<section id="tabulating-basis-functions">
<h2><span class="section-number">2.7. </span>Tabulating basis functions<a class="headerlink" href="#tabulating-basis-functions" title="Link to this heading">¶</a></h2>
<details class="sd-sphinx-override sd-dropdown sd-card sd-mb-3">
<summary class="sd-summary-title sd-card-header">
<span class="sd-summary-text">A video recording of the following material is available here.</span><span class="sd-summary-state-marker sd-summary-chevron-right"><svg version="1.1" width="1.5em" height="1.5em" class="sd-octicon sd-octicon-chevron-right" viewBox="0 0 24 24" aria-hidden="true"><path d="M8.72 18.78a.75.75 0 0 1 0-1.06L14.44 12 8.72 6.28a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018l6.25 6.25a.75.75 0 0 1 0 1.06l-6.25 6.25a.75.75 0 0 1-1.06 0Z"></path></svg></span></summary><div class="sd-summary-content sd-card-body docutils">
<div class="vimeo docutils container">
<iframe src="https://player.vimeo.com/video/495447930"
frameborder="0" allow="autoplay; fullscreen"
allowfullscreen></iframe></div>
<p class="sd-card-text">Imperial students can also <a class="reference external" href="https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=7126cc73-ff67-48a0-b84b-aca000b63478">watch this video on Panopto</a></p>
</div>
</details><p>A core operation in the finite element method is integrating
expressions involving functions in finite element spaces. This is
usually accomplished using <a class="reference internal" href="1_quadrature.html"><span class="doc">numerical quadrature</span></a>. This means that we need to be able to evaluate the
basis functions at a set of quadrature points. The operation of
evaluating a set of basis functions at a set of points is called
<em>tabulation</em>.</p>
<p>Recall that the coefficients of the basis functions are defined with
respect to the monomial basis in <a class="reference internal" href="#equation-coef-definition">(2.9)</a>. To tabulate
the basis functions at a particular set of points therefore requires
that the monomial basis be evaluated at that set of points. In other
words, the Vandermonde matrix needs to be evaluated at the quadrature
points. Suppose we have a set of points <span class="math notranslate nohighlight">\(\{X_i\}\)</span> and a set of basis
functions <span class="math notranslate nohighlight">\(\{\phi_j\}\)</span> with coefficents with respect to the monomial
basis given by the matrix <span class="math notranslate nohighlight">\(C\)</span>. Then the tabulation matrix is given by:</p>
<div class="math notranslate nohighlight" id="equation-2-finite-elements-3">
<span class="eqno">(2.10)<a class="headerlink" href="#equation-2-finite-elements-3" title="Link to this equation">¶</a></span>\[ T_{ij} = \phi_j(X_i) = \sum_b V(X_i)_b C_{bj} = (V(X_:) \cdot C)_{ij}\]</div>
<div class="proof proof-type-exercise" id="id12">
<span id="ex-tabulate"></span>
<div class="proof-title">
<span class="proof-type">Exercise 2.49</span>
</div><div class="proof-content">
<p>Implement <a class="reference internal" href="fe_utils.html#fe_utils.finite_elements.FiniteElement.tabulate" title="fe_utils.finite_elements.FiniteElement.tabulate"><code class="xref py py-meth docutils literal notranslate"><span class="pre">tabulate()</span></code></a>.
You can use a Vandermonde matrix to evaluate the polynomial terms
and take the matrix product of this with the basis function
coefficients. The method should have at most two executable
lines. For the purposes of this exercise, ignore the <code class="docutils literal notranslate"><span class="pre">grad</span></code>
argument.</p>
<p>The test file <code class="docutils literal notranslate"><span class="pre">test/test_05_tabulate.py</span></code> checks that tabulating the
nodes of a finite element produces the identity matrix.</p>
</div></div></section>
<section id="gradients-of-basis-functions">
<h2><span class="section-number">2.8. </span>Gradients of basis functions<a class="headerlink" href="#gradients-of-basis-functions" title="Link to this heading">¶</a></h2>
<details class="sd-sphinx-override sd-dropdown sd-card sd-mb-3">
<summary class="sd-summary-title sd-card-header">
<span class="sd-summary-text">A video recording of the following material is available here.</span><span class="sd-summary-state-marker sd-summary-chevron-right"><svg version="1.1" width="1.5em" height="1.5em" class="sd-octicon sd-octicon-chevron-right" viewBox="0 0 24 24" aria-hidden="true"><path d="M8.72 18.78a.75.75 0 0 1 0-1.06L14.44 12 8.72 6.28a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018l6.25 6.25a.75.75 0 0 1 0 1.06l-6.25 6.25a.75.75 0 0 1-1.06 0Z"></path></svg></span></summary><div class="sd-summary-content sd-card-body docutils">
<div class="vimeo docutils container">
<iframe src="https://player.vimeo.com/video/495196047"
frameborder="0" allow="autoplay; fullscreen"
allowfullscreen></iframe></div>
<p class="sd-card-text">Imperial students can also <a class="reference external" href="https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=45826405-6d18-45d9-a935-ac9f00e04883">watch this video on Panopto</a></p>
</div>
</details><p>A function <span class="math notranslate nohighlight">\(f\)</span> defined over a single finite element with basis
<span class="math notranslate nohighlight">\(\{\phi_i\}\)</span> is represented by a weighted sum of that basis:</p>
<div class="math notranslate nohighlight" id="equation-2-finite-elements-4">
<span class="eqno">(2.11)<a class="headerlink" href="#equation-2-finite-elements-4" title="Link to this equation">¶</a></span>\[f = \sum_i f_i\phi_i\]</div>
<p>In order to be able to represent and solve PDEs, we will naturally
also have terms incorporating derivatives. Since the coefficients
<span class="math notranslate nohighlight">\(f_i\)</span> are spatially constant, derivative operators pass through to
apply to the basis functions:</p>
<div class="math notranslate nohighlight" id="equation-2-finite-elements-5">
<span class="eqno">(2.12)<a class="headerlink" href="#equation-2-finite-elements-5" title="Link to this equation">¶</a></span>\[\nabla f = \sum_i f_i\nabla\phi_i\]</div>
<p>This means that we will need to be able to evaluate the gradient of
the basis functions at quadrature points. Recall once again that the
basis functions are evaluated by multiplying the Vandermonde matrix
evaluated at the relevant points by the matrix of basis function
coefficients. Hence:</p>
<div class="math notranslate nohighlight" id="equation-2-finite-elements-6">
<span class="eqno">(2.13)<a class="headerlink" href="#equation-2-finite-elements-6" title="Link to this equation">¶</a></span>\[ \nabla\phi(X) = \nabla\left( V(X) \cdot C \right) = \left(\nabla V(X)\right) \cdot C\]</div>
<p>The last step follows because <span class="math notranslate nohighlight">\(C\)</span> is not a function of <span class="math notranslate nohighlight">\(X\)</span>, so it passes
through <span class="math notranslate nohighlight">\(\nabla\)</span>. The effect of this is that evaluating the gradient
of a function in a finite element field just requires the evaluation
of the gradient of the Vandermonde matrix.</p>
<div class="proof proof-type-exercise" id="id13">
<div class="proof-title">
<span class="proof-type">Exercise 2.50</span>
</div><div class="proof-content">
<p>Extend <a class="reference internal" href="fe_utils.html#fe_utils.finite_elements.vandermonde_matrix" title="fe_utils.finite_elements.vandermonde_matrix"><code class="xref py py-meth docutils literal notranslate"><span class="pre">vandermonde_matrix()</span></code></a> so that
setting <code class="docutils literal notranslate"><span class="pre">grad</span></code> to <code class="docutils literal notranslate"><span class="pre">True</span></code> produces a rank 3 generalised
Vandermonde tensor whose indices represent points, monomial basis function,
and gradient component respectively. That is:</p>
<div class="math notranslate nohighlight" id="equation-2-finite-elements-7">
<span class="eqno">(2.14)<a class="headerlink" href="#equation-2-finite-elements-7" title="Link to this equation">¶</a></span>\[ \nabla V_{ijk} = \frac{\partial V_j(X_i)}{\partial x_k}\]</div>
<p>In other words, each entry of
<span class="math notranslate nohighlight">\(V\)</span> is replaced by a vector of the gradient of that polynomial
term. For example, the entry <span class="math notranslate nohighlight">\(x^2y^3\)</span> would be replaced by the
vector <span class="math notranslate nohighlight">\([ 2xy^3, 3x^2y^2 ]\)</span>.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">test/test_06_vandermonde_matrix_grad.py</span></code> file has tests of this
extension. You should also ensure that you still pass
<code class="docutils literal notranslate"><span class="pre">test/test_03_vandermonde_matrix.py</span></code>.</p>
</div></div><div class="admonition hint">
<p class="admonition-title">Hint</p>
<p>The <a class="reference external" href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.transpose.html#numpy.ndarray.transpose" title="(in NumPy v2.4)"><code class="xref py py-meth docutils literal notranslate"><span class="pre">transpose()</span></code></a> method of numpy arrays enables
generalised transposes swapping any dimensions.</p>
</div>
<div class="admonition hint">
<p class="admonition-title">Hint</p>
<p>At least one of the natural ways of implementing this function
results in a whole load of <code class="xref py py-data docutils literal notranslate"><span class="pre">nan</span></code> values in the generalised
Vandermonde matrix. In this case, you might find
<a class="reference external" href="https://numpy.org/doc/stable/reference/generated/numpy.nan_to_num.html#numpy.nan_to_num" title="(in NumPy v2.4)"><code class="xref py py-func docutils literal notranslate"><span class="pre">numpy.nan_to_num()</span></code></a> useful.</p>
</div>
<div class="proof proof-type-exercise" id="id14">
<div class="proof-title">
<span class="proof-type">Exercise 2.51</span>
</div><div class="proof-content">
<p>Extend <a class="reference internal" href="fe_utils.html#fe_utils.finite_elements.FiniteElement.tabulate" title="fe_utils.finite_elements.FiniteElement.tabulate"><code class="xref py py-meth docutils literal notranslate"><span class="pre">tabulate()</span></code></a> to
pass the <code class="docutils literal notranslate"><span class="pre">grad</span></code> argument through to
<a class="reference internal" href="fe_utils.html#fe_utils.finite_elements.vandermonde_matrix" title="fe_utils.finite_elements.vandermonde_matrix"><code class="xref py py-meth docutils literal notranslate"><span class="pre">vandermonde_matrix()</span></code></a>. Then
generalise the matrix product in
<a class="reference internal" href="fe_utils.html#fe_utils.finite_elements.FiniteElement.tabulate" title="fe_utils.finite_elements.FiniteElement.tabulate"><code class="xref py py-meth docutils literal notranslate"><span class="pre">tabulate()</span></code></a> so that
the result of this function (when <code class="docutils literal notranslate"><span class="pre">grad</span></code> is true) is a rank 3
tensor:</p>
<div class="math notranslate nohighlight" id="equation-2-finite-elements-8">
<span class="eqno">(2.15)<a class="headerlink" href="#equation-2-finite-elements-8" title="Link to this equation">¶</a></span>\[\mathrm{T}_{ijk} = \nabla(\phi_j(X_i))\cdot \mathbf{e}_k\]</div>
<p>where <span class="math notranslate nohighlight">\(\mathbf{e}_0\ldots\mathbf{e}_{\dim -1}\)</span> is the coordinate
basis on the reference cell.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">test/test_07_tabulate_grad.py</span></code> script tests this
extension. Once again, make sure you still pass
<code class="docutils literal notranslate"><span class="pre">test/test_05_tabulate.py</span></code></p>
</div></div><details class="sd-sphinx-override sd-dropdown sd-card sd-mb-3">
<summary class="sd-summary-title sd-card-header">
<span class="sd-summary-text">A video recording about this exercise is available here.</span><span class="sd-summary-state-marker sd-summary-chevron-right"><svg version="1.1" width="1.5em" height="1.5em" class="sd-octicon sd-octicon-chevron-right" viewBox="0 0 24 24" aria-hidden="true"><path d="M8.72 18.78a.75.75 0 0 1 0-1.06L14.44 12 8.72 6.28a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018l6.25 6.25a.75.75 0 0 1 0 1.06l-6.25 6.25a.75.75 0 0 1-1.06 0Z"></path></svg></span></summary><div class="sd-summary-content sd-card-body docutils">
<div class="vimeo docutils container">
<iframe src="https://player.vimeo.com/video/495196228"
frameborder="0" allow="autoplay; fullscreen"
allowfullscreen></iframe></div>
<p class="sd-card-text">Imperial students can also <a class="reference external" href="https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=5666bc7b-db54-4acd-a711-ac9f00e064c1">watch this video on Panopto</a></p>
</div>
</details><div class="admonition hint">
<p class="admonition-title">Hint</p>
<p>The <a class="reference external" href="https://numpy.org/doc/stable/reference/generated/numpy.einsum.html#numpy.einsum" title="(in NumPy v2.4)"><code class="xref py py-func docutils literal notranslate"><span class="pre">numpy.einsum()</span></code></a> function implements generalised tensor
contractions using <a class="reference external" href="http://mathworld.wolfram.com/EinsteinSummation.html">Einstein summation notation</a>. For
example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">A</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">einsum</span><span class="p">(</span><span class="s2">"ijk,jl->ilk"</span><span class="p">,</span> <span class="n">T</span><span class="p">,</span> <span class="n">C</span><span class="p">)</span>
</pre></div>
</div>
<p>is equivalent to <span class="math notranslate nohighlight">\(A_{ilk} = \sum_j T_{ijk} C_{jl}\)</span>.</p>
</div>
</section>
<section id="interpolating-functions-to-the-finite-element-nodes">
<h2><span class="section-number">2.9. </span>Interpolating functions to the finite element nodes<a class="headerlink" href="#interpolating-functions-to-the-finite-element-nodes" title="Link to this heading">¶</a></h2>
<details class="sd-sphinx-override sd-dropdown sd-card sd-mb-3">
<summary class="sd-summary-title sd-card-header">
<span class="sd-summary-text">A video recording of the following material is available here.</span><span class="sd-summary-state-marker sd-summary-chevron-right"><svg version="1.1" width="1.5em" height="1.5em" class="sd-octicon sd-octicon-chevron-right" viewBox="0 0 24 24" aria-hidden="true"><path d="M8.72 18.78a.75.75 0 0 1 0-1.06L14.44 12 8.72 6.28a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018l6.25 6.25a.75.75 0 0 1 0 1.06l-6.25 6.25a.75.75 0 0 1-1.06 0Z"></path></svg></span></summary><div class="sd-summary-content sd-card-body docutils">
<div class="vimeo docutils container">
<iframe src="https://player.vimeo.com/video/495445487"
frameborder="0" allow="autoplay; fullscreen"
allowfullscreen></iframe></div>
<p class="sd-card-text">Imperial students can also <a class="reference external" href="https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=6f7d5b2f-4995-4cd2-9d38-ac9f00e0a666">watch this video on Panopto</a></p>
</div>
</details><p>Recall once again that a function can be represented on a single finite element as:</p>
<div class="math notranslate nohighlight" id="equation-2-finite-elements-9">
<span class="eqno">(2.16)<a class="headerlink" href="#equation-2-finite-elements-9" title="Link to this equation">¶</a></span>\[f = \sum_i f_i\phi_i\]</div>
<p>Since <span class="math notranslate nohighlight">\(\{\phi_i\}\)</span> is a nodal basis, it follows immediately that:</p>
<div class="math notranslate nohighlight" id="equation-2-finite-elements-10">
<span class="eqno">(2.17)<a class="headerlink" href="#equation-2-finite-elements-10" title="Link to this equation">¶</a></span>\[f_i = \phi_i^*(f)\]</div>
<p>where <span class="math notranslate nohighlight">\(\phi_i^*\)</span> is the node associated with the basis function
<span class="math notranslate nohighlight">\(\phi_i\)</span>. Since we are only interested in nodes which are the point
evaluation of their function input, we know that:</p>
<div class="math notranslate nohighlight" id="equation-2-finite-elements-11">
<span class="eqno">(2.18)<a class="headerlink" href="#equation-2-finite-elements-11" title="Link to this equation">¶</a></span>\[f_i = f(X_i)\]</div>
<p>where <span class="math notranslate nohighlight">\(X_i\)</span> is the point associated with the <span class="math notranslate nohighlight">\(i\)</span>-th node.</p>
<div class="proof proof-type-exercise" id="id15">
<span id="ex-interpolate"></span>
<div class="proof-title">
<span class="proof-type">Exercise 2.52</span>
</div><div class="proof-content">
<p>Implement <a class="reference internal" href="fe_utils.html#fe_utils.finite_elements.FiniteElement.interpolate" title="fe_utils.finite_elements.FiniteElement.interpolate"><code class="xref py py-meth docutils literal notranslate"><span class="pre">interpolate()</span></code></a>.</p>
</div></div><p>Once you have done this, you can use the script provided to plot
functions of your choice interpolated onto any of the finite
elements you can make:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">plot_interpolate_lagrange</span> <span class="s2">"sin(2*pi*x[0])"</span> <span class="mi">2</span> <span class="mi">5</span>
</pre></div>
</div>
<div class="admonition hint">
<p class="admonition-title">Hint</p>
<p>You can find help on the arguments to this function with:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">plot_interpolate_lagrange</span> <span class="o">-</span><span class="n">h</span>
</pre></div>
</div>
</div>
<p class="rubric">Footnotes</p>
<aside class="footnote-list brackets">
<aside class="footnote brackets" id="vandermonde" role="doc-footnote">
<span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#id3">1</a><span class="fn-bracket">]</span></span>
<p>A <a class="reference external" href="http://mathworld.wolfram.com/VandermondeMatrix.html">Vandermonde
matrix</a>
is the one-dimensional case of the generalised Vandermonde matrix.</p>
</aside>
</aside>
</section>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer" role="contentinfo">
© Copyright 2014-2026, David A. Ham and Colin J. Cotter.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.4.7.
</div>
</body>
</html>