def ExportResults(self): if self.lineEdit_FileName.text() != "": if self.save_path != "": self.export_path_folder = self.save_path + "/" else: error( "Plese, choose a folder before trying export the results!") return else: error("Inform a file name before trying export the results!") return self.check(export=True) freq = self.frequencies self.export_path = self.export_path_folder + self.lineEdit_FileName.text( ) + ".dat" if self.save_Absolute: response = get_structural_frf(self.mesh, self.solution, self.nodeID, self.localDof) header = ( "Frequency[Hz], Real part [{}], Imaginary part [{}], Absolute [{}]" ).format(self.unit_label, self.unit_label, self.unit_label) data_to_export = np.array( [freq, np.real(response), np.imag(response), np.abs(response)]).T elif self.save_Real_Imaginary: response = get_structural_frf(self.mesh, self.solution, self.nodeID, self.localDof) header = ( "Frequency[Hz], Real part [{}], Imaginary part [{}]").format( self.unit_label, self.unit_label) data_to_export = np.array( [freq, np.real(response), np.imag(response)]).T np.savetxt(self.export_path, data_to_export, delimiter=",", header=header) self.messages("The results has been exported.")
def get_response(self): response = get_structural_frf(self.preprocessor, self.solution, self.node_ID, self.localDof) if self.SingleDiff: output_data = response * (1j * 2 * np.pi) * self.frequencies elif self.DoubleDiff: output_data = response * ((1j * 2 * np.pi * self.frequencies)**2) else: output_data = response return output_data
def plot(self): frequencies = self.frequencies dof_response = get_structural_frf(self.mesh, self.solution, self.nodeID, self.localDof) fig = plt.figure(figsize=[10, 6]) ax = fig.add_subplot(1, 1, 1) #cursor = Cursor(ax) cursor = SnaptoCursor(ax, frequencies, dof_response, show_cursor=True) plt.connect('motion_notify_event', cursor.mouse_move) legend_label = "Response {} at node {}".format(self.localdof_label, self.nodeID) if dof_response.all() == 0: first_plot, = plt.plot(frequencies, dof_response, color=[1, 0, 0], linewidth=2, label=legend_label) else: first_plot, = plt.semilogy(frequencies, dof_response, color=[1, 0, 0], linewidth=2, label=legend_label) first_legend = plt.legend(handles=[first_plot], loc='upper right') plt.gca().add_artist(first_legend) ax.set_title(('Frequency Response Function: {} Method').format( self.analysisMethod), fontsize=18, fontweight='bold') ax.set_xlabel(('Frequency [Hz]'), fontsize=16, fontweight='bold') ax.set_ylabel(("FRF's magnitude [{}]").format(self.unit_label), fontsize=16, fontweight='bold') # plt.axis([np.min(frequencies), np.max(frequencies), np.min(dof_response), np.max(dof_response)]) plt.show()
def plot(self): fig = plt.figure(figsize=[12, 7]) ax = fig.add_subplot(1, 1, 1) # file_open = open("C:/AIV\PROJECT/OpenPulse/examples/validation_structural/data/ey_5mm_ez_0mm/FRF_Fx_1N_n361_Ux_n436.csv", "r") # file_open = open("C:/AIV\PROJECT/OpenPulse/examples/validation_structural/data/ey_5mm_ez_0mm/FRF_Fx_1N_n361_Uy_n187.csv", "r") # file_open = open("C:/AIV\PROJECT/OpenPulse/examples/validation_structural/data/ey_5mm_ez_0mm/FRF_Fx_1N_n361_Uz_n711.csv", "r") # data = np.loadtxt(file_open, delimiter="," , skiprows=2) frequencies = self.frequencies response = get_structural_frf(self.mesh, self.solution, self.nodeID, self.localDof, absolute=self.plotAbs, real=self.plotReal, imaginary=self.plotImag) if self.plotAbs: ax.set_ylabel(("Structural Response - Absolute [{}]").format( self.unit_label), fontsize=14, fontweight='bold') elif self.plotReal: ax.set_ylabel( ("Structural Response - Real [{}]").format(self.unit_label), fontsize=14, fontweight='bold') elif self.plotImag: ax.set_ylabel(("Structural Response - Imaginary [{}]").format( self.unit_label), fontsize=14, fontweight='bold') #cursor = Cursor(ax) cursor = SnaptoCursor(ax, frequencies, response, show_cursor=True) plt.connect('motion_notify_event', cursor.mouse_move) legend_label = "Response {} at node {}".format(self.localdof_label, self.nodeID) if self.imported_data is None: if any(value <= 0 for value in response): first_plot, = plt.plot(frequencies, response, color=[1, 0, 0], linewidth=2, label=legend_label) else: first_plot, = plt.semilogy(frequencies, response, color=[1, 0, 0], linewidth=2, label=legend_label) # second_plot, = plt.semilogy(data[:,0], np.abs(data[:,1]+1j*data[:,2]), color=[0,0,1], linewidth=1) _legends = plt.legend(handles=[first_plot], labels=[legend_label], loc='upper right') else: data = self.imported_data imported_Xvalues = data[:, 0] if self.plotAbs: imported_Yvalues = np.abs(data[:, 1] + 1j * data[:, 2]) elif self.plotReal: imported_Yvalues = data[:, 1] elif self.plotImag: imported_Yvalues = data[:, 2] if any(value <= 0 for value in response) or any( value <= 0 for value in imported_Yvalues): first_plot, = plt.plot(frequencies, response, color=[1, 0, 0], linewidth=2) second_plot, = plt.plot(imported_Xvalues, imported_Yvalues, color=[0, 0, 1], linewidth=1, linestyle="--") else: first_plot, = plt.semilogy(frequencies, response, color=[1, 0, 0], linewidth=2, label=legend_label) second_plot, = plt.semilogy(imported_Xvalues, imported_Yvalues, color=[0, 0, 1], linewidth=1, linestyle="--") _legends = plt.legend(handles=[first_plot, second_plot], labels=[legend_label, self.legend_imported], loc='upper right') plt.gca().add_artist(_legends) ax.set_title( ('Frequency Response: {} Method').format(self.analysisMethod), fontsize=18, fontweight='bold') ax.set_xlabel(('Frequency [Hz]'), fontsize=14, fontweight='bold') plt.show()
plot_results(mesh, coord_def, scf=0.5, out_OpenPulse=True, Show_nodes=True, Undeformed=False, Deformed=False, Animate_Mode=True, Save=False) #%% # GETTING FRF response_node = 361 local_DOF = 0 response_DM = get_structural_frf(mesh, direct, response_node, local_DOF) response_MS = get_structural_frf(mesh, modal, response_node, local_DOF) DOF_label = dict(zip(np.arange(6), ["Ux", "Uy", "Uz", "Rx", "Ry", "Rz"])) Unit_label = dict( zip(np.arange(6), ["[m]", "[m]", "[m]", "[rad]", "[rad]", "[rad]"])) # PLOTTING RESULTS fig = plt.figure(figsize=[10, 6]) ax = fig.add_subplot(1, 1, 1) first_legend_label = "Direct" second_legend_label = "Mode superposition" if response_DM.all() == 0 or response_MS.all() == 0: first_plot, = plt.plot(frequencies,
if run==1: # nodal respose (node, dof_corrected) node_response = 436 # Desired node to get response. local_dof_response = 0 # Get the response at the following degree of freedom if run==2: # nodal respose (node, dof_corrected) node_response = 187 # Desired node to get response. local_dof_response = 1 # Get the response at the following degree of freedom if run==3: # nodal respose (node, dof_corrected) node_response = 711 # Desired node to get response. local_dof_response = 2 # Get the response at the following degree of freedom Xd = get_structural_frf(mesh, direct, node_response, local_dof_response) Xs = get_structural_frf(mesh, modal, node_response, local_dof_response) test_label = "ey_{}mm_ez_{}mm".format(int(offset[0]*1000),int(offset[1]*1000)) if run==1: file1 = open("examples/validation_structural/data/" + test_label + "/FRF_Fx_1N_n361_Ux_n436.csv", "r") FRF = np.loadtxt(file1, delimiter=",", skiprows=2) file1.close() elif run==2: file2 = open("examples/validation_structural/data/" + test_label + "/FRF_Fx_1N_n361_Uy_n187.csv", "r") FRF = np.loadtxt(file2, delimiter=",", skiprows=2) file2.close() elif run==3: file3 = open("examples/validation_structural/data/" + test_label + "/FRF_Fx_1N_n361_Uz_n711.csv", "r") FRF = np.loadtxt(file3, delimiter=",", skiprows=2)
if run == 1: # nodal response (node, dof_corrected) node_response = 436 # Desired node to get response. local_dof_response = 0 # Get the response at the following degree of freedom if run == 2: # nodal response (node, dof_corrected) node_response = 187 # Desired node to get response. local_dof_response = 1 # Get the response at the following degree of freedom if run == 3: # nodal response (node, dof_corrected) node_response = 711 # Desired node to get response. local_dof_response = 2 # Get the response at the following degree of freedom Xd = get_structural_frf(preprocessor, direct, node_response, local_dof_response, absolute=True) Xs = get_structural_frf(preprocessor, modal, node_response, local_dof_response, absolute=True) # test_label = "ey_{}mm_ez_{}mm".format(int(offset[0]*1000),int(offset[1]*1000)) # if run==1: # # file1 = open("examples/validation_structural/data/" + test_label + "/FRF_Fx_1N_n361_Ux_n436.csv", "r") # file1 = "C:/Users/" # FRF = np.loadtxt(file1, delimiter=",", skiprows=2) # # file1.close()