示例#1
0
 def test_c_completeness(self):
     self.sys_pipe.name = 1
     node0 = ConnectionNode()
     node1 = ConnectionNode()
     self.sys_pipe.input_node = node0
     self.sys_pipe.output_node = node1
     self.sys_pipe.set_length(100, 'm')
     self.sys_pipe.set_inner_diam(10, 'in')
     self.assertFalse(self.sys_pipe.is_complete())
示例#2
0
 def test_repeated_output(self):
     output_node = ConnectionNode()
     other_node = ConnectionNode()
     self.sys_pipe.output_node = output_node
     fail = False
     try:
         self.sys_pipe.output_node = other_node
     except IndexError:
         fail = True
     self.assertTrue(fail)
示例#3
0
 def test_k_complete(self):
     in_node = ConnectionNode()
     out_node = EndNode()
     self.nozzle0.input_node = in_node
     self.nozzle0.output_node = out_node
     self.nozzle0.set_required_pressure(30, 'psi')
     self.assertFalse(self.nozzle0.is_complete())
示例#4
0
 def test_jacobian(self):
     self.sys_pipe.set_length(900, 'm')
     self.sys_pipe.set_inner_diam(7.981, 'in')
     self.sys_pipe.set_c_coefficient(100)
     node_i = ConnectionNode()
     node_i.set_energy(90.01, 'psi')
     node_o = ConnectionNode()
     node_o.set_energy(90, 'psi')
     self.sys_pipe.input_node = node_i
     self.sys_pipe.output_node = node_o
     result = 626.507748
     self.assertAlmostEqual(self.sys_pipe.get_node_jacobian(node_i), result,
                            5)
     self.assertAlmostEqual(self.sys_pipe.get_node_jacobian(node_o),
                            -result, 5)
示例#5
0
 def test_input(self):
     input_node = ConnectionNode()
     other_node = ConnectionNode()
     self.sys_pipe.input_node = input_node
     self.assertEqual(self.sys_pipe.input_node, input_node)
     input_node.set_output_pipe(self.sys_pipe)
     fail = False
     try:
         self.sys_pipe.input_node = other_node
     except IndexError:
         fail = True
     self.assertTrue(fail)
     self.assertTrue(self.sys_pipe in input_node.get_output_pipes())
 def test_input_node(self):
     other_node = ConnectionNode()
     self.eductor0.input_node = self.in_node
     self.assertEqual(self.eductor0.input_node, self.in_node)
     with self.assertRaises(IndexError):
         self.eductor0.input_node = other_node
 def test_fails_when_outlet_is_not_EductorOutlet(self):
     outlet = ConnectionNode()
     with self.assertRaises(TypeError):
         self.eductor0.output_node = outlet
 def test_fails_when_inlet_is_not_EductorInlet(self):
     inlet = ConnectionNode()
     with self.assertRaises(TypeError):
         self.eductor0.input_node = inlet
示例#9
0
 def test_output(self):
     output_node = ConnectionNode()
     self.sys_pipe.output_node = output_node
     self.assertEqual(self.sys_pipe.output_node, output_node)
     output_node.set_input_pipe(self.sys_pipe)
     self.assertTrue(self.sys_pipe in output_node.get_input_pipes())
示例#10
0
 def test_when_second_input_set_fails(self):
     in_node = ConnectionNode()
     self.pump.input_node = in_node
     other_node = ConnectionNode()
     with self.assertRaises(IndexError):
         self.pump.input_node = other_node
