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())
solvgmr.solve() lamgmr = solvgmr.lam() errgmr = solvgmr.err() kgmr = solvgmr.k() errvgmr = solvgmr.errv() solvgmr.evaluate(kernel) #---------------------------------------------------------------------------------------- #Solution and point cloud plotting #---------------------------------------------------------------------------------------- print('Steady State Adv.-Diff. Heat Transfer with RBF') xlabel = 'Lx [m]' ylabel = 'Ly [m]' barlabel = 'Temparature °C' plotl = plotter(solvl,kernel) plotl.levelplot(title = 'linalg.solve()', xlabel = xlabel, ylabel = ylabel, barlabel = barlabel,fileName = 'StationaryL_l.png') #plotj = plotter(solvj,kernel) #plotj.levelplot(title = 'Jacobi - error : %g, iteraciones : %d' % (errj, kj), xlabel = xlabel, ylabel = ylabel, barlabel = barlabel,fileName = 'StationaryL_j.png') #plotgs = plotter(solvgs,kernel) #plotgs.levelplot(title = title+'Gauss-Seidel - error : %g, iteraciones : %d' % (errgs, kgs), xlabel = xlabel, ylabel = ylabel, barlabel = barlabel,fileName = 'StationaryL_gs.png') #plotsor = plotter(solvsor,kernel) #plotsor.levelplot(title = title+'SOR - error : %g, iteraciones : %d' % (errsor, ksol), xlabel = xlabel, ylabel = ylabel, barlabel = barlabel,fileName = 'StationaryL_sor.png') plotgcm = plotter(solvgcm,kernel) plotgcm.levelplot(title = 'CGM - error : %g, iteraciones : %d' % (errgcm, kgcm), xlabel = xlabel, ylabel = ylabel, barlabel = barlabel,fileName = 'StationaryL_gcm.png') plotbi = plotter(solvbi,kernel) plotbi.levelplot(title = 'BICGSTAB - error : %g, iteraciones : %d' % (errbi, kbi), xlabel = xlabel, ylabel = ylabel, barlabel = barlabel,fileName = 'StationaryL_bi.png') plotgmr = plotter(solvgmr,kernel) plotgmr.levelplot(title = 'GMRES - error : %g, iteraciones : %d' % (errgmr, kgmr), xlabel = xlabel, ylabel = ylabel, barlabel = barlabel,fileName = 'StationaryL_gmr.png')
} pend_configuration = {} for i in range(num_plant): pend_configuration['pend_%s' % (i)] = {'id': i} # pendulum_manager = pendulum_manager(configuration, pend_configuration) mps = list() manager = multiprocessing.Manager() shared_dict, shared_lists = init_plot_dict(num_plant, manager) mprun_break = manager.Value(ctypes.c_bool, False) mp1 = pendulum_manager(mprun_break, configuration, pend_configuration, shared_dict, shared_lists) mp1.daemon = True mp2 = plotter(mprun_break, configuration, shared_dict, shared_lists) mp2.daemon = True mps.append(mp1) mps.append(mp2) print(" befor start ") for mp in mps: mp.start() time.sleep(testing_interval) mprun_break.value = True print("before join") for mp in mps: mp.join()
data_collector.save_data_set(format='%d') trainer = preprocessor(data_collector.data, seq_length = 5) trainer.scale() trainer.preprocess() print( trainer.data.shape ) print( trainer.label.shape ) print( trainer.index.shape ) Network = LSTM_Network(trainer) with Network.graph.as_default(): Network.construct_placeholders() Network.train_network(trainer.data, trainer.label, 2) Network.restore_network('model/temp') prediction = Network.infer() p = plotter(np.asarray(prediction), trainer.label, trainer.index, 6) p.plot_comparison() Network.close() data_collector.open_port() data_collector.clear_data() for i in range(10): data_collector.recieve_data() print(data_collector.data) trainer = preprocessor(data_collector.data, seq_length = 5) trainer.scale() trainer.preprocess() tf.reset_default_graph() Network = LSTM_Network(trainer) Network.restore_network('model/temp')
def generate(): ## Get the values of all variables ## cvar = constvar.get() # Which variable is the constant one? sams = int(samples.get()) # Number of samples avg = float(var.get()) # Average value of sampled variable eps = eRange.get() # Range of sampled variable para = float(const.get()) # Value of constant variable its = int(iterations.get()) # Number of iterations star = int(start.get()) # First iteration to display to user styp = sampleType.get() # Type of sampling method ## Set the view variables according to the check boxes make their default ## values an empty string. c,s,b = "","","" if c_check.get() == '1': c = "c" # Indicates if cylinder view is checked. if s_check.get() == '1': s = "s" # Indicates if spherical view is checked. if b_check.get() == '1': b = "b" # Indicates if stadia view is checked. # get the eps value ready to pass to the plotter if eps == "pi/4": epsi = pi/4 elif eps == "pi/16": epsi = pi/16 elif eps == "pi/64": epsi = pi/64 elif eps == "pi/256": epsi = pi/256 elif eps == "pi/1024": epsi = pi/1024 else: print "Invalid input from drop down menu" ## Make sure that the number of iterations and the first iteration to ## ## display are consistent ------------------------------------------- ## if its <= star: iteration_error_window = tk.Toplevel(master) iteration_error_window.geometry("300x150") iteration_error_window.title("ILLEGAL INPUT DETECTED") text = Message(iteration_error_window, text = ITERMESSAGE) text.pack() return False ## Make sure that theta is in the proper range ## if cvar == "theta" and (para < 0 or para >= 2*pi): # para is a theta value and its outside of the [0,2pi) range. # Mod it into the [0,2pi) range. para = mod2pi(para) ## Make sure that phi is in the proper range ## if cvar == "phi" and (para <= -pi/2 or para >= pi/2): phi_error_window = tk.Toplevel(master) phi_error_window.geometry("400x300") phi_error_window.title("ILLEGAL INPUT DETECTED") text = Message(phi_error_window, text = PHIMESSAGE1) text.pack() return False ## Make sure that phi is in the proper range ## if cvar == "theta" and (avg - epsi <= -pi/2 or avg + epsi >= pi/2): phi_error_window = tk.Toplevel(master) phi_error_window.geometry("400x200") phi_error_window.title("ILLEGAL INPUT DETECTED") text = Message(phi_error_window, text = PHIMESSAGE2) text.pack() return False if plotter(cvar, sams, avg - epsi, avg + epsi, para, its+1, star, 2, \ styp, c + s + b): confirm_window = tk.Toplevel(master) confirm_window.geometry("200x100") confirm_window.title("Success!") msg = """ Pdf(s) of the desired images were created in the folder containing this application. """ text = Message(confirm_window, text = msg, padx = 10) text.pack()