From c0c098ba582b6b2ad432039041496c0ff92b52d3 Mon Sep 17 00:00:00 2001 From: Daniel Shapero Date: Thu, 2 Jan 2025 11:15:25 -0800 Subject: [PATCH] Convert to simplicial at the end of demo --- demo/simplification.ipynb | 63 ++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 10 deletions(-) diff --git a/demo/simplification.ipynb b/demo/simplification.ipynb index 78b8aac..b4d40ad 100644 --- a/demo/simplification.ipynb +++ b/demo/simplification.ipynb @@ -238,11 +238,12 @@ "id": "b3c894c1-0895-404b-8e8a-172429882dea", "metadata": {}, "source": [ - "The cell below shows the resulting matrix, which we'll call $e_1$.\n", - "(I'm showing the transpose so that we don't have to spill lines.)\n", - "You might notice that, for example, rows 0 and 1 are identical.\n", - "Any two rows that are scalar multiples of each other can be merged.\n", - "The adjacency of higher-dimensional cells can then be coalesced into adjacency to the merged cell." + "The code below shows the resulting matrix, which we'll call $e_1$.\n", + "You might notice that, for example, columns 0 and 1 are identical.\n", + "(So are columns 4 and 6 and columns 3 and 13.)\n", + "From a geometric viewpoint, this means that we have two edges that start at the same vertex and end at the same vertex.\n", + "This is undesirable.\n", + "The new 2-cells are the same as the old for now." ] }, { @@ -252,8 +253,10 @@ "metadata": {}, "outputs": [], "source": [ + "e_0 = d_0\n", "e_1 = P @ d_1\n", - "e_1.T" + "e_2 = d_2\n", + "print(e_1)" ] }, { @@ -261,7 +264,13 @@ "id": "2ca5ef8d-739d-4440-a4ea-17db3ff03725", "metadata": {}, "source": [ - "The function below creates the matrices that we will multiply by $e_1$ and $d_2$ in order to merge these cells." + "We might also have columns that are not exact duplicates by scalar multiples of each other.\n", + "For example, an edge that goes from vertex 0 to vertex 1, and another edge that goes from vertex 1 to vertex 0.\n", + "We can clean things up by:\n", + "1. replacing all 1-cells that are multiples of each other with a single representative\n", + "2. for any 2-cell that was incident upon any of the degenerate 1-cells, replace it with a 2-cell that is incident upon the new representative 1-cell.\n", + "\n", + "The function below creates the matrices that we will multiply by $e_1$ and $e_2$ in order to merge these cells." ] }, { @@ -325,7 +334,8 @@ "metadata": {}, "outputs": [], "source": [ - "print(e_1 @ A)" + "f_1 = e_1 @ A\n", + "print(f_1)" ] }, { @@ -333,7 +343,7 @@ "id": "1e546417-668c-4420-836b-7d3a640de149", "metadata": {}, "source": [ - "And the columns of $B\\cdot d_2$ have their adjacencies to redundant columns summed together." + "And the columns of $B\\cdot e_2$ have their adjacencies to redundant columns summed together." ] }, { @@ -343,7 +353,19 @@ "metadata": {}, "outputs": [], "source": [ - "print(B @ d_2)" + "print(B @ e_2)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6a6f55e7-411d-4c84-9a16-a09a75d6de15", + "metadata": {}, + "outputs": [], + "source": [ + "empty_cell_ids = np.flatnonzero(np.count_nonzero(B @ e_2, axis=0) < 3)\n", + "f_2 = np.delete(B @ e_2, empty_cell_ids, axis=1)\n", + "print(f_2)" ] }, { @@ -353,6 +375,27 @@ "source": [ "You'll also note that some 2-cells are now empty, which we expect." ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cc4032ba-f62b-4c53-b6cb-0ba439ebd4cb", + "metadata": {}, + "outputs": [], + "source": [ + "ltriangles = zmsh.polytopal.to_simplicial([e_0, f_1, f_2])\n", + "print(ltriangles)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2a875059-817e-422b-ac3c-451c9caa151d", + "metadata": {}, + "outputs": [], + "source": [ + "vertex_ids[ltriangles]" + ] } ], "metadata": {