示例#11
0
class NozzleTests(unittest.TestCase):
    def setUp(self):
        self.nozzle0 = Nozzle()
        self.in_node = ConnectionNode()
        self.out_node = EndNode()

    def test_creation(self):
        self.assertTrue(isinstance(self.nozzle0, Nozzle))
        self.assertTrue(isinstance(self.nozzle0, Edge))

    def test_name(self):
        self.nozzle0.name = 3
        self.assertEqual(self.nozzle0.name, '3')

    def test_input_node(self):
        other_node = ConnectionNode()
        self.nozzle0.input_node = self.in_node
        self.assertEqual(self.nozzle0.input_node, self.in_node)
        with self.assertRaises(IndexError):
            self.nozzle0.input_node = other_node

    def test_false_input(self):
        false_input = 'false node'
        with self.assertRaises(ValueError):
            self.nozzle0.input_node = false_input

    def test_output(self):
        self.nozzle0.output_node = self.out_node
        self.assertEqual(self.nozzle0.output_node, self.out_node)

    def test_end_output(self):
        with self.assertRaises(ValueError):
            self.nozzle0.output_node = self.in_node

    def test_repeated_output(self):
        other_node = EndNode()
        self.nozzle0.output_node = self.out_node
        with self.assertRaises(ValueError):
            self.nozzle0.output_node = other_node

    def test_k_factor(self):
        self.nozzle0.set_factor(1.2, 'gpm/psi^0.5')
        k_lpm = self.nozzle0.get_factor('lpm/bar^0.5')
        self.assertAlmostEqual(k_lpm, 17.29954989, 5)
        self.nozzle0.set_factor(17.29954989, 'lpm/bar^0.5')
        self.assertAlmostEqual(self.nozzle0.get_factor('gpm/psi^0.5'), 1.2)

    def test_gpm_flow(self):
        self.nozzle0.set_factor(2, 'gpm/psi^0.5')
        self.in_node.set_elevation(5, 'm')
        self.in_node.set_pressure(36, 'psi')
        self.out_node.set_elevation(5, 'm')
        self.nozzle0.input_node = self.in_node
        self.nozzle0.output_node = self.out_node
        nozzle_flow = self.nozzle0.calculate_gpm_flow()
        self.assertAlmostEqual(nozzle_flow, 12)

    def test_required_pressure(self):
        self.nozzle0.set_required_pressure(30, 'psi')
        self.assertEqual(self.nozzle0.get_required_pressure('psi'), 30)

    def test_complete_nozzle(self):
        self.nozzle0.input_node = self.in_node
        self.nozzle0.output_node = self.out_node
        self.nozzle0.set_required_pressure(30, 'psi')
        self.nozzle0.set_factor(1.2, 'gpm/psi^0.5')
        self.assertTrue(self.nozzle0.is_complete())

    def test_k_complete(self):
        in_node = ConnectionNode()
        out_node = EndNode()
        self.nozzle0.input_node = in_node
        self.nozzle0.output_node = out_node
        self.nozzle0.set_required_pressure(30, 'psi')
        self.assertFalse(self.nozzle0.is_complete())
示例#12
0
 def test_pipe_zero_energy_flow(self):
     node0 = ConnectionNode()
     node1 = ConnectionNode()
     node0.set_elevation(10, 'm')
     node1.set_elevation(10, 'm')
     node1.set_pressure(10, 'psi')
     node0.set_pressure(10, 'psi')
     self.sys_pipe.output_node = node1
     self.sys_pipe.input_node = node0
     self.sys_pipe.set_c_coefficient(100)
     self.sys_pipe.set_length(100, 'm')
     self.sys_pipe.set_inner_diam(10.75, 'in')
     self.sys_pipe.calculate_gpm_flow()
     self.assertAlmostEqual(self.sys_pipe.get_vol_flow('gpm'), 0, 5)
示例#13
0
 def test_pipe_negative_energy_flow(self):
     node0 = ConnectionNode()
     node1 = ConnectionNode()
     node0.set_elevation(10, 'm')
     node1.set_elevation(10, 'm')
     node1.set_pressure(11.26528826, 'psi')
     node0.set_pressure(10, 'psi')
     self.sys_pipe.output_node = node1
     self.sys_pipe.input_node = node0
     self.sys_pipe.set_c_coefficient(100)
     self.sys_pipe.set_length(100, 'm')
     self.sys_pipe.set_inner_diam(10.75, 'in')
     self.sys_pipe.calculate_gpm_flow()
     self.assertClose(self.sys_pipe.get_vol_flow('gpm'), -1135.4647, 5)
