MO (.mo, .moe)
Background & Context
-
- Modelica models.
- File format specified by the Modelica Association.
Import & Export
- Import["file.mo","MO"] imports the specified model and makes it available as a SystemModel.
- Export["file.mo",model,"MO"] saves the SystemModel model as a MO file.
- See the following reference pages for full general information:
-
Import, Export import from or export to a file CloudImport, CloudExport import from or export to a cloud object ImportString, ExportString import from or export to a string ImportByteArray, ExportByteArray import from or export to a byte array
Import Elements
- General Import elements:
-
"Elements" list of elements and options available in this file "Summary" summary of the file "Rules" list of rules for all available elements
Examples
open all close allBasic Examples (3)
model = Import["ExampleData/ExampleModel.mo", "MO"]Examine the model's equations:
model["SystemEquations"]sim = SystemModelSimulate[model, 1]SystemModelPlot[sim, {"x", "y", "y"'}]model = CreateSystemModel[{u[t] == u'[t]}, t];Save the model, which renames the model to "DiffEq":
file = Export["DiffEq.mo", model, "MO"]FilePrint[file]Clean up by deleting the new file and models:
DeleteFile[file];
DeleteObject[{model, SystemModel["DiffEq"]}];Create a new model inside a new package:
model = CreateSystemModel["MyPackage.DiffEq", {u[t] == u'[t]}, t];Save the package in a directory structure:
targetDirectory = FileNameJoin[{$TemporaryDirectory, "Models"}];
Export[targetDirectory, SystemModel["MyPackage"], "MO"]The package is saved in a directory "MyPackage", where files mirror the model structure:
FileNames["*.mo", targetDirectory, ∞]Clean up by deleting the new files and model:
DeleteDirectory[FileNameJoin[{targetDirectory, "MyPackage"}], DeleteContents -> True];
DeleteObject[model];Import Options (1)
"TrustExternalFunctions" (1)
External function evaluation is disabled by default:
modelStr = "package ModelWithExternalFunction
function fun
input Real x;
output Real y;
external
y = f_ext(x) annotation(Include = \"double f_ext(double x){return cos(x);}\");
end fun;
model MyModel
Real z = fun(time);
end MyModel;
end ModelWithExternalFunction;";model = ImportString[modelStr, "MO"]SystemModelSimulate["ModelWithExternalFunction.MyModel", 10]Import with evaluation of external functions enabled:
ImportString[modelStr, "MO", "TrustExternalFunctions" -> True]Simulate the model and plot the simulation results:
SystemModelPlot["ModelWithExternalFunction.MyModel", "z", 10]Properties & Relations (1)
Use "SME" to import SystemModelSimulationData:
sim = Import["ExampleData/OneMass.sme", {"SME", "SystemModelSimulationData"}]SystemModelPlot[sim]Possible Issues (1)
Already-saved models cannot be saved in a different place using Export:
differentFile = "NewFile.mo";Export[differentFile, SystemModel["DocumentationExamples"], "MO"]Make a copy of the model to save it in a different location:
newModel = SystemModel["DocumentationExamples", "ModelName" -> "NewExamples"];Export[differentFile, newModel, "MO"]Clean up by deleting the new files and model:
DeleteFile[differentFile];
DeleteObject[newModel];Related Guides
Related Links
History
Introduced in 2018 (11.3)