Created
February 3, 2022 09:28
-
-
Save nschloe/487dc8d806d9656b0bd0fc3c2f061420 to your computer and use it in GitHub Desktop.
Plot Ackley function layers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
Author
nschloe
commented
Feb 3, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment