def create_acid_biorefinery(preprocessed):
    flowsheet = bst.Flowsheet('acid')
    bst.main_flowsheet.set_flowsheet(flowsheet)
    s = flowsheet.stream
    u = flowsheet.unit
    feedstock = preprocessed.copy('feedstock')
    feedstock.price = preprocessed.price
    get_feedstock_dry_mass = (lambda : (feedstock.F_mass - feedstock.imass['H2O']))
    get_flow_tpd = (lambda : (((feedstock.F_mass - feedstock.imass['H2O']) * 24) / _kg_per_ton))
    groups = []
    (flowsheet, groups) = create_acid_pretreatment_process(flowsheet, groups, feedstock, get_feedstock_dry_mass)
    (flowsheet, groups) = create_ethanol_process(flowsheet, groups, (u.P201 - 0))
    wwt_streams = ((u.H201 - 0), (u.D402_P - 0), (u.S401 - 1), '')
    (flowsheet, groups) = create_wastewater_process(flowsheet, groups, get_flow_tpd, wwt_streams, need_ammonia=False, bypass_R501=False, recover_sodium_sulfate=True)
    CHP_wastes = ((u.S401 - 0), (u.S504 - 1))
    CHP_biogas = (u.R501 - 0)
    CHP_side_streams = (s.water_M201, s.water_M202, s.steam_M203)
    process_water_streams = {'pretreatment': (s.water_M201, s.water_M202, s.steam_M203, s.water_M205), 'ethanol': (s.water_M301, s.water_U401)}
    recycled_water = (u.S505 - 0)
    (flowsheet, groups) = create_facilities(flowsheet, groups, get_flow_tpd, CHP_wastes, CHP_biogas, CHP_side_streams, process_water_streams, recycled_water, if_HXN=False, if_BDM=True)
    u.T603.outs[0] = s.sulfuric_acid_T201
    u.T604_S.outs[0] = s.ammonia_M205
    (flowsheet, teas, funcs) = create_biorefinery(flowsheet, groups, get_flow_tpd)
    return (flowsheet, groups, teas, funcs)
def create_acid_biorefinery(preprocessed):
    flowsheet = bst.Flowsheet('acid')
    bst.main_flowsheet.set_flowsheet(flowsheet)
    s = flowsheet.stream
    u = flowsheet.unit
    feedstock = preprocessed.copy('feedstock')
    feedstock.price = preprocessed.price
    get_feedstock_dry_mass = (lambda : (feedstock.F_mass - feedstock.imass['H2O']))
    get_flow_tpd = (lambda : (((feedstock.F_mass - feedstock.imass['H2O']) * 24) / _kg_per_ton))
    groups = []
    (flowsheet, groups) = create_acid_pretreatment_process(flowsheet, groups, feedstock, get_feedstock_dry_mass)
    (flowsheet, groups) = create_ethanol_process(flowsheet, groups, (u.P201 - 0))
    wwt_streams = ((u.H201 - 0), (u.D402_P - 0), (u.S401 - 1), )
    (flowsheet, groups) = create_wastewater_process(flowsheet, groups, get_flow_tpd, wwt_streams, need_ammonia=False, bypass_R501=False, recover_sodium_sulfate=True)
    CHP_wastes = ((u.S401 - 0), (u.S504 - 1))
    CHP_biogas = (u.R501 - 0)
    CHP_side_streams = (s.water_M201, s.water_M202, s.steam_M203)
    process_water_streams = {'pretreatment': (s.water_M201, s.water_M202, s.steam_M203, s.water_M205), 'ethanol': (s.water_M301, s.water_U401)}
    recycled_water = (u.S505 - 0)
    (flowsheet, groups) = create_facilities(flowsheet, groups, get_flow_tpd, CHP_wastes, CHP_biogas, CHP_side_streams, process_water_streams, recycled_water, if_HXN=False, if_BDM=True)
    u.T603.outs[0] = s.sulfuric_acid_T201
    u.T604_S.outs[0] = s.ammonia_M205
    (flowsheet, teas, funcs) = create_biorefinery(flowsheet, groups, get_flow_tpd)
    return (flowsheet, groups, teas, funcs)