Skip to content

Commit f4438cf

Browse files
committed
Update GMSH interface in DOLFINx
1 parent 6545e69 commit f4438cf

27 files changed

+631
-683
lines changed

.github/workflows/build-publish.yml

Lines changed: 1 addition & 1 deletion
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:02072022
23+
container: dokken92/dolfinx_custom:15072022
2424

2525
env:
2626
HDF5_MPI: "ON"

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## Dev
4+
- Using new GMSH interface in DOLFINx (`dolfinx.io.gmshio`) in all demos using GMSH
45
- Added a section on custom Newton-solvers, see [chapter4/newton-solver].
56
- Various minor DOLFINx API updates. `dolfinx.mesh.compute_boundary_facets` -> `dolfinx.mesh.exterior_facet_indices` with slightly different functionality. Use `dolfinx.mesh.MeshTagsMetaClass.find` instead of `mt.indices[mt.values==value]`.
67
- Various numpy updates, use `np.full_like`.

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM dokken92/dolfinx_custom:02072022
1+
FROM dokken92/dolfinx_custom:15072022
22

33
# create user with a home directory
44
ARG NB_USER

chapter1/complex_mode.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@
425425
{
426426
"data": {
427427
"application/vnd.jupyter.widget-view+json": {
428-
"model_id": "01cf0d12a4c34809bc9465aa22b7dfd9",
428+
"model_id": "d78185ab2481475d8596d2e5cfa2f975",
429429
"version_major": 2,
430430
"version_minor": 0
431431
},
@@ -455,7 +455,7 @@
455455
{
456456
"data": {
457457
"application/vnd.jupyter.widget-view+json": {
458-
"model_id": "c19f2e16f48c480289da0d46a1a3c4b1",
458+
"model_id": "8594601f751740259e13087567cb8d79",
459459
"version_major": 2,
460460
"version_minor": 0
461461
},

chapter1/fundamentals_code.ipynb

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,10 +497,18 @@
497497
}
498498
},
499499
"outputs": [
500+
{
501+
"name": "stderr",
502+
"output_type": "stream",
503+
"text": [
504+
"\u001b[0m\u001b[2m2022-07-15 17:29:58.326 ( 0.450s) [ A689B000] vtkExtractEdges.cxx:435 INFO| \u001b[0mExecuting edge extractor: points are renumbered\u001b[0m\n",
505+
"\u001b[0m\u001b[2m2022-07-15 17:29:58.327 ( 0.451s) [ A689B000] vtkExtractEdges.cxx:551 INFO| \u001b[0mCreated 144 edges\u001b[0m\n"
506+
]
507+
},
500508
{
501509
"data": {
502510
"application/vnd.jupyter.widget-view+json": {
503-
"model_id": "96bf5e0086d947c9ac1e63e47da9158e",
511+
"model_id": "aa1c4a39e706471fbbbc7660e9e614cc",
504512
"version_major": 2,
505513
"version_minor": 0
506514
},
@@ -564,10 +572,18 @@
564572
}
565573
},
566574
"outputs": [
575+
{
576+
"name": "stderr",
577+
"output_type": "stream",
578+
"text": [
579+
"\u001b[0m\u001b[2m2022-07-15 17:29:58.535 ( 0.659s) [ A689B000] vtkExtractEdges.cxx:435 INFO| \u001b[0mExecuting edge extractor: points are renumbered\u001b[0m\n",
580+
"\u001b[0m\u001b[2m2022-07-15 17:29:58.536 ( 0.660s) [ A689B000] vtkExtractEdges.cxx:551 INFO| \u001b[0mCreated 144 edges\u001b[0m\n"
581+
]
582+
},
567583
{
568584
"data": {
569585
"application/vnd.jupyter.widget-view+json": {
570-
"model_id": "de3d6bc61d624957be68d54112ebed07",
586+
"model_id": "fe89f520dad64572a085fb57e0320767",
571587
"version_major": 2,
572588
"version_minor": 0
573589
},
@@ -612,7 +628,7 @@
612628
{
613629
"data": {
614630
"application/vnd.jupyter.widget-view+json": {
615-
"model_id": "b3261590b61343e6b41facd8f29970d7",
631+
"model_id": "239cddce9b5c4e09b0c82c36b5f3cac6",
616632
"version_major": 2,
617633
"version_minor": 0
618634
},

chapter1/membrane_code.ipynb

Lines changed: 47 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,21 @@
5959
"cell_type": "code",
6060
"execution_count": 3,
6161
"metadata": {},
62-
"outputs": [],
62+
"outputs": [
63+
{
64+
"data": {
65+
"text/plain": [
66+
"1"
67+
]
68+
},
69+
"execution_count": 3,
70+
"metadata": {},
71+
"output_type": "execute_result"
72+
}
73+
],
6374
"source": [
6475
"gdim = 2\n",
65-
"status = gmsh.model.addPhysicalGroup(gdim, [membrane], 1)"
76+
"gmsh.model.addPhysicalGroup(gdim, [membrane], 1)"
6677
]
6778
},
6879
{
@@ -83,10 +94,10 @@
8394
"text": [
8495
"Info : Meshing 1D...\n",
8596
"Info : Meshing curve 1 (Ellipse)\n",
86-
"Info : Done meshing 1D (Wall 0.000161882s, CPU 0.000254s)\n",
97+
"Info : Done meshing 1D (Wall 0.000842374s, CPU 0.000939s)\n",
8798
"Info : Meshing 2D...\n",
8899
"Info : Meshing surface 1 (Plane, Frontal-Delaunay)\n",
89-
"Info : Done meshing 2D (Wall 0.0748596s, CPU 0.075328s)\n",
100+
"Info : Done meshing 2D (Wall 0.0902373s, CPU 0.088198s)\n",
90101
"Info : 1550 nodes 3099 elements\n"
91102
]
92103
}
@@ -101,7 +112,9 @@
101112
"cell_type": "markdown",
102113
"metadata": {},
103114
"source": [
104-
"We will import the GMSH-mesh directly from GMSH, using the approach in Section 2 of [A GMSH tutorial for DOLFINx](https://jsdokken.com/src/tutorial_gmsh.html). To make sure this runs in parallel and serial, we will read in the mesh on one processor, and let DOLFINx distribute the mesh data among the processros."
115+
"# 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`."
105118
]
106119
},
107120
{
@@ -110,63 +123,12 @@
110123
"metadata": {},
111124
"outputs": [],
112125
"source": [
113-
"from dolfinx import io\n",
126+
"from dolfinx.io import gmshio\n",
114127
"from mpi4py import MPI\n",
115-
"if MPI.COMM_WORLD.rank == 0:\n",
116-
" # Get mesh geometry\n",
117-
" geometry_data = io.extract_gmsh_geometry(gmsh.model)\n",
118-
" # Get mesh topology for each element\n",
119-
" topology_data = io.extract_gmsh_topology_and_markers(gmsh.model)"
120-
]
121-
},
122-
{
123-
"cell_type": "markdown",
124-
"metadata": {},
125-
"source": [
126-
"The topology data is a dictionary, where the key is the gmsh cell type (an integer). Each key accesses a dictionary with the topology data and corresponding topology markers. As this mesh only contains one cell type (triangles), as we did not mark any facets, we do not need to loop over the keys of this dictionary, only extract the first one."
127-
]
128-
},
129-
{
130-
"cell_type": "code",
131-
"execution_count": 6,
132-
"metadata": {},
133-
"outputs": [],
134-
"source": [
135-
"import numpy as np\n",
136-
"if MPI.COMM_WORLD.rank == 0:\n",
137-
" # Extract the cell type and number of nodes per cell and broadcast\n",
138-
" # it to the other processors \n",
139-
" gmsh_cell_type = list(topology_data.keys())[0] \n",
140-
" properties = gmsh.model.mesh.getElementProperties(gmsh_cell_type)\n",
141-
" name, dim, order, num_nodes, local_coords, _ = properties\n",
142-
" cells = topology_data[gmsh_cell_type][\"topology\"]\n",
143-
" cell_id, num_nodes = MPI.COMM_WORLD.bcast([gmsh_cell_type, num_nodes], root=0)\n",
144-
"else: \n",
145-
" cell_id, num_nodes = MPI.COMM_WORLD.bcast([None, None], root=0)\n",
146-
" cells, geometry_data = np.empty([0, num_nodes]), np.empty([0, gdim])"
147-
]
148-
},
149-
{
150-
"cell_type": "markdown",
151-
"metadata": {},
152-
"source": [
153-
"As we have now broadcasted all the information required to distribute the mesh in parallel"
154-
]
155-
},
156-
{
157-
"cell_type": "code",
158-
"execution_count": 7,
159-
"metadata": {},
160-
"outputs": [],
161-
"source": [
162-
"from dolfinx import mesh, cpp\n",
163-
"# Permute topology data from MSH-ordering to dolfinx-ordering\n",
164-
"ufl_domain = io.ufl_mesh_from_gmsh(cell_id, gdim)\n",
165-
"gmsh_cell_perm = io.cell_perm_gmsh(cpp.mesh.to_type(str(ufl_domain.ufl_cell())), num_nodes)\n",
166-
"cells = cells[:, gmsh_cell_perm]\n",
167128
"\n",
168-
"# Create distributed mesh\n",
169-
"domain = mesh.create_mesh(MPI.COMM_WORLD, cells, geometry_data[:, :gdim], ufl_domain)"
129+
"gmsh_model_rank = 0\n",
130+
"mesh_comm = MPI.COMM_WORLD\n",
131+
"domain, cell_markers, facet_markers = gmshio.model_to_mesh(gmsh.model, mesh_comm, gmsh_model_rank, gdim=gdim)"
170132
]
171133
},
172134
{
@@ -178,7 +140,7 @@
178140
},
179141
{
180142
"cell_type": "code",
181-
"execution_count": 8,
143+
"execution_count": 6,
182144
"metadata": {},
183145
"outputs": [],
184146
"source": [
@@ -196,7 +158,7 @@
196158
},
197159
{
198160
"cell_type": "code",
199-
"execution_count": 9,
161+
"execution_count": 7,
200162
"metadata": {},
201163
"outputs": [],
202164
"source": [
@@ -218,10 +180,11 @@
218180
},
219181
{
220182
"cell_type": "code",
221-
"execution_count": 10,
183+
"execution_count": 8,
222184
"metadata": {},
223185
"outputs": [],
224186
"source": [
187+
"import numpy as np\n",
225188
"def on_boundary(x):\n",
226189
" return np.isclose(np.sqrt(x[0]**2 + x[1]**2), 1)\n",
227190
"boundary_dofs = fem.locate_dofs_geometrical(V, on_boundary)"
@@ -236,7 +199,7 @@
236199
},
237200
{
238201
"cell_type": "code",
239-
"execution_count": 11,
202+
"execution_count": 9,
240203
"metadata": {},
241204
"outputs": [],
242205
"source": [
@@ -253,7 +216,7 @@
253216
},
254217
{
255218
"cell_type": "code",
256-
"execution_count": 12,
219+
"execution_count": 10,
257220
"metadata": {},
258221
"outputs": [],
259222
"source": [
@@ -276,7 +239,7 @@
276239
},
277240
{
278241
"cell_type": "code",
279-
"execution_count": 13,
242+
"execution_count": 11,
280243
"metadata": {},
281244
"outputs": [],
282245
"source": [
@@ -296,15 +259,23 @@
296259
},
297260
{
298261
"cell_type": "code",
299-
"execution_count": 14,
262+
"execution_count": 12,
300263
"metadata": {
301264
"scrolled": true
302265
},
303266
"outputs": [
267+
{
268+
"name": "stderr",
269+
"output_type": "stream",
270+
"text": [
271+
"\u001b[0m\u001b[2m2022-07-15 17:30:39.952 ( 0.525s) [ 76AC1000] vtkExtractEdges.cxx:435 INFO| \u001b[0mExecuting edge extractor: points are renumbered\u001b[0m\n",
272+
"\u001b[0m\u001b[2m2022-07-15 17:30:39.958 ( 0.531s) [ 76AC1000] vtkExtractEdges.cxx:551 INFO| \u001b[0mCreated 4521 edges\u001b[0m\n"
273+
]
274+
},
304275
{
305276
"data": {
306277
"application/vnd.jupyter.widget-view+json": {
307-
"model_id": "b0f7b49211fa49ddafd2bcb0e28e0fc7",
278+
"model_id": "32d8b1feff23457cb167bf0dc36d7ab8",
308279
"version_major": 2,
309280
"version_minor": 0
310281
},
@@ -347,13 +318,13 @@
347318
},
348319
{
349320
"cell_type": "code",
350-
"execution_count": 15,
321+
"execution_count": 13,
351322
"metadata": {},
352323
"outputs": [
353324
{
354325
"data": {
355326
"application/vnd.jupyter.widget-view+json": {
356-
"model_id": "9620c7a85a8c480f8afe9cd768fe9969",
327+
"model_id": "1f73d1fd610047b7b68f4ebd6375eec0",
357328
"version_major": 2,
358329
"version_minor": 0
359330
},
@@ -392,7 +363,7 @@
392363
},
393364
{
394365
"cell_type": "code",
395-
"execution_count": 16,
366+
"execution_count": 14,
396367
"metadata": {},
397368
"outputs": [],
398369
"source": [
@@ -415,7 +386,7 @@
415386
},
416387
{
417388
"cell_type": "code",
418-
"execution_count": 17,
389+
"execution_count": 15,
419390
"metadata": {},
420391
"outputs": [],
421392
"source": [
@@ -437,7 +408,7 @@
437408
},
438409
{
439410
"cell_type": "code",
440-
"execution_count": 18,
411+
"execution_count": 16,
441412
"metadata": {},
442413
"outputs": [],
443414
"source": [
@@ -462,7 +433,7 @@
462433
},
463434
{
464435
"cell_type": "code",
465-
"execution_count": 19,
436+
"execution_count": 17,
466437
"metadata": {},
467438
"outputs": [],
468439
"source": [
@@ -480,7 +451,7 @@
480451
},
481452
{
482453
"cell_type": "code",
483-
"execution_count": 20,
454+
"execution_count": 18,
484455
"metadata": {},
485456
"outputs": [
486457
{
@@ -518,7 +489,7 @@
518489
},
519490
{
520491
"cell_type": "code",
521-
"execution_count": 21,
492+
"execution_count": 19,
522493
"metadata": {},
523494
"outputs": [],
524495
"source": [

0 commit comments

Comments
 (0)