def test_with_nonstorage_load(self, model): """ Test load from dict with 'storage_node' key. """ m = model m.scenarios.setup() s = Storage(m, 'Storage', max_volume=100.0) l = Link(m, 'Link') data = { "type": "controlcurve", "control_curve": 0.8, "values": [10.0, 0.0], "storage_node": "Storage" } l.cost = p = load_parameter(model, data) assert isinstance(p, ControlCurveParameter) s.setup(m) # Init memory view on storage (bypasses usual `Model.setup`) si = ScenarioIndex(0, np.array([0], dtype=np.int32)) print(s.volume) assert_allclose(l.get_cost(m.timestepper.current, si), 0.0) # When storage volume changes, the cost of the link changes. s.initial_volume = 90.0 m.reset() assert_allclose(l.get_cost(m.timestepper.current, si), 10.0)
def test_with_nonstorage(self, model): """ Test usage on non-`Storage` node. """ # Now test if the parameter is used on a non storage node m = model m.scenarios.setup() s = Storage(m, 'Storage', max_volume=100.0) l = Link(m, 'Link') cc = ConstantParameter(0.8) l.cost = ControlCurveParameter(s, cc, [10.0, 0.0]) s.setup(m) # Init memory view on storage (bypasses usual `Model.setup`) print(s.volume) si = ScenarioIndex(0, np.array([0], dtype=np.int32)) assert_allclose(l.get_cost(m.timestepper.current, si), 0.0) # When storage volume changes, the cost of the link changes. s.initial_volume = 90.0 m.reset() print(s.volume) assert_allclose(l.get_cost(m.timestepper.current, si), 10.0)