def test_network_missing_data_in_individual_design_case_file(): """ Test for missing data in individual design case files. """ nw = network(['water']) source = basics.source('source') pipe = piping.pipe('pipe', Q=0, pr=0.95, design=['pr'], offdesign=['zeta']) sink = basics.sink('sink') a = connection(source, 'out1', pipe, 'in1', m=1, p=1e5, T=293.15, fluid={'water': 1}) b = connection(pipe, 'out1', sink, 'in1', design_path='tmp2') nw.add_conns(a, b) nw.solve('design') nw.save('tmp') nw.save('tmp2') inputs = open('./tmp/conn.csv') all_lines = inputs.readlines() all_lines.pop(len(all_lines) - 1) inputs.close() with open('./tmp2/conn.csv', 'w') as out: for line in all_lines: out.write(line.strip() + '\n') offdesign_TESPyNetworkError(nw, design_path='tmp', init_only=True) shutil.rmtree('./tmp', ignore_errors=True) shutil.rmtree('./tmp2', ignore_errors=True)
def setup(self): self.nw = network(['water', 'air']) self.comp = combustion.combustion_engine('combustion engine') self.pipe = piping.pipe('pipe') self.conn = connection(self.comp, 'out1', self.pipe, 'in1') self.bus = bus('mybus') self.sub = subsystems.subsystem('MySub')
def test_network_missing_data_in_design_case_files(self): """Test for missing data in design case files.""" self.setup_network_tests() pipe = piping.pipe('pipe', Q=0, pr=0.95, design=['pr'], offdesign=['zeta']) a = connection(self.source, 'out1', pipe, 'in1', m=1, p=1, T=293.15, fluid={'water': 1}) b = connection(pipe, 'out1', self.sink, 'in1') self.nw.add_conns(a, b) self.nw.solve('design') self.nw.save('tmp') self.nw.save('tmp2') inputs = open('./tmp/connections.csv') all_lines = inputs.readlines() all_lines.pop(len(all_lines) - 1) inputs.close() with open('./tmp2/connections.csv', 'w') as out: for line in all_lines: out.write(line.strip() + '\n') self.offdesign_TESPyNetworkError(design_path='tmp2', init_only=True) shutil.rmtree('./tmp', ignore_errors=True) shutil.rmtree('./tmp2', ignore_errors=True)
def test_ref_creation_error(): """Test errors creating reference objects.""" comb = combustion.combustion_engine('combustion engine') pipeline = piping.pipe('pipeline') conn = connection(comb, 'out1', pipeline, 'in1') create_ref_TypeError([conn, 7, 'hi']) create_ref_TypeError([conn, 'hi', 0]) create_ref_TypeError([comb, 1, 0])
def test_set_attr_errors(): """Test errors of set_attr methods.""" nw = network(['water', 'air']) comb = combustion.combustion_engine('combustion engine') pipeline = piping.pipe('pipeline') conn = connection(comb, 'out1', pipeline, 'in1') mybus = bus('mybus') # ValueErrors set_attr_ValueError(comb, offdesign=['Q']) set_attr_ValueError(conn, offdesign=['f']) set_attr_ValueError(nw, m_unit='kg') set_attr_ValueError(nw, h_unit='kg') set_attr_ValueError(nw, p_unit='kg') set_attr_ValueError(nw, T_unit='kg') set_attr_ValueError(nw, v_unit='kg') set_attr_ValueError(conn, state=5) # TypeErrors set_attr_TypeError(comb, P=[5]) set_attr_TypeError(comb, tiP_char=7) set_attr_TypeError(comb, design='f') set_attr_TypeError(comb, lamb=dc_cc()) set_attr_TypeError(comb, design_path=7) set_attr_TypeError(comb, local_design=5) set_attr_TypeError(comb, local_offdesign=5) set_attr_TypeError(pipeline, hydro_group=5) set_attr_TypeError(comb, printout=5) set_attr_TypeError(conn, design='h') set_attr_TypeError(conn, fluid_balance=1) set_attr_TypeError(conn, h0=[4]) set_attr_TypeError(conn, fluid=5) set_attr_TypeError(conn, design_path=5) set_attr_TypeError(conn, local_design=5) set_attr_TypeError(conn, local_offdesign=5) set_attr_TypeError(conn, printout=5) set_attr_TypeError(conn, label=5) set_attr_TypeError(conn, state='f') set_attr_TypeError(nw, m_range=5) set_attr_TypeError(nw, p_range=5) set_attr_TypeError(nw, h_range=5) set_attr_TypeError(nw, iterinfo=5) set_attr_TypeError(mybus, P='some value') set_attr_TypeError(mybus, printout=5) # KeyErrors set_attr_KeyError(dc_cc(), x=7) set_attr_KeyError(comb, wow=5) set_attr_KeyError(conn, jey=5) set_attr_KeyError(mybus, power_output=100000) # NotImplementedError set_attr_NotImplementedError(conn, Td_bp=ref(conn, 1, 0))
def test_connection_creation_ValueError(): """Test ValueErrors creating connections.""" comb = combustion.combustion_engine('combustion engine') pipeline = piping.pipe('pipeline') with raises(ValueError): connection(comb, 'out6', pipeline, 'in1') with raises(ValueError): connection(comb, 'out1', pipeline, 'in5')
def test_network_max_iter(self): """Test reaching maximum iteration count.""" self.setup_network_tests() pipe = piping.pipe('pipe', pr=1, Q=100e3) a = connection(self.source, 'out1', pipe, 'in1', m=1, p=1, T=280, fluid={'water': 1}) b = connection(pipe, 'out1', self.sink, 'in1') self.nw.add_conns(a, b) self.nw.solve('design', max_iter=2) msg = ('This test must result in the itercount being equal to the max ' 'iter statement.') assert self.nw.max_iter == self.nw.iter + 1, msg
def test_network_no_progress(self): """Test no convergence progress.""" self.setup_network_tests() pipe = piping.pipe('pipe', pr=1, Q=-100e3) a = connection(self.source, 'out1', pipe, 'in1', m=1, p=1, T=280, fluid={'water': 1}) b = connection(pipe, 'out1', self.sink, 'in1') self.nw.add_conns(a, b) self.nw.solve('design') msg = ('This test must result in a calculation making no progress, as ' 'the pipe\'s outlet enthalpy is below fluid property range.') assert self.nw.progress is False, msg
def test_network_max_iter(): nw = network(['water']) source = basics.source('source') pipe = piping.pipe('pipe', pr=1, Q=100e3) sink = basics.sink('sink') a = connection(source, 'out1', pipe, 'in1', m=1, p=1e5, T=280, fluid={'water': 1}) b = connection(pipe, 'out1', sink, 'in1') nw.add_conns(a, b) nw.solve('design', max_iter=2) msg = ('This test must result in the itercount being equal to the max ' 'iter statement.') eq_(nw.max_iter, nw.iter + 1, msg)
def test_network_no_progress(): nw = network(['water']) source = basics.source('source') pipe = piping.pipe('pipe', pr=1, Q=-100e3) sink = basics.sink('sink') a = connection(source, 'out1', pipe, 'in1', m=1, p=1e5, T=280, fluid={'water': 1}) b = connection(pipe, 'out1', sink, 'in1') nw.add_conns(a, b) nw.solve('design') msg = ('This test must result in a calculation making no progress, as the ' 'pipe\'s outlet enthalpy is below fluid property range.') eq_(nw.progress, False, msg)
def test_bus_add_comps_errors(): """Test errors adding components to busses.""" mybus = bus('mybus') comb = combustion.combustion_engine('combustion engine') pipeline = piping.pipe('pipeline') conn = connection(comb, 'out1', pipeline, 'in1') bus_add_comps_TypeError(mybus, {'comp': conn}) bus_add_comps_TypeError(mybus, {'f': comb}) bus_add_comps_TypeError(mybus, {'comp': comb, 'char': 'Hi'}) bus_add_comps_TypeError(mybus, {'comp': comb, 'param': 5}) bus_add_comps_TypeError(mybus, {'comp': comb, 'P_ref': 'what'}) bus_add_comps_TypeError(mybus, comb) with raises(ValueError): mybus.add_comps({'comp': comb, 'base': 5})
def test_get_attr_errors(): """Test errors of get_attr methods.""" nw = network(['water', 'air']) comb = combustion.combustion_engine('combustion engine') pipeline = piping.pipe('pipeline') conn = connection(comb, 'out1', pipeline, 'in1') mybus = bus('mybus') sub = subsystems.subsystem('MySub') get_attr_KeyError(comb, 'wow') get_attr_KeyError(conn, 'key') get_attr_KeyError(mybus, 'components') get_attr_KeyError(nw, 'missing') get_attr_KeyError(ref(conn, 1, 0), 'comp') get_attr_KeyError(sub, 'test') get_attr_KeyError(char_line(), 'test') get_attr_KeyError(data_container(), 'somekey') get_attr_KeyError(char_map(), 'Stuff')
def test_pipe(self): """ Test component properties of pipe. """ instance = pipe('pipe') self.setup_piping_network(instance)