You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+7-4Lines changed: 7 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,15 +16,18 @@ If you want to contribute to this tutorial, please make a fork of the repository
16
16
act -j test-nightly
17
17
```
18
18
19
-
Any code added to the tutorial should work in parallel.
20
-
21
19
Alternatively, if you want to add a separate chapter, a Jupyter notebook can be added to a pull request, without integrating it into the tutorial. If so, the notebook will be reviewed and modified to be included in the tutorial.
22
20
23
-
Note that every chapter is written as an IPython notebook and a Python file. These are kept in sync by jupytext. See [their notes](https://jupytext.readthedocs.io/en/latest/install.html#jupytext-commands-in-jupyterlab) on how to keep them in sync.
24
-
Also ensure that both Python file and notebook files are updated by using jupytext, i.e.
21
+
Any code added to the tutorial should work in parallel. If any changes are made to `ipynb` files, please ensure that these changes are reflected in the corresponding `py` files by using [`jupytext`](https://jupytext.readthedocs.io/en/latest/faq.html#can-i-use-jupytext-with-jupyterhub-binder-nteract-colab-saturn-or-azure):
25
22
26
23
```bash
27
24
python3 -m jupytext --sync */*.ipynb
25
+
```
26
+
27
+
Any code added to the tutorial should work in parallel.
28
+
29
+
## Dependencies
30
+
28
31
It is adviced to use a pre-installed version of DOLFINx, for instance through conda or docker. Remaining dependencies can be installed with
Copy file name to clipboardExpand all lines: chapter1/complex_mode.ipynb
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -73,7 +73,7 @@
73
73
"source": [
74
74
"However, as we would like to solve linear algebra problems of the form $Ax=b$, we need to be able to use matrices and vectors that support real and complex numbers. As [PETSc](https://petsc.org/release/) is one of the most popular interfaces to linear algebra packages, we need to be able to work with their matrix and vector structures.\n",
75
75
"\n",
76
-
"Unfortunately, PETSc only supports one floating type in their matrices, thus we need to install two versions of PETSc, one that supports `float64` and one that supports `complex128`. In the [docker images](https://hub.docker.com/r/dolfinx/dolfinx) for DOLFINx, both versions are installed, and one can switch between them by calling `source dolfinx-real-mode` or `source dolfinx-complex-mode`. For the `dolfinx/lab` images, one can change the Python kernel to be either the real or complex mode, by going to `Kernel->Change Kernel...` and choose `Python3 (ipykernel)` (for real mode) or `Python3 (DOLFINx complex)` (for complex mode).\n",
76
+
"Unfortunately, PETSc only supports one floating type in their matrices, thus we need to install two versions of PETSc, one that supports `float64` and one that supports `complex128`. In the [docker images](https://hub.docker.com/r/dolfinx/dolfinx) for DOLFINx, both versions are installed, and one can switch between them by calling `source dolfinx-real-mode` or `source dolfinx-complex-mode`. For the `dolfinx/lab` images, one can change the Python kernel to be either the real or complex mode, by going to `Kernel->Change Kernel...` and choosing `Python3 (ipykernel)` (for real mode) or `Python3 (DOLFINx complex)` (for complex mode).\n",
77
77
"\n",
78
78
"We check that we are using the correct installation of PETSc by inspecting the scalar type."
79
79
]
@@ -161,7 +161,7 @@
161
161
"id": "9efe0968-bf32-4184-85f7-4e8cc3401cfb",
162
162
"metadata": {},
163
163
"source": [
164
-
"Similarly, if we want to use the function `ufl.derivative` to take derivatives of functionals, we need to take some special care. As `derivative` inserts a `ufl.TestFunction` to represent the variation, we need to take the conjugate of this to in order to assemble vectors.\n"
164
+
"Similarly, if we want to use the function `ufl.derivative` to take derivatives of functionals, we need to take some special care. As `ufl.derivative` inserts a `ufl.TestFunction` to represent the variation, we need to take the conjugate of this to be able to use it to assemble vectors.\n"
Copy file name to clipboardExpand all lines: chapter1/complex_mode.py
+4-10Lines changed: 4 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@
6
6
# extension: .py
7
7
# format_name: light
8
8
# format_version: '1.5'
9
-
# jupytext_version: 1.15.2
9
+
# jupytext_version: 1.16.1
10
10
# kernelspec:
11
11
# display_name: Python 3 (DOLFINx complex)
12
12
# language: python
@@ -19,7 +19,7 @@
19
19
#
20
20
# Many PDEs, such as the [Helmholtz equation](https://docs.fenicsproject.org/dolfinx/v0.4.1/python/demos/demo_helmholtz.html) require complex-valued fields.
21
21
#
22
-
# For simplicity, let us consider a Poisson equation of the form:
22
+
# For simplicity, let us consider a Poisson equation of the form:
23
23
#
24
24
# $$-\Delta u = f \text{ in } \Omega,$$
25
25
# $$ f = -1 - 2j \text{ in } \Omega,$$
@@ -59,20 +59,17 @@
59
59
60
60
# However, as we would like to solve linear algebra problems of the form $Ax=b$, we need to be able to use matrices and vectors that support real and complex numbers. As [PETSc](https://petsc.org/release/) is one of the most popular interfaces to linear algebra packages, we need to be able to work with their matrix and vector structures.
61
61
#
62
-
# Unfortunately, PETSc only supports one floating type in their matrices, thus we need to install two versions of PETSc, one that supports `float64` and one that supports `complex128`. In the [docker images](https://hub.docker.com/r/dolfinx/dolfinx) for DOLFINx, both versions are installed, and one can switch between them by calling `source dolfinx-real-mode` or `source dolfinx-complex-mode`. For the `dolfinx/lab` images, one can change the Python kernel to be either the real or complex mode, by going to `Kernel->Change Kernel...` and choose `Python3 (ipykernel)` (for real mode) or `Python3 (DOLFINx complex)` (for complex mode).
62
+
# Unfortunately, PETSc only supports one floating type in their matrices, thus we need to install two versions of PETSc, one that supports `float64` and one that supports `complex128`. In the [docker images](https://hub.docker.com/r/dolfinx/dolfinx) for DOLFINx, both versions are installed, and one can switch between them by calling `source dolfinx-real-mode` or `source dolfinx-complex-mode`. For the `dolfinx/lab` images, one can change the Python kernel to be either the real or complex mode, by going to `Kernel->Change Kernel...` and choosing `Python3 (ipykernel)` (for real mode) or `Python3 (DOLFINx complex)` (for complex mode).
63
63
#
64
64
# We check that we are using the correct installation of PETSc by inspecting the scalar type.
65
-
#
66
65
67
66
frompetsc4pyimportPETSc
68
67
fromdolfinx.fem.petscimportassemble_vector
69
68
print(PETSc.ScalarType)
70
69
assertnp.dtype(PETSc.ScalarType).kind=='c'
71
70
72
71
# ## Variational problem
73
-
#
74
72
# We are now ready to define our variational problem
75
-
#
76
73
77
74
importufl
78
75
u=ufl.TrialFunction(V)
@@ -86,13 +83,12 @@
86
83
# Secondly, note that we are using `ufl.inner` to describe multiplication of $f$ and $v$, even if they are scalar values. This is because `ufl.inner` takes the conjugate of the second argument, as decribed by the $L^2$ inner product. One could alternatively write this out explicitly
87
84
#
88
85
# ### Inner-products and derivatives
89
-
#
90
86
91
87
L2=f*ufl.conj(v) *ufl.dx
92
88
print(L)
93
89
print(L2)
94
90
95
-
# Similarly, if we want to use the function `ufl.derivative` to take derivatives of functionals, we need to take some special care. As `derivative` inserts a `ufl.TestFunction` to represent the variation, we need to take the conjugate of this to in order to assemble vectors.
91
+
# Similarly, if we want to use the function `ufl.derivative` to take derivatives of functionals, we need to take some special care. As `ufl.derivative` inserts a `ufl.TestFunction` to represent the variation, we need to take the conjugate of this to be able to use it to assemble vectors.
96
92
#
97
93
98
94
J=u_c**2*ufl.dx
@@ -101,9 +97,7 @@
101
97
print(residual.array)
102
98
103
99
# We define our Dirichlet condition and setup and solve the variational problem.
Copy file name to clipboardExpand all lines: chapter1/fundamentals.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,8 @@ Authors: Hans Petter Langtangen, Anders Logg
4
4
5
5
Adapted to FEniCSx by Jørgen S. Dokken
6
6
7
-
The goal of this tutorial is to solve one of the most basic PDEs, the Poisson equation, with a few lines of code in FEniCSx. We start by introducing some fundamental FEniCSx objects, such as `Function`, `functionspace`, `TrialFunction` and `TestFunction`, and learn how to write a basic PDE solver.
7
+
The goal of this tutorial is to solve one of the most basic PDEs, the Poisson equation, with a few lines of code in FEniCSx.
8
+
We start by introducing some fundamental FEniCSx objects, such as `Function`, `functionspace`, `TrialFunction` and `TestFunction`, and learn how to write a basic PDE solver.
8
9
This will include:
9
10
10
11
- How to formulate a mathematical variational problem
Here, $u=u(\mathbf{x})$ is the unknown function, $f=f(\mathbf{x})$ a prescribed function, $\nabla^2$ the Laplace operator
22
-
(often written as $\Delta$), $\Omega$ the spatial domain, and $\partial\Omega$ the boundary of $\Omega$. The Poisson problem, including both the PDE, $-\nabla^2 u = f$, and the boundary condition, $u=u_D$ on $\partial\Omega$, is an example of a _boundary-value problem_, which must be precisely stated before we can start solving it numerically with FEniCSx.
23
+
(often written as $\Delta$), $\Omega$ the spatial domain, and $\partial\Omega$ the boundary of $\Omega$.
24
+
The Poisson problem, including both the PDE, $-\nabla^2 u = f$, and the boundary condition, $u=u_D$ on $\partial\Omega$, is an example of a _boundary-value problem_, which must be precisely stated before we can start solving it numerically with FEniCSx.
23
25
24
26
In the two-dimensional space with coordinates $x$ and $y$, we can expand the Poisson equation as
0 commit comments