added a CLI option to adjust output verbosity

This commit is contained in:
ignis 2021-11-30 10:52:30 +09:00
parent 7a7a69fe1f
commit cffbff559f

35
coal.py
View file

@ -1,15 +1,25 @@
from functools import reduce
import argparse
import logging
import cantera as ct
import argparse
logger = logging.getLogger()
stream_handler = logging.StreamHandler()
logger.addHandler(stream_handler)
parser = argparse.ArgumentParser(description='Calculate Thermodynamic States of the Coal fired Boiler')
parser.add_argument('--hhv', action='store_true', help='Higher heating value is used')
parser.add_argument('-v', '--verbose', action='store_true', help='Verbose output')
args = parser.parse_args()
is_HHV = vars(args)['hhv']
is_verbose = vars(args)['verbose']
if is_verbose:
logger.setLevel(logging.INFO)
else:
logger.setLevel(logging.WARNING)
stdT = 298.15 # Temperature at standard state, K
@ -72,7 +82,7 @@ airs = [
]
for i, air in enumerate(airs):
print("air {}, T = {}, mass flow rate = {}".format(i+1, air.T, air.mass))
logger.info("air {}, T = {}, mass flow rate = {}".format(i+1, air.T, air.mass))
airmix = reduce(lambda a, b: a+b, airs)
print("Total Air flow rate = ", airmix.mass)
@ -128,18 +138,19 @@ Discrepency in Enthalpy of Formation for H2O is due to phase difference
value above is for vapor and otherwise is for liquid water
'''
print(hf_product_coefs("CO2", "C"))
print(hf_product_coefs("H2O", "H"))
print(hf_product_coefs("SO2", "S"))
logger.info("hf(CO2) / W(C) = {}".format(hf_product_coefs("CO2", "C")))
logger.info("hf(H2O) / W(H) = {}".format(hf_product_coefs("H2O", "H")))
logger.info("hf(SO2) / W(S) = {}".format(hf_product_coefs("SO2", "S")))
sum_product_hf = (
hf_product_coefs("CO2", "C") * coal.elemental_mass_fraction('C')
+ hf_product_coefs("H2O", "H") * coal.elemental_mass_fraction('H')
+ hf_product_coefs("SO2", "S") * coal.elemental_mass_fraction('S'))
print("Sum(Hf_product), kJ/kg = ", sum_product_hf)
sum_coal_hf = - coalHV + sum_product_hf
print("Sum(Hf_reactant), kJ/kg = ", sum_coal_hf)
logger.info("Sum(Hf_product), kJ/kg = {}".format(sum_product_hf))
logger.info("Sum(Hf_reactant), kJ/kg = {}".format(sum_coal_hf))
"""#############################################################################
@ -150,11 +161,11 @@ Coal Enthalpy at 348.15 K = \Delta H_f + (H(348.15) - H(298.15))
gr = ct.Solution('graphite.cti')
gr.TP = coalT, ct.one_atm
coal_preheat_enthalpy = gr.enthalpy_mass / 1000. # kJ/kg
print("Coal preheat H , kJ/kg = ", coal_preheat_enthalpy)
coal_enthalpy = sum_coal_hf + coal_preheat_enthalpy
print("Coal enthalpy , kJ/kg = ", coal_enthalpy)
print("Dummy Coal H , kJ/kg = ", coal.enthalpy_mass/1000.)
logger.info("Coal preheat H , kJ/kg = ", coal_preheat_enthalpy)
logger.info("Coal enthalpy , kJ/kg = ", coal_enthalpy)
logger.info("Dummy Coal H , kJ/kg = ", coal.enthalpy_mass/1000.)
"""#############################################################################
@ -165,7 +176,7 @@ Therefore only difference between real coal enthalpy and dummy gas coal is
#############################################################################"""
enthalpy_added_after_mixing = (coal_enthalpy*1000 - coal.enthalpy_mass) * fuelMfr # J
print("enthalpy to add later = ", enthalpy_added_after_mixing)
logger.info("enthalpy to add later = ", enthalpy_added_after_mixing)
################################################################################