Skip to content

Commit 1976eb1

Browse files
committed
Added notebooks
1 parent 67c3d8c commit 1976eb1

7 files changed

+1033
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -258,3 +258,5 @@ IPCToolkitOptions.cmake
258258
src/ipc/config.hpp
259259

260260
docs/_doxygen
261+
262+
notebooks/*.[ch]pp

notebooks/area_weights.ipynb

+166
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"import numpy\n",
10+
"import sympy\n",
11+
"from sympy.printing import ccode\n",
12+
"\n",
13+
"from generate_cpp_code import *\n",
14+
"from utils import norm"
15+
]
16+
},
17+
{
18+
"cell_type": "code",
19+
"execution_count": 2,
20+
"metadata": {},
21+
"outputs": [],
22+
"source": [
23+
"funcs = []"
24+
]
25+
},
26+
{
27+
"cell_type": "markdown",
28+
"metadata": {},
29+
"source": [
30+
"## Edge Length"
31+
]
32+
},
33+
{
34+
"cell_type": "code",
35+
"execution_count": 3,
36+
"metadata": {},
37+
"outputs": [],
38+
"source": [
39+
"def edge_len(e0, e1):\n",
40+
" return norm(e1 - e0)"
41+
]
42+
},
43+
{
44+
"cell_type": "code",
45+
"execution_count": 4,
46+
"metadata": {},
47+
"outputs": [],
48+
"source": [
49+
"x_2D = numpy.array(sympy.symbols(\" \".join([f\"e{i}_{d}\" for i in range(2) for d in \"xy\"])))\n",
50+
"x_3D = numpy.array(sympy.symbols(\" \".join([f\"e{i}_{d}\" for i in range(2) for d in \"xyz\"])))"
51+
]
52+
},
53+
{
54+
"cell_type": "code",
55+
"execution_count": 5,
56+
"metadata": {},
57+
"outputs": [],
58+
"source": [
59+
"funcs.append(CXXGradientGenerator(\n",
60+
" edge_len(*numpy.split(x_2D, 2)), x_2D, \n",
61+
" \"edge_length_gradient_2D\", out_param_name=\"dA\"))"
62+
]
63+
},
64+
{
65+
"cell_type": "code",
66+
"execution_count": 6,
67+
"metadata": {},
68+
"outputs": [],
69+
"source": [
70+
"funcs.append(CXXGradientGenerator(\n",
71+
" edge_len(*numpy.split(x_3D, 2)), x_3D, \n",
72+
" \"edge_length_gradient_3D\", out_param_name=\"dA\"))"
73+
]
74+
},
75+
{
76+
"cell_type": "markdown",
77+
"metadata": {},
78+
"source": [
79+
"## Triangle Area"
80+
]
81+
},
82+
{
83+
"cell_type": "code",
84+
"execution_count": 7,
85+
"metadata": {},
86+
"outputs": [],
87+
"source": [
88+
"def triangle_area(t0, t1, t2):\n",
89+
" n = numpy.cross(t1 - t0, t2 - t0)\n",
90+
" return norm(n) / 2"
91+
]
92+
},
93+
{
94+
"cell_type": "code",
95+
"execution_count": 8,
96+
"metadata": {},
97+
"outputs": [],
98+
"source": [
99+
"x = numpy.array(sympy.symbols(\" \".join([f\"t{i}_{d}\" for i in range(3) for d in \"xyz\"])))"
100+
]
101+
},
102+
{
103+
"cell_type": "code",
104+
"execution_count": 9,
105+
"metadata": {},
106+
"outputs": [],
107+
"source": [
108+
"funcs.append(CXXGradientGenerator(\n",
109+
" triangle_area(*numpy.split(x, 3)), x,\n",
110+
" \"triangle_area_gradient\", out_param_name=\"dA\"))"
111+
]
112+
},
113+
{
114+
"attachments": {},
115+
"cell_type": "markdown",
116+
"metadata": {},
117+
"source": [
118+
"# Generate Code"
119+
]
120+
},
121+
{
122+
"cell_type": "code",
123+
"execution_count": 10,
124+
"metadata": {},
125+
"outputs": [],
126+
"source": [
127+
"generate_hpp_file(funcs, \"area_gradient.hpp\")\n",
128+
"generate_cpp_file(funcs, \"area_gradient.cpp\")"
129+
]
130+
},
131+
{
132+
"cell_type": "code",
133+
"execution_count": null,
134+
"metadata": {},
135+
"outputs": [],
136+
"source": []
137+
}
138+
],
139+
"metadata": {
140+
"kernelspec": {
141+
"display_name": "Python 3",
142+
"language": "python",
143+
"name": "python3"
144+
},
145+
"language_info": {
146+
"codemirror_mode": {
147+
"name": "ipython",
148+
"version": 3
149+
},
150+
"file_extension": ".py",
151+
"mimetype": "text/x-python",
152+
"name": "python",
153+
"nbconvert_exporter": "python",
154+
"pygments_lexer": "ipython3",
155+
"version": "3.11.1"
156+
},
157+
"orig_nbformat": 4,
158+
"vscode": {
159+
"interpreter": {
160+
"hash": "5c7b89af1651d0b8571dde13640ecdccf7d5a6204171d6ab33e7c296e100e08a"
161+
}
162+
}
163+
},
164+
"nbformat": 4,
165+
"nbformat_minor": 2
166+
}

0 commit comments

Comments
 (0)