Skip to content

Update import-scheme in all demos. #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
container: dokken92/dolfinx_custom:06022022
container: dokken92/dolfinx_custom:22022022

env:
HDF5_MPI: "ON"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ jobs:
run: echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
- name: Push to the DockerHub registry
run: |
docker push dokken92/dolfinx_custom:06022022
docker push dokken92/dolfinx_custom:22022022
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM dokken92/dolfinx_custom:06022022
FROM dokken92/dolfinx_custom:22022022

# create user with a home directory
ARG NB_USER
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ Docker images for this tutorial can be found at [Docker hub](https://hub.docker.
Additional requirements on top of the `dolfinx/lab` images can be found at [Dockerfile](docker/Dockerfile) and [requirements.txt](docker/requirements.txt)

##
An image building DOLFINx, Basix and FFCx from source can be built using:
An image building DOLFINx, Basix, UFL and FFCx from source can be built using:
```bash
docker built -f docker/LocalDockerFile -t local_lab_env .
cd docker
docker build -f LocalDockerfile -t local_lab_env .
```
and run
```bash
docker run --rm -v $PWD:/root/shared -w /root/shared --init -p 8888:8888 local_lab_env
```
docker run --rm -ti -v $(pwd):/root/shared -w /root/shared --init -p 8888:8888 local_lab_env
```
from the main directory
101 changes: 48 additions & 53 deletions chapter1/fundamentals_code.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from mpi4py import MPI\n",
"from dolfinx.mesh import CellType, create_unit_square\n",
"mesh = create_unit_square(MPI.COMM_WORLD, 8, 8, CellType.quadrilateral)"
"from dolfinx import mesh\n",
"domain = mesh.create_unit_square(MPI.COMM_WORLD, 8, 8, mesh.CellType.quadrilateral)"
]
},
{
Expand All @@ -95,12 +95,12 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"from dolfinx.fem import FunctionSpace\n",
"V = FunctionSpace(mesh, (\"CG\", 1))"
"V = FunctionSpace(domain, (\"CG\", 1))"
]
},
{
Expand All @@ -126,12 +126,12 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"from dolfinx.fem import Function\n",
"uD = Function(V)\n",
"from dolfinx import fem\n",
"uD = fem.Function(V)\n",
"uD.interpolate(lambda x: 1 + x[0]**2 + 2 * x[1]**2)"
]
},
Expand All @@ -147,17 +147,16 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"import numpy\n",
"from dolfinx.mesh import compute_boundary_facets\n",
"# Create facet to cell connectivity required to determine boundary facets\n",
"tdim = mesh.topology.dim\n",
"tdim = domain.topology.dim\n",
"fdim = tdim - 1\n",
"mesh.topology.create_connectivity(fdim, tdim)\n",
"boundary_facets = numpy.flatnonzero(compute_boundary_facets(mesh.topology))"
"domain.topology.create_connectivity(fdim, tdim)\n",
"boundary_facets = numpy.flatnonzero(mesh.compute_boundary_facets(domain.topology))"
]
},
{
Expand All @@ -176,13 +175,12 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"from dolfinx.fem import locate_dofs_topological, dirichletbc\n",
"boundary_dofs = locate_dofs_topological(V, fdim, boundary_facets)\n",
"bc = dirichletbc(uD, boundary_dofs)"
"boundary_dofs = fem.locate_dofs_topological(V, fdim, boundary_facets)\n",
"bc = fem.dirichletbc(uD, boundary_dofs)"
]
},
{
Expand All @@ -199,7 +197,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -218,13 +216,12 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"from dolfinx.fem import Constant\n",
"from petsc4py.PETSc import ScalarType\n",
"f = Constant(mesh, ScalarType(-6))"
"f = fem.Constant(domain, ScalarType(-6))"
]
},
{
Expand All @@ -241,7 +238,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -271,18 +268,17 @@
"\n",
"## Forming and solving the linear system\n",
"\n",
"Having defined the finite element variational problem and boundary condition, we can create our `dolfinx.fem.LinearProblem`, as class for solving \n",
"Having defined the finite element variational problem and boundary condition, we can create our `dolfinx.fem.petsc.LinearProblem`, as class for solving \n",
"the variational problem: Find $u_h\\in V$ such that $a(u_h, v)==L(v) \\quad \\forall v \\in \\hat{V}$. We will use PETSc as our linear algebra backend, using a direct solver (LU-factorization). See the [PETSc-documentation](https://petsc.org/main/docs/manual/ksp/?highlight=ksp#ksp-linear-system-solvers) of the method for more information."
]
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"from dolfinx.fem import LinearProblem\n",
"problem = LinearProblem(a, L, bcs=[bc], petsc_options={\"ksp_type\": \"preonly\", \"pc_type\": \"lu\"})\n",
"problem = fem.petsc.LinearProblem(a, L, bcs=[bc], petsc_options={\"ksp_type\": \"preonly\", \"pc_type\": \"lu\"})\n",
"uh = problem.solve()"
]
},
Expand All @@ -297,12 +293,12 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"V2 = FunctionSpace(mesh, (\"CG\", 2))\n",
"uex = Function(V2)\n",
"V2 = fem.FunctionSpace(domain, (\"CG\", 2))\n",
"uex = fem.Function(V2)\n",
"uex.interpolate(lambda x: 1 + x[0]**2 + 2 * x[1]**2)"
]
},
Expand All @@ -316,14 +312,13 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"from dolfinx.fem import assemble_scalar, form\n",
"L2_error = form(ufl.inner(uh - uex, uh - uex) * ufl.dx)\n",
"error_local = assemble_scalar(L2_error)\n",
"error_L2 = numpy.sqrt(mesh.comm.allreduce(error_local, op=MPI.SUM))"
"L2_error = fem.form(ufl.inner(uh - uex, uh - uex) * ufl.dx)\n",
"error_local = fem.assemble_scalar(L2_error)\n",
"error_L2 = numpy.sqrt(domain.comm.allreduce(error_local, op=MPI.SUM))"
]
},
{
Expand All @@ -340,7 +335,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 17,
"metadata": {},
"outputs": [
{
Expand All @@ -355,7 +350,7 @@
"source": [
"error_max = numpy.max(numpy.abs(uD.x.array-uh.x.array))\n",
"# Only print the error on one process\n",
"if mesh.comm.rank == 0:\n",
"if domain.comm.rank == 0:\n",
" print(f\"Error_L2 : {error_L2:.2e}\")\n",
" print(f\"Error_max : {error_max:.2e}\")"
]
Expand All @@ -372,13 +367,13 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"from dolfinx.plot import create_vtk_mesh\n",
"from dolfinx import plot\n",
"import pyvista\n",
"topology, cell_types, geometry = create_vtk_mesh(mesh, mesh.topology.dim)\n",
"topology, cell_types, geometry = plot.create_vtk_mesh(domain, tdim)\n",
"grid = pyvista.UnstructuredGrid(topology, cell_types, geometry)"
]
},
Expand All @@ -391,7 +386,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -408,13 +403,13 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8153fbfcef014a3899925003792a4ba1",
"model_id": "1097226e4af046409f3ee7526bb758ef",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -447,11 +442,11 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"u_topology, u_cell_types, u_geometry = create_vtk_mesh(V)"
"u_topology, u_cell_types, u_geometry = plot.create_vtk_mesh(V)"
]
},
{
Expand All @@ -463,13 +458,13 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "54e3bc7b8f764a31836e14906e188aff",
"model_id": "9a2c3d07867d4c04bd31f10ea7287c58",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -502,13 +497,13 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "c03cdb732aa94579ab795f0188ce9572",
"model_id": "879d16dc01274ae1b929357fcd0f06c8",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -538,15 +533,15 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
"import dolfinx.io\n",
"with dolfinx.io.VTKFile(MPI.COMM_WORLD, \"output.pvd\", \"w\") as vtk:\n",
"from dolfinx import io\n",
"with io.VTKFile(domain.comm, \"output.pvd\", \"w\") as vtk:\n",
" vtk.write([uh._cpp_object])\n",
"with dolfinx.io.XDMFFile(MPI.COMM_WORLD, \"output.xdmf\", \"w\") as xdmf:\n",
" xdmf.write_mesh(mesh)\n",
"with io.XDMFFile(domain.comm, \"output.xdmf\", \"w\") as xdmf:\n",
" xdmf.write_mesh(domain)\n",
" xdmf.write_function(uh)"
]
},
Expand Down
Loading