Exemplo n.º 1
0
    def helper_numerical_tests_eqf(self, materials, backings, tol):

        for mat_name in materials:
            mat = from_yaml(THIS_FILE_DIR +
                            '/materials/{}.yaml'.format(mat_name),
                            force=EqFluidJCA)

            for (backing_type, backing_func) in backings:
                for d in THICKNESSES:
                    for a in ANGLES:
                        reference = np.loadtxt(
                            THIS_FILE_DIR +
                            '/references/eqf/{}_{}mm_{}_{}deg.PW'.format(
                                mat_name, int(d * 1e3), backing_type, a))

                        for l in reference:
                            S = Solver()
                            S.layers = [Layer(mat, d)]
                            S.backing = backing_func
                            result = S.solve(l[0], a)

                            asserts.assertAlmostEqual(
                                result['R'][0], l[2] + 1j * l[3], tol,
                                '(reflection) {}: f={}Hz angle={}deg d={:2.3f}m'
                                .format(mat_name, l[0], a, d))
                            if backing_func == backing.transmission:
                                asserts.assertAlmostEqual(
                                    result['T'][0], l[5] + 1j * l[6], tol,
                                    '(transmission) {}: f={}Hz angle={}deg d={:2.3f}m'
                                    .format(mat_name, l[0], a, d))
Exemplo n.º 2
0
    def helper_bi_mat(self, mat1_name, mat2_name, backings, tol):

        mat1 = from_yaml(THIS_FILE_DIR +
                         '/materials/{}.yaml'.format(mat1_name))
        mat2 = from_yaml(THIS_FILE_DIR +
                         '/materials/{}.yaml'.format(mat2_name))

        prefix = '{}_{}'.format(mat1_name, mat2_name)

        for (backing_type, backing_func) in backings:
            for (d1, d2) in itertools.product(THICKNESSES, THICKNESSES):
                filename = THIS_FILE_DIR + '/references/{}_{}mm_{}mm_{}.csv'.format(
                    prefix, int(d1 * 1e3), int(d2 * 1e3), backing_type)
                if not os.path.exists(filename):
                    continue

                reference = np.loadtxt(filename)

                for l in reference:
                    S = Solver()
                    S.layers = [Layer(mat1, d1), Layer(mat2, d2)]
                    S.backing = backing_func
                    result = S.solve(l[0], l[1])

                    asserts.assertAlmostEqual(result['R'][0], l[2] + 1j * l[3],
                                              tol)
                    if backing_func == backing.transmission:
                        asserts.assertAlmostEqual(result['T'][0],
                                                  l[4] + 1j * l[5], tol)
Exemplo n.º 3
0
def result_pymls(**kwargs):
    name_project = kwargs.get("name_project", "unnamed_project")
    ml = kwargs.get("ml", False)
    termination = kwargs.get("termination", "rigid")
    theta_d = kwargs.get("theta_d", 45)
    freq = kwargs.get("frequencies", np.array([440]))
    plot_RT = kwargs.get("plot_RT", False)
    solver = Solver()
    for _l in ml:
        mat = load_material(_l[0])
        solver.layers.append(Layer(mat, _l[1]))

    R = []
    if termination in ["rigid", "Rigid", "Rigid Wall", "Wall"]:
        solver.backing = backing.rigid
        T = False
    else:
        T = []
        solver.backing = backing.transmission
    for _f in freq:
        _ = solver.solve(_f, theta_d)
        R.append(_["R"][0])
        if termination == "transmission":
            T.append(_["T"][0])
    if plot_RT:
        plt.figure(name_project + "/ Reflection coefficient")
        plt.plot(freq, [_.real for _ in R], 'r', label="Re(R) pymls")
        plt.plot(freq, [_.imag for _ in R], 'b', label="Im(R) pymls")
        plt.legend()
        if T is not False:
            plt.figure(name_project + "/ Transmission coefficient")
            plt.plot(freq, [_.real for _ in T], 'r', label="Re(T) pymls")
            plt.plot(freq, [_.imag for _ in T], 'b', label="Im(T) pymls")
            plt.legend()
    return freq, R, T
Exemplo n.º 4
0
    def helper_bi_mat_eqf(self,
                          mat1_name,
                          mat2_name,
                          backings,
                          tol,
                          no_is_default=-1,
                          ref_path='eqf'):

        if no_is_default == 1:
            mat1 = from_yaml(THIS_FILE_DIR +
                             '/materials/{}.yaml'.format(mat1_name))
        else:
            mat1 = from_yaml(THIS_FILE_DIR +
                             '/materials/{}.yaml'.format(mat1_name),
                             force=EqFluidJCA)

        if no_is_default == 2:
            mat2 = from_yaml(THIS_FILE_DIR +
                             '/materials/{}.yaml'.format(mat2_name))
        else:
            mat2 = from_yaml(THIS_FILE_DIR +
                             '/materials/{}.yaml'.format(mat2_name),
                             force=EqFluidJCA)

        prefix = '{}_{}'.format(mat1_name, mat2_name)

        for (backing_type, backing_func) in backings:
            for (d1, d2) in itertools.product(THICKNESSES, THICKNESSES):
                for a in ANGLES:
                    filename = THIS_FILE_DIR + '/references/{}/{}_{}mm_{}mm_{}_{}deg.PW'.format(
                        ref_path, prefix, int(d1 * 1e3), int(d2 * 1e3),
                        backing_type, a)
                    if not os.path.exists(filename):
                        continue

                    reference = np.loadtxt(filename)

                    for l in reference:
                        S = Solver()
                        S.layers = [Layer(mat1, d1), Layer(mat2, d2)]
                        S.backing = backing_func
                        result = S.solve(l[0], a)

                        asserts.assertAlmostEqual(
                            result['R'][0], l[2] + 1j * l[3], tol,
                            '(reflection) {} {} : f={}Hz angle={}deg d1={:2.3f}m d2={:2.3f}m'
                            .format(mat1_name, mat2_name, l[0], a, d1, d2))
                        if backing_func == backing.transmission:
                            asserts.assertAlmostEqual(
                                result['T'][0], l[5] + 1j * l[6], tol,
                                '(transmission) {} {} : f={}Hz angle={}deg d1={:2.3f}m d2={:2.3f}m'
                                .format(mat1_name, mat2_name, l[0], a, d1, d2))
