|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": null, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [], |
| 8 | + "source": [ |
| 9 | + "import numpy as np\n", |
| 10 | + "import plotly.figure_factory as ff\n", |
| 11 | + "import plotly.graph_objects as go\n", |
| 12 | + "from plotly.subplots import make_subplots\n", |
| 13 | + "import meshio, numpy, copy\n", |
| 14 | + "import meshplot as mp\n", |
| 15 | + "# import sys\n", |
| 16 | + "# import pathlib\n", |
| 17 | + "# sys.path.append(str(pathlib.Path(\"\").resolve().parent / \"build\" / \"release\" / \"python\")) # noqa\n", |
| 18 | + "\n", |
| 19 | + "from ipctk import *" |
| 20 | + ] |
| 21 | + }, |
| 22 | + { |
| 23 | + "cell_type": "code", |
| 24 | + "execution_count": null, |
| 25 | + "metadata": {}, |
| 26 | + "outputs": [], |
| 27 | + "source": [ |
| 28 | + "V = np.array([[0.5,0],[1.0,0],[1.5,0],[0.9,0.3],[1,0.1],[1.1,0.3],[1,-0.5]])\n", |
| 29 | + "E = np.array([[1,0],[2,1],[3,4],[4,5],[5,3],[0,6],[6,2]], dtype=int)\n", |
| 30 | + "F = np.array([])\n", |
| 31 | + "\n", |
| 32 | + "p = mp.plot(V, F, shading={\"width\": 200, \"height\": 200})\n", |
| 33 | + "p.add_points(V, shading={\"point_color\": \"green\", \"point_size\": 0.1})\n", |
| 34 | + "p.add_lines(V[E[:,0],:],V[E[:,1],:], shading={\"line_width\": 2})\n", |
| 35 | + "\n", |
| 36 | + "dhat=0.12\n", |
| 37 | + "param = ParameterType(dhat, 1, 0, 1, 0, 1, 200)\n", |
| 38 | + "mesh = CollisionMesh(V, E, F)" |
| 39 | + ] |
| 40 | + }, |
| 41 | + { |
| 42 | + "cell_type": "code", |
| 43 | + "execution_count": null, |
| 44 | + "metadata": {}, |
| 45 | + "outputs": [], |
| 46 | + "source": [ |
| 47 | + "# high order\n", |
| 48 | + "\n", |
| 49 | + "def potential_high_order(points):\n", |
| 50 | + " cs1 = SmoothCollisions2()\n", |
| 51 | + " cs1.use_high_order_quadrature = True\n", |
| 52 | + " cs1.build(mesh, points, param)\n", |
| 53 | + "\n", |
| 54 | + " B = SmoothPotential(param)\n", |
| 55 | + " # g = B.gradient(cs1, mesh, points)\n", |
| 56 | + "\n", |
| 57 | + " return B(cs1, mesh, points)" |
| 58 | + ] |
| 59 | + }, |
| 60 | + { |
| 61 | + "cell_type": "code", |
| 62 | + "execution_count": null, |
| 63 | + "metadata": {}, |
| 64 | + "outputs": [], |
| 65 | + "source": [ |
| 66 | + "cs1 = SmoothCollisions2()\n", |
| 67 | + "cs1.use_high_order_quadrature = True\n", |
| 68 | + "cs1.build(mesh, V, param)\n", |
| 69 | + "print(cs1.to_string(mesh, V, param))\n", |
| 70 | + "print(mesh.edges)" |
| 71 | + ] |
| 72 | + }, |
| 73 | + { |
| 74 | + "cell_type": "code", |
| 75 | + "execution_count": null, |
| 76 | + "metadata": {}, |
| 77 | + "outputs": [], |
| 78 | + "source": [ |
| 79 | + "# single point\n", |
| 80 | + "\n", |
| 81 | + "def potential_single_point(points):\n", |
| 82 | + " cs2 = SmoothCollisions2()\n", |
| 83 | + " cs2.use_high_order_quadrature = False\n", |
| 84 | + " cs2.build(mesh, points, param)\n", |
| 85 | + " \n", |
| 86 | + " B = SmoothPotential(param)\n", |
| 87 | + " # g = B.gradient(cs1, mesh, points)\n", |
| 88 | + "\n", |
| 89 | + " return B(cs2, mesh, points)" |
| 90 | + ] |
| 91 | + }, |
| 92 | + { |
| 93 | + "cell_type": "code", |
| 94 | + "execution_count": null, |
| 95 | + "metadata": {}, |
| 96 | + "outputs": [], |
| 97 | + "source": [ |
| 98 | + "# IPC\n", |
| 99 | + "\n", |
| 100 | + "def potential_IPC(points):\n", |
| 101 | + " cs3 = Collisions()\n", |
| 102 | + " cs3.build(mesh, points, param.dhat)\n", |
| 103 | + "\n", |
| 104 | + " B = BarrierPotential(param.dhat)\n", |
| 105 | + " # g = B.gradient(cs3, mesh, points)\n", |
| 106 | + "\n", |
| 107 | + " return B(cs3, mesh, points)" |
| 108 | + ] |
| 109 | + }, |
| 110 | + { |
| 111 | + "cell_type": "code", |
| 112 | + "execution_count": null, |
| 113 | + "metadata": {}, |
| 114 | + "outputs": [], |
| 115 | + "source": [ |
| 116 | + "print(potential_IPC(V), potential_single_point(V), potential_high_order(V))" |
| 117 | + ] |
| 118 | + }, |
| 119 | + { |
| 120 | + "cell_type": "code", |
| 121 | + "execution_count": null, |
| 122 | + "metadata": {}, |
| 123 | + "outputs": [], |
| 124 | + "source": [ |
| 125 | + "displacements = np.linspace(-0.1, 0.1, 200)\n", |
| 126 | + "pA = []\n", |
| 127 | + "pB = []\n", |
| 128 | + "pC = []\n", |
| 129 | + "\n", |
| 130 | + "for disp in displacements:\n", |
| 131 | + " V_disp = copy.deepcopy(V)\n", |
| 132 | + " V_disp[[3,4,5], 0] += disp\n", |
| 133 | + " \n", |
| 134 | + " pA.append(potential_IPC(V_disp))\n", |
| 135 | + " pB.append(potential_single_point(V_disp))\n", |
| 136 | + " pC.append(potential_high_order(V_disp))\n" |
| 137 | + ] |
| 138 | + }, |
| 139 | + { |
| 140 | + "cell_type": "code", |
| 141 | + "execution_count": null, |
| 142 | + "metadata": {}, |
| 143 | + "outputs": [], |
| 144 | + "source": [ |
| 145 | + "fig = go.Figure(data=[\n", |
| 146 | + " go.Scatter(x=displacements, y=pA, name=\"IPC\"),\n", |
| 147 | + " go.Scatter(x=displacements, y=pB, name=\"Single Point\"),\n", |
| 148 | + " go.Scatter(x=displacements, y=pC, name=\"Exact Quadrature\"),\n", |
| 149 | + "], layout=go.Layout(width=800, height=400))\n", |
| 150 | + "\n", |
| 151 | + "# fig.update_layout(\n", |
| 152 | + "# yaxis_type=\"log\"\n", |
| 153 | + "# )\n", |
| 154 | + "\n", |
| 155 | + "fig.show()" |
| 156 | + ] |
| 157 | + }, |
| 158 | + { |
| 159 | + "cell_type": "code", |
| 160 | + "execution_count": null, |
| 161 | + "metadata": {}, |
| 162 | + "outputs": [], |
| 163 | + "source": [] |
| 164 | + } |
| 165 | + ], |
| 166 | + "metadata": { |
| 167 | + "kernelspec": { |
| 168 | + "display_name": "base", |
| 169 | + "language": "python", |
| 170 | + "name": "python3" |
| 171 | + }, |
| 172 | + "language_info": { |
| 173 | + "codemirror_mode": { |
| 174 | + "name": "ipython", |
| 175 | + "version": 3 |
| 176 | + }, |
| 177 | + "file_extension": ".py", |
| 178 | + "mimetype": "text/x-python", |
| 179 | + "name": "python", |
| 180 | + "nbconvert_exporter": "python", |
| 181 | + "pygments_lexer": "ipython3", |
| 182 | + "version": "3.11.8" |
| 183 | + } |
| 184 | + }, |
| 185 | + "nbformat": 4, |
| 186 | + "nbformat_minor": 2 |
| 187 | +} |
0 commit comments