示例#1
0
def test_teaser_four_element():
    from modesto.LTIModels.RCmodels import TeaserFourElement
    import pandas as pd

    start_time = pd.Timestamp('20140101')
    time_step = 3600
    n_steps = 24
    horizon = n_steps * time_step

    RCmodel = TeaserFourElement('test', False)

    time_index = pd.DatetimeIndex(start=start_time,
                                  freq=str(time_step) + 'S',
                                  periods=n_steps)
    min_temp_room = pd.Series(16 + 273.15, index=time_index)
    max_temp_room = pd.Series(24 + 273.15, index=time_index)

    datapath = resource_filename('modesto', 'Data')
    c_f = ut.read_time_data(
        path=datapath,
        name='ElectricityPrices/DAM_electricity_prices-2014_BE.csv'
    )['price_BE']

    params = {
        'neighbName': 'OudWinterslag',
        'streetName': 'Gierenshof',
        'buildingName': 'Gierenshof_22_1589272',
        'day_min_temperature': min_temp_room,
        'day_max_temperature': max_temp_room,
        'delta_T': 20,
        'mult': 100,
        'horizon': horizon,
        'time_step': 100,
        'horizon': 1000
    }

    for param in params:
        RCmodel.change_param(param, params[param])

    try:
        RCmodel.compile(start_time='20140201', model=ConcreteModel())
        return True
    except ValueError:
        return False
示例#2
0
    model, optimizers = representative(duration_repr=duration_repr,
                                       selection=selection,
                                       VWat=75000,
                                       solArea=150000,
                                       VSTC=100000,
                                       time_step=time_step)
    solve_repr(model, probe=False, solver='gurobi')

    # ## Post-processing

    # In[ ]:

    import matplotlib.pyplot as plt
    import numpy as np

    t_amb = ut.read_time_data(DATAPATH, name='Weather/extT.csv', expand=True)

    cmap = plt.get_cmap('gnuplot')
    colors = [cmap(i) for i in np.linspace(0, 1, len(selection))]

    coli = 0

    fig, (ax1, ax2, ax3) = plt.subplots(3, 1, sharex=True)
    for startday, reps in selection.items():
        res = sum(
            optimizers[startday].get_result(
                'heat_flow', node=node, comp='tank', check_results=False)
            for node in ['SolarArray', 'WaterscheiGarden', 'TermienWest'])
        ax1.plot(res,
                 color=colors[coli],
                 label='S {} R {}'.format(startday, reps))
示例#3
0
def setup_modesto(time_step=3600, n_steps=24 * 365, repr=False):
    repr_days = get_json(
        resource_filename(
            'TimeSliceSelection',
            '../Scripts/NoSeasons/ordered_solutions1_20bins_new.txt'),
        'repr_days')

    model = Modesto(pipe_model='ExtensivePipe',
                    graph=setup_graph(repr),
                    repr_days=repr_days[16] if repr else None)
    heat_demand = ut.read_time_data(resource_filename('modesto',
                                                      'Data/HeatDemand'),
                                    name='SH_GenkNet.csv')
    weather_data = ut.read_time_data(resource_filename('modesto',
                                                       'Data/Weather'),
                                     name='weatherData.csv')

    model.opt_settings(allow_flow_reversal=False)

    elec_cost = \
        ut.read_time_data(
            resource_filename('modesto', 'Data/ElectricityPrices'),
            name='DAM_electricity_prices-2014_BE.csv')['price_BE']

    general_params = {
        'Te': weather_data['Te'],
        'Tg': weather_data['Tg'],
        'Q_sol_E': weather_data['QsolE'],
        'Q_sol_W': weather_data['QsolW'],
        'Q_sol_S': weather_data['QsolS'],
        'Q_sol_N': weather_data['QsolN'],
        'time_step': time_step,
        'horizon': n_steps * time_step,
        'cost_elec': pd.Series(0.1, index=weather_data.index)
    }

    model.change_params(general_params)

    build_params = {
        'delta_T': 20,
        'mult': 1,
        'heat_profile': heat_demand['WaterscheiGarden']
    }
    model.change_params(build_params, node='demand', comp='build')

    stor_params = {
        'temperature_supply': 80 + 273.15,
        'temperature_return': 60 + 273.15,
        'mflo_max': 110,
        'mflo_min': -110,
        'mult': 1,
        'volume': 30000,
        'ar': 1,
        'dIns': 0.3,
        'kIns': 0.024,
        'heat_stor': 200000,
        'mflo_use': pd.Series(0, index=weather_data.index)
    }
    model.change_params(dict=stor_params, node='demand', comp='stor')
    model.change_init_type('heat_stor',
                           new_type='cyclic',
                           comp='stor',
                           node='demand')

    sol_data = ut.read_time_data(resource_filename('modesto',
                                                   'Data/RenewableProduction'),
                                 name='GlobalRadiation.csv')['0_40']

    stc_params = {
        'temperature_supply': 80 + 273.15,
        'temperature_return': 60 + 273.15,
        'solar_profile': sol_data,
        'area': 2000
    }
    model.change_params(stc_params, node='STC', comp='solar')

    pipe_data = {
        'diameter': 500,
        'temperature_supply': 80 + 273.15,
        'temperature_return': 60 + 273.15
    }
    model.change_params(pipe_data, node=None, comp='pipe')

    backup_params = {
        'delta_T': 20,
        'efficiency': 0.95,
        'PEF': 1,
        'CO2': 0.178,
        'fuel_cost': elec_cost,
        'Qmax': 500e8,
        'ramp_cost': 0,
        'ramp': 0
    }
    model.change_params(backup_params, node='STC', comp='backup')

    return model
