-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
code that needs to be reviewed to see what is causing errors #3
base: main
Are you sure you want to change the base?
Changes from all commits
fb04506
cacaa04
01d42f1
7af5ecf
99aa755
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,7 @@ def run_mcor(input_dict): | |
net_metering_rate=net_metering_inputs["net_metering_rate"], | ||
demand_rate=demand_rate_inputs["demand_rate"], | ||
existing_components=existing_components_inputs["existing_components"], | ||
existing_generator='existing_generator' in input_dict['existing_components_inputs'], | ||
output_tmy=True, | ||
validate=True, | ||
net_metering_limits=net_metering_inputs["net_metering_limits"], | ||
|
@@ -101,7 +102,9 @@ def run_mcor(input_dict): | |
optim.get_load_profiles() | ||
|
||
# Run all simulations | ||
optim.run_sims_par() | ||
# optim.run_sims_par() | ||
#run without multi-threading | ||
optim.run_sims() | ||
|
||
# Filter and rank results | ||
optim.parse_results() | ||
|
@@ -202,7 +205,15 @@ def run_mcor(input_dict): | |
# input_dict["existing_components_inputs"]["pv"] = PV(existing=True, pv_capacity=100, tilt=tilt, azimuth=azimuth, | ||
# module_capacity=0.360, module_area=3, spacing_buffer=2, | ||
# pv_tracking='fixed', pv_racking='ground') | ||
# input_dict["existing_components_inputs"]["existing_components"] = {'pv': pv} | ||
# input_dict["existing_components_inputs"]["existing_components"] = {"pv": ["pv"]} | ||
|
||
input_dict["existing_components_inputs"]["existing_generator"] = Generator(existing=True, rated_power=500, num_units=1, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we'll want to specify all of the parameters that are passed into the Generator object in the input_dict and then create the Generator object separately, probably in microgrid_optimizer.define_grid(). The code that will be creating the input_dict in gridpiq will not have access to the Generator class, only the run_mcor function. We should also do the same for any existing PV or Battery objects. |
||
fuel_curve_model={'1/4 Load (gal/hr)': 11, '1/2 Load (gal/hr)': 18.5, | ||
'3/4 Load (gal/hr)': 26.4, 'Full Load (gal/hr)': 35.7}, | ||
capital_cost=191000, ideal_minimum_load=0.3, | ||
loading_level_to_add_unit=0.9, | ||
loading_level_to_remove_unit=0.3, validate=True) | ||
input_dict["existing_components_inputs"]["existing_components"] = {'generator': input_dict["existing_components_inputs"]["existing_generator"]} | ||
|
||
# Specific PV and battery sizes dictionary | ||
input_dict["specific_pv_battery_sizes_inputs"] = {} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -395,9 +395,7 @@ def size_single_generator(self, generator_options, validate=True): | |
self.dispatch_df[['load_not_met']], self.duration, validate=False) | ||
self.load_duration_df = calculate_load_duration(grouped_load, validate=False) | ||
|
||
def calc_existing_generator_dispatch(self, generator_options, | ||
add_additional_generator=True, | ||
validate=True): | ||
def calc_existing_generator_dispatch(self, generator_options, validate=True): | ||
""" | ||
If there is an existing generator, determine how it meets the load and consumes fuel. | ||
|
||
|
@@ -412,12 +410,12 @@ def calc_existing_generator_dispatch(self, generator_options, | |
|
||
# Validate input parameters | ||
if validate: | ||
args_dict = {'generator_options': generator_options, | ||
'add_additional_generator': add_additional_generator} | ||
args_dict = {'generator_costs': generator_options} | ||
validate_all_parameters(args_dict) | ||
|
||
# Get info from existing generator | ||
gen = self.system.components['generator'] | ||
|
||
self.generator_power_kW = gen.rated_power | ||
|
||
# Create a temporary dataframe to hold load not met cropped at the existing generator | ||
|
@@ -435,68 +433,14 @@ def calc_existing_generator_dispatch(self, generator_options, | |
self.dispatch_df.loc[self.dispatch_df['load_not_met_by_generator'] < 0, | ||
'load_not_met_by_generator'] = 0 | ||
|
||
# If the load cannot be fully met by the existing generator | ||
if self.dispatch_df['load_not_met_by_generator'].sum() > 0: | ||
|
||
# If another generator can be added | ||
if add_additional_generator: | ||
|
||
# Total rated power (including multiple units together) based on max unmet | ||
# power | ||
max_power = self.dispatch_df['load_not_met_by_generator'].max() | ||
|
||
# Find the smallest generator with sufficent rated power, assumes generators | ||
# are sorted from smallest to largest | ||
addl_gen = None | ||
num_gen = 1 | ||
while addl_gen is None: | ||
# Find an appropriately sized generator | ||
best_gen = generator_options[generator_options.index | ||
* num_gen >= max_power | ||
* self.generator_buffer] | ||
|
||
# If no single generator is large enough, increase the number of | ||
# generators | ||
if not len(best_gen): | ||
num_gen += 1 | ||
else: | ||
# Create generator object | ||
best_gen = best_gen.iloc[0] | ||
self.generator_power_kW += best_gen.name*num_gen | ||
addl_gen = Generator( | ||
existing=False, rated_power=best_gen.name, | ||
num_units=num_gen, | ||
fuel_curve_model=best_gen[ | ||
['1/4 Load (gal/hr)', '1/2 Load (gal/hr)', | ||
'3/4 Load (gal/hr)', 'Full Load (gal/hr)']].to_dict(), | ||
capital_cost=best_gen['Cost (USD)'], | ||
validate=False) | ||
self.generator_obj = addl_gen | ||
|
||
# Calculate the load duration curve and fuel consumption for the additional | ||
# generator | ||
grouped_load, addl_fuel_used = \ | ||
addl_gen.calculate_fuel_consumption( | ||
self.dispatch_df[['load_not_met_by_generator']], | ||
self.duration, validate=False) | ||
self.load_duration_df = calculate_load_duration(grouped_load, | ||
validate=False) | ||
self.fuel_used_gal = existing_gen_fuel_used + addl_fuel_used | ||
|
||
# If another generator cannot be dispatched | ||
else: | ||
self.load_duration_df = pd.DataFrame( | ||
0, index=temp_load_duration_curve.index, | ||
columns=temp_load_duration_curve.columns) | ||
self.fuel_used_gal = existing_gen_fuel_used | ||
|
||
|
||
# If the existing generator can meet load, use empty load duration curve and existing | ||
# fuel used | ||
else: | ||
self.load_duration_df = pd.DataFrame( | ||
0, index=temp_load_duration_curve.index, | ||
columns=temp_load_duration_curve.columns) | ||
self.fuel_used_gal = existing_gen_fuel_used | ||
|
||
self.load_duration_df = pd.DataFrame( | ||
0, index=temp_load_duration_curve.index, | ||
columns=temp_load_duration_curve.columns) | ||
self.fuel_used_gal = existing_gen_fuel_used | ||
|
||
def get_load_breakdown(self): | ||
return self.load_breakdown | ||
|
@@ -639,7 +583,8 @@ def calculate_load_duration(grouped_load, validate=True): | |
# Run the simulation | ||
sim.scale_power_profile() | ||
sim.calc_dispatch() | ||
sim.size_single_generator(generator_options, validate=False) | ||
# sim.size_single_generator(generator_options, validate=False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One of these two lines needs to but uncommented for it to run, right? |
||
# sim.calc_existing_generator_dispatch(generator_options, validate=False) | ||
|
||
# Plot dispatch | ||
sim.dispatch_df[['load', 'pv_power', 'delta_battery_power', 'load_not_met']].plot() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should change this back.