WSMCreateModel
WSMCreateModel["newmodel",sys]
creates the Modelica model "newmodel" of the systems model sys.
WSMCreateModel["newmodel",eqns,t]
creates a model for the system equations eqns with independent variable t.
WSMCreateModel["newmodel",…,tspecs]
creates a model with type specifications tspecs for variables and parameters.
WSMCreateModel["newmodel"∈"partial",eqns,t]
creates a component model extending the specification given by "partial".
Details and Options
- WSMCreateModel returns WSMModelData["newmodel"].
- WSMCreateModel["PackageA.NewModel"] inserts "NewModel" into "PackageA".
- Possible systems models sys include TransferFunctionModel and StateSpaceModel. »
- Possible equations eqns include ordinary differential equations (ODE), differential algebraic equations (DAE), initial value equations and event specifications given by WhenEvent. »
- Parameters in eqns and sys are taken to be variables that do not explicitly depend on t.
- Type specifications tspecs for variables and parameters {tspec1,…}, where each tspeci has the form:
-
pari∈typei parameter type typei vari∈typei variable type typei - The types typei can be basic Reals, Integers and Booleans, or any Modelica type including units. »
- WSMNames["Modelica.Units.*","type"] can be used to find built-in standard units.
- Modelica models are typically built by combining many models into a larger system. The interaction between these models is described by the Modelica concept connector. »
- A connector consists of effort and flow variables. When connecting multiple connectors, flow variables are summed to 0, while effort variables are set equal.
- As an example, an electrical circuit connector, commonly called a pin, consists of a voltage variable v and a current variable i.
- Connecting pins n and p sums the flow variables, in this case currents i, to 0, and sets the efforts, in this case voltages v, equal:
- All flow variables are positive in the direction flowing into a component.
- Effort and flow variables for different domains include:
-
Domain Effort Variables Flow Variables electrical circuits voltage current magnetic circuits magnetic potential magnetic flux translational mechanics position force rotational mechanics angle torque 3D mechanics position vector, orientation object cut force vector, cut torque vector fluid flow systems pressure, specific enthalpy mass flow rate, enthalpy flow rate heat transfer systems temperature heat flow rate block diagrams real, integer, Boolean - - Possible connectors conni for a domain are usually defined in an Interfaces package. For example, WSMNames["Modelica.Electrical.Analog.Interfaces.*","connector"] can be used to find connectors for the built-in electrical library.
- The specification vari∈conni can be used to specify that a variable vari refers to a connector of type conni.
- Variables vi in a connector c can be referred to in eqns with c▴vi, where the "▴" character is input as \[UpPointer].
- The variables defined by a connector conn can be listed with WSMModelData[conn,"SystemVariables"].
- Libraries often contain partial models, called interfaces, for building new component models. These interfaces usually consist of connectors and equations describing the basic relationships between them.
- With WSMCreateModel["newmodel"∈"partial",eqns,…], "newmodel" combines eqns with the existing "partial" model defined in Modelica. »
- WSMCreateModel["newmodel"∈"partial",…] corresponds to using the "extends" keyword in Modelica.
- A model can extend multiple models using "newmodel"∈{…,"partiali",…}.
- Partial models to build on are usually defined in an Interfaces package. For example, WSMNames["Modelica.Electrical.Analog.Interfaces.*","model" "block"] can be used to find partial models for the built-in electrical library.
- The shortest unique "type" or "partial" can be used where WSMNames["*.type"] gives a unique match. »
- The following options can be given:
-
WSMInitialValues Automatic start values WSMParameterValues Automatic parameter values - WSMInitialValues corresponds to the start property in the Modelica model.
Examples
open allclose allBasic Examples (4)
Load Wolfram System Modeler Link:
Create a model based on a StateSpaceModel:
Create a model based on a TransferFunctionModel:
Scope (25)
Systems Models (9)
Create a model of a single-input, single-output TransferFunctionModel:
Create a model of a single-input, single-output StateSpaceModel:
Multiple input, multiple output:
Create a model with parameters in a transfer-function model:
Specify parameters in a state-space model:
Define parameter values in a transfer-function model:
Give parameter values in a state-space model:
Give the type and values of parameters:
Create a model from a discrete transfer-function model:
Differential Equations (11)
Create a single-equation ODE system:
Specify any order equation. Reduction of higher-order derivatives is done automatically:
Define a system of multiple equations:
Define a system with an algebraic constraint, resulting in a high index problem:
Hybrid equations can be specified using WhenEvent:
Wolfram Language functions are automatically translated to their Modelica equivalent:
Specify a default parameter value:
Specify a type for variables and parameters:
Arrays are expressed using Indexed:
Connectors (3)
Options (7)
WSMInitialValues (5)
Give a start value for a variable:
Give a start value for a parameter:
With both a start value and an initial equation, the initial equation has higher priority:
WSMInitialValues gives start values for solving the initialization:
Because y[0]2 is given as an initial equation, the start value for x is ignored:
Applications (5)
Define the equations for a bouncing ball:
Simulate with a restitution of 95%:
Create a model of the Lotka–Volterra equations, modeling a predator-prey relationship:
Define initial values for the two states:
Show the levels of predators and prey over time:
A higher prey growth parameter speeds up the cycles in the system:
Model two connected tanks with a leak in the second tank:
Set up the equations, which include initial equations and parameters:
Create the model, using a given set of parameter values as the default:
Both tanks drain over time, because the second tank is leaking:
Create a mechanical translational damper with damping in only one direction:
Create the damper using a partial interface from the translational mechanics library:
Compare with a bidirectional damper:
Create a digital lowpass filter:
Convert the filter into a transfer function:
Create a signal generating source:
Connect the signal source to the filter:
Simulate and plot the signal output and the filtered signal:
Properties & Relations (3)
WSMModelData can be used to extract information from a model:
Create a new model with equations from an existing model, changing a parameter:
Simulate and compare the two models:
Special characters are translated into their long form:
Subscript is translated into _: