def implicitSolver(i): time_step = i * dt solv = Solver(matrix, 'gmres') solv.solve() solv.evaluate(kernel) u = solv.getSol() Z = solv.interpolate(kernel) matrix.update(u, dt) #matrix.setDirichletRegular(T1,1) matrix.setDirichletRegular(T2, 2) matrix.setDirichletRegular(T4, 4) plt.contourf(X, Y, Z, 10, cmap=plt.cm.bone, origin='lower') if i >= Tsteps: C = plt.contour(X, Y, Z, 10, colors='black') plt.clabel(C, inline=1, fontsize=7.5) plt.savefig('TempSolution.png') label.set_text('Step = {:>8d} \n Time = {:>8.5f}'.format(i, time_step)) print(i, '\n')
def main(): # ---------------------------------------------------------------------------------------- # Attributes of Mesh # the value dp is result of equation w(dp) * h(dp) = num_nodes # you have to change this value manually in order to have the same number of node # ---------------------------------------------------------------------------------------- width = 2 height = 4 num_nodes = 200 dp = 5 radius = 1.0 D = 1 T1 = 100 # ---------------------------------------------------------------------------------------- # Create Domain Regular # ---------------------------------------------------------------------------------------- d1 = dm.Domain(width, height) d1.createSquare(dp=dp) xd1 = d1.nodes_x() yd1 = d1.nodes_y() dst = dt.Distribution(domain=d1, dp=dp) # ---------------------------------------------------------------------------------------- # show boundary of Domain # ---------------------------------------------------------------------------------------- fig, ax = plt.subplots(nrows=1, ncols=1) plt.plot(d1.nodes_x()[0][0], d1.nodes_y()[0][0]) plt.plot(d1.nodes_x()[1][0], d1.nodes_y()[1][0]) plt.plot(d1.nodes_x()[2][0], d1.nodes_y()[2][0]) plt.plot(d1.nodes_x()[3][0], d1.nodes_y()[3][0]) # ---------------------------------------------------------------------------------------- # Make the knots of Domain: ngd (gaussian distribution) or rdp (regular) # ---------------------------------------------------------------------------------------- dst.calcDist(shape='ngd', nodes=num_nodes, width=width, height=height, bx=d1.nodes_x(), by=d1.nodes_y(), dp=dp) #dst.calcDist(shape='rdp', width=width, height=height, bx=xd1, by=yd1, dp=dp, nodes=num_nodes) # ---------------------------------------------------------------------------------------- # Kernel selection # ---------------------------------------------------------------------------------------- kernel = Multiquadric2D(1 / np.sqrt(dst.nodes())) # ---------------------------------------------------------------------------------------- # Gramm matrix allocation # ---------------------------------------------------------------------------------------- matrix = GrammMatrix(dst) matrix.fillMatrixLaplace2D(kernel, D) # ---------------------------------------------------------------------------------------- # Dirichlet boundary condition # ---------------------------------------------------------------------------------------- matrix.setDirichletRegular(T1, 3) # print(dst.NI(), dst.NB(), test[dst.NI():], len(test[dst.NI():]), len(test[0:dst.NI()])) # ---------------------------------------------------------------------------------------- # Gram matrix solution # ---------------------------------------------------------------------------------------- solv = Solver(matrix, 'linalg') solv.solve() solv.evaluate(kernel) # ---------------------------------------------------------------------------------------- # Solution storage(optional) # ---------------------------------------------------------------------------------------- zx = solv.interpolate(kernel) u = solv.getSol() lam = solv.lam() # ---------------------------------------------------------------------------------------- # Solution and point cloud plotting # ---------------------------------------------------------------------------------------- title = 'Heat difussion in two dimensional domain' xlabel = 'Lx [m]' ylabel = 'Ly [m]' barlabel = 'Temparature °C' plot = plotter(solv, kernel) # plot.regularMesh2D (title='Spatial created grid', xlabel=xlabel, ylabel=ylabel) plot.surface3D(title=title, xlabel=xlabel, ylabel=ylabel, barlabel=barlabel) plot.levelplot(title=title, xlabel=xlabel, ylabel=ylabel, barlabel=barlabel) plt.spy(matrix.getMatrix(), markersize=1.0) plt.show() # ---------------------------------------------------------------------------------------- # Select the search method and time of execution # ---------------------------------------------------------------------------------------- nn = nb.Neighbor(method='bf', x=dst.a(), y=dst.b(), r=radius) neighborhood = nn.nearest_neighbors() nn = nb.Neighbor(method='bt', x=dst.a(), y=dst.b(), r=radius) neighborhood = nn.nearest_neighbors() nn = nb.Neighbor(method='ball', x=dst.a(), y=dst.b(), r=radius) neighborhood = nn.nearest_neighbors() #print (neighborhood) #print (nn.location()) start_time = time.time() painter(neighborhood) print("Painter Time in NN method:") print("--- %s seconds ---" % (time.time() - start_time)) print("Data Domain") print('_' * 20) print("number points: ", len(dst.a())) plt.scatter(dst.a(), dst.b()) plt.grid() plt.axis([-2, width + 2, -1, height + 1]) warnings.filterwarnings("ignore") #ax.set_axis_bgcolor("lightslategray") plt.show() # ---------------------------------------------------------------------------------------- # Gramm matrix allocation with NN # ---------------------------------------------------------------------------------------- matrixNN = GrammMatrix(dst) matrixNN.fillMatrixLapace2D_CSupported(kernel, D, nn.location()) # ---------------------------------------------------------------------------------------- # Dirichlet boundary condition # ---------------------------------------------------------------------------------------- matrixNN.setDirichletRegular(T1, 3) # print(dst.NI(), dst.NB(), test[dst.NI():], len(test[dst.NI():]), len(test[0:dst.NI()])) # ---------------------------------------------------------------------------------------- # Gram matrix solution with NN # ---------------------------------------------------------------------------------------- solvnn = Solver(matrixNN, 'linalg') solvnn.solve() solvnn.evaluate(kernel) # ---------------------------------------------------------------------------------------- # Solution storage(optional) # ---------------------------------------------------------------------------------------- zx = solvnn.interpolate(kernel) u = solvnn.getSol() lam = solvnn.lam() # ---------------------------------------------------------------------------------------- # Solution and point cloud plotting # ---------------------------------------------------------------------------------------- title = 'Heat difussion in two dimensional domain' xlabel = 'Lx [m]' ylabel = 'Ly [m]' barlabel = 'Temparature °C' plot = plotter(solvnn, kernel) # plot.regularMesh2D (title='Spatial created grid', xlabel=xlabel, ylabel=ylabel) plot.surface3D(title=title, xlabel=xlabel, ylabel=ylabel, barlabel=barlabel) plot.levelplot(title=title, xlabel=xlabel, ylabel=ylabel, barlabel=barlabel) plt.spy(matrixNN.getMatrix(), markersize=1.0) plt.show() print(matrixNN.N(), matrixNN.NI())
matrix = GrammMatrix(mesh) matrix.fillMatrixLaplace2D(kernel, D) #---------------------------------------------------------------------------------------- #Dirichlet boundary condition #---------------------------------------------------------------------------------------- matrix.setNeummanRegular(kernel, 0, 2) matrix.setNeummanRegular(kernel, 0, 4) matrix.setDirichletRegular(T1, 1) #---------------------------------------------------------------------------------------- #Gram matrix solution #---------------------------------------------------------------------------------------- solv = Solver(matrix, 'gmres') solv.solve() solv.evaluate(kernel) #---------------------------------------------------------------------------------------- #Solution storage(optional) #---------------------------------------------------------------------------------------- zx = solv.interpolate(kernel) u = solv.getSol() lam = solv.lam() #---------------------------------------------------------------------------------------- #Solution and point cloud plotting #---------------------------------------------------------------------------------------- title = 'Heat difussion in two dimensional domain'
matrix = GrammMatrix(mesh) matrix.fillMatrixAdvDiffTime2D(kernel, Dx, Dy, Ux, Uy, rho) #---------------------------------------------------------------------------------------- #Dirichlet boundary condition #---------------------------------------------------------------------------------------- #matrix.setDirichletRegular(T1,1) matrix.setDirichletRegular(T2, 2) matrix.setDirichletRegular(T4, 4) #---------------------------------------------------------------------------------------- #Gram matrix initial solution #---------------------------------------------------------------------------------------- solv = Solver(matrix, 'bicgstab') solv.solve() #---------------------------------------------------------------------------------------- #Plot and animation initializtion #---------------------------------------------------------------------------------------- title = 'Transient State Advection-Diffusion Heat Transfer with RBF' xlabel = 'Lx [m]' ylabel = 'Ly [m]' barlabel = 'Temparature °C' plot = Plotter(solv, kernel) x = np.linspace(0, mesh.Lx(), mesh.Nx()) y = np.linspace(0, mesh.Ly(), mesh.Ny()) X, Y = np.meshgrid(x, y) Z = solv.interpolate(kernel)
#atrix content print #---------------------------------------------------------------------------------------- plt.figure(figsize=(10,10)) plt.matshow(matrix.getMatrix(), cmap=plt.cm.bone, fignum=1) plt.show() #---------------------------------------------------------------------------------------- #Gram matrix solution #---------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------- #Gram matrix solution Linalg #---------------------------------------------------------------------------------------- solvl = Solver(matrix,'linalg') solvl.solve() laml = solvl.lam() solvl.evaluate(kernel) #---------------------------------------------------------------------------------------- #Gram matrix solution Jacobi #---------------------------------------------------------------------------------------- solvj = Solver(matrix,'jacobi',test=True) solvj.solve() lamj = solvj.lam() errj = solvj.err() kj = solvj.k() errvj = solvj.errv() solvj.evaluate(kernel)