Skip to content

Commit 8fabd57

Browse files
authored
Fix typos and improve text in membrane_code.ipynb (#110)
* fix typos and improve text in membrane_code.ipynb * autosync corresponding Python file
1 parent d2cebba commit 8fabd57

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

chapter1/membrane_code.ipynb

+15-15
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
"In this section, we will solve the deflection of the membrane problem.\n",
1111
"After finishing this section, you should be able to:\n",
1212
"- Create a simple mesh using the GMSH Python API and load it into DOLFINx\n",
13-
"- How to create a constant boundary conditions using a geometrical identifier\n",
14-
"- Using s`ufl.SpatialCoordinate` to create a spatially varying function\n",
15-
"- How to interpolate a `ufl.Expression` into an appropriate function space\n",
16-
"- How to evaluate a `dolfinx.Function` at any point $x$\n",
13+
"- Create constant boundary conditions using a geometrical identifier\n",
14+
"- Use `ufl.SpatialCoordinate` to create a spatially varying function\n",
15+
"- Interpolate a `ufl.Expression` into an appropriate function space\n",
16+
"- Evaluate a `dolfinx.Function` at any point $x$\n",
1717
"- Use Paraview to visualize the solution of a PDE\n",
1818
"\n",
1919
"## Creating the mesh\n",
2020
"\n",
21-
"To create the computational geometry, we use the python-API of [GMSH](http://gmsh.info/). We start by import the gmsh-module, and initalizing it."
21+
"To create the computational geometry, we use the python-API of [GMSH](http://gmsh.info/). We start by importing the gmsh-module and initializing it."
2222
]
2323
},
2424
{
@@ -35,7 +35,7 @@
3535
"cell_type": "markdown",
3636
"metadata": {},
3737
"source": [
38-
"The next step is to create the membrane and starting the computations by the GMSH CAD kernel, to generate the relevant underlying data structures. The arguments into `addDisk` is the x, y and z coordinate of the center of the circle, while the to last argument is the x-radius and y-radius."
38+
"The next step is to create the membrane and start the computations by the GMSH CAD kernel, to generate the relevant underlying data structures. The first arguments of `addDisk` are the x, y and z coordinate of the center of the circle, while the two last arguments are the x-radius and y-radius."
3939
]
4040
},
4141
{
@@ -52,7 +52,7 @@
5252
"cell_type": "markdown",
5353
"metadata": {},
5454
"source": [
55-
"The next step is to make the membrane a physical surface, such that it is recognized by gmsh when generating the mesh. As a surface is a two-dimensional entity, we add two as the first argument, the entity tag of the membrane as the second argument, and the last argument is the physical tag. In a later demo, we will get into when this tag matters."
55+
"After that, we make the membrane a physical surface, such that it is recognized by `gmsh` when generating the mesh. As a surface is a two-dimensional entity, we add `2` as the first argument, the entity tag of the membrane as the second argument, and the physical tag as the last argument. In a later demo, we will get into when this tag matters."
5656
]
5757
},
5858
{
@@ -80,7 +80,7 @@
8080
"cell_type": "markdown",
8181
"metadata": {},
8282
"source": [
83-
"Finally, we generate the two-dimensional mesh. We set a uniform mesh size by modifying the GMSH options"
83+
"Finally, we generate the two-dimensional mesh. We set a uniform mesh size by modifying the GMSH options."
8484
]
8585
},
8686
{
@@ -113,8 +113,8 @@
113113
"metadata": {},
114114
"source": [
115115
"# Interfacing with GMSH in DOLFINx\n",
116-
"We will import the GMSH-mesh directly from GMSH, using the `dolfinx.io.gmshio` interface in DOLFINx.\n",
117-
"As we in the example have not specified which process we have created the gmsh model on, a model has been created on each mpi process. However, we would like to be able to use a mesh distributed over all processes. We therefore take the model generated on rank 0 of `MPI.COMM_WORLD`, and distribute it over all available ranks. We will also get two mesh tags, one for cells marked with physical groups in the mesh and one for facets marked with physical groups. As we did not not add any physical groups of dimension `gdim-1`, there will be no entities in the `facet_markers`."
116+
"We will import the GMSH-mesh directly from GMSH into DOLFINx via the `dolfinx.io.gmshio` interface.\n",
117+
"As in this example, we have not specified which process we have created the `gmsh` model on, a model has been created on each mpi process. However, we would like to be able to use a mesh distributed over all processes. Therefore, we take the model generated on rank 0 of `MPI.COMM_WORLD`, and distribute it over all available ranks. We will also get two mesh tags, one for cells marked with physical groups in the mesh and one for facets marked with physical groups. As we did not add any physical groups of dimension `gdim-1`, there will be no entities in the `facet_markers`."
118118
]
119119
},
120120
{
@@ -153,7 +153,7 @@
153153
"metadata": {},
154154
"source": [
155155
"## Defining a spatially varying load\n",
156-
"The right hand side pressure function is represented using `ufl.SpatialCoordinate` and a two constants, one for $\\beta$ and one for $R_0$."
156+
"The right hand side pressure function is represented using `ufl.SpatialCoordinate` and two constants, one for $\\beta$ and one for $R_0$."
157157
]
158158
},
159159
{
@@ -175,7 +175,7 @@
175175
"metadata": {},
176176
"source": [
177177
"## Create a Dirichlet boundary condition using geometrical conditions\n",
178-
"The next step is to create the homogenous boundary condition. As opposed to the [First tutorial](./fundamentals_code.ipynb) we will use `dolfinx.fem.locate_dofs_geometrical` to locate the degrees of freedom on the boundary. As we know that our domain is a circle with radius 1, we know that any degree of freedom should be located at a coordinate $(x,y)$ such that $\\sqrt{x^2+y^2}=1$."
178+
"The next step is to create the homogeneous boundary condition. As opposed to the [first tutorial](./fundamentals_code.ipynb) we will use `dolfinx.fem.locate_dofs_geometrical` to locate the degrees of freedom on the boundary. As we know that our domain is a circle with radius 1, we know that any degree of freedom should be located at a coordinate $(x,y)$ such that $\\sqrt{x^2+y^2}=1$."
179179
]
180180
},
181181
{
@@ -194,7 +194,7 @@
194194
"cell_type": "markdown",
195195
"metadata": {},
196196
"source": [
197-
"As our Dirichlet condition is homogenous (`u=0` on the whole boundary), we can initialize the `dolfinx.fem.dirichletbc` with a constant value, the degrees of freedom and the function space to apply the boundary condition on."
197+
"As our Dirichlet condition is homogeneous (`u=0` on the whole boundary), we can initialize the `dolfinx.fem.dirichletbc` with a constant value, the degrees of freedom and the function space to apply the boundary condition on."
198198
]
199199
},
200200
{
@@ -379,7 +379,7 @@
379379
"cell_type": "markdown",
380380
"metadata": {},
381381
"source": [
382-
"As a finite element function is the linear combination of all degrees of freedom, $u_h(x)=\\sum_{i=1}^N c_i \\phi_i(x)$ where $c_i$ are the coefficients of $u_h$, $\\phi_i$ the $i$th basis function, we can compute the exact solution at any point in $\\Omega$.\n",
382+
"As a finite element function is the linear combination of all degrees of freedom, $u_h(x)=\\sum_{i=1}^N c_i \\phi_i(x)$ where $c_i$ are the coefficients of $u_h$ and $\\phi_i$ is the $i$-th basis function, we can compute the exact solution at any point in $\\Omega$.\n",
383383
"However, as a mesh consists of a large set of degrees of freedom (i.e. $N$ is large), we want to reduce the number of evaluations of the basis function $\\phi_i(x)$. We do this by identifying which cell of the mesh $x$ is in. \n",
384384
"This is efficiently done by creating a bounding box tree of the cells of the mesh, allowing a quick recursive search through the mesh entities."
385385
]
@@ -446,7 +446,7 @@
446446
"cell_type": "markdown",
447447
"metadata": {},
448448
"source": [
449-
"As we now have an array of coordinates and two arrays of function values, we use matplotlib to plot them"
449+
"As we now have an array of coordinates and two arrays of function values, we can use `matplotlib` to plot them"
450450
]
451451
},
452452
{

chapter1/membrane_code.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# extension: .py
77
# format_name: light
88
# format_version: '1.5'
9-
# jupytext_version: 1.14.1
9+
# jupytext_version: 1.14.4
1010
# kernelspec:
1111
# display_name: Python 3 (ipykernel)
1212
# language: python
@@ -19,38 +19,38 @@
1919
# In this section, we will solve the deflection of the membrane problem.
2020
# After finishing this section, you should be able to:
2121
# - Create a simple mesh using the GMSH Python API and load it into DOLFINx
22-
# - How to create a constant boundary conditions using a geometrical identifier
23-
# - Using s`ufl.SpatialCoordinate` to create a spatially varying function
24-
# - How to interpolate a `ufl.Expression` into an appropriate function space
25-
# - How to evaluate a `dolfinx.Function` at any point $x$
22+
# - Create constant boundary conditions using a geometrical identifier
23+
# - Use `ufl.SpatialCoordinate` to create a spatially varying function
24+
# - Interpolate a `ufl.Expression` into an appropriate function space
25+
# - Evaluate a `dolfinx.Function` at any point $x$
2626
# - Use Paraview to visualize the solution of a PDE
2727
#
2828
# ## Creating the mesh
2929
#
30-
# To create the computational geometry, we use the python-API of [GMSH](http://gmsh.info/). We start by import the gmsh-module, and initalizing it.
30+
# To create the computational geometry, we use the python-API of [GMSH](http://gmsh.info/). We start by importing the gmsh-module and initializing it.
3131

3232
import gmsh
3333
gmsh.initialize()
3434

35-
# The next step is to create the membrane and starting the computations by the GMSH CAD kernel, to generate the relevant underlying data structures. The arguments into `addDisk` is the x, y and z coordinate of the center of the circle, while the to last argument is the x-radius and y-radius.
35+
# The next step is to create the membrane and start the computations by the GMSH CAD kernel, to generate the relevant underlying data structures. The first arguments of `addDisk` are the x, y and z coordinate of the center of the circle, while the two last arguments are the x-radius and y-radius.
3636

3737
membrane = gmsh.model.occ.addDisk(0, 0, 0, 1, 1)
3838
gmsh.model.occ.synchronize()
3939

40-
# The next step is to make the membrane a physical surface, such that it is recognized by gmsh when generating the mesh. As a surface is a two-dimensional entity, we add two as the first argument, the entity tag of the membrane as the second argument, and the last argument is the physical tag. In a later demo, we will get into when this tag matters.
40+
# After that, we make the membrane a physical surface, such that it is recognized by `gmsh` when generating the mesh. As a surface is a two-dimensional entity, we add `2` as the first argument, the entity tag of the membrane as the second argument, and the physical tag as the last argument. In a later demo, we will get into when this tag matters.
4141

4242
gdim = 2
4343
gmsh.model.addPhysicalGroup(gdim, [membrane], 1)
4444

45-
# Finally, we generate the two-dimensional mesh. We set a uniform mesh size by modifying the GMSH options
45+
# Finally, we generate the two-dimensional mesh. We set a uniform mesh size by modifying the GMSH options.
4646

4747
gmsh.option.setNumber("Mesh.CharacteristicLengthMin",0.05)
4848
gmsh.option.setNumber("Mesh.CharacteristicLengthMax",0.05)
4949
gmsh.model.mesh.generate(gdim)
5050

5151
# # Interfacing with GMSH in DOLFINx
52-
# We will import the GMSH-mesh directly from GMSH, using the `dolfinx.io.gmshio` interface in DOLFINx.
53-
# As we in the example have not specified which process we have created the gmsh model on, a model has been created on each mpi process. However, we would like to be able to use a mesh distributed over all processes. We therefore take the model generated on rank 0 of `MPI.COMM_WORLD`, and distribute it over all available ranks. We will also get two mesh tags, one for cells marked with physical groups in the mesh and one for facets marked with physical groups. As we did not not add any physical groups of dimension `gdim-1`, there will be no entities in the `facet_markers`.
52+
# We will import the GMSH-mesh directly from GMSH into DOLFINx via the `dolfinx.io.gmshio` interface.
53+
# As in this example, we have not specified which process we have created the `gmsh` model on, a model has been created on each mpi process. However, we would like to be able to use a mesh distributed over all processes. Therefore, we take the model generated on rank 0 of `MPI.COMM_WORLD`, and distribute it over all available ranks. We will also get two mesh tags, one for cells marked with physical groups in the mesh and one for facets marked with physical groups. As we did not add any physical groups of dimension `gdim-1`, there will be no entities in the `facet_markers`.
5454

5555
# +
5656
from dolfinx.io import gmshio
@@ -67,7 +67,7 @@
6767
V = fem.FunctionSpace(domain, ("CG", 1))
6868

6969
# ## Defining a spatially varying load
70-
# The right hand side pressure function is represented using `ufl.SpatialCoordinate` and a two constants, one for $\beta$ and one for $R_0$.
70+
# The right hand side pressure function is represented using `ufl.SpatialCoordinate` and two constants, one for $\beta$ and one for $R_0$.
7171

7272
import ufl
7373
from petsc4py.PETSc import ScalarType
@@ -77,14 +77,14 @@
7777
p = 4 * ufl.exp(-beta**2 * (x[0]**2 + (x[1] - R0)**2))
7878

7979
# ## Create a Dirichlet boundary condition using geometrical conditions
80-
# The next step is to create the homogenous boundary condition. As opposed to the [First tutorial](./fundamentals_code.ipynb) we will use `dolfinx.fem.locate_dofs_geometrical` to locate the degrees of freedom on the boundary. As we know that our domain is a circle with radius 1, we know that any degree of freedom should be located at a coordinate $(x,y)$ such that $\sqrt{x^2+y^2}=1$.
80+
# The next step is to create the homogeneous boundary condition. As opposed to the [first tutorial](./fundamentals_code.ipynb) we will use `dolfinx.fem.locate_dofs_geometrical` to locate the degrees of freedom on the boundary. As we know that our domain is a circle with radius 1, we know that any degree of freedom should be located at a coordinate $(x,y)$ such that $\sqrt{x^2+y^2}=1$.
8181

8282
import numpy as np
8383
def on_boundary(x):
8484
return np.isclose(np.sqrt(x[0]**2 + x[1]**2), 1)
8585
boundary_dofs = fem.locate_dofs_geometrical(V, on_boundary)
8686

87-
# As our Dirichlet condition is homogenous (`u=0` on the whole boundary), we can initialize the `dolfinx.fem.dirichletbc` with a constant value, the degrees of freedom and the function space to apply the boundary condition on.
87+
# As our Dirichlet condition is homogeneous (`u=0` on the whole boundary), we can initialize the `dolfinx.fem.dirichletbc` with a constant value, the degrees of freedom and the function space to apply the boundary condition on.
8888

8989
bc = fem.dirichletbc(ScalarType(0), boundary_dofs, V)
9090

@@ -159,7 +159,7 @@ def on_boundary(x):
159159
u_values = []
160160
p_values = []
161161

162-
# As a finite element function is the linear combination of all degrees of freedom, $u_h(x)=\sum_{i=1}^N c_i \phi_i(x)$ where $c_i$ are the coefficients of $u_h$, $\phi_i$ the $i$th basis function, we can compute the exact solution at any point in $\Omega$.
162+
# As a finite element function is the linear combination of all degrees of freedom, $u_h(x)=\sum_{i=1}^N c_i \phi_i(x)$ where $c_i$ are the coefficients of $u_h$ and $\phi_i$ is the $i$-th basis function, we can compute the exact solution at any point in $\Omega$.
163163
# However, as a mesh consists of a large set of degrees of freedom (i.e. $N$ is large), we want to reduce the number of evaluations of the basis function $\phi_i(x)$. We do this by identifying which cell of the mesh $x$ is in.
164164
# This is efficiently done by creating a bounding box tree of the cells of the mesh, allowing a quick recursive search through the mesh entities.
165165

@@ -190,7 +190,7 @@ def on_boundary(x):
190190
u_values = uh.eval(points_on_proc, cells)
191191
p_values = pressure.eval(points_on_proc, cells)
192192

193-
# As we now have an array of coordinates and two arrays of function values, we use matplotlib to plot them
193+
# As we now have an array of coordinates and two arrays of function values, we can use `matplotlib` to plot them
194194

195195
import matplotlib.pyplot as plt
196196
fig = plt.figure()

0 commit comments

Comments
 (0)