motulator_export.simulink
=========================

.. py:module:: motulator_export.simulink

.. autoapi-nested-parse::

   
   Export motulator systems to Simulink.

   `write_model` writes the MATLAB scripts that build a Simulink model of a system built
   in motulator, and `simulate` builds and runs the model via the MATLAB Engine API for
   Python.















   ..
       !! processed by numpydoc !!


Functions
---------

.. autoapisummary::

   motulator_export.simulink.simulate
   motulator_export.simulink.write_model


Package Contents
----------------

.. py:function:: simulate(path, t_eval, mdl, ctrl, build = True)

   
   Simulate the Simulink model of the system via the MATLAB Engine API for Python.

   :param path: Path of the model (.slx), next to its scripts.
   :type path: str | Path
   :param t_eval: Output times (s).
   :type t_eval: ndarray
   :param mdl: Continuous-time system model of the written model.
   :type mdl: Drive | GridConverterSystem
   :param ctrl: Discrete-time control system of the written model, which defines the
                monitored signals.
   :type ctrl: VectorControlSystem | VHzControlSystem | GridConverterControlSystem
   :param build: Run the build script `build_<model>.m` first, defaults to True.
   :type build: bool, optional

   :returns: * **mdl** (*dict[str, ndarray]*) -- Signals of the system model (the output port "mdl") and the time "t".
             * **ctrl** (*dict[str, ndarray]*) -- Monitored signals of the control system (the output port "ctrl") and the time
               "t".















   ..
       !! processed by numpydoc !!

.. py:function:: write_model(path, mdl, ctrl, t_stop, code = 'c')

   
   Write the MATLAB scripts that build the Simulink model of the system.

   Running `build_<model>.m` in MATLAB builds the model and saves it in the same
   folder. The model runs `init_<model>.m`, which defines the parameters, after
   loading and at the start of each simulation. The references are read from `mdl`
   and `ctrl` as in `plecs.write_model`, but the gate enable must be 1, since the
   system model of Simulink does not block the gates.

   :param path: Path of the model (.slx). The scripts `build_<model>.m` and `init_<model>.m`
                are written in the same folder, with the sources of the S-functions
                (`sfun_*.c`) or the MATLAB functions (`mfun_*.m`) of the blocks.
   :type path: str | Path
   :param mdl: Continuous-time system model.
   :type mdl: Drive | GridConverterSystem
   :param ctrl: Discrete-time control system.
   :type ctrl: VectorControlSystem | VHzControlSystem | GridConverterControlSystem
   :param t_stop: Simulation stop time (s).
   :type t_stop: float
   :param code: Code of the blocks of the control system: "c" (the C port in S-functions,
                the default) or "matlab" (the MATLAB port in MATLAB Function blocks).
   :type code: str, optional

   :returns: Path of the build script.
   :rtype: Path















   ..
       !! processed by numpydoc !!

