Skip to content

Instantly share code, notes, and snippets.

@nschloe
Created February 3, 2022 09:28
Show Gist options
  • Save nschloe/487dc8d806d9656b0bd0fc3c2f061420 to your computer and use it in GitHub Desktop.
Save nschloe/487dc8d806d9656b0bd0fc3c2f061420 to your computer and use it in GitHub Desktop.
Plot Ackley function layers
import numpy as np
import meshzoo
import meshio
def ackley(x):
xx = np.einsum("i...,i...->...", x, x)
sumcos = np.sum(np.cos(2 * np.pi * x), axis=0)
return (
-20.0 * np.exp(-0.2 * np.sqrt(0.5 * xx))
- np.exp(0.5 * sumcos)
+ np.exp(1)
+ 20.0
)
points, cells = meshzoo.cube_hexa(
np.linspace(-5.0, 5.0, 101),
np.linspace(-5.0, 5.0, 101),
np.linspace(-5.0, 5.0, 101),
)
vals = ackley(points.T)
meshio.Mesh(points, {"hexahedron": cells}, point_data={"ackley": vals}).write("out.vtk")
@nschloe
Copy link
Author

nschloe commented Feb 3, 2022

3d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment