Skip to content

Commit 7550089

Browse files
authored
Minor opt formulation fixes (#317)
1 parent 4a7afa7 commit 7550089

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

h2integrate/controllers/openloop_controllers.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ class DemandOpenLoopController(ControllerBaseClass):
246246
the system.
247247
{resource_name}_missed_load (float): Missed load timeseries when demand exceeds supply.
248248
- Units: Defined in `resource_rate_units` (e.g., "kg/h").
249-
249+
total_{resource_name}_missed_load (float): Total missed load over the simulation period.
250+
- Units: Defined in `resource_rate_units` (e.g., "kg").
250251
"""
251252

252253
def setup(self):
@@ -303,6 +304,12 @@ def setup(self):
303304
desc=f"{resource_name} missed load timeseries",
304305
)
305306

307+
self.add_output(
308+
f"total_{resource_name}_missed_load",
309+
units=self.config.resource_rate_units,
310+
desc=f"Total {resource_name} missed load over the simulation period",
311+
)
312+
306313
def compute(self, inputs, outputs):
307314
"""
308315
Compute the state of charge (SOC) and output flow based on demand and storage constraints.
@@ -383,3 +390,5 @@ def compute(self, inputs, outputs):
383390

384391
# Record the missed load at the current time step
385392
missed_load_array[t] = max(0, (demand_t - output_array[t]))
393+
394+
outputs[f"total_{resource_name}_missed_load"] = np.sum(missed_load_array)

h2integrate/core/pose_optimization.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,10 @@ def set_driver(self, opt_prob):
356356
return opt_prob
357357

358358
def set_objective(self, opt_prob):
359-
"""Set merit figure. Each objective has its own scaling. Check first for user override
359+
"""Set merit figure. Each objective has its own scaling. Check first for user override.
360+
361+
The optimization is always minimizing the objective. If you wish to maximize the objective,
362+
use a negative ref or scaler value in the config.
360363
361364
Args:
362365
opt_prob (openmdao problem instance): openmdao problem instance for
@@ -413,11 +416,12 @@ def set_constraints(self, opt_prob):
413416
opt_prob (openmdao problem instance): openmdao problem instance for
414417
current optimization problem edited to include constraint setup
415418
"""
416-
for technology, variables in self.config["constraints"].items():
417-
for key, value in variables.items():
418-
if value["flag"]:
419-
value.pop("flag")
420-
opt_prob.model.add_constraint(f"{technology}.{key}", **value)
419+
if self.config.get("constraints", False):
420+
for technology, variables in self.config["constraints"].items():
421+
for key, value in variables.items():
422+
if value["flag"]:
423+
value.pop("flag")
424+
opt_prob.model.add_constraint(f"{technology}.{key}", **value)
421425

422426
def set_recorders(self, opt_prob):
423427
"""sets up a recorder for the openmdao problem as desired in the input yaml

0 commit comments

Comments
 (0)