Exemplo n.º 5
0
    def helper_bi_mat_eqf(self,
                          mat1_name,
                          mat2_name,
                          backings,
                          tol,
                          no_is_default=-1,
                          ref_path='eqf'):

        if no_is_default == 1:
            mat1 = from_yaml(THIS_FILE_DIR + f'/materials/{mat1_name}.yaml')
        else:
            mat1 = from_yaml(THIS_FILE_DIR + f'/materials/{mat1_name}.yaml',
                             force=EqFluidJCA)

        if no_is_default == 2:
            mat2 = from_yaml(THIS_FILE_DIR + f'/materials/{mat2_name}.yaml')
        else:
            mat2 = from_yaml(THIS_FILE_DIR + f'/materials/{mat2_name}.yaml',
                             force=EqFluidJCA)

        prefix = f'{mat1_name}_{mat2_name}'

        for (backing_type, backing_func) in backings:
            for (d1, d2) in itertools.product(THICKNESSES, THICKNESSES):
                for a in ANGLES:
                    filename = THIS_FILE_DIR + f'/references/{ref_path}/{prefix}_{int(d1*1e3)}mm_{int(d2*1e3)}mm_{backing_type}_{a}deg.PW'
                    if not os.path.exists(filename):
                        continue

                    reference = np.loadtxt(filename)

                    for l in reference:
                        S = Solver()
                        S.layers = [Layer(mat1, d1), Layer(mat2, d2)]
                        S.backing = backing_func
                        result = S.solve(l[0], a)

                        self.assertAlmostEqual(
                            result['R'][0], l[2] + 1j * l[3], tol,
                            f'(reflection) {mat1_name} {mat2_name} : f={l[0]}Hz angle={a}deg d1={d1:2.3f}m d2={d2:2.3f}m'
                        )
                        if backing_func == backing.transmission:
                            self.assertAlmostEqual(
                                result['T'][0], l[5] + 1j * l[6], tol,
                                f'(transmission) {mat1_name} {mat2_name} : f={l[0]}Hz angle={a}deg d1={d1:2.3f}m d2={d2:2.3f}m'
                            )
Exemplo n.º 6
0
    def test_air_analytical(self):

        for d in THICKNESSES:
            S = Solver()
            S.layers = [Layer(Air, d)]
            S.backing = backing.rigid
            result = S.solve(FREQS, 0)

            for i_f, f in enumerate(result['f']):
                omega = 2 * np.pi * f
                k_air = omega * np.sqrt(Air.rho / Air.K)
                Z_s = -1j * Air.Z / np.tan(k_air * d)

                R_analytical = (Z_s - Air.Z) / (Z_s + Air.Z)

                asserts.assertAlmostEqual(
                    R_analytical, result['R'][i_f], NB_PLACES,
                    '(reflection) f={}Hz, d={}, theta=0'.format(f, d))
Exemplo n.º 7
0
    def helper_numerical_tests(self, materials, backings, tol):

        for mat_name in materials:
            mat = from_yaml(THIS_FILE_DIR +
                            '/materials/{}.yaml'.format(mat_name))

            for (backing_type, backing_func) in backings:
                for d in THICKNESSES:
                    reference = np.loadtxt(
                        THIS_FILE_DIR + '/references/{}_{}mm_{}.csv'.format(
                            mat_name, int(d * 1e3), backing_type))

                    for l in reference:
                        S = Solver()
                        S.layers = [Layer(mat, d)]
                        S.backing = backing_func
                        result = S.solve(l[0], l[1])

                        asserts.assertAlmostEqual(result['R'][0],
                                                  l[2] + 1j * l[3], tol)
                        if backing_func == backing.transmission:
                            asserts.assertAlmostEqual(result['T'][0],
                                                      l[4] + 1j * l[5], tol)
Exemplo n.º 8
0
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#

import sys
sys.path.append('../')

from pymls import from_yaml, Solver, Layer, backing

freq = 20
d = 200e-3
theta = 30

foam = from_yaml('materials/foam2.yaml')

S = Solver()
S.layers = [Layer(foam, d)]
S.backing = backing.rigid

result = S.solve(freq, theta)
pymls = result['R'][0]

print("pymls: R = ", pymls)