示例#4
0
def construct_model():
    G = nx.DiGraph()

    G.add_node('ThorPark',
               x=4000,
               y=4000,
               z=0,
               comps={'plant': 'ProducerVariable'})
    G.add_node('p1', x=2600, y=5000, z=0, comps={})
    G.add_node('waterscheiGarden',
               x=2500,
               y=4600,
               z=0,
               comps={
                   'buildingD': 'RCmodel',
                   'storage': 'StorageVariable'
               })
    G.add_node('zwartbergNE',
               x=2000,
               y=5500,
               z=0,
               comps={'buildingD': 'RCmodel'})

    G.add_edge('ThorPark', 'p1', name='bbThor')
    G.add_edge('p1', 'waterscheiGarden', name='spWaterschei')
    G.add_edge('p1', 'zwartbergNE', name='spZwartbergNE')

    # nx.draw(G, with_labels=True, font_weight='bold')
    # plt.show()

    ###################################
    # Set up the optimization problem #
    ###################################

    optmodel = Modesto(pipe_model='ExtensivePipe', graph=G, repr_days=None)

    ##################################
    # Fill in the parameters         #
    ##################################

    df_weather = ut.read_time_data(resource_filename('modesto',
                                                     'Data/Weather'),
                                   name='weatherData.csv')
    df_userbehaviour = ut.read_time_data(resource_filename(
        'modesto', 'Data/UserBehaviour'),
                                         name='ISO13790.csv')
    elec_data = ut.read_time_data(resource_filename('modesto', 'Data'),
                                  name='ElectricityPrices/AvgPEF_CO2.csv')

    t_amb = df_weather['Te']
    t_g = df_weather['Tg']
    QsolN = df_weather['QsolN']
    QsolE = df_weather['QsolS']
    QsolS = df_weather['QsolN']
    QsolW = df_weather['QsolW']
    day_max = df_userbehaviour['day_max']
    day_min = df_userbehaviour['day_min']
    night_max = df_userbehaviour['night_max']
    night_min = df_userbehaviour['night_min']
    bathroom_max = df_userbehaviour['bathroom_max']
    bathroom_min = df_userbehaviour['bathroom_min']
    floor_max = df_userbehaviour['floor_max']
    floor_min = df_userbehaviour['floor_min']
    Q_int_D = df_userbehaviour['Q_int_D']
    Q_int_N = df_userbehaviour['Q_int_N']

    optmodel.opt_settings(allow_flow_reversal=True)

    # general parameters

    datapath = resource_filename('modesto', 'Data')
    c_f = ut.read_time_data(
        path=datapath,
        name='ElectricityPrices/DAM_electricity_prices-2014_BE.csv'
    )['price_BE']

    general_params = {
        'Te': t_amb,
        'Tg': t_g,
        'Q_sol_E': QsolE,
        'Q_sol_W': QsolW,
        'Q_sol_S': QsolS,
        'Q_sol_N': QsolN,
        'time_step': time_step,
        'horizon': n_steps * time_step,
        'cost_elec': c_f,
        'PEF_elec': elec_data['AvgPEF'],
        'CO2_elec': elec_data['AvgCO2/kWh']
    }

    optmodel.change_params(general_params)

    # building parameters

    zw_building_params = {
        'delta_T': 20,
        'mult': 100,
        'night_min_temperature': night_min,
        'night_max_temperature': night_max,
        'day_min_temperature': day_min,
        'day_max_temperature': day_max,
        'bathroom_min_temperature': bathroom_min,
        'bathroom_max_temperature': bathroom_max,
        'floor_min_temperature': floor_min,
        'floor_max_temperature': floor_max,
        'model_type': 'SFH_T_5_ins_TAB',
        'Q_int_D': Q_int_D,
        'Q_int_N': Q_int_N,
        'TiD0': 20 + 273.15,
        'TflD0': 20 + 273.15,
        'TwiD0': 20 + 273.15,
        'TwD0': 20 + 273.15,
        'TfiD0': 20 + 273.15,
        'TfiN0': 20 + 273.15,
        'TiN0': 20 + 273.15,
        'TwiN0': 20 + 273.15,
        'TwN0': 20 + 273.15,
        'max_heat': 6000
    }

    ws_building_params = zw_building_params.copy()
    ws_building_params['mult'] = 200
    ws_building_params['model_type'] = 'SFH_T_5_ins_TAB'

    optmodel.change_params(zw_building_params,
                           node='zwartbergNE',
                           comp='buildingD')
    optmodel.change_params(ws_building_params,
                           node='waterscheiGarden',
                           comp='buildingD')

    optmodel.change_init_type(node='zwartbergNE',
                              comp='buildingD',
                              state='TiD0',
                              new_type='cyclic')

    bbThor_params = {
        'diameter': 500,
        'temperature_supply': 80 + 273.15,
        'temperature_return': 60 + 273.15
    }
    spWaterschei_params = bbThor_params.copy()
    spWaterschei_params['diameter'] = 500
    spZwartbergNE_params = bbThor_params.copy()
    spZwartbergNE_params['diameter'] = 500

    optmodel.change_params(bbThor_params, comp='bbThor')
    optmodel.change_params(spWaterschei_params, comp='spWaterschei')
    optmodel.change_params(bbThor_params, comp='spZwartbergNE')

    # Storage parameters

    stor_design = {
        # Thi and Tlo need to be compatible with delta_T of previous
        'temperature_supply': 80 + 273.15,
        'temperature_return': 60 + 273.15,
        'mflo_max': 110,
        'mflo_min': -110,
        'volume': 2e4,
        'stor_type': 1,
        'heat_stor': 0,
        'mflo_use': pd.Series(0, index=t_amb.index),
        'cost_inv': 1
    }

    optmodel.change_params(dict=stor_design,
                           node='waterscheiGarden',
                           comp='storage')

    optmodel.change_state_bounds('heat_stor',
                                 new_ub=10**12,
                                 new_lb=0,
                                 slack=False,
                                 node='waterscheiGarden',
                                 comp='storage')

    # Production parameters

    c_f = ut.read_time_data(
        path=resource_filename('modesto', 'Data/ElectricityPrices'),
        name='DAM_electricity_prices-2014_BE.csv')['price_BE']
    # cf = pd.Series(0.5, index=t_amb.index)

    prod_design = {
        'delta_T': 20,
        'efficiency': 0.95,
        'CO2': 0.178,  # based on HHV of CH4 (kg/KWh CH4)
        'fuel_cost': c_f,
        # http://ec.europa.eu/eurostat/statistics-explained/index.php/Energy_price_statistics (euro/kWh CH4)
        'Qmax': 1.5e7,
        'ramp_cost': 0.01,
        'ramp': 1e6 / 3600,
        'cost_inv': 1
    }

    optmodel.change_params(prod_design, 'ThorPark', 'plant')

    ##################################
    # Print parameters               #
    ##################################

    # optmodel.print_all_params()
    # optmodel.print_general_param('Te')
    # optmodel.print_comp_param('ThorPark', 'plant')
    # optmodel.print_comp_param('waterscheiGarden', 'storage')
    # optmodel.print_comp_param('waterscheiGarden', 'storage', 'kIns', 'volume')

    return optmodel
示例#5
0
def setup_modesto_with_stor(graph, objtype='cost'):
    numdays = 1
    horizon = numdays * 24 * 3600
    time_step = 3600
    start_time = pd.Timestamp('20140101')
    pipe_model = 'ExtensivePipe'

    optmodel = Modesto(pipe_model=pipe_model,
                       graph=graph
                       )

    from pkg_resources import resource_filename
    datapath = resource_filename('modesto', 'Data')
    wd = ut.read_time_data(datapath, name='Weather/weatherData.csv')
    t_amb = wd['Te']
    t_g = wd['Tg']
    QsolN = wd['QsolN']
    QsolE = wd['QsolS']
    QsolS = wd['QsolN']
    QsolW = wd['QsolW']
    c_f = ut.read_time_data(path=datapath, name='ElectricityPrices/DAM_electricity_prices-2014_BE.csv')['price_BE']
    elec_data = ut.read_time_data(datapath, name='ElectricityPrices/AvgPEF_CO2.csv')

    general_params = {'Te': t_amb,
                      'Tg': t_g,
                      'Q_sol_E': QsolE,
                      'Q_sol_W': QsolW,
                      'Q_sol_S': QsolS,
                      'Q_sol_N': QsolN,
                      'time_step': time_step,
                      'horizon': horizon,
                      'cost_elec': c_f,
                      'CO2_elec': elec_data['AvgCO2/kWh'],
                      'PEF_elec': elec_data['AvgPEF']
                      }
    optmodel.change_params(general_params)

    Pnom = 4e4

    # Building parameters
    index = pd.DatetimeIndex(start=start_time, freq=str(time_step) + 'S', periods=horizon / time_step)
    building_params = {
        'temperature_supply': 50 + 273.15,
        'temperature_return': 20 + 273.15,
        'mult': 1,
        'heat_profile': pd.Series(index=index, name='Heat demand', data=[0, 1, 0, 0, 1, 1] * 4 * numdays) * Pnom,
        'DHW_demand': pd.Series(index=index, name='Heat demand', data=[0, 1, 0, 0, 1, 1] * 4 * numdays) * 60
    }
    optmodel.change_params(building_params, node='cons', comp='cons')

    # Producer parameters
    prod_design = {'delta_T': 30,
                   'efficiency': 0.95,
                   'CO2': 0.178,  # based on HHV of CH4 (kg/KWh CH4)
                   'fuel_cost': c_f,
                   'Qmax': Pnom,
                   'ramp_cost': 0.00,
                   'ramp': Pnom,
                   'cost_inv': 1}

    optmodel.change_params(prod_design, 'prod', 'prod')

    # Storage parameters
    stor_design = {'temperature_supply': 60 + 273.15,
                   'temperature_return': 20 + 273.15,
                   'mflo_max': 100,
                   'mflo_min': -100,
                   'volume': 5000,
                   'heat_stor': 10,
                   'stor_type': 0,  # 0 pit, 1 tank
                   'mflo_use': pd.Series(index=c_f.index, data=0),
                   'cost_inv': 1}

    for stor in ['stor', 'stor2']:
        optmodel.change_params(stor_design, stor, 'stor')
        optmodel.change_init_type('heat_stor', 'free', stor, 'stor')

    # optmodel.change_param('stor', 'stor', 'dIns', 0.001)
    # optmodel.change_param('stor', 'stor', 'kIns', 0.01)

    # Pipe parameters
    params = {
        'diameter': 150
    }

    if pipe_model is 'ExtensivePipe':
        params['temperature_supply'] = 30 + 273.15
        params['temperature_return'] = 20 + 273.15

    for p in ['pipe1', 'pipe2', 'pipe3']: optmodel.change_params(params, node=None, comp=p)

    optmodel.compile(start_time=start_time)

    optmodel.set_objective(objtype)
    optmodel.opt_settings(allow_flow_reversal=True)

    return optmodel
