def init_simulation_pv(): """ Create the simulation object needed to calculate the objective of the problem :return: The HOPP simulation as defined for this problem """ # Create the site for the design evaluation site = 'irregular' location = locations[3] if site == 'circular': site_data = make_circular_site(lat=location[0], lon=location[1], elev=location[2]) elif site == 'irregular': site_data = make_irregular_site(lat=location[0], lon=location[1], elev=location[2]) else: raise Exception("Unknown site '" + site + "'") # Load in weather and price data files solar_file = Path( __file__).parent.parent / "resource_files" / "solar" / WEATHER_FILE #"Beni_Miha" / "659265_32.69_10.90_2019.csv" grid_file = Path(__file__).parent.parent / "resource_files" / "grid" / PRICE_FILE #"tunisia_est_grid_prices.csv" # Combine the data into a site definition site_info = SiteInfo(site_data, solar_resource_file=solar_file, grid_resource_file=grid_file) # set up hybrid simulation with all the required parameters solar_size_mw = 200 battery_capacity_mwh = 15 battery_capacity_mw = 100 interconnection_size_mw = 100 technologies = {'pv': {'system_capacity_kw': solar_size_mw * 1000, 'array_type': 2, 'dc_ac_ratio': 1.1}, 'battery': {'system_capacity_kwh': battery_capacity_mwh * 1000, 'system_capacity_kw': battery_capacity_mw * 1000}, 'grid': interconnection_size_mw * 1000} # Create the hybrid plant simulation # TODO: turn these off to run full year simulation dispatch_options = {'is_test_start_year': False, 'is_test_end_year': False, 'solver': 'gurobi_ampl', 'grid_charging': False, 'pv_charging_only': True} # TODO: turn-on receiver and field optimization before... initial simulation hybrid_plant = HybridSimulation(technologies, site_info, interconnect_kw=interconnection_size_mw * 1000, dispatch_options=dispatch_options) # Customize the hybrid plant assumptions here... hybrid_plant.pv.value('inv_eff', 95.0) hybrid_plant.pv.value('array_type', 0) hybrid_plant.pv.dc_degradation = [0] * 25 return hybrid_plant
def init_simulation_csp(): """ Create the simulation object needed to calculate the objective of the problem :return: The HOPP simulation as defined for this problem """ # Create the site for the design evaluation site = 'irregular' location = locations[3] if site == 'circular': site_data = make_circular_site(lat=location[0], lon=location[1], elev=location[2]) elif site == 'irregular': site_data = make_irregular_site(lat=location[0], lon=location[1], elev=location[2]) else: raise Exception("Unknown site '" + site + "'") # Load in weather and price data files solar_file = Path( __file__).parent.parent / "resource_files" / "solar" / WEATHER_FILE #"Beni_Miha" / "659265_32.69_10.90_2019.csv" grid_file = Path(__file__).parent.parent / "resource_files" / "grid" / PRICE_FILE #"tunisia_est_grid_prices.csv" # Combine the data into a site definition site_info = SiteInfo(site_data, solar_resource_file=solar_file, grid_resource_file=grid_file) # set up hybrid simulation with all the required parameters tower_cycle_mw = 100 interconnection_size_mw = 100 technologies = {'tower': {'cycle_capacity_kw': tower_cycle_mw * 1000, 'solar_multiple': 2.0, 'tes_hours': 12.0, 'optimize_field_before_sim': True}, # TODO: turn on 'grid': interconnection_size_mw * 1000} # Create the hybrid plant simulation # TODO: turn these off to run full year simulation dispatch_options = {'is_test_start_year': False, 'is_test_end_year': False, 'solver': 'gurobi_ampl'} # TODO: turn-on receiver and field optimization before... initial simulation hybrid_plant = HybridSimulation(technologies, site_info, interconnect_kw=interconnection_size_mw * 1000, dispatch_options=dispatch_options) return hybrid_plant
from collections import OrderedDict from hybrid.sites import make_circular_site, make_irregular_site, SiteInfo, locations from hybrid.hybrid_simulation import HybridSimulation from hybrid.layout.wind_layout import WindBoundaryGridParameters from hybrid.layout.pv_layout import PVGridParameters from tools.optimization import DataRecorder from tools.optimization.optimization_problem import OptimizationProblem from tools.optimization.optimization_driver import OptimizationDriver site = 'irregular' location = locations[1] site_data = None if site == 'circular': site_data = make_circular_site(lat=location[0], lon=location[1], elev=location[2]) elif site == 'irregular': site_data = make_irregular_site(lat=location[0], lon=location[1], elev=location[2]) else: raise Exception("Unknown site '" + site + "'") g_file = Path(__file__).absolute( ).parent.parent.parent / "resource_files" / "grid" / "pricing-data-2015-IronMtn-002_factors.csv" site_info = SiteInfo(site_data, grid_resource_file=g_file) # set up hybrid simulation with all the required parameters solar_size_mw = 100 wind_size_mw = 100
def run(default_config: Dict) -> None: config, output_path, run_name = setup_run(default_config) recorder = DataRecorder.make_data_recorder(output_path) max_evaluations = config['max_evaluations'] location_index = config['location'] location = locations[location_index] site = config['site'] site_data = None if site == 'circular': site_data = make_circular_site(lat=location[0], lon=location[1], elev=location[2]) elif site == 'irregular': site_data = make_irregular_site(lat=location[0], lon=location[1], elev=location[2]) else: raise Exception("Unknown site '" + site + "'") site_info = SiteInfo(site_data) inner_problem = HybridOptimizationProblem(site_info, config['num_turbines'], config['solar_capacity']) problem = HybridParametrization(inner_problem) optimizer = ParametrizedOptimizationDriver(problem, recorder=recorder, **config['optimizer_config']) figure = plt.figure(1) axes = figure.add_subplot(111) axes.set_aspect('equal') plt.grid() plt.tick_params(which='both', labelsize=15) plt.xlabel('x (m)', fontsize=15) plt.ylabel('y (m)', fontsize=15) site_info.plot() score, evaluation, best_solution = optimizer.central_solution() score, evaluation = problem.objective(best_solution) if score is None else score print(-1, ' ', score, evaluation) print('setup 1') num_substeps = 1 figure, axes = plt.subplots(dpi=200) axes.set_aspect(1) animation_writer = PillowWriter(2 * num_substeps) animation_writer.setup(figure, os.path.join(output_path, 'trajectory.gif'), dpi=200) print('setup 2') _, _, central_solution = optimizer.central_solution() print('setup 3') bounds = problem.inner_problem.site_info.polygon.bounds site_sw_bound = np.array([bounds[0], bounds[1]]) site_ne_bound = np.array([bounds[2], bounds[3]]) site_center = .5 * (site_sw_bound + site_ne_bound) max_delta = max(bounds[2] - bounds[0], bounds[3] - bounds[1]) reach = (max_delta / 2) * 1.3 min_plot_bound = site_center - reach max_plot_bound = site_center + reach print('setup 4') best_score, best_evaluation, best_solution = 0.0, 0.0, None def plot_candidate(candidate): nonlocal best_score, best_evaluation, best_solution axes.cla() axes.set(xlim=(min_plot_bound[0], max_plot_bound[0]), ylim=(min_plot_bound[1], max_plot_bound[1])) wind_color = (153 / 255, 142 / 255, 195 / 255) solar_color = (241 / 255, 163 / 255, 64 / 255) central_color = (.5, .5, .5) conforming_candidate, _, __ = problem.make_conforming_candidate_and_get_penalty(candidate) problem.plot_candidate(conforming_candidate, figure, axes, central_color, central_color, alpha=.7) if best_solution is not None: conforming_best, _, __ = problem.make_conforming_candidate_and_get_penalty(best_solution) problem.plot_candidate(conforming_best, figure, axes, wind_color, solar_color, alpha=1.0) axes.set_xlabel('Best Solution AEP: {}'.format(best_evaluation)) else: axes.set_xlabel('') axes.legend([ Line2D([0], [0], color=wind_color, lw=8), Line2D([0], [0], color=solar_color, lw=8), Line2D([0], [0], color=central_color, lw=8), ], ['Wind Layout', 'Solar Layout', 'Mean Search Vector'], loc='lower left') animation_writer.grab_frame() print('plot candidate') plot_candidate(central_solution) central_prev = central_solution # TODO: make a smooth transition between points # TODO: plot exclusion zones print('begin') try: while optimizer.num_evaluations() < max_evaluations: print('step start') logger.info("Starting step, num evals {}".format(optimizer.num_evaluations())) optimizer.step() print('step end') proportion = min(1.0, optimizer.num_evaluations() / max_evaluations) g = 1.0 * proportion b = 1.0 - g a = .5 color = (b, g, b) best_score, best_evaluation, best_solution = optimizer.best_solution() central_score, central_evaluation, central_solution = optimizer.central_solution() a1 = optimizer.converter.convert_from(central_prev) b1 = optimizer.converter.convert_from(central_solution) a = np.array(a1, dtype=np.float64) b = np.array(b1, dtype=np.float64) for i in range(num_substeps): p = (i + 1) / num_substeps c = (1 - p) * a + p * b candidate = optimizer.converter.convert_to(c) plot_candidate(candidate) central_prev = central_solution print(optimizer.num_iterations(), ' ', optimizer.num_evaluations(), best_score, best_evaluation) except: raise RuntimeError("Optimizer error encountered. Try modifying the config to use larger generation_size if" " encountering singular matrix errors.") animation_writer.finish() optimizer.close() print("Results and animation written to " + os.path.abspath(output_path))
def init_simulation(): """ Create the simulation object needed to calculate the objective of the problem TODO: make this representative of the design variables, is there currently a tradeoff in objectives? :return: The HOPP simulation as defined for this problem """ site = 'irregular' location = locations[1] if site == 'circular': site_data = make_circular_site(lat=location[0], lon=location[1], elev=location[2]) elif site == 'irregular': site_data = make_irregular_site(lat=location[0], lon=location[1], elev=location[2]) else: raise Exception("Unknown site '" + site + "'") solar_file = examples_dir.parent / "resource_files" / "solar" / "Beni_Miha" / "659265_32.69_10.90_2019.csv" grid_file = examples_dir.parent / "resource_files" / "grid" / "tunisia_est_grid_prices.csv" site_info = SiteInfo(site_data, solar_resource_file=solar_file, grid_resource_file=grid_file) # set up hybrid simulation with all the required parameters solar_size_mw = 200 tower_cycle_mw = 125 # battery_capacity_mwh = 15 interconnection_size_mw = 400 technologies = { 'tower': { 'cycle_capacity_kw': tower_cycle_mw * 1000, 'solar_multiple': 2.0, 'tes_hours': 12.0, 'optimize_field_before_sim': False }, # TODO: turn on 'pv': { 'system_capacity_kw': solar_size_mw * 1000 }, # 'battery': {'system_capacity_kwh': battery_capacity_mwh * 1000, # 'system_capacity_kw': battery_capacity_mwh * 1000 / 10}, 'grid': interconnection_size_mw * 1000 } # Create model # TODO: turn these off to run full year simulation dispatch_options = {'is_test_start_year': True, 'is_test_end_year': False} # TODO: turn-on receiver and field optimization before... initial simulation hybrid_plant = HybridSimulation(technologies, site_info, interconnect_kw=interconnection_size_mw * 1000, dispatch_options=dispatch_options) # Customize the hybrid plant assumptions here... hybrid_plant.pv.value('inv_eff', 95.0) hybrid_plant.pv.value('array_type', 0) return hybrid_plant