Esempio n. 1
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)
Esempio n. 2
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))
Esempio n. 3
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))
Esempio 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 + 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'
                            )
Esempio n. 5
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)
Esempio n. 6
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)
Esempio n. 7
0
# 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_pem = 200e-3
d_wood = 2e-2
theta = 30

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

S = Solver()
S.layers = [
    Layer(foam, d_pem),
    Layer(wood, d_wood),
]
S.backing = backing.rigid

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

print("pymls: R = ", pymls)
Esempio 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 = 10
d = 0.5e-3
theta = 10

glass = from_yaml('materials/glass.yaml')

S = Solver()
S.layers = [Layer(glass, d)]
S.backing = backing.transmission

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

print("pymls: R = ", pymls)
Esempio n. 9
0
def load_material(mat):
    if mat == "Air":
        Air_mat = Air()
        return Fluid(c=Air_mat.c, rho=Air_mat.rho)
    else:
        return from_yaml("materials/" + mat + ".yaml")