-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathimplementation.html
More file actions
350 lines (338 loc) · 22.4 KB
/
implementation.html
File metadata and controls
350 lines (338 loc) · 22.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
<!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>The implementation exercise — 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>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="1. Numerical quadrature" href="1_quadrature.html" />
<link rel="prev" title="Software tools" href="tools.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="the-implementation-exercise">
<h1>The implementation exercise<a class="headerlink" href="#the-implementation-exercise" title="Link to this heading">¶</a></h1>
<p>The object of the implementation exercise is to gain an understanding
of the finite element method by producing a working one and two
dimensional finite element solver library. Along the way you will have
the opportunity to pick up valuable scientific computing skills in
coding, software engineering and rigorous testing.</p>
<p>This part of the module is very practical, and there are never conventional
lectures for it, even when everything is taught on campus. Each week you should
work through the notes and videos until you come to an exercise. Each exercise
will invite you to implement another part of a finite element implementation, so
that by the end of the term we will be solving finite element problems.</p>
<p>Along the way, there will be the opportunity to get help and feedback through
the module Ed board, weekly online labs, and through pull requests for
feedback in weeks 4 and 7.</p>
<section id="formalities-and-marking-scheme">
<h2>Formalities and marking scheme<a class="headerlink" href="#formalities-and-marking-scheme" title="Link to this heading">¶</a></h2>
<p>The implementation exercise is due at 1300 on Monday 24 March 2025. Submission
is via GitHub: the last commit pushed to GitHub and dated before the deadline
will be marked.</p>
<p>The marking scheme will be as follows:</p>
<dl class="simple">
<dt>First/distinction (70-100)</dt><dd><p>All parts of the implementation are correct and all tests pass. The
code style is always very clear and the implementation of every
exercise is transparent and elegant.</p>
</dd>
<dt>Upper second/merit (60-70)</dt><dd><p>The implementation is correct but let down somewhat by poor coding
style. Alternatively, submissions which are correct and well
written up to and including solving the Helmholtz problem but
which do not include a correct solution to boundary conditions will
earn an upper second.</p>
</dd>
<dt>Lower second/pass (50-60)</dt><dd><p>There are significant failings in the implementation resulting in
many test failures, and/or the coding style is
sufficiently poor that the code is hard to understand.</p>
</dd>
<dt>Fail (0-50)</dt><dd><p>The implementation is substantially incomplete. Correct
implementations may have been provided for some of the earlier exercises but
the more advanced parts of the implementation exercise have not been
attempted or do not work.</p>
</dd>
</dl>
<p>Code execution performance is not a primary concern of this module, however the
code must still be algorithmically correct. This means not just returning the
correct answer but also having the correct algorithmic complexity. Occasionally
students submit code that uses quadratic algorithms where linear ones would be
possible. The result is that examples that should run in seconds and take
megabytes of memory instead take gigabytes of memory and many hours to complete.
Such submissions are incorrect, and will be marked as such.</p>
</section>
<section id="extension-mastery-exercise">
<h2>Extension (mastery) exercise<a class="headerlink" href="#extension-mastery-exercise" title="Link to this heading">¶</a></h2>
<p>Fourth year and masters students must also complete the mastery
exercise, which is <a class="reference internal" href="9_mixed_problems.html#mixed"><span class="std std-numref">Section 9</span></a> This will be
worth 20% of the implementation exercise marks and will be marked on
the same scheme as above.</p>
</section>
<section id="obtaining-the-skeleton-code">
<h2>Obtaining the skeleton code<a class="headerlink" href="#obtaining-the-skeleton-code" 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/495157536"
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=c92e73b4-b383-4412-b5f9-ac9f00b08789">watch this video on Panopto</a></p>
</div>
</details><p>This section assumes you’ve already done everything to <a class="reference internal" href="tools.html"><span class="doc">set up the software
tools you need</span></a>.</p>
<section id="set-up-a-folder-to-hold-the-repository-and-virtual-environment">
<h3>Set up a folder to hold the repository and virtual environment<a class="headerlink" href="#set-up-a-folder-to-hold-the-repository-and-virtual-environment" title="Link to this heading">¶</a></h3>
<p>You can call this folder anything you like, and store it anywhere that suits
you, though don’t move it once you’ve created it as this will break the virtual
environment. Suppose you would like to keep the new folder in a folder called
<code class="file docutils literal notranslate"><span class="pre">docs</span></code> in your home directory. We first <a class="reference external" href="https://imperial-fons-computing.github.io/terminal.html" title="(in Installation instructions for FoNS v2020.0)"><span class="xref std std-doc">open a
terminal</span></a> and switch to the folder:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span><span class="nb">cd</span><span class="w"> </span>docs
</pre></div>
</div>
<p>Note that <cite>$</cite> is the command prompt (which might be a different character such
as <cite>%</cite> or <cite>></cite> for you). You don’t type the prompt. Start with <cite>cd</cite>. Next we
create the folder we’ll use for this course. Suppose we choose to call it
<code class="file docutils literal notranslate"><span class="pre">finite-element</span></code>, then we would type:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>mkdir<span class="w"> </span>finite-element
</pre></div>
</div>
<p><cite>mkdir</cite> stands for “make directory”. <em>Directory</em> is an alternative term to
<em>folder</em>. Finally we switch (“change directory”) into that folder:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span><span class="nb">cd</span><span class="w"> </span>finite-element
</pre></div>
</div>
</section>
<section id="setting-up-your-venv">
<h3>Setting up your venv<a class="headerlink" href="#setting-up-your-venv" title="Link to this heading">¶</a></h3>
<p>We’re going to use a Python venv. This is a private Python environment
in which we’ll install the packages we need, including our own
implementation exercise. This minimises interference between this
project and anything else which might be using Python on the
system. With your current working folder set to the course folder, run:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>python3<span class="w"> </span>-m<span class="w"> </span>venv<span class="w"> </span>fe_venv
</pre></div>
</div>
<p>If your Python interpreter has a different name (e.g. <cite>python3.11</cite> or <cite>py</cite>)
then you type that instead.</p>
</section>
<section id="activating-your-venv">
<h3>Activating your venv<a class="headerlink" href="#activating-your-venv" title="Link to this heading">¶</a></h3>
<p><strong>Every time</strong> you want to work on the implementation exercise, you need
to activate the venv. On Linux or Mac do this with:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span><span class="nb">source</span><span class="w"> </span>fe_venv/bin/activate
</pre></div>
</div>
<p>while on Windows the command is:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="go">> source fe_venv/Scripts/activate</span>
</pre></div>
</div>
<p>Obviously if you are typing this in a directory other than the one
containing the venv, you need to modify the path accordingly.</p>
</section>
<section id="setting-up-your-repository">
<h3>Setting up your repository<a class="headerlink" href="#setting-up-your-repository" title="Link to this heading">¶</a></h3>
<p>If you’re taking the Imperial module then we’re using a tool called <a class="reference external" href="https://classroom.github.com">GitHub
classroom</a> to automate the creation of your
copies of the repository. To create your repository, <a class="reference external" href="https://classroom.github.com/a/WOdAhT90">click here</a>.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>When attempt to accept an assignment you might instead receive an error
message starting:</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Your GitHub account cannot this invitation at this time. The
Classroom’s Organization restricts membership to users within the same
enterprise.</p>
</div>
<p>This means that you need to associate your GitHub account with the Imperial
College London GitHub enterprise. You should click on the Imperial
GitHub <a class="reference external" href="https://github.com/orgs/ImperialCollegeLondon/sso">single sign on page</a> and sign in using
your Imperial credentials. If prompted to do so, also sign in with your
GitHub username. You should now be able to go back and click on the
assignment acceptance link.</p>
</div>
<p>If you’re not taking the Imperial module and simply want to attempt the
exercised for your own purposes, then you can obtain the skeleton code by
forking <a class="reference external" href="https://github.com/finite-element/finite-element-course">the course repository</a>.</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>If you are taking the Imperial module for credit, you must use the GitHub
classroom link. If you do not do so then your commits will not show as
submission of the exercise.</p>
</div>
</section>
<section id="cloning-a-local-copy">
<h3>Cloning a local copy<a class="headerlink" href="#cloning-a-local-copy" title="Link to this heading">¶</a></h3>
<p>At the command line on your working machine type:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>git<span class="w"> </span>clone<span class="w"> </span><url><span class="w"> </span>finite-element-course
</pre></div>
</div>
<p>Substituting your git repository url for <url>. Your git repository
url can be found by clicking on <cite>clone or download</cite> at the top right of your repository page on GitHub.</p>
</section>
<section id="installing-the-course-python-package">
<h3>Installing the course Python package<a class="headerlink" href="#installing-the-course-python-package" title="Link to this heading">¶</a></h3>
<p>Your git repository contains a Python package. Installing this will cause the
other Python packages on which it depends to be installed into your venv, and
will create various visualisation scripts you’ll need later in the module. Run:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>python<span class="w"> </span>-m<span class="w"> </span>pip<span class="w"> </span>install<span class="w"> </span>-e<span class="w"> </span>finite-element-course/
</pre></div>
</div>
</section>
</section>
<section id="skeleton-code-documentation">
<h2>Skeleton code documentation<a class="headerlink" href="#skeleton-code-documentation" title="Link to this heading">¶</a></h2>
<p>There is web documentation for the complete <a class="reference internal" href="fe_utils.html"><span class="doc">fe_utils package</span></a>. There is
also an <a class="reference internal" href="genindex.html"><span class="std std-ref">alphabetical index</span></a> and a <a class="reference internal" href="search.html"><span class="std std-ref">search page</span></a>.</p>
</section>
<section id="how-to-do-the-implementation-exercises">
<h2>How to do the implementation exercises<a class="headerlink" href="#how-to-do-the-implementation-exercises" title="Link to this heading">¶</a></h2>
<p>The implementation exercises build up a finite element library from
its component parts. Quite a lot of the coding infrastructure you will
need is provided already. Your task is to write the crucial
mathematical operations at key points. The mathematical operations
required are described on this website, interspersed with exercises
which require you to implement and test parts of the mathematics.</p>
<p>The code on which you will build is in the <code class="docutils literal notranslate"><span class="pre">fe_utils</span></code> directory of
your repository. The code has embedded documentation which is used to
build the <a class="reference internal" href="fe_utils.html"><span class="doc">fe_utils package</span></a> web documentation.</p>
<p>As you do the exercises, <strong>commit your code</strong> to your repository. This
will build up your finite element library. You should commit code
early and often - small commits are easier to understand and debug
than large ones.</p>
</section>
<section id="testing-your-work">
<h2>Testing your work<a class="headerlink" href="#testing-your-work" title="Link to this heading">¶</a></h2>
<p>As you complete the exercises, there will often be test scripts which
exercise the code you have just written. These are located in the
<code class="docutils literal notranslate"><span class="pre">test</span></code> directory and employ the <a class="reference external" href="http://pytest.org/">pytest</a>
testing framework. You run the tests with:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>py.test<span class="w"> </span>test_script.py
</pre></div>
</div>
<p>from the bash command line, replacing <code class="docutils literal notranslate"><span class="pre">test_script.py</span></code> with the appropriate
test file name. The <code class="docutils literal notranslate"><span class="pre">-x</span></code> option to <code class="docutils literal notranslate"><span class="pre">py.test</span></code> will cause the test
to stop at the first failure it finds, which is often the best place
to start fixing a problem. For those familiar with debuggers, the
<code class="docutils literal notranslate"><span class="pre">--pdb</span></code> option will drop you into the Python debugger at the first
error.</p>
<p>You can also run all the tests by running <code class="docutils literal notranslate"><span class="pre">py.test</span></code> on the tests
directory. This works particularly well with the -x option, resulting
in the tests being run in course order and stopping at the first
failing test:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>py.test<span class="w"> </span>-x<span class="w"> </span>tests/
</pre></div>
</div>
</section>
<section id="coding-style-and-commenting">
<h2>Coding style and commenting<a class="headerlink" href="#coding-style-and-commenting" title="Link to this heading">¶</a></h2>
<p>Computer code is not just functional, it also conveys information to
the reader. It is important to write clear, intelligible code. <strong>The
readability and clarity of your code will count for marks</strong>.</p>
<p>The Python community has agreed standards for coding, which are
documented in <a class="reference external" href="https://www.python.org/dev/peps/pep-0008/">PEP8</a>. There are programs and
editor modes which can help you with this. The skeleton implementation
follows PEP8 quite closely. You are encouraged, especially if you are
a more experienced programmer, to follow PEP8 in your
implementation. However nobody is going to lose marks for PEP8
failures.</p>
</section>
<section id="getting-help">
<h2>Getting help<a class="headerlink" href="#getting-help" title="Link to this heading">¶</a></h2>
<p>It’s expected that you will find there are tasks in the implementation exercise
that you don’t know how to do. Your first port of call should be the Ed
forum, followed by the weekly live lab sessions.</p>
<section id="using-ed">
<h3>Using Ed<a class="headerlink" href="#using-ed" title="Link to this heading">¶</a></h3>
<p>The key advantage of asking for help on Ed is that you can do this at any
point during the week, whenever you are stuck. The whole class can see the forum,
but you can choose to publish anonymously so nobody need know who asked the
question. You should also watch the other questions as they appear on Ed,
because you will find that you learn a lot from what other people ask, as well
as the answers they get. Other students might notice issues that didn’t even
occur to you!</p>
<p>Do please try to answer other students’ questions. Doing so
is actually a really effective way of understanding the work better, since you
will be looking at the tasks from another student’s perspective.</p>
</section>
<section id="formulating-a-good-question">
<h3>Formulating a good question<a class="headerlink" href="#formulating-a-good-question" title="Link to this heading">¶</a></h3>
<p>One of the key skills in getting help with code is to ask the question in a
structured way which provides all the information required by the person helping
you. Not only does this radically increase the chances of getting a useful
response first time, but often the process of thinking through how to ask the
question leads you to its solution before you even ask. Please review the
information from the second year Principles of Programming <a class="reference external" href="https://object-oriented-python.github.io/a1_help.html#issue-report" title="(in Object-oriented Programming v2023.0)"><span class="xref std std-ref">instructions on
raising an issue</span></a>.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Please don’t post large pieces of code to Ed. Just post minimal examples
if they help. However always commit and push your work, and post the
<a class="reference external" href="https://imperial-fons-computing.github.io/git.html#git-hash" title="(in Installation instructions for FoNS v2020.0)"><span class="xref std std-ref">git commit hash</span></a> in the repository. The lecturer can
always find your work from the git hash, so long as you’ve pushed to GitHub.</p>
</div>
</section>
</section>
<section id="tips-and-tricks-for-the-implementation-exercise">
<h2>Tips and tricks for the implementation exercise<a class="headerlink" href="#tips-and-tricks-for-the-implementation-exercise" title="Link to this heading">¶</a></h2>
<dl class="simple">
<dt>Work from the documentation.</dt><dd><p>The notes, and particularly the exercise specifications, contain
important information about how and what to implement. If you just
read the source code then you will miss out on important
information.</p>
</dd>
<dt>Read the hints</dt><dd><p>The pink sections in the notes starting with a lightbulb are
hints. Usually they contain suggestions about how to go about
writing your answer, or suggest Python functions which you might
find useful.</p>
</dd>
<dt>Don’t forget the 1D case</dt><dd><p>Your finite element library needs to work in one and two dimensions.</p>
</dd>
<dt>Return a <a class="reference external" href="https://numpy.org/doc/stable/reference/generated/numpy.array.html#numpy.array" title="(in NumPy v2.4)"><code class="xref py py-func docutils literal notranslate"><span class="pre">numpy.array()</span></code></a></dt><dd><p>Many of the functions you have to write return arrays. Make sure
you actually return an array and not a list (it’s usually fine to
build the answer as a list, but convert it to an array before you
return it).</p>
</dd>
</dl>
</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>