|
12 | 12 | "from numpy import pi as π\n", |
13 | 13 | "import matplotlib.pyplot as plt\n", |
14 | 14 | "import firedrake\n", |
15 | | - "from firedrake import inner, grad, dx, ds, exp, min_value, max_value, Constant, derivative\n", |
| 15 | + "from firedrake import inner, grad, dx, ds, exp, min_value, max_value, Constant\n", |
16 | 16 | "import irksome\n", |
17 | 17 | "import icepack\n", |
18 | 18 | "from icepack2 import model" |
|
34 | 34 | "We'll use a computational domain about half that size." |
35 | 35 | ] |
36 | 36 | }, |
| 37 | + { |
| 38 | + "cell_type": "code", |
| 39 | + "execution_count": null, |
| 40 | + "id": "de2a5adf-a9b1-4948-aa16-5f7459f670c0", |
| 41 | + "metadata": {}, |
| 42 | + "outputs": [], |
| 43 | + "source": [ |
| 44 | + "def read_mesh_file(mesh_file):\n", |
| 45 | + " lines = mesh_file.readlines()\n", |
| 46 | + " line_number = [\"Vertices\" in line for line in lines].index(True) + 1\n", |
| 47 | + " num_vertices = int(lines[line_number])\n", |
| 48 | + " points = np.zeros((num_vertices, 2))\n", |
| 49 | + " vertex_lines = lines[line_number + 1: line_number + num_vertices + 1]\n", |
| 50 | + " for index, line in enumerate(vertex_lines):\n", |
| 51 | + " points[index, :] = [float(val) for val in line.split(\" \")[:2]]\n", |
| 52 | + "\n", |
| 53 | + " line_number = [\"Triangles\" in line for line in lines].index(True) + 1\n", |
| 54 | + " num_triangles = int(lines[line_number])\n", |
| 55 | + " triangles = np.zeros((num_triangles, 3), dtype=int)\n", |
| 56 | + " triangle_lines = lines[line_number + 1: line_number + num_triangles + 1]\n", |
| 57 | + " for index, line in enumerate(triangle_lines):\n", |
| 58 | + " triangles[index, :] = [int(val) for val in line.split(\" \")[:3]]\n", |
| 59 | + "\n", |
| 60 | + " return points, triangles - 1" |
| 61 | + ] |
| 62 | + }, |
| 63 | + { |
| 64 | + "cell_type": "code", |
| 65 | + "execution_count": null, |
| 66 | + "id": "2f071b37-552a-4096-b36f-5782d6d53dc9", |
| 67 | + "metadata": {}, |
| 68 | + "outputs": [], |
| 69 | + "source": [ |
| 70 | + "mesh_filename = \"disk_anisotropic.mesh\"\n", |
| 71 | + "with open(mesh_filename, \"r\") as mesh_file:\n", |
| 72 | + " points, triangles = read_mesh_file(mesh_file)\n", |
| 73 | + "\n", |
| 74 | + "comm = firedrake.COMM_WORLD\n", |
| 75 | + "plex = firedrake.mesh.plex_from_cell_list(2, triangles, points, comm)\n", |
| 76 | + "mesh = firedrake.Mesh(plex)" |
| 77 | + ] |
| 78 | + }, |
37 | 79 | { |
38 | 80 | "cell_type": "code", |
39 | 81 | "execution_count": null, |
|
42 | 84 | "outputs": [], |
43 | 85 | "source": [ |
44 | 86 | "radius = Constant(12e3)\n", |
45 | | - "mesh = firedrake.UnitDiskMesh(4)\n", |
46 | 87 | "mesh.coordinates.dat.data[:] *= float(radius)" |
47 | 88 | ] |
48 | 89 | }, |
| 90 | + { |
| 91 | + "cell_type": "code", |
| 92 | + "execution_count": null, |
| 93 | + "id": "1019369b-c328-40be-b6e1-8f275aea433e", |
| 94 | + "metadata": {}, |
| 95 | + "outputs": [], |
| 96 | + "source": [ |
| 97 | + "fig, ax = plt.subplots()\n", |
| 98 | + "ax.set_aspect(\"equal\")\n", |
| 99 | + "firedrake.triplot(mesh, axes=ax);" |
| 100 | + ] |
| 101 | + }, |
49 | 102 | { |
50 | 103 | "cell_type": "markdown", |
51 | 104 | "id": "55e5e816-7f40-435e-aa22-78051037a76b", |
|
0 commit comments