Skip to content

Commit

Permalink
Convert to simplicial at the end of demo
Browse files Browse the repository at this point in the history
  • Loading branch information
danshapero committed Jan 2, 2025
1 parent d334aa8 commit c0c098b
Showing 1 changed file with 53 additions and 10 deletions.
63 changes: 53 additions & 10 deletions demo/simplification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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."
]
},
{
Expand All @@ -252,16 +253,24 @@
"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)"
]
},
{
"cell_type": "markdown",
"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."
]
},
{
Expand Down Expand Up @@ -325,15 +334,16 @@
"metadata": {},
"outputs": [],
"source": [
"print(e_1 @ A)"
"f_1 = e_1 @ A\n",
"print(f_1)"
]
},
{
"cell_type": "markdown",
"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."
]
},
{
Expand All @@ -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)"
]
},
{
Expand All @@ -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": {
Expand Down

0 comments on commit c0c098b

Please sign in to comment.