MapleSim[Tools] - MapleSim Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : MapleSim : MapleSim Application Programming Interface : API Commands : Tools : MapleSim/Tools/MapleToModelica

MapleSim[Tools]

  

MapleToModelica

  

create a Modelica model from Maple input

 

Calling Sequence

Parameters

Options

Description

Examples

Calling Sequence

MapleToModelica(sys, opts)

Parameters

sys

-

(optional) list or set of equations, a DynamicSystems object, or a string

opts

-

(optional) equation(s) of the form option = value; specify options for MapleToModelica

Options

• 

annotation = string

  

A Maple string containing the content of a Modelica annotation. It is used to create an annotation for the generated Modelica.

• 

class = model or connector

  

Specifies whether the Modelica is a model or a connector. The default is model.

• 

class_name = string

  

The name of the generated Modelica class (model). The default is "custom" with a positive integer appended.

• 

comment = string

  

A string used to annotate the generated Modelica.

• 

display = true or false

  

True means print a formatted version of the generated Modelica. The default is false.

• 

equations_only = true or false

  

True means return only the Modelica initial equations, and equations, as a string.  This is useful for displaying how sys is interpreted as Modelica.

• 

flatten = true or false

  

True means flatten the Modelica. The default is false.

• 

omit_annotations = true or false

  

True means omit annotations from the generated Modelica. This may be used with display to view the code without the distraction of the annotations. The default is false.

• 

warning_only = true or false

  

True means generate a warning, but do not raise an error, if there is a problem with the generated Modelica code. Using this allows the code to be inspected. The default is false.

Interface Options

These options specify the interface between the component equations, sys, and the outside world.

• 

append_custom_connectors = truefalse

  

True means append any custom connectors assigned by the custom_connectors option to the generated modelica. The default is true.

• 

components = list or set

  

Specifies Modelica components used in the model. The general form of each element is id::type=modifications.

• 

constants = list or set

  

Specifies the constants, their types, and their values. The format is identical to parameters. Note that because constants is an assigned Maple global name, this keyword must be forward-quoted when used. The default is the empty set.

• 

connections or connectors = list or set

  

Specifies the connections to the component. The order of the corresponding declarations in the output matches that of the input. A list should be used when using the default pin placement strategy, the order determines the order on an edge. This option is ignored if sys is a DynamicSystems object.

– 

Each element of connections specifies the characteristics of one port.

– 

The full specification has the form id::type=signals, where id is a string that becomes the port name, type specifies the type of connection, and signals specify the Maple expressions connected to the port.

– 

The id field is required.  It is a string or name that corresponds to a valid Modelica unquoted identifier.

• 

A Modelica flow or stream variable in a connector is designated by wrapping the id with flow or stream, for example, flowi.

– 

The type field is a Maple name or string that specifies the type of the connection. The type may be omitted. The default is real.

• 

The names real, boolean, and integer correspond to the causal Modelica types Real, Boolean, and Integer. The names electrical, fluidheatflow, magnetic, rotational, thermal, and translational correspond to standard Modelica acausal interface ports.

• 

Type names may be indexed by a positive integer to indicate the dimension of the connector. For example, electrical[3] specifies an electrical port with dimension three.

• 

The type field may be a full Modelica type, or can be an identifier for a custom connector defined via the custom_connectors option.

– 

The signals field specifies the Maple expression that is connected to the port.

• 

It is optional for causal types. If omitted, the id is used as the connection.

• 

An acausal connector type requires a list of Maple expressions, the first being the across-variable (potential), the second the through-variable (flow). For example, for an electric port the signals may be vt,it.

• 

A custom connector type also requires a list of Maple expressions, the list corresponds to the signals in the connector.

• 

An array type must have a signal field that is a list of expressions, or listlist of expressions.

– 

The neutral-operator &c may be used to a attach a comment string to a connection.  For example, p :: electrical = [v(t),i(t)] &c "positive pin" adds the comment string "positive pin" to the Modelica declaration of the p connector.

• 

custom_connectors = list or set of equations

  

Specifies custom connectors. The left side of the equation is a string or symbol that identifies the connector type. The right side of the equation is a string of Modelica code that defines the connector. For example, MyConn = "connector MyConn input Real u; output Real y; end MyConn;".

• 

