def pltResult(model, device, nSample, params): rList = np.linspace(0, params["radius"], nSample) thetaList = np.linspace(0, math.pi * 2, nSample) xx = np.zeros([nSample, nSample]) yy = np.zeros([nSample, nSample]) zz = np.zeros([nSample, nSample]) for i in range(nSample): for j in range(nSample): xx[i, j] = rList[i] * math.cos(thetaList[j]) yy[i, j] = rList[i] * math.sin(thetaList[j]) coord = np.array([xx[i, j], yy[i, j]]) zz[i, j] = model(torch.from_numpy(coord).float().to(device)).item() # zz[i,j] = params["radius"]**2-xx[i,j]**2-yy[i,j]**2 # Plot the exact solution. file = open("nSample.txt", "w") file.write(str(nSample)) file = open("Data.txt", "w") writeSolution.write(xx, yy, zz, nSample, file) edgeList = [[ params["radius"] * math.cos(i), params["radius"] * math.sin(i) ] for i in thetaList] writeSolution.writeBoundary(edgeList)
def pltResult(model, device, nSample, params): xList = np.linspace(-1, 1, nSample) yList = np.linspace(-1, 1, nSample) thetaList = np.linspace(0, 2 * math.pi, 50) xx = np.zeros([nSample, nSample]) yy = np.zeros([nSample, nSample]) zz = np.zeros([nSample, nSample]) for i in range(nSample): for j in range(nSample): xx[i, j] = xList[i] yy[i, j] = yList[j] coord = np.array([xx[i, j], yy[i, j]]) zz[i, j] = model(torch.from_numpy(coord).float().to(device)).item() # zz[i,j] = xx[i,j]*yy[i,j] # Plot the exact solution. if np.linalg.norm(coord - np.array([0.3, 0.0])) < 0.3: zz[i, j] = "NaN" file = open("nSample.txt", "w") file.write(str(nSample)) file = open("Data.txt", "w") writeSolution.write(xx, yy, zz, nSample, file) edgeList2 = [[0.3 * math.cos(i) + 0.3, 0.3 * math.sin(i)] for i in thetaList] edgeList1 = [[-1.0, -1.0], [1.0, -1.0], [1.0, 1.0], [-1.0, 1.0], [-1.0, -1.0]] writeSolution.writeBoundary(edgeList1, edgeList2)