示例#1
0
status = oms.instantiate("test")
printStatus(status, 0)

v, status = oms.getReal("test.co_sim.A.A")
printStatus(status, 0)
print("test.co_sim.A.A: %g" % v, flush=True)

status = oms.setReal("test.co_sim.A.A", v + 1.0)
printStatus(status, 0)

v, status = oms.getReal("test.co_sim.A.A")
printStatus(status, 0)
print("test.co_sim.A.A: %g" % v, flush=True)

status = oms.initialize("test")
printStatus(status, 0)

v, status = oms.getReal("test.co_sim.A.y")
printStatus(status, 0)
print("test.co_sim.A.y: %g" % v, flush=True)

status = oms.simulate("test")
printStatus(status, 0)

v, status = oms.getReal("test.co_sim.A.y")
printStatus(status, 0)
print("test.co_sim.A.y: %g" % v, flush=True)

status = oms.terminate("test")
printStatus(status, 0)
示例#2
0
session.addTable("PI_Controller", "setpoint.csv", "setpoint")
session.addTable("PI_Controller", "drivetrain.csv", "driveTrain")

# add connections
session.addConnection("PI_Controller", "setpoint:speed", "addP:u1")
session.addConnection("PI_Controller", "setpoint:speed", "addI:u1")

session.addConnection("PI_Controller", "driveTrain:w", "addP:u2")
session.addConnection("PI_Controller", "driveTrain:w", "addI:u2")

# simulation settings
session.setResultFile("PI_Controller", "PI_Controller.mat")

# simulation
print("info:    Initialization")
session.initialize("PI_Controller")
print("info:      limiter.u: " +
      str(session.getReal("PI_Controller.limiter:u")[1]))
print("info:      limiter.y: " +
      str(session.getReal("PI_Controller.limiter:y")[1]))

print("info:    Simulation")
session.simulate("PI_Controller")
print("info:      limiter.u: " +
      str(session.getReal("PI_Controller.limiter:u")[1]))
print("info:      limiter.y: " +
      str(session.getReal("PI_Controller.limiter:y")[1]))

session.unloadModel("PI_Controller")

vars = ["limiter.u", "limiter.y"]
示例#3
0
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)

src, status = oms.list("test")
print(src, flush=True)

oms.instantiate("test")
oms.initialize("test")
oms.simulate("test")
oms.terminate("test")

oms.delete("test")


## Result:
## <?xml version="1.0"?>
## <ssd:SystemStructureDescription xmlns:ssc="http://ssp-standard.org/SSP1/SystemStructureCommon" xmlns:ssd="http://ssp-standard.org/SSP1/SystemStructureDescription" xmlns:ssv="http://ssp-standard.org/SSP1/SystemStructureParameterValues" xmlns:ssm="http://ssp-standard.org/SSP1/SystemStructureParameterMapping" xmlns:ssb="http://ssp-standard.org/SSP1/SystemStructureSignalDictionary" xmlns:oms="https://raw.githubusercontent.com/OpenModelica/OMSimulator/master/schema/oms.xsd" name="test" version="1.0">
## 	<ssd:System name="eoo">
## 		<ssd:Elements>
## 			<ssd:Component name="source" type="application/x-fmu-sharedlibrary" source="resources/0001_source.fmu">
## 				<ssd:Connectors>
## 					<ssd:Connector name="y" kind="output">
## 						<ssc:Real />
示例#4
0
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])
print("info:      model.root.CauerLowPassAnalog.der(L1.i): " , oms.getDirectionalDerivative("model.root.CauerLowPassAnalog.der(L1.i)")[0])
print("info:      model.root.CauerLowPassAnalog.der(L2.i): " , oms.getDirectionalDerivative("model.root.CauerLowPassAnalog.der(L2.i)")[0])


oms.terminate("model")
oms.delete("model")

## Result:
from OMSimulator import OMSimulator
session = OMSimulator()

session.setLogFile("omsllog.txt")

model = session.newModel()
session.setTempDirectory(".")

session.instantiateFMU(model, "../FMUs/cs_test1.fmu", "test1")
session.describe(model)

session.setStopTime(model, 2.1)
session.setTolerance(model, 1e-5)
session.setResultFile(model, "cs_test1_res.mat")

session.initialize(model)
session.simulate(model)
session.terminate(model)

session.unload(model)

vars = ["test1.x"]
for var in vars:
    if (1 == session.compareSimulationResults(
            "cs_test1_res.mat", "../ReferenceFiles/cs_test1.mat", var, 1e-2,
            1e-4)):
        print(var + " is equal")
    else:
        print(var + " is not equal")

