def simulate(self, parameter_assignments, duration=STEP_SIZE): # print('SIMULATE with parameters %s' % (parameter_assignments)) # compose scenario world = mosaik.World(self.sim_config) # create input simulator self.input_adapter.init(world, self.model_structure) self.input_adapter.mosaik_init(parameter_assignments) self.input_adapter.mosaik_create(parameter_assignments) # create a data collector self.collector_adapter.init(world, self.model_structure) self.collector_adapter.mosaik_init(parameter_assignments) self.collector_adapter.mosaik_create(parameter_assignments) # create the model under investigation self.model_adapter.init(world, self.model_structure) self.model_adapter.mosaik_init(parameter_assignments) self.model_adapter.mosaik_create(parameter_assignments) # connect inputs self.connect_inputs(world, self.input_adapter, self.model_adapter) # connect outputs self.connect_outputs(world, self.collector_adapter, self.model_adapter) # simulate world.run(until=duration) # collect data model_entity = self.model_adapter.model_entity output_data = self.collector_adapter.get_data() return output_data[model_entity.full_id]
def test_integration(sim_config_data): # sim_config_data is a fixture created by conftest.py and contains # information shared across test cases sim_config, end = sim_config_data # Create World world = mosaik.World(sim_config) # Start simulatorsfs examplesim = world.start('ExampleSim', eid_prefix='Model_') examplectrl = world.start('ExampleCtrl') collector = world.start('Collector', step_size=60) # Instantiate models models = [examplesim.ExampleModel(init_val=i) for i in range(-2, 3, 2)] agents = examplectrl.Agent.create(len(models)) monitor = collector.Monitor() # Connect entities for model, agent in zip(models, agents): world.connect(model, agent, ('val', 'val_in'), async_requests=True) mosaik.util.connect_many_to_one(world, models, monitor, 'val', 'delta') # Run simulation The collector will test for error free execution. world.run(until=end)
def main(): global NQUBIT global PROTOCOL_USED random.seed(23) if SIMULATION_OUTPUT == True: for i in range(5, 300, 15): #NQUBIT for j in range(0, 10, 2): NQUBIT = i print('NQUBITS = ', i, 'Attack probability = ', j) EVE_ATTACK_PROBABILITY = j / 10 EVE_SIMULATION['probability'] = EVE_ATTACK_PROBABILITY world = mosaik.World(sim_config) create_scenario(world) world.run(until=END) else: world = mosaik.World(sim_config) create_scenario(world) world.run(until=END) # As fast as possilbe
def main(): change_parameter = [ "adjust_feedin", "adjust_market_requirements", "adjust_hh_demand" ] #parameters to be changed random.seed(24) world = mosaik.World(SIM_CONFIG) for parameter in change_parameter: #run three different scenarios scenarios = create_scenario(world, parameter) runs = world.run(until=END, rt_factor=1 / 3600) print(scenarios) #print the result of the three different scenarios
def main(): random.seed(23) # Create World world = mosaik.World(SIM_CONFIG) # Start simulators factoryDispatcher = world.start('Dispatcher') factoryProfileP = world.start('CSV', sim_start=START, datafile=PROFILE_P) factoryProfileC = world.start('CSV', sim_start=START, datafile=PROFILE_C) # Instantiate models print("instanciation Dispatcher") entiteDispatcher = factoryDispatcher.ModelDispatcher() #creation des noeuds entitePP = factoryProfileP.ModelProfil() # .create(1) entitePC = factoryProfileC.ModelProfil() # .create(1) world.connect(entitePP, entiteDispatcher, ('P', 'Iproduction')) world.connect(entitePC, entiteDispatcher, ('P', 'Iconsommation')) webvis = world.start('WebVis', start_date=START, step_size=60) webvis.set_config(ignore_types=['Topology', 'ResidentialLoads', 'Grid', 'Database']) vis_topo = webvis.Topology() # On connecte les noeuds a la visualisation web world.connect(entiteDispatcher, vis_topo, 'Oequilibre') world.connect(entitePP, vis_topo, 'P') world.connect(entitePC, vis_topo, 'P') webvis.set_etypes({ 'ModelProfil': { 'cls': 'load', 'attr': 'P', 'unit': 'P.', 'default': 0, 'min': -1000, 'max': 1000, }, }) webvis.set_etypes({ 'ModelDispatcher': { 'cls': 'load', 'attr': 'Oequilibre', 'unit': 'Equ.', 'default': 0, 'min': -3000, 'max': 3000, },}) webbrowser.open('http://localhost:8000') # Run simulation world.run(until=END)
def main(): #--- Process input arguments parser = argparse.ArgumentParser(description='Run Smartgrid simulation') parser.add_argument( '--devs_file', type=str, help='devices configuration file', default = DEVS_FILE ) parser.add_argument( '--random_seed', type=int, help='ns-3 random generator seed', default=1 ) args = parser.parse_args() print( 'Starting simulation with args: {0}'.format( vars( args ) ) ) readDevices(args.devs_file) world = mosaik.World( sim_config=SIM_CONFIG, mosaik_config=MOSAIK_CONFIG, debug=False ) create_scenario( world, args ) world.run( until=END_TIME )
def main(): parser = argparse.ArgumentParser(description='Run a TC3 simulation with the SimICT component') parser.add_argument( '--ctrl_dead_time', type=float, help='controller deadtime in seconds', default=1 ) parser.add_argument( '--send_time_diff', type=float, help='time difference between sending volatge readings', default=3 ) parser.add_argument( '--random_seed', type=int, help='ns-3 random generator seed', default=1 ) parser.add_argument( '--output_file', type=str, help='output file name', default='erigridstore.h5' ) args = parser.parse_args() print( 'Starting simulation with args: {0}'.format( vars( args ) ) ) world = mosaik.World( SIM_CONFIG ) create_scenario( world, args ) world.run( until=STOP )
def main(): topoloader = topology_loader() conf = topoloader.get_config() global START START = conf['start'] global END END = int(conf['end']) global RT_FACTOR RT_FACTOR = float(conf['rt_factor']) global PV_DATA PV_DATA = os.path.join("data", conf['pv_data']) global GEN_DATA GEN_DATA = os.path.join("data", conf['gen_data']) if 'gen_data' in conf else None global DEFAULT_VOLTAGE DEFAULT_VOLTAGE = float(conf['default_voltage']) global PROFILE_FILE PROFILE_FILE = os.path.join("data", conf['profile_file']) logger.warning("Profile file: {} ".format(PROFILE_FILE)) global GRID_NAME GRID_NAME = conf['grid_name'] global GRID_FILE GRID_FILE = os.path.join("data", conf['grid_file']) global RTU_FILE RTU_FILE = os.path.join("data", conf['rtu_file']) global RTU_STATS_OUTPUT RTU_STATS_OUTPUT = bool(strtobool(conf['rtu_stats_output'].lower())) global RECORD_TIMES RECORD_TIMES = bool(strtobool(conf['recordtimes'].lower())) # TODO read it from GUI if RECORD_TIMES : try: os.remove('./outputs/times.csv') except OSError: pass random.seed(23) start_time = time.time() world = mosaik.World(sim_config, {'start_timeout': 30}) create_scenario(world) if RT_FACTOR == 0: world.run(until=END) else: world.run(until=END, rt_factor=RT_FACTOR) # As fast as possilb elapsed_time = time.time() - start_time print("Elapsed time: {}".format(elapsed_time))
def test_integration_server(sim_config_data_client): # sim_config_data_client is a fixture created by conftest.py and contains # information shared across test cases sim_config, end, addr = sim_config_data_client # start Java Simulator as Server in a separate process, # which listens on addr_server_test if sys.platform == 'win32': proc = subprocess.Popen(['examplesim.bat', addr, 'server'], cwd=os.path.dirname( os.path.realpath(__file__)).replace( '\\tests', '')) else: proc = subprocess.Popen(['./examplesim.sh', addr, 'server']) # wait for the Java Server time.sleep(2) # Create World print("Create World") world = mosaik.World(sim_config) # Start simulatorsfs examplesim = world.start('ExampleSim', eid_prefix='Model_') examplectrl = world.start('ExampleCtrl') collector = world.start('Collector', step_size=60) # Instantiate models models = [examplesim.ExampleModel(init_val=i) for i in range(-2, 3, 2)] agents = examplectrl.Agent.create(len(models)) monitor = collector.Monitor() # Connect entities for model, agent in zip(models, agents): world.connect(model, agent, ('val', 'val_in'), async_requests=True) mosaik.util.connect_many_to_one(world, models, monitor, 'val', 'delta') # Run simulation. The collector will test for error free execution. world.run(until=end)
def test_constant_inputsim_and_collector(): # prepare mosaik sim config sim_config = { 'InputSim': InputProvider.SIM_CONFIG, 'CollectorSim': Collector.SIM_CONFIG } sim_step_size = 300 sim_steps = 10 # create world world = mosaik.World(sim_config) # input simulator(s) input_values = {'a': 5., 'b': 3.} map_of_input_entities = create_constant_input_providers( world, input_values, sim_step_size) full_ids = { k: entity.full_id for k, entity in map_of_input_entities.items() } # data collector collector_sim = world.start('CollectorSim', step_size=sim_step_size) monitor = collector_sim.Monitor() # connect entities for attr, input_entity in map_of_input_entities.items(): world.connect(input_entity, monitor, ('value', attr)) # Run simulation world.run(until=sim_step_size * sim_steps) monitored_data = collector_sim.get_monitored_data() print(monitored_data) for key, id in full_ids.items(): data = monitored_data[id][key] # assert that length of the collected data is as expected assert len(data) == sim_steps # assert that the value is constant and the one given to the input provider assert all([val == input_values[key] for val in data])
def main(): """Compose the mosaik scenario and run the simulation.""" # We first create a World instance with our SIM_CONFIG: world = mosaik.World(SIM_CONFIG) # We then start the WECS simulator and our MAS and pass the "init()" params # to them: wecssim = world.start('WecsSim', wind_file=WIND_FILE) mas = world.start('MAS', start_date=START_DATE, controller_config=CONTROLLER_CONFIG) # Create WECS and agent instances/entities. # # We will create one (WECS, agent) pair at a time and immediately connect # them. This way, we can easily make sure they both have the same config # values and thus represent the same WECS. # # It would also be possible to create multiple WECS/agent and the same time # via "wecssim.WECS.create(n_wecs, **params)" but it would make connecting # the right WECS to right agent a bit more complicated and error prone: wecs = [] for n_wecs, params in WECS_CONFIG: # Iterate over the config sets for _ in range(n_wecs): w = wecssim.WECS(**params) a = mas.WecsAgent(**params) # Connect "w.P" to "a.P" and allow "a" to do async. requests to "w" # (e.g., set_data() to set new P_max to "w"): world.connect(w, a, 'P', async_requests=True) # Remember the WECS entity for connecting it to the DB later: wecs.append(w) # Start the database process and connect all WECS entities to it: db = world.start('DB', step_size=60 * 15, duration=DURATION) hdf5 = db.Database(filename=DB_PATH) mosaik.util.connect_many_to_one(world, wecs, hdf5, 'v', 'P', 'P_max') # Run the simulation world.run(DURATION)
def main(): #--- Process input arguments parser = argparse.ArgumentParser(description='Run Smartgrid simulation') parser.add_argument('--appcon_file', type=str, help='application connections file', default=APPCON_FILE) parser.add_argument('--random_seed', type=int, help='ns-3 random generator seed', default=1) args = parser.parse_args() print('Starting simulation with args: {0}'.format(vars(args))) readAppConnections(args.appcon_file) #readActives(ACTS_FILE) -- not necessary in the moment world = mosaik.World(sim_config=SIM_CONFIG, mosaik_config=MOSAIK_CONFIG, debug=False) create_scenario(world, args) world.run(until=END_TIME)
#'cmd': 'matlab.exe -minimize -nosplash -r "ExampleSim(\'%(addr)s\')"' 'connect': "127.0.0.1:9999" }, 'Monitor': { #'cwd': os.path.dirname(os.path.realpath(__file__)), # Set here the path of your Matlab Simulator #'cmd': 'matlab.exe -minimize -nosplash -r "MosaikUtilities.Collector(\'%(addr)s\')"' 'connect': "127.0.0.1:9998" } } mosaik_config = { 'start_timeout': 600, # seconds 'stop_timeout': 10, # seconds } world = mosaik.World(sim_config, mosaik_config) matlab = world.start('Matlab', step_size=1) monitor = world.start('Monitor', step_size=1) model = matlab.Model(init_value=2) model2 = matlab.Model(init_value=5) collector = monitor.Collector(graphical_output=True) world.connect(model, collector, 'val', 'delta') world.connect(model2, collector, 'val', 'delta') # Run simulation world.run(until=10) # Optional extra function
def main(): random.seed(23) # Create World world = mosaik.World(SIM_CONFIG) # Start simulators factoryModeles = world.start('SimulateurModels') factoryBat = world.start('SimulateurModels') factoryDispatcher = world.start('Dispatcher') factoryProfileP = world.start('CSV', sim_start=START, datafile=PROFILE_P) factoryProfileC = world.start('CSV', sim_start=START, datafile=PROFILE_C) webvis = world.start('WebVis', start_date=START, step_size=60) webvis.set_config(ignore_types=['Topology', 'ResidentialLoads', 'Grid', 'Database']) vis_topo = webvis.Topology() # Instantiate models print("instanciation Dispatcher") entitesDispatcher = factoryDispatcher.ModelDispatcher.create(NB_DISPATCHER) connect_many_to_one(world, entitesDispatcher, vis_topo, 'Oequilibre') for dispatcher in entitesDispatcher: #creation des noeuds entiteCA = factoryModeles.ModelCA() batterie = factoryBat.Batterie() entitePP = factoryProfileP.ModelProfil() # .create(1) entitePC = factoryProfileC.ModelProfil() # .create(1) entiteBC = factoryModeles.ModelBC() entiteBP = factoryModeles.ModelBP() # Connection des noeuds # Un CA est compose d'une batterie, d'un systeme de production et de consommation world.connect(entitePP, entiteCA, ('P', 'Iproduction')) world.connect(entitePC, entiteCA, ('P', 'Iconsommation')) world.connect(batterie, entiteCA, ('Ocharge', 'Icharge')) world.connect(entiteCA, batterie, ('Ocharge', 'Icharge'), time_shifted=True, initial_data={'Ocharge': 10}) # On connecte au dispatcher, un CA, un BP, un BC world.connect(entiteCA, dispatcher, ('Oconsommation','Iconsommation')) world.connect(dispatcher, entiteCA, ('Oequilibre','Iequilibre'), time_shifted=True, initial_data={'Oequilibre': 0}) world.connect(entiteBC, dispatcher, ('Oconsommation', 'Iconsommation')) world.connect(entiteBP, dispatcher, ('Oproduction', 'Iproduction')) # On connecte les noeuds a la visualisation web world.connect(entiteBC, vis_topo, 'Oconsommation') world.connect(entiteBP, vis_topo, 'Oproduction') world.connect(entitePP, vis_topo, 'P') world.connect(entitePC, vis_topo, 'P') world.connect(batterie, vis_topo, 'Ocharge') world.connect(entiteCA, vis_topo, 'Oconsommation') webvis.set_etypes({ 'Batterie': { 'cls': 'load', 'attr': 'Ocharge', 'unit': 'Charge', 'default': 0, 'min': 0, 'max': 100, }, }) webvis.set_etypes({ 'ModelProfil': { 'cls': 'load', 'attr': 'P', 'unit': 'P.', 'default': 0, 'min': -1000, 'max': 1000, }, }) webvis.set_etypes({ 'ModelCA': { 'cls': 'load', 'attr': 'Oconsommation', 'unit': 'Conso.', 'default': 0, 'min': 0, 'max': 100, }, }) webvis.set_etypes({ 'ModelBC': { 'cls': 'load', 'attr': 'Oconsommation', 'unit': 'Conso.', 'default': 0, 'min': 0, 'max': 100, }, }) webvis.set_etypes({ 'ModelBP': { 'cls': 'load', 'attr': 'Oproduction', 'unit': 'Prod.', 'default': 0, 'min': 0, 'max': 3000, }, }) webvis.set_etypes({ 'ModelDispatcher': { 'cls': 'load', 'attr': 'Oequilibre', 'unit': 'Equ.', 'default': 0, 'min': -3000, 'max': 3000, },}) webbrowser.open('http://localhost:8000') # Run simulation world.run(until=END)
def main(): random.seed(24) world = mosaik.World(SIM_CONFIG) create_scenario(world) world.run(until = END, rt_factor = 1/3600)
def main(): world = mosaik.World(sim_config) create_scenario(world)
def main(): world = mosaik.World(sim_config, mosaik_config=mosaik_config) create_scenario(world) world.run(until=END)
def main(): world = mosaik.World(SIM_CONFIG) create_scenario(world) world.run(until=END)
}, 'ExampleCtrl': { #'connect': '127.0.0.1:7777' 'python': 'controller:Controller', }, 'Collector': { 'connect': '127.0.0.1:9998' #}, #'Odysseus': { # 'connect': '127.0.0.1:5554', } } END = 10 * 60 # 10 minutes # Create World world = mosaik.World(SIM_CONFIG) # Start simulators examplesim = world.start('ExampleSim', eid_prefix='Model_') examplectrl = world.start('ExampleCtrl') collector = world.start('Collector', step_size=60) #odysseusModel = world.start('Odysseus', step_size=60*15) # Instantiate models model = examplesim.JModel() agent = examplectrl.Agent.create(1) monitor = collector.Collector() #odysseus = odysseusModel.Odysseus.create(1)
'cmd': 'mosaik-powerfactory-ldf %(addr)s', }, 'Collector': { 'cmd': 'python collector.py %(addr)s', }, 'CSV': { 'python': 'mosaik_csv:CSV', }, } START = '2014-01-01 00:00:00' END = 1 * 24 * 3600 # 1 day HH_DATA = 'data/household.csv' # Create World, increase timeout for power-factory world = mosaik.World(SIM_CONFIG, {'start_timeout': 60}) # Start simulators and get the model factory pfsim = world.start('PFSim', project_name='MOSIAK\\DEV', options={'ref_date_time': START}) hhsim = world.start('CSV', sim_start=START, datafile=HH_DATA, delimiter=';') collector = world.start('Collector', step_size=900) # Instantiate models using the model factory Netz = pfsim.ElmNet(loc_name='Netz') monitor = collector.Monitor() load_input = hhsim.Household.create(1)[0] # Access the powerfactory entities loads = Netz.children_of_model('ElmLod')
def main(sim_config, START, END, PV_DATA, PROFILE_FILE, GRID_NAME, GRID_FILE): random.seed(0) world = mosaik.World(sim_config) create_scenario(world, START, END, PV_DATA, PROFILE_FILE, GRID_NAME, GRID_FILE) world.run(until=END) # As fast as possilbe
def run_simulation(database_name, run_data, verbose=True): SIM_CONFIG = { 'DemandModel': { 'python': 'dtu_mosaik.mosaik_demand:DemandModel', }, 'SimpleGridModel': { 'python': 'dtu_mosaik.mosaik_grid:SimpleGridModel', }, 'CollectorSim': { 'python': 'dtu_mosaik.collector:Collector', }, 'PVModel': { 'python': 'dtu_mosaik.mosaik_pv:PVModel' }, 'BatteryModel': { 'python': 'dtu_mosaik.mosaik_battery:BatteryModel' }, 'Control': { 'python': 'dtu_mosaik.mosaik_control:Control' }, #'WTModel': { # 'python': 'dtu_mosaik.mosaik_wt:WTModel' #} 'NoiseGenerator': { 'python': 'dtu_mosaik.mosaik_noise:NoiseGenerator' } } run_id = run_data['ID'] pv1_cap = run_data['pv1_scaling'] battery_cap = run_data['batt_storage_capacity'] battery_rate = run_data['batt_charge_capacity'] change_rate = run_data['controller_change_rate'] day_type = run_data['climate_conditions'] random_weather = run_data['random_weather'] stochastic = run_data['stochastic'] noise_scale = run_data['noise_scale'] season = run_data['season'] seasons = {'summer': 1, 'autumn': 3, 'winter': 5, 'spring': 2} demand = seasons[run_data['season']] weather_base = { 'cloudy': [ '/PV715_20180125', '/PV715_20180126', '/PV715_20180127', '/PV715_20180130' ], 'intermittent': [ '/PV715_20180423', '/PV715_20180430', '/PV715_20180820', '/PV715_20180722' ], 'sunny': [ '/PV715_20180730', '/PV715_20180728', '/PV715_20180729', '/PV715_20180721' ] } if random_weather: day = weather_base[day_type][np.random.randint(0, 4)] else: day = weather_base[day_type][0] def init_entities(world, pv1_rated_capacity=pv1_cap, batt1_rated_cap=battery_cap, batt1_rate=battery_rate, con_change_rate=change_rate, weather=day, base_demand=demand, noise_scale=noise_scale, filename=data_path + database_name): sim_dict = {} entity_dict = {} # quick check if filepath exists directory = os.path.dirname(filename) if not os.path.exists(directory): os.makedirs(directory) ## Demand demand_sim = world.start('DemandModel', eid_prefix='demand_', step_size=1) demand_entity_1 = demand_sim.DemandModel( rated_capacity=base_demand, seriesname='/flexhouse_20180219') sim_dict['demand'] = demand_sim entity_dict['demand1'] = demand_entity_1 ## Grid model grid_sim = world.start('SimpleGridModel', eid_prefix='grid_', step_size=1) grid_entity_1 = grid_sim.SimpleGridModel(V0=240, droop=0.1) sim_dict['grid'] = grid_sim entity_dict['grid1'] = grid_entity_1 ## Collector collector_sim = world.start( 'CollectorSim', step_size=60, save_h5=True, h5_storename='{}_data.h5'.format(filename), h5_framename='timeseries/sim_{}'.format(run_id), print_results=False) collector_entity = collector_sim.Collector() sim_dict['collector'] = collector_sim entity_dict['collector'] = collector_entity ## PV pv_sim = world.start('PVModel', eid_prefix='pv_', step_size=1) sim_dict['pv1'] = pv_sim pv_entity_1 = pv_sim.PVModel(rated_capacity=pv1_rated_capacity, series_name=weather) entity_dict['pv1'] = pv_entity_1 ## WT #wt_sim = world.start( # 'WTModel', # eid_prefix='wt_', # step_size=1) #sim_dict['wt1'] = wt_sim #wt_entity_1 = wt_sim.WTModel( # rated_capacity=1, # series_name='/Gaia_20180510') #entity_dict['wt1'] = wt_entity_1 ## Battery batt_sim = world.start('BatteryModel', eid_prefix='batt_', step_size=1) batt_entity_1 = batt_sim.BatteryModel( rated_capacity=batt1_rated_cap, rated_discharge_capacity=batt1_rate, rated_charge_capacity=batt1_rate, initial_charge_rel=0.5, charge_change_rate=0.90, ) sim_dict['batt'] = batt_sim entity_dict['batt1'] = batt_entity_1 ## Controller control_sim = world.start('Control', eid_prefix='demand_', step_size=1) control_entity_1 = control_sim.Control( setpoint_change_rate=con_change_rate) sim_dict['control'] = control_sim entity_dict['control1'] = control_entity_1 ## "Noisifier" noise_injector = world.start('NoiseGenerator', eid_prefix='ng_', step_size=1) noise_entity_1 = noise_injector.NoiseGenerator(scale=noise_scale) sim_dict['noise'] = noise_injector entity_dict['noise1'] = noise_entity_1 return sim_dict, entity_dict world = mosaik.World(SIM_CONFIG) sim_dict, entity_dict = init_entities(world) # Connect units to grid busbar world.connect(entity_dict['demand1'], entity_dict['grid1'], ('P', 'P')) world.connect(entity_dict['pv1'], entity_dict['grid1'], ('P', 'P')) world.connect(entity_dict['batt1'], entity_dict['grid1'], ('P', 'P')) # Connect controller, note that the grid measurement is passed by a noise injection if stochastic: world.connect(entity_dict['grid1'], entity_dict['noise1'], ('Pgrid', 'input')) world.connect(entity_dict['noise1'], entity_dict['control1'], ('output', 'Pgrid')) else: world.connect(entity_dict['grid1'], entity_dict['control1'], ('Pgrid', 'Pgrid')) world.connect(entity_dict['control1'], entity_dict['batt1'], ('Pset', 'Pset'), time_shifted=True, initial_data={'Pset': 0.0}) world.connect(entity_dict['batt1'], entity_dict['control1'], ('relSoC', 'relSoC')) # Connect to Collector world.connect(entity_dict['batt1'], entity_dict['collector'], ('P', 'BattP')) world.connect(entity_dict['batt1'], entity_dict['collector'], ('SoC', 'BattSoC')) world.connect(entity_dict['demand1'], entity_dict['collector'], ('P', 'DemP')) if stochastic: world.connect(entity_dict['noise1'], entity_dict['collector'], ('output', 'GridP')) else: world.connect(entity_dict['grid1'], entity_dict['collector'], ('Pgrid', 'GridP')) world.connect(entity_dict['pv1'], entity_dict['collector'], ('P', 'SolarP')) #world.connect(entity_dict['wt1'], entity_dict['collector'], ('P', 'WindP')) END = 24 * 60 * 60 - 1 # 24 hours, 1 MosaikTime = 1 second world.run(END) ## End of simulation # # Data processing sim_store = pd.HDFStore('temp_files/{}_data.h5'.format(database_name)) sim_data = sim_store['/timeseries/sim_{}'.format(run_data['ID'])] sim_store.close() # The measurement at PCC # print(sim_data.keys()) if stochastic: grid_balance = sim_data['NoiseGenerator-0.ng__0'] else: grid_balance = sim_data['SimpleGridModel-0.grid__0'] cost = 0.39 # DKK/kWh energy_imported = grid_balance.apply(lambda x: x[x > 0].sum()) / 60 energy_exported = grid_balance.apply(lambda x: x[x < 0].sum()) / 60 energy_bill = energy_imported * cost maximum_infeed = np.abs(grid_balance).max() pv_generated = sim_data['PVModel-0.pv__0']['SolarP'].sum() / 60 self_consumption_index = (pv_generated + energy_exported) / pv_generated sim_data = { 'ID': [run_id], 'Energy bill [DKK/kWh]': [energy_bill['GridP']], 'Max. in-feed [kW]': [maximum_infeed['GridP']], 'Energy Imported [kWh]': [energy_imported['GridP']], 'Energy exported [kWh]': [energy_exported['GridP']], 'Self consumption index': [self_consumption_index['GridP']], 'pv1_capacity [kW]': [pv1_cap], 'battery storage capacity [kWh]': [battery_cap], 'battery charge capacity[kW]': [battery_rate], 'climate_conditions': [day_type], 'controller_change_rate': [change_rate], 'season': [season], 'File ID/dataframe': [ '{}'.format(database_name) + '/' + 'timeseries/sim_{}'.format(run_data['ID']) ] } run_store = pd.HDFStore( 'temp_files/runs_summary_{}.h5'.format(database_name)) run_df = pd.DataFrame(data=sim_data) print(run_df) run_store['run_{}'.format(run_data['ID'])] = run_df run_store.close()
def main(): random.seed(23) world = mosaik.World(sim_config) create_scenario(world) webbrowser.open('http://localhost:8000') world.run(until=END) # As fast as possilbe
def main(): random.seed(23) world = mosaik.World(sim_config) create_scenario(world) world.run(until=END) # As fast as possilbe
def main(): random.seed(23) world = mosaik.World(sim_config) create_scenario(world) # world.run(until=END) # As fast as possilbe world.run(until=END, rt_factor=1/(30*60))