Пример #1
0
 def test_norm_speed_of_sound(self):
     f = BaseFluid(4.0, 0.0, 4.0, 0.0)
     self.assertEqual(1.0, f.norm_speed_of_sound)
     f = BaseFluid(4.0, 0.0, 16.0, 0.0)
     self.assertEqual(2.0, f.norm_speed_of_sound)
     f = BaseFluid(64.0, 0.0, 16.0, 0.0)
     self.assertEqual(0.5, f.norm_speed_of_sound)
Пример #2
0
 def test_density(self):
     p = self.fluid.norm_pressure
     t = self.fluid.norm_temperature
     self.assertEqual(self.fluid.norm_density, self.fluid.density(p, t))
     answer = np.asarray([self.fluid.norm_density, self.fluid.norm_density])
     result = self.fluid.density([p, p], [t, t])
     self.assertEqual(answer.shape, result.shape)
     npt.assert_almost_equal(result, answer)
     self.assertEqual(self.fluid.norm_density, self.fluid.density())
     f = BaseFluid(2.0, 0, 3.0, 0)
     p = f.norm_pressure + 5.0
     self.assertAlmostEqual(10.5889801009, f.density(p))
Пример #3
0
 def test_check_fluid(self):
     c = BaseComponent()
     f = BaseFluid(1, 2, 3, 4)
     self.assertEqual(None, c._global_fluid)
     c.check_fluid(123)
     self.assertEqual(123, c._global_fluid)
     c.check_fluid(f)
     self.assertEqual(f, c._global_fluid)
Пример #4
0
 def test_fluid(self):
     # Test setter
     s = BaseSolver(None, None)
     with self.assertRaises(TypeError):
         s.fluid = 123
     f = BaseFluid(1, 2, 3, 4)
     s.fluid = f
     self.assertEqual(f, s._fluid)
     # Test getter
     s = BaseSolver(None, None)
     self.assertEqual(None, s.fluid)
     s._fluid = 123
     self.assertEqual(123, s.fluid)
Пример #5
0
 def test_fluid(self):
     # Test getter
     c = BaseComponent()
     with self.assertRaises(AssertionError):
         c.fluid
     c._fluid = 456
     self.assertEqual(456, c.fluid)
     c._fluid = None
     c._global_fluid = 'abc'
     self.assertEqual('abc', c.fluid)
     # Test setter
     c = BaseComponent()
     f = BaseFluid(1, 2, 3, 4)
     self.assertEqual(None, c._fluid)
     with self.assertRaises(TypeError):
         c.fluid = 123
     c.fluid = f
     self.assertEqual(f, c._fluid)
Пример #6
0
 def test___init__(self):
     # Test invalid parameters
     with self.assertRaises(TypeError):
         BaseSolver(fluid=123, seeds=[])
     with self.assertRaises(TypeError):
         BaseSolver(fluid=None, seeds='xzy')
     with self.assertRaises(TypeError):
         BaseSolver(fluid=None, seeds=[Component(), 'abc'])
     # Test valid parameters
     f = BaseFluid(1, 2, 3, 4)
     s = BaseSolver(None, None)
     self.assertEqual(None, s._fluid)
     self.assertEqual([], s._seeds)
     s = BaseSolver(f, [])
     self.assertEqual(f, s._fluid)
     self.assertEqual([], s._seeds)
     c = Component()
     s = BaseSolver(f, c)
     self.assertEqual(f, s._fluid)
     self.assertCountEqual([c], s._seeds)
     c = [Component(), Component(), Component()]
     s = BaseSolver(None, c)
     self.assertEqual(None, s._fluid)
     self.assertCountEqual(c, s._seeds)
Пример #7
0
 def test___init__(self):
     # Invalid parameter tests
     with self.assertRaises(TypeError):
         BaseFluid('abc', 2, 3, 4, 5, 6)
     with self.assertRaises(TypeError):
         BaseFluid(1, 'def', 3, 4, 5, 6)
     with self.assertRaises(TypeError):
         BaseFluid(1, 2, 'ghi', 4, 5, 6)
     with self.assertRaises(TypeError):
         BaseFluid(1, 2, 3, 'jkl', 5, 6)
     with self.assertRaises(TypeError):
         BaseFluid(1, 2, 3, 4, 'mno', 6)
     with self.assertRaises(TypeError):
         BaseFluid(1, 2, 3, 4, 5, 'pqr')
     # Valid parameter tests
     self.assertEqual(101325, self.fluid._norm_pressure)
     self.assertEqual(293.15, self.fluid._norm_temperature)
     f = BaseFluid(9, 8, 7, 6, 5, 4)
     self.assertEqual(9, f._norm_density)
     self.assertEqual(8, f._norm_viscosity)
     self.assertEqual(7, f._norm_bulk_modulus)
     self.assertEqual(6, f._norm_vapor_pressure)
     self.assertEqual(5, f._norm_pressure)
     self.assertEqual(4, f._norm_temperature)
