Пример #1
0
    def get_TL_NR(self):

        self.stop = False

        noise = 1e-10

        P_input = get_acoustic_frf(self.preprocessor, self.solution,
                                   self.input_node_ID)
        P_output = get_acoustic_frf(self.preprocessor, self.solution,
                                    self.output_node_ID)

        P_input2 = 0.5 * np.real(P_input * np.conjugate(P_input)) + noise
        P_output2 = 0.5 * np.real(P_output * np.conjugate(P_output)) + noise

        d_in, rho_in, c0_in = self.get_minor_outer_diameter_from_node(
            self.input_node_ID)
        d_out, rho_out, c0_out = self.get_minor_outer_diameter_from_node(
            self.output_node_ID)

        # if 0 not in P_input2 and 0 not in P_output2:

        if self.flagTL:
            alpha_T = (P_output2 * rho_out * c0_out) / (P_input2 * rho_in *
                                                        c0_in)
            TL = -10 * np.log10(alpha_T)
            return TL

        if self.flagNR:
            delta = (P_output2 * rho_out * c0_out *
                     (d_out**2)) / (P_input2 * rho_in * c0_in * (d_in**2))
            NR = 10 * np.log10(delta)
            return NR
    def ExportResults(self):

        if self.lineEdit_FileName.text() != "":
            if self.save_path != "":
                self.export_path_folder = self.save_path + "/"
            else:
                title = "None folder selected"
                message = "Plese, choose a folder before trying export the results."
                PrintMessageInput([title, message, window_title1])
                return
        else:
            title = "Empty file name"
            message = "Inform a file name before trying export the results."
            PrintMessageInput([title, message, window_title1])
            return

        if self.check(export=True):
            return

        freq = self.frequencies
        self.export_path = self.export_path_folder + self.lineEdit_FileName.text(
        ) + ".dat"
        if self.save_Absolute:
            response = get_acoustic_frf(self.preprocessor, self.solution,
                                        self.node_ID)
            header = "Frequency[Hz], Real part [Pa], Imaginary part [Pa], Absolute [Pa]"
            data_to_export = np.array(
                [freq,
                 np.real(response),
                 np.imag(response),
                 np.abs(response)]).T
        elif self.save_Real_Imaginary:
            response = get_acoustic_frf(self.preprocessor, self.solution,
                                        self.node_ID)
            header = "Frequency[Hz], Real part [Pa], Imaginary part [Pa]"
            data_to_export = np.array(
                [freq, np.real(response),
                 np.imag(response)]).T

        np.savetxt(self.export_path,
                   data_to_export,
                   delimiter=",",
                   header=header)
        title = "Information"
        message = "The results have been exported."
        PrintMessageInput([title, message, window_title2])
Пример #3
0
    def get_TL_NR(self):
        P_input = get_acoustic_frf(self.mesh, self.solution, self.input_node)
        P_output = get_acoustic_frf(self.mesh, self.solution, self.output_node)

        P_input2 = 0.5 * np.real(P_input * np.conjugate(P_input))
        P_output2 = 0.5 * np.real(P_output * np.conjugate(P_output))

        d_in, rho_in, c0_in = self.get_minor_external_diameter_from_node(
            self.input_node)
        d_out, rho_out, c0_out = self.get_minor_external_diameter_from_node(
            self.output_node)

        if P_input2.all() != 0:
            alpha_T = (P_output2 * rho_out * c0_out) / (P_input2 * rho_in *
                                                        c0_in)
            TL = -10 * np.log10(alpha_T)
            delta = (P_output2 * rho_out * c0_out *
                     (d_out**2)) / (P_input2 * rho_in * c0_in * (d_in**2))
            NR = 10 * np.log10(delta)
        else:
            message = "The input pressure must be different from zero value!"
            error(message, title=" Input pressure value Error ")
        return TL, NR
Пример #4
0
    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_acoustic_frf(self.mesh, self.solution, self.nodeID)
            header = "Frequency[Hz], Real part [Pa], Imaginary part [Pa], Absolute [Pa]"
            data_to_export = np.array(
                [freq,
                 np.real(response),
                 np.imag(response),
                 np.abs(response)]).T
        elif self.save_Real_Imaginary:
            response = get_acoustic_frf(self.mesh, self.solution, self.nodeID)
            header = "Frequency[Hz], Real part [Pa], Imaginary part [Pa]"
            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.")
