def tractor_fueling(Days, Hours, Frequence, Ext_T): """ Generate a fueling profile based on annual diesel consumption, weather and fueling time. The fueling takes place from 18:00 to 04:00. Check that the sum of the fueling profile equals annual consumption and cause an error if not. """ Daily_avg_T = np.mean(Ext_T, axis=1) Fueling_days = np.sum(Frequence[Daily_avg_T > P['Farm', 'Temp_tractors']]) meta = ['kW/year', 'Fuel consumed by tractors in a year', 'calc'] Fuel_cons = P['Farm', 'cons_Diesel_annual'] * P['Physical', 'Diesel_LHV'] data.make_param('Farm', 'Fuel_cons', Fuel_cons, meta) meta = ['kW', 'Fuel consumed by tractors during fueling', 'calc'] Fueling_load = Fuel_cons / (Fueling_days * P['GFS', 'Fueling_Time']) data.make_param('Farm', 'Fueling_load', Fueling_load, meta) Fueling_day = np.zeros(len(Hours)) Fueling_day[18:] = Fueling_load Fueling_day[:P['GFS', 'Fueling_Time'] - 6] = Fueling_load Fueling_profile = [ Fueling_day if Daily_avg_T[d] > P['Farm', 'Temp_tractors'] else np.zeros(len(Hours)) for d in Days ] if np.round(np.sum(Fueling_profile * Frequence[:, None])) == Fuel_cons: return Fueling_profile else: print( 'Error: The fueling profile does not match annual fuel consumption' )
def building_gains(): """ Building gains based on building parameters and weather """ c = 'build' meta = ['kW/m^2', 'Heat gains from people', 5] Gains_ppl = annual_to_daily(P[c, 'Gains_ppl_annual'], Occupation) make_param(c, 'Gains_ppl', 'inputs.h5', meta) meta = ['kW/m^2', 'Heat gains from appliances', 7] Gains_elec = (P[c, 'Elec_heat_frac'] * Elec_cons / P['build', 'Heated_area']) make_param(c, 'Gains_elec', 'inputs.h5', meta) meta = ['kW/m^2', 'Heat gains from irradiation', 9] Gains_solar = P[c, 'Absorptance'] * Irradiance make_param(c, 'Gains_solar', 'inputs.h5', meta) meta = ['kW/m^2', 'Sum of all heat gains', 10] Gains = Gains_ppl + Gains_elec + Gains_solar make_param(c, 'Gains', 'inputs.h5', meta) # N.B. Equivalent to: # Gains = np.zeros((len(Days), len(Hours))) # for d in Days: # Gains[d] = Gains_ppl + Gains_elec + Gains_solar[d] # C_meta['Gains_ppl'] = ['Building people gains', 4, 'P'] # C_meta['Gains_elec'] = ['Building electric gains', 3, 'P'] # C_meta['Gains_solar'] = ['Building solar gains', 3, 'P'] # C_meta['Gains'] = ['Sum of all building heating gains', 3, 'P'] return Gains
def ad_sizing(): """ Calculates the maxium size of the AD and its dimentions relative to the avilable manure. """ meta = {} c = 'AD' name = 'Capacity' meta[name] = ['kW', 'Rated Biogas production capacity', 'calc'] P[c, name] = np.round(P['Farm', 'Biomass_prod'] * P[c, 'Eff'], 2) name = 'Sludge_volume' meta[name] = ['m^3', 'Sludge volume capacity', 'calc'] P[c, name] = np.ceil(P[c, 'Residence_time'] * P['AD', 'LSU'] * P['AD', 'Manure_per_cattle'] / (1 - P[c, 'Biomass_water']) / 1000) name = 'Cyl_volume' meta[name] = ['m^3', 'Cylinder volume', 'calc'] P[c, name] = np.ceil(P[c, 'Sludge_volume'] / P[c, 'Cyl_fill']) name = 'Cap_height' meta[name] = ['m', 'Height of the AD top cap', 'calc'] P[c, name] = np.round( (P[c, 'Sludge_volume'] * P[c, 'Cap_V_ratio'] * (6 / np.pi) / (3 * P[c, 'Cap_h_ratio']**2 + 1))**(1 / 3), 2) name = 'Diameter' meta[name] = ['m', 'Diameter of the AD cylindrical body', 'calc'] P[c, name] = np.round(P[c, 'Cap_h_ratio'] * P[c, 'Cap_height'] * 2, 2) name = 'Ground_area' meta[name] = ['m^2', 'Ground floor area', 'calc'] P[c, name] = np.round(np.pi * (P[c, 'Diameter'] / 2)**2, 2) name = 'Cap_area' meta[name] = ['m^2', 'Surface area of the AD top cap', 'calc'] P[c, name] = np.round( np.pi * (P[c, 'Cap_height']**2 + (P[c, 'Diameter'] / 2)**2), 2) name = 'Cyl_height' meta[name] = ['m', 'Height of the AD cylindrical body', 'calc'] P[c, name] = np.round( P[c, 'Cyl_volume'] / (np.pi * (P[c, 'Diameter'] / 2)**2), 2) make_param('AD', list(meta.keys()), P, meta)
def ad_gains(T_min): """ Calculates the gains of the AD based on AD size and weather. Concerning solar gains: Since the cover surface is the same outside and inside (the temperature is hotter inside but close) the heat absorbed by the cover is considered to be emitted equally to the outside and inside. """ meta = {} c, p = 'AD', 'Physical' n = 'U' meta[n] = ['kW/C', 'AD heat conductance', 'calc'] P[c, n] = P[c, 'Cap_area'] * P[c, 'U_cap'] n = 'C' meta[n] = ['kWh/C', 'Heat capacity of the AD', 'calc'] P[c, n] = (P[p, 'Cp_water'] * P[c, 'Sludge_volume'] + P['build', 'C_b'] * P[c, 'Ground_area']) C_meta['Gains_solar_AD'] = ['Heat gains from irradiation', 0, 'P'] metadata = ['kW', 'Heat gains from irradiation', 'calc'] Gains_solar = P[c, 'Cap_abs'] * P[c, 'Ground_area'] * Irradiance / 2 make_param(c, 'Gains_solar', 'inputs.h5', metadata) C_meta['Losses_biomass'] = [ 'Heat losses due to cold biomass input', 0, 'P' ] metadata = ['kW', 'Heat gains from irradiation', 'calc'] Losses_biomass = ((P['Farm', 'Biomass_prod'] / (P[c, 'Manure_HHV_dry'] * (1 - P[c, 'Biomass_water']))) * (P[p, 'Cp_water'] / 1000) * (T_min - Ext_T)) make_param(c, 'Losses_biomass', 'inputs.h5', metadata) n = 'Losses_ground' meta[n] = ['kW', 'Heat gains from irradiation', 'calc'] P[c, n] = P[c, 'Ground_losses'] * P[c, 'Ground_area'] n = 'Gains_elec' meta[n] = ['kW', 'Heat gains from electricity consumption', 'calc'] P[c, n] = P[c, 'Capacity'] * P[c, 'Elec_cons'] metadata = ['kW/m^2', 'Sum of all heat gains and losses', 0] C_meta['Gains_AD'] = ['Sum of all AD heating gains and losses', 0, 'P'] Gains = Gains_solar + ( np.ones(np.shape(Ext_T)) * (P[c, 'Gains_elec'] - P[c, 'Losses_ground'] - Losses_biomass)) make_param(c, 'Gains', 'inputs.h5', metadata) make_param('AD', list(meta.keys()), P, meta) return Gains
def biomass_prod(file): """ Given an number of cows and pigs, calculate: 1. The biomass potential in kW 2. The CO2 from untreated manure """ A, A_meta = data.get_param(file) # Set of all animals animals = set(A.index.get_level_values(0)) meta = ['kW', 'Methane yield from animals', 'calc'] C_meta['Biogas_prod'] = ['Methane potential relative to animals', 13] Biogas_prod = sum( (A[a, 'Nbr_at_farm'] / A[a, 'LSU']) * A[a, 'Methane_yield'] for a in animals) / P['Physical', 'Hours_per_year'] data.make_param('Farm', 'Biogas_prod', Biogas_prod, meta) meta = ['kW', 'Biomass yield from animals', 'calc'] C_meta['Biomass_prod'] = ['Biomass potential relative to AD eff', 13] Biomass_prod = Biogas_prod / P['AD', 'Eff'] data.make_param('Farm', 'Biomass_prod', Biomass_prod, meta) meta = ['kt-CO2/year', 'Emissions from untreated manure', 'calc'] C_meta['Biomass_emissions'] = [ 'Tonne of manure times emissions for one tonne of pig manure', 1, 'P' ] Biomass_emissions = 1e-6 * sum( (A[a, 'Nbr_at_farm'] / A[a, 'LSU']) * A[a, 'Manure'] for a in animals) * P['Physical', 'Manure_emissions'] data.make_param('Farm', 'Biomass_emissions', Biomass_emissions, meta)