Skip to content

Commit

Permalink
update samples
Browse files Browse the repository at this point in the history
  • Loading branch information
aoymt committed Jul 20, 2024
1 parent 83387fd commit 7700d45
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
9 changes: 6 additions & 3 deletions sample/analytical/minsearch/do.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/sh

python3 ../../../src/py2dmat_main.py input.toml
rm -rf output

python3 ../plot_himmel.py --xcol=1 --ycol=2 --output=output/res.pdf output/SimplexData.txt
# python3 ../plot_himmel.py --xcol=1 --ycol=2 --output=output/res.png output/SimplexData.txt
time python3 ../../../src/py2dmat_main.py input.toml
# time mpirun -np 16 python3 ../../../src/py2dmat_main.py input.toml

# python3 plot.py --xcol=1 --ycol=2 --output=output/res.png output/*/SimplexData.txt
python3 plot.py --xcol=1 --ycol=2 --output=output/res.pdf output/*/SimplexData.txt
38 changes: 38 additions & 0 deletions sample/analytical/minsearch/plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import numpy as np
import matplotlib.pyplot as plt
import argparse

plot_style = { "linewidth": 2.0, "markersize": 4.0 }

def himmelblau(x, y):
return (x ** 2 + y - 11) ** 2 + (x + y ** 2 - 7) ** 2

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--xcol", type=int, default=0)
parser.add_argument("--ycol", type=int, default=1)
parser.add_argument("--output", default="res.pdf")
parser.add_argument("--format", default="-o")
parser.add_argument("--skip", type=int, default=0)
parser.add_argument("inputfiles", nargs="+")
args = parser.parse_args()

npts = 201
c_x, c_y = np.mgrid[-6 : 6 : npts * 1j, -6 : 6 : npts * 1j]
c_z = himmelblau(c_x, c_y)
levels = np.logspace(0.35, 3.2, 8)

fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.set_aspect("equal", adjustable="box")
ax.contour(c_x, c_y, c_z, levels, colors="k")

cmap = plt.get_cmap("tab10")
for idx,filename in enumerate(args.inputfiles):
data = np.loadtxt(filename, unpack=True, skiprows=args.skip)
ax.plot(data[args.xcol], data[args.ycol], args.format, color=cmap(idx%10), **plot_style)

ax.set_xticks(np.linspace(-6, 6, num=5, endpoint=True))
ax.set_yticks(np.linspace(-6, 6, num=5, endpoint=True))

fig.savefig(args.output)

0 comments on commit 7700d45

Please sign in to comment.