示例#6
0
def test_producer():
    from modesto.main import Modesto
    import pandas as pd
    import networkx as nx
    import modesto.utils as ut
    from pkg_resources import resource_filename

    def construct_model():
        G = nx.DiGraph()

        G.add_node('plant', x=0, y=0, z=0, comps={'gen': 'ProducerVariable'})
        G.add_node('user', x=10, y=0, z=0, comps={'building': 'BuildingFixed'})

        G.add_edge('plant', 'user', name='pipe')

        return G

    start_time = '20140101'
    time_step = 3600
    n_steps = 24
    time_index = pd.DatetimeIndex(start=start_time,
                                  freq=str(time_step) + 'S',
                                  periods=n_steps)

    t_amb = pd.Series(0, time_index)
    t_g = pd.Series(0, time_index)
    QsolN = pd.Series(0, time_index)
    QsolE = pd.Series(0, time_index)
    QsolS = pd.Series(0, time_index)
    QsolW = pd.Series(0, time_index)

    optmodel = Modesto(pipe_model='SimplePipe', graph=construct_model())

    datapath = resource_filename('modesto', 'Data')
    c_f = ut.read_time_data(
        path=datapath,
        name='ElectricityPrices/DAM_electricity_prices-2014_BE.csv'
    )['price_BE']
    elec_data = ut.read_time_data(datapath,
                                  name='ElectricityPrices/AvgPEF_CO2.csv')

    general_params = {
        'Te': t_amb,
        'Tg': t_g,
        'Q_sol_E': QsolE,
        'Q_sol_W': QsolW,
        'Q_sol_S': QsolS,
        'Q_sol_N': QsolN,
        'horizon': n_steps * time_step,
        'time_step': time_step,
        'cost_elec': c_f,
        'PEF_elec': elec_data['AvgPEF'],
        'CO2_elec': elec_data['AvgCO2/kWh']
    }

    optmodel.change_params(general_params)

    heat_profiles = [
        pd.Series(([5e4, 1e5, 5e4] + [0, 1e4, 0]) * 4, index=time_index),
        pd.Series(([6e4, 1e5, 6e4] + [0, 1e4, 0]) * 4, index=time_index),
        pd.Series(([5e4, 1e5, 5e4] + [500] * 3) * 4, index=time_index)
    ]

    building_params = {
        'temperature_supply':
        80 + 273.15,
        'temperature_return':
        60 + 273.15,
        'mult':
        1,
        'DHW_demand':
        pd.Series(([5e4, 1e5, 5e4] + [0, 1e4, 0]) * 4, index=time_index)
    }

    optmodel.change_params(building_params, node='user', comp='building')

    c_f = pd.Series(1, time_index)

    params = {
        'delta_T': 20,
        'efficiency': 0.95,
        'CO2': 0.2052,
        'fuel_cost': c_f,
        'Qmax': 1e5,
        'Qmin': 1e4,
        'ramp_cost': 1,
        'ramp': 1e5 / 2 / time_step,
        'cost_inv': 1
    }

    optmodel.change_params(params, node='plant', comp='gen')

    try:
        flags = []
        for heat_profile in heat_profiles:
            optmodel.change_params({'heat_profile': heat_profile},
                                   node='user',
                                   comp='building')
            optmodel.compile(start_time)
            optmodel.set_objective('cost')
            flags.append(optmodel.solve(tee=True))

        if flags == [0, 1, 1]:
            return True
    except ValueError:
        return False
示例#7
0
def construct_model():
    G = nx.DiGraph()

    G.add_node('ThorPark',
               x=4000,
               y=4000,
               z=0,
               comps={'plant': 'ProducerVariable'})
    G.add_node('p1', x=2600, y=5000, z=0, comps={})
    G.add_node('waterscheiGarden',
               x=2500,
               y=4600,
               z=0,
               comps={
                   'buildingD': 'BuildingFixed',
                   'storage': 'StorageVariable'
               })
    G.add_node('zwartbergNE',
               x=2000,
               y=5500,
               z=0,
               comps={'buildingD': 'BuildingFixed'})

    G.add_edge('ThorPark', 'p1', name='bbThor')
    G.add_edge('p1', 'waterscheiGarden', name='spWaterschei')
    G.add_edge('p1', 'zwartbergNE', name='spZwartbergNE')

    # nx.draw(G, with_labels=True, font_weight='bold')
    # plt.show()

    ###################################
    # Set up the optimization problem #
    ###################################

    optmodel = Modesto(pipe_model='SimplePipe', graph=G)

    ##################################
    # Fill in the parameters         #
    ##################################

    heat_profile = ut.read_time_data(resource_filename('modesto',
                                                       'Data/HeatDemand/Old'),
                                     name='HeatDemandFiltered.csv')
    dhw_demand = ut.read_time_data(resource_filename('modesto',
                                                     'Data/HeatDemand'),
                                   name='DHW_GenkNet.csv')
    t_amb = ut.read_time_data(resource_filename('modesto', 'Data/Weather'),
                              name='extT.csv')['Te']
    t_g = pd.Series(12 + 273.15, index=t_amb.index)

    # Solar radiation
    datapath = resource_filename('modesto', 'Data')
    wd = ut.read_time_data(datapath, name='Weather/weatherData.csv')
    QsolN = wd['QsolN']
    QsolE = wd['QsolS']
    QsolS = wd['QsolN']
    QsolW = wd['QsolW']

    optmodel.opt_settings(allow_flow_reversal=True)

    # general parameters

    c_f = ut.read_time_data(
        path=datapath,
        name='ElectricityPrices/DAM_electricity_prices-2014_BE.csv'
    )['price_BE']
    elec_data = ut.read_time_data(datapath,
                                  name='ElectricityPrices/AvgPEF_CO2.csv')

    general_params = {
        'Te': t_amb,
        'Tg': t_g,
        'Q_sol_E': QsolE,
        'Q_sol_W': QsolW,
        'Q_sol_S': QsolS,
        'Q_sol_N': QsolN,
        'time_step': time_step,
        'horizon': n_steps * time_step,
        'cost_elec': c_f,
        'PEF_elec': elec_data['AvgPEF'],
        'CO2_elec': elec_data['AvgCO2/kWh']
    }

    optmodel.change_params(general_params)

    # building parameters

    zw_building_params = {
        'temperature_supply': 80 + 273.15,
        'temperature_return': 60 + 273.15,
        'mult': 1,
        'heat_profile': heat_profile['ZwartbergNEast'],
        'DHW_demand': dhw_demand['ZwartbergNEast']
    }

    ws_building_params = zw_building_params.copy()
    ws_building_params['mult'] = 1
    ws_building_params['heat_profile'] = heat_profile['WaterscheiGarden']

    optmodel.change_params(zw_building_params,
                           node='zwartbergNE',
                           comp='buildingD')
    optmodel.change_params(ws_building_params,
                           node='waterscheiGarden',
                           comp='buildingD')

    bbThor_params = {'diameter': 500}
    spWaterschei_params = bbThor_params.copy()
    spWaterschei_params['diameter'] = 500
    spZwartbergNE_params = bbThor_params.copy()
    spZwartbergNE_params['diameter'] = 500

    optmodel.change_params(bbThor_params, comp='bbThor')
    optmodel.change_params(spWaterschei_params, comp='spWaterschei')
    optmodel.change_params(bbThor_params, comp='spZwartbergNE')

    # Storage parameters

    stor_design = {  # Thi and Tlo need to be compatible with delta_T of previous
        'temperature_supply': 80 + 273.15,
        'temperature_return': 60 + 273.15,
        'mflo_max': 110,
        'mflo_min': -110,
        'volume': 2e4,
        'stor_type': 0,
        'heat_stor': 0,
        'mflo_use': pd.Series(0, index=t_amb.index),
        'cost_inv': 1
    }

    optmodel.change_params(dict=stor_design,
                           node='waterscheiGarden',
                           comp='storage')

    optmodel.change_state_bounds('heat_stor',
                                 new_ub=10**12,
                                 new_lb=0,
                                 slack=False,
                                 node='waterscheiGarden',
                                 comp='storage')

    # Production parameters

    c_f = ut.read_time_data(
        path=resource_filename('modesto', 'Data/ElectricityPrices'),
        name='DAM_electricity_prices-2014_BE.csv')['price_BE']

    prod_design = {
        'delta_T': 20,
        'efficiency': 0.95,
        'CO2': 0.178,  # based on HHV of CH4 (kg/KWh CH4)
        'fuel_cost': c_f,
        # http://ec.europa.eu/eurostat/statistics-explained/index.php/Energy_price_statistics (euro/kWh CH4)
        'Qmax': 1.5e8,
        'ramp_cost': 0.01,
        'ramp': 1e6 / 3600,
        'cost_inv': 1
    }

    optmodel.change_params(prod_design, 'ThorPark', 'plant')

    ##################################
    # Print parameters               #
    ##################################

    # optmodel.print_all_params()
    # optmodel.print_general_param('Te')
    # optmodel.print_comp_param('ThorPark', 'plant')
    # optmodel.print_comp_param('waterscheiGarden', 'storage')
    # optmodel.print_comp_param('waterscheiGarden', 'storage', 'kIns', 'volume')

    ##################################
    # Solve                          #
    ##################################

    return optmodel
