2 This page collects a few answers to questions that have frequently been asked about deal.II and that we thought are worth recording as they may be useful to others as well.
5 * [The deal.II FAQ](#the-dealii-faq)
6 * [Table of Contents](#table-of-contents)
7 * [General questions on deal.II](#general-questions-on-dealii)
8 * [Can I use/implement triangles/tetrahedra in deal.II?](#can-i-useimplement-trianglestetrahedra-in-dealii)
9 * [I'm stuck!](#im-stuck)
10 * [I'm not sure the mailing list is the right place to ask ...](#im-not-sure-the-mailing-list-is-the-right-place-to-ask-)
11 * [How fast is deal.II?](#how-fast-is-dealii)
12 * [deal.II programs behave differently in 1d than in 2/3d](#dealii-programs-behave-differently-in-1d-than-in-23d)
13 * [I want to use deal.II for work in my company. Do I need a special license?](#i-want-to-use-dealii-for-work-in-my-company-do-i-need-a-special-license)
14 * [Supported System Architectures](#supported-system-architectures)
15 * [Can I use deal.II on a Windows platform?](#can-i-use-dealii-on-a-windows-platform)
16 * [Run deal.II in the Linux Subsystem for Windows 10](#run-dealii-in-the-linux-subsystem-for-windows-10)
17 * [Run deal.II natively on Windows](#run-dealii-natively-on-windows)
18 * [Run deal.II through a virtual box](#run-dealii-through-a-virtual-box)
19 * [Dual-boot your machine with Ubuntu](#dual-boot-your-machine-with-ubuntu)
20 * [Can I use deal.II on an Apple Macintosh?](#can-i-use-dealii-on-an-apple-macintosh)
21 * [Does deal.II support shared memory parallel computing?](#does-dealii-support-shared-memory-parallel-computing)
22 * [Does deal.II support parallel computing with message passing?](#does-dealii-support-parallel-computing-with-message-passing)
23 * [How does deal.II support multi-threading?](#how-does-dealii-support-multi-threading)
24 * [My deal.II installation links with the Threading Building Blocks (TBB) but doesn't appear to use multiple threads!](#my-dealii-installation-links-with-the-threading-building-blocks-tbb-but-doesnt-appear-to-use-multiple-threads)
25 * [Configuration and Compiling](#configuration-and-compiling)
26 * [Where do I start?](#where-do-i-start)
27 * [I tried to install deal.II on system X and it does not work](#i-tried-to-install-dealii-on-system-x-and-it-does-not-work)
28 * [How do I change the compiler?](#how-do-i-change-the-compiler)
29 * [I can configure and compile the library but installation fails. What is going on?](#i-can-configure-and-compile-the-library-but-installation-fails-what-is-going-on)
30 * [I get warnings during linking when compiling the library. What's wrong?](#i-get-warnings-during-linking-when-compiling-the-library-whats-wrong)
31 * [I can't seem to link/run with PETSc](#i-cant-seem-to-linkrun-with-petsc)
32 * [Is there a sure-fire way to compile deal.II with PETSc?](#is-there-a-sure-fire-way-to-compile-dealii-with-petsc)
33 * [I want to use HYPRE through PETSc](#i-want-to-use-hypre-through-petsc)
34 * [Is there a sure-fire way to compile dealii with SLEPc?](#is-there-a-sure-fire-way-to-compile-dealii-with-slepc)
35 * [Trilinos detection fails with an error in the file Sacado.hpp or <code>Sacado_cmath.hpp</code>](#trilinos-detection-fails-with-an-error-in-the-file-sacadohpp-or-sacado_cmathhpp)
36 * [My program links with some template parameters but not with others.](#my-program-links-with-some-template-parameters-but-not-with-others)
37 * [When trying to run my program on Mac OS X, I get image errors.](#when-trying-to-run-my-program-on-mac-os-x-i-get-image-errors)
38 * [C++ questions](#c-questions)
39 * [What integrated development environment (IDE) works well with deal.II?](#what-integrated-development-environment-ide-works-well-with-dealii)
40 * [Is there a good introduction to C++?](#is-there-a-good-introduction-to-c)
41 * [Are there features of C++ that you avoid in deal.II?](#are-there-features-of-c-that-you-avoid-in-dealii)
42 * [Why use templates for the space dimension?](#why-use-templates-for-the-space-dimension)
43 * [Doesn't it take forever to compile templates?](#doesnt-it-take-forever-to-compile-templates)
44 * [Why do I need to use typename in all these templates?](#why-do-i-need-to-use-typename-in-all-these-templates)
45 * [Why do I need to use this-> in all these templates?](#why-do-i-need-to-use-this--in-all-these-templates)
46 * [Does deal.II require C++11 support?](#does-dealii-require-c11-support)
47 * [deal.II version 9.0.0](#dealii-version-900)
48 * [deal.II version 8.5.0 and previous](#dealii-version-850-and-previous)
49 * [Can I convert Triangulation cell iterators to DoFHandler cell iterators?](#can-i-convert-triangulation-cell-iterators-to-dofhandler-cell-iterators)
50 * [Questions about specific behavior of parts of deal.II](#questions-about-specific-behavior-of-parts-of-dealii)
51 * [How do I create the mesh for my problem?](#how-do-i-create-the-mesh-for-my-problem)
52 * [How do I describe complex boundaries?](#how-do-i-describe-complex-boundaries)
53 * [I am using discontinuous Lagrange elements (FE_DGQ) but they don't seem to have vertex degrees of freedom!?](#i-am-using-discontinuous-lagrange-elements-fe_dgq-but-they-dont-seem-to-have-vertex-degrees-of-freedom)
54 * [How do I access values of discontinuous elements at vertices?](#how-do-i-access-values-of-discontinuous-elements-at-vertices)
55 * [Does deal.II support anisotropic finite element shape functions?](#does-dealii-support-anisotropic-finite-element-shape-functions)
56 * [The graphical output files don't make sense to me -- they seem to have too many degrees of freedom!](#the-graphical-output-files-dont-make-sense-to-me----they-seem-to-have-too-many-degrees-of-freedom)
57 * [In my graphical output, the solution appears discontinuous at hanging nodes](#in-my-graphical-output-the-solution-appears-discontinuous-at-hanging-nodes)
58 * [When I run the tutorial programs, I get slightly different results](#when-i-run-the-tutorial-programs-i-get-slightly-different-results)
59 * [How do I access the whole vector in a parallel MPI computation?](#how-do-i-access-the-whole-vector-in-a-parallel-mpi-computation)
60 * [How to get the (mapped) position of support points of my element?](#how-to-get-the-mapped-position-of-support-points-of-my-element)
61 * [Debugging deal.II applications](#debugging-dealii-applications)
62 * [I don't have a whole lot of experience programming large-scale software. Any recommendations?](#i-dont-have-a-whole-lot-of-experience-programming-large-scale-software-any-recommendations)
63 * [Are there strategies to avoid bugs in the first place?](#are-there-strategies-to-avoid-bugs-in-the-first-place)
64 * [How can deal.II help me find bugs?](#how-can-dealii-help-me-find-bugs)
65 * [Should I use a debugger?](#should-i-use-a-debugger)
66 * [deal.II aborts my program with an error message](#dealii-aborts-my-program-with-an-error-message)
67 * [The program aborts saying that an exception was thrown, but I can't find out where](#the-program-aborts-saying-that-an-exception-was-thrown-but-i-cant-find-out-where)
68 * [I get an exception in virtual dealii::Subscriptor::~Subscriptor() that makes no sense to me!](#i-get-an-exception-in-virtual-dealiisubscriptorsubscriptor-that-makes-no-sense-to-me)
69 * [I get an error that the solver doesn't converge. But which solver?](#i-get-an-error-that-the-solver-doesnt-converge-but-which-solver)
70 * [How do I know whether my finite element solution is correct? (Or: What is the "Method of Manufactured Solutions"?)](#how-do-i-know-whether-my-finite-element-solution-is-correct-or-what-is-the-method-of-manufactured-solutions)
71 * [My program doesn't produce the expected output!](#my-program-doesnt-produce-the-expected-output)
72 * [The solution converges initially, but the error doesn't go down below 10<sup>-8</sup>!](#the-solution-converges-initially-but-the-error-doesnt-go-down-below-10-8)
73 * [My code converges with one version of deal.II but not with another](#my-code-converges-with-one-version-of-dealii-but-not-with-another)
74 * [My time dependent solver does not produce the correct answer!](#my-time-dependent-solver-does-not-produce-the-correct-answer)
75 * [My Newton method for a nonlinear problem does not converge (or converges too slowly)!](#my-newton-method-for-a-nonlinear-problem-does-not-converge-or-converges-too-slowly)
76 * [Printing deal.II data types in debuggers is barely readable!](#printing-dealii-data-types-in-debuggers-is-barely-readable)
77 * [My program is slow!](#my-program-is-slow)
78 * [How do I debug MPI programs?](#how-do-i-debug-mpi-programs)
79 * [I have an MPI program that hangs](#i-have-an-mpi-program-that-hangs)
80 * [One statement/block/function in my MPI program takes a long time](#one-statementblockfunction-in-my-mpi-program-takes-a-long-time)
81 * [I have a special kind of equation!](#i-have-a-special-kind-of-equation)
82 * [Where do I start?](#where-do-i-start-1)
83 * [Can I solve my particular problem?](#can-i-solve-my-particular-problem)
84 * [Why use deal.II instead of writing my application from scratch?](#why-use-dealii-instead-of-writing-my-application-from-scratch)
85 * [Can I solve problems over complex numbers?](#can-i-solve-problems-over-complex-numbers)
86 * [How can I solve a problem with a system of PDEs instead of a single equation?](#how-can-i-solve-a-problem-with-a-system-of-pdes-instead-of-a-single-equation)
87 * [Is it possible to use different models/equations on different parts of the domain?](#is-it-possible-to-use-different-modelsequations-on-different-parts-of-the-domain)
88 * [Where do I start to implement a new Finite Element Class?](#where-do-i-start-to-implement-a-new-finite-element-class)
89 * [General finite element questions](#general-finite-element-questions)
90 * [How do I compute the error](#how-do-i-compute-the-error)
91 * [How to plot the error as a pointwise function](#how-to-plot-the-error-as-a-pointwise-function)
92 * [I'm trying to plot the right hand side vector but it doesn't seem to make sense!](#im-trying-to-plot-the-right-hand-side-vector-but-it-doesnt-seem-to-make-sense)
93 * [What does XXX mean?](#what-does-xxx-mean)
94 * [I want to contribute to the development of deal.II!](#i-want-to-contribute-to-the-development-of-dealii)
95 * [I found a typo or a bug and fixed it on my machine. How do I get it included in deal.II?](#i-found-a-typo-or-a-bug-and-fixed-it-on-my-machine-how-do-i-get-it-included-in-dealii)
96 * [I'm fluent in deal.II, are there jobs for me?](#im-fluent-in-dealii-are-there-jobs-for-me)
98 ## General questions on deal.II
100 ### Can I use/implement triangles/tetrahedra in deal.II?
102 This is truly one of the most frequently asked questions. The short answer
103 is: No, you can't. deal.II's basic data structures are too much tailored to
104 quadrilaterals and hexahedra to make this trivially possible. Implementing
105 other reference cells such as triangles and tetrahedra amounts to
106 re-implementing nearly all grid and DoF classes from scratch, along with
107 the finite element shape functions, mappings, quadratures and a whole host
108 of other things. Making triangles and tetrahedra work would certainly involve
109 having to write several ten thousand lines of code, and to make it usable
110 in all the rest of the library would require auditing a very significant
111 fraction of the 600,000 lines of code that make up deal.II today.
113 That said, the current specialization on quadrilaterals and hexahedra has
114 two very positive aspects: First, quadrilaterals and hexahedra typically
115 provide a significantly better approximation quality than triangular meshes
116 with the same number of degrees of freedom; you therefore get more accurate
117 solutions for the same amount of work. Secondly, because the shape of cells
118 are known, we can make a lot of things known to the compiler (such as the
119 number of iterations of a loop over all vertices of a cell) which avoid a
120 large number of run-time computations and makes the library as fast as it
121 is. A simple example is that in deal.II we know that a loop over all
122 vertices of a cell has exactly `GeometryInfo<dim>::vertices_per_cell`
123 iterations, a number that is known to the compiler at compile-time. If we
124 allowed both triangles and quadrilaterals, the loop would have
125 `cell->n_vertices()` iterations, but this would in general not be known at
126 compile time and consequently not allow the compiler to optimize on.
128 If you do need to work with a geometry for which all you have is a
129 triangular or tetrahedral mesh, then you can convert this mesh into one
130 that consists of quadrilaterals and hexahedra using the `tethex` program,
131 see https://github.com/martemyev/tethex .
135 Further down below on this page (in the debugging section) we list a number
136 of strategies on how to find errors in your program. If your question is
137 how to implement something new for which you don't know where to start,
138 have you taken a look at the set of tutorial programs and checked whether
139 one or the other already has something that's close to what you want?
141 That said, there will be situations where documentation doesn't help and
142 where you need other someone else's opinion. That's what the [deal.II
143 mailing lists](http://dealii.org/mail.html) are there for: Feel free to
144 ask! You may also wish to subscribe to the users' list -- not so much
145 because someone else might ask the same question you have, but because
146 reading the list gives you background information on things others are
147 working on that may help you when you want to do something similar.
149 When asking for help on the mailing list, be specific. We frequently get mail of the following kind:
151 I'm trying to do X. This works fine but it fails when I try to transfer
152 the data to my MyClass::Estimator object. I tried to use something
153 similar to what's done in a couple of tutorial programs but it doesn't
154 work. I'm new at C++ and I just can't seem to get the syntax right.
157 This message doesn't contain nearly enough information for anyone to really
158 help you: we don't know what `MyClass::Estimator` is, we don't know how you
159 try to transfer data, we haven't seen your code, and we haven't seen the
160 compiler's error messages. (For more examples of how not to write help
161 requests, see [Section 3.2 of this
162 document](http://faculty.washington.edu/dchinn/how-not-to-code.pdf).) We
163 could poke in the dark, but it would probably be more productive if you
164 gave us a bit more detail explaining what doesn't work: show us the code
165 you implemented, show us the compiler's error message, or be specific in
166 some other way in describing what the problem is!
168 ### I'm not sure the mailing list is the right place to ask ...
170 Yes, it probably is. Please direct your questions to the mailing list and
171 not to individual developers. There are many reasons:
173 1. Others might have similar questions in the future and can search the
175 1. There are many active users on the mailing list that are happy to
176 help. There probably is someone who did something very similar before.
177 1. Imagine everyone would stop using the mailing list and email us
178 directly. We would spend most of our time answering the same questions
180 1. Many users are reading the mailing list and are interested in deal.II
181 in general and are learning by skimming emails. Give them a chance.
182 1. As a consequence of all this, we typically prioritize questions on
183 mailing lists over emails sent directly to us asking for help.
184 1. Don't be afraid. There are no stupid questions (only off-topic ones).
185 Everyone started out at some point. Asking the questions in the open
186 helps us improve the library and documentation.
188 That said, if there is something you can not discuss in the open, feel free
192 ### How fast is deal.II?
194 The answer to this question really depends on your metric. If you had to
195 write, say, a Stokes solver with a particular linear solver, a particular
196 time stepping scheme, on a piecewise polygonal domain, and Q2/Q1 elements,
197 you can write a code that is 20% or 30% faster than what you would get when
198 using deal.II because you know the building blocks, shape functions,
199 mappings, etc. But it'll take you 6 months to do so, and 20,000 lines of
200 code. On the other hand, when using deal.II, you can do it in 2 weeks and
201 204 lines (that's the number of semicolons in step-22).
203 In other words, if by "fast" you mean the absolute maximal efficiency in
204 terms of CPU time deal.II is more than likely to lose against a
205 hand-written Fortran77 code. But for most of us, the real question of
206 "fast" also includes the time it takes to get the code running and
207 verified, and in that case deal.II is most likely the fastest library out
208 there simply by virtue of the fact that it is by far the largest and most
209 comprehensive finite element library available as Open Source.
211 This all, by the way, does not mean that we don't care about speed: We
212 spend a lot of effort profiling the library and working on the hot spots to
213 make codes fast. The discussion of this issue in the introduction of
214 step-22 is a good example. There are also some guidelines below on how to
215 profile your code in the debugging section of this FAQ.
217 ### deal.II programs behave differently in 1d than in 2/3d
219 In deal.II, you can write programs that look exactly the same in 2d and 3d,
220 but there are cases where 1d is slightly different. That said, this is an
221 area that we have significantly rewritten, and starting with deal.II 7.1,
222 most cases should work in 1d in just the same way as they do in 2d/3d. If
223 you find something that doesn't work, please report it to the mailing list.
225 Historically, the differences primarily resulted from the fact that in
226 deal.II, we represent vertices differently from lines and quads; whereas
227 the latter can store information (for example boundary indicators, user
228 flags, etc) vertices don't. As a consequence, the boundary indicator of a
229 boundary part in 1d (i.e. either the left or right vertex) were determined
230 by convention, rather than by setting it explicitly: the left boundary of a
231 1d domain always had boundary indicator zero, the right boundary always
232 boundary indicator one. This was different from the 2d/3d case where by
233 default (unless you explicitly set things differently) all boundaries have
234 indicator zero. This left-boundary-has-id-0, right-boundary-has-id-1 is
235 still the default today, but at least you can set the boundary indicators
236 of these end-points to something different today.
238 A second difference is that vertices have no extent, and so you can't apply
239 quadrature to them. As a consequence, the FEFaceValues class wasn't usable
240 in 1d. Again, this should work these days: every quadrature formula that
241 has a single quadrature point is a valid one for points as well.
243 ### I want to use deal.II for work in my company. Do I need a special license?
245 Before going into any more details, you **need** to carefully read the
246 license deal.II is under. In particular, the explanations below are not meant
247 to be legal advice and does not override the provisions in the Open Source
250 However, before this, let us provide our overarching philosophy: It is our
251 intention to have constructive relationships with those who want to use our
252 work commercially, and we encourage commercial use. After having used a
253 more restrictive license until 2013, we have come to the conclusion that
254 these licenses serve neither side particularly well: it made commercial use
255 difficult, and the lack of commercial use deprived us of critical feedback,
256 potential contributions from professional users, and our users of potential
257 employment opportunities. Everyone is better off with the LGPL license we
258 are using now, and we hope that deal.II also finds use in commercial
261 Now for the smaller print: Generally, the LGPL is a fairly liberal license.
262 In particular, if you *develop a code based on deal.II*, then there is no
263 requirement that you also open source your own code: you can keep it closed
264 source, under a proprietary license, and you don't need to give it to
265 anyone (neither your customers nor to us).
267 The LGPL is only restrictive in that the *changes you make to deal.II
268 itself* must also be licensed under the LGPL. There is not frequently a
269 need to change the library itself, and in many of these cases you will
270 probably be interested to get them into the upstream development sources
271 anyway (e.g., in cases of bugs) rather than having to forward port them
272 indefinitely. Of course, we are interested in this as well. However, there
273 is no such requirement that you upstream these changes: the only people you
274 have to make these modifications to deal.II available to are your
277 As mentioned above, the preceding paragraphs are not a legal
278 interpretation. For definite interpretations of the LGPL, you may want to
279 consult lawyers familiar with the topic or search the web for more detailed
283 ## Supported System Architectures
285 ### Can I use deal.II on a Windows platform?
287 deal.II has been developed with a Unix-like environment in mind and it
288 shows in a number of places regarding the build system and compilers
289 supported. That said, there are multiple methods to get deal.II running if
290 you have a Windows machine.
292 #### Run deal.II in the Linux Subsystem for Windows 10
294 Windows 10 has gained a compatibility layer for running Linux binaries
295 natively on Windows. You can find more information on the
296 [Wikipedia page](https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux).
297 This means you do not have to use
298 [virtualization](#run-dealii-through-a-virtual-box), or [dual
299 boot](#dual-boot-your-machine-with-ubuntu) any more to install a
300 full-featured Linux distribution! We summarize the installation on a
301 separate wiki page on [[Windows]].
303 #### Run deal.II natively on Windows
305 Since deal.II 8.4.0 we have experimental support for Microsoft Visual Studio (2013 and 2015). See the separate page on [[Windows]] for more details.
307 #### Run deal.II through a virtual box
309 The simplest way to try out deal.II is to run it in a premade virtual
310 machine. You can download the virtual machine for VirtualBox from
311 http://www.math.clemson.edu/~heister/dealvm/ and run it inside windows.
313 Note that your experience depends on how powerful your machine is. More
314 than 4GB RAM are recommended. A native installation of Linux is preferable
317 #### Dual-boot your machine with Ubuntu
319 The simplest way to install Linux as a Windows user is to dual-boot.
320 Dual-boot means that you simply install a second operating system on your
321 computer and you choose which one to start when you boot the machine. Most
322 versions of Linux support installing themselves as a second operating
323 system. One example is using the Ubuntu installer for Windows. This
324 installer will automatically dual-boot your system for you in a safe and
325 fully reversible manner. Simply follow the instructions on
326 http://www.ubuntu.com/download/desktop/install-ubuntu-with-windows
328 If at some point in the future you wish to remove Ubuntu from your system,
329 from the Windows program manager (add-remove programs in older versions and
330 programs and features in newer versions) you can simply uninstall Ubuntu as
331 you would any other program.
333 *Note:* The actual install file is linked through the text "Windows
334 installer" in the first gray box. You will be prompted to donate to
335 Ubuntu, which is entirely optional. You will also be prompted to use a
336 different version of Ubuntu if you use Windows 8.
338 ### Can I use deal.II on an Apple Macintosh?
340 Yes, at least on the more modern OS X operating systems this works just
341 fine. deal.II supports native compilers shipping with XCode as well as gcc
344 The only issue we are currently aware of is that if deal.II is configured
345 to interface with PETSc, then PETSc needs to be configured with the
346 <code>--with-x=0</code> flag to prevent linking in the X11 libraries (you
347 probably won't need them anyway). Installing with PETSc has a myriad of
348 other problems, though we believe that we have a way to stably interface
349 it. You may want to read through the PETSc-related entries further down,
352 ### Does deal.II support shared memory parallel computing?
354 Yes. deal.II supports multithreading with the help of the
355 [http://www.threadingbuildingblocks.org Threading Building Blocks (TBB)
356 library](c967ec2ff74d85bd4327f9f773a93af3]). It is enabled by default and
357 can be controlled via the `DEAL_II_WITH_THREADS` configuration toggle
358 passed to `cmake` (see the deal.II readme file).
360 ### Does deal.II support parallel computing with message passing?
362 Yes, and in fact it has been shown to scale very nicely to at least 16,384
363 processor cores in a paper by Bangerth, Burstedde, Heister and Kronbichler.
364 You should take a look at the documentation modules discussing parallel
365 computing, as well as the step-40 tutorial program.
368 ### How does deal.II support multi-threading?
370 deal.II will use multi-threading using several approaches:
371 1. some BLAS routines might be multi-threaded (typically using OpenMP).
372 This can be controlled from the command line using OMP_NUM_THREADS (also
373 see the entry in the FAQ below)
374 2. Many places in the library are parallelized using the Threading Building
375 Blocks (TBB) library.
377 MPI_InitFinalize() has an optional third argument that specifies the number
378 of threads to use for the TBB. The default is 1. This gets send to the TBB
379 via a call to MultithreadInfo::set_thread_limit(). If you pass
380 numbers::invalid_unsigned_int into MPI_InitFinalize (or if you don't use
381 that class, call set_thread_limit directly) then TBB will use the maximum
382 number of threads that makes sense (and you can limit it using
383 DEAL_II_NUM_THREADS from the command line).
385 Also note that while our Trilinos wrappers support multi-threading, the
386 PETSc wrappers do not support this at this time, so you need to run with
387 one thread per process.
389 ### My deal.II installation links with the Threading Building Blocks (TBB) but doesn't appear to use multiple threads!
391 This may be a quirky interaction with the [GOTO
392 BLAS](http://www.tacc.utexas.edu/tacc-projects/gotoblas2/) :-( If you use
393 Trilinos or PETSc, both of these require a BLAS library from your system,
394 and the deal.II cmake configuration will make sure that it is linked with.
395 The problem stems from the fact that by default, the GOTO BLAS will simply
396 grab all cores of the system for its own use, and -- before your `main()`
397 function even starts, allow the main thread to use only a single core. (For
398 the technically interested: it sets the processor scheduling affinity mask,
399 using `set_sched_affinity` to a single bit.)
401 When the TBB initialization runs, still before `main()` starts, it will
402 find that it can only run on a single core and will consequently not be
403 able to work on multiple tasks in parallel.
405 The solution to this problem is to forbid the GOTO BLAS to grab all
406 processors for itself, since we spend very little time in BLAS anyway. This
407 can be done by setting either the `OMP_NUM_THREADS` or `GOTO_NUM_THREADS`
408 environment variables to 1, see
409 http://www.tacc.utexas.edu/tacc-software/gotoblas2/faq .
412 ## Configuration and Compiling
414 ### Where do I start?
416 Have a look at the [ReadMe instructions](http://www.dealii.org/developer/readme.html) for details on how to configure and install the library with `cmake`.
418 ### I tried to install deal.II on system X and it does not work
420 That does occasionally (though relatively rarely) happen, in particular if
421 you work on an operating system or with a compiler that the primary
422 developers don't have access to. In a case like this, you should ask for
423 help on the mailing list. However, remember: If your question only contains
424 the text "I tried to install deal.II on system X and it does not work" then
425 that's not quite enough to figure out what is happening. Even though the
426 people developing this software belong to the most able programmers in the
427 universe (and a decent number of parallel universes), all of us need data
428 to find errors. So, whatever went wrong, paste the error message into your
429 email. If the error is from the `cmake` invocation, show us the error
430 message that was printed on screen.
431 If the error happens after configuring and during compiling, add lines from
432 screen output showing the error to the mail.
435 ### How do I change the compiler?
437 deal.II can be compiled by a number of compilers without problems (see the
438 section [prerequisites](http://www.dealii.org/readme.html#prerequisites) in
439 the readme file). If `cmake` does not pick the right one, selecting another
440 is simple, and described in a
441 [section](http://www.dealii.org/developer/development/cmake.html#compiler)
443 documentation](http://www.dealii.org/developer/development/cmake.html).
445 ### I can configure and compile the library but installation fails. What is going on?
447 If you configure with the default ``CMAKE_INSTALL_PREFIX``, the library is configured to installed to ``/usr/local`` and this fails without superuser rights with an error message like
449 CMake Error at cmake/scripts/cmake_install.cmake:42 (FILE):
450 file cannot create directory: /usr/local/common/scripts. Maybe need
451 administrative privileges.
453 Please see the [readme](http://www.dealii.org/developer/readme.html#configuration) on how to pick an install directory with write access (for example some path below your home directory).
455 ### I get warnings during linking when compiling the library. What's wrong?
457 On some linux distributions with particular versions of the system
458 compiler, one can get warnings like these during the linking stage of
459 compiling the library:
461 `.L3019' referenced in section `.rodata' of
462 /home/bangerth/deal.II/lib/lac/sparse_matrix.float.g.o: defined in discarded section
463 `.gnu.linkonce.t._ZN15SparsityPattern21optimized_lower_boundEPKjS1_RS0_'
464 of /home/bangerth/deal.II/lib/lac/sparse_matrix.float.g.o
467 While annoying, these warnings do not actually seem to indicate anything
468 particularly harmful. Apparently, the compiler generates the same code
469 multiple times in exactly the same form, and the linker is only warning
470 that it is throwing away all but one of the copies. There doesn't seem to
471 be way to avoid these warnings, but they can be safely ignored.
473 ### I can't seem to link/run with PETSc
475 Recent deal.II releases support PETSc 3.0 and later. This works, but there
476 are a number of things that can go wrong and that result in compilation or
477 linker errors, as explained below. If your program links properly with
478 PETSc support, it will very likely also produce the correct results.
480 If you get errors like this when trying to run step-17 of the tutorials,
481 even though linking seems to have succeeded just fine:
484 ============================ Running step-17
485 ./step-17: error while loading shared libraries: libpetsc.so: cannot open
486 shared object file: No such file or directory
487 make: *** [run](step-17]) Error 127
490 this means is that while linking, the compiler could find the libpetsc.so
491 library, but the executable can't find it when running. The reason is that
492 we can tell the linker where to look, but the executable apparently did not
493 remember this (this is the standard Unix behavior). What you have to do is
494 to set the LD_LIBRARY_PATH to include the path to the PETSc libraries. For
495 example, under `bash` you would have to do this:
497 export LD_LIBRARY_PATH=/path/to/petsc/libraries:$LD_LIBRARY_PATH
500 If you do so, the Unix loader can query the environment variable for where
501 to find this particular library when trying to run the executable, and
502 running the program should succeed.
504 Similarly, if you get errors of the kind during linking
506 /home/xxx/deal.II/lib/libdeal_II.g.so: undefined reference to
507 `KSPSetInitialGuessNonzero(_p_KSP*, PetscTruth)'
508 /home/xxx/deal.II/lib/libdeal_II.g.so: undefined reference to
509 `VecAXPY(_p_Vec*, double, _p_Vec*)'
513 then the compiler can't seem to find the PETSc libraries. The solution is
514 as above: specify the path to those libraries via `LD_LIBRARY_PATH`.
517 #### Is there a sure-fire way to compile deal.II with PETSc?
519 Short answer is "No". The slightly longer answer is, "PETSc has too many
520 knobs, switches, dials, and a kitchen sink too many for its own damned
521 good. There is not a sure-fire way to compile deal.II with PETSc!". It
522 turns out that PETSc is a very versatile machine and, as such, there is no
523 shortage of things that can go wrong in trying to configure PETSc to work
524 seamlessly with deal.II on a first attempt. We have all struggled with
525 this, although it has become a lot better in recent years.
527 You can find instructions on how to install PETSc linked to from the
528 deal.II ReadMe file, or going directly to
529 http://www.dealii.org/developer/external-libs/petsc.html .
531 #### I want to use HYPRE through PETSc
533 Hypre implements algebraic multigrid methods (AMG) as preconditioners, for
534 example the BoomerAMG method. AMGs are among the most efficient
535 preconditioners available and they have also been shown to be scalable to
536 thousands of processors. deal.II allows the use of Hypre through the
537 PETScWrappers::PreconditionBoomerAMG class; it is used in `step-40`. Hypre
538 can be installed as a sub-package of PETSc and deal.II can access it
539 through the PETSc interfaces.
541 To use the Hypre interfaces through PETSc, you need to configure PETSc as
542 discussed in http://www.dealii.org/developer/external-libs/petsc.html ,
543 and add the following switch to the command line: `--download-hypre=1`.
545 #### Is there a sure-fire way to compile dealii with SLEPc?
547 Happily, the answer to this question is a definite yes; that is, <b>if you
548 have successfully compiled and linked PETSc already</b>.
550 The real trick here is that during configuration SLEPc will pull out
551 PETSc's configuration and just does whatever that tells it to do. Detailed
552 steps are discussed in
553 http://www.dealii.org/developer/external-libs/slepc.html .
555 Once deal.II is compiled, it is worth to start by looking at the step-36
556 tutorial program to see how to get started using the interface with SLEPc.
559 Note: To use the solvers and other algorithms SLEPc provides it is
560 absolutely essential to have your PETSc installation working correctly
561 since they share the same vector-matrix (and other) data structures.
565 ### Trilinos detection fails with an error in the file `Sacado.hpp` or `Sacado_cmath.hpp`
567 This is a complicated one (and it should also be fixed in more recent
568 Trilinos versions). In the Trilinos file `Sacado_cmath.hpp`, there is some
573 inline float acosh(float x)
575 return std::log(x + std::sqrt(x*x - float(1.0)));
581 In other words, Sacado is putting things into namespace `std`. The functions it
582 is putting there are functions that have been defined by the C99 standard but
583 that didn't make it into the C++98 standard before; some of them are widely
584 used. The problem is that these functions were later added to the standard and
585 so if your compiler is new enough (e.g. GCC 4.5 and later) then the compiler's
586 C++ standard library already contains these functions. Adding them again in this
587 file then yields errors of the kind
589 /home/.../trilinos-10.4.2/include/Sacado_cmath.hpp: In function 'float std::acosh(float)':
590 /home/.../trilinos-10.4.2/include/Sacado_cmath.hpp:41:16: error: redefinition of 'float std::acosh(float)'
591 /usr/include/c++/4.5/tr1_impl/cmath:321:3: error: 'float std::acosh(float)' previously defined here
594 The only useful way to avoid this error is to edit the Trilinos header
595 file. To do this, find and open the file `include/Sacado_cmath.hpp` in the
596 directory in which Trilinos was installed. Then change the block enclosed
607 #ifndef _GLIBCXX_USE_C99_MATH
615 What this will do is make sure that the new members of namespace `std` are
616 only added if the compiler has not already done so itself.
621 ### My program links with some template parameters but not with others.
623 deal.II has many types for whose initialization you need to provide a
624 template parameter, e.g. `SparseMatrix<double>`. The implementation of
625 these classes can typically be found in files ending `.templates.h`, e.g.
626 `sparse_matrix.templates.h`. The corresponding `.cc` files, e.g.
627 `sparse_matrix.cc`, essentially only provide the explicit instantiations of
628 these classes for the most commonly used template parameters. Sometimes
629 this is done by including a corresponding `.inst` file, e.g.
630 `sparse_matrix.inst`.
632 If you want to use a data type with a template parameter for which there is
633 an explicit instantiation, you only need to include the respective `.h`
634 header file, e.g. `sparse_matrix.h`. If, however, you want to use a
635 template parameter for which there is no explicit instantiation in the
636 corresponding `.cc` file, you have to include the respective `.templates.h`
637 file in order for your program to link successfully.
639 The reason for all of this is essentially a matter of reducing compilation
640 time. As long as you use data types with template parameters for which
641 there is an explicit instantiation - and this should be the case most of
642 the time - you do not need to compile the respective (lengthy) .templates.h
643 file every time you compile your code. If, however, you need to use an
644 instance of e.g. `SparseMatrix<bool>`, you have to include the respective
645 `.templates.h` file and you have to compile it along with the remaining
646 files of your program every time.
648 ### When trying to run my program on Mac OS X, I get image errors.
650 You may encounter an error of the form
653 dyld: Library not loaded: libdeal_II.g.7.0.0.dylib. Reason: image not found
656 on OS X. This goes hand in hand with the following message you should have
657 gotten at the end of the output of `./configure`:
661 export DYLD_LIBRARY_PATH=\$DYLD_LIBRARY_PATH:$DEAL2_DIR/lib
662 to your .bash_profile file so that OSX will be
663 able to find the deal.II shared libraries when
664 executing your programs.
667 What happens is this: when you say "make all", all the deal.II files are
668 compiled and linked into a library (called libdeal_II.g.7.0.0) which on Macs
669 have the file ending .dylib. Then you go to examples/step-1 and compile your
670 program, which uses all the functions and classes that have previously been
671 put into this library.
673 Now the following happens: On most operating systems, the actual executable
674 program (i.e. the file step-1 in your directory that resulted from compiling)
675 does not contain any information that would indicate where the various
676 libraries that it uses can be found. For example, the step-1 program does not
677 know where the libdeal_II.g.7.0.0.dylib file is. This is just how most
678 operating systems function. But when you want to execute the program, somehow
679 the program has to know where the library it needs is located. On most
680 unix-like operating systems, this is done by setting an "environment
681 variable" -- on linux this would the variable "LD_LIBRARY_PATH", on Mac OS X
682 it is "DYLD_LIBRARY_PATH".
684 So to let the operating system know where the library is located, you could
686 export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/Users/renjun/deal.ii/lib
687 every time before you want to execute the program. That would be cumbersome. A
688 simpler way would be if this export command is executed every time when you
689 open a new shell window. This can be achieved by putting this command in a
690 file that is executed every time you open a shell window. Depending on what
691 shell you use, these files are alternatively called
695 or similar. I'm not quite sure which file is relevant for you, but you can try
696 them one after the other by putting the text in there, closing the window,
697 opening it again, and then trying to execute
699 (or saying "make run" in this directory) and seeing whether that works.
703 ### What integrated development environment (IDE) works well with deal.II?
705 The short answer is probably: whatever works best for you. deal.II uses the
706 build tool CMake, which can generate a project description for virtually every
707 IDE. In the past, many of the main developers have used emacs (or even vi), but
708 there are much better tools around today, such as [eclipse](http://www.eclipse.org/),
709 [KDevelop](http://www.kdevelop.org),
710 [Xcode](http://developer.apple.com/technologies/tools/),
711 [QtCreator](http://qt.nokia.com/products/developer-tools/), all of which
712 have been used by people using deal.II.
714 We have gathered some notes on using the following IDEs for deal.II:
717 - [[emacs]]: While we don't recommend using emacs any more, this link provides a couple of notes on formatting styles used within deal.II.
719 When thinking about what IDE to use, keep this in mind: Many of us have
720 used emacs (or, worse, vi) for years and feel very comfortable with it.
721 But, emacs and vi were both started in 1976, at a time when computers had
722 little memory, virtually no CPU power, and only text-based interfaces.
723 While they have of course become a lot better over time, the design
724 limitations this involved are still very much part of the code base:
725 fundamentally, they are both still text-based and file-oriented. What IDEs
726 can provide are multiple views of the same project in graphical and textual
727 form and, more importantly, can integrate entire projects spanning hundreds
728 of files in multiple directories: they know where a variable is declared
729 (even if it's in a different file), what it's type is, and the properties
730 of this type. Neither emacs nor vi nor any other older editor can provide
731 anything that comes even close to what kdevelop or eclipse can offer in
734 What all this implies is that you should consider using one of the more
735 modern tools, even if you're well acquainted with an existing, older one.
736 Of course it takes a while to get used to a new application but my
737 (Wolfgang's) experience with switching from emacs to kdevelop was that I
738 have become '''so''' much more productive by using modern tools that the
739 time invested in learning it was amortized very quickly. I found this
740 experience a real eye-opener!
742 ### Is there a good introduction to C++?
744 There are of course many good books and online resources that explain C++.
745 As far as websites are concerned,
746 [www.cplusplus.com](http://www.cplusplus.com) has both [reference material
747 for individual classes of the C++ standard
748 library](http://cplusplus.com/reference/) as well as a [a tutorial on parts
749 of the C++ language](http://cplusplus.com/tutorial) if you want to brush up
750 on the correct syntax of things.
752 ### Are there features of C++ that you avoid in deal.II?
754 There are few things that we avoid <i>as a matter of principle.</i> C++ is,
755 by and large, a pretty well designed language in the sense that its
756 features are there because they have been found to be useful by a lot of
757 people. As an example, people have found that it is easier to write and
758 debug code that throws exceptions in error cases rather than encoding error
759 situations by special return values (e.g. by returning -1). There are of
760 course ways to avoid exceptions (or templates, or certain parts of the C++
761 standard libraries, or any number of other things people have found
762 objectionable in C++) and some software projects have chosen to restrict
763 the use of C++ (for example Mozilla) or to emulate only those parts of C++
764 they like in C (e.g. the GNOME desktop environment, which leads to awkward
766 [as described here](http://developer.gnome.org/gobject/stable/howto-gobject-methods.html)).
768 But ultimately, it is our belief that these approaches shoot their
769 inventors in the foot: they avoid features of C++ that were really intended
770 to make programming life simpler. It may be simpler for novice programmers
771 to read code without templates; ultimately, however, learning to read and
772 use templates will make you a much more productive programmer since you
773 don't write the same code multiple times. As a consequence, the use of C++
774 is driven by the question of what is best suited to write a particular
775 algorithm, not by abstract considerations. This fits into the realization
776 that deal.II is a large piece of software -- not a small research project
777 -- that requires professional software management practices and for which
778 long term development can no longer be driven by an individual programmer's
779 preferences of style.
781 ### Why use templates for the space dimension?
783 The fundamental motivation for this is to use dimension-independent
784 programming, i.e. you want to write code in such a way that it looks
785 exactly the same in 2d as in 3d (or 1d, for that matter). There are of
786 course many ways to do this (and libraries have done this for a long time
787 before deal.II has). The three most popular ones are to use a preprocessor
788 `#define` that sets the space dimension globally, to use a global variable
789 that does this, and to have each object have a member variable that denotes
790 the space dimension it is supposed to live in (in much the same way as the
791 template argument does in deal.II). Neither of these approaches is optimal
792 (nor is our own approach to use templates), however. In particular, using a
793 preprocessor symbol or a global variable will not allow you to mix and
794 match objects of different dimensionality. There are situations when you
795 want to do that; for example deal.II internally builds higher dimensional
796 quadrature formulas as tensor products of lower dimensional ones, and in
797 application codes you may wish to discretize both volume models (e.g.
798 simulating 3d models of plate tectonics and mountain belt formation) with
799 surface models (e.g. erosion processes on the 2d earth surface).
801 This leaves the option to have a member variable denoting the space
802 dimension in each object, a choice most other finite element libraries have
803 followed. But this isn't optimal either, for two reasons. For example,
804 consider this code that describes the equivalent of the `Point<dim>` class
805 for points in dim-dimensional space and its `norm()` member function:
811 Point (const unsigned int dimension)
813 coordinates (new double[dim])
816 ~Point() { delete[] coordinates; }
818 double norm () const;
825 double Point::norm () const
828 for (unsigned int d=0; d<dim; ++d)
829 s += coordinates[d] * coordinates[d];
834 This is going to lead to rather slow code, for multiple reasons:
836 - The constructor and destructor have to allocate and deallocate memory on
837 the heap, both expensive processes.
839 - When accessing any element of the `coordinates` array, two pointers have
840 to be dereferenced. For example, the access to `coordinates[d]` really
841 expands to `*(this->coordinates + d)`.
843 - The compiler can not optimize the loop since the upper bound `dim` of
844 the loop variable is unknown at compile time.
847 Compare this to the way deal.II (approximately) implements this class:
857 double norm () const;
860 double coordinates[dim];
864 double Point<dim>::norm () const
867 for (unsigned int d=0; d<dim; ++d)
868 s += coordinates[d] * coordinates[d];
873 Here, the following holds:
875 - Constructor and destructor do not have to allocate and deallocate memory
876 on the heap; rather, since the size of the `coordinates` array is known
877 at compile time (i.e. whenever you instantiate the template for a
878 particular dimension), the array lives on the stack. It is also much
879 smaller than before: the dimension is encoded in the type and doesn't
880 need a memory location, we don't need to store a pointer to an array,
881 and we don't incur the memory overhead of having to manage an object on
884 - When accessing any element of the `coordinates` array, only one pointer
885 has to be dereferenced. For example, the access to `coordinates` really
886 expands to `*(this + d)`.
888 - The compiler can optimize the loop since the upper bound `dim` of the
889 loop variable is known at compile time. In particular, for a point in
890 2d, the code the compiler will produce is likely to look more like this
891 because the loop can be unrolled and the loop counter can be optimized
894 double Point<2>::norm () const
896 return std::sqrt(coordinates[0] * coordinates[0] + coordinates[1] * coordinates[1]);
899 Obviously, for a 3d point, the code will look differently, but the compiler
900 can do this since it knows what the dimension of the point is at compile
903 There is another reason for the deal.II way: type safety. In short, a 2d
904 point is not the same as a 3d point. If you assign one to the other, then
905 this may be on purpose and the executable should simply change the value of
906 the `dim` member variable from 2 to 3. But it may also be a legitimate
907 error -- for example, you shouldn't be able to use 2d points to initialize
908 the 3d quadrature points needed to integrate on a 3d cell. This can of
909 course be caught by run-time checks, but the reason for strongly typed
910 languages such as C++ has always been that it is much more efficient if the
911 compiler can already catch this sort of error at compile time. Using
912 templates for the space dimension avoids these sort of mistakes up front by
913 forcing the programmer to explicitly specify her intent, rather than
914 encoding intent in assertions.
916 Of course there are also downsides to using templates. Most notably, error
917 messages that involve templates are notoriously unreadable, and that
918 compiling template heavy code is slow: for example, we have to compile the
919 `Point` class three times (for dim=1, dim=2 and dim=3) rather than only
920 once. Nevertheless, we believe that these valid objections do not outweigh
921 the benefits of templates.
923 ### Doesn't it take forever to compile templates?
925 Yes, in general it does. The reason is that while for non-templates it is
926 enough to put the ''declaration'' of a function into the header file and
927 the ''definition'' into the `.cc` file, for templates that doesn't work.
928 Let's say you have something like
930 template <typename T> T square (const T & t);
933 in your header file and you put the definition
935 template <typename T> T square (const T & t) { return t*t; }
938 into the `.cc` file, then the compiler will say "Yes, I saw this template,
939 and if I see a use of this function later on I will generate a function
940 from it by replacing `T` by whatever type you use in the call". But if
941 there is no call later on in the same `.cc` file, then the compiler won't
942 do anything. If, at the same time, in a different `.cc` file that includes
943 the header file, you use the function with `T=double` the compiler will say
944 "Yes, I saw the declaration, but there is no definition; I assume the
945 function has been compiled in a different `.cc` file with `T=double` and
946 I'll simply record a call to this instantiation in the object file". The
947 call will then be resolved at link time if indeed another object file
948 contains an instantiation of the template for `T=double`. However, if no
949 other object file contains such a definition, a linker error will result.
951 In general, for functions like the above, it is difficult to foresee what
952 kinds of template arguments the function may be instantiated for, and so
953 there is no real practical way to put the definition into a `.cc` file.
954 Rather, one puts it into a header file, and so all `.cc` files that may use
955 this function see its definition (i.e. its body) and the compiler can
956 instantiate it in each source file for whatever template argument is
957 necessary. This makes sure that you never get linker errors, but at the
958 same time it makes compiling slow since every header file now not only has
959 to parse the function's declaration, but also its definition -- and in the
960 case of deal.II the definitions of all template functions add up to tens or
961 hundreds of thousands of lines of code. This is one of the reason why many
962 C++ programs compile relatively slowly: because they use a significant part
963 of the C++ standard library, most of which consists of templates.
965 deal.II can avoid much of this overhead. The trick is to recognize that in
966 the example above we don't really know what types `T` user code may
967 possibly want to use for this template. But in the case of using the space
968 dimension as a template parameter, we know pretty exactly all the possibly
969 values: `Triangulation<dim>` may really only be instantiated for `dim=1, 2,
970 3` and for nothing else. Consequently, we can do the following: Put all the
971 definitions of the member functions of deal.II into the `.cc` file and at
972 the bottom of the file instruct the compiler to please instantiate all of
973 these templates for `dim=1, 2, 3`. Similar things can be done for many
974 other template functions in deal.II; for example, there are a good number
975 of functions that require vector types as template arguments, of which
976 deal.II provides a good number, yet this list is finite and enumerable.
977 Consequently, we can simply, at the bottom of the `.cc` file, tell the
978 compiler to instantiate all of these template functions for every single
979 vector type deal.II supports, and then don't have to put thousands of lines
980 of template definitions into header files.
982 In many cases, enumerating all possible template arguments is tedious; it
983 is also difficult to extend this list when a new vector type is added, for
984 example. To simplify this task, deal.II uses a preprocessor: for many files
985 that want to instantiate a function or class for multiple template
986 arguments, we have a file `.inst.in` that has the equivalent of a
987 `for`-loop over all possible values or types for a template argument; the
988 file is processed by the `common/scripts/expand_instantiations` program to
989 produce a `.inst` file that can then be included into the `.cc` file.
991 ### Why do I need to use `typename` in all these templates?
993 This is indeed a frequent question. To answer it, it is necessary to
994 understand how a compiler deals with templates, which will take a bit of
995 space here. Let's take for example this case:
1006 Here, in the function `void g(double)`, we call `f` with a double as an
1007 argument. Because at that point the compiler has only seen the declaration
1008 of the first overload of `f`, it will convert the double `d` to an integer
1009 and call this first overload. The fact that a second overload was declared
1010 later does not change this situation, since it wasn't visible at the time
1011 the compiler parsed `g`.
1013 Templates are designed to work essentially the same, but there are slight
1014 complications. Take this example:
1019 template <typename T> void g(T t)
1027 In the first line of `g`, the same thing happens as before: the argument is
1028 cast to `int` and the first of the two overloads of `f` is called. But when
1029 the compiler sees the template, it doesn't know yet what type `T` actually
1030 represents, so there is no way to settle on one of the two functions `f`
1031 the compiler has seen before when deciding about the second line. In fact,
1032 the C++ standard says that because the type of the argument `t` in the call
1033 depends on the template type, determining what function to actually call
1034 should only happen <i>at the time and place when the template is
1035 instantiated</i> (this is called <i>argument dependent name lookup</i> or
1036 <i>ADL</i>). In other words, if below the code above we had this:
1044 then in the instantiation of `g` the first call would be to `f(int)`
1045 (because the argument 1.1 does not depend on the type given in the template
1046 argument, and consequently only functions are considered that were seen
1047 <i>before the definition of</i> `g(T)`) whereas the second call to `f`
1048 would be to `f(double)` -- even though `f(double)` wasn't even declared at
1049 the place the compiler saw the call in the template (though it is available
1050 at the place where we instantiate `g<double>`) -- because the function call
1051 argument `t` has type `T` and therefore depends on the template argument.
1053 Argument dependent lookup allows you to use function templates like `g`
1054 with your own data types. For example, you could have your own library that
1059 struct X { /* something */ };
1061 void f (const X & x) { /* do something with the X */ }
1070 Presumably the writer of the `g` function did not know about your own type
1071 `X` yet, but her code still works because you provided a suitable overload
1072 of `f` in your own code.
1074 So ADL is clever and allows you to use templates in ways the author of the
1075 template did not anticipate. But it has a dark side: for every statement in
1076 your code, the compiler has to figure out whether it depends on the
1077 template types or not, and it needs in fact to know quite a lot about it.
1082 template <typename T>
1090 Here, is the call to `f` dependent because `p` depends on the type `T`? If
1091 `f` is called with an argument of type `X` that is declared like this
1096 typedef int something;
1100 then `T::something * p;` would declare a local variable called `p` that is
1101 of type pointer-to-int. On the other hand, if we had
1106 static double something;
1110 then `T::something * p;` multiplies the variable `X::something` by the
1111 global variable `p` and ignores the result of the multiplication. The
1112 following call to `f` would then be non-dependent because the type of the
1113 (global) variable `p` does not depend on the template argument.
1115 The example shows that the compiler can't know whether a call is dependent
1116 or not in a template it is just seeing unless we tell it that
1117 `T::something` is supposed to be a type or a variable or function name. To
1118 avoid this situation, C++ says: if a compiler sees `T::something` then this
1119 is a variable or function name unless it is prefixed by the keyword
1120 `typename` in which case it is supposed to be a type. In other words, the
1121 call to `f` here is going to be non-dependent:
1124 template <typename T>
1132 and instantiating `g` with the first example for `X` is going to lead to
1133 errors because `T::something` didn't turn out to be a variable. On the
1134 other hand, if we had
1137 template <typename T>
1140 typename T::something * p;
1145 then the call is dependent and will be deferred until the compiler knows
1148 ### Why do I need to use `this->` in all these templates?
1150 This is a consequence of the same rule in the C++ standard as discussed in
1151 the previous question, Argument Dependent Lookup of names (ADL). Consider
1154 template <typename T>
1161 template <typename T>
1162 class Derived : public Base<T>
1168 template <typename T>
1169 void Derived<T>::g()
1175 By the rules, when the compiler <i>parses</i> the function `Derived::g`
1176 (note that parsing happens before and independently of <i>instantiating</i>
1177 the function for a particular argument type `T`), it sees that the call to
1178 `f()` does not depend on the template type and so it looks for a
1179 declaration of such a function somewhere. In the example above, it doesn't
1180 find one (we'll come to this in a second), which will yield an error. On
1181 the other hand, in this code,
1183 void f(); // global function
1185 template <typename T>
1192 template <typename T>
1193 class Derived : public Base<T>
1199 template <typename T>
1200 void Derived<T>::g()
1206 it would find the global function and so when instantiating the function
1207 for, say, `T=int`, you'd get a function `Derived<int>::g` that would call
1208 the global function `::f`. This may or may not be what you had in mind.
1210 The question of course is why the compiler didn't record a call to
1211 `Base<T>::f` in `Derived<int>::g`? After all, the compiler knows that
1212 `Derived` is derived from `Base`. This has a lot to do with the fact that
1213 at the time of <i>parsing</i> the template, the compiler doesn't know for
1214 which template arguments the template will later be instantiated, and with
1215 explicit or partial specializations. Consider for example this code:
1217 template <typename T>
1230 template <> class Base<int> : public X {};
1232 template <typename T>
1233 class Derived : public Base<T>
1239 template <typename T>
1240 void Derived<T>::g()
1246 Here, if you look at `Derived<T>::g`, the call to `f()` will be resolved to
1247 `Base<T>::f` for all possible types `T`, unless `T=int` in which case the
1248 call will be to `X::f`. The point is that at the time the compiler sees
1249 (parses) the template, it simply doesn't know yet what `T` is, and so ADL
1250 says: if the call is not dependent, find a non-dependent function to record
1251 (e.g. a global function) rather than trying to find a call in scopes you
1252 can't yet know will be relevant (e.g. `Base` or `X`). Likewise, in this
1255 template <typename T>
1269 template <typename T>
1270 class Derived : public Base<T>
1276 template <typename T>
1277 void Derived<T>::g()
1283 the meaning of `f()` changes depending on the template type: if `T=int`, it
1284 creates an object of type `Base<int>>::f` and then throws the object away
1285 again immediately. For all other template arguments `T`, it calls
1288 Given this longish description of how compilers look up names under the ADL
1289 rule, let's get back to the original question: If you have this code,
1291 template <typename T>
1298 template <typename T>
1299 class Derived : public Base<T>
1305 template <typename T> void Derived<T>::g()
1311 how do you achieve that the call in `Derived::g` goes to `Base::f`? The
1312 answer is: Tell the compiler to defer the decision of what the call is
1313 supposed to do till the time when it knows what `T` actually is. And we've
1314 already seen how to do that: we need to make the call <i>dependent</i> on
1315 `T`! The way to do that is this:
1317 template <typename T>
1318 void Derived<T>::g()
1324 Here, `this` is a pointer to an object of type `Derived<T>`, which is of
1325 course dependent. So the resolution of what the statement is supposed to
1326 represent is deferred until instantiation time; at that time, however, the
1327 compiler knows what the base class is (for example it knows if there are
1328 explicit specializations) and so it knows which base classes to look into
1329 in an attempt to find a function with the name `f`.
1331 ### Does deal.II require C++11 support?
1332 The answer to this question depends on the version of deal.II that you are
1335 #### deal.II version 9.0.0
1336 As of version 9.0.0, deal.II requires C++11 support equivalent to that provided
1337 by GCC 4.8.0., which is, essentially, every new feature in C++11.
1339 #### deal.II version 8.5.0 and previous
1340 The current release of deal.II, 8.5.0, is compatible with the C++98 and C++03
1341 standards, but some features (e.g., the `LinearOperator` class) are only
1342 available if your compiler supports a subset of C++11 features. GCC 4.6 and
1343 newer implement enough of C++11 for these features to be turned on. More
1344 exactly, we currently require the following language features to be present:
1346 1. `auto`-typed variables
1347 2. The `nullptr` keyword
1348 3. Move constructors
1349 4. The `declval` and `decltype` keywords
1352 while we do not use the following features:
1354 1. Marking virtual functions as `override`
1355 2. Some features of the `type_traits` header, such as `std::is_trivially_copyable`
1356 3. Inheriting constructors
1359 The deal.II documentation has a
1360 [page](http://dealii.org/8.5.0/doxygen/deal.II/group__CPP11.html) dedicated to
1361 the issue of what parts of C++11 we use and how this works. For a more complete
1362 list of features we do and do not use see
1363 [the GCC 4.6 C++11 compatibility page](https://gcc.gnu.org/gcc-4.6/cxx0x_status.html).
1365 ### Can I convert Triangulation cell iterators to DoFHandler cell iterators?
1367 Yes. You can also convert between iterators belonging to different
1368 DoFHandlers as long as the are based on the identical Triangulation:
1371 Triangulation<2>::active_cell_iterator it = triangulation.begin_active();
1373 DoFHandler<2>::active_cell_iterator it2 (&triangulation, it->level(), it->index(), &dof_handler);
1376 ## Questions about specific behavior of parts of deal.II
1378 ### How do I create the mesh for my problem?
1380 Before answering the immediate question, one remark: When you use adaptive
1381 mesh refinement, you definitely want the initial mesh to be as coarse as
1382 possible. The reason is that you can make it as fine as you want using
1383 adaptive refinement as long as you have memory and CPU time available.
1384 However, this requires that you don't waste mesh cells in parts of the
1385 domain where they don't pay off. As a consequence, you don't want to start
1386 with a mesh that is too fine to start with, because that takes up a good
1387 part of your cell budget already, and because you can't coarsen away cells
1388 that are in the initial mesh.
1390 That said, there are essentially three ways to generate a mesh, all of
1391 which are discussed in significantly more detail in the step-49 tutorial
1393 - For many standard geometries (square, cube, circle, sphere, ...) there
1394 are functions in namespace `GridGenerator` that can generate coarse
1396 - If `GridGenerator` does not offer a mesh for the geometry you have, but
1397 if the geometry is simple, then you can often create one "by hand". Take
1398 a look, for example, at how we create the mesh in step-14 using the
1399 `Triangulation::create_triangulation` function. All you need to do is
1400 take a piece of paper, draw the geometry and a number of coarse cells
1401 that form quadrilaterals, identify the locations of vertices and the
1402 connectivity from cells to vertices, and pass the corresponding lists to
1403 the Triangulation. Something similar can be done for simple 3d
1405 - If your geometry is truly complicated enough so that you can't draw a
1406 mesh by hand any more (i.e. if it requires more than, for example, 20-30
1407 coarse mesh cells), then you'll need a mesh generator. For
1408 quadrilaterals and hexahedra, there aren't all that many mesh
1409 generators. [gmsh](http://www.gmsh.info),
1410 [lagrit](https://lagrit.lanl.gov/) and [cubit](http://cubit.sandia.gov/)
1411 come to mind. The primary problem is that most mesh generators' output
1412 meshes aren't particularly coarse by default, so you may want to pay
1413 particular attention to this point when running the mesh generator.
1414 (This is relevant since deal.II is particularly good about creating
1415 adaptively refined meshes, but if your coarse mesh is already very large
1416 then you will likely not have a lot of resources left to adaptively
1417 refine it some more.) Once you have a mesh from a mesh generator, you
1418 would read it using the `GridIn` class, as demonstrated, for example, in
1420 - As it was already mentioned, if you do need to work with a geometry for which all you have is a triangular or tetrahedral mesh, then you can convert this mesh into one that consists of quadrilaterals and hexahedra using the tethex program, see https://github.com/martemyev/tethex .
1422 ### How do I describe complex boundaries?
1424 You need to define classes derived from the `Boundary` base class and
1425 attach these to particular parts of the boundary of the triangulation. The
1426 `Triangulation` class will then query your boundary object whenever it
1427 needs a new point on the boundary after mesh refinement.
1429 In deal.II releases after 8.1, the way geometry is described has been made
1430 much more flexible. In particular, it is no longer only possible to
1431 describe the boundary, but it is also possible to describe where points in
1432 the interior lie. The step-53 tutorial program explains how this is done
1433 for a realistic example.
1436 ### I am using discontinuous Lagrange elements (`FE_DGQ`) but they don't seem to have vertex degrees of freedom!?
1438 Indeed. And here's the reason: a vertex is an entity that is shared between
1439 different cells, i.e. it doesn't belong to one cell or another. If you have
1440 a shape function that is associated with it, then its support will extend
1441 to all of the cells that are adjacent to the vertex since no cell is
1442 different than any other cell. This is what happens, for example, with the
1443 `FE_Q(1)` element. The same is true, by the way, for degrees of freedom
1444 (and associated shape functions) that correspond to edges and faces between
1447 But that doesn't answer the question of discontinuous elements. There, you
1448 have functions that are interpolation polynomials whose <i>support
1449 point</i> happens to be located at the same position as the vertex, but the
1450 actual support of the shape function is restricted to a single cell. In
1451 other words, '''logically''' these shape functions belong to a cell, not a
1452 vertex or edge or face, since the latter are all shared between adjacent
1453 cells. What this leads to is that, for example for the `FE_DGQ(1)` element,
1455 - `fe.dofs_per_vertex` is zero
1456 - `fe.dofs_per_line` is zero
1457 - `fe.dofs_per_face` is zero
1458 - `fe.dofs_per_cell` is 4 in 2d and 8 in 3d.
1459 In other words, all shape functions are associated with the cell interior.
1461 If this answer isn't quite satisfactory (because, after all, the shape
1462 functions <i>are</i> defined by interpolation at the location of the
1463 vertices), one could turn the question around: If you ask me for the degree
1464 of freedom associated with vertex 13, then I should ask you in return
1465 <i>which one</i> you have in mind since if there, say, four cells that meet
1466 at this vertex, then there will be 4 degrees of freedom defined there.
1467 Likewise, if you ask me for the value of the degree of freedom associated
1468 with vertex 13, then I should ask you in return <i>which one</i> as the
1469 function is discontinuous there and will have multiple values at the
1470 location of the vertex.
1472 ### How do I access values of discontinuous elements at vertices?
1474 The previous question answered why DG elements aren't defined at the
1475 vertices of the mesh. Consequently, functions like `cell->vertex_dof_index`
1476 aren't going to provide anything useful. Nevertheless, there are occasions
1477 where one would like to recover values of a discontinuous field at the
1478 location of the vertices, for example to average the values one gets from
1479 all adjacent cells in recovery estimators.
1481 So how does one do that? The answer is: Getting the values at the vertices
1482 of a cell works just like getting the values at any other point of a cell.
1483 You have to set up a quadrature formula that has quadrature points at the
1484 vertices and then use an FEValues object with it. If you then use
1485 FEValues::get_function_values, you will get the values at all quadrature
1486 points (i.e. vertices) at once.
1488 Setting up this quadrature formula can be done in two different ways: (i)
1489 You can create an object of type `Quadrature` from a vector of points that
1490 you can initialize with the reference coordinates of the 2<sup>dim</sup>
1491 vertices of a cell; or (ii) you can use the `QTrapez` class that has its
1492 quadrature points in the vertices. In the latter case, however, you need to
1493 verify that the order of quadrature points is indeed the same order as the
1494 vertices of a cell and, if that is not the case, translate between the two
1497 ### Does deal.II support anisotropic finite element shape functions?
1499 There is currently no easy-to-use support for this. It's not going to work
1500 for continuous elements because we assume that `fe.dofs_per_face` is the
1501 same for all faces of a cell.
1503 It may be possible to make this work for discontinuous elements, though.
1504 What you would have to do is define a bunch of different elements with
1505 anisotropic shape functions and select which element to use on which cells,
1506 using the `hp::DoFHandler` to deal with using different elements on
1507 different cells. The part that's missing is to implement elements with
1508 anisotropic shape functions. I imagine that this wouldn't be too
1509 complicated to do since the element is discontinuous, but someone would
1510 have to implement it.
1512 That said, you can do anisotropic <i>refinement</i>, which of course also
1513 introduces a kind of anisotropic approximation of your finite element
1516 ### The graphical output files don't make sense to me -- they seem to have too many degrees of freedom!
1518 Let's assume you have a 2x2 mesh and a Q<sub>1</sub> element then you would
1519 assume that output files (e.g. in VTK format) just have 9 vertex locations
1520 and 9 values, one for each of the 9 nodes of the mesh. However, the file
1521 actually shows 16 vertices and 16 such values.
1523 The reason is that frequently output quantities in deal.II are
1524 discontinuous: it may be that the finite element in use is discontinuous to
1525 begin with; or that the quantity we want to output is defined on a
1526 cell-by-cell basis (e.g. error indicators) and therefore discontinuous; or
1527 that it is a quantity computed from a DataPostprocessor object that could
1528 be discontinuous. In order to not make things more complicated than
1529 necessary, deal.II <i>always</i> assumes that quantities are discontinuous,
1530 even if some of them may in fact be continuous. The problem is that all
1531 graphical formats want to see one value for each output field per vertex.
1532 But discontinuous fields have more than one value at the location of a
1533 vertex of the mesh. The solution to the problem is then to simply output
1534 each vertex multiple times -- with different vertex numbers but at exactly
1535 the same location, once for each cell it is adjacent to. In other words, in
1536 2d, each cell has four unique vertices. The 2x2 mesh in the example
1537 therefore has 16 vertices (4 vertices for each of the 4 cells) and we
1538 output 16 values. Several of these vertices will have the same location and
1539 if the field is indeed continuous, several of the values will also be the
1542 ### In my graphical output, the solution appears discontinuous at hanging nodes
1544 Let me guess -- you are using higher order elements? If that's the
1545 case, then the solution only looks discontinuous but isn't
1546 really. What's happening is that the solution is, in fact, a higher
1547 order polynomial (e.g., a quadratic polynomial) along each edge of a
1548 cell but because all visualization file formats only support writing
1549 data as bilinear elements we need to write data in a way that shows
1550 only a linear interpolation of this higher order polynomial along each
1551 edge. This is no problem if the two neighboring elements share the
1552 entire edge because then the linear interpolations from both sides
1553 coincide. However, if we have a hanging node, then the value at the
1554 hanging node appears to float above or below the linear interpolation
1555 from the longer side, like here (in the left picture, see the gap at
1556 the bottom in the blue green area, and around the top left in the
1557 greenish area; pictures by Kevin Dugan):
1559 <img width="400px" src="http://www.dealii.org/images/wiki/gap-in-q2-1.png" align="center" />
1560 <img width="400px" src="http://www.dealii.org/images/wiki/gap-in-q2-2.png" align="center" />
1562 From this description you can already guess what the solution is: the
1563 solution is internally in fact continuous: even though we only show a
1564 linear interpolation on the long edge, the true solution actually goes
1565 through the "floating" node. All this is, consequently, just an
1566 artifact of the way visualization programs show data.
1568 If this bothers you or it simply looks bad in your graphics, you can
1569 lessen the problem by not plotting just a linear interpolation on each
1570 cell but outputting the solution as a linear interpolation on a larger
1571 number of "patches" per cell (e.g., plotting 5x5 patches per
1572 cell). This can be done by using the `DataOut::build_patches` function
1573 with an argument larger than one -- see its documentation.
1575 This all said, if you are in fact using a Q1 element and you see such
1576 gaps in the solution, then something is genuinely wrong. One
1577 possibility is that you forget to call `ConstraintMatrix::distribute`
1578 after solving the linear system, or you do not set up these
1579 constraints correctly. In either case, it's a bug if this happens with
1582 ### When I run the tutorial programs, I get slightly different results
1584 This is sometimes unavoidable. deal.II uses a number of iterative
1585 algorithms (e.g. in solving linear systems, but the adaptive mesh
1586 refinement loop is also an iteration if you think about it) where certain
1587 criteria are specified by comparing floating point numbers. For example,
1588 the CG method terminates the iteration whenever the residual drops below a
1589 certain threshold; similarly, we refine as many cells as are necessary to
1590 take care of a fraction of the total error. In both cases, the quantities
1591 that are compared are floating point numbers which are subject to floating
1592 point round off. The problem is that floating point round off depends on
1593 the processor (sometimes), compiler flags or randomness (if parallelization
1594 is involved) and consequently an a solver may terminate one iteration
1595 earlier or later, depending on your environment, than the one from which we
1596 produced our results. With a different solution typically come different
1597 refinement indicators and different meshes downstream.
1599 In other words, this is something that simply happens. What should worry
1600 you, however, is if you run the same program twice and you get slightly
1601 different output. This hints at non-deterministic effects that one should
1604 ### How do I access the whole vector in a parallel MPI computation?
1606 Note that this causes a bottleneck for large scale computations and you
1607 should try to use a parallel vector with ghost entries instead. If you
1608 really need to do this, create a TrilinosWrappers::Vector (or a
1609 PETScWrappers::Vector) and assign your parallel vector to it (or use a copy
1610 constructor). You can find this being done in step-17 if you search for
1611 "localized_solution".
1613 ### How to get the (mapped) position of support points of my element?
1615 Option 1: The support points on the unit cell can be accessed using
1616 FiniteElement::get_unit_support_point(s) and mapped to real coordinates
1617 using Mapping::transform_unit_to_real_cell()
1619 Option 2: DoFTools::map_dofs_to_support_points() maps all the support
1622 Option 3: You can create a FEValues object using the support points as a
1625 Quadrature<dim> q(fe.get_unit_support_points());
1626 FEValues<dim> fe_values (..., q, update_q_points);
1628 fe_values.get_quadrature_points();
1632 ## Debugging deal.II applications
1634 ### I don't have a whole lot of experience programming large-scale software. Any recommendations?
1636 Yes. First, the questions of this FAQ already give you a number of good
1637 pointers for example on debugging. Also, a good resource for some of the
1638 questions mathematicians, scientists and engineers (who may have taken a
1639 programming course, but know little of the bigger world of software
1640 engineering) typically have, is the [Software
1641 Carpentry](http://software-carpentry.org/) page. That site is specifically
1642 targeted at people who may want to use scientific computing to solve
1643 particular applications, but have little or no formal training in dealing
1644 with large software. In other words, it is specifically written for people
1645 for an audience like the users of deal.II.
1648 ### Are there strategies to avoid bugs in the first place?
1650 Why yes, good you ask. There are indeed techniques that help you avoid
1651 writing code that has bugs. By and large, these techniques go by the name
1652 <i>defensive programming</i>, and the idea is to get yourself into a
1653 mindset while programming that anticipates that you will make mistakes,
1654 rather than expecting that your code is correct and then reacting to the
1655 situation when it turns out that this isn't true. The point is that even
1656 the most experienced programmers do introduce a lot of bugs into their
1657 code; what makes them good is that they have strategies to find them
1658 quickly and systematically.
1660 Below we show one of the most important lessons learned. A more complete
1661 list can be found in [our code conventions
1662 page](http://dealii.org/developer/doxygen/deal.II/CodingConventions.html)
1663 which has a collection of best practices including code snippets to show
1666 The single most successful strategy to avoid bugs is to <i>make assumptions explicit</i>. For example, assume for a second that you have a class that denotes a point in 3d space:
1671 double coordinate (const unsigned int i) const;
1674 double coordinates[3];
1678 Point3d::coordinate (const unsigned int i) const
1680 return coordinates[i];
1684 Here, when we wrote the `coordinate()` function, we worked under the
1685 assumption that the index `i` is between zero and two. As long as that
1686 assumption is satisfied, everything is fine. The problems start when
1687 someone calls this function with an index greater than two -- the function
1688 will in that case simply return garbage, but that may not be immediately
1689 obvious and may only much later lead to weird results in your program.
1690 Inexperienced programmers will say "Why would I do that, it doesn't make
1691 any sense!". Defensive programming starts from the premise that this is
1692 something that simply <i>will happen</i> at one point in time, whether you
1693 want to or not. It's actually not very difficult to do, since all of us
1694 have probably written code like this:
1697 // ... do something with it
1699 for (unsigned int i=0; i<=3; ++i)
1700 norm += point.coordinate(i) ** point.coordinate(i);
1701 norm = std::sqrt(norm);
1704 Note that we have accidentally used `<=` instead of `<` in the loop.
1706 If we accept that bugs will happen, we should make it as simple as possible
1707 to find them. In the spirit of making assumptions explicit, let's write
1708 above function like this:
1711 Point3d::coordinate (const unsigned int i) const
1715 std::cout << "Error: function called with invalid argument!" << std::endl;
1718 return coordinates[i]
1722 This has the advantage that an error message is produced whenever the
1723 function is called with invalid arguments, and for good measure we also
1724 abort the program to make sure the error message can really not be missed
1725 in the rest of the output of the program. The disadvantage is that this
1726 check will always be performed whenever the program runs, even if it is
1727 well tested and we are fairly certain that in all places where the function
1728 is called, indices are valid. To avoid this drawback, the C programming
1729 language has the `assert` macro, which expands to the code above by
1730 default, but that can be disabled using a compiler flag. deal.II provides
1731 an improved version of this macro that is used as follows:
1734 Point3d::coordinate (const unsigned int i) const
1736 Assert (i<3, ExcMessage ("Function called with invalid argument!"));
1737 return coordinates[i];
1741 The macro expands to nothing in optimized mode (see below), and if it is
1742 triggered in debug mode it doesn't only abort the program, but also prints
1743 an error message and shows how we got to this point in the program.
1745 Using assertions in your program is the single most efficient way to make
1746 assumptions explicit and help find bugs in your program as early as
1747 possible. If you are looking for some more background, check out the
1748 wikipedia articles on
1749 [assertions](http://en.wikipedia.org/wiki/Assertion_(computing)),
1750 [preconditions](http://en.wikipedia.org/wiki/Precondition) and
1751 [postconditions](http://en.wikipedia.org/wiki/Postcondition), and generally
1752 the [design by contract
1753 methodology](http://en.wikipedia.org/wiki/Design_by_contract).
1755 ### How can deal.II help me find bugs?
1757 In addition to using the `Assert` macro introduced above, the deal.II
1758 libraries come in two flavors: debug mode and optimized mode. The
1759 difference is that the debug mode libraries contain a lot of assertions
1760 that verify the validity of parameters you may pass when calling library
1761 functions and classes; the optimized libraries don't contain these and are
1762 compiled with flags that instruct the compiler to optimize. This makes
1763 executables linked against the optimized libraries between 4 and 10 times
1764 faster. On the other hand, you will find that you will find 90% or more of
1765 your bugs by using the debug libraries because most bugs simply pass data
1766 to other functions that they don't expect or that don't make sense. The
1767 consequence is that you should always use debug mode when you are still
1768 developing your code. Only when it runs without bugs -- and under no
1769 circumstances any earlier -- should you switch to optimized mode to do
1770 production runs. One of the silliest things you can do is switch to
1771 optimized mode because you otherwise get an error you can't make sense of
1772 and that you don't know how to fix; certainly, if the library complains
1773 about something and you ignore it, nothing good can come out of the
1774 remainder of the run of your program.
1776 You can switch between debug and optimized mode, at least for the example
1777 programs, by compiling the example with either `make debug` or `make
1778 release`. There are further
1779 [instructions](https://www.dealii.org/8.3.0/users/cmakelists.html#cmakesimple.build_type)
1780 in the documentation describing how to set this up in your own codes.
1782 ### Should I use a debugger?
1784 This question has an emphatic, unambiguous answer: Yes! You may get by for
1785 a while by just putting debug output into your program, compiling it, and
1786 running it, but ultimately finding bugs with a debugger is much faster,
1787 much more convenient, and more reliable because you don't have to recompile
1788 the program all the time and because you can inspect the values of
1789 variables and how they change. Learn how to use a debugger as soon as
1790 possible. It is time well invested.
1792 Debuggers come in a variety of ways. On Linux and other Unix-like operating
1793 systems, they are almost all based in one way or other on the [GNU Debugger
1794 (GDB)](http://www.gnu.org/s/gdb/). GDB itself is a tool that is driven by
1795 interactively typing commands; if you know your way around with it, it is
1796 quite usable but it is rather austere and unless you are already familiar
1797 with this style of debugging, don't learn it. Rather, you should either use
1798 a graphical front-end or, even better, a front-end to GDB that is
1799 integrated into an Integrated Development Environment (IDE). An example of
1800 the stand-alone graphical front-ends to GDB are
1801 [DDD](http://www.gnu.org/software/ddd/), a program that was the first of
1802 its kind on Linux for many years but whose development has pretty much
1803 ceased in the early 2000s; it is still quite a good program, though.
1804 Another example is [KDbg](http://kdbg.org/), a GDB front-end for the KDE
1805 desktop environment.
1807 As mentioned, a better choice is to use a debugger front-end that is
1808 integrated into the IDE. Every decent IDE has an integrated debugger, so
1809 you have your choice. A list of IDEs and how they work with deal.II is
1810 given in the C++ section of this FAQ.
1812 ### deal.II aborts my program with an error message
1814 You are likely seeing something like the following:
1816 --------------------------------------------------------
1817 An error occurred in line <1223> of file </.../dealii/include/deal.II/lac/vector.h> in function
1818 Number& dealii::Vector<Number>::operator()(dealii::Vector<Number>::size_type)
1819 [with Number = double; dealii::Vector<Number>::size_type = unsigned int]
1820 The violated condition was:
1822 The name and call sequence of the exception was:
1823 ExcIndexRangeType<size_type>(i,0,vec_size)
1824 Additional Information:
1825 Index 10 is not in the half-open range [0,10).
1829 #0 ./deliberate-mistake: foo()
1830 #1 ./deliberate-mistake: main
1831 --------------------------------------------------------
1835 This error is generated by the following program:
1837 #include <deal.II/lac/vector.h>
1838 using namespace dealii;
1842 Vector<double> x(10);
1843 for (unsigned int i=0; i<=x.size(); ++i)
1854 So what to do in a case like this? The first step is to carefully read what
1855 the error message actually says as it contains pretty much all the
1856 information you need. So let's take the error message apart:
1858 - The first two lines tell you where the problem happened: in the current
1859 case, in line 1223 of file
1860 `/.../dealii/include/deal.II/lac/vector.h` in the function
1861 `Number& dealii::Vector<Number>::operator()(dealii::Vector<Number>::size_type)`.
1862 This is a function in the library, so you likely don't know what exactly it
1863 does and what to do with it, but there is more information to come.
1865 - The second part is the condition that should have been true but wasn't,
1866 leading to the error: `i<vec_size`. The variables involved in this
1867 condition (`i,vec_size`) are local variables of the function, or member
1868 variables of the class, so again you may not be entirely familiar with
1869 them. But you can already gather some of the information: `i` likely is
1870 an index, which should have been less than the variable `vec_size`
1871 (which sounds a lot like the length of a vector); the assertion says
1872 that it <i>should</i> have been smaller, but that it wasn't actually.
1874 - There is more information: The exception generated is of kind
1875 `ExcIndexRange<size_type>(i,0,vec_size)` and the additional information says
1876 `Index 10 is not in the half-open range [0,10)`. In other words, the variable
1877 `i` has value `10`, and `vec_size` is also ten. This should already give you
1878 a fairly good idea what is happening: the vector has size ten, and following
1879 C array convention, that means that only indices zero through nine are value,
1882 - The final part of the error message -- the stack trace -- tells you how
1883 you got to this place: reading from the bottom, `main()` called `foo()`
1884 which called the function that generated the error.
1886 Taken together, this information should allow you figure out in 80% of
1887 cases what was going on, and fix the problem. Here, it is that we used the
1888 condition `i<=x.size()` in the loop, rather than the correct condition
1889 `i<x.size()`. In the remaining 20% of cases, things might be more
1890 difficult. For example, `foo()` might be a large and difficult function,
1891 and you would need to know in which part of the function did we access an
1892 invalid index of the vector. Or `i` was an index computed from other
1893 variables and you'd need to find out why it got the invalid value. In these
1894 cases, you'll have to learn how to use a debugger such as gdb, and in
1895 particular how to move up and down in the call stack and to inspect local
1896 variables in your source code.
1898 ### The program aborts saying that an exception was thrown, but I can't find out where
1900 deal.II creates two kinds of exceptions (in deal.II language): ones where we
1901 simply abort the program because you are doing something that can't be right
1902 (such as accessing element 11 of a 10-element vector; this results in what has
1903 been discussed in the previous question) and ones that use the C++ construct
1904 `throw` to raise an exception. The latter construct is used for things that
1905 can't be statically checked in debug mode because they may depend on values
1906 read from input files or on a status that may simply change from one run of
1907 the program to the next; consequently, they <i>always</i> need to be verified,
1908 not only in debug mode, and there is sometimes a way to work around it in a
1909 program. The typical case is trying to write to a file that can't be opened
1910 (e.g. because the directory/file you specified in a parameter file doesn't
1911 exist or because the file system has run out of disk space).
1913 Most of the time, the exceptions deal.II throws are annotated with the
1914 location and function where this exception was raised, and if you use a
1915 `main()` function such as the one used starting in step-6, this information
1916 will be printed. However, there are also cases where this kind of information
1917 is not available and then it is often difficult to establish where exactly the
1918 problem is coming from: all you know is that an exception was thrown, but not
1921 To debug such problems, two approaches have proven useful:
1923 - Run your program in a debugger (see the question about debuggers above,
1924 as well as these videos showing how to use the debugger in
1925 22c8e221823811aa1178b450171824af:
1926 http://www.math.tamu.edu/~bangerth/videos.676.8.html,
1927 http://www.math.tamu.edu/~bangerth/videos.676.25.html). You need to
1928 instruct the debugger to stop whenever an exception is thrown. If you
1929 work with gdb on the command line, then issue the command `catch throw`
1930 before starting the program and it will stop everytime the code executes
1931 a `throw` statement. Integrated development environments typically also
1932 have ways of switching this on. Note that not every exception that is
1933 thrown actually indicates an error -- sometimes, there are legitimate
1934 reasons to throw an exception and catch it in the calling function, so
1935 you may have to continue (resume) a number of times before finding the
1936 place where this happens.
1938 - Debugging by subtraction: Starting at the end of your program, remove
1939 one function/code block after the other until your program runs through
1940 without aborting. For example, if your program looked like step-6, see
1941 if it runs through if you don't create graphical output in `run()`. If
1942 it does, then you know that the exception must have been thrown in the
1943 block of code you just removed. If the program continues to abort, then
1944 reduce the number of mesh refinement cycles to find out within which
1945 cycle the problem happens. If it happens in the very first cycle, then
1946 remove calling the linear solver. If the program now runs through, then
1947 the problem happened in the solver. If it still aborts, then it must
1948 have happened before the solver, for example in the assembly. Repeating
1949 this, you will be able to narrow down which statement caused the
1950 problem, and knowing where a problem happens is already more than half
1951 of what you need to know to fix it.
1954 ### I get an exception in `virtual dealii::Subscriptor::~Subscriptor()` that makes no sense to me!
1956 The full text of the error message probably looks something like this (the
1957 stack trace at the bottom is of course different in your code):
1959 An error occurred in line <103> of file </.../deal.II/source/base/subscriptor.cc> in function
1960 virtual dealii::Subscriptor::~Subscriptor()
1961 The violated condition was:
1963 The name and call sequence of the exception was:
1964 ExcInUse (counter, object_info->name(), infostring)
1965 Additional Information:
1966 Object of class N6dealii15SparsityPatternE is still used by 5 other objects.
1967 from Subscriber SparseMatrix
1971 #0 /.../deal.II/lib/libdeal_II.g.so.7.0.0: dealii::Subscriptor::~Subscriptor()
1972 #1 /.../deal.II/lib/libdeal_II.g.so.7.0.0: dealii::SparsityPattern::~SparsityPattern()
1973 #2 /.../deal.II/lib/libdeal_II.g.so.7.0.0: dealii::BlockSparsityPatternBase<dealii::SparsityPattern>::reinit(unsigned int, unsigned int)
1974 #3 /.../deal.II/lib/libdeal_II.g.so.7.0.0: dealii::BlockSparsityPattern::reinit(unsigned int, unsigned int)
1975 #4 /.../deal.II/lib/libdeal_II.g.so.7.0.0: dealii::BlockSparsityPattern::copy_from(dealii::BlockCompressedSimpleSparsityPattern const&)
1976 #5 ./step-6: NavierStokesProjectionIB<2>::setup_system()
1977 #6 ./step-6: NavierStokesProjectionIB<2>::run(bool, unsigned int)
1981 What is happening is this: deal.II derives a bunch of classes from the
1982 `Subscriptor` base class and then uses the `SmartPointer` class to point to
1983 such objects. `SmartPointer` is actually a fairly simple class: when given
1984 a pointer, it increases a counter in the `Subscriptor` base of the object
1985 pointed to by one, and when the pointer is reset to another object or goes
1986 out of scope, it decreases the counter again. (It can also records
1987 <i>who</i> points to this object.) If someone tries to delete the object
1988 pointed to, then the destructor `dealii::Subscriptor::~Subscriptor()` is
1989 run and checks that in fact the counter in this object is zero, i.e. that
1990 nobody is pointing to the object any more -- because if some pointer was
1991 still pointing to it, it would be a poor decision to delete the object as
1992 then the pointer would point to invalid memory. If the counter is nonzero,
1993 you get the error above: you are trying to delete an object that is still
1994 pointed to. In the case above, you try to delete a `SparsityPattern` object
1995 (that is, from the stack trace, a part of a block sparsity pattern) even
1996 though there is still a `SparseMatrix` pointing to it (we get this from the
1997 "Additional Information" field).
1999 The solution in cases like these is to make sure that at the time you
2000 delete the object, no other objects still have pointers that point to it.
2002 There is one rather frequent case that results in an error like the above
2003 and that is often difficult to understand: if an exception is thrown in
2004 some function and not caught, all local objects are destroyed in the
2005 opposite order of their declaration; if it isn't caught in the function
2006 that called the place where the exception was generated, its local
2007 variables are also destroyed, and so on. This automatic destruction of
2008 objects typically bypasses all the clean-up code you may have at the end of
2009 a function and can then lead to errors like the above. For example, take
2016 // initialize sp somehow
2019 // build a linear system
2021 solve_linear_system (s, v);
2027 If the code executes normally, at the bottom of the function, the local
2028 variables `s,sp,v` will be destroyed in reverse order. Since we have called
2029 `s.reinit()`, the object no longer stores a pointer to `sp` and so
2030 destruction of `sp` before `s` incurs no harm. But if the function
2031 `solve_linear_system` throws an exception, for example because the linear
2032 system is singular, the call to `s.reinit()` isn't executed any more, and
2033 you will get an error like the one shown at the top.
2035 In cases like these, the challenge becomes finding where the exception was
2036 thrown. The easiest way is to run your program in a debugger and let the
2037 debugger tell you whenever an exception is generated. In `gdb`, you can do
2038 that by saying `catch throw` before running the program; essentially, the
2039 command puts a breakpoint on all places where exceptions are thrown.
2040 Remember, however, that not every place where an exception is thrown is a
2041 candidate for the problem above: it may also be an exception that is caught
2042 in the function above and that never propagates to a point where it
2043 produces trouble. Consequently, it may well happen that you have to
2044 continue several times after seeing an exception thrown until you finally
2045 find the place where the offending exception happens.
2047 ### I get an error that the solver doesn't converge. But which solver?
2049 Solvers are often deeply nested -- take a look for example at step-20 or
2050 step-22, where there is an outer solver for a Schur complement matrix, but
2051 both in the implementation of the Schur complement as well as in the
2052 implementation of the preconditioner we solve other linear problems which
2053 themselves may have to be preconditioned, etc. So if you get an exception
2054 that the solver didn't converge, which one is it?
2056 The way to find out is to not wait till the exception propagates all the
2057 way to `main()` and display the error code there. Rather, you probably
2058 don't have a Plan B anyway if a solver fails, so you may want to abort the
2059 program if that happens. To do this, wrap the call to the solver in a
2060 try-catch block like this:
2064 cg.solve (system_matrix, solution, system_rhs, preconditioner);
2068 std::cerr << "*** Failure in Schur complement solver! ***" << std::endl;
2073 Of course, if this is in the Schur preconditioner, you may want to use a
2074 different error message. In any case, what this code does is catch the
2075 exceptions thrown by the solver here, or by the system matrix's `vmult`
2076 function (if not already caught there) or by the preconditioner (if not
2077 already caught there). If you had already caught exceptions in the `vmult`
2078 function and in the preconditioner, then you now know that any exception
2079 you get at this location must have been because the CG solver failed, not
2080 the preconditioner, etc. The upshot is that you need to wrap <i>every</i>
2081 call to a solver with such a try-catch block.
2083 ### How do I know whether my finite element solution is correct? (Or: What is the "Method of Manufactured Solutions"?)
2085 This is not always trivial, but there is an "industry-standard" way of
2086 verifying that your code works as intended, called the '''method of
2087 manufactured solutions'''. Before we describe the method, let us point this
2088 out: '''A code that has not been verified (i.e. for which correctness has
2089 not been established) is worthless. You do not want to have results in your
2090 thesis or a publication that may later turn out to be incorrect because
2091 your code does not converge to the correct solution!'''
2093 The idea to verify a code is that you need a problem for which you know the
2094 exact solution. Unless you solve the very simplest possible partial
2095 differential equations, it is typically not possible to choose a right hand
2096 side and boundary values and then find the corresponding solution to the
2097 PDE analytically, on a piece of paper. But you can turn this around: Let's
2098 say your equation is <i>Lu=f</i>, then choose some function <i>u</i> and
2099 compute <i>f=Lu</i>. Note that the solution <i>u</i> does not necessarily
2100 have to be something that looks like a useful or physically reasonable
2101 solution to the equation, all that is necessary is that it is a function
2102 you know. Because <i>L</i> is a differential operator, computing <i>f</i>
2103 only involves computing the derivatives of the known function; this may
2104 yield lengthy expressions if you have nonlinearities or spatially variable
2105 coefficients in the equation, but should not be too complicated and can
2106 also be done using computer algebra programs such as Maple or Mathematica.
2108 If you now put this particular right hand side <i>f</i> into your program
2109 (along with boundary values that correspond to the values of the function
2110 <i>u</i> you have chosen) you will get a numerical solution
2111 <i>u<sub>h</sub></i> that we would hope converges against the exact
2112 solution <i>u</i> at a particular rate, say <i>O(h<sup>2</sup>)</i> in the
2113 <i>L<sub>2</sub></i> norm. But since you know the exact solution (you have
2114 chosen it before), you can compute the error between numerical solution and
2115 exact solution, and verify not only that your code converges, but also that
2116 it shows the convergence rate you expect.
2118 The method of manufactured solutions is shown in the step-7 tutorial
2121 ### My program doesn't produce the expected output!
2123 There are of course many possible causes for this, and you need to find out
2124 which of these causes might be the reason. Possible places to start are:
2126 - Are matrix and right hand side assembled correctly? For most reasonably
2127 simple problems, you can compute the local contributions to these
2128 matrices by hand, and then compare those with the ones you compute on
2129 every cell of your program (remember that you can print the contents of
2130 the local matrix and right hand side to screen). A good strategy is also
2131 to reduce your problem to a 1x1 or 2x2 mesh and then print out the
2132 entire system matrix for comparison.
2134 - Do you compute the matrix you need, or its transpose? The mathematical
2135 literature often multiplies the equation from the right with a test
2136 function but that is awkward because the matrix you get this way is the
2137 transpose from the one you need. The deal.II documentation goes to
2138 lengths in multiplying test functions from the left to avoid this sort
2139 of error; do the same in your derivations.
2141 - Your constraints or boundary values may be wrong. While the
2142 ConstraintMatrix and functions like
2143 VectorTools::interpolate_boundary_values are well enough tested that
2144 they are unlikely candidates for problems, you may have computed
2145 constraints wrongly if you collect them by hand (for example if you deal
2146 with periodic boundary conditions or similar) or you may have specified
2147 the wrong boundary indicator for a Dirichlet boundary condition. Again,
2148 the solution is to reduce the problem to the simplest one you can find
2149 (e.g. on the 1x1 or 2x2 mesh talked about above) and to ask the
2150 ConstraintMatrix to print its contents so that you can compare it by
2151 hand with your expectations.
2153 - Your discretization might be wrong. Some equations require you to use
2154 particular (combination of) finite elements; for example, for the Stokes
2155 equations and many other saddle point problems, you need to satisfy an
2156 LBB or Babuska-Brezzi condition. For other equations, you need to add
2157 stabilization terms to the bilinear form; for example, advection or
2158 transport dominated problems require stabilization terms such as
2159 artificial diffusion, streamlinear diffusion, or SUPG.
2161 - The solver might be wrong. This can reasonably easily happen if you have
2162 a complex solver such as, for example, the one used in step-22. In such
2163 cases it has proven useful to simply replace the entire solver by the
2164 sparse direct UMFPACK solver (see step-29). UMFPACK is not the fastest
2165 solver around, but it never fails: if the linear system has a solution,
2166 UMFPACK will find it. If the output of your program is essentially the
2167 same as before, then the solver wasn't your problem.
2169 - Your assumptions may be wrong. Double check that you had the correct
2170 right hand side to compute the numerical solution you compare against
2171 your analytical one. Also remember that the numerical solution is
2172 usually only an approximation of the true one.
2174 In general, if your program is not computing the output you expect, here
2175 are a few strategies that have often worked in finding the problem:
2176 - Take a good look at the output you get. For example, a close look can
2177 already tell you if (i) the boundary conditions are correct, (ii) the
2178 solution is continuous at hanging nodes, (iii) the solution follows the
2179 characteristics of the right hand side. This may already help you narrow
2180 down which part of the program may be the culprit. A common mistake is
2181 also to have a solution that by some accident is too large by a certain
2182 factor; consequently, the error will not converge to zero but to some
2183 constant value. This, again, is easily visible from a graphical
2184 representation of the solution and/or the error. Plotting the error is
2185 discussed in the section below entitled "How to plot the error as a
2186 pointwise function".
2187 - If you have a time dependent problem, is the first time step right?
2188 There is no point in running the program for 1000 time steps and trying
2189 to find our why it is wrong, if already the first time step is wrong.
2190 - If you still can't find what's going on, make the program as small as
2191 possible. Copy it to another directory and start stripping off parts
2192 that you don't need. For example, if it is a time dependent program for
2193 which you have previously already found out that the first time step is
2194 wrong, then remove the time loop. If you have tried whether you have the
2195 same problem when the mesh is uniformly refined, then throw out all the
2196 code that deals with adaptive refinement, constraints and hanging nodes.
2197 In this process, every time you simplify the program, verify that the
2198 problem is still there. If the problem disappears, you know that it must
2199 have been in the last simplification step. If the problem remains, it
2200 must be in the code that is now one step smaller. Ultimately, the code
2201 should be small enough so that you can just go through it and find the
2202 error by inspection.
2203 - Learn to use a debugger. You will find that using a debugger is so much
2204 more convenient than trying to put screen output statements into your
2205 code, recompiling, and hoping that they reveal the problem. Modern
2206 integrated development environment as the ones discussed elsewhere in
2207 this FAQ have the debugger built-in, allowing you to use it seamlessly
2208 in your editing environment.
2210 ### The solution converges initially, but the error doesn't go down below 10<sup>-8</sup>!
2212 First: If the error converges to zero, then you are basically doing
2213 something right already. Congratulations!
2215 As for why the error does not converge any further, there are two typical
2216 cases what could be the reason:
2218 - While the discretization error should converge to zero, the error of
2219 your numerical solution is composed of both the discretization error and
2220 the error of your linear or nonlinear solver. If, for example, you solve
2221 the linear system to an accuracy of 10<sup>-5</sup>, then there will be
2222 a point where the discretization error will get smaller than that by
2223 using finer and finer meshes but the solver error will not become
2224 smaller any more. To continue observing the correct convergence order,
2225 you will also have to solve the linear system with more accuracy.
2227 - If you compute the error through an external program, for example by
2228 writing out the solution to a file and reading it from another program
2229 that knows about the exact solution, then you need to make sure you
2230 write the solution with sufficient accuracy. The default setting of C++
2231 writes floating point numbers with approximately 8 digits, so if you
2232 want to make sure that your solution is correct to 10<sup>-10</sup>, for
2233 example, you'll have to write out the solution with more than 10 digits.
2236 ### My code converges with one version of deal.II but not with another
2238 That is a tough case because the problem could literally be anywhere in the functions you call from deal.II.
2239 Rather than trying to start debugging blindly to find out what exactly is going on it's probably more productive to delineate the steps one could use to narrow down where the problem is.
2241 In an ideal world, you would have already found out which commit in the history of deal.II caused the problem.
2242 Let's say you have checked out the two offending versions of deal.II into separate source directories `dealii-good` and `dealii-bad`, and that you compiled them both separately and installed them into directories `install-good` and `install-bad`. If you can't find out which commit caused the problem, the good and bad versions could also be the last two releases.
2244 Let's also say that you have a directory `application` in which you have your own code.
2245 Now create two directories, `app-good`, `app-bad` parallel to `application`. Then do
2249 ln -s $i ../app-good/$i
2250 ln -s $i ../app-bad/$i
2253 This way you have two directories in which you can configure, compile, and run the exact same version of your application (exact same because they both contain links to the exact same source files), just compiled against the good and bad versions of the library, respectively.
2258 cmake . -DDEAL_II_DIR=.../install-good
2262 cmake . -DDEAL_II_DIR=.../install-bad
2265 If you run in these two directories, e.g., in two separate xterm windows, you will get one working and one failing run. Now start modifying the source files in `application` to figure out where the first point in the program is where there are differences. For example, after assembly, you could do insert a statement of the form
2267 std::cout << "Linear system: " << system_matrix.l1_norm() << ' ' << system_rhs.l2_norm() << std::endl;
2269 I would suspect (though that doesn't have to be true -- but just assume for the moment) that if you compile and run this modification in your two windows that you will get different results. At this point, you can remove everything that is executed after this point from your program -- likely a few hundred lines of code. Or, if you're too lazy, just put `abort()` after that statement because everything that comes after it clearly only shows symptoms but not the cause of the problem.
2271 Now that you know that the problem exists at the end of assembly, make your way further forward in the program. For example, is the local matrix on the first cell on which you assemble the same between the two programs? If it is, the problem is on a later cell. If it isn't the same, try to think about what the cause may be. Is the mesh the same? You can test that by putting output into an earlier spot of the program; if that output is different between the two programs, you can again delete everything that happens after that point.
2273 The whole exercise is designed to find the first place in the program where you can unambiguously say that something has changed. Non-convergence is just such a non-specific problem that it is not helpful in finding what exactly is going on. It also happens rather late in typical programs that there are too many possibilities for where the root cause may be.
2275 ### My time dependent solver does not produce the correct answer!
2277 For time dependent problems, there are a number of other things you can try
2278 over the discussion already given in the previous answer. In particular:
2280 - If you have a time iteration and the solution at the final time (where
2281 you may evaluate the error) is wrong, then it was likely already wrong
2282 at the first time step. Try to run your program only for a single time
2283 step and make sure the solution there is correct. For example, it could
2284 be that you set the boundary values wrongly; this would be quite
2285 apparent if you looked at the first time step because the effect would
2286 be largest close to the boundary, but it may no longer be visible if you
2287 ran your program for a couple hundred time steps.
2289 - Are your initial values correct? Output the initial values using DataOut
2290 just like you output the solution and inspect it for correctness.
2292 - If you have a multi-stage time stepping scheme, are *all* the initial
2295 - Finally, you can test your scheme by setting the time step to zero. In
2296 that case, the solution at time step zero should of course be equal to
2297 the solution at time step zero. If it isn't, you already know better
2300 ### My Newton method for a nonlinear problem does not converge (or converges too slowly)!
2302 Newton methods are tricky to get right. In particular, they sometimes
2303 converge (if slowly) even though the implementation has a bug because all
2304 that is required for convergence is that the search direction is a
2305 direction of descent; consequently, if for example you have the wrong
2306 matrix, you may compute something that is a direction of descent, but not
2307 the full Newton direction, and so converges but not at quadratic order.
2309 Here are a few considerations for implementing Newton's method for
2312 - Try it with a linear program by removing all the nonlinearities in your
2313 problem. Your Newton iteration must converge in a single step, i.e. the
2314 Newton residual must be zero at the beginning of the second iteration.
2315 If that's not the case, something is wrong in your implementation.
2317 - Newton's iteration will converge with optimal order for the problem
2318 *R(u)=0*, where *R* may be thought of as a residual, if you
2319 <i>consistently</i> compute the Newton residual
2320 *(φ<sup>i</sup>, R(u<sup>k</sup>))* and the Newton (Jacobian) matrix
2321 *R'(u<sup>k</sup>)*. If you have
2322 a bug in either of the two, your method may converge, but typically at a
2323 (much) lower rate and with consequently many more iterations.
2325 Consequently, one way to debug Newton's methods is to verify that the Newton
2326 matrix and Newton residual are matching in their code. However, if you
2327 have a matching bug in <i>both</i> of the matrix and right hand side
2328 assembly, then your Newton method will converge with correct order but
2329 against the wrong solution.
2331 - If you have nonzero boundary values for your problem, set the correct
2332 boundary values for the initial guess and use zero boundary values for
2333 all following updates. This way, the updated
2334 *u<sup>k+1</sup> = u<sup>k</sup> + δ u<sup>k</sup>*
2335 already has the right boundary values for all following iterations, where
2336 *δ u<sup>k</sup>* is the Newton update.
2338 - If your problem is strongly nonlinear, you may need to employ a line
2339 search where you compute
2340 *u<sup>k+1</sup> = u<sup>k</sup> + α δ u<sup>k</sup>*
2341 and successively try *α=1, α=1/2, α=1/4*, etc., until the
2342 residual computed for *u<sup>k+1</sup>* for this *α* is smaller than
2343 the residual for *u<sup>k</sup>*.
2345 - A rule of thumb is that if your problem is strongly nonlinear, you may
2346 need 5 or 10 iterations with a step length *α* less than one, and
2347 all following steps use the full step length *α=1*.
2349 - For most reasonably behaved problems, once your iteration reaches the
2350 point where it takes full steps, it usually converges in 5 or 10 more
2351 iterations to very high accuracy. If you need significantly more than 10
2352 iterations, something is likely wrong.
2354 ### Printing deal.II data types in debuggers is barely readable!
2356 Indeed. For example, plain gdb prints this for cell iterators:
2358 $2 = {<dealii::TriaIterator<dealii::DoFCellAccessor<dealii::DoFHandler<2, 3> > >> = {<dealii::TriaRawIterator<dealii::DoFCellAccessor<dealii::DoFHandler<2, 3> > >> = {<std::iterator<std::bidirectional_iterator_tag, dealii::DoFCellAccessor<dealii::DoFHandler<2, 3> >, long, dealii::DoFCellAccessor<dealii::DoFHandler<2, 3> >*, dealii::DoFCellAccessor<dealii::DoFHandler<2, 3> >&>> = {<No data fields>},
2359 accessor = {<dealii::DoFAccessor<2, dealii::DoFHandler<2, 3> >> = {<dealii::CellAccessor<2, 3>> = {<dealii::TriaAccessor<2, 2, 3>> = {<dealii::TriaAccessorBase<2, 2, 3>> = {
2360 static space_dimension = <optimized out>, static dimension = <optimized out>,
2361 static structure_dimension = <optimized out>, present_level = -9856,
2362 present_index = 32767, tria = 0x4a1556}, <No data fields>}, <No data fields>},
2363 static dimension = 2, static space_dimension = 3, dof_handler = 0x7fffffffdac8},
2364 static dim = <optimized out>,
2365 static spacedim = <optimized out>}}, <No data fields>}, <No data fields>}
2368 Fortunately, this can be simplified to this:
2371 triangulation = 0x4a1556,
2372 dof_handler = 0x7fffffffdac8,
2378 All you need is (i) gdb version 7.1 or later, or a graphical frontend for
2379 it (e.g. [DDD](http://www.gnu.org/software/ddd/) or
2380 [kdevelop](http://www.kdevelop.org)), (ii) some code that goes into your
2381 $HOME/.gdbinit file. Instructions for setting up this file, which implements
2382 pretty printers for `Point`, `Tensor`, `Vector`, and the various iterator
2383 classes for triangulations and DoFHandlers, are posted
2384 [here](Debugging-with-GDB).
2386 gdb can also pretty print many of the `std::XXX` classes, but not all linux
2387 distributions have it configured this way. To enable this, follow the
2388 instructions [from this
2389 website](http://sourceware.org/gdb/wiki/STLSupport). The little python
2390 snippet can be placed as a separate python block into `.gdbinit`.
2392 ### My program is slow!
2394 This is a problem that is true for a lot of us. The question is which part
2395 of your program is causing it. Before going into more detail, there are,
2396 however, some general observations:
2398 - Running deal.II programs in debug mode will take, depending on the program,
2399 between 4 and 10 times as long as in optimized mode. If you are using the
2400 standard setup for your own `CMakeLists.txt` file (described in the
2401 [documentation](https://www.dealii.org/8.3.0/users/cmakelists.html)), then
2402 compiling your code with `make release` will both compile your code at a
2403 higher optimization level and link it against the optimized version of
2406 - A typical finite element program will spend around one third of its time
2407 in assembling linear systems, around one half in solving these linear
2408 systems, and the rest of the time on other things. If your program's
2409 percentages significant deviate from this rule of thumb, you know where
2412 - There is a rule that says that even the best programmers are unable to
2413 point out where in the program the most CPU time is spent without some
2414 form of profiling. This is definitely true also for the primary
2415 developers of deal.II, so it is likely true for you as well. A corollary
2416 to this rule is that if you start optimizing parts of your code without
2417 first profiling it, you are more than likely just going to make things
2418 more complicated without significant gains because you pick the simplest
2419 places to optimize, not the ones with the biggest impact.
2421 So how can you find out which parts of the program are slow? There are two
2422 tools that we've really come to like, both from the
2423 [valgrind](http://www.valgrind.org/) project: callgrind and cachegrind.
2424 Valgrind essentially emulates what your CPU would do with your program and
2425 in the process collects all sorts of information. In particular, if you run
2428 valgrind --tool=callgrind ./myprogram
2431 (this will take around 10 times longer than when you just call
2432 `./myprogram` because of the emulation) then the result will be a file in
2433 this directory that contains information about where your program spent its
2434 time. There are a number of graphical frontends that can visualize this
2435 data; my favorite is `kcachegrind` (a misnomer -- it is, despite its name,
2436 actually a frontend from callgrind, not cachegrind). Pictures of how this
2437 output looks can be found in the introduction of step-22. It typically
2438 shows how much time was spent in each function and a call graph of which
2439 functions where called from where.
2441 Using valgrind's cachegrind can give you a more detailed look at much of
2442 the same kind of information. In particular, it can show you source line
2443 for source line how many instructions were executed there, and how many
2444 memory accesses (as well as cache hits and misses) were generated there.
2445 See the valgrind manual for more information.
2447 Lastly, since you are probably most interested in the performance of the
2448 optimized version of your code (which you will probably use for long
2449 expensive runs), you should run valgrind on the optimized executable.
2451 ### How do I debug MPI programs?
2453 This is clearly an awkward topic for which there are few good options:
2454 debugging parallel programs using MPI has always been a pain and it is
2455 frustrating even to experienced programmers. That said, there are parallel
2456 debuggers that can deal with MPI, for example
2457 [TotalView](http://www.roguewave.com/products/totalview-family/totalview.aspx)
2458 that can make this process at least somewhat simpler.
2460 Whether you have or don't have TotalView, here are a few guidelines of
2461 strategies that have helped us in the past:
2463 - Try to reduce the problem to the smallest one you can find: The smallest
2464 mesh, the smallest number of processors. Reducing the number of
2465 processors needed to demonstrate the bug must be your highest priority.
2467 - One of the biggest problems you typically have is that the processes
2468 that communicate via MPI typically run on different machines. If you can
2469 manage to reduce the problem to a small enough number of processors, you
2470 can run them all locally on a single workstation, rather than a cluster
2471 of computers. Ideally, you would reduce the problem to 2 or 4 processors
2472 and then just start the program using `mpirun -np 4 ./myexecutable` on
2473 the headnode of the cluster, a workstation, or even a laptop.
2475 - Try to figure out which MPI process (the MPI rank) has the problem, for
2476 example by printing the output of
2477 `Utilities::System::get_this_mpi_process(MPI_COMM_WORLD)` at various
2478 points in your program.
2480 - If you know which MPI process has the problem and if this is
2481 reproducible, let each process print out its MPI rank and its process id
2482 (PID) using the system function `getpid` at the very beginning of the
2483 program. The PID is going to be different every time you run the
2484 program, but if you know the connection between MPI rank and PID and you
2485 know which rank will produce the problem, then you can predict which PID
2486 will have the problem. The point of this is that you can attach a
2487 debugger to this PID; for example, `gdb` has the command `attach <pid>`
2488 with which you can attach the debugger to a running program, rather than
2489 running the program from the start within the debugger. Attaching a
2490 program to the debugger will stop it (and, after a while, will typically
2491 also stop all the other MPI processes once they come to a place where
2492 they are waiting for a communication from the stopped process). You can
2493 then look at variables, continue running to breakpoints, or do whatever
2494 else you want to do with the process you attached the debugger to. In
2495 particular, if for example you attached the debugger to the process that
2496 you know will segfault or run onto a failing assertion, you can just
2497 type `continue` in the debugger to let the program continue till it
2498 aborts. You can then inspect the state of the program at the point of
2499 the problem inside the debugger you attached.
2501 - The above process relies on the fact that you have time to attach a
2502 debugger between starting the program, reading the mapping from MPI
2503 process rank to PID, and attaching a debugger. If the program produces
2504 the error very quickly, it is often useful to insert a call to
2505 `sleep(60);` (and including the appropriate header file) just after
2506 outputting MPI rank and PID. This gives you 60 seconds to attach the
2507 debugger before the program will continue.
2509 - If finding out which MPI process has the problem turns out to be too
2510 complicated, or if it isn't predictable which process will produce an
2511 error, then there is a fallback option: attach a debugger to
2512 <i>every</i> MPI process. This is awkward to do by hand, but there is a
2513 shortcut: under linux (or any other unix system) you can run
2516 mpirun -np 4 xterm -e gdb --args ./my_executable
2518 The equivalent for macOS is
2520 mpirun -np 4 xterm -e lldb -f ./my_executable
2523 In this example, we start 4 MPI processes; in each of these 4 processes, we
2524 open an `xterm` window in which we start an instance of `gdb`/`lldb` with the
2525 executable. You'd then `run` the executable in each of the 4 windows, and
2526 debug it as you usually would. This might be tedious but as mentioned
2527 above, debugging MPI programs often is tedious indeed. To find out which
2528 gdb window belongs to which MPI rank, you can type the command
2532 into the gdb window (this works with OpenMPI at least). See https://plus.google.com/+TimoHeister/posts/AgmoMT8W7GZ for more info.
2534 ### I have an MPI program that hangs
2536 Apart from programs that segfault or that run onto a failing assertion
2537 (both cases that are relatively easy to debug using the techniques above),
2538 programs that just hang are the most common problem in parallel
2539 programming. The typical cause for this is that there is a point in your
2540 program where all or some MPI processes expect to get a message from a
2541 process X (e.g. in a global communication, say MPI_Reduce, MPI_Barrier, or
2542 directly in point-to-point communications) but process X is not where it
2543 should be -- for example, because it is in an endless loop, or -- more
2544 likely -- because process X didn't think that it should participate in this
2545 communication. In either case, the other processes will wait forever for
2546 process X's message and deadlock the program. An example for this case
2549 void assemble_system ()
2551 // optimization in case there is nothing to do; we won't
2552 // have to initialize FEValues and other local objects in
2554 if (tria.n_locally_owned_active_cells() == 0)
2559 if (!cell->is_ghost() && !cell->is_artificial())
2560 ...do the assembly on the locally owned cells...
2562 system_rhs.compress();
2566 Here, the call to `compress()` at the end involves communication between
2567 MPI processes. In particular, say, it implies that process Y will wait for
2568 some data from process X. Now what happens if process X realizes that it
2569 doesn't have any locally owned cells? In that case, process X will quit the
2570 function at the very top, and will never call `compress()`. In other words,
2571 process Y will wait forever, possibly making process Z wait further down
2572 the program etc. In the end, the program will be deadlocked.
2574 The goal of debugging the program must be to find where individual
2575 processes are stopped in order to determine which incoming communication
2576 they are waiting for. If you attached a debugger to the program above,
2577 you'd find for example that all but one process is stopped in the call to
2578 `compress()`, and the one remaining process is stopped in some other MPI
2579 call, then you already have a good idea what may be going on.
2581 ### One statement/block/function in my MPI program takes a long time
2583 Let's say you have a block of code that you suspect takes a long time and
2584 you want to time it like this:
2590 if (my MPI rank == 0)
2591 std::cout << "Calling my_function() took " << timer() << " seconds." << std::endl;
2594 The output is large, i.e. you think that the function you called is taking
2595 a long time to execute and that you should focus your efforts on optimizing
2596 it. But in an MPI program, this isn't quite always true. Imagine, for
2597 example, that the function looked like this:
2601 double val = compute_something_locally();
2602 double global_sum = 0;
2603 MPI_Reduce (&val, &global_sum, MPI_DOUBLE, 1, 0, MPI_COMM_WORLD);
2604 if (my MPI rank == 0)
2605 std::cout << "Global sum = " << global_sum << std::endl;
2609 In the call to `MPI_Reduce`, all processors have to send something to
2610 processor zero. Processor zero will have to wait till everyone sends stuff
2611 to this processor. But what if processor X is still busy doing something
2612 else (stuff above the call to `my_function`) for a while? The processor
2613 zero will wait for quite a while, not because the operations in
2614 `my_function` are particularly expensive (either on processor zero or
2615 processor X) but because processor X was still busy doing something else.
2616 In other words: you need to direct your efforts in making the "something
2617 else on processor X" faster, not making `my_function` faster.
2619 To find out whether this is really the problem, here is a simple way to see
2620 what the "real" cost of `my_function` is:
2623 MPI_Barrier (MPI_COMM_WORLD);
2626 MPI_Barrier (MPI_COMM_WORLD);
2628 if (my MPI rank == 0)
2629 std::cout << "Calling my_function() took " << timer() << " seconds." << std::endl;
2632 This way, you really only measure the time spent between when all
2633 processors have finished doing what they were doing before, and when they
2634 are all finished doing what they needed to do for `my_function`.
2636 Another way to find some answers is to use the capabilities of the `Timer`
2637 class which can provide more detailed information when deal.II is
2638 configured to support MPI.
2640 ## I have a special kind of equation!
2642 ### Where do I start?
2644 The deal.II tutorial has a number of programs that deal with particular
2645 kinds of equations, such as vector-valued problems, mixed discretizations,
2646 nonlinear and time-dependent problems, etc. The best way to start is to
2647 take a look at the existing tutorial programs and see if there is one that
2648 is already close to what you want to do. Then take that, try to understand
2649 its structure, and find a way to modify it to solve your problem as well.
2650 Most applications written based on deal.II are not written entirely from
2651 scratch, but have started out as modified tutorial programs.
2653 ### Can I solve my particular problem?
2655 The simple answer is: if it can be written as a PDE, then this is possible
2656 as evidenced by the many publications in widely disparate fields obtained
2657 with the help of deal.II. The more complicated answer is: deal.II is not a
2658 problem-solving environment, it is a toolbox that supports you in solving a
2659 PDE by the method of finite elements. You will have to implement assembling
2660 matrices and right hand side vectors yourself, as well as nonlinear outer
2661 iterations, etc. However, you will not need to care about programming a
2662 triangulation class that can handle locally refined grids in one, two, and
2663 three dimensions, linear algebra classes, linear solvers, different finite
2664 element classes, etc.
2666 To give only a very brief overview of what is possible, here is a list of
2667 the nontrivial problems that were treated by the programs that the main
2668 authors alone wrote to date:
2670 - Time-dependent acoustic and elastic wave equation, including nonlocal
2671 absorbing boundary conditions;
2672 - Stokes flow discretized with the discontinuous Galerkin finite element
2674 - General hyperbolic problems including Euler flow, using the
2675 discontinuous Galerkin finite element method;
2676 - Distributed parameter estimation problems;
2677 - Mixed finite element discretization of a mortar multiblock formulation
2678 of the Laplace equation;
2679 - Large-deformation elasto-plasticity in the simulation of plate
2682 To illustrate the complexity of the programs mentioned above we note that
2683 most of them include adaptive mesh refinement tailored to the efficient
2684 computation of specific quantities of physical interest and error
2685 estimation measured in terms of these quantities. This includes the
2686 solution of a so-called dual problems, that means e.g. for the wave
2687 equation the solution of a wave equation solved backward in time.
2689 Problems other users of deal.II have solved include:
2691 - Porous media flow;
2692 - Crystal growth simulations;
2693 - Fuel cell simulations and optimization;
2694 - Fluid-structure interaction problems;
2695 - Time dependent large deformation problems for metal forming;
2697 - Viscoelastic deformation of continental plates;
2698 - Glacial ice flows;
2699 - Thermoelastoplastic metal forming;
2700 - Eulerian coordinates problems in biomechanical modeling.
2702 Some images from these applications can be found on this wiki's [[Gallery]]
2703 page. A good overview of the sort of problems that are being solved with the
2704 help of deal.II can also be obtained by looking at the large number of
2705 [publications](http://www.dealii.org/publications.html) written with the help of
2708 Probably, many other problem types are solved by the many users which we do
2709 not know of directly. If someone would like to have his project added to
2710 this page, just contact us.
2713 ### Why use deal.II instead of writing my application from scratch?
2715 You can usually get the initial version of a code for any given problem
2716 done relatively quickly when you write it yourself, since the learning
2717 curve is not as steep as if you had to learn a new library; it's also true
2718 that it's easy to make this code twice as fast as if you had to use a
2719 library. In other words, this sounds like you should write finite element
2720 codes for your problem yourself.
2722 However, you also need to keep in mind that it is the things you want to do
2723 after the first 3 months that will take you forever if you want to write it
2724 yourself, and where you will never be able to catch up with existing,
2725 established libraries: higher order elements; complicated, unstructured 3d
2726 meshes; parallelization; producing output in a format that's easily
2727 visualizable in 3d; adding an advected field for a tracer quantity; etc.
2728 Viewed this way, it's worth remembering that the primary commodity that's
2729 in short supply is not CPU time but your own programming time, and that's
2730 where you will be '''orders magnitude faster''' when using what others have
2731 already done, even if maybe your program ends up twice as slow as if you
2732 had written it from scratch with a particular application in mind.
2734 ### Can I solve problems over complex numbers?
2736 Yes, you can, and it has been done numerous times with deal.II. However, we
2737 have a standard recommendation: consider such problems as systems of
2738 partial differential equations, where the individual components of the
2739 solution are the real and imaginary part of your unknown. The reason for
2740 this is that for complex-valued problems, the product `<u,v>` of two vectors
2741 is not the same as `<v,u>`, and it is very easy to get this wrong in many
2742 places. If you want to avoid these common traps, then the easiest way
2743 around is to split up you equation into two equations of real and imaginary
2744 part first, and then treat the resulting system as a system of real
2745 variables. This also makes the type of linear system clearer that you get
2746 after discretization, and tells you something about which solver may be
2749 The step-29 tutorial program shows how this is done for a complex-valued
2752 ### How can I solve a problem with a system of PDEs instead of a single equation?
2754 The easiest way to do this is setting up a system finite element after you
2755 chose your base element, e.g.,
2757 FE_Q<dim> base_element(2);
2758 FESystem<dim> system_element(base_element, 3);
2761 will produce a biquadratic element for a system of 3 equations. With this
2762 finite element, all the functions that you always called for a scalar
2763 finite element should just work for this vector-valued element as well.
2765 Refer to the step-8 and in particular to the step-20 tutorial programs for
2766 a lot more information on this topic. Several of the other tutorial
2767 programs beyond step-20 also use vector-valued elements and there is a
2768 whole module in the documentation on vector-valued problems that is worth
2771 ### Is it possible to use different models/equations on different parts of the domain?
2773 Yes. The step-46 tutorial program shows how to do this: It solves a problem
2774 in which we solve Stokes flow in one part of the domain, and elasticity in
2775 the rest of the domain, and couple them on the interface. Similar
2776 techniques can be used if you want to exclude part of the domain from
2777 consideration, for example when considering voids in a body in which the
2778 governing equations do not make sense because there is no medium.
2780 ### Where do I start to implement a new Finite Element Class?
2782 If you really need an element that isn't already implemented in deal.II,
2783 then you'll have to understand the interplay between FEValues, the finite
2784 element, the mapping, and quadrature objects. A good place to start would
2785 be to read the deal.II paper (Bangerth, Hartmann, Kanschat, ACM Trans.
2786 Math. Softw., 2007).
2788 The actual implementation would most conveniently start from the `FE_Poly`
2789 class. You first implement the necessary polynomial space in the base
2790 library, then you derive `FE_Your_FE_Name` from `FE_Poly` (using your new
2791 polynomial class as a template) and add the connectivity information.
2793 You'll probably need more specific help at various points -- this is what
2794 the mailing list is there for!
2796 ## General finite element questions
2798 ### How do I compute the error
2800 If your goal is to compute the error in the form `||`u-u<sub>h</sub>`||` in some
2801 kind of norm, then you should use the function
2802 [VectorTools::integrate_difference](https://www.dealii.org/8.3.0/doxygen/deal.II/namespaceVectorTools.html#a01174a2a7e2ee8fa6abdfdd93ac7a317)
2803 which can compute the norm above in any number of norms (such as the L2, H1,
2804 etc., norms). Take a look at step-7.
2806 On the other hand, if your goal is to *estimate* the error, then the one class
2808 [Kelly Error Estimator](https://www.dealii.org/8.3.0/doxygen/deal.II/classKellyErrorEstimator.html).
2809 This class is used in most of the tutorial programs that use adaptively refined
2810 meshes, starting with step-6.
2812 ### How to plot the error as a pointwise function
2814 The functions mentioned in the previous question compute the error as a
2815 cellwise value. As a consequence, the values computed also include a factor
2816 that results from the size of the cell. If you're interested in the pointwise
2817 error as something that can be visualized, for example because you want to
2818 find a pattern in why the solution is not as you expect it to be, what you
2820 - Interpolate the exact solution
2821 - Subtract the interpolated exact solution from the computed solution
2822 - Put the resulting vector into a
2823 [DataOut object](https://www.dealii.org/8.3.0/doxygen/deal.II/classDataOut.html).
2824 This will plot the nodal values of the errors u-u<sub>h</sub> on the current
2827 As an example, the following code shows how to do this in principle:
2830 class ExactSolution : public Function<dim>
2833 ExactSolution () : Function<dim>(dim+1) {}
2835 virtual double value (const Point<dim> &p,
2836 const unsigned int component) const
2838 return ...exact solution as a function of p...
2844 void MyProblem<dim>::plot_error () const
2846 Vector<double> interpolated_exact_solution (dof_handler.n_dofs());
2847 VectorTools::interpolate (dof_handler,
2848 ExactSolution<dim>(),
2849 interpolated_exact_solution);
2850 interpolated_exact_solution -= solution;
2852 DataOut<dim> data_out;
2854 data_out.attach_dof_handler (dof_handler);
2855 data_out.add_data_vector (solution, "solution");
2856 data_out.add_data_vector (interpolated_exact_solution, "pointwise_error");
2861 ### I'm trying to plot the right hand side vector but it doesn't seem to make sense!
2863 In particular, what you probably see is that the plot shows values that are
2864 smaller by a factor of two along the boundary than in the inside, and by a
2865 factor of four in the corners (in 2d) or eight (in 3d). Similarly, on
2866 adaptively refined cells, the values appear to scale with the cell size.
2867 The reason is that trying to plot a right hand side vector doesn't make
2870 While you plot the vector as if it is function (by connecting dots with
2871 straight lines in 1d, or plotting surfaces in 2d), the thing you right hand
2872 side vector is in fact an element of the dual space. To wit:
2873 - A vector in primal space is a vector of nodal values so that `sum_i U_i
2874 phi_i(x)` is a reasonable function of `x`. Solution vectors are examples
2875 of elements of primal space.
2876 - A vector in dual space is a vector W formed from the integration of an
2877 object in primal space against the shape functions, e.g. `W_i = int
2878 f(x) phi_i(x)`. Examples of dual vectors are right hand side vectors.
2880 For vectors in dual space, it doesn't make sense to plot them as functions
2882 `sum_i W_i phi_i(x)`.
2883 The reason is that the values of the coefficients W_i are not of
2884 **amplitude** kind. Rather, the W_i are of kind amplitude (e.g. f(x)) times
2885 integration volume (the integral `*` dx over the support of shape functions
2886 phi_i). In other words, the sizes of cells comes into play for W_i, as does
2887 whether a shape function lies in the interior or at the boundary. In your
2888 case, the area of the integral when you integrate against shape functions
2889 at the boundary happens to be half the size of the integration area for
2890 shape functions in the interior.
2893 ### What does XXX mean?
2895 The documentation of deal.II uses many finite element specific terms that
2896 may not always be entirely clear to someone not familiar with this
2897 language. In addition, we have certainly also invented our shares of
2898 deal.II specific terminology. If you encounter something you are not
2899 familiar with, take a look at the [deal.II glossary
2900 page](http://www.dealii.org/developer/doxygen/deal.II/DEALGlossary.html)
2901 that explains many of them.
2903 ## I want to contribute to the development of deal.II!
2905 deal.II is Open Source -- this not only implies that you as everyone else has
2906 access to the source codes, it also implies a certain development model:
2907 whoever would like to contribute to the further development is invited to do
2908 so: If you have changes or ideas, please send them to the
2909 [deal.II mailing list](http://www.dealii.org/mail.html)!
2911 This model follows a small number of simple rules. The first and basic one
2912 is that if you have something that might be of interest to others as well,
2913 you are invited to send it to the list for possible inclusion into the
2914 library and use by others as well. Such additions useful to others are, for
2916 - new backends for output in a new graphical format;
2917 - input filters for some kind of data;
2918 - tool classes that do something that might be interesting to use in other
2921 A few projects (some easy, some difficult) can also be found in the
2922 [list of open issues](https://github.com/dealii/dealii/issues), where they
2923 are generally marked as "Enhancements".
2925 If you consider providing some code for inclusion with the library, these
2926 are the simple rules of gaining reputation in the Open Source community:
2927 - your reputation grows with the number and complexity of your
2929 - your reputation with the maintainers of the library also grows with the
2930 degree of conformance of your proposed additions with the administrative
2932 - originators of code are credited full authorship.
2934 In order to allow that a library remains a consistent piece of software,
2935 there are a number of administrative rules:
2936 - there are a number of maintainers that decide what goes into the
2938 - maintainers are benevolent, i.e. in general they want your addition to
2939 become part of the library;
2940 - however, they have to evaluate additions with respect to some criteria,
2941 among which are value for others;
2942 - whether it fits into the general framework (meaning that if your
2943 contribution requires the installation of some obscure other library
2944 that people do not usually have, then that must be discussed;
2945 alternatively, a way must be provided to disable your contribution on
2946 machines that do not have this lib);
2947 - completeness and amount of documentation;
2948 - existence and completeness of error checking through assertions.
2950 However, again: the basic rule is that if you think your addition is
2951 interesting to others, there most probably is a way to get it into the
2955 ## I found a typo or a bug and fixed it on my machine. How do I get it included in deal.II?
2957 First: thank you for wanting to do this! This software project is kept alive
2958 by people like you contributing to it. We like to include any improvement,
2959 even if it is just a single typo that you fixed.
2961 If you have only a small change, or if this is your first time submitting
2962 changes, the easiest way to get them to us is by just emailing the
2963 [deal.II mailing lists](http://dealii.org/mail.html) and we will make sure they
2964 get incorporated. If you continue submitting patches (which we hope you will!)
2965 and become more experienced, we will start to ask you to use
2966 [git](http://en.wikipedia.org/wiki/Git_%28software%29) as the version control
2967 system and base your patches off of the
2968 [deal.II github repository](https://github.com/dealii/dealii).
2970 The process for this is essentially the following (if you don't quite
2971 understand the terminology below, take a look at the manuals at the
2972 [github web site](https://github.com/), read
2973 [this online tutorial](https://www.atlassian.com/git/tutorial), or ask on the
2975 - Create a github account
2976 - Fork the deal.II github repository, using the button at the top right
2977 of https://github.com/dealii/dealii
2978 - Clone the repository onto your local file system
2979 - Create a branch for your changes
2981 - Push your changes to your github repository
2982 - Create a pull request for your changes by going to your github
2983 account's deal.II tab where, after the previous step, there should be a
2984 button that allows you to create a pull request.
2986 This list may sound intimidating at first, but in reality it's a fairly
2987 straightforward process that takes no more than 2 minutes after the first
2988 couple of times. But, as said, we'll be happy to hold your hand the first few
2989 times around and help you with the process! There's also a video lecture that
2991 [how to submit a patch to github](http://www.math.colostate.edu/~bangerth/videos.676.32.8.html).
2993 If you've submitted patches several times and know your way around git by now,
2994 please also consider to
2995 - make sure you base your patch off the most recent revision of the
2997 - you rewrite the history of your patch so that it contains a relatively
2998 small number of commits that are each internally consistent and could
2999 also be applied independently (see, for example, [the discussion
3000 towards the bottom of this
3001 page](https://github.com/dealii/dealii/pull/87)).
3005 ## I'm fluent in deal.II, are there jobs for me?
3007 Certainly. People with numerical skills are a sought commodity, both in
3008 academia and in businesses. In the US, the National Labs are also hiring
3009 lots of people in this field.