示例#14
0
class NodeTests(unittest.TestCase):
    def setUp(self):
        self.sys_node = ConnectionNode()

    def test_creation(self):
        self.assertTrue(isinstance(self.sys_node, ConnectionNode))

    def test_pressure(self):
        self.sys_node.set_pressure(8, "psi")
        self.assertEqual(self.sys_node.get_pressure("psi"), 8)
        self.assertAlmostEqual(self.sys_node.get_pressure("Pa"), 8 * 6894.757)
        self.assertAlmostEqual(self.sys_node.get_pressure('kPa'), 8 * 6.894757)
        self.assertAlmostEqual(self.sys_node.get_pressure('mH2O'), 5.625996944)
        self.sys_node.set_pressure(40000, 'Pa')
        self.assertAlmostEqual(self.sys_node.get_pressure('psi'),
                               5.80150975589)
        self.sys_node.set_pressure(100, 'mH2O')
        self.assertAlmostEqual(self.sys_node.get_pressure('kPa'), 980.638)
        self.sys_node.set_pressure(15, 'psi')

    def test_elevation(self):
        self.sys_node.set_elevation(8, 'm')
        self.assertEqual(self.sys_node.get_elevation('m'), 8)
        elevation = self.sys_node.get_elevation('ft')
        self.assertAlmostEqual(elevation, 8 * 3.28083989)

    def test_when_elevation_and_pressure_set_get_energy(self):
        self.sys_node.set_elevation(20, 'm')
        self.sys_node.set_pressure(20, 'mH2O')
        self.assertEqual(self.sys_node.get_energy('mH2O'), 40)
        self.sys_node.set_pressure(15, 'psi')
        self.assertAlmostEqual(self.sys_node.get_energy('psi'), 43.439404)

    def test_name(self):
        self.sys_node.name = 1
        self.assertEqual(self.sys_node.name, '1')

    def test_when_elevation_and_energy_set_get_pressure(self):
        self.sys_node.set_elevation(20, 'm')
        self.sys_node.set_energy(35, 'mH2O')
        self.assertEqual(self.sys_node.get_pressure('mH2O'), 15)
        self.sys_node.set_pressure(10, 'mH2O')
        self.assertEqual(self.sys_node.get_energy('mH2O'), 30)

    def test_input_pipe(self):
        sys_pipe = Pipe()
        sys_pipe2 = Pipe()
        self.sys_node.set_input_pipe(sys_pipe)
        self.sys_node.set_input_pipe(sys_pipe2)
        self.assertTrue(sys_pipe in self.sys_node.get_input_pipes())
        self.assertTrue(sys_pipe2 in self.sys_node.get_input_pipes())

    def test_output_pipe(self):
        sys_pipe = Pipe()
        self.sys_node.set_output_pipe(sys_pipe)
        self.assertTrue(sys_pipe in self.sys_node.get_output_pipes())

    def test_end_node_energy(self):
        node = EndNode()
        node.set_elevation(10, 'm')
        self.assertEqual(node.get_energy('mH2O'), 10)
        self.assertAlmostEqual(node.get_energy('psi'), 14.219702)

    def test_initial_flow_output(self):
        self.assertEqual(self.sys_node.get_output_flow('gpm'), 0)

    def test_flow_output(self):
        self.sys_node.set_output_flow(20, 'gpm')
        self.assertEqual(self.sys_node.get_output_flow('gpm'), 20)
        self.assertAlmostEqual(self.sys_node.get_output_flow('m3/H'), 4.5425,
                               4)

    def test_input_node_is_connection_node(self):
        in_node = InputNode()
        self.assertTrue(isinstance(in_node, ConnectionNode))
示例#15
0
 def setUp(self):
     self.nozzle0 = Nozzle()
     self.in_node = ConnectionNode()
     self.out_node = EndNode()
示例#16
0
 def setUp(self):
     self.sys_node = ConnectionNode()
示例#17
0
 def test_input_node_set_then_input_node_retrieved(self):
     in_node = ConnectionNode()
     self.pump.input_node = in_node
     self.assertEqual(self.pump.input_node, in_node)