"addI") session.addFMU("PI_Controller", "../FMUs/Modelica.Blocks.Continuous.Integrator.fmu", "I") session.addFMU("PI_Controller", "../FMUs/Modelica.Blocks.Math.Add.fmu", "addPI") session.addFMU("PI_Controller", "../FMUs/Modelica.Blocks.Math.Gain.fmu", "gainPI") session.addFMU("PI_Controller", "../FMUs/Modelica.Blocks.Nonlinear.Limiter.fmu", "limiter") session.addFMU("PI_Controller", "../FMUs/Modelica.Blocks.Math.Add.fmu", "addSat") session.addFMU("PI_Controller", "../FMUs/Modelica.Blocks.Math.Gain.fmu", "gainTrack") # add connections session.addConnection("PI_Controller", "addP:y", "P:u") session.addConnection("PI_Controller", "addI:y", "I:u") session.addConnection("PI_Controller", "P:y", "addPI:u1") session.addConnection("PI_Controller", "I:y", "addPI:u2") session.addConnection("PI_Controller", "addPI:y", "gainPI:u") session.addConnection("PI_Controller", "gainPI:y", "limiter:u") session.addConnection("PI_Controller", "gainPI:y", "addSat:u2") session.addConnection("PI_Controller", "limiter:y", "addSat:u1") session.addConnection("PI_Controller", "addSat:y", "gainTrack:u") session.addConnection("PI_Controller", "gainTrack:y", "addI:u3") # parameters k = 100.0 yMax = 12.0 yMin = -yMax wp = 1.0
from OMSimulator import OMSimulator session = OMSimulator() session.setLogFile("omsllog.txt") session.setTempDirectory(".") model = session.newModel() ## instantiate FMUs session.instantiateFMU(model, "../FMUs/me_source1.fmu", "sourceA") session.instantiateFMU(model, "../FMUs/me_source1.fmu", "sourceB") session.instantiateFMU(model, "../FMUs/me_adder1.fmu", "adder") ## add connections session.addConnection(model, "sourceA.y", "adder.x1") session.addConnection(model, "sourceB.y", "adder.x2") ## set parameter session.setReal(model, "sourceA.A", 0.5) session.setReal(model, "sourceA.omega", 2.0) session.setStartTime(model, 0.0) session.setStopTime(model, 10.0) session.setTolerance(model, 1e-5) session.exportXML(model, "ImportExport.xml") session.unload(model) model2 = session.loadModel("ImportExport.xml") session.describe(model2)
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, oms.signal_type_integer) status = oms.addConnector("model.wc.sc2.y3", oms.output, oms.signal_type_real) printStatus(status, 0) status = oms.addConnection("model.wc.sc1.u1", "model.wc.sc2.y1") printStatus(status, 0) ## Connecting input to input (illegal) status = oms.addConnection("model.wc.sc1.y", "model.wc.sc2.y3") printStatus(status, 3) ## Connecting Real to Integer (illegal) status = oms.addConnection("model.wc.sc1.u2", "model.wc.sc2.y2") printStatus(status, 3) ## Connecting to already connected connector (illegal) status = oms.addConnection("model.wc.sc1.u1", "model.wc.sc2.y3") printStatus(status, 3) src, status = oms.list("model.wc")
## status: correct from OMSimulator import OMSimulator session = OMSimulator() session.setLogFile("omsllog.txt") model = session.newModel() session.setTempDirectory(".") session.instantiateFMU(model, "../FMUs/cs.loop1.A.fmu", "A") session.instantiateFMU(model, "../FMUs/cs.loop1.B.fmu", "B") session.instantiateFMU(model, "../FMUs/cs.loop1.P.fmu", "P") # add connections session.addConnection(model, "A.y", "B.u") session.addConnection(model, "B.y", "A.u") session.addConnection(model, "P.y", "A.p") session.addConnection(model, "P.y", "B.p") session.setResultFile(model, "cs_loop1_res.mat") session.setStopTime(model, 0.5) session.setCommunicationInterval(model, 1e-2) session.setTolerance(model, 1e-6) session.describe(model) session.initialize(model) session.simulate(model) session.terminate(model)
printStatus(status, 0) status = oms.addBus("test.eoo.foo2.bus") printStatus(status, 0) status = oms.addConnectorToBus("test.eoo.foo2.bus", "test.eoo.foo2.u1") printStatus(status, 0) status = oms.addConnectorToBus("test.eoo.foo2.bus", "test.eoo.foo2.u2") printStatus(status, 0) status = oms.addTLMConnection("test.eoo.foo.tlm", "test.eoo.foo2.tlm", 0.001, 0.3, 100, 0) printStatus(status, 0) status = oms.addConnection("test.eoo.foo.y1", "test.eoo.foo2.u1") printStatus(status, 0) status = oms.addConnection("test.eoo.foo.y2", "test.eoo.foo2.u2") printStatus(status, 0) status = oms.addConnection("test.eoo.foo.bus", "test.eoo.foo2.bus") printStatus(status, 0) status, src = oms.list("test") printStatus(status, 0) print(src) status = oms.export("test", "test-py.ssp") printStatus(status, 0)
## teardown_command: rm DualMassOscillator_cs.log DualMassOscillator_cs.mat from OMSimulator import OMSimulator session = OMSimulator() session.setLogFile("DualMassOscillator_cs.log") session.newFMIModel("DualMassOscillator") session.setTempDirectory("./DualMassOscillator_cs_tmp") # instantiate FMUs session.addFMU("DualMassOscillator", "../FMUs/DualMassOscillator.System1_cs.fmu", "System1") session.addFMU("DualMassOscillator", "../FMUs/DualMassOscillator.System2_cs.fmu", "System2") # add connections session.addConnection("DualMassOscillator", "System1:F", "System2:F") session.addConnection("DualMassOscillator", "System1:s", "System2:s") session.addConnection("DualMassOscillator", "System1:v", "System2:v") session.addConnection("DualMassOscillator", "System1:a", "System2:a") session.setResultFile("DualMassOscillator", "DualMassOscillator_cs.mat") session.setStopTime("DualMassOscillator", 0.1) session.setCommunicationInterval("DualMassOscillator", 1e-5) session.initialize("DualMassOscillator") session.simulate("DualMassOscillator") (_, tcur) = session.getCurrentTime("DualMassOscillator") vars = ["DualMassOscillator.System1:mass1.s", "DualMassOscillator.System2:mass2.s"] for var in vars:
status = oms.addConnectorToBus("model.tlm.wc1.bus1", "model.tlm.wc2.y1") printStatus(status, 3) status = oms.addConnectorToBus("model.tlm.wc1.bus1", "model.tlm.wc1.y") printStatus(status, 0) status = oms.addBus("model.tlm.wc2.bus2") printStatus(status, 0) status = oms.addConnectorToBus("model.tlm.wc2.bus2", "model.tlm.wc2.y1") printStatus(status, 0) status = oms.addConnectorToBus("model.tlm.wc2.bus2", "model.tlm.wc2.y2") printStatus(status, 0) status = oms.addConnection("model.tlm.wc1.u1", "model.tlm.wc2.y1") printStatus(status, 0) status = oms.addConnection("model.tlm.wc1.bus1", "model.tlm.wc2.bus2") printStatus(status, 0) status = oms.addConnection("model.tlm.wc1.u2", "model.tlm.wc2.y2") printStatus(status, 0) status = oms.addConnection("model.tlm.wc2.bus2", "model.tlm.wc1.bus1") printStatus(status, 3) src, status = oms.list("model.tlm") print(src, flush=True) status = oms.deleteConnectorFromBus("model.tlm.wc1.bus1", "model.tlm.wc1.y")
from OMSimulator import OMSimulator session=OMSimulator() session.setLogFile("omsllog.txt") model = session.newModel() session.setTempDirectory(".") # instantiate FMUs session.instantiateFMU(model, "../FMUs/me_source1.fmu", "sourceA") session.instantiateFMU(model, "../FMUs/me_source1.fmu", "sourceB") session.instantiateFMU(model, "../FMUs/me_adder1.fmu", "adder1") session.instantiateFMU(model, "../FMUs/me_adder1.fmu", "adder2") # add connections session.addConnection(model, "sourceA.y", "adder1.x1") session.addConnection(model, "sourceB.y", "adder1.x2") session.addConnection(model, "adder1.y", "adder2.x1") session.addConnection(model, "sourceB.y", "adder2.x2") # set parameter session.setReal(model, "sourceA.A", 0.5) session.setReal(model, "sourceA.omega", 2.0) session.setStopTime(model, 10.0) session.describe(model) session.initialize(model) session.stepUntil(model, 10.0)
oms.newFMIModel("RealNetwork1") oms.setTempDirectory("./RealNetwork1_tmp") # instantiate FMUs oms.addFMU("RealNetwork1", "../FMUs/Modelica.Blocks.Math.Add.fmu", "add") oms.addFMU("RealNetwork1", "../FMUs/Modelica.Blocks.Math.Feedback.fmu", "feedback") oms.addFMU("RealNetwork1", "../FMUs/Modelica.Blocks.Math.Gain.fmu", "gain") oms.addFMU("RealNetwork1", "../FMUs/Modelica.Blocks.Math.Product.fmu", "product") oms.addFMU("RealNetwork1", "../FMUs/Modelica.Blocks.Sources.Clock.fmu", "clock") oms.addFMU("RealNetwork1", "../FMUs/Modelica.Blocks.Sources.Constant.fmu", "constant") oms.addFMU("RealNetwork1", "../FMUs/Modelica.Blocks.Sources.Sine.fmu", "sine") oms.addFMU("RealNetwork1", "../FMUs/Modelica.Blocks.Sources.Step.fmu", "step") # add connections oms.addConnection("RealNetwork1", "clock:y", "product:u1") oms.addConnection("RealNetwork1", "constant:y", "add:u2") oms.addConnection("RealNetwork1", "feedback:y", "add:u1") oms.addConnection("RealNetwork1", "gain:y", "feedback:u1") oms.addConnection("RealNetwork1", "product:y", "gain:u") oms.addConnection("RealNetwork1", "sine:y", "feedback:u2") oms.addConnection("RealNetwork1", "step:y", "product:u2") # parameters oms.setReal("RealNetwork1.clock:offset", 0.0) oms.setReal("RealNetwork1.clock:startTime", 0.0) oms.setReal("RealNetwork1.step:height", 3.0) oms.setReal("RealNetwork1.step:offset", 1.0) oms.setReal("RealNetwork1.step:startTime", 3.0) oms.setReal("RealNetwork1.gain:k", 1e-1) oms.setReal("RealNetwork1.sine:amplitude", 1.0)
# instantiate FMUs oms.instantiateFMU(model, "../FMUs/Modelica.Blocks.Math.Add.fmu", "add") oms.instantiateFMU(model, "../FMUs/Modelica.Blocks.Math.Feedback.fmu", "feedback") oms.instantiateFMU(model, "../FMUs/Modelica.Blocks.Math.Gain.fmu", "gain") oms.instantiateFMU(model, "../FMUs/Modelica.Blocks.Math.Product.fmu", "product") oms.instantiateFMU(model, "../FMUs/Modelica.Blocks.Sources.Clock.fmu", "clock") oms.instantiateFMU(model, "../FMUs/Modelica.Blocks.Sources.Constant.fmu", "constant") oms.instantiateFMU(model, "../FMUs/Modelica.Blocks.Sources.Sine.fmu", "sine") oms.instantiateFMU(model, "../FMUs/Modelica.Blocks.Sources.Step.fmu", "step") # add connections oms.addConnection(model, "clock.y", "product.u1") oms.addConnection(model, "constant.y", "add.u2") oms.addConnection(model, "feedback.y", "add.u1") oms.addConnection(model, "gain.y", "feedback.u1") oms.addConnection(model, "product.y", "gain.u") oms.addConnection(model, "sine.y", "feedback.u2") oms.addConnection(model, "step.y", "product.u2") # parameters oms.setReal(model, "clock.offset", 0.0) oms.setReal(model, "clock.startTime", 0.0) oms.setReal(model, "step.height", 3.0) oms.setReal(model, "step.offset", 1.0) oms.setReal(model, "step.startTime", 3.0) oms.setReal(model, "gain.k", 1e-1) oms.setReal(model, "sine.amplitude", 1.0)
from OMSimulator import OMSimulator session = OMSimulator() session.setLogFile("omsllog.txt") model = session.newModel() session.setTempDirectory(".") # instantiate FMUs session.instantiateFMU(model, "../FMUs/DualMassOscillator.System1_cs.fmu", "System1") session.instantiateFMU(model, "../FMUs/DualMassOscillator.System2_cs.fmu", "System2") # add connections session.addConnection(model, "System1.F", "System2.F") session.addConnection(model, "System1.s", "System2.s") session.addConnection(model, "System1.v", "System2.v") session.addConnection(model, "System1.a", "System2.a") session.setResultFile(model, "DualMassOscillator_cs.mat") session.setStopTime(model, 0.1) session.setCommunicationInterval(model, 1e-5) session.initialize(model) session.simulate(model) tcur = session.getCurrentTime(model) vars = ["System1.mass1.s", "System2.mass2.s"] for var in vars:
session = OMSimulator() version = session.getVersion() session.setLogFile("HelloWorld_cs_Fit_py.log") session.setTempDirectory(".") model = "HelloWorld_cs_Fit" session.newFMIModel(model) # session.setTolerance(model, 1e-5) # 2018-04-25 Not yet supported in oms2 API # add FMU session.addFMU(model, "../FMUs/HelloWorld_cs.fmu", "HelloWorld") # add solver session.addSolver(model, "solver1", "internal") session.addConnection(model, "HelloWorld", "solver1") # create simodel for model simodel = OMSysIdent(model) # 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 = ["HelloWorld:x"] data_x = np.array([ 1, 0.9, 0.8100000000000001, 0.7290000000000001, 0.6561, 0.5904900000000001, 0.5314410000000001, 0.4782969000000001, 0.43046721, 0.387420489, 0.3486784401