def test_calculate_storage_u_value(): params = { 's_iso': 50, # mm 'lamb_iso': 0.05, # W/(m*K) 'alpha_inside': 1, # W/(m2*K) 'alpha_outside': 1 # W/(m2*K) } u_value = calculate_storage_u_value(**params) assert u_value == 1 / 3
from oemof.thermal.stratified_thermal_storage import calculate_storage_u_value from oemof.thermal import facades from oemof.solph import (processing, Source, Sink, Bus, Flow, Model, EnergySystem) # Set paths data_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data/stratified_thermal_storage.csv') # Read input data input_data = pd.read_csv(data_path, index_col=0, header=0)['var_value'] # Precalculation u_value = calculate_storage_u_value(input_data['s_iso'], input_data['lamb_iso'], input_data['alpha_inside'], input_data['alpha_outside']) # Set up an energy system model solver = 'cbc' periods = 100 datetimeindex = pd.date_range('1/1/2019', periods=periods, freq='H') demand_timeseries = np.zeros(periods) demand_timeseries[-5:] = 1 heat_feedin_timeseries = np.zeros(periods) heat_feedin_timeseries[:10] = 1 energysystem = EnergySystem(timeindex=datetimeindex) bus_heat = Bus(label='bus_heat')
def calc_strat_tes_param( weather, temperature_col="temp_air", user_inputs_pvcompare_directory=None, user_inputs_mvs_directory=None, ): """ This function does the precalculations of the stratified thermal storage. It calculates the following parameters: 1. nominal_storage_capacity 2. loss_rate 3. fixed_losses_relative 4. fixed_losses_absolute from the storage's input data provided in `stratified_thermal_storage.csv` and using functions implemented in oemof.thermal (github.com/oemof/oemof-thermal). Parameters ---------- weather : :pandas:`pandas.DataFrame<frame>` Contains weather data time series. Required: ambient temperature in column `temperature_col`. temperature_col : str Name of column in `weather` containing ambient temperature. Default: "temp_air". user_inputs_pvcompare_directory: str or None Directory of the user inputs. If None, `constants.DEFAULT_USER_INPUTS_PVCOMPARE_DIRECTORY` is used as user_inputs_pvcompare_directory. Default: None. user_inputs_mvs_directory: str or None Path to input directory containing files that describe the energy system and that are an input to MVS. Default: DEFAULT_MVS_OUTPUT_DIRECTORY (see :func:`~pvcompare.constants`. Returns ------- nominal_storage_capacity : numeric Maximum amount of stored thermal energy [MWh] loss_rate : numeric (sequence or scalar) The relative loss of the storage capacity between two consecutive timesteps [-] fixed_losses_relative : numeric (sequence or scalar) Losses independent of state of charge between two consecutive timesteps relative to nominal storage capacity [-] fixed_losses_absolute : numeric (sequence or scalar) Losses independent of state of charge and independent of nominal storage capacity between two consecutive timesteps [MWh] """ # ********************************************************************************************* # Set paths - Read and prepare data # ********************************************************************************************* if user_inputs_pvcompare_directory is None: input_directory = constants.DEFAULT_USER_INPUTS_PVCOMPARE_DIRECTORY if user_inputs_mvs_directory == None: user_inputs_mvs_directory = constants.DEFAULT_USER_INPUTS_MVS_DIRECTORY input_data_filename = os.path.join(user_inputs_pvcompare_directory, "stratified_thermal_storage.csv") input_data = pd.read_csv(input_data_filename, header=0, index_col=0)["var_value"] # Prepare ambient temperature for precalculations ambient_temperature = weather[temperature_col] # ********************************************************************************************* # Precalculations # ********************************************************************************************* u_value = strat_tes.calculate_storage_u_value( input_data["s_iso"], input_data["lamb_iso"], input_data["alpha_inside"], input_data["alpha_outside"], ) volume, surface = strat_tes.calculate_storage_dimensions( input_data["height"], input_data["diameter"]) nominal_storage_capacity = (strat_tes.calculate_capacities( volume, input_data["temp_h"], input_data["temp_c"]) * 1000) try: int(float(nominal_storage_capacity)) except ValueError: if math.isnan(nominal_storage_capacity) is True: nominal_storage_capacity = 0 ( loss_rate, fixed_losses_relative, fixed_losses_absolute, ) = strat_tes.calculate_losses( u_value, input_data["diameter"], input_data["temp_h"], # TODO: In future heat pump temp here input_data["temp_c"], # TODO: In future relation to temp_h here ambient_temperature, ) return ( nominal_storage_capacity, loss_rate, fixed_losses_relative, fixed_losses_absolute, )
def run_storage_model(initial_storage_level, temp_h, temp_c): data_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), './data/validation_data.csv') input_data = pd.read_csv(data_path, index_col=0, header=0)['var_value'] u_value = calculate_storage_u_value( input_data['s_iso'], input_data['lamb_iso'], input_data['alpha_inside'], input_data['alpha_outside']) # Set up an energy system model periods = 10 datetimeindex = pd.date_range('1/1/2019', periods=periods, freq='H') demand_timeseries = np.zeros(periods) heat_feedin_timeseries = np.zeros(periods) energysystem = EnergySystem(timeindex=datetimeindex) bus_heat = Bus(label='bus_heat') heat_source = Source( label='heat_source', outputs={bus_heat: Flow( nominal_value=1, fix=heat_feedin_timeseries)}) shortage = Source( label='shortage', outputs={bus_heat: Flow(variable_costs=1e6)}) excess = Sink( label='excess', inputs={bus_heat: Flow()}) heat_demand = Sink( label='heat_demand', inputs={bus_heat: Flow( nominal_value=1, fix=demand_timeseries)}) thermal_storage = facades.StratifiedThermalStorage( label='thermal_storage', bus=bus_heat, diameter=input_data['diameter'], height=input_data['height'], temp_h=temp_h, temp_c=temp_c, temp_env=input_data['temp_env'], u_value=u_value, # W/(m2*K) min_storage_level=input_data['min_storage_level'], max_storage_level=input_data['max_storage_level'], initial_storage_level=initial_storage_level, capacity=input_data['maximum_heat_flow_charging'], efficiency=1, marginal_cost=0.0001 ) energysystem.add( bus_heat, heat_source, shortage, excess, heat_demand, thermal_storage) # create and solve the optimization model optimization_model = Model(energysystem) optimization_model.write('storage_model_facades.lp', io_options={'symbolic_solver_labels': True}) optimization_model.solve(solver='cbc', solve_kwargs={'tee': False}) energysystem.results['main'] = solph.processing.results(optimization_model) string_results = solph.views.convert_keys_to_strings(energysystem.results['main']) # Get time series of level (state of charge) of the thermal energy storage TES_soc = (string_results['thermal_storage', 'None']['sequences']) # Save results to csv file TES_soc.to_csv("./data/storage_soc_calculated.csv") return