Пример #8
0
 def setUp(self):
     self.fluid = BaseFluid(1, 2, 3, 4)
Пример #9
0
class TestBaseFluid(TestCase):
    def setUp(self):
        self.fluid = BaseFluid(1, 2, 3, 4)

    def tearDown(self):
        del self.fluid
        self.fluid = None

    def test___init__(self):
        # Invalid parameter tests
        with self.assertRaises(TypeError):
            BaseFluid('abc', 2, 3, 4, 5, 6)
        with self.assertRaises(TypeError):
            BaseFluid(1, 'def', 3, 4, 5, 6)
        with self.assertRaises(TypeError):
            BaseFluid(1, 2, 'ghi', 4, 5, 6)
        with self.assertRaises(TypeError):
            BaseFluid(1, 2, 3, 'jkl', 5, 6)
        with self.assertRaises(TypeError):
            BaseFluid(1, 2, 3, 4, 'mno', 6)
        with self.assertRaises(TypeError):
            BaseFluid(1, 2, 3, 4, 5, 'pqr')
        # Valid parameter tests
        self.assertEqual(101325, self.fluid._norm_pressure)
        self.assertEqual(293.15, self.fluid._norm_temperature)
        f = BaseFluid(9, 8, 7, 6, 5, 4)
        self.assertEqual(9, f._norm_density)
        self.assertEqual(8, f._norm_viscosity)
        self.assertEqual(7, f._norm_bulk_modulus)
        self.assertEqual(6, f._norm_vapor_pressure)
        self.assertEqual(5, f._norm_pressure)
        self.assertEqual(4, f._norm_temperature)

    def test_norm_pressure(self):
        self.fluid._norm_pressure = None
        self.assertEqual(None, self.fluid.norm_pressure)
        self.fluid._norm_pressure = 123.45
        self.assertEqual(123.45, self.fluid.norm_pressure)

    def test_norm_temperature(self):
        self.fluid._norm_temperature = None
        self.assertEqual(None, self.fluid.norm_temperature)
        self.fluid._norm_temperature = 123.45
        self.assertEqual(123.45, self.fluid.norm_temperature)

    def test_norm_density(self):
        self.fluid._norm_density = None
        self.assertEqual(None, self.fluid.norm_density)
        self.fluid._norm_density = 123.45
        self.assertEqual(123.45, self.fluid.norm_density)

    def test_norm_viscosity(self):
        self.fluid._norm_viscosity = None
        self.assertEqual(None, self.fluid.norm_viscosity)
        self.fluid._norm_viscosity = 123.45
        self.assertEqual(123.45, self.fluid.norm_viscosity)

    def test_norm_bulk_modulus(self):
        self.fluid._norm_bulk_modulus = None
        self.assertEqual(None, self.fluid.norm_bulk_modulus)
        self.fluid._norm_bulk_modulus = 123.45
        self.assertEqual(123.45, self.fluid.norm_bulk_modulus)

    def test_norm_compressibility(self):
        self.fluid._norm_bulk_modulus = 123.45
        self.assertAlmostEqual(1.0 / 123.45, self.fluid.norm_compressibility)

    def test_norm_vapor_pressure(self):
        self.fluid._norm_vapor_pressure = None
        self.assertEqual(None, self.fluid.norm_vapor_pressure)
        self.fluid._norm_vapor_pressure = 123.45
        self.assertEqual(123.45, self.fluid.norm_vapor_pressure)

    def test_density(self):
        p = self.fluid.norm_pressure
        t = self.fluid.norm_temperature
        self.assertEqual(self.fluid.norm_density, self.fluid.density(p, t))
        answer = np.asarray([self.fluid.norm_density, self.fluid.norm_density])
        result = self.fluid.density([p, p], [t, t])
        self.assertEqual(answer.shape, result.shape)
        npt.assert_almost_equal(result, answer)
        self.assertEqual(self.fluid.norm_density, self.fluid.density())
        f = BaseFluid(2.0, 0, 3.0, 0)
        p = f.norm_pressure + 5.0
        self.assertAlmostEqual(10.5889801009, f.density(p))

    def test_viscosity(self):
        self.assertEqual(self.fluid.norm_viscosity,
                         self.fluid.viscosity(99, 111))
        answer = np.asarray(
            [self.fluid.norm_viscosity, self.fluid.norm_viscosity])
        result = self.fluid.viscosity([99, 99], [111, 111])
        self.assertEqual(answer.shape, result.shape)
        npt.assert_allclose(result, answer)

    def test_kinematic_viscosity(self):
        f = DummyFluid(1, 2)
        self.assertEqual(0.5, f.kinematic_viscosity(1, 2, 3))
        f = DummyFluid(15, 5)
        self.assertEqual(3, f.kinematic_viscosity(1, 2, 3))
        answer = np.asarray([3, 3])
        result = f.kinematic_viscosity([1, 1], [2, 2], [3, 3])
        self.assertEqual(answer.shape, result.shape)
        npt.assert_allclose(result, answer)

    def test_compressibility(self):
        self.assertEqual(self.fluid.norm_compressibility,
                         self.fluid.compressibility(222))
        answer = np.asarray(
            [self.fluid.norm_compressibility, self.fluid.norm_compressibility])
        result = self.fluid.compressibility([222, 222])
        self.assertEqual(answer.shape, result.shape)
        npt.assert_allclose(result, answer)

    def test_bulk_modulus(self):
        self.assertEqual(self.fluid.norm_bulk_modulus,
                         self.fluid.bulk_modulus(222))
        answer = np.asarray(
            [self.fluid.norm_bulk_modulus, self.fluid.norm_bulk_modulus])
        result = self.fluid.bulk_modulus([222, 222])
        self.assertEqual(answer.shape, result.shape)
        npt.assert_allclose(result, answer)

    def test_vapor_pressure(self):
        self.assertEqual(self.fluid.norm_vapor_pressure,
                         self.fluid.vapor_pressure(333))
        answer = np.asarray(
            [self.fluid.norm_vapor_pressure, self.fluid.norm_vapor_pressure])
        result = self.fluid.vapor_pressure([333, 333])
        self.assertEqual(answer.shape, result.shape)
        npt.assert_allclose(result, answer)

    def test_norm_speed_of_sound(self):
        f = BaseFluid(4.0, 0.0, 4.0, 0.0)
        self.assertEqual(1.0, f.norm_speed_of_sound)
        f = BaseFluid(4.0, 0.0, 16.0, 0.0)
        self.assertEqual(2.0, f.norm_speed_of_sound)
        f = BaseFluid(64.0, 0.0, 16.0, 0.0)
        self.assertEqual(0.5, f.norm_speed_of_sound)

    def test_speed_of_sound(self):
        f = DummyFluid(0., 4.0, 4.0)
        self.assertEqual(1.0, f.speed_of_sound(7, 8))
        f = DummyFluid(0., 4.0, 16.0)
        self.assertEqual(2.0, f.speed_of_sound(7, 8))
        f = DummyFluid(0., 64.0, 16.0)
        self.assertEqual(0.5, f.speed_of_sound(7, 8))
        answer = np.asarray([0.5, 0.5])
        result = f.speed_of_sound([7, 7], [8, 8])
        self.assertEqual(answer.shape, result.shape)
        npt.assert_allclose(result, answer)

    def test__ones(self):
        f = BaseFluid(4.0, 0.0, 4.0, 0.0)
        self.assertEqual(1.0, f._ones())
        self.assertEqual(1.0, f._ones(4))
        self.assertEqual(1.0, f._ones(param2=4))
        self.assertEqual(1.0, f._ones(7, 8))
        npt.assert_almost_equal(np.asarray([1, 1, 1]),
                                f._ones(np.asarray([1, 2, 3])))
        npt.assert_almost_equal(
            np.asarray([1, 1]), f._ones(np.asarray([1, 2]), np.asarray([3,
                                                                        4])))
        with self.assertRaises(IndexError):
            f._ones(1, np.asarray([1, 2]))
        with self.assertRaises(IndexError):
            f._ones(np.asarray([1, 2]), np.asarray([3, 4, 5, 6]))
Пример #10
0
 def test__ones(self):
     f = BaseFluid(4.0, 0.0, 4.0, 0.0)
     self.assertEqual(1.0, f._ones())
     self.assertEqual(1.0, f._ones(4))
     self.assertEqual(1.0, f._ones(param2=4))
     self.assertEqual(1.0, f._ones(7, 8))
     npt.assert_almost_equal(np.asarray([1, 1, 1]),
                             f._ones(np.asarray([1, 2, 3])))
     npt.assert_almost_equal(
         np.asarray([1, 1]), f._ones(np.asarray([1, 2]), np.asarray([3,
                                                                     4])))
     with self.assertRaises(IndexError):
         f._ones(1, np.asarray([1, 2]))
     with self.assertRaises(IndexError):
         f._ones(np.asarray([1, 2]), np.asarray([3, 4, 5, 6]))