examples.levelSet.distanceFunction.squareΒΆ
Here we solve the level set equation in two dimensions for a square. The equation is given by:
\[\begin{split}\abs{\nabla \phi} &= 1 \\
\phi &= 0 \qquad \text{at} \qquad \begin{cases}
x = \left( L / 3, 2 L / 3 \right)
& \text{for $L / 3 \le y \le 2 L / 3$} \\
y = \left( L / 3, 2 L / 3 \right)
& \text{for $L / 3 \le x \le 2 L / 3$}
\end{cases}\end{split}\]
Do the tests:
>>> var.calcDistanceFunction(order=1)
>>> def evalCell(phix, phiy, dx, dy):
... aa = dy**2 + dx**2
... bb = -2 * ( phix * dy**2 + phiy * dx**2)
... cc = dy**2 * phix**2 + dx**2 * phiy**2 - dx**2 * dy**2
... sqr = numerix.sqrt(bb**2 - 4. * aa * cc)
... return ((-bb - sqr) / 2. / aa, (-bb + sqr) / 2. / aa)
>>> val = evalCell(-dy / 2., -dx / 2., dx, dy)[0]
>>> v1 = evalCell(val, -3. * dx / 2., dx, dy)[0]
>>> v2 = evalCell(-3. * dy / 2., val, dx, dy)[0]
>>> v3 = evalCell(v2, v1, dx, dy)[0]
>>> v4 = dx * dy / numerix.sqrt(dx**2 + dy**2) / 2
>>> arr = numerix.array((
... v3, v2, -3. * dy / 2., v2, v3,
... v1, val, -dy / 2., val, v1,
... -3. * dx / 2., -dx / 2., v4, -dx / 2., -3. * dx / 2.,
... v1, val, -dy / 2., val, v1,
... v3, v2, -3. * dy / 2., v2, v3 ))
>>> print(var.allclose(arr))
1
Last updated on Feb 14, 2025.
Created using Sphinx 7.1.2.