Skip to content

Commit e8726b8

Browse files
committed
Include changes from #237 by @MattFerraro
1 parent c45338d commit e8726b8

5 files changed

Lines changed: 38 additions & 22 deletions

File tree

chapter1/fundamentals_code.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@
290290
"The inner product $\\int_\\Omega \\nabla u \\cdot \\nabla v ~\\mathrm{d} x$ can be expressed in various ways in UFL. We have used the notation `ufl.dot(ufl.grad(u), ufl.grad(v))*ufl.dx`.\n",
291291
"The dot product in UFL computes the sum (contraction) over the last index of the first factor and first index of the second factor.\n",
292292
"In this case, both factors are tensors of rank one (vectors) and so the sum is just over the single index of both $\\nabla u$ and $\\nabla v$.\n",
293-
"To compute an inner product of matrices (with two indices), one must instead of `ufl.dot` use the function `ufl.inner`. For vectors, `ufl.dot` and `ufl.inner` are equivalent.\n",
293+
"To compute an inner product of matrices (with two indices), on must use use the function `ufl.inner` instead of `ufl.dot`.\n",
294+
"For vectors, `ufl.dot` and `ufl.inner` are equivalent.\n",
294295
"\n",
295296
"```{admonition} Complex numbers\n",
296297
"In DOLFINx, one can solve complex number problems by using an installation of PETSc using complex numbers.\n",

chapter1/fundamentals_code.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@
173173
# The inner product $\int_\Omega \nabla u \cdot \nabla v ~\mathrm{d} x$ can be expressed in various ways in UFL. We have used the notation `ufl.dot(ufl.grad(u), ufl.grad(v))*ufl.dx`.
174174
# The dot product in UFL computes the sum (contraction) over the last index of the first factor and first index of the second factor.
175175
# In this case, both factors are tensors of rank one (vectors) and so the sum is just over the single index of both $\nabla u$ and $\nabla v$.
176-
# To compute an inner product of matrices (with two indices), one must instead of `ufl.dot` use the function `ufl.inner`. For vectors, `ufl.dot` and `ufl.inner` are equivalent.
176+
# To compute an inner product of matrices (with two indices), on must use use the function `ufl.inner` instead of `ufl.dot`.
177+
# For vectors, `ufl.dot` and `ufl.inner` are equivalent.
177178
#
178179
# ```{admonition} Complex numbers
179180
# In DOLFINx, one can solve complex number problems by using an installation of PETSc using complex numbers.