dont_declare = set of symbols

  

Specifies variables that should not be declared. These are variables that are used in the system equations but have been inherited from an extension (see the extends options). The default is an empty set.

• 

extends = name, string, or list of such

  

Generates Modelica extends clause(s). The value is the class name from which the component is extended. A list may be used to create multiple extends-clauses.

• 

import = list

  

List of Modelica imports. Each element can be a name or string, or an equation of such.

• 

initial = list or set of equations

  

Specifies initial equations. Values at the initial time are specified as x0,Dx0,D2x0.

• 

parameters = list or set

  

Specifies the parameters, their types, and their default values. The order of the corresponding declarations in the output matches that of the input.

– 

Each element specifies one parameter.

– 

The full specification has the form id::type=value

– 

The id field is required.  It is a string or symbol that corresponds to a valid Modelica unquoted identifier.  It should match the Maple symbol used in the eqs.

• 

A Modelica protected parameter is indicated by wrapping the id with protected; for example, protectedK. A Modelica public parameter is indicated in a similar manner, using  public. By default, parameters are public.

– 

The optional type field specifies the parameter type. The allowable types are real, boolean, and integer. The default is real.  A type may be indexed with a positive integer to specify an array parameter.

– 

The optional value field specifies the start value of the parameter. The value is an algebraic expression, or, if the parameter is an array type, a list of algebraic expressions.

– 

The neutral operator &c may be used to attach a comment string to the parameter declaration.  For example, Larm :: real = 3 &c "length of arm" adds the comment string "length of arm" to the Modelica declaration of the parameter Larm.

• 

tvar = symbol

  

Specifies the independent time variable used in the equations. Used when sys is a set of equations. The default is t.

• 

variables = list or set

  

Specifies variables, their types, and, optionally, their initial values. The specification and operation is essentially identical to that of the parameters option; see the parameters option in this section for details.

Icon Options

These options specify the component icon and the placement and type of pins on its edge. Component icons are always rectangular.

• 

bitmap = string

  

Specify a bitmap file to use for the component icon. The bitmap file may have extension bmp, jpg, jpeg, or png. The syntax is that of a URI: a scheme name (file or attachment), followed by a colon, followed by the location.  For example, "file:///home/bob/icons/myicon.png". The attachment scheme is used for bitmap files attached to the MapleSim document. The default is the empty string, which specifies that no bitmap file is used.

• 

copy_icon = string or none

  

Specifies a Modelica component. The icon of the specified component is used for this component. If none is used, no icon is created. This is useful when extending a model that assigns the icon. The default icon is "Maplesoft.Icons.CustomComponent".

• 

filled_pins = list or set of strings

  

Specifies which connection icons are filled (solid). The keyword input_pins is a synonym. By convention, the inputs of causal connections are filled, the outputs are unfilled. The strings correspond to the connection names (see the connections option in the Interface Options section). By default all connections are filled, though connections generated automatically from a DynamicSystems object get the proper convention. See also unfilled_pins.

• 

icon_graphics = list of strings

  

The strings are Modelica graphical annotations; they are combined with the existing graphical annotations of the icon. This can be used to add some small detail to an existing icon, say a line for an added connection. The default is an empty list.

• 

icon_size = list of two positive integers

  

Specifies the dimensions of the icon in pixels, as width,height. The default is 200 x 200.

• 

input_pins = list or set of strings

  

A synonym for filled_pins.

• 

min_gap = positive integer

  

Specifies the minimum gap between pins, when placed automatically. If this cannot be met, the edge dimension is increased, unless icon_size is specified, in which case an error is raised. The default is 10.

• 

output_pins = list or set of strings

  

A synonym for unfilled_pins.

• 

pin_placement = list or set of equations

  

Specifies the placement of the connections.

– 

The left side of each equation is a name corresponding to an edge, left, right, top, or bottom.

– 

The right side of each equation specifies the connections made on the corresponding edge. It is a string, or list of strings. A string must match one of the strings used on the left side of the connection equations (see the connections option in the Interface Options section). If a string, the pin is placed in the center of the edge. If a list, the pins are arranged in that order, from top to bottom, or left to right, depending whether the edge is vertical or horizontal.

– 

The default for a DynamicSystems object is to place the inputs on the left and the outputs on the right. Other systems must specify the locations.

