SetComponent - MapleSim Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


SetComponent

create a component from either Modelica source or a DynamicSystems object

 

Calling Sequence

Parameters

Options

Description

Examples

Calling Sequence

SetComponent(model)

Parameters

model

-

string or DynamicSystems object

Options

• 

forceupdate = truefalse

  

True means update an existing component without querying. False means query if the update replaces an existing component. The default is false.

• 

nosource = truefalse

  

True means uses the empty string for the source. This prevents opening the source worksheet when double-clicking on an instance of the created component. This overrides the source option (it is different from assigning the empty string to the source option). The default is false.

• 

source = string

  

String corresponding to the name of an attachment to the current msim file, typically the source file used to create the component.  If provided, double-clicking on an instance of the created component opens a worksheet that describes where the source file is attached. The default is an empty string.  Using the default embeds a copy of the current worksheet into the generated component such that double-clicking on it opens that copy of the worksheet.

• 

savemodelica = truefalse

  

True means save the literal modelica code with the component (as the user wrote it); as a result, a subsequent opening of the component in the GUI will display the modelica code in the Modelica Code editor. The default is false.

• 

warning_only = truefalse

  

True means issue a warning rather than raise an error if there is an error while attaching model. The default is false.

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

Because SetComponent modifies the MapleSim file, for this example we copy the original to a temporary location and then use it.

origcatkerneloptstoolboxdir=MapleSim,/data/examples/RLCcircuit.msim

msimFileTools:-TemporaryFileRLCcircuit,.msim:

FileTools:-Copyorig,msim:

Link to the MapleSim model.

AMapleSim:-LinkModelfilename=msim:

A:-ListAttachments

(1)

Assign the equations for a simple nonlinear resistor.

eqsvt=V1itk,vt=vptvnt

eqsvt=V1itk,vt=vptvnt

(2)

Use MapleToModelica to create Modelica code for the model.

withMapleSim:-Tools:

moMapleToModelicaeqs,comment=Nonlinear resistor, v = R1*i^k,class_name=nonlinear_resistor,import=Modelica.Units.SI.*,parameters=V1::Voltage=1&cvoltage at one ampere,k::real=2&ccurrent exponent,connections=p::electrical=vpt,it,n::electrical=vnt,it,unfilled_pins=n,display:

model nonlinear_resistor "Nonlinear resistor, v = R1*i^k"
    import Modelica.Units.SI.*;

    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.Units.SI.Voltage V1 = 1 "voltage at one ampere";
    parameter Real k = 2 "current exponent";
    Modelica.Units.SI.Current i;
    Modelica.Units.SI.ElectricPotential vn;
    Modelica.Units.SI.ElectricPotential 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;

Add the component to the linked MapleSim model.

A:-SetComponentmo

A DynamicSystems object can also be attached as a component.

sysDynamicSystems:-DiffEquationks+ω,parameters=k=1,ω=1:

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

sys:-systemnamefilter:

A:-SetComponentsys:

See Also

DynamicSystems

MapleSim

MapleSim Embedded Component

MapleSim[LinkModel]

MapleSim[Tools][MapleToModelica]