Пример #5
0
    def plot(self):

        fig = plt.figure(figsize=[12, 7])
        ax = fig.add_subplot(1, 1, 1)

        frequencies = self.frequencies
        response = get_acoustic_frf(self.mesh,
                                    self.solution,
                                    self.nodeID,
                                    absolute=self.plotAbs,
                                    real=self.plotReal,
                                    imag=self.plotImag)

        if self.scale_dB:
            if self.plotAbs:
                response = self.dB(response)
                ax.set_ylabel("Acoustic Response - Absolute [dB]",
                              fontsize=14,
                              fontweight='bold')
            else:
                if self.plotReal:
                    ax.set_ylabel("Acoustic Response - Real [Pa]",
                                  fontsize=14,
                                  fontweight='bold')
                elif self.plotImag:
                    ax.set_ylabel("Acoustic Response - Imaginary [Pa]",
                                  fontsize=14,
                                  fontweight='bold')
                self.messages(
                    "The dB scalling can only be applied with the absolute \nY-axis representation, therefore, it will be ignored."
                )
        else:
            if self.plotAbs:
                ax.set_ylabel("Acoustic Response - Absolute [Pa]",
                              fontsize=14,
                              fontweight='bold')
            elif self.plotReal:
                ax.set_ylabel("Acoustic Response - Real [Pa]",
                              fontsize=14,
                              fontweight='bold')
            elif self.plotImag:
                ax.set_ylabel("Acoustic Response - Imaginary [Pa]",
                              fontsize=14,
                              fontweight='bold')

        # mng = plt.get_current_fig_manager()
        # mng.window.state('zoomed')

        #cursor = Cursor(ax)
        cursor = SnaptoCursor(ax, frequencies, response, show_cursor=True)
        plt.connect('motion_notify_event', cursor.mouse_move)

        legend_label = "Acoustic Pressure at node {}".format(self.nodeID)

        if self.imported_data is None:

            if self.plotAbs and not self.scale_dB:
                first_plot, = plt.semilogy(frequencies,
                                           response,
                                           color=[1, 0, 0],
                                           linewidth=2,
                                           label=legend_label)
            else:
                first_plot, = plt.plot(frequencies,
                                       response,
                                       color=[1, 0, 0],
                                       linewidth=2,
                                       label=legend_label)
            _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])
                if self.scale_dB:
                    imported_Yvalues = self.dB(imported_Yvalues)
            elif self.plotReal:
                imported_Yvalues = data[:, 1]
            elif self.plotImag:
                imported_Yvalues = data[:, 2]

            if self.plotAbs and not self.scale_dB:
                first_plot, = plt.semilogy(frequencies,
                                           response,
                                           color=[1, 0, 0],
                                           linewidth=2)
                second_plot, = plt.semilogy(imported_Xvalues,
                                            imported_Yvalues,
                                            color=[0, 0, 1],
                                            linewidth=1,
                                            linestyle="--")
            else:
                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="--")

            _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()
Пример #6
0
    preprocessor.set_radiation_impedance_bc_by_node(1086 , 1)
elif flanged:
    preprocessor.set_radiation_impedance_bc_by_node(1086 , 2)

preprocessor.set_fluid_by_element('all', air)
preprocessor.set_cross_section_by_element('all', cross_section)
# Analisys Frequencies
f_max = 2500
df = 1
frequencies = np.arange(df, f_max+df, df)

solution = SolutionAcoustic(preprocessor, frequencies)

direct = solution.direct_method()

pressure = get_acoustic_frf(preprocessor, direct, 1086, dB=True)
p_ref = 20e-6
 
plt.rcParams.update({'font.size': 12})

if unflanged:
    fem=np.loadtxt("examples/validation_radiation_impedance/pout_fem_unflanged.dat", delimiter = ',')
    title = "Pressure out - Unflanged pipe"
elif flanged:
    fem=np.loadtxt("examples/validation_radiation_impedance/pout_fem_flanged.dat", delimiter = ',')
    title = "Pressure out - Flanged pipe"

fem_dB = 20*np.log10(np.abs((fem[:, 3])/p_ref))

#Axis plots and legends
plt.title(title)
Пример #7
0
], 0, "section")  # Expansion correction
preprocessor.set_length_correction_by_element([
    608, 609, 610, 967, 968, 984, 985, 986, 987, 988, 1004, 1005, 1006, 1007,
    1008, 1009, 1047, 1048, 1097, 1098, 1147, 1148, 1149
], 1, "section")  # Side branch correction
# Analisys Frequencies
f_max = 250
df = 1
frequencies = np.arange(df, f_max + df, df)

solution = SolutionAcoustic(mesh, frequencies)

direct = solution.direct_method()
#%% Validation

pressure = get_acoustic_frf(mesh, direct, 1047, dB=True)
p_ref = 20e-6

plt.rcParams.update({'font.size': 12})

f_fem = np.loadtxt(
    "examples/validation_length_correction/tube_2_expasion.dat")[:, 0]
p_fem = np.loadtxt(
    "examples/validation_length_correction/tube_2_expasion.dat")[:, 1:]
