A, w, h = 0.0008, 1., 0.01 y = np.zeros((2), float) y[0] = 0.09 y[1] = 0. f(0, y) # Time Loop for t in np.arange(0, 40, h): # Call rk4 y = rk4Algor(t, h, 2, y, f) tt.append(t) # x(t) yy.append(y[0]) vy.append(y[1]) obj = plot2d(aspect="auto") ax1 = obj.add_axs(2, 2, 1, aspect="auto") ax1.plot(tt[1000:], yy[1000:]) # 1000 avoids transients # x(t) ax1.set_title('Duffing Oscillator x(t)') ax1.set_xlabel('t') ax1.set_ylabel('x(t)') ax2 = obj.add_axs(2, 2, 4, aspect="equal") ax2.plot(yy[1000:], vy[1000:]) ax2.set_title('Phase Space Orbits, Duffing Oscillator') ax2.set_xlabel('x(t)') ax2.set_ylabel('v(t)') obj.SavePng()
if __name__ == '__main__': argvs = sys.argv parser = OptionParser() parser.add_option("--file", dest="file", default="ugridex.vtk") opt, argc = parser.parse_args(argvs) print(opt, argc) reader = meshio.read(opt.file) print(reader) xyz = reader.points tri = reader.cells["quad"] dat_scl = reader.point_data["scalars"] dat_vec = reader.point_data["vectors"] obj = plot2d() obj.new_3Dfig() obj.axs.plot(xyz[:, 0], xyz[:, 1], xyz[:, 2]) obj.SavePng_Serial() obj.axs.scatter(xyz[:, 0], xyz[:, 1], xyz[:, 2]) obj.SavePng_Serial() obj.axs.plot_trisurf(xyz[:, 0], xyz[:, 1], xyz[:, 2]) obj.SavePng_Serial() obj.new_2Dfig() obj.axs.tricontourf(xyz[:, 0], xyz[:, 1], dat_scl, cmap="jet") obj.SavePng_Serial()
for line in fp_lines: txt = "" dat = line.split() for t in dat: txt += str(t.decode("utf-8")) + "\t" qp.write(txt + "\n") data = [] for idx, line in enumerate(fp_lines[1:]): data.append([float(v) for v in line.split()]) return np.array(data) if __name__ == '__main__': argvs = sys.argv parser = OptionParser() parser.add_option("--dir", dest="dir", default="./") parser.add_option("--name", dest="name", default="dae") opt, argc = parser.parse_args(argvs) print(opt, argc) obj = plot2d(aspect="equal") cfg = json.load(open("./cfg.json", "r")) name = opt.name for dat_name in cfg[name]["dat"]: data = uiuc_database(dat_name) print(dat_name, data.shape) obj.axs.plot(data[:, 0], data[:, 1], label=dat_name) plt.legend(loc='lower right', bbox_to_anchor=(1.0, -2.0)) obj.SavePng("./uiuc_dat/{}.png".format(name))