– 

An alternative syntax is for each equation to have the form string=numeric,numeric, where the left side is the name of a pin and the right side specifies its location. The locations should lie on the edge of the icon.

• 

unfilled_pins = list or set of strings

  

Specifies which connection icons are unfilled (open). The keyword output_pins is a synonym. By convention, the inputs of causal connections are filled and the outputs are unfilled. The strings correspond to the connection names (see the connections option in the Interface Options section). By default all connections are filled, however, connections generated automatically from a DynamicSystems object get the proper convention. See also filled_pins.

Description

• 

The MapleToModelica command creates a Modelica model from either Maple equations, a DynamicSystems object, or a Modelica class name. It also creates a Modelica connector from a connector specification.

• 

The optional sys parameter specifies the system equations. It may be a list or set of differential-algebraic equations, a DynamicSystems object, or a string corresponding to a Modelica class. The default value of sys is an empty set. This is useful when creating a custom connector.

• 

When sys is a list or set of equations, the following considerations apply:

– 

Variables in the equations should be represented as functions of time, for example, xt. The tvar option specifies the time variable, by default t.

– 

Time derivatives are expressed as diff(x(t),t).

– 

Time derivatives of order greater than one are converted to first-order derivatives using auxiliary variables.

– 

Initial conditions are expressed by substituting 0 for the time-variable; for example, x0=0. The D operator expresses initial derivatives; for example, Dx0=1.

– 

Conditional expressions may be represented as piecewise expressions; for example, piecewisext<yt&comma;xt&comma;yt. A symbolic expression, say bt, in a condition may be expressed as bt&equals;true; piecewise requires a Maple boolean expression.

– 

The and, or, and not boolean operators may be used in boolean expressions.

– 

The Modelica function noEvent may be applied to an expression to prevent events from being generated by the inequalities of the expression; for example, noEventpiecewiset<1&comma;t&comma;t2.

– 

The following standard Maple functions are handled: sin, cos, tan, arcsin, arccos, arctan, sinh, cosh, tanh, exp, ln, and log; arctan may be used in either the one or two argument form.  The log function is identical to the ln function.

• 

When sys is a DynamicSystems object, the inputs and output of the object become the inputs and outputs of the model, respectively. The inputs are placed on the left side of the icon, the outputs on the right. The systemname field of the DynamicSystems object is used as the class name of the model, unless it is the empty string or the class_name parameter is passed to MapleToModelica.

• 

When sys is a string corresponding to a fully-qualified Modelica class, the modelica corresponding to the class definition is returned.  This is primarily useful for inspecting the equations of a class to be extended. See the Modelon Hydraulics example.

• 

The generated Modelica model is returned as a string.

Examples

Access MapleToModelica directly.

withMapleSim:-Tools&colon;

DynamicSystems

Create a DynamicSystems object and convert it to Modelica.

withDynamicSystems&colon;

sysNewSystemKs2&plus;&omega;0sQ&plus;&omega;02&colon;

MapleToModelicasys&comma;class_name&equals;second_order&comma;display&colon;

model second_order
    extends Maplesoft.Icons.CustomComponent;

    Modelica.Blocks.Interfaces.RealInput u[1] annotation (Placement(transformation(
        extent = {
            {-110, -10},
            {-90, 10}},
        rotation = 0)));
    Modelica.Blocks.Interfaces.RealOutput y[1] annotation (Placement(transformation(
        extent = {
            {90, -10},
            {110, 10}},
        rotation = 0)));
    parameter Real K = 0;
    parameter Real Q = 0;
    parameter Real omega0 = 0;
    Real x[2];
equation
    der(x[1]) = -omega0 ^ (-1) * Q * x[2];
    der(x[2]) = omega0 ^ 3 / Q * x[1] - omega0 / Q * x[2] - omega0 / Q * u[1];
    y[1] = K * x[1];
end second_order;

Create a multi-input, multi-output DynamicSystems object.

sys2NewSystem1s2&verbar;s2s3&plus;5s2&plus;7s&plus;6&comma;1s&verbar;cs2&plus;as&plus;b

sys2:=Transfer Functioncontinuous2 output(s); 2 input(s)inputvariable&equals;u1s&comma;u2soutputvariable&equals;y1s&comma;y2s

