Skip to content

Commit

Permalink
Added notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Ferguson committed Feb 21, 2023
1 parent 67c3d8c commit 1976eb1
Show file tree
Hide file tree
Showing 7 changed files with 1,033 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,5 @@ IPCToolkitOptions.cmake
src/ipc/config.hpp

docs/_doxygen

notebooks/*.[ch]pp
166 changes: 166 additions & 0 deletions notebooks/area_weights.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy\n",
"import sympy\n",
"from sympy.printing import ccode\n",
"\n",
"from generate_cpp_code import *\n",
"from utils import norm"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"funcs = []"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Edge Length"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def edge_len(e0, e1):\n",
" return norm(e1 - e0)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"x_2D = numpy.array(sympy.symbols(\" \".join([f\"e{i}_{d}\" for i in range(2) for d in \"xy\"])))\n",
"x_3D = numpy.array(sympy.symbols(\" \".join([f\"e{i}_{d}\" for i in range(2) for d in \"xyz\"])))"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"funcs.append(CXXGradientGenerator(\n",
" edge_len(*numpy.split(x_2D, 2)), x_2D, \n",
" \"edge_length_gradient_2D\", out_param_name=\"dA\"))"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"funcs.append(CXXGradientGenerator(\n",
" edge_len(*numpy.split(x_3D, 2)), x_3D, \n",
" \"edge_length_gradient_3D\", out_param_name=\"dA\"))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Triangle Area"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"def triangle_area(t0, t1, t2):\n",
" n = numpy.cross(t1 - t0, t2 - t0)\n",
" return norm(n) / 2"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"x = numpy.array(sympy.symbols(\" \".join([f\"t{i}_{d}\" for i in range(3) for d in \"xyz\"])))"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"funcs.append(CXXGradientGenerator(\n",
" triangle_area(*numpy.split(x, 3)), x,\n",
" \"triangle_area_gradient\", out_param_name=\"dA\"))"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Generate Code"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"generate_hpp_file(funcs, \"area_gradient.hpp\")\n",
"generate_cpp_file(funcs, \"area_gradient.cpp\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.1"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "5c7b89af1651d0b8571dde13640ecdccf7d5a6204171d6ab33e7c296e100e08a"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 1976eb1

Please sign in to comment.