def test_load_composite_connections(): JSON_STRING = """ {"systems": { "controlled_spring": { "type": "CompositeSystem", "module": "pysim.compositesystem", "connections": [], "inputs": {"amp": 0.0}, "ports": { "in": { "amp": { "connections": [{"input": "amplitude", "subsystem": "wave_sys"}], "description": "amplitude of wave", "type": "scalar", "value": 0.0 } }, "out": { "out": { "connections": [{"output": "x1", "subsystem": "msd"}], "description": "position", "type": "scalar", "value": 0.0 }, "signal": { "connections": [{"output": "signal", "subsystem": "wave_sys"}], "description": "signal from wave", "type": "scalar", "value": 0.0 } } }, "stores": [], "subsystems": { "msd": { "connections": [], "inputs": {"b": 80.0, "f": 0.0, "k": 50.0, "m": 50.0}, "module": "pysim.systems.defaultsystemcollection1", "stores": [], "type": "MassSpringDamper" }, "wave_sys": { "connections": [["signal", "msd", "f"]], "inputs": {"amplitude": 50.0, "freq": 0.1, "phaseRad": 0.0}, "module": "pysim.systems.defaultsystemcollection1", "stores": [], "type": "SquareWave" } } } } } """ sim = Sim() file = tempfile.NamedTemporaryFile(delete=False, mode="w+") file.write(JSON_STRING) file.close() sim.load_config(file.name) sim.simulate(2, 0.1) assert np.abs(sim.systems["controlled_spring"].outputs.out-0.3240587706226495) < 1e-10
def test_load_connections(): JSON_STRING = """ {"systems": { "msd": { "connections": [], "inputs": {"b": 80.0, "f": 0.0, "k": 50.0, "m": 50.0}, "module": "pysim.systems.defaultsystemcollection1", "stores": [], "type": "MassSpringDamper" }, "wave_sys": { "connections": [["signal", "msd", "f"]], "inputs": {"amplitude": 50.0, "freq": 0.1,"phaseRad": 0.0}, "module": "pysim.systems.defaultsystemcollection1", "stores": [], "type": "SquareWave" } } } """ sim = Sim() file = tempfile.NamedTemporaryFile(delete=False, mode="w+") file.write(JSON_STRING) file.close() sim.load_config(file.name) sim.simulate(2, 0.1) res = sim.systems["msd"].states.x1 assert np.abs(sim.systems["msd"].states.x1-0.3240587706226495) < 1e-10
def test_load_config(): """Tests the loading of a system configuration from file""" configstring = """{ "systems": { "vanderpol1": { "inputs": { "a": 1.234, "b": 1.0 }, "module": "pysim.systems.defaultsystemcollection1", "type": "VanDerPol", "connections": [] }, "vanderpol2": { "inputs": { "a": 1.0, "b": 3.456 }, "module": "pysim.systems.python_systems", "type": "VanDerPol", "connections": [] } } } """ sim = Sim() file = tempfile.NamedTemporaryFile(delete=False, mode="w+") file.write(configstring) file.close() sim.load_config(file.name) assert sim.systems["vanderpol1"].inputs.a == 1.234 assert sim.systems["vanderpol2"].inputs.b == 3.456
def test_load_connections(): JSON_STRING = """ {"systems": { "msd": { "connections": [], "inputs": {"b": 80.0, "f": 0.0, "k": 50.0, "m": 50.0}, "module": "pysim.systems.defaultsystemcollection1", "stores": [], "type": "MassSpringDamper" }, "wave_sys": { "connections": [["signal", "msd", "f"]], "inputs": {"amplitude": 50.0, "freq": 0.1,"phaseRad": 0.0}, "module": "pysim.systems.defaultsystemcollection1", "stores": [], "type": "SquareWave" } } } """ sim = Sim() file = tempfile.NamedTemporaryFile(delete=False, mode="w+") file.write(JSON_STRING) file.close() sim.load_config(file.name) sim.simulate(2, 0.1) res = sim.systems["msd"].states.x1 assert np.abs(sim.systems["msd"].states.x1 - 0.3240587706226495) < 1e-10
def test_load_config(): """Tests the loading of a system configuration from file""" configstring = """{ "systems": { "vanderpol1": { "inputs": { "a": 1.234, "b": 1.0 }, "module": "pysim.systems.defaultsystemcollection1", "type": "VanDerPol", "connections": [] }, "vanderpol2": { "inputs": { "a": 1.0, "b": 3.456 }, "module": "pysim.systems.python_systems", "type": "VanDerPol", "connections": [] } } } """ sim = Sim() file = tempfile.NamedTemporaryFile(delete=False, mode="w+") file.write(configstring) file.close() sim.load_config(file.name) assert sim.systems["vanderpol1"].inputs.a == 1.234 assert sim.systems["vanderpol2"].inputs.b == 3.456
def test_load_composite_connections(): JSON_STRING = """ {"systems": { "controlled_spring": { "type": "CompositeSystem", "module": "pysim.compositesystem", "connections": [], "inputs": {"amp": 0.0}, "ports": { "in": { "amp": { "connections": [{"input": "amplitude", "subsystem": "wave_sys"}], "description": "amplitude of wave", "type": "scalar", "value": 0.0 } }, "out": { "out": { "connections": [{"output": "x1", "subsystem": "msd"}], "description": "position", "type": "scalar", "value": 0.0 }, "signal": { "connections": [{"output": "signal", "subsystem": "wave_sys"}], "description": "signal from wave", "type": "scalar", "value": 0.0 } } }, "stores": [], "subsystems": { "msd": { "connections": [], "inputs": {"b": 80.0, "f": 0.0, "k": 50.0, "m": 50.0}, "module": "pysim.systems.defaultsystemcollection1", "stores": [], "type": "MassSpringDamper" }, "wave_sys": { "connections": [["signal", "msd", "f"]], "inputs": {"amplitude": 50.0, "freq": 0.1, "phaseRad": 0.0}, "module": "pysim.systems.defaultsystemcollection1", "stores": [], "type": "SquareWave" } } } } } """ sim = Sim() file = tempfile.NamedTemporaryFile(delete=False, mode="w+") file.write(JSON_STRING) file.close() sim.load_config(file.name) sim.simulate(2, 0.1) assert np.abs(sim.systems["controlled_spring"].outputs.out - 0.3240587706226495) < 1e-10