SetComponent - MapleSim Help

SetComponent

create a component from either Modelica source or a DynamicSystems object

 Calling Sequence SetComponent(model)

Parameters

 model - string or DynamicSystems object

Description

 • SetComponent attaches a model to the linked MapleSim model. The model appears in the Components palette under the Definitions tab.
 • The model parameter is either a string consisting of Modelica source code or a DynamicSystems[System] object.

Examples

 > $A≔\mathrm{MapleSim}:-\mathrm{LinkModel}\left(\right):$

Assign the equations for a simple nonlinear resistor.

 > $\mathrm{eqs}≔\left\{v\left(t\right)=\mathrm{V1}{i\left(t\right)}^{k},v\left(t\right)=\mathrm{vp}\left(t\right)-\mathrm{vn}\left(t\right)\right\}$
 ${\mathrm{eqs}}{≔}\left\{{v}{}\left({t}\right){=}{\mathrm{V1}}{}{{i}{}\left({t}\right)}^{{k}}{,}{v}{}\left({t}\right){=}{\mathrm{vp}}{}\left({t}\right){-}{\mathrm{vn}}{}\left({t}\right)\right\}$ (1)

Use MapleToModelica to create Modelica code for the model.

 > $\mathrm{with}\left(\mathrm{MapleSim}:-\mathrm{Tools}\right):$
 > $\mathrm{mo}≔\mathrm{MapleToModelica}\left(\mathrm{eqs},\mathrm{comment}="Nonlinear resistor, v = R1*i^k",\mathrm{class_name}="nonlinear_resistor",\mathrm{import}="Modelica.SIunits.*",\mathrm{parameters}=\left[\mathrm{V1}::\mathrm{Voltage}=1&c"voltage at one ampere",k::\mathrm{real}=2&c"current exponent"\right],\mathrm{connections}=\left["p"::\mathrm{electrical}=\left[\mathrm{vp}\left(t\right),i\left(t\right)\right],"n"::\mathrm{electrical}=\left[\mathrm{vn}\left(t\right),-i\left(t\right)\right]\right],\mathrm{unfilled_pins}=\left\{"n"\right\},\mathrm{display}\right):$
 model nonlinear_resistor "Nonlinear resistor, v = R1*i^k"     import Modelica.SIunits.*;     extends Maplesoft.Icons.CustomComponent;     Modelica.Electrical.Analog.Interfaces.PositivePin p annotation (Placement(transformation(         extent = {             {-110, -10},             {-90, 10}},         rotation = 0)));     Modelica.Electrical.Analog.Interfaces.NegativePin n annotation (Placement(transformation(         extent = {             {90, -10},             {110, 10}},         rotation = 0)));     parameter Modelica.SIunits.Voltage V1 = 1 "voltage at one ampere";     parameter Real k = 2 "current exponent";     Modelica.SIunits.Current i;     Modelica.SIunits.Voltage vn;     Modelica.SIunits.Voltage vp;     Real v; equation     v = V1 * i ^ k;     v = vp - vn;     n.i = -i;     n.v = vn;     p.i = i;     p.v = vp; end nonlinear_resistor;

 > $A:-\mathrm{SetComponent}\left(\mathrm{mo}\right)$

Create a DynamicSystems object and attach it as a component.

 > $\mathrm{sys}≔\mathrm{DynamicSystems}:-\mathrm{DiffEquation}\left(\frac{k}{s+\mathrm{ω}},\mathrm{parameters}=\left[k=1,\mathrm{ω}=1\right]\right):$

Reassign the systemname field of sys; the new name is used as the model name.

 > $\mathrm{sys}:-\mathrm{systemname}≔"filter":$
 > $A:-\mathrm{SetComponent}\left(\mathrm{sys}\right):$