(1)

Convert the system to Modelica. Override the default connector names, specify initial values for the state variables, and specify the default values for the parameters a, b, and c.

MapleToModelicasys2&comma;connectors&equals;inp::real2&equals;u&lsqb;1&rsqb;&comma;u&lsqb;2&rsqb;t&comma;out::real2&equals;y&lsqb;1&rsqb;&comma;y&lsqb;2&rsqb;t&comma;initial&equals;x&equals;0&comma;0&comma;0&comma;0&comma;0&comma;0&comma;0&comma;class_name&equals;MIMO&comma;output_pins&equals;out&comma;parameters&equals;a&equals;1&comma;b&equals;2&comma;c&equals;&pi;&comma;display&colon;

model MIMO
    extends Maplesoft.Icons.CustomComponent;

    Modelica.Blocks.Interfaces.RealInput inp[2] annotation (Placement(transformation(
        extent = {
            {-110, -10},
            {-90, 10}},
        rotation = 0)));
    Modelica.Blocks.Interfaces.RealOutput out[2] annotation (Placement(transformation(
        extent = {
            {90, -10},
            {110, 10}},
        rotation = 0)));
    parameter Real a = 0;
    parameter Real b = 0;
    parameter Real c = 0;
    Real x[7];
    Real u[2];
    Real y[2];
initial equation
    x = {0, 0, 0, 0, 0, 0, 0};
equation
    der(x[1]) = x[2];
    der(x[2]) = u[1];
    der(x[3]) = x[4];
    der(x[4]) = x[5];
    der(x[5]) = x[6];
    der(x[6]) = (-5 - a) ^ (-1) * x[7];
    der(x[7]) = -6 * b * (-5 - a) * x[3] + (-6 * a - 7 * b) * (-5 - a) * x[4] + (-6 - 7 * a - 5 * b) * (-5 - a) * x[5] + (-7 - 5 * a - b) * (-5 - a) * x[6] + (-5 - a) * x[7] + (-5 - a) * u[2];
    y[1] = x[1] + b * x[5] + a * x[6] + (-5 - a) ^ (-1) * x[7];
    y[2] = x[2] + 6 * c * x[3] + 7 * c * x[4] + 5 * c * x[5] + c * x[6];
    inp[1] = u[1];
    inp[2] = u[2];
    out[1] = y[1];
    out[2] = y[2];
end MIMO;

Simple Causal Model

Implement the equation y&equals;uKv1&plus;v2, with v1 and v2 two components of a vector input.

MapleToModelicayt&equals;u1t&plus;Kv1t&plus;v2t&comma;class_name&equals;mymodel&comma;parameters&equals;K&equals;1&comma;connections&equals;u::real&equals;u1&comma;v::real2&equals;v1&comma;v2&comma;y::real&equals;y&comma;unfilled_pins&equals;y&comma;omit_annotations&comma;display&colon;

model mymodel
    extends Maplesoft.Icons.CustomComponent;

    Modelica.Blocks.Interfaces.RealInput u;
    Modelica.Blocks.Interfaces.RealInput v[2];
    Modelica.Blocks.Interfaces.RealOutput y;
    parameter Real K = 1;
    Real u1;
    Real v1;
    Real v2;
equation
    u = u1;
    y = u1 + K * (v1 + v2);
    v[1] = v1;
    v[2] = v2;
end mymodel;

Simple Acausal Model

Implement a resistor model with a power variable.

eqsvt&equals;Rit&comma;vt&equals;vptvnt&comma;Pt&equals;vtit&colon;

MapleToModelicaeqs&comma;class_name&equals;resistor_with_power&comma;import&equals;Modelica.SIunits.*&comma;parameters&equals;R::Resistance&equals;1 &c resistance&comma;variables&equals;P::Power&comma;i::Current&comma;v::Voltage&comma;vn::Voltage&comma;vp::Voltage&comma;connections&equals;p::electrical&equals;vp&comma;it &c positive pin&comma;n::electrical&equals;vn&comma;it &c negative pin&comma;unfilled_pins&equals;n&comma;omit_annotations&comma;display&colon;

