else: cmp = "wrong" if 0 == status: status = "ok" elif 1 == status: status = "warning" elif 3 == status: status = "error" print("status: [%s] %s" % (cmp, status), flush=True) status = oms.newModel("test") printStatus(status, 0) status = oms.addSystem("test.co_sim", oms.system_wc) printStatus(status, 0) status = oms.addSubModel("test.co_sim.A", "../resources/tlm.source.fmu") printStatus(status, 0) status = oms.addSubModel("test.co_sim.B", "../resources/tlm.source.fmu") printStatus(status, 0) oms.exportDependencyGraphs("test.co_sim", "test_init.dot", "test_sim.dot") oms.setResultFile("test", "test.mat") status = oms.instantiate("test") printStatus(status, 0)
## teardown_command: rm -rf snapshot_py/ ## linux: yes ## mingw32: yes ## mingw64: yes ## win: yes ## mac: no from OMSimulator import OMSimulator oms = OMSimulator() oms.setCommandLineOption("--suppressPath=true") oms.setTempDirectory("./snapshot_py/") oms.setWorkingDirectory("./snapshot_py/") oms.newModel("snapshot") oms.addSystem("snapshot.root", oms.system_wc) oms.newResources("snapshot.root:snapshot.ssv") oms.addConnector("snapshot.root.C1", oms.input, oms.signal_type_real) oms.setReal("snapshot.root.C1", -10) oms.addSubModel("snapshot.root.add", "../../resources/Modelica.Blocks.Math.Add.fmu") oms.setReal("snapshot.root.add.u1", 10) oms.setReal("snapshot.root.add.k1", 30) snapshot, status = oms.exportSnapshot("snapshot") ##print(snapshot, flush=True) oms.setReal("snapshot.root.add.u1", 3.5)
cmp = "correct" else: cmp = "wrong" if 0 == status: status = "ok" elif 1 == status: status = "warning" elif 3 == status: status = "error" print("status: [%s] %s" % (cmp, status), flush=True) oms.newModel("test") oms.addSystem("test.eoo", oms.system_wc) oms.addSubModel("test.eoo.source", "../resources/Modelica.Blocks.Sources.Sine.fmu") ## save snapshot src, status = oms.list("test") print(src, flush=True) ## change model oms.addSystem("test.eoo.goo", oms.system_sc) oms.delete("test.eoo.source") oms.addSubModel("test.eoo.source", "../resources/Modelica.Blocks.Sources.Constant.fmu") ## restore model from snapshot status = oms.loadSnapshot("test", src) printStatus(status, 0)
if status == expected: cmp = "correct" else: cmp = "wrong" if 0 == status: status = "ok" elif 1 == status: status = "warning" elif 3 == status: status = "error" print "status: [%s] %s" % (cmp, status) oms.newModel("model") oms.addSystem("model.tlm", oms.system_tlm) oms.setTLMSocketData("model.tlm", "127.0.1.1", 11111, 11121) oms.addSystem("model.tlm.wc1", oms.system_wc) oms.addConnector("model.tlm.wc1.y", oms.output, oms.signal_type_real) oms.addConnector("model.tlm.wc1.x", oms.output, oms.signal_type_real) oms.addConnector("model.tlm.wc1.v", oms.output, oms.signal_type_real) oms.addConnector("model.tlm.wc1.f", oms.input, oms.signal_type_real) oms.addSystem("model.tlm.wc2", oms.system_wc) oms.addConnector("model.tlm.wc2.y", oms.input, oms.signal_type_real) oms.addConnector("model.tlm.wc2.x", oms.output, oms.signal_type_real) oms.addConnector("model.tlm.wc2.v", oms.output, oms.signal_type_real) oms.addConnector("model.tlm.wc2.f", oms.input, oms.signal_type_real) status = oms.addTLMBus("model.tlm.wc1.bus1", oms.tlm_domain_input, 1, oms.default)
if 0 == status: status = "ok" elif 1 == status: status = "warning" elif 3 == status: status = "error" print "status: [%s] %s" % (cmp, status) status = oms.setTempDirectory("./externalmodels-py/") printStatus(status, 0) status = oms.newModel("model") printStatus(status, 0) status = oms.addSystem("model.tlm", oms.system_tlm) printStatus(status, 0) status = oms.addExternalModel("model.tlm.external", "resources/external.mo", "resources/startscript.sh") printStatus(status, 0) status = oms.addTLMBus("model.tlm.external.tlmbus", oms.tlm_domain_mechanical, 1, oms.default) status, src = oms.list("model.tlm") print(src) status = oms.delete("model") printStatus(status, 0)
## status: correct ## teardown_command: rm HelloWorld_cs_Fit_py.log HelloWorld_cs_Fit_res.mat from OMSimulator import OMSimulator from OMSysIdent import OMSysIdent import numpy as np oms = OMSimulator() oms.setLogFile("HelloWorld_cs_Fit_py.log") oms.setTempDirectory("./HelloWorld_cs_Fit_py/") oms.newModel("HelloWorld_cs_Fit") oms.addSystem("HelloWorld_cs_Fit.root", oms.system_wc) # oms.setTolerance("HelloWorld_cs_Fit.root", 1e-5) # add FMU oms.addSubModel("HelloWorld_cs_Fit.root.HelloWorld", "../resources/HelloWorld.fmu") # create simodel for model simodel = OMSysIdent("HelloWorld_cs_Fit") # simodel.describe() # Data generated from simulating HelloWorld.mo for 1.0s with Euler and 0.1s step size kNumSeries = 1 kNumObservations = 11 data_time = np.array([0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]) inputvars = [] measurementvars = ["root.HelloWorld.x"] data_x = np.array([ 1, 0.9, 0.8100000000000001, 0.7290000000000001, 0.6561, 0.5904900000000001,
else: cmp = "wrong" if 0 == status: status = "ok" elif 1 == status: status = "warning" elif 3 == status: status = "error" print "status: [%s] %s" % (cmp, status) status = oms.newModel("model") printStatus(status, 0) status = oms.addSystem("model.sc", oms.system_sc) printStatus(status, 0) src, status = oms.list("model") printStatus(status, 0) print(src) status = oms.export("model", "model.ssp") printStatus(status, 0) status = oms.export("model", "model.ssp") printStatus(status, 0) ## Result: ## status: [correct] ok ## status: [correct] ok
if 0 == status: status = "ok" elif 1 == status: status = "warning" elif 3 == status: status = "error" print("status: [%s] %s" % (cmp, status), flush=True) status = oms.setTempDirectory("./connections-py/") printStatus(status, 0) status = oms.newModel("model") printStatus(status, 0) status = oms.addSystem("model.wc", oms.system_wc) printStatus(status, 0) status = oms.addSystem("model.wc.sc1", oms.system_sc) printStatus(status, 0) status = oms.addSystem("model.wc.sc2", oms.system_sc) printStatus(status, 0) status = oms.addConnector("model.wc.sc1.u1", oms.input, oms.signal_type_real) status = oms.addConnector("model.wc.sc1.u2", oms.input, oms.signal_type_real) status = oms.addConnector("model.wc.sc1.y", oms.output, oms.signal_type_real) printStatus(status, 0) status = oms.addConnector("model.wc.sc2.y1", oms.output, oms.signal_type_real) status = oms.addConnector("model.wc.sc2.y2", oms.output,
## linux: no ## mingw32: no ## mingw64: yes ## win: yes ## mac: no from OMSimulator import OMSimulator oms = OMSimulator() oms.setCommandLineOption("--suppressPath=true") oms.setTempDirectory("./getDirectionalDerivative_ME_py/") oms.newModel("model") oms.addSystem("model.root", oms.system_sc) oms.addSubModel("model.root.CauerLowPassAnalog", "../resources/Modelica.Electrical.Analog.Examples.CauerLowPassAnalog.fmu") oms.setResultFile("model", "getDirectionalDerivatives_ME_Py.mat", 10) oms.instantiate("model") oms.initialize("model") ## error msg for wrong cref oms.getDirectionalDerivative("model.root.CauerLowPassAnalog.der(C1.v2)") print("info: Partial Derivatives after Initialization") print("info: model.root.CauerLowPassAnalog.der(C1.v): " , oms.getDirectionalDerivative("model.root.CauerLowPassAnalog.der(C1.v)")[0]) print("info: model.root.CauerLowPassAnalog.der(C3.v): " , oms.getDirectionalDerivative("model.root.CauerLowPassAnalog.der(C3.v)")[0]) print("info: model.root.CauerLowPassAnalog.der(C5.v): " , oms.getDirectionalDerivative("model.root.CauerLowPassAnalog.der(C5.v)")[0])
oms.setCommandLineOption("--suppressPath=true") oms.setTempDirectory("./exportssvtemplate_py/") def readFile(filename): f = open(filename, "r") content = f.read() print(content) f:close() oms.newModel("test") oms.addSystem("test.Root", oms.system_wc) oms.addSubModel("test.Root.Gain", "../resources/Modelica.Blocks.Math.Gain.fmu") oms.addSubModel("test.Root.add", "../resources/Modelica.Blocks.Math.Add.fmu") oms.exportSSVTemplate("test", "template.ssv") readFile("template.ssv") oms.exportSSVTemplate("test.Root.add", "add.ssv") readFile("add.ssv") oms.exportSSVTemplate("test.Root.Gain", "gain.ssv") readFile("gain.ssv") ## Result:
else: cmp = "wrong" if 0 == status: status = "ok" elif 1 == status: status = "warning" elif 3 == status: status = "error" print "status: [%s] %s" % (cmp, status) status = oms.newModel("test") printStatus(status, 0) status = oms.addSystem("test.eoo", oms.system_tlm) printStatus(status, 0) status = oms.setTLMSocketData("test.eoo", "127.0.1.1", 11111, 11121) status = oms.addSystem("test.eoo.foo", oms.system_wc) printStatus(status, 0) ## CS FMU status = oms.addSubModel("test.eoo.foo.A", "../resources/tlm.source.fmu") printStatus(status, 0) ## table status = oms.addSubModel("test.eoo.foo.T", "../resources/setpoint.csv") printStatus(status, 0)
cmp = "wrong" if 0 == status: status = "ok" elif 1 == status: status = "warning" elif 3 == status: status = "error" print("status: [%s] %s" % (cmp, status), flush=True) status = oms.setTempDirectory("./buses-py/") printStatus(status, 0) status = oms.newModel("model") status = oms.addSystem("model.tlm", oms.system_tlm) status = oms.addSystem("model.tlm.wc1", oms.system_wc) status = oms.addSystem("model.tlm.wc2", oms.system_wc) status = oms.addConnector("model.tlm.wc1.u1", oms.input, oms.signal_type_real) status = oms.addConnector("model.tlm.wc1.u2", oms.input, oms.signal_type_real) status = oms.addConnector("model.tlm.wc1.y", oms.output, oms.signal_type_real) status = oms.addConnector("model.tlm.wc2.y1", oms.output, oms.signal_type_real) status = oms.addConnector("model.tlm.wc2.y2", oms.output, oms.signal_type_real) status = oms.addConnector("model.tlm.wc2.y3", oms.output, oms.signal_type_real) status = oms.addBus("model.tlm.wc1.bus1") printStatus(status, 0) status = oms.addConnectorToBus("model.tlm.wc1.bus1", "model.tlm.wc1.u1") printStatus(status, 0) status = oms.addConnectorToBus("model.tlm.wc1.bus1", "model.tlm.wc1.u2")
## teardown_command: rm -rf HelloWorldWithInput_cs_Fit/ HelloWorldWithInput_cs_Fit.log HelloWorldWithInput_cs_Fit_res.csv ## linux: yes ## mingw: no ## win: no ## mac: no from OMSimulator import OMSimulator from OMSysIdent import OMSysIdent import numpy as np oms = OMSimulator() oms.setLogFile("HelloWorldWithInput_cs_Fit.log") oms.setTempDirectory("./HelloWorldWithInput_cs_Fit/") oms.newModel("HelloWorldWithInput_cs_Fit") oms.addSystem("HelloWorldWithInput_cs_Fit.root", oms.system_wc) oms.setFixedStepSize("HelloWorldWithInput_cs_Fit.root", 1e-1) oms.setTolerance("HelloWorldWithInput_cs_Fit.root", 1e-5, 1e-5) oms.setResultFile("HelloWorldWithInput_cs_Fit", ""); # add FMU status = oms.addSubModel("HelloWorldWithInput_cs_Fit.root.HelloWorldWithInput", "../resources/HelloWorldWithInput.fmu") # create system identification model for model simodel = OMSysIdent("HelloWorldWithInput_cs_Fit") # simodel.describe() # Data generated from simulating HelloWorldWithInput.mo for 1.0s with Euler and 0.1s step size kNumSeries = 1; kNumObservations = 11;
## linux: yes ## mingw32: yes ## mingw64: yes ## win: yes ## mac: no from OMSimulator import OMSimulator oms = OMSimulator() oms.setCommandLineOption("--suppressPath=true") oms.setTempDirectory("./addExternalResources3_lua/") oms.setWorkingDirectory("./addExternalResources3_lua/") oms.newModel("addExternalResources") oms.addSystem("addExternalResources.root", oms.system_wc) oms.addConnector("addExternalResources.root.Input1", oms.input, oms.signal_type_real) oms.addConnector("addExternalResources.root.Input2", oms.input, oms.signal_type_real) ## add Top level resources oms.newResources("addExternalResources.root:root.ssv") oms.setReal("addExternalResources.root.Input1", 10) oms.setReal("addExternalResources.root.Input2", 50) oms.addSystem("addExternalResources.root.system1", oms.system_sc) oms.addConnector("addExternalResources.root.system1.C1", oms.input, oms.signal_type_real) oms.addConnector("addExternalResources.root.system1.C2", oms.input, oms.signal_type_real) ## add resources to subsystem oms.newResources("addExternalResources.root.system1:system1.ssv")
#!/usr/bin/python3 from OMSimulator import OMSimulator if __name__ == '__main__': oms = OMSimulator() oms.newModel('model') oms.addSystem('model.root', oms.system_sc) oms.addSubModel('model.root.system1', 'Cirship.fmu') oms.instantiate('model') oms.initialize('model') oms.stepUntil('model', 0.5) print(oms.getReal('model.root.system1.resistor.i')) oms.setReal('model.root.system1.b1Open', 1) oms.stepUntil('model', 1.0) oms.setReal('model.root.system1.b1Open', 0) oms.stepUntil('model', 1.1) print(oms.getReal('model.root.system1.resistor.i')) oms.terminate('model') oms.delete('model')