Skip to content

Commit 77d9946

Browse files
committed
removed refinable mesh
1 parent b1c41ef commit 77d9946

27 files changed

Lines changed: 7642 additions & 346 deletions

examples/Discrete_Laplacian.ipynb

Lines changed: 1210 additions & 0 deletions
Large diffs are not rendered by default.

examples/faces.ipynb

Lines changed: 340 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,340 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "219aa85c-7c68-456b-998e-7f33597df555",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"import numpy as np"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": 2,
16+
"id": "d588a3a1-7cc2-498f-839f-4adb924b9e2e",
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"n = 500000\n",
21+
"k = 5"
22+
]
23+
},
24+
{
25+
"cell_type": "code",
26+
"execution_count": 3,
27+
"id": "26da88a6-4316-4c68-bd91-044e7cdfbc36",
28+
"metadata": {},
29+
"outputs": [],
30+
"source": [
31+
"faces = np.random.randint(0,n,(n,k))"
32+
]
33+
},
34+
{
35+
"cell_type": "code",
36+
"execution_count": 4,
37+
"id": "e36b486d-c793-45c6-b91a-f8d0c1028b89",
38+
"metadata": {},
39+
"outputs": [
40+
{
41+
"data": {
42+
"text/plain": [
43+
"(500000, 5)"
44+
]
45+
},
46+
"execution_count": 4,
47+
"metadata": {},
48+
"output_type": "execute_result"
49+
}
50+
],
51+
"source": [
52+
"faces.shape"
53+
]
54+
},
55+
{
56+
"cell_type": "code",
57+
"execution_count": 5,
58+
"id": "b7bb21ef-d4b8-4063-90bd-4f3d8c9d6a71",
59+
"metadata": {},
60+
"outputs": [],
61+
"source": [
62+
"num_edges_per_face = k "
63+
]
64+
},
65+
{
66+
"cell_type": "code",
67+
"execution_count": 8,
68+
"id": "1da88955-e4c2-4bb5-8955-d2eb605c0676",
69+
"metadata": {},
70+
"outputs": [],
71+
"source": [
72+
"%load_ext memory_profiler"
73+
]
74+
},
75+
{
76+
"cell_type": "code",
77+
"execution_count": 19,
78+
"id": "3b62d7fd-9893-4cf9-a487-3ed05b67c156",
79+
"metadata": {},
80+
"outputs": [
81+
{
82+
"name": "stdout",
83+
"output_type": "stream",
84+
"text": [
85+
"peak memory: 148.63 MiB, increment: 0.00 MiB\n"
86+
]
87+
}
88+
],
89+
"source": [
90+
"%%memit\n",
91+
"indices = np.stack(\n",
92+
" [np.arange(num_edges_per_face), (np.arange(num_edges_per_face) + 1) % num_edges_per_face], \n",
93+
" axis=1\n",
94+
")\n",
95+
"\n",
96+
"# Use advanced indexing to select face pairs\n",
97+
"es = faces[:, indices].reshape(-1, 2)"
98+
]
99+
},
100+
{
101+
"cell_type": "code",
102+
"execution_count": 22,
103+
"id": "78255cc0-20c1-4f55-99a2-f2b144f098da",
104+
"metadata": {},
105+
"outputs": [
106+
{
107+
"name": "stdout",
108+
"output_type": "stream",
109+
"text": [
110+
"peak memory: 148.58 MiB, increment: 0.00 MiB\n"
111+
]
112+
}
113+
],
114+
"source": [
115+
"%%memit\n",
116+
"es = np.concatenate( [\n",
117+
" faces[:, [i, (i + 1) % num_edges_per_face]]\n",
118+
" for i in range(num_edges_per_face)\n",
119+
" ],\n",
120+
" axis=0,\n",
121+
" )\n"
122+
]
123+
},
124+
{
125+
"cell_type": "code",
126+
"execution_count": 23,
127+
"id": "13a599b9-ded1-4660-8a8d-6a98569382f0",
128+
"metadata": {},
129+
"outputs": [],
130+
"source": [
131+
"target_vertices = np.arange(n)"
132+
]
133+
},
134+
{
135+
"cell_type": "code",
136+
"execution_count": 26,
137+
"id": "e91e6804-b698-4ef0-888c-7c588c3fc32e",
138+
"metadata": {},
139+
"outputs": [
140+
{
141+
"name": "stdout",
142+
"output_type": "stream",
143+
"text": [
144+
"1.13 ms ± 23.9 μs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)\n"
145+
]
146+
}
147+
],
148+
"source": [
149+
"%%timeit\n",
150+
"a = np.tile(target_vertices[:,None], [1,3])"
151+
]
152+
},
153+
{
154+
"cell_type": "code",
155+
"execution_count": 25,
156+
"id": "21a85517-0762-43c2-a86f-2ae25eb3aa9f",
157+
"metadata": {},
158+
"outputs": [
159+
{
160+
"name": "stdout",
161+
"output_type": "stream",
162+
"text": [
163+
"1.25 ms ± 103 μs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)\n"
164+
]
165+
}
166+
],
167+
"source": [
168+
"%%timeit\n",
169+
"repeated_arr = np.repeat(target_vertices[:, np.newaxis], 3, axis=1)"
170+
]
171+
},
172+
{
173+
"cell_type": "code",
174+
"execution_count": 27,
175+
"id": "263446a5-a9ac-48fc-9b87-d361befc6a12",
176+
"metadata": {},
177+
"outputs": [
178+
{
179+
"name": "stdout",
180+
"output_type": "stream",
181+
"text": [
182+
"3.12 ms ± 170 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
183+
]
184+
}
185+
],
186+
"source": [
187+
"%%timeit\n",
188+
"repeated_arr = np.stack([target_vertices]*3,axis=1)"
189+
]
190+
},
191+
{
192+
"cell_type": "code",
193+
"execution_count": 28,
194+
"id": "a55153ae-0754-4b98-b5c6-38659cd7879e",
195+
"metadata": {},
196+
"outputs": [
197+
{
198+
"data": {
199+
"text/plain": [
200+
"(500000, 3)"
201+
]
202+
},
203+
"execution_count": 28,
204+
"metadata": {},
205+
"output_type": "execute_result"
206+
}
207+
],
208+
"source": [
209+
"repeated_arr = np.stack([target_vertices]*3,axis=1)\n",
210+
"repeated_arr.shape"
211+
]
212+
},
213+
{
214+
"cell_type": "code",
215+
"execution_count": 34,
216+
"id": "54f1f7c4-e9ee-468d-a226-9f419d6b527d",
217+
"metadata": {},
218+
"outputs": [],
219+
"source": [
220+
"nearest_triangles = np.random.randint(0,n, (3,3))\n",
221+
"\n",
222+
"target_nodes = np.tile(np.arange(3)[:, None], (1, 3))\n",
223+
"res = np.stack(\n",
224+
" [nearest_triangles[..., None], target_nodes[..., None]], axis=-1\n",
225+
" ).reshape(-1, 2)\n"
226+
]
227+
},
228+
{
229+
"cell_type": "code",
230+
"execution_count": 35,
231+
"id": "1f1023ad-6dbe-416a-9096-c98b16977cc8",
232+
"metadata": {},
233+
"outputs": [
234+
{
235+
"data": {
236+
"text/plain": [
237+
"array([[310133, 67769, 2770],\n",
238+
" [ 48884, 167275, 180288],\n",
239+
" [433041, 57137, 122329]])"
240+
]
241+
},
242+
"execution_count": 35,
243+
"metadata": {},
244+
"output_type": "execute_result"
245+
}
246+
],
247+
"source": [
248+
"nearest_triangles"
249+
]
250+
},
251+
{
252+
"cell_type": "code",
253+
"execution_count": 36,
254+
"id": "50942dc6-8038-43de-a5d1-289a32573ddd",
255+
"metadata": {},
256+
"outputs": [
257+
{
258+
"data": {
259+
"text/plain": [
260+
"array([[0, 0, 0],\n",
261+
" [1, 1, 1],\n",
262+
" [2, 2, 2]])"
263+
]
264+
},
265+
"execution_count": 36,
266+
"metadata": {},
267+
"output_type": "execute_result"
268+
}
269+
],
270+
"source": [
271+
"target_nodes"
272+
]
273+
},
274+
{
275+
"cell_type": "code",
276+
"execution_count": 37,
277+
"id": "042a3169-631c-4eb2-9084-547c02ed68a3",
278+
"metadata": {},
279+
"outputs": [
280+
{
281+
"data": {
282+
"text/plain": [
283+
"array([[310133, 0],\n",
284+
" [ 67769, 0],\n",
285+
" [ 2770, 0],\n",
286+
" [ 48884, 1],\n",
287+
" [167275, 1],\n",
288+
" [180288, 1],\n",
289+
" [433041, 2],\n",
290+
" [ 57137, 2],\n",
291+
" [122329, 2]])"
292+
]
293+
},
294+
"execution_count": 37,
295+
"metadata": {},
296+
"output_type": "execute_result"
297+
}
298+
],
299+
"source": [
300+
"res"
301+
]
302+
},
303+
{
304+
"cell_type": "code",
305+
"execution_count": null,
306+
"id": "a248e01d-73d3-45a3-9d43-d7b8a16762f8",
307+
"metadata": {},
308+
"outputs": [],
309+
"source": []
310+
}
311+
],
312+
"metadata": {
313+
"kernelspec": {
314+
"display_name": "Python 3 (ipykernel)",
315+
"language": "python",
316+
"name": "python3"
317+
},
318+
"language_info": {
319+
"codemirror_mode": {
320+
"name": "ipython",
321+
"version": 3
322+
},
323+
"file_extension": ".py",
324+
"mimetype": "text/x-python",
325+
"name": "python",
326+
"nbconvert_exporter": "python",
327+
"pygments_lexer": "ipython3",
328+
"version": "3.12.8"
329+
},
330+
"widgets": {
331+
"application/vnd.jupyter.widget-state+json": {
332+
"state": {},
333+
"version_major": 2,
334+
"version_minor": 0
335+
}
336+
}
337+
},
338+
"nbformat": 4,
339+
"nbformat_minor": 5
340+
}

examples/icosphere_transfer.ipynb

Lines changed: 198 additions & 70 deletions
Large diffs are not rendered by default.

examples/length_distribution.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from sphedron import Icosphere
2+
from sphedron.helpers import compute_edges_angles
3+
import matplotlib.pyplot as plt
4+
import numpy as np
5+
6+
7+
mesh = Icosphere(refine_factor=16, refine_by_angle=False)
8+
distances = compute_edges_angles(mesh.nodes, mesh.edges)
9+
print("mean:", np.mean(distances))
10+
print("std:", np.std(distances))
11+
print("max:", np.max(distances))
12+
print("min:", np.min(distances))
13+
# print(plt.hist(distances, bins=40))
14+
plt.show()

examples/mesh_transfer.ipynb

Lines changed: 308 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)