## Result:
# 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:
  (_, value) = session.getReal(var)
  print('{0} at {1}: {2}'.format(var, tcur, value))

session.unloadModel("DualMassOscillator")

## Result:
## DualMassOscillator.System1:mass1.s at 0.1: -0.437361150714
## DualMassOscillator.System2:mass2.s at 0.1: -0.284406319121
## info:    Logging information has been saved to "DualMassOscillator_cs.log"
## info:    3 warnings
示例#7
0
#!/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')
示例#8
0
## change model
oms.addSystem("test03py.eoo.goo", oms.system_sc)
oms.delete("test03py.eoo.source")
oms.addSubModel("test03py.eoo.source",
                "../resources/Modelica.Blocks.Sources.Constant.fmu")

## restore model from snapshot
newCref, status = oms.loadSnapshot("test03py", src)
printStatus(status, 0)

src, status = oms.list("test03py")
print(src, flush=True)

oms.instantiate("test03py")
oms.initialize("test03py")
oms.simulate("test03py")
oms.terminate("test03py")

oms.delete("test03py")

## Result:
## <?xml version="1.0"?>
## <ssd:SystemStructureDescription xmlns:ssc="http://ssp-standard.org/SSP1/SystemStructureCommon" xmlns:ssd="http://ssp-standard.org/SSP1/SystemStructureDescription" xmlns:ssv="http://ssp-standard.org/SSP1/SystemStructureParameterValues" xmlns:ssm="http://ssp-standard.org/SSP1/SystemStructureParameterMapping" xmlns:ssb="http://ssp-standard.org/SSP1/SystemStructureSignalDictionary" xmlns:oms="https://raw.githubusercontent.com/OpenModelica/OMSimulator/master/schema/oms.xsd" name="test03py" version="1.0">
## 	<ssd:System name="eoo">
## 		<ssd:Elements>
## 			<ssd:Component name="source" type="application/x-fmu-sharedlibrary" source="resources/0001_source.fmu">
## 				<ssd:Connectors>
## 					<ssd:Connector name="y" kind="output">
## 						<ssc:Real />
## 						<ssd:ConnectorGeometry x="1.000000" y="0.500000" />
oms.setReal("RealNetwork1.step:startTime", 3.0)
oms.setReal("RealNetwork1.gain:k", 1e-1)
oms.setReal("RealNetwork1.sine:amplitude", 1.0)
oms.setReal("RealNetwork1.sine:freqHz", 1.0)
oms.setReal("RealNetwork1.sine:phase", 0.0)
oms.setReal("RealNetwork1.sine:offset", 0.0)
oms.setReal("RealNetwork1.sine:startTime", 2.0)
oms.setReal("RealNetwork1.constant:k", -3.0)
oms.setReal("RealNetwork1.add:k1", 2.0)
oms.setReal("RealNetwork1.add:k2", 1.0)

# simulation settings
oms.setResultFile("RealNetwork1", "RealNetwork1.mat")
oms.setStopTime("RealNetwork1", 10.0)

oms.initialize("RealNetwork1")
oms.simulate("RealNetwork1")
oms.terminate("RealNetwork1")

oms.unloadModel("RealNetwork1")

signals = ["add.y", "feedback.y", "gain.y", "step.y"]
for signal in signals:
  if (1 == oms.compareSimulationResults("RealNetwork1.mat", "../ReferenceFiles/RealNetwork1.mat", signal, 1e-2, 1e-4)):
    print(signal + " is equal")
  else:
    print(signal + " is not equal")

## Result:
## add.y is equal
## feedback.y is equal
示例#10
0
oms.setReal(model, "step.startTime", 3.0)
oms.setReal(model, "gain.k", 1e-1)
oms.setReal(model, "sine.amplitude", 1.0)
oms.setReal(model, "sine.freqHz", 1.0)
oms.setReal(model, "sine.phase", 0.0)
oms.setReal(model, "sine.offset", 0.0)
oms.setReal(model, "sine.startTime", 2.0)
oms.setReal(model, "constant.k", -3.0)
oms.setReal(model, "add.k1", 2.0)
oms.setReal(model, "add.k2", 1.0)

# simulation settings
oms.setResultFile(model, "RealNetwork1.mat")
oms.setStopTime(model, 10.0)

oms.initialize(model)
oms.simulate(model)
oms.terminate(model)

oms.unload(model)

signals = ["add.y", "feedback.y", "gain.y", "step.y"]
for signal in signals:
    if (1 == oms.compareSimulationResults(
            "RealNetwork1.mat", "../ReferenceFiles/RealNetwork1.mat", signal,
            1e-2, 1e-4)):
        print(signal + " is equal")
    else:
        print(signal + " is not equal")

## Result: