oms.newModel("model") oms.addSystem("model.root", oms.system_wc) oms.addSubModel("model.root.sine", "../resources/Modelica.Blocks.Sources.Sine.fmu") ## add resources to submodule oms.newResources("model.root.sine:sine.ssv") oms.setReal("model.root.sine.phase", 27) oms.setReal("model.root.sine.amplitude", -100) oms.setReal("model.root.sine.freqHz", -300) oms.setResultFile("model", "") (src, status) = oms.exportSnapshot("model:resources/sine.ssv") print(src) ## change the unit to meter oms.setUnit("model.root.sine.phase", "m") oms.setUnit("model.root.sine.amplitude", "m") (src, status) = oms.exportSnapshot("model:resources/sine.ssv") print(src) oms.terminate("model") oms.delete("model") ## Result: ## <?xml version="1.0"?> ## <oms:snapshot
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) oms.importSnapshot("snapshot", snapshot) snapshot, status = oms.exportSnapshot("snapshot") print(snapshot, flush=True) oms.delete("snapshot") ## Result: ## <?xml version="1.0"?> ## <oms:snapshot ## xmlns:oms="https://raw.githubusercontent.com/OpenModelica/OMSimulator/master/schema/oms.xsd" ## partial="false">
## add resources to submodule oms.newResources("addExternalResources.root.Gain:gain.ssv") oms.setReal("addExternalResources.root.Gain.k", 27) oms.setResultFile("addExternalResources", "addExternalResources1.mat", 10) oms.export("addExternalResources", "addExternalResources3.ssp") oms.terminate("addExternalResources") oms.delete("addExternalResources") oms.importFile("addExternalResources3.ssp") ## old Resources and references src, status = oms.exportSnapshot("addExternalResources") print(src, flush=True) ## add list of external resources from filesystem to ssp oms.addResources("addExternalResources", "../../resources/externalRoot.ssv") oms.addResources("addExternalResources:externalSystem.ssv", "../../resources/externalSystem1.ssv") oms.addResources("addExternalResources", "../../resources/externalGain.ssv") ## delete the root references oms.deleteResources("addExternalResources.root:root.ssv") ## switch with new references oms.referenceResources("addExternalResources.root:externalRoot.ssv") ## delete the system references oms.deleteResources("addExternalResources.root.system1:system1.ssv") ## switch with new references