diff --git a/docs/whats_new/v0-3-5.rst b/docs/whats_new/v0-3-5.rst index 8492b9308..9f08b8105 100644 --- a/docs/whats_new/v0-3-5.rst +++ b/docs/whats_new/v0-3-5.rst @@ -56,8 +56,7 @@ API Changes New Features ############ - Add methods for exergy and entropy analyses of networks. - Examples will follow (`PR #215 `_), - + Examples will follow (`PR #215 `_). - Add a method :code:`get_plotting_data` to each component to export the input data required by FluProDia in order to generate the data required to display state changes in the components in a fluid property diagram. Each component @@ -91,7 +90,6 @@ New Features For more information see the respective :ref:`documentation section ` (`PR #234 `_). - - Add a flag to deactivate calculation of all component equations in every iteration. This improves stability in some cases but may reduce calculation speed (`PR #226 `_). To deactivate @@ -101,7 +99,6 @@ New Features .. code-block:: python mynetwork.solve('design', always_all_equations=False) - - Add a flag use cuda instead of numpy for matrix inversion. With cuda matrix inversion is outsourced to the graphics card. Using cuda additionally requires :code:`cupy` installed on your machine @@ -166,7 +163,6 @@ Other Changes - An error message is raised in case the user specifies a fluid vector containing fluids, that are not part of the network's fluid list (`PR #233 `_). - - For improved convergence stability of the methods :py:meth:`tespy.components.heat_exchangers.heat_exchanger_simple.HeatExchangerSimple.kA_func` and :py:meth:`tespy.components.heat_exchangers.heat_exchanger_simple.HeatExchangerSimple.kA_char_func`, @@ -174,6 +170,9 @@ Other Changes temperature difference between ambient and inlet and outlet temperature, if the terminal temperature differences do not have the same sign (`PR #225 `_). +- An understandable error message is raised in case the user misses out on + fluids required by components of class CombustionChamber or CombustionEngine + (`PR #242 `_). Contributors ############ diff --git a/src/tespy/components/combustion/combustion_chamber.py b/src/tespy/components/combustion/combustion_chamber.py index f1f61d220..e44782141 100644 --- a/src/tespy/components/combustion/combustion_chamber.py +++ b/src/tespy/components/combustion/combustion_chamber.py @@ -222,14 +222,23 @@ def setup_reaction_parameters(self): self.component() + ' are: ' + str(self.fuel_list) + '.') logging.debug(msg) - self.o2 = [x for x in self.nw_fluids if x in [ - a.replace(' ', '') for a in CP.get_aliases('O2')]][0] - self.co2 = [x for x in self.nw_fluids if x in [ - a.replace(' ', '') for a in CP.get_aliases('CO2')]][0] - self.h2o = [x for x in self.nw_fluids if x in [ - a.replace(' ', '') for a in CP.get_aliases('H2O')]][0] - self.n2 = [x for x in self.nw_fluids if x in [ - a.replace(' ', '') for a in CP.get_aliases('N2')]][0] + for fluid in ['o2', 'co2', 'h2o', 'n2']: + try: + setattr( + self, fluid, [x for x in self.nw_fluids if x in [ + a.replace(' ', '') for a in + CP.get_aliases(fluid.upper()) + ]][0]) + except IndexError: + msg = ( + 'The component ' + self.label + ' (class ' + + self.__class__.__name__ + ') requires that the fluid ' + '[fluid] is in the network\'s list of fluids.') + aliases = ', '.join(CP.get_aliases(fluid.upper())) + msg = msg.replace( + '[fluid]', fluid.upper() + ' (aliases: ' + aliases + ')') + logging.error(msg) + raise TESPyComponentError(msg) self.fuels = {} for f in self.fuel_list: diff --git a/tests/test_errors.py b/tests/test_errors.py index 3131752d3..933851a4e 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -254,6 +254,18 @@ def test_CombustionChamber_missing_fuel(): with raises(TESPyComponentError): nw.solve('design', init_only=True) + +def test_CombustionChamber_missing_oxygen(): + """Test no fuel in network.""" + nw = Network(['H2O', 'N2', 'Ar', 'CO2', 'CH4']) + instance = CombustionChamber('combustion chamber') + c1 = Connection(Source('air'), 'out1', instance, 'in1') + c2 = Connection(Source('fuel'), 'out1', instance, 'in2') + c3 = Connection(instance, 'out1', Sink('flue gas'), 'in1') + nw.add_conns(c1, c2, c3) + with raises(TESPyComponentError): + nw.solve('design', init_only=True) + ############################################################################## # CombustionChamberStoich