Skip to content

Commit 30c19dd

Browse files
authored
Revision all imports after change in main (#53)
* Revision all imports after change in main * Minor fix
1 parent be4ea67 commit 30c19dd

28 files changed

+1594
-1122
lines changed

.github/workflows/build-publish.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
build:
2121
# The type of runner that the job will run on
2222
runs-on: ubuntu-latest
23-
container: dokken92/dolfinx_custom:10092021
23+
container: dokken92/dolfinx_custom:28112021
2424

2525
env:
2626
HDF5_MPI: "ON"

.github/workflows/docker-image.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ jobs:
3737
run: echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
3838
- name: Push to the DockerHub registry
3939
run: |
40-
docker push dokken92/dolfinx_custom:10092021
40+
docker push dokken92/dolfinx_custom:28112021

.github/workflows/main-test.yml

+2-5
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ jobs:
2727

2828
env:
2929
HDF5_MPI: "ON"
30-
CC: mpicc
31-
HDF5_DIR: "/usr/lib/x86_64-linux-gnu/hdf5/mpich/"
32-
DISPLAY: ":99.0"
3330
PYVISTA_OFF_SCREEN: true
3431

3532
# Steps represent a sequence of tasks that will be executed as part of the job
@@ -39,12 +36,12 @@ jobs:
3936

4037
- name: Install dependencies
4138
run: |
42-
wget -qO - https://deb.nodesource.com/setup_16.x | bash
39+
wget -qO - https://deb.nodesource.com/setup_17.x | bash
4340
apt-get -qq update
4441
apt-get install -y libgl1-mesa-dev xvfb nodejs
4542
apt-get clean
4643
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
47-
pip3 install --no-cache-dir --no-binary=h5py h5py meshio
44+
CC=mpicc HDF_MPI="ON" HDF5_DIR="/usr/lib/x86_64-linux-gnu/hdf5/mpich/" pip3 install --no-cache-dir --no-binary=h5py h5py meshio
4845
pip3 install --no-cache-dir tqdm pandas seaborn
4946
pip3 install notebook nbconvert jupyter-book myst_parser pyvista jupyterlab
5047
pip3 install --no-cache-dir matplotlib itkwidgets ipywidgets setuptools --upgrade

Changelog.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Changelog
22

3-
## Dev
3+
## Dev
4+
- Various API changes relating to the import structure of DOLFINx
5+
6+
## 0.3.0 (09.09.2021)
47
- Major improvements in [Form compiler parameters](chapter4/compiler_parameters), using pandas and seaborn for visualization of speed-ups gained using form compiler parameters.
58
- API change: `dolfinx.cpp.la.scatter_forward(u.x)` -> `u.x.scatter_forward`
69
- Various plotting updates due to new version of pyvista.

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM dokken92/dolfinx_custom:03112021
1+
FROM dokken92/dolfinx_custom:28112021
22

33
# create user with a home directory
44
ARG NB_USER

chapter1/fundamentals_code.ipynb

+48-47
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"However, in cases where we have a solution we know that should have no approximation error, we know that the solution should\n",
5252
"be produced to machine precision by the program.\n",
5353
"\n",
54-
"The first eight lines of the program are importing the different modules required for solving the problem."
54+
"We start by importing external modules used alongside `dolfinx`."
5555
]
5656
},
5757
{
@@ -60,7 +60,6 @@
6060
"metadata": {},
6161
"outputs": [],
6262
"source": [
63-
"import dolfinx\n",
6463
"import numpy\n",
6564
"import ufl\n",
6665
"from mpi4py import MPI"
@@ -70,9 +69,9 @@
7069
"cell_type": "markdown",
7170
"metadata": {},
7271
"source": [
73-
"A major difference between a traditional FEniCS code and a FEniCSx code, is that one is not advised to use the wildcard import.\n",
72+
"A major difference between a traditional FEniCS code and a FEniCSx code, is that one is not advised to use the wildcard import. We will see this throughout this first example.\n",
7473
"## Generating simple meshes\n",
75-
"The next step is to define the discrete domain, _the mesh_\n"
74+
"The next step is to define the discrete domain, _the mesh_. We do this by importing the built-in `dolfinx.generation.UnitSquareMesh` function, that can build a $[0,1]\\times[0,1]$ mesh, consisting of either triangles or quadrilaterals."
7675
]
7776
},
7877
{
@@ -81,7 +80,9 @@
8180
"metadata": {},
8281
"outputs": [],
8382
"source": [
84-
"mesh = dolfinx.UnitSquareMesh(MPI.COMM_WORLD, 8, 8, dolfinx.cpp.mesh.CellType.quadrilateral)"
83+
"from dolfinx.generation import UnitSquareMesh\n",
84+
"from dolfinx.mesh import CellType\n",
85+
"mesh = UnitSquareMesh(MPI.COMM_WORLD, 8, 8, CellType.quadrilateral)"
8586
]
8687
},
8788
{
@@ -111,7 +112,8 @@
111112
"metadata": {},
112113
"outputs": [],
113114
"source": [
114-
" V = dolfinx.FunctionSpace(mesh, (\"CG\", 1))"
115+
"from dolfinx.fem import FunctionSpace\n",
116+
"V = FunctionSpace(mesh, (\"CG\", 1))"
115117
]
116118
},
117119
{
@@ -124,12 +126,15 @@
124126
"and hexahedra). For an overview, see:\n",
125127
"*FIXME: Add link to all the elements we support*\n",
126128
"\n",
127-
"The element degree in the code is 1. This means that we are choosing the standard $P_1$ linear Lagrange element, which has degrees of freedom at the vertices. The computed solution will be continuous across elements and linearly varying in $x$ and $y$ inside each element. Higher degree polynomial approximations are obtained by increasing the degree argument. \n",
129+
"The element degree in the code is 1. This means that we are choosing the standard $P_1$ linear Lagrange element, which has degrees of freedom at the vertices. \n",
130+
"The computed solution will be continuous across elements and linearly varying in $x$ and $y$ inside each element. Higher degree polynomial approximations are obtained by increasing the degree argument. \n",
128131
"\n",
129132
"## Defining the boundary conditions\n",
130133
"\n",
131-
"The next step is to specify the boundary condition $u=u_D$ on $\\partial\\Omega_D$, which is done by over several steps. The first step is to define the function $u_D$. Into this function, we would like to interpolate the boundary condition $1 + x^2+2y^2$. We do this by first defining a `dolfinx.Function`, and then using a [lambda-function](https://docs.python.org/3/tutorial/controlflow.html#lambda-expressions) in Python to define the \n",
132-
"spatially varying function. As we would like this program to work on one or multiple processors, we have to update the coefficients of $u_D$ that data shared between the processors. We do this by sending (scattering) the ghost values in the underlying data structure of `uD`.\n"
134+
"The next step is to specify the boundary condition $u=u_D$ on $\\partial\\Omega_D$, which is done by over several steps. \n",
135+
"The first step is to define the function $u_D$. Into this function, we would like to interpolate the boundary condition $1 + x^2+2y^2$.\n",
136+
"We do this by first defining a `dolfinx.Function`, and then using a [lambda-function](https://docs.python.org/3/tutorial/controlflow.html#lambda-expressions) in Python to define the \n",
137+
"spatially varying function.\n"
133138
]
134139
},
135140
{
@@ -138,9 +143,9 @@
138143
"metadata": {},
139144
"outputs": [],
140145
"source": [
141-
"uD = dolfinx.Function(V)\n",
142-
"uD.interpolate(lambda x: 1 + x[0]**2 + 2 * x[1]**2)\n",
143-
"uD.x.scatter_forward()"
146+
"from dolfinx.fem import Function\n",
147+
"uD = Function(V)\n",
148+
"uD.interpolate(lambda x: 1 + x[0]**2 + 2 * x[1]**2)"
144149
]
145150
},
146151
{
@@ -150,7 +155,7 @@
150155
"We now have the boundary data (and in this case the solution of \n",
151156
"the finite element problem) represented in the discrete function space.\n",
152157
"Next we would like to apply the boundary values to all degrees of freedom that are on the boundary of the discrete domain. We start by identifying the facets (line-segments) representing the outer boundary, using `dolfinx.cpp.mesh.compute_boundary_facets`.\n",
153-
"This function returns an array of booleans of the same size as the number of facets on this processor, where `True` indicates that the local facet $i$ is on the boundary. To reduce this to only the indices that are `True`, we use `numpy.where`.\n"
158+
"This function returns an array of booleans of the same size as the number of facets on this processor, where `True` indicates that the local facet $i$ is on the boundary. To reduce this to only the indices that are `True`, we use `numpy.where`."
154159
]
155160
},
156161
{
@@ -161,8 +166,9 @@
161166
"source": [
162167
"fdim = mesh.topology.dim - 1\n",
163168
"# Create facet to cell connectivity required to determine boundary facets\n",
169+
"from dolfinx.cpp.mesh import compute_boundary_facets\n",
164170
"mesh.topology.create_connectivity(fdim, mesh.topology.dim)\n",
165-
"boundary_facets = numpy.where(numpy.array(dolfinx.cpp.mesh.compute_boundary_facets(mesh.topology)) == 1)[0]"
171+
"boundary_facets = numpy.where(numpy.array(compute_boundary_facets(mesh.topology)) == 1)[0]"
166172
]
167173
},
168174
{
@@ -185,8 +191,9 @@
185191
"metadata": {},
186192
"outputs": [],
187193
"source": [
188-
"boundary_dofs = dolfinx.fem.locate_dofs_topological(V, fdim, boundary_facets)\n",
189-
"bc = dolfinx.DirichletBC(uD, boundary_dofs)"
194+
"from dolfinx.fem import locate_dofs_topological, DirichletBC\n",
195+
"boundary_dofs = locate_dofs_topological(V, fdim, boundary_facets)\n",
196+
"bc = DirichletBC(uD, boundary_dofs)"
190197
]
191198
},
192199
{
@@ -223,7 +230,8 @@
223230
"metadata": {},
224231
"outputs": [],
225232
"source": [
226-
"f = dolfinx.Constant(mesh, -6)"
233+
"from dolfinx.fem import Constant\n",
234+
"f = Constant(mesh, -6)"
227235
]
228236
},
229237
{
@@ -273,7 +281,8 @@
273281
"metadata": {},
274282
"outputs": [],
275283
"source": [
276-
"problem = dolfinx.fem.LinearProblem(a, L, bcs=[bc], petsc_options={\"ksp_type\": \"preonly\", \"pc_type\": \"lu\"})\n",
284+
"from dolfinx.fem import LinearProblem\n",
285+
"problem = LinearProblem(a, L, bcs=[bc], petsc_options={\"ksp_type\": \"preonly\", \"pc_type\": \"lu\"})\n",
277286
"uh = problem.solve()"
278287
]
279288
},
@@ -292,27 +301,27 @@
292301
"metadata": {},
293302
"outputs": [],
294303
"source": [
295-
"V2 = dolfinx.FunctionSpace(mesh, (\"CG\", 2))\n",
296-
"uex = dolfinx.Function(V2)\n",
297-
"uex.interpolate(lambda x: 1 + x[0]**2 + 2 * x[1]**2)\n",
298-
"uex.x.scatter_forward()"
304+
"V2 = FunctionSpace(mesh, (\"CG\", 2))\n",
305+
"uex = Function(V2)\n",
306+
"uex.interpolate(lambda x: 1 + x[0]**2 + 2 * x[1]**2)"
299307
]
300308
},
301309
{
302310
"cell_type": "markdown",
303311
"metadata": {},
304312
"source": [
305-
"We compute the error in two different ways. First, we compute the $L^2$-norm of the error, defined by $E=\\sqrt{\\int_\\Omega (u_D-u_h)^2\\mathrm{d} x}$. We use UFL to express the $L^2$-error:"
313+
"We compute the error in two different ways. First, we compute the $L^2$-norm of the error, defined by $E=\\sqrt{\\int_\\Omega (u_D-u_h)^2\\mathrm{d} x}$. We use UFL to express the $L^2$-error, and use `dolfinx.fem.assemble_scalar` to compute the scalar value."
306314
]
307315
},
308316
{
309317
"cell_type": "code",
310-
"execution_count": 12,
318+
"execution_count": 15,
311319
"metadata": {},
312320
"outputs": [],
313321
"source": [
322+
"from dolfinx.fem import assemble_scalar\n",
314323
"L2_error = ufl.inner(uh - uex, uh - uex) * ufl.dx\n",
315-
"error_L2 = numpy.sqrt(dolfinx.fem.assemble_scalar(L2_error))"
324+
"error_L2 = numpy.sqrt(assemble_scalar(L2_error))"
316325
]
317326
},
318327
{
@@ -329,15 +338,15 @@
329338
},
330339
{
331340
"cell_type": "code",
332-
"execution_count": 13,
341+
"execution_count": 16,
333342
"metadata": {},
334343
"outputs": [
335344
{
336345
"name": "stdout",
337346
"output_type": "stream",
338347
"text": [
339348
"Error_L2 : 8.24e-03\n",
340-
"Error_max : 2.22e-15\n"
349+
"Error_max : 3.11e-15\n"
341350
]
342351
}
343352
],
@@ -361,7 +370,7 @@
361370
},
362371
{
363372
"cell_type": "code",
364-
"execution_count": 14,
373+
"execution_count": 17,
365374
"metadata": {},
366375
"outputs": [],
367376
"source": [
@@ -371,7 +380,7 @@
371380
},
372381
{
373382
"cell_type": "code",
374-
"execution_count": 15,
383+
"execution_count": 18,
375384
"metadata": {},
376385
"outputs": [],
377386
"source": [
@@ -388,7 +397,7 @@
388397
},
389398
{
390399
"cell_type": "code",
391-
"execution_count": 16,
400+
"execution_count": 19,
392401
"metadata": {},
393402
"outputs": [],
394403
"source": [
@@ -409,13 +418,13 @@
409418
},
410419
{
411420
"cell_type": "code",
412-
"execution_count": 17,
421+
"execution_count": 20,
413422
"metadata": {},
414423
"outputs": [
415424
{
416425
"data": {
417426
"application/vnd.jupyter.widget-view+json": {
418-
"model_id": "e67d55e5b10847bc8134ae036945a0bf",
427+
"model_id": "c8d829e8954c46699aca8c42cd8b5b12",
419428
"version_major": 2,
420429
"version_minor": 0
421430
},
@@ -442,19 +451,19 @@
442451
"cell_type": "markdown",
443452
"metadata": {},
444453
"source": [
445-
"## Interactive plotting in notebooks\n",
446-
"To create an interactive plot using pyvista in a Jupyter notebook we us `pyvista.ITKPlotter` which uses `itkwidgets`. To modify the visualization, click on the three bars in the top left corner."
454+
"## Alternative plotting\n",
455+
"To create a more interactive plot using pyvista in a Jupyter notebook we us `pyvista.ITKPlotter` which uses `itkwidgets`. To modify the visualization, click on the three bars in the top left corner."
447456
]
448457
},
449458
{
450459
"cell_type": "code",
451-
"execution_count": 18,
460+
"execution_count": 21,
452461
"metadata": {},
453462
"outputs": [
454463
{
455464
"data": {
456465
"application/vnd.jupyter.widget-view+json": {
457-
"model_id": "f352aee90a2c403cadaa4c4885907023",
466+
"model_id": "5a5bdbffdc324a548691f67bb09a5a4c",
458467
"version_major": 2,
459468
"version_minor": 0
460469
},
@@ -484,17 +493,9 @@
484493
},
485494
{
486495
"cell_type": "code",
487-
"execution_count": 19,
496+
"execution_count": 22,
488497
"metadata": {},
489-
"outputs": [
490-
{
491-
"name": "stderr",
492-
"output_type": "stream",
493-
"text": [
494-
"2021-09-10 08:49:40.089 ( 4.500s) [main ] VTKFile.cpp:617 WARN| Output data is interpolated into a first order Lagrange space.\n"
495-
]
496-
}
497-
],
498+
"outputs": [],
498499
"source": [
499500
"import dolfinx.io\n",
500501
"with dolfinx.io.VTKFile(MPI.COMM_WORLD, \"output.pvd\", \"w\") as vtk:\n",
@@ -537,7 +538,7 @@
537538
"name": "python",
538539
"nbconvert_exporter": "python",
539540
"pygments_lexer": "ipython3",
540-
"version": "3.9.5"
541+
"version": "3.9.7"
541542
}
542543
},
543544
"nbformat": 4,

0 commit comments

Comments
 (0)