Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- Adds `H2IntegrateModel`, `load_yaml`, `write_yaml`, and `write_readable_yaml` as package-level imports [PR 728](https://github.com/NatLabRockies/H2Integrate/pull/728).
- Update N2 diagram for Pyomo heuristic control from static image to dynamic and interactive embedded diagram [PR 726](https://github.com/NatLabRockies/H2Integrate/pull/726)
- Added ability to use timeseries for finance calculations [PR 725](https://github.com/NatLabRockies/H2Integrate/pull/725)
- Reduced import time for `h2integrate_model.py` by deferring imports of heavy dependencies until they are needed [PR 762](https://github.com/NatLabRockies/H2Integrate/pull/762)
- Added multivariable purge gas stream output to `AmmoniaSynLoopPerformanceModel` [PR 760](https://github.com/NatLabRockies/H2Integrate/pull/760)
- Add `constant` pricing mode for Grid cost models, allowing an explicit scalar price configuration alongside `per_timestep` and `per_year` modes. [PR 764](https://github.com/NatLabRockies/H2Integrate/pull/764)

Expand Down
53 changes: 33 additions & 20 deletions h2integrate/core/h2integrate_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,19 @@
import numpy as np
import networkx as nx
import openmdao.api as om
import matplotlib.pyplot as plt

from h2integrate.core.sites import SiteLocationComponent
from h2integrate.core.utilities import create_xdsm_from_config
from h2integrate.core.dict_utils import check_inputs
from h2integrate.core.file_utils import get_path, find_file, load_yaml
from h2integrate.finances.finances import AdjustedCapexOpexComp, AdjustedCapacityFactorComp
from h2integrate.core.supported_models import (
no_cost_models,
supported_models,
no_replacement_schedule_models,
)
from h2integrate.core.inputs.validation import load_tech_yaml, load_plant_yaml, load_driver_yaml
from h2integrate.core.pose_optimization import PoseOptimization
from h2integrate.postprocess.sql_to_csv import convert_sql_to_csv_summary
from h2integrate.core.commodity_stream_definitions import (
multivariable_streams,
is_electricity_producer,
)
from h2integrate.control.control_strategies.pyomo_storage_controller_baseclass import (
PyomoStorageControllerBaseClass,
)


try:
Expand Down Expand Up @@ -192,6 +183,12 @@ def load_config(self, config_input):
self.system_summary = config.get("system_summary")

# Load and validate each component configuration using the helper method
from h2integrate.core.inputs.validation import (
load_tech_yaml,
load_plant_yaml,
load_driver_yaml,
)

self.driver_config, self.driver_config_path, _ = self._load_component_config(
"driver_config", config.get("driver_config"), config_path, load_driver_yaml
)
Expand All @@ -212,17 +209,20 @@ def load_config(self, config_input):
if "control_strategy" in vals:
controller_model_name = vals["control_strategy"]["model"]
controller_cls = supported_models.get(controller_model_name)
if controller_cls is not None and issubclass(
controller_cls, PyomoStorageControllerBaseClass
):
model_inputs = self.technology_config["technologies"][name]["model_inputs"]
if (
"control_parameters" not in model_inputs
or model_inputs["control_parameters"] is None
):
model_inputs["control_parameters"] = {"tech_name": name}
else:
model_inputs["control_parameters"]["tech_name"] = name
if controller_cls is not None:
from h2integrate.control.control_strategies.pyomo_storage_controller_baseclass import ( # noqa: E501
PyomoStorageControllerBaseClass,
)

if issubclass(controller_cls, PyomoStorageControllerBaseClass):
model_inputs = self.technology_config["technologies"][name]["model_inputs"]
if (
"control_parameters" not in model_inputs
or model_inputs["control_parameters"] is None
):
model_inputs["control_parameters"] = {"tech_name": name}
else:
model_inputs["control_parameters"]["tech_name"] = name

def create_custom_models(self, model_config, config_parent_path, model_types, prefix=""):
"""This method loads custom models from the specified directory and adds them to the
Expand Down Expand Up @@ -416,6 +416,9 @@ def create_site_group(self, plant_config_dict: dict, site_config: dict):
Returns:
om.Group: OpenMDAO group for a site
"""

from h2integrate.core.sites import SiteLocationComponent

# Initialize the site group
site_group = om.Group()

Expand Down Expand Up @@ -453,6 +456,7 @@ def create_plant_model(self):
the same for each technology. This includes site information, project parameters,
control strategy, and finance parameters.
"""

plant_group = om.Group()

# Create the plant model group and add components
Expand Down Expand Up @@ -732,6 +736,9 @@ def create_finance_model(self):
# attaches a ProFAST finance model component to the plant.

"""

from h2integrate.finances.finances import AdjustedCapexOpexComp, AdjustedCapacityFactorComp

# if there aren't any finance parameters don't setup a finance model
if "finance_parameters" not in self.plant_config:
return
Expand Down Expand Up @@ -1420,6 +1427,8 @@ def create_driver_model(self):
Add the driver to the OpenMDAO model and add recorder.
"""

from h2integrate.core.pose_optimization import PoseOptimization

myopt = PoseOptimization(self.driver_config)
if "driver" in self.driver_config:
myopt.set_driver(self.prob)
Expand Down Expand Up @@ -1479,12 +1488,16 @@ def post_process(self, print_results=True, summarize_sql=False, show_plots=False
self.print_results(self.prob.model, excludes=["*resource_data"])

if summarize_sql and self.recorder_path is not None:
from h2integrate.postprocess.sql_to_csv import convert_sql_to_csv_summary

convert_sql_to_csv_summary(self.recorder_path, save_to_file=True)

for model in self.performance_models:
if hasattr(model, "post_process") and callable(model.post_process):
model.post_process(show_plots=show_plots)
if show_plots:
import matplotlib.pyplot as plt

plt.show()
self.state = State.POST_PROCESS

Expand Down
Loading
Loading