示例#8
0
if __name__ == '__main__':
    optmodel = construct_model()
    # compare_ramping_costs()

    optmodel.opt_settings(allow_flow_reversal=False)
    optmodel.compile(start_time)
    optmodel.set_objective('cost')

    optmodel.solve(tee=False, mipgap=0.01)

    ##################################
    # Collect result s               #
    ##################################

    # Fuel costs
    c_f = ut.read_time_data(path=resource_filename('modesto', 'Data/ElectricityPrices'),
                            name='DAM_electricity_prices-2014_BE.csv')
    # Converting to euro per kWh
    c_f = c_f['price_BE'] / 1000

    fig4, ax4 = plt.subplots()
    plotcf = ut.select_period_data(c_f, start_time=start_time, time_step=time_step, horizon=n_steps * time_step)
    ax4.plot(plotcf,
             label='Electricity day-ahead market')
    # ax3.axhline(y=0, linewidth=2, color='k', lines tyle='--')
    ax4.legend()
    ax4.set_ylabel('Electricity price [euro/kWh]')
    # fig3.tight_layout()

    # c_f = [0.034] * int(n_steps/2) + [0.034] * int(n_steps/2) # http://ec.europa.eu/eurostat/statistics-explained/index.php/Energy_price_statistics (euro/kWh CH4)

    # Heat flows
    level=logging.DEBUG,
    format='%(asctime)s %(name)-36s %(levelname)-8s %(message)s',
    datefmt='%m-%d %H:%M')
logger = logging.getLogger('Main.py')

###########################
# Set up Graph of network #
###########################

time_step = 900
n_steps = int(24 * 3 * 3600 / time_step)

start_time = pd.Timestamp('20140101')

df_weather = ut.read_time_data(resource_filename('modesto', 'Data/Weather'),
                               name='weatherData.csv',
                               expand=True)
df_userbehaviour = ut.read_time_data(resource_filename('modesto',
                                                       'Data/UserBehaviour'),
                                     name='ISO13790.csv',
                                     expand=True)
df_Qcon = ut.read_time_data(resource_filename('modesto', 'Data/UserBehaviour'),
                            name='QCon.csv',
                            expand=True)
df_Qrad = ut.read_time_data(resource_filename('modesto', 'Data/UserBehaviour'),
                            name='QRad.csv',
                            expand=True)