p_fem_dB = 20 * np.log10(np.abs((p_fem[:, 0] + 1j * p_fem[:, 1]) / p_ref))

#Axis plots and legends
plt.title("Node 1047")
plt.plot(frequencies, pressure)
plt.plot(f_fem, p_fem_dB, '-.')
plt.legend(['FETM - OpenPulse', 'FEM 3D - Comsol'], loc='best')
Пример #8
0
mesh.set_fluid_by_element('all', hydrogen)
mesh.set_material_by_element('all', steel)
mesh.set_cross_section_by_element('all', cross_section)

# Analisys Frequencies
f_max = 250
df = 1
frequencies = np.arange(df, f_max + df, df)

solution_acoustic = SolutionAcoustic(mesh, frequencies)

direct = solution_acoustic.direct_method()
#%% Acoustic validation

if run == 1:
    p_out = get_acoustic_frf(mesh, direct, 1086)
    p_b1 = get_acoustic_frf(mesh, direct, 1136)
    p_b2 = get_acoustic_frf(mesh, direct, 1186)
    p_b3 = get_acoustic_frf(mesh, direct, 1236)
    text_out = "Node 1086 (output)"
    text_b1 = "Node 1136 (branch 1)"
    text_b2 = "Node 1186 (branch 2)"
    text_b3 = "Node 1236 (branch 3)"

elif run == 2:
    p_out = get_acoustic_frf(mesh, direct, 1047)
    p_b1 = get_acoustic_frf(mesh, direct, 1087)
    p_b2 = get_acoustic_frf(mesh, direct, 1137)
    p_b3 = get_acoustic_frf(mesh, direct, 1187)
    text_out = "Node 1047 (output)"
    text_b1 = "Node 1087 (branch 1)"
Пример #9
0
# Frequencies of analysis
f_max = 1000
df = 1
frequencies = np.arange(df, f_max + df, df)
solution = SolutionAcoustic(preprocessor, frequencies)

direct = solution.direct_method()

f_fem = np.loadtxt("examples/validation_mean_flow/dataM0p1_peters.txt",
                   delimiter=',')[:, 0]
p_fem = np.loadtxt("examples/validation_mean_flow/dataM0p1_peters.txt",
                   delimiter=',')[:, 1:3]
p_fem = p_fem[:, 0] + 1j * p_fem[:, 1]

p_ref = 20e-6
p_fem_dB = 20 * np.log10(np.abs(p_fem) / (np.sqrt(2) * p_ref))
p_out = get_acoustic_frf(preprocessor, direct, 103, dB=True)

plt.rcParams.update({'font.size': 12})
plt.figure()
#Axis plots and legends
plt.title('Node 51. Model: ' + str(element_type) + '. Mach: ' + str(mach))
plt.plot(frequencies, p_out)
plt.plot(f_fem, p_fem_dB, ':')
plt.legend(['FETM - OpenPulse', 'FETM - Martin'], loc='best')
plt.xlabel('Frequency [Hz]')
plt.ylabel('Pressure [dB]')
plt.xlim(df, f_max)
plt.grid(True)
plt.show()
Пример #10
0
solution = SolutionAcoustic(preprocessor, frequencies)
direct_pp = solution.direct_method()

f_fem = np.loadtxt("examples/validation_perforated_plate/FEM.txt",
                   delimiter=',')[:, 0]
p_fem = np.loadtxt("examples/validation_perforated_plate/FEM.txt",
                   delimiter=',')[:, 1:4]

p_ref = 20e-6
p_fem_dB = 20 * np.log10(p_fem[:, 2] / (np.sqrt(2) * p_ref))

plt.rcParams.update({'font.size': 12})
plt.figure()
#Axis plots and legends
plt.title("Node 234")
plt.plot(frequencies, get_acoustic_frf(preprocessor, direct, 234, dB=True))
plt.plot(frequencies, get_acoustic_frf(preprocessor, direct_pp, 234, dB=True),
         '-.')
plt.plot(f_fem, p_fem_dB, ':')
# plt.plot(f_fem, p_fem_zlin[:,2],':')
plt.legend([
    'FETM - OpenPulse', 'FETM - OpenPulse w/ Perforated Plate',
    'FEM - w/ Perforated Plate'
],
           loc='best')
plt.xlabel('Frequency [Hz]')
plt.ylabel('Pressure [dB]')
plt.xlim(0, 400)
# plt.ylim(40, 120)
plt.grid(True)
plt.show()
Пример #11
0
preprocessor.set_fluid_by_element('all', hydrogen)
preprocessor.set_material_by_element('all', steel)
preprocessor.set_cross_section_by_element('all', cross_section)

# Analisys Frequencies
f_max = 250
df = 1
frequencies = np.arange(df, f_max + df, df)

solution_acoustic = SolutionAcoustic(preprocessor, frequencies)

