Beispiel #1
0
def test_store_connections():
    """Test that it is possible to store connections in a config file"""
    sim = Sim()
    wave_sys = SquareWave()
    wave_sys.inputs.amplitude = 50
    wave_sys.inputs.freq = 0.1
    sim.add_system(wave_sys,"wave_sys")

    msd = MassSpringDamper()
    msd.inputs.b = 80
    msd.inputs.m = 50
    msd.inputs.f = 0
    sim.add_system(msd,"msd")

    wave_sys.connections.add_connection("signal", msd, "f")

    # In this test a temp file is used, it should be deleted automatically
    # after the test.
    file = tempfile.NamedTemporaryFile()
    file.close()
    sim.save_config(file.name)

    file2 = open(file.name)
    simdict = json.load(file2)
    file2.close()
    print(simdict)

    cons = simdict["systems"]["wave_sys"]["connections"]
    assert cons[0] == ["signal", "msd", "f"]
Beispiel #2
0
def test_store_connections():
    """Test that it is possible to store connections in a config file"""
    sim = Sim()
    wave_sys = SquareWave()
    wave_sys.inputs.amplitude = 50
    wave_sys.inputs.freq = 0.1
    sim.add_system(wave_sys, "wave_sys")

    msd = MassSpringDamper()
    msd.inputs.b = 80
    msd.inputs.m = 50
    msd.inputs.f = 0
    sim.add_system(msd, "msd")

    wave_sys.connections.add_connection("signal", msd, "f")

    # In this test a temp file is used, it should be deleted automatically
    # after the test.
    file = tempfile.NamedTemporaryFile()
    file.close()
    sim.save_config(file.name)

    file2 = open(file.name)
    simdict = json.load(file2)
    file2.close()
    print(simdict)

    cons = simdict["systems"]["wave_sys"]["connections"]
    assert cons[0] == ["signal", "msd", "f"]
Beispiel #3
0
def test_store_config_composite_ports():
    """Test that it is possible to store the ports of a composite systems
    to a file.
    """

    sys = CompositeSpring()
    sim = Sim()
    sim.add_system(sys, "composite_root")

    # In this test a temp file is used, it should be deleted automatically
    # after the test.
    file = tempfile.NamedTemporaryFile()
    file.close()
    sim.save_config(file.name)

    file2 = open(file.name)
    simdict = json.load(file2)
    file2.close()
    print(simdict)

    ports = simdict["systems"]["composite_root"]["ports"]
    forceport = ports["in"]["force"]
    assert forceport["type"] == "scalar"
    assert forceport["value"] == 0
    assert forceport["description"] == "force acting on mass"
    assert forceport["connections"][0]["subsystem"] == "msd"
    assert forceport["connections"][0]["input"] == "f"

    posport = ports["out"]["position"]
    assert posport["type"] == "scalar"
    assert posport["value"] == 0
    assert posport["description"] == "Position"
    assert posport["connections"][0]["subsystem"] == "msd"
    assert posport["connections"][0]["output"] == "x1"
Beispiel #4
0
def test_store_config_composite_ports():
    """Test that it is possible to store the ports of a composite systems
    to a file.
    """

    sys = CompositeSpring()
    sim = Sim()
    sim.add_system(sys, "composite_root")

    # In this test a temp file is used, it should be deleted automatically
    # after the test.
    file = tempfile.NamedTemporaryFile()
    file.close()
    sim.save_config(file.name)

    file2 = open(file.name)
    simdict = json.load(file2)
    file2.close()
    print(simdict)

    ports = simdict["systems"]["composite_root"]["ports"]
    forceport = ports["in"]["force"]
    assert forceport["type"] == "scalar"
    assert forceport["value"] == 0
    assert forceport["description"] == "force acting on mass"
    assert forceport["connections"][0]["subsystem"] == "msd"
    assert forceport["connections"][0]["input"] == "f"

    posport = ports["out"]["position"]
    assert posport["type"] == "scalar"
    assert posport["value"] == 0
    assert posport["description"] == "Position"
    assert posport["connections"][0]["subsystem"] == "msd"
    assert posport["connections"][0]["output"] == "x1"
Beispiel #5
0
def test_store_config(test_class):
    """Test that it is possible to store the simulation to a file.
    """
    sys = test_class()
    sim = Sim()
    sim.add_system(sys)
    sys.inputs.a = 1.234
    sys.store("x")

    # In this test a temp file is used, it should be deleted automatically
    # after the test.
    file = tempfile.NamedTemporaryFile()
    file.close()
    sim.save_config(file.name)

    file2 = open(file.name)
    simdict = json.load(file2)
    file2.close()
    assert simdict["systems"]["vanderpol"]["inputs"]["a"] == 1.234
    assert "x" in simdict["systems"]["vanderpol"]["stores"]
Beispiel #6
0
def test_store_config(test_class):
    """Test that it is possible to store the simulation to a file.
    """
    sys = test_class()
    sim = Sim()
    sim.add_system(sys)
    sys.inputs.a = 1.234
    sys.store("x")

    # In this test a temp file is used, it should be deleted automatically
    # after the test.
    file = tempfile.NamedTemporaryFile()
    file.close()
    sim.save_config(file.name)

    file2 = open(file.name)
    simdict = json.load(file2)
    file2.close()
    assert simdict["systems"]["vanderpol"]["inputs"]["a"] == 1.234
    assert "x" in simdict["systems"]["vanderpol"]["stores"]
Beispiel #7
0
def test_store_connections_composite():
    """Test that it is possible to store subsystem connections
    in a config file.
    """
    sim = Sim()
    sys = ControlledSpring()
    sim.add_system(sys, "controlled_spring")

    # In this test a temp file is used, it should be deleted automatically
    # after the test.
    file = tempfile.NamedTemporaryFile()
    file.close()
    sim.save_config(file.name)

    file2 = open(file.name)
    simdict = json.load(file2)
    file2.close()
    print(simdict)


    cons = simdict["systems"]["controlled_spring"]["subsystems"]["wave_sys"]["connections"]
    assert cons[0] == ["signal", "msd", "f"]
Beispiel #8
0
def test_store_connections_composite():
    """Test that it is possible to store subsystem connections
    in a config file.
    """
    sim = Sim()
    sys = ControlledSpring()
    sim.add_system(sys, "controlled_spring")

    # In this test a temp file is used, it should be deleted automatically
    # after the test.
    file = tempfile.NamedTemporaryFile()
    file.close()
    sim.save_config(file.name)

    file2 = open(file.name)
    simdict = json.load(file2)
    file2.close()
    print(simdict)

    cons = simdict["systems"]["controlled_spring"]["subsystems"]["wave_sys"][
        "connections"]
    assert cons[0] == ["signal", "msd", "f"]