Engee documentation

The general syntax of the Engee physical Modeling language

Form and data type of variables and parameters

By default, variables and parameters are treated as real numbers (Real), but if necessary, you can set the type and form of the data for the parameters. So:

  • For the parameters (@parameters and @structural_parameters) any typing is available;

  • Common variables (@variables without event=true) and intermediate expressions (@intermediates) always have a type Real;

  • Discrete variables (@variables with event=true) may have types Real, Int, Bool.

Typing allows you to:

  • Explicitly specify which data type should be used;

  • Control the input of values in the interface (for example, the boolean value will be a checkbox, and the enumeration will be a drop—down list),

  • Set the data structure (scalar, vector, matrix),

  • To increase the rigor of the model and eliminate errors even at the stage of the announcement.

The following types are supported:

  • Real — real numbers (default value if no type is specified);

  • Int — integers;

  • Bool — logical values (true / false);

  • Arrays ([:] for the vector, [:, :] for the matrix);

  • Enumerations that are set separately.

For @parameters/@variables/@intermediates/@structural_parameters you can specify the dimension (scalar, vector, matrix).

@parameters begin
    a::Bool = true
    b = 1
    c[:] = [2, 3] # vector
    d[:, :] = [1 2; 3 4] # The matrix
end

Vectors and matrices

When declaring arrays, it is important to consider the rules:

  • a[:] — vector (one-dimensional array).

  • b[:,:] — a matrix (two-dimensional array).

  • j[:,:,:] — a three-dimensional array.

  • If the parameter is declared without [:] then it is always a scalar.

  • The sizes of arrays can be set using structural parameters.

Example:

@structural_parameters begin
    n1::Int = 5
    n2::Int = 3
end
@parameters begin
    a[:] = [0.1, 0.2, 0.3] # vector
    b[:] = zeros(n1) # vector of length n1
    c[:,:] = ones(n1, n2) # matrix n1×n2
    j[:,:,:] = zeros(3,3,3) # three-dimensional array
end
@variables begin
    x = 0
end
@equations begin
    x ~ a[1] + b[2] + c[3,2] + j[1,1,1]
end
The same techniques for declaring arrays and their sizes work equally for @variables, @intermediates, @parameters and @structural_parameters.

Let’s look at what this code does.:

  • In the construction @structural_parameters the sizes of arrays are set: n1 = 5, n2 = 3. These parameters determine the shape of the vectors and matrices.

  • In the construction @parameters:

    • a[:] = [0.1, 0.2, 0.3] — creates a vector of length 4 with fixed values [0.1, 0.2, 0.3].

    • b[:] = zeros(n1) — creates a vector of length n1 (in this case, 5), filled with zeros.

    • c[:,:] = ones(n1, n2) — creates a matrix of the size 5×3, filled with units.

    • j[:,:,:] = zeros(3,3,3) — creates a three-dimensional array of the size 3×3×3 filled with zeros.

  • In the construction @variables a variable is introduced x, initially equal to 0.

  • In the construction @equations an equation is given in which x expressed in terms of the elements of all arrays:

    • a[1] — the first element of the vector a (value 0.1).

    • b[2] — the second element of the vector b (the value is 0, since the vector is filled with zeros).

    • c[3,2] — an element of the matrix c in the 3rd row and the 2nd column (the value is 1, since the matrix is filled with units).

    • j[1,1,1] — an element of a three-dimensional array j (value 0).

Indexing is used to access individual elements.

Scalar types

Example of declaring simple parameters of different types:

@parameters begin
    flag::Bool = true
    count::Int = 5
    gain::Real = 1.25 # the Real type is used by default
end

where:

  • Bool — boolean type, accepts only two values: true (true) or false (false). In the interface, this parameter is displayed as a checkbox that can be turned on or off.

  • Int — an integer without a fractional part. It is convenient to use for counters, indexes, and array sizes.

  • Real — a number with a fractional part (real). It is suitable for any physical quantities: mass, speed, voltage, etc.

Passing values to sub-components

If a number without units of measurement is passed to a sub-component, the default unit of measurement specified in its parameters is used. To set the unit of measurement explicitly, use NamedTuple. Example:

@engeemodel A begin
    @parameters begin
        x = 1, [unit = "mV"]
    end
end

@engeemodel B begin
    @components begin
        a1 = A(x = 2) # is interpreted as 2 mV → 0.002 V
        a2 = A(x = (value = 2, unit = "V"))
    end
end

This example shows that:

  • a1 gets the value 2 in millivolts, as it is specified by default in the component A.

  • a2 gets the value of 2 volts because we explicitly set the unit of measurement via NamedTuple.

Similarly, if the parameter is declared with a unit of measurement "kA", then passing the number 0.8 it will be interpreted as 0.8 kA (800 A). To set exactly 0.8 amperes, you need to write:

@components begin
    a = A(h = (value = 0.8, unit = "A"))
end

Transfers

Enumerations allow you to set a finite set of acceptable parameter values and are conveniently combined with branches. Due to this, the component can operate in different modes, which are selected by the user through a drop-down list in the interface.

For a detailed analysis of enumerations, syntax, and examples, see the article Enumerations, branches, loops, and modules of the Engee Physics Modeling Language