model resistor_with_power
    import Modelica.SIunits.*;

    extends Maplesoft.Icons.CustomComponent;

    Modelica.Electrical.Analog.Interfaces.PositivePin p "positive pin";
    Modelica.Electrical.Analog.Interfaces.NegativePin n "negative pin";
    parameter Modelica.SIunits.Resistance R = 1 "resistance";
    Modelica.SIunits.Power P;
    Modelica.SIunits.Current i;
    Modelica.SIunits.Voltage v;
    Modelica.SIunits.Voltage vn;
    Modelica.SIunits.Voltage vp;
equation
    P = v * i;
    v = R * i;
    v = vp - vn;
    n.i = -i;
    n.v = vn;
    p.i = i;
    p.v = vp;
end resistor_with_power;

Multiphase Resistor

Create a multiphase resistor with a common value. While one should normally declare all variables, here we use the defaults chosen by MapleToModelica, which is to declare undeclared variables as Real. The declared dimension is the largest index used.

The copy_icon option is used to copy the resistor symbol from an existing component.

num3&colon;

eqsseqopv&lsqb;k&rsqb;t&equals;Ri&lsqb;k&rsqb;t&comma;v&lsqb;k&rsqb;t&equals;vp&lsqb;k&rsqb;tvn&lsqb;k&rsqb;t&comma;k&equals;1..num

eqs:=v1t&equals;Ri1t&comma;v1t&equals;vp1tvn1t&comma;v2t&equals;Ri2t&comma;v2t&equals;vp2tvn2t&comma;v3t&equals;Ri3t&comma;v3t&equals;vp3tvn3t

(2)

MapleToModelicaeqs&comma;class_name&equals;multiphase_common_resistor&comma;parameters&equals;R&equals;1&comma;copy_icon&equals;Modelica.Electrical.MultiPhase.Basic.Resistor&comma;connections&equals;p::electricalnum&equals;seq&apos;vp&lsqb;k&rsqb;&comma;i&lsqb;k&rsqb;&apos;&comma;k&equals;1..numt&comma;n::electricalnum&equals;seq&apos;vn&lsqb;k&rsqb;&comma;i&lsqb;k&rsqb;&apos;&comma;k&equals;1..numt&comma;unfilled_pins&equals;n&comma;omit_annotations&comma;display&colon;

model multiphase_common_resistor
    Modelica.Electrical.Analog.Interfaces.PositivePin p[3];
    Modelica.Electrical.Analog.Interfaces.NegativePin n[3];
    parameter Real R = 1;
    Real i[3];
    Real v[3];
    Real vn[3];
    Real vp[3];
equation
    v[1] = R * i[1];
    v[1] = vp[1] - vn[1];
    v[2] = R * i[2];
    v[2] = vp[2] - vn[2];
    v[3] = R * i[3];
    v[3] = vp[3] - vn[3];
    n[1].i = -i[1];
    n[1].v = vn[1];
    n[2].i = -i[2];
    n[2].v = vn[2];
    n[3].i = -i[3];
    n[3].v = vn[3];
    p[1].i = i[1];
    p[1].v = vp[1];
    p[2].i = i[2];
    p[2].v = vp[2];
    p[3].i = i[3];
    p[3].v = vp[3];
end multiphase_common_resistor;

Modelon Hydraulics

Model a thick-edged hydraulic orifice with the following cross-sectional dimensions.

Use the modelica two-port template to create the base equations:

templateHydraulics.Templates.TwoPortComponent&colon;

Inspect the template equations.

MapleToModelicatemplate&comma;equations_only&comma;display&colon;

equation
  port_A.m_flow + port_B.m_flow = 0;
  T = oil.T0 + dT_system;
  q = port_A.m_flow / rho;
  dp = pA_limited - pB_limited;
  nu = Modelica.Media.Air.MoistAir.Utilities.spliceFunction(x = dp, pos = oil.kinematicViscosity(p_abs = pA_abs, T = T, v_air = oil.v_gas, p_sat = p_sat), neg = oil.kinematicViscosity(p_abs = pB_abs, T = T, v_air = oil.v_gas, p_sat = p_sat), deltax = 100);
  pA_abs = port_A.p + oil.p_atm;
  pB_abs = port_B.p + oil.p_atm;
  rho = Modelica.Media.Air.MoistAir.Utilities.spliceFunction(x = dp, pos = oil.density(p_abs = pA_abs, T = T, v_air = oil.v_gas, p_sat = p_sat), neg = oil.density(p_abs = pB_abs, T = T, v_air = oil.v_gas, p_sat = p_sat), deltax = 100);
  pA_limited = max(port_A.p, oil.p_vapour - oil.p_atm);
  pB_limited = max(port_B.p, oil.p_vapour - oil.p_atm);