direct = solution_acoustic.direct_method()
#%% Acoustic validation

if run == 1:
    p_out = get_acoustic_frf(preprocessor, direct, 1086)
    p_b1 = get_acoustic_frf(preprocessor, direct, 1136)
    p_b2 = get_acoustic_frf(preprocessor, direct, 1186)
    p_b3 = get_acoustic_frf(preprocessor, direct, 1236)
    text_out = "Node 1086 (output)"
    text_b1 = "Node 1136 (branch 1)"
    text_b2 = "Node 1186 (branch 2)"
    text_b3 = "Node 1236 (branch 3)"

elif run == 2:
    p_out = get_acoustic_frf(preprocessor, direct, 1047)
    p_b1 = get_acoustic_frf(preprocessor, direct, 1087)
    p_b2 = get_acoustic_frf(preprocessor, direct, 1137)
    p_b3 = get_acoustic_frf(preprocessor, direct, 1187)
    text_out = "Node 1047 (output)"
    text_b1 = "Node 1087 (branch 1)"
    def plot(self):

        self.fig = plt.figure(figsize=[12, 7])
        ax = self.fig.add_subplot(1, 1, 1)

        frequencies = self.frequencies
        response = get_acoustic_frf(self.preprocessor,
                                    self.solution,
                                    self.node_ID,
                                    absolute=self.plotAbs,
                                    real=self.plotReal,
                                    imag=self.plotImag)

        if complex(0) in response:
            response += np.ones(len(response), dtype=float) * (1e-12)

        if self.scale_dB:
            if self.plotAbs:
                response = self.dB(response)
                ax.set_ylabel("Acoustic Response - Absolute [dB]",
                              fontsize=14,
                              fontweight='bold')
            else:
                if self.plotReal:
                    ax.set_ylabel("Acoustic Response - Real [Pa]",
                                  fontsize=14,
                                  fontweight='bold')
                elif self.plotImag:
                    ax.set_ylabel("Acoustic Response - Imaginary [Pa]",
                                  fontsize=14,
                                  fontweight='bold')
                title = "Plot Information"
                message = "The dB scalling can only be applied with the absolute \nY-axis representation, therefore, it will be ignored."
                PrintMessageInput([title, message, window_title2])
        else:
            if self.plotAbs:
                ax.set_ylabel("Acoustic Response - Absolute [Pa]",
                              fontsize=14,
                              fontweight='bold')
            elif self.plotReal:
                ax.set_ylabel("Acoustic Response - Real [Pa]",
                              fontsize=14,
                              fontweight='bold')
            elif self.plotImag:
                ax.set_ylabel("Acoustic Response - Imaginary [Pa]",
                              fontsize=14,
                              fontweight='bold')

        # mng = plt.get_current_fig_manager()
        # mng.window.state('zoomed')

        #cursor = Cursor(ax)
        self.cursor = SnaptoCursor(ax, frequencies, response, self.use_cursor)
        self.mouse_connection = self.fig.canvas.mpl_connect(
            s='motion_notify_event', func=self.cursor.mouse_move)

        legend_label = "Acoustic Pressure at node {}".format(self.node_ID)

        if self.imported_data is None:

            response += np.ones(len(response), dtype=float) * (1e-12)

            if self.plotAbs and not self.scale_dB and not complex(
                    0) in response:
                first_plot, = plt.semilogy(frequencies,
                                           response,
                                           color=[1, 0, 0],
                                           linewidth=2,
                                           label=legend_label)
            else:
                first_plot, = plt.plot(frequencies,
                                       response,
                                       color=[1, 0, 0],
                                       linewidth=2,
                                       label=legend_label)
            _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])
                if complex(0) in imported_Yvalues:
                    imported_Yvalues += np.ones(len(imported_Yvalues),
                                                dtype=float) * (1e-12)

                if self.scale_dB:
                    imported_Yvalues = self.dB(imported_Yvalues)
            elif self.plotReal:
                imported_Yvalues = data[:, 1]
            elif self.plotImag:
                imported_Yvalues = data[:, 2]

            if self.plotAbs and not self.scale_dB and not complex(
                    0) in response:
                first_plot, = plt.semilogy(frequencies,
                                           response,
                                           color=[1, 0, 0],
                                           linewidth=2)
                second_plot, = plt.semilogy(imported_Xvalues,
                                            imported_Yvalues,
                                            color=[0, 0, 1],
                                            linewidth=1,
                                            linestyle="--")
            else:
                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="--")

            _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(('ACOUSTIC FREQUENCY RESPONSE - {}').format(
            self.analysisMethod.upper()),
                     fontsize=16,
                     fontweight='bold')
        ax.set_xlabel(('Frequency [Hz]'), fontsize=14, fontweight='bold')

        self.fig.show()