df_sh_day = ut.read_time_data(resource_filename('modesto',
                                                'Data/UserBehaviour'),
                              name='sh_day.csv',
def construct_model():
    G = nx.DiGraph()

    G.add_node('waterscheiGarden',
               x=2500,
               y=4600,
               z=0,
               comps={
                   'plant': 'ProducerVariable',
                   'buildingD': 'TeaserFourElement'
               })

    ###################################
    # Set up the optimization problem #
    ###################################

    optmodel = Modesto(pipe_model='SimplePipe', graph=G)

    ##################################
    # Fill in the parameters         #
    ##################################

    t_amb = df_weather['Te']
    t_g = df_weather['Tg']
    QsolN = df_weather['QsolN']
    QsolE = df_weather['QsolS']
    QsolS = df_weather['QsolN']
    QsolW = df_weather['QsolW']
    day_max = df_userbehaviour['day_max']
    day_min = ut.expand_df(df_sh_day['1'] + 273.15)
    floor_max = df_userbehaviour['floor_max']
    floor_min = df_userbehaviour['floor_min']
    Q_int_con = ut.expand_df(df_Qcon['1'])
    Q_int_rad = ut.expand_df(df_Qrad['1'])

    c_f = ut.read_time_data(path=resource_filename('modesto',
                                                   'Data/ElectricityPrices'),
                            name='DAM_electricity_prices-2014_BE.csv',
                            expand=True)['price_BE']
    # cf = pd.Series(0.5, index=t_amb.index)

    optmodel.opt_settings(allow_flow_reversal=True)

    # general parameters

    general_params = {
        'Te': t_amb,
        'Tg': t_g,
        'Q_sol_E': QsolE,
        'Q_sol_W': QsolW,
        'Q_sol_S': QsolS,
        'Q_sol_N': QsolN,
        'time_step': time_step,
        'horizon': n_steps * time_step,
        'cost_elec': c_f
    }

    optmodel.change_params(general_params)

    # building parameters

    ws_building_params = {
        'TAir0': 20 + 273.15,
        'TExt0': 12 + 273.15,
        'TRoof0': 10 + 273.15,
        'TFloor0': 10 + 273.15,
        'delta_T': 20,
        'mult': 10,
        'day_min_temperature': day_min,
        'day_max_temperature': day_max,
        'floor_min_temperature': floor_min,
        'floor_max_temperature': floor_max,
        'neighbName': 'OudWinterslag',
        'streetName': 'Gierenshof',
        'buildingName': 'Gierenshof_17_1589280',
        'Q_int_rad': Q_int_rad,
        'Q_int_con': Q_int_con,
        'max_heat': 2000000,
        'fra_rad': 0.3,
        'ACH': 0.4
    }

    optmodel.change_params(ws_building_params,
                           node='waterscheiGarden',
                           comp='buildingD')

    # Production parameters

    prod_design = {
        'efficiency': 0.95,
        'PEF': 1,
        'CO2': 0.178,  # based on HHV of CH4 (kg/KWh CH4)
        'fuel_cost': c_f,
        # http://ec.europa.eu/eurostat/statistics-explained/index.php/Energy_price_statistics (euro/kWh CH4)
        'Qmax': 1.5e6,
        'ramp_cost': 0.00,
        'ramp': 0,
        'delta_T': 20
    }

    optmodel.change_params(prod_design, 'waterscheiGarden', 'plant')

    ##################################
    # Print parameters               #
    ##################################

    # optmodel.print_all_params()
    # optmodel.print_general_param('Te')
    # optmodel.print_comp_param('ThorPark', 'plant')
    # optmodel.print_comp_param('waterscheiGarden', 'storage')
    # optmodel.print_comp_param('waterscheiGarden', 'storage', 'kIns', 'volume')

    return optmodel
示例#11
0
def construct_model():
    G = nx.DiGraph()

    G.add_node('waterscheiGarden',
               x=2500,
               y=4600,
               z=0,
               comps={
                   'plant': 'ProducerVariable',
                   'buildingD': 'RCmodel'
               })

    ###################################
    # Set up the optimization problem #
    ###################################

    optmodel = Modesto(pipe_model='SimplePipe', graph=G)

    ##################################
    # Fill in the parameters         #
    ##################################

    df_weather = ut.read_time_data(resource_filename('modesto',
                                                     'Data/Weather'),
                                   name='weatherData.csv',
                                   expand=True)
    df_userbehaviour = ut.read_time_data(resource_filename(
        'modesto', 'Data/UserBehaviour'),
                                         name='ISO13790.csv',
                                         expand=True)

    t_amb = df_weather['Te']
    t_g = df_weather['Tg']
    QsolN = df_weather['QsolN']
    QsolE = df_weather['QsolS']
    QsolS = df_weather['QsolN']
    QsolW = df_weather['QsolW']
    day_max = df_userbehaviour['day_max']
    day_min = df_userbehaviour['day_min']
    bathroom_min = df_userbehaviour['bathroom_min']
    bathroom_max = df_userbehaviour['bathroom_max']
    night_max = df_userbehaviour['night_max']
    night_min = df_userbehaviour['night_min']
    floor_max = df_userbehaviour['floor_max']
    floor_min = df_userbehaviour['floor_min']
    Q_int_D = df_userbehaviour['Q_int_D']
    Q_int_N = df_userbehaviour['Q_int_N']

    optmodel.opt_settings(allow_flow_reversal=True)

    # general parameters

    general_params = {
        'Te': t_amb,
        'Tg': t_g,
        'Q_sol_E': QsolE,
        'Q_sol_W': QsolW,
        'Q_sol_S': QsolS,
        'Q_sol_N': QsolN,
        'time_step': time_step,
        'horizon': n_steps * time_step
    }

    optmodel.change_params(general_params)

    # building parameters

    ws_building_params = {
        'delta_T': 20,
        'mult': 100,
        'night_min_temperature': night_min,
        'night_max_temperature': night_max,
        'day_min_temperature': day_min,
        'day_max_temperature': day_max,
        'bathroom_min_temperature': bathroom_min,
        'bathroom_max_temperature': bathroom_max,
        'floor_min_temperature': floor_min,
        'floor_max_temperature': floor_max,
        'model_type': 'SFH_T_5_ins_TAB',
        'Q_int_D': Q_int_D,
        'Q_int_N': Q_int_N,
        'TiD0': 20 + 273.15,
        'TflD0': 20 + 273.15,
        'TwiD0': 20 + 273.15,
        'TwD0': 20 + 273.15,
        'TfiD0': 20 + 273.15,
        'TfiN0': 20 + 273.15,
        'TiN0': 20 + 273.15,
        'TwiN0': 20 + 273.15,
        'TwN0': 20 + 273.15,
        'max_heat': 60000
    }

    optmodel.change_params(ws_building_params,
                           node='waterscheiGarden',
                           comp='buildingD')

    # Production parameters

    c_f = ut.read_time_data(
        path=resource_filename('modesto', 'Data/ElectricityPrices'),
        name='DAM_electricity_prices-2014_BE.csv')['price_BE']
    # cf = pd.Series(0.5, index=t_amb.index)

    prod_design = {
        'efficiency': 0.95,
        'PEF': 1,
        'CO2': 0.178,  # based on HHV of CH4 (kg/KWh CH4)
        'fuel_cost': c_f,
        # http://ec.europa.eu/eurostat/statistics-explained/index.php/Energy_price_statistics (euro/kWh CH4)
        'Qmax': 1.5e6,
        'ramp_cost': 0.00,
        'ramp': 1e6
    }

    optmodel.change_params(prod_design, 'waterscheiGarden', 'plant')

    ##################################
    # Print parameters               #
    ##################################

    # optmodel.print_all_params()
    # optmodel.print_general_param('Te')
    # optmodel.print_comp_param('ThorPark', 'plant')
    # optmodel.print_comp_param('waterscheiGarden', 'storage')
    # optmodel.print_comp_param('waterscheiGarden', 'storage', 'kIns', 'volume')

    return optmodel
示例#12
0
def setup_opt(horizon=365 * 24 * 3600, time_step=6 * 3600):
    G = nx.DiGraph()

    G.add_node('WaterscheiGarden', x=0, y=0, z=0,
               comps={'neighb': 'BuildingFixed'})

    G.add_node('p1', x=1000, y=2400, z=0, comps={})

    G.add_node('p2', x=4000, y=2800, z=0, comps={})

    G.add_node('TermienWest', x=4200, z=0, y=4600,
               comps={'neighb': 'BuildingFixed'})

    G.add_node('Production', x=6000, y=4000, z=0, comps={'backup': 'ProducerVariable',
                                                         'tank': 'StorageVariable'})
    G.add_node('TermienEast', x=5400, y=200, z=0, comps={'neighb': 'BuildingFixed'})

    G.add_edge('p1', 'WaterscheiGarden', name='servWat')
    G.add_edge('p1', 'p2', name='backBone')
    G.add_edge('p2', 'TermienWest', name='servTer')
    G.add_edge('p2', 'TermienEast', name='servBox')
    G.add_edge('Production', 'p2', name='servPro')

    # pos = {}
    # for node in G:
    #     # print node
    #     pos[node] = (G.nodes[node]['x'], G.nodes[node]['y'])
    #
    # fig, ax = plt.subplots()
    # nx.draw_networkx(G, with_labels=True, pos=pos, ax=ax)
    # ax.set_xlim(-1500, 7000)

    # fig.savefig('img/NetworkLayout.svg')  # , dpi=150)

    # # Setting up modesto

    # Decide the following characteristics of the optimization problem:
    # * **Horizon** of the optimization problem (in seconds)
    # * **Time step** of the (discrete) problem (in seconds)
    # * **Start time** (should be a pandas TimeStamp). Currently, weather and prixe data for 2014 are available in modesto.
    # * **Pipe model**: The type of model used to model the pipes. Only one type can be selected for the whole optimization problem (unlike the component model types). Possibilities: SimplePipe (= perfect pipe, no losses, no time delays), ExtensivePipe (limited mass flows and heat losses, no time delays) and NodeMethod (heat losses and time delays, but requires mass flow rates to be known in advance)

    horizon = horizon
    time_step = time_step
    pipe_model = 'ExtensivePipe'

    # And create the modesto object

    model = Modesto(pipe_model=pipe_model,
                    graph=G)

    # # Adding data

    # modesto is now aware of the position and interconnections between components, nodes and edges, but still needs information rergarding, weather, prices, customer demands, component sizing, etc.
    #

    # ## Collect data

    # modesto provides some useful data handling methods (found in modesto.utils). Most notable is read_time_data, that can load time-variable data from a csv file. In this example, the data that is available in the folder modesto/Data is used.

    # #### Weather data:

    from pkg_resources import resource_filename

    datapath = resource_filename('modesto', 'Data')

    wd = ut.read_time_data(datapath, name='Weather/weatherData.csv')
    t_amb = wd['Te']
    t_g = wd['Tg']
    QsolN = wd['QsolN']
    QsolE = wd['QsolS']
    QsolS = wd['QsolN']
    QsolW = wd['QsolW']

    # #### Electricity price

    # In[11]:

    c_f = ut.read_time_data(path=datapath, name='ElectricityPrices/DAM_electricity_prices-2014_BE.csv')['price_BE']
    elec_data = ut.read_time_data(datapath, name='ElectricityPrices/AvgPEF_CO2.csv')

    # ## Changing parameters

    # In order to solve the problem, all parameters of the optimization probkem need to get a value. A list of the parameters that modesto needs and their description can be found with the following command:

    general_params = {'Te': t_amb,
                      'Tg': t_g,
                      'Q_sol_E': QsolE,
                      'Q_sol_W': QsolW,
                      'Q_sol_S': QsolS,
                      'Q_sol_N': QsolN,
                      'time_step': time_step,
                      'horizon': horizon,
                      'cost_elec': c_f,
                      'PEF_elec': elec_data['AvgPEF'],
                      'CO2_elec': elec_data['AvgCO2/kWh']}

    model.change_params(general_params)

    # Notice how all parameters are first grouped together in a dictionary and then given all at once to modesto.
    #
    # If we print the parameters again, we can see the values have now been added:

    building_params_common = {
        'temperature_supply': 70 + 273.15,
        'temperature_return': 30 + 273.15,
        'mult': 1
    }

    heat_profile = ut.read_time_data(datapath, name='HeatDemand/Old/HeatDemandFiltered.csv')
    dhw_demand = ut.read_time_data(datapath, name='HeatDemand/DHW_GenkNet.csv')

    print('#######################')
    print('# Sum of heat demands #')
    print('#######################')
    print('')
    for name in ['WaterscheiGarden', 'TermienWest',
                 'TermienEast']:  # ['Boxbergheide', 'TermienWest', 'WaterscheiGarden']:
        build_param = building_params_common
        build_param['heat_profile'] = heat_profile[name]
        build_param['DHW_demand'] = dhw_demand[name]

        print(name, ':', str(sum(heat_profile[name]['2014']) / 1e9))  # Quarterly data

        model.change_params(build_param, node=name, comp='neighb')

    # ### Heat generation unit

    prod_design = {'delta_T': 40,
                   'efficiency': 0.95,
                   'CO2': 0.178,  # based on HHV of CH4 (kg/KWh CH4)
                   'fuel_cost': c_f,
                   'Qmax': 65e6,
                   'ramp_cost': 0.01,
                   'ramp': 120e6 / 3600,
                   'cost_inv': 1}

    model.change_params(prod_design, 'Production', 'backup')

    prod_stor_design = {
        'temperature_supply': 70 + 273.15,
        'temperature_return': 30 + 273.15,
        'mflo_max': 1100,
        'mflo_min': -1100,
        'mflo_use': pd.Series(0, index=t_amb.index),
        'volume': 3e3,
        'stor_type': 1, # 1 tank
        'heat_stor': 0,
        'cost_inv': 1
    }
    model.change_params(prod_stor_design, node='Production', comp='tank')
    model.change_init_type('heat_stor', 'cyclic', node='Production', comp='tank')

    # ### Pipes

    pipeDiam = {
        'backBone': 500,
        'servWat': 400,
        'servTer': 250,
        'servPro': 500,
        'servBox': 250
    }

    for pipe, DN in pipeDiam.items():
        model.change_param(node=None, comp=pipe, param='diameter', val=DN)
        model.change_param(node=None, comp=pipe, param='temperature_supply', val=70 + 273.15)
        model.change_param(node=None, comp=pipe, param='temperature_return', val=30 + 273.15)

    return model
示例#13
0
def construct_model():
    G = nx.DiGraph()

    G.add_node('ThorPark', x=4000, y=4000, z=0,
               comps={'plant': 'ProducerVariable'})
    G.add_node('p1', x=2600, y=5000, z=0,
               comps={})
    G.add_node('waterscheiGarden', x=2500, y=4600, z=0,
               comps={'buildingD': 'FixedProfile',
                      }
               )
    G.add_node('zwartbergNE', x=2000, y=5500, z=0,
               comps={'buildingD': 'FixedProfile'})

    G.add_edge('ThorPark', 'p1', name='bbThor')
    G.add_edge('p1', 'waterscheiGarden', name='spWaterschei')
    G.add_edge('p1', 'zwartbergNE', name='spZwartbergNE')

    nx.draw(G, with_labels=True)

    optmodel = Modesto(pipe_model='NodeMethod', graph=G, repr_days=None)

    ##################################
    # Set up data                    #
    ##################################

    # Initial temperatures in network
    supply_temp = 333.15
    return_temp = 303.15

    # Heat profiles
    linear = np.linspace(0, 1000, n_steps).tolist()
    step = [0] * int(n_steps / 2) + [1000] * int(n_steps / 2)
    sine = 600 + 400 * np.sin(
        [i / int(86400 / time_step) * 2 * np.pi - np.pi / 2 for i in range(int(5 * 86400 / time_step))])

    # TODO fix sine profiles
    time_index = pd.DatetimeIndex(start=start_time, freq=str(time_step) + 'S', periods=n_steps)

    heat_profile_step = pd.Series(step, index=time_index)
    heat_profile_linear = pd.Series(linear, index=time_index)
    heat_profile_sine = pd.Series(sine[0:n_steps], index=time_index)

    heat_profile = heat_profile_sine

    # Ambient temperature
    t_amb = ut.read_time_data(path=resource_filename('modesto', 'Data/Weather'),
                              name='extT.csv')

    # Ground temperature
    t_g = pd.Series(12 + 273.15, index=t_amb.index)

    # Solar radiation
    datapath = resource_filename('modesto', 'Data')
    wd = ut.read_time_data(datapath, name='Weather/weatherData.csv')
    QsolN = wd['QsolN']
    QsolE = wd['QsolS']
    QsolS = wd['QsolN']
    QsolW = wd['QsolW']

    # Historical temperatures and mass flows
    temp_history_return = pd.Series([return_temp] * 20, index=list(range(20)))
    temp_history_supply = pd.Series([supply_temp] * 20, index=list(range(20)))
    mass_flow_history = pd.Series([10] * 20, index=list(range(20)))

    # Fuel costs
    c_f = ut.read_time_data(path=resource_filename('modesto', 'Data/ElectricityPrices'),
                            name='DAM_electricity_prices-2014_BE.csv')
    elec_data = ut.read_time_data(datapath, name='ElectricityPrices/AvgPEF_CO2.csv')


    # c_f = [0.034] * int(n_steps/2) + [0.034] * int(n_steps/2) # http://ec.europa.eu/eurostat/statistics-explained/index.php/Energy_price_statistics (euro/kWh CH4)

    ###########################
    # Set parameters          #
    ###########################

    # general_parameters

    general_params = {'Te': t_amb['Te'],
                      'Tg': t_g,
                      'Q_sol_E': QsolE,
                      'Q_sol_W': QsolW,
                      'Q_sol_S': QsolS,
                      'Q_sol_N': QsolN,
                      'time_step': time_step,
                      'horizon': n_steps*time_step,
                      'cost_elec': c_f['price_BE'],
                      'PEF_elec': elec_data['AvgPEF'],
                      'CO2_elec': elec_data['AvgCO2/kWh']
                      }

    optmodel.change_params(general_params)
    optmodel.test = 'Test'
    # building parameters

    ZW_building_params = {'mult': 500,
                          'heat_profile': heat_profile,
                          'temperature_return': return_temp,
                          'temperature_supply': supply_temp,
                          'temperature_max': 363.15,
                          'temperature_min': 283.15}

    WS_building_params = ZW_building_params.copy()
    WS_building_params['mult'] = 1000

    # Calculating mass flows through network
    mfcalc = MfCalculation(G, time_step, time_step*n_steps)
    mfcalc.add_mf(node='waterscheiGarden', name='buildingD',
                  mf_df=WS_building_params['mult'] * heat_profile / 4186 / (WS_building_params['temperature_supply'] - WS_building_params['temperature_return']))
    mfcalc.add_mf(node='zwartbergNE', name='buildingD',
                  mf_df=ZW_building_params['mult'] * heat_profile / 4186 / (ZW_building_params['temperature_supply'] - ZW_building_params['temperature_return']))
    mfcalc.set_producer_node('ThorPark')
    mfcalc.set_producer_component('plant')
    mfcalc.calculate_mf()
    ZW_building_params['mass_flow'] = mfcalc.get_comp_mf(node='zwartbergNE', comp='buildingD')
    WS_building_params['mass_flow'] = mfcalc.get_comp_mf(node='waterscheiGarden', comp='buildingD')

    optmodel.change_params(ZW_building_params, node='zwartbergNE', comp='buildingD')
    optmodel.change_params(WS_building_params, node='waterscheiGarden', comp='buildingD')



    # pipe parameters

    bbThor_params = {'diameter': 200,
                     'mass_flow_history': mass_flow_history,
                     'temperature_history_return': temp_history_return,
                     'temperature_history_supply': temp_history_supply,
                     'wall_temperature_supply': supply_temp,
                     'wall_temperature_return': return_temp,
                     'temperature_out_supply': supply_temp,
                     'temperature_out_return': return_temp,
                     'mass_flow': mfcalc.get_edge_mf('bbThor')}
    spWaterschei_params = bbThor_params.copy()
    spWaterschei_params['diameter'] = 150
    spWaterschei_params['mass_flow'] = mfcalc.get_edge_mf('spWaterschei')
    spZwartbergNE_params = bbThor_params.copy()
    spZwartbergNE_params['diameter'] = 150
    spZwartbergNE_params['mass_flow'] = mfcalc.get_edge_mf('spZwartbergNE')

    optmodel.change_params(spWaterschei_params, comp='spWaterschei')
    optmodel.change_params(spZwartbergNE_params, comp='spZwartbergNE')
    optmodel.change_params(bbThor_params, comp='bbThor')

    # production parameters

    prod_design = {'efficiency': 3.5,
                   'CO2': 0.178,  # based on HHV of CH4 (kg/KWh CH4)
                   'fuel_cost': c_f['price_BE'],
                   'Qmax': 2e6,
                   'temperature_supply': supply_temp,
                   'temperature_return': return_temp,
                   'temperature_max': 363.15,
                   'temperature_min': 323.15,
                   'ramp': 1e6 / 3600,
                   'ramp_cost': 0.01,
                   'mass_flow': mfcalc.get_comp_mf(node='ThorPark', comp='plant'),
                   'cost_inv': 1}

    optmodel.change_params(prod_design, node='ThorPark', comp='plant')

    ##################################
    # Print parameters               #
    ##################################

    # optmodel.print_all_params()
    # optmodel.print_general_param('Te')
    # optmodel.print_comp_param(node='ThorPark', comp='plant')
    # optmodel.print_comp_param('waterscheiGarden.storage')
    # optmodel.print_comp_param('waterscheiGarden.storage', 'kIns', 'volume')

    return optmodel
示例#14
0
def setup_modesto(time_step=3600, n_steps=24 * 30):
    model = Modesto(pipe_model='ExtensivePipe', graph=setup_graph())
    heat_demand = ut.read_time_data(resource_filename('modesto', 'Data/HeatDemand/Old'), name='HeatDemandFiltered.csv')
    dhw_demand = ut.read_time_data(resource_filename('modesto', 'Data/HeatDemand'), name='DHW_GenkNet.csv')
    weather_data = ut.read_time_data(resource_filename('modesto', 'Data/Weather'), name='weatherData.csv')

    model.opt_settings(allow_flow_reversal=False)

    elec_cost = ut.read_time_data(resource_filename('modesto', 'Data/ElectricityPrices'),
                                  name='DAM_electricity_prices-2014_BE.csv')['price_BE']
    elec_data = ut.read_time_data(resource_filename('modesto', 'Data/ElectricityPrices'), name='AvgPEF_CO2.csv')



    general_params = {'Te': weather_data['Te'],
                      'Tg': weather_data['Tg'],
                      'Q_sol_E': weather_data['QsolE'],
                      'Q_sol_W': weather_data['QsolW'],
                      'Q_sol_S': weather_data['QsolS'],
                      'Q_sol_N': weather_data['QsolN'],
                      'time_step': time_step,
                      'horizon': n_steps * time_step,
                      'cost_elec': pd.Series(0.1, index=weather_data.index),
                      'PEF_elec': elec_data['AvgPEF'],
                      'CO2_elec': elec_data['AvgCO2/kWh']
                      }

    model.change_params(general_params)

    build_params = {
        'temperature_supply': 80 + 273.15,
        'temperature_return': 60 + 273.15,
        'mult': 1,
        'heat_profile': heat_demand['ZwartbergNEast'],
        'DHW_demand': dhw_demand['ZwartbergNEast']
    }
    model.change_params(build_params, node='demand', comp='build')

    stor_params = {
        'temperature_supply': 80 + 273.15,
        'temperature_return': 60 + 273.15,
        'mflo_max': 110,
        'mflo_min': -110,
        'volume': 30000,
        'stor_type': 0,
        'heat_stor': 0,
        'mflo_use': pd.Series(0, index=weather_data.index),
        'cost_inv': 1
    }
    model.change_params(dict=stor_params, node='demand', comp='stor')
    model.change_init_type('heat_stor', new_type='fixedVal', comp='stor', node='demand')

    stc_params = {
        'temperature_supply': 80 + 273.15,
        'temperature_return': 60 + 273.15,
        'area': 2000
    }
    model.change_params(stc_params, node='STC', comp='solar')

    pipe_data = {
        'diameter': 250,
        'temperature_supply': 80 + 273.15,
        'temperature_return': 60 + 273.15
    }
    model.change_params(pipe_data, node=None, comp='pipe')

    backup_params = {
        'delta_T': 20,
        'efficiency': 0.95,
        'CO2': 0.178,
        'fuel_cost': elec_cost,
        'Qmax': 7e6,
        'ramp_cost': 0,
        'ramp': 0,
        'cost_inv': 1
    }
    model.change_params(backup_params, node='STC', comp='backup')

    return model
示例#15
0
def setup_modesto(graph, objtype='cost'):
    """
    Instantiate and compile Modesto object using network graph supplied.

    :param graph: nx.DiGraph object specifying network lay-out
    :return:
    """

    numdays = 1
    horizon = numdays * 24 * 3600
    time_step = 3600
    start_time = pd.Timestamp('20140101')
    pipe_model = 'ExtensivePipe'

    optmodel = Modesto(pipe_model=pipe_model,
                       graph=graph
                       )

    from pkg_resources import resource_filename
    datapath = resource_filename('modesto', 'Data')
    wd = ut.read_time_data(datapath, name='Weather/weatherData.csv')
    t_amb = wd['Te']
    t_g = wd['Tg']
    QsolN = wd['QsolN']
    QsolE = wd['QsolS']
    QsolS = wd['QsolN']
    QsolW = wd['QsolW']
    c_f = ut.read_time_data(path=datapath, name='ElectricityPrices/DAM_electricity_prices-2014_BE.csv')['price_BE']

    elec_data = ut.read_time_data(datapath, name='ElectricityPrices/AvgPEF_CO2.csv')

    general_params = {'Te': t_amb,
                      'Tg': t_g,
                      'Q_sol_E': QsolE,
                      'Q_sol_W': QsolW,
                      'Q_sol_S': QsolS,
                      'Q_sol_N': QsolN,
                      'time_step': time_step,
                      'horizon': horizon,
                      'cost_elec': c_f,
                      'CO2_elec': elec_data['AvgCO2/kWh'],
                      'PEF_elec': elec_data['AvgPEF']}
    optmodel.change_params(general_params)

    Pnom = 5e6

    # Building parameters
    index = pd.DatetimeIndex(start=start_time, freq=str(time_step) + 'S', periods=horizon / time_step)
    building_params = {
        'temperature_supply': 50 + 273.15,
        'temperature_return': 20 + 273.15,
        'mult': 1,
        'heat_profile': pd.Series(index=index, name='Heat demand', data=[0, 1, 0, 0, 1, 1] * 4 * numdays) * Pnom,
        'DHW_demand': pd.Series(index=index, name='Heat demand', data=[0, 1, 0, 0, 1, 1] * 4 * numdays) * 60
    }
    optmodel.change_params(building_params, node='cons', comp='cons')

    # Producer parameters
    prod_design = {'delta_T': 30,
                   'efficiency': 0.95,
                   'CO2': 0.178,  # based on HHV of CH4 (kg/KWh CH4)
                   'fuel_cost': c_f,
                   'Qmax': Pnom * 1.5,
                   'ramp_cost': 0.01,
                   'ramp': Pnom / 3500,
                   'cost_inv': 1}

    optmodel.change_params(prod_design, 'prod', 'prod')

    # Pipe parameters
    params = {
        'diameter': 150,
        'temperature_supply': 50 + 273.15,
        'temperature_return': 20 + 273.15
    }
    optmodel.change_params(params, node=None, comp='pipe')

    optmodel.compile(start_time=start_time)

    optmodel.set_objective(objtype)
    optmodel.opt_settings(allow_flow_reversal=True)

    return optmodel
示例#16
0
#!/usr/bin/env python
"""
Description
"""

import matplotlib.pyplot as plt
from matplotlib.dates import DateFormatter
import pandas as pd
from pkg_resources import resource_filename

import modesto.utils as ut

moddata = resource_filename('modesto', 'Data')

weadat = ut.read_time_data(moddata, name='Weather/weatherData.csv')[:]['2014']
headat = ut.read_time_data(moddata,
                           name='HeatDemand/HeatDemandFiltered.csv')[:]['2014']

fig, axs = plt.subplots(2, 1, sharex=True)

axs[0].plot(weadat['Te'] - 273.15,
            label='Ambient',
            color='red',
            linewidth=0.75)
axs[0].plot(weadat['Tg'] - 273.15, label='Ground', color='orange', ls='-.')
axs[0].set_ylabel('Temperature [$^\circ$C]')

axs[0].legend(loc='best')

# TODO markers
axs[1].plot(headat['WaterscheiGarden'] / 1e6, label='A', linewidth=0.75)
示例#17
0
def set_params(model,
               pipe_model,
               verbose=True,
               repr=False,
               horizon=3600 * 24,
               time_step=3600):
    """
    Set all necessary parameters (can still be changed before compilation).

    :param model: Model in which parameters are to be set
    :param pipe_model: Type of pipe model.
    :return:
    """

    # # Adding data

    # modesto is now aware of the position and interconnections between components, nodes and edges, but still needs information rergarding, weather, prices, customer demands, component sizing, etc.
    #

    # ## Collect data

    # modesto provides some useful data handling methods (found in modesto.utils). Most notable is read_time_data, that can load time-variable data from a csv file. In this example, the data that is available in the folder modesto/Data is used.

    # #### Weather data:
    from pkg_resources import resource_filename

    datapath = resource_filename('modesto', 'Data')

    wd = utils.read_time_data(datapath,
                              name='Weather/weatherData.csv',
                              expand=repr)
    t_amb = wd['Te']
    t_g = wd['Tg']
    QsolN = wd['QsolN']
    QsolE = wd['QsolS']
    QsolS = wd['QsolN']
    QsolW = wd['QsolW']

    # #### Electricity price

    # In[11]:

    c_f = utils.read_time_data(
        path=datapath,
        name='ElectricityPrices/DAM_electricity_prices-2014_BE.csv',
        expand=repr)['price_BE']
    elec_data = utils.read_time_data(datapath,
                                     name='ElectricityPrices/AvgPEF_CO2.csv')

    # ## Changing parameters

    # In order to solve the problem, all parameters of the optimization probkem need to get a value. A list of the parameters that modesto needs and their description can be found with the following command:

    general_params = {
        'Te': t_amb,
        'Tg': t_g,
        'Q_sol_E': QsolE,
        'Q_sol_W': QsolW,
        'Q_sol_S': QsolS,
        'Q_sol_N': QsolN,
        'time_step': time_step,
        'horizon': horizon,
        'cost_elec': c_f,
        'PEF_elec': elec_data['AvgPEF'],
        'CO2_elec': elec_data['AvgCO2/kWh']
    }

    model.change_params(general_params)

    # Notice how all parameters are first grouped together in a dictionary and then given all at once to modesto.
    #
    # If we print the parameters again, we can see the values have now been added:

    building_params_common = {
        'temperature_supply': 70 + 273.15,
        'temperature_return': 30 + 273.15,
        'mult': 1
    }

    heat_profile = utils.read_time_data(
        datapath, name='HeatDemand/Old/HeatDemandFiltered.csv', expand=repr)
    dhw_demand = utils.read_time_data(datapath,
                                      name='HeatDemand/DHW_GenkNet.csv',
                                      expand=repr)

    if verbose:
        print('#######################')
        print('# Sum of heat demands #')
        print('#######################')
        print('')
        print(
            sum(heat_profile[i] for i in
                ['WaterscheiGarden', 'TermienWest', 'TermienEast']).max())
    for name in ['WaterscheiGarden', 'TermienWest', 'TermienEast'
                 ]:  # ['Boxbergheide', 'TermienWest', 'WaterscheiGarden']:
        build_param = building_params_common
        build_param['heat_profile'] = heat_profile[name]
        build_param['DHW_demand'] = dhw_demand[name]

        if verbose:
            print(name, ':',
                  str(sum(heat_profile[name]['2014']) / 1e9))  # Quarterly data

        model.change_params(build_param, node=name, comp='neighb')

    # ### Heat generation unit

    prod_design = {
        'delta_T': 40,
        'efficiency': 0.97,
        'CO2': 0.178,  # based on HHV of CH4 (kg/KWh CH4)
        'fuel_cost': c_f,
        'Qmax': 7.5e7,
        'ramp_cost': 0.00,
        'ramp': 0,
        'cost_inv': 1
    }

    model.change_params(prod_design, 'Production', 'backup')
    STOR_COST = resource_filename('modesto', 'Data/Investment/Storage.xlsx')
    pit_cost = utils.read_xlsx_data(STOR_COST, use_sheet='Pit')['Cost']
    tank_cost = utils.read_xlsx_data(STOR_COST, use_sheet='Tank')['Cost']
    prod_stor_design = {
        'temperature_supply': 70 + 273.15,
        'temperature_return': 30 + 273.15,
        'mflo_max': 1100,
        'mflo_min': -1100,
        'mflo_use': pd.Series(0, index=t_amb.index),
        'volume': 3e3,
        'stor_type': 1,
        'heat_stor': 0,
        'cost_inv': tank_cost
    }

    model.change_init_type('heat_stor',
                           'cyclic',
                           node='Production',
                           comp='tank')
    model.change_params(prod_stor_design, node='Production', comp='tank')
    for node in ['SolarArray', 'TermienWest', 'WaterscheiGarden']:
        model.change_init_type('heat_stor', 'cyclic', node=node, comp='tank')

    # ### Storage Unit

    stor_design = {
        'temperature_supply': 70 + 273.15,
        'temperature_return': 30 + 273.15,
        'mflo_max': 11000,
        'mflo_min': -11000,
        'mflo_use': pd.Series(0, index=t_amb.index),
        'volume': 50e3,
        'stor_type': 0,
        'heat_stor': 0,
        'cost_inv': pit_cost
    }

    model.change_params(stor_design, node='SolarArray', comp='tank')
    stor_design = {
        'TermienWest': {
            'temperature_supply': 70 + 273.15,
            'temperature_return': 30 + 273.15,
            'mflo_max': 11000,
            'mflo_min': -11000,
            'mflo_use': pd.Series(0, index=t_amb.index),
            'volume': 20e3,
            'stor_type': 0,  # Pit
            'heat_stor': 0,
            'cost_inv': pit_cost
        },
        'WaterscheiGarden': {
            'temperature_supply': 70 + 273.15,
            'temperature_return': 30 + 273.15,
            'mflo_max': 11000,
            'mflo_min': -11000,
            'mflo_use': pd.Series(0, index=t_amb.index),
            'volume': 60e3,
            'stor_type': 0,  # pit
            'heat_stor': 0,
            'cost_inv': pit_cost
        }
    }

    for node in ['TermienWest', 'WaterscheiGarden']:
        model.change_params(stor_design[node], node=node, comp='tank')

    for node in [
            'Production', 'SolarArray', 'TermienWest', 'WaterscheiGarden'
    ]:
        if repr:
            model.change_init_type('heat_stor', 'free', node=node, comp='tank')
        else:
            model.change_init_type('heat_stor',
                                   'cyclic',
                                   node=node,
                                   comp='tank')

    # ### Pipes

    pipeDiam = {
        'backBone': 500,
        'servWat': 400,
        'servTer': 250,
        'servPro': 500,
        'servSol': 500,
        'servBox': 250
    }

    for pipe, DN in pipeDiam.items():
        model.change_param(node=None, comp=pipe, param='diameter', val=DN)
        if pipe_model == 'ExtensivePipe':
            model.change_param(node=None,
                               comp=pipe,
                               param='temperature_supply',
                               val=70 + 273.15)
            model.change_param(node=None,
                               comp=pipe,
                               param='temperature_return',
                               val=30 + 273.15)

    # ### Solar collector
    solData = utils.read_time_data(
        datapath, name='RenewableProduction/GlobalRadiation.csv', expand=False)

    solParam = {
        'temperature_supply': 70 + 273.15,
        'temperature_return': 30 + 273.15,
        'area': 300000
    }

    model.change_params(solParam, node='SolarArray', comp='solar')

    return model