Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/fem-shapeopt/demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
"\n",
"We denote the design space as a function $g$ that maps the design variables to a signed distance field. Then, we can then define the density field $\\rho(\\mathbf{x})$ as a function of a signed distance field (SDF) value $g(\\mathbf{x})$. Finally we denote the differentiable finite element method (FEM) solver as $f$, which takes the density field as input and returns the structure's compliance. Therefore, the optimization problem can be formulated as follows:\n",
"\n",
"$$\n",
"\\begin{equation}\n",
"\\min_{\\theta} f(\\rho(g(\\theta))).\n",
"\\end{equation}\n",
"$$\n",
"\n",
"Here, $\\theta$ is the vector of design variables (the $y$-coordinates of the vertices)."
]
Expand All @@ -47,9 +49,11 @@
"\n",
"Since we want use a gradient based optimizer, we need to compute the gradient of the compliance with respect to the design variables. Hence we are interested in the following derivative:\n",
"\n",
"$$\n",
"\\begin{equation}\n",
"\\frac{\\partial f}{\\partial\\theta} = \\frac{\\partial f}{\\partial \\rho} \\cdot \\frac{\\partial \\rho}{\\partial g} \\cdot \\frac{\\partial g}{\\partial\\theta}\n",
"\\end{equation}\n",
"$$\n",
"\n",
"Note that each term is a (Jacobian) matrix. With modern AD libraries such as [JAX](https://github.com/jax-ml/jax), backpropagation uses the vector-Jacobian-product to pull back the gradients over the entire pipeline, without ever materializing Jacobian matrices. This is a powerful feature, but it typically requires that the entire pipeline is implemented in a single monolithic application – which can be cumbersome and error-prone, and does not scale well to large applications or compute needs.\n",
"\n",
Expand Down Expand Up @@ -362,9 +366,11 @@
"\n",
"Now that we have the signed distance field (SDF) from the design space, we can proceed to compute the *density field*, which is what the FEM solver expects. That is, we need to define a function $\\rho$ that maps the SDF to a density value. This function needs to be smooth and differentiable to ensure that the optimization process can effectively navigate the design space. We use a parametrized sigmoid function, which ensures that the density values are bounded between 0 and 1. Here, $s$ is the slope of the sigmoid and $\\varepsilon$ is the offset. The parameters $s$ and $\\varepsilon$ can be adjusted to control the steepness and position of the transition between 0 and 1 in the density field.\n",
"\n",
"$$\n",
"\\begin{equation}\n",
" \\rho(\\text{SDF}) = \\frac{1}{1 + e^{s \\cdot \\text{SDF} - \\varepsilon}}\n",
"\\end{equation}\n",
"$$\n",
"\n",
"Since this function is straightforward to implement, we can directly use the JAX library to define it."
]
Expand Down