The pressure drop across the orifice is given by &Delta;p&equals;12ζtotρv12, with

ρ the density of the fluid;

v1 the mean-velocity in the large cross-sectional areas; and

ζtot the pressure loss coefficient.

eqszeta_tot&equals;0.51A_0A_10.75&plus;&tau;1A_0A_11.375&plus;1A_0A_12&plus;lambda_fril_barA_1A_02&comma;&tau;&equals;2.4l_bar10&phi;&comma;&phi;&equals;0.25&plus;0.535l_bar80.05&plus;l_bar8&comma;`port_A.m_flow`&equals;&rho;A_1dp0.5&rho;zeta_tot

eqs:=zeta_tot&equals;0.51A_0A_10.75&plus;&tau;1A_0A_11.375&plus;1A_0A_12&plus;lambda_fril_barA_12A_02&comma;&tau;&equals;2.4l_bar10&phi;&comma;&phi;&equals;0.25&plus;0.535l_bar80.05&plus;l_bar8&comma;port_A.m_flow&equals;1.414213562&rho;A_1dp&rho;zeta_tot

(3)

Generate the modelica.

MapleToModelicaeqs&comma;class_name&equals;ThickEdgedOrifice&comma;extends&equals;Hydraulics.Templates.TwoPortComponent&comma;import&equals;Modelica.SIunits.*&comma;comment&equals;Thick-edged orifice, from Idelchik&comma;parameters&equals;A_0::Area &c small cross-section area&comma;A_1::Area &c area cross-section area&comma;C_0::Length &c large circumference&comma;L::Length &c length of vena contracta&comma;lambda_fri&equals;0.02 &c Darcy friction factor&comma;protectedl_bar&equals;Ld_hyd_0 &c relative length of orifice&comma;protectedd_hyd_0::Length&equals;4A_0C_0 &c hydraulic diameter&comma;variables&equals;zeta_tot &c pressure loss coefficient&comma;protected&tau; &c geometry factor&comma;protected&phi; &c geometry factor&comma;warning_only&comma;omit_annotations&comma;display&colon;

model ThickEdgedOrifice "Thick-edged orifice, from Idelchik"
    import Modelica.SIunits.*;

    extends Hydraulics.Templates.TwoPortComponent;
    extends Maplesoft.Icons.CustomComponent;

    parameter Modelica.SIunits.Area A_0 = 0 "small cross-section area";
    parameter Modelica.SIunits.Area A_1 = 0 "area  cross-section area";
    parameter Modelica.SIunits.Length C_0 = 0 "large circumference";
    parameter Modelica.SIunits.Length L = 0 "length of vena contracta";
    parameter Real lambda_fri = 0.02 "Darcy friction factor";
protected
    parameter Real l_bar = L / d_hyd_0 "relative length of orifice";
    parameter Modelica.SIunits.Length d_hyd_0 = 4 * A_0 / C_0 "hydraulic diameter";
public
    Real zeta_tot "pressure loss coefficient";
protected
    Real tau "geometry factor";
    Real phi "geometry factor";
equation
    phi = 0.25 + 0.535 * l_bar ^ 8 / (0.05 + l_bar ^ 8);
    tau = (2.4 - l_bar) * 10 ^ (-phi);
    zeta_tot = (0.5 * (1 - A_0 / A_1) ^ 0.75 + tau * (1 - A_0 / A_1) ^ 1.375 + (1 - A_0 / A_1) ^ 2 + lambda_fri * l_bar) * A_1 ^ 2 / A_0 ^ 2;
    'port_A.m_flow' = 1.414213562 * rho * A_1 * sqrt(dp / rho / zeta_tot);
end ThickEdgedOrifice;

Custom Connector

If the option class=connector is passed to MapleToModelica, the output is a Modelica connector definition. This can then be used with the custom_connectors option in a subsequent call to MapleToModelica.

