Пример #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_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)
Пример #3
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))
Пример #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__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]))
Пример #6
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)
Пример #7
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)
Пример #8
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)
Пример #9
0
 def setUp(self):
     self.fluid = BaseFluid(1, 2, 3, 4)