chapter2/linearelasticity_code.ipynb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
"- Compute Von Mises stresses\n",
1515
"\n",
1616
"## Test problem\n",
17-
"As a test example, we will model a clamped beam deformed under its own weight in 3D. This can be modeled, by setting the right-hand side body force per unit volume to $f=(0,0,-\\rho g)$ with $\\rho$ the density of the beam and $g$ the acceleration of gravity. The beam is box-shaped with length $L$ and has a square cross section of width $W$. We set $u=u_D=(0,0,0)$ at the clamped end, x=0. The rest of the boundary is traction free, that is, we set $T=0$. We start by defining the physical variables used in the program."
17+
"As a test example, we will model a clamped beam deformed under its own weight in 3D.\n",
18+
"This can be modeled, by setting the right-hand side body force per unit volume to $f=(0,0,-\\rho g)$ with $\\rho$ the density of the beam and $g$ the acceleration of gravity.\n",
19+
"The beam is box-shaped with length $L$ and has a square cross section of width $W$. We set $u=u_D=(0,0,0)$ at the clamped end, x=0. The rest of the boundary is traction free, that is, we set $T=0$.\n",
20+
"We start by defining the physical variables used in the program."
1821
]
1922
},
2023
{
@@ -24,7 +27,6 @@
2427
"metadata": {},
2528
"outputs": [],
2629
"source": [
27-
"# Scaled variable\n",
2830
"import pyvista\n",
2931
"from dolfinx import mesh, fem, plot, io, default_scalar_type\n",
3032
"from dolfinx.fem.petsc import LinearProblem\n",
@@ -41,7 +43,7 @@
4143
},
4244
"outputs": [],
4345
"source": [
44-
"L = 1\n",
46+
"L = 1.0\n",
4547
"W = 0.2\n",
4648
"mu = 1\n",
4749
"rho = 1\n",

chapter4/compiler_parameters.ipynb

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@
2626
"metadata": {},
2727
"outputs": [],
2828
"source": [
29-
"import matplotlib.pyplot as plt\n",
3029
"import pandas as pd\n",
3130
"import seaborn\n",
3231
"import time\n",
33-
"import ufl\n",
3432
"\n",
3533
"from ufl import TestFunction, TrialFunction, dx, inner\n",
3634
"from dolfinx.mesh import create_unit_cube\n",
@@ -50,7 +48,8 @@
5048
"id": "2",
5149
"metadata": {},
5250
"source": [
53-
"Next we generate a general function to assemble the mass matrix for a unit cube. Note that we use `dolfinx.fem.form` to compile the variational form. For codes using `dolfinx.fem.petsc.LinearProblem`, you can supply `jit_options` as a keyword argument."
51+
"Next we generate a general function to assemble the mass matrix for a unit cube. Note that we use `dolfinx.fem.form` to compile the variational form.\n",
52+
"For codes using `dolfinx.fem.petsc.LinearProblem`, you can supply `jit_options` as a keyword argument."
5453
]
5554
},
5655
{
@@ -136,8 +135,11 @@
136135
" cffi_options = [option, \"-march=native\"]\n",
137136
" else:\n",
138137
" cffi_options = [option]\n",
139-
" jit_options = {\"cffi_extra_compile_args\": cffi_options,\n",
140-
" \"cache_dir\": cache_dir, \"cffi_libraries\": [\"m\"]}\n",
138+
" jit_options = {\n",
139+
" \"cffi_extra_compile_args\": cffi_options,\n",
140+
" \"cache_dir\": cache_dir,\n",
141+
" \"cffi_libraries\": [\"m\"],\n",
142+
" }\n",
141143
" runtime = compile_form(space, degree, jit_options=jit_options)\n",
142144
" results[\"Space\"].append(space)\n",
143145
" results[\"Degree\"].append(str(degree))\n",
@@ -150,7 +152,9 @@
150152
"id": "10",
151153
"metadata": {},
152154
"source": [
153-
"We have now stored all the results to a dictionary. To visualize it, we use pandas and its Dataframe class. We can inspect the data in a jupyter notebook as follows"
155+
"We have now stored all the results to a dictionary. To visualize it, we use pandas and its Dataframe class.\n",
156+
"To instpect the data in a Jupyter notebook, call the code below.\n",
157+
"If you are running this code in a script, you can use `print(results_df)` instead."
154158
]
155159
},
156160
{
@@ -169,7 +173,8 @@
169173
"id": "12",
170174
"metadata": {},
171175
"source": [
172-
"We can now make a plot for each element type to see the variation given the different compile options. We create a new colum for each element type and degree."
176+
"Next, we inspect the impact of the compiler option on each type of finite element family.\n",
177+
"To achieve this, we add an extra column to the dataframe, which combines the space and degree of the finite element."
173178
]
174179
},
175180
{
@@ -195,7 +200,8 @@
195200
"id": "14",
196201
"metadata": {},
197202
"source": [
198-
"We observe that the compile time increases when increasing the degree of the function space, and that we get most speedup by using \"-O3\" or \"-Ofast\" combined with \"-march=native\"."
203+
"We observe that the compile time increases when increasing the degree of the function space,\n",
204+
"and that we get most speedup by using \"-O3\" or \"-Ofast\" combined with \"-march=native\"."
199205
]
200206
}
201207
],

chapter4/compiler_parameters.py

Lines changed: 15 additions & 9 deletions
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.16.5
9+
# jupytext_version: 1.17.2
1010
# kernelspec:
1111
# display_name: Python 3 (ipykernel)
1212
# language: python
@@ -27,11 +27,9 @@
2727
# We start by specifying the current directory as the location to place the generated C files, we obtain the current directory using pathlib
2828

2929
# +
30-
import matplotlib.pyplot as plt
3130
import pandas as pd
3231
import seaborn
3332
import time
34-
import ufl
3533

3634
from ufl import TestFunction, TrialFunction, dx, inner
3735
from dolfinx.mesh import create_unit_cube
@@ -46,7 +44,8 @@
4644
print(f"Directory to put C files in: {cache_dir}")
4745
# -
4846

49-
# Next we generate a general function to assemble the mass matrix for a unit cube. Note that we use `dolfinx.fem.form` to compile the variational form. For codes using `dolfinx.fem.petsc.LinearProblem`, you can supply `jit_options` as a keyword argument.
47+
# Next we generate a general function to assemble the mass matrix for a unit cube. Note that we use `dolfinx.fem.form` to compile the variational form.
48+
# For codes using `dolfinx.fem.petsc.LinearProblem`, you can supply `jit_options` as a keyword argument.
5049

5150
# +
5251

@@ -86,20 +85,26 @@ def compile_form(space: str, degree: int, jit_options: Dict):
8685
cffi_options = [option, "-march=native"]
8786
else:
8887
cffi_options = [option]
89-
jit_options = {"cffi_extra_compile_args": cffi_options,
90-
"cache_dir": cache_dir, "cffi_libraries": ["m"]}
88+
jit_options = {
89+
"cffi_extra_compile_args": cffi_options,
90+
"cache_dir": cache_dir,
91+
"cffi_libraries": ["m"],
92+
}
9193
runtime = compile_form(space, degree, jit_options=jit_options)
9294
results["Space"].append(space)
9395
results["Degree"].append(str(degree))
9496
results["Options"].append("\n".join(cffi_options))
9597
results["Time"].append(runtime)
9698

97-
# We have now stored all the results to a dictionary. To visualize it, we use pandas and its Dataframe class. We can inspect the data in a jupyter notebook as follows
99+
# We have now stored all the results to a dictionary. To visualize it, we use pandas and its Dataframe class.
100+
# To instpect the data in a Jupyter notebook, call the code below.
101+
# If you are running this code in a script, you can use `print(results_df)` instead.
98102

99103
results_df = pd.DataFrame.from_dict(results)
100104
results_df
101105

102-
# We can now make a plot for each element type to see the variation given the different compile options. We create a new colum for each element type and degree.
106+
# Next, we inspect the impact of the compiler option on each type of finite element family.
107+
# To achieve this, we add an extra column to the dataframe, which combines the space and degree of the finite element.
103108

104109
seaborn.set(style="ticks")
105110
seaborn.set(font_scale=1.2)
@@ -111,4 +116,5 @@ def compile_form(space: str, degree: int, jit_options: Dict):
111116
g = seaborn.catplot(x="Options", y="Time", kind="bar", data=df_e, col="Element")
112117
g.fig.set_size_inches(16, 4)
113118

114-
# We observe that the compile time increases when increasing the degree of the function space, and that we get most speedup by using "-O3" or "-Ofast" combined with "-march=native".
119+
# We observe that the compile time increases when increasing the degree of the function space,
120+
# and that we get most speedup by using "-O3" or "-Ofast" combined with "-march=native".

0 commit comments

Comments
 (0)