Assign a function that prepends Modelica.SIunits. to a string.

SIdim&rarr;sprintfModelica.SIunits.%s&comma;dim&colon;

Create the modelica for a custom connector that models both electrical and thermal connections. It has variables for voltage, current, temperature, and heat-flow.

ETmoMapleToModelicaclass&equals;connector&comma;class_name&equals;ETconn&comma;connections&equals;v::SIVoltage &c Voltage at connection&comma;flowi::SICurrent &c Current into connection&comma;T::SITemperature &c Temperature at connection&comma;flowQ::SIHeatFlowRate &c Heat flow into connection&comma;display&colon;

connector ETconn
    Modelica.SIunits.Voltage v "Voltage at connection";
    flow Modelica.SIunits.Current i "Current into connection";
    Modelica.SIunits.Temperature T "Temperature at connection";
    flow Modelica.SIunits.HeatFlowRate Q "Heat flow into connection";
end ETconn;

Assign the equations for a voltage source with a series resistor.

eqsvt&equals;V&plus;Rit&comma;Pt&equals;Rit2&comma;Trt&equals;Rth2Pt&plus;Qt&plus;Ta&comma;Tt&equals;Trt&plus;Rth1Qt

eqs:=Pt&equals;Rit2&comma;Tt&equals;Trt&plus;Rth1Qt&comma;Trt&equals;Rth2Pt&plus;Qt&plus;Ta&comma;vt&equals;V&plus;Rit

(4)

Generate the modelica, using the custom connector.

MapleToModelicaeqs&comma;class_name&equals;supply&comma;connections&equals;ET::ETconn&equals;v&comma;i&comma;T&comma;Qt&comma;custom_connectors&equals;ETconn&equals;ETmo&comma;parameters&equals;R::SIResistance&equals;1 &c Supply series resistance&comma;Rth1::SIThermalResistance&equals;1 &c Thermal resistance from port to resistor&comma;Rth2::SIThermalResistance&equals;1 &c Thermal resistance from resistor to ambient&comma;V::SIVoltage&equals;1 &c Supply open-circuit voltage&comma;Ta::SITemperature&equals;300 &c Ambient temperature&comma;variables&equals;P::SIPower &c Power dissipation in resistor&comma;Q::SIHeatFlowRate &c Heat flow rate into thermal port&comma;T::SITemperature &c Temperature at thermal port&comma;Tr::SITemperature &c Temperature of resistor&comma;i::SICurrent &c Current into electrical pin&comma;v::SIVoltage &c Voltage at electrical pin&comma;omit_annotations&comma;display&colon;

model supply
    extends Maplesoft.Icons.CustomComponent;

    ETconn ET;
    parameter Modelica.SIunits.Resistance R = 1 "Supply series resistance";
    parameter Modelica.SIunits.ThermalResistance Rth1 = 1 "Thermal resistance from port to resistor";
    parameter Modelica.SIunits.ThermalResistance Rth2 = 1 "Thermal resistance from resistor to ambient";
    parameter Modelica.SIunits.Temperature Ta = 300 "Ambient temperature";
    parameter Modelica.SIunits.Voltage V = 1 "Supply open-circuit voltage";
    Modelica.SIunits.Power P "Power dissipation in resistor";
    Modelica.SIunits.HeatFlowRate Q "Heat flow rate into thermal port";
    Modelica.SIunits.Temperature T "Temperature at thermal port";
    Modelica.SIunits.Temperature Tr "Temperature of resistor";
    Modelica.SIunits.Current i "Current into electrical pin";
    Modelica.SIunits.Voltage v "Voltage at electrical pin";
equation
    P = R * i ^ 2;
    T = Tr + Rth1 * Q;
    v = V + R * i;
    Tr = Rth2 * (P + Q) + Ta;
    ET.Q = Q;
    ET.T = T;
    ET.i = i;
    ET.v = v;
end supply;
connector ETconn
    Modelica.SIunits.Voltage v "Voltage at connection";
    flow Modelica.SIunits.Current i "Current into connection";
    Modelica.SIunits.Temperature T "Temperature at connection";
    flow Modelica.SIunits.HeatFlowRate Q "Heat flow into connection";
end ETconn;

See Also

DynamicSystems

MapleSim

MapleSim[LinkModel]

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam