Skip to content

Commit

Permalink
Structure of reg test for electrolyzer added, but good input sequence…
Browse files Browse the repository at this point in the history
… still needed.
  • Loading branch information
misi9170 committed Dec 3, 2024
1 parent f00f643 commit 2acbd0b
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions tests/regression_tests/electrolyzer_plant_regression_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
"""Regression tests for 'SolarPySAM'."""

import numpy as np
from hercules.python_simulators.electrolyzer_plant import ElectrolyzerPlant

PRINT_VALUES = True

test_input_dict = {
"general": {
"verbose": False
},
"electrolyzer": {
"initialize": True,
"initial_power_kW": 3000,
"supervisor": {
"n_stacks": 10,
},
"stack": {
"cell_type": "PEM",
"cell_area": 1000.0,
"max_current": 2000,
"temperature": 60,
"n_cells": 100,
"min_power": 50,
"stack_rating_kW": 500,
"include_degradation_penalty": True,
},
"controller": {
"n_stacks": 10,
"control_type": "DecisionControl",
"policy": {
"eager_on": False,
"eager_off": False,
"sequential": False,
"even_dist": False,
"baseline": True,
},
},
"costs": None,
"cell_params": {
"cell_type": "PEM",
"PEM_params": {
"cell_area": 1000,
"turndown_ratio": 0.1,
"max_current_density": 2,
},
},
"degradation": {
"PEM_params": {
"rate_steady": 1.41737929e-10,
"rate_fatigue": 3.33330244e-07,
"rate_onoff": 1.47821515e-04,
},
},
}
}

available_power_test = np.concatenate(
(
np.linspace(0, 1000, 3), # Ramp up
np.linspace(1000, -500, 6), # Ramp down
np.random.normal(-500, 100, 3) # Random fluctuations
)
)

# TODO: currently, this produces zero output.
# available_power_test should be made into a reasonable test input.
H2_output_base = np.zeros(11)

stacks_on_base = np.zeros(11)

def test_ElectrolyzerPlant_regression_():

dt = 0.5

electrolyzer = ElectrolyzerPlant(test_input_dict, dt)

times_test = np.arange(0, 5.5, dt)
H2_output_test = np.zeros_like(times_test)
stacks_on_test = np.zeros_like(times_test)

for i, t in enumerate(times_test):
out = electrolyzer.step({
"time": t,
"py_sims": {
"inputs": {
"available_power": available_power_test[i]
}
}
})
H2_output_test[i] = out["H2_output"]
stacks_on_test[i] = out["stacks_on"]

if PRINT_VALUES:
print("H2 output: ", H2_output_test)
print("Stacks on: ", stacks_on_test)

assert np.allclose(H2_output_base, H2_output_test)
assert np.allclose(stacks_on_base, stacks_on_test)

0 comments on commit 2acbd0b

Please sign in to comment.