
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "grid_examples/grid_following/plot_10kva_startup_gfl.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_grid_examples_grid_following_plot_10kva_startup_gfl.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_grid_examples_grid_following_plot_10kva_startup_gfl.py:


10-kVA, start-up, GFL
=====================

This example simulates the start-up of a grid-following converter with DC-bus voltage
control. The converter gates are blocked at first. The DC bus is charged from its
initial voltage of 500 V through the antiparallel diodes toward the peak line-to-line
voltage of the grid, while the phase-locked loop synchronizes with the grid and the
current controller tracks the measured converter voltage. The gates are released at
40 ms, after which the DC-bus voltage controller raises the voltage to 650 V, with the
power limited to the nominal power. A reactive power reference step follows.

.. GENERATED FROM PYTHON SOURCE LINES 16-21

.. code-block:: Python

    import matplotlib.pyplot as plt
    import numpy as np

    from motulator.grid import control, model, utils








.. GENERATED FROM PYTHON SOURCE LINES 22-23

Compute base values based on the nominal values.

.. GENERATED FROM PYTHON SOURCE LINES 23-27

.. code-block:: Python


    nom = utils.NominalValues(U=400, I=14.5, f=50, P=10e3)
    base = utils.BaseValues.from_nominal(nom)








.. GENERATED FROM PYTHON SOURCE LINES 28-29

Configure the system model.

.. GENERATED FROM PYTHON SOURCE LINES 29-36

.. code-block:: Python


    ac_filter = model.LFilter(L_f=0.2 * base.L)
    ac_source = model.ThreePhaseSource(w_g=base.w, e_g=base.u)
    converter = model.VoltageSourceConverter()
    dc_bus = model.DCBus(C_dc=1e-3, u_dc=500, converters=[converter])
    mdl = model.GridConverterSystem(converter, ac_filter, ac_source, dc_bus=dc_bus)








.. GENERATED FROM PYTHON SOURCE LINES 37-38

Configure the control system.

.. GENERATED FROM PYTHON SOURCE LINES 38-46

.. code-block:: Python


    cfg = control.CurrentVectorControllerCfg(i_max=1.5 * base.i, L=0.2 * base.L)
    inner_ctrl = control.CurrentVectorController(cfg)
    dc_bus_voltage_ctrl = control.DCBusVoltageController(
        C_dc=1e-3, alpha_dc=2 * np.pi * 30, p_max=base.p
    )
    ctrl = control.GridConverterControlSystem(inner_ctrl, dc_bus_voltage_ctrl)








.. GENERATED FROM PYTHON SOURCE LINES 47-48

Set the gate enable and the references.

.. GENERATED FROM PYTHON SOURCE LINES 48-53

.. code-block:: Python


    ctrl.set_enable(lambda t: t >= 0.04)
    ctrl.set_dc_bus_voltage_ref(650)
    ctrl.set_reactive_power_ref(lambda t: (t > 0.1) * 4e3)








.. GENERATED FROM PYTHON SOURCE LINES 54-55

Create the simulation object, simulate, and plot the results in per-unit values.

.. GENERATED FROM PYTHON SOURCE LINES 55-61

.. code-block:: Python


    sim = model.Simulation(mdl, ctrl)
    res = sim.simulate(t_stop=0.15)
    utils.plot_control_signals(res, base)
    utils.plot_grid_waveforms(res, base)




.. rst-class:: sphx-glr-horizontal


    *

      .. image-sg:: /grid_examples/grid_following/images/sphx_glr_plot_10kva_startup_gfl_001.png
         :alt: plot 10kva startup gfl
         :srcset: /grid_examples/grid_following/images/sphx_glr_plot_10kva_startup_gfl_001.png
         :class: sphx-glr-multi-img

    *

      .. image-sg:: /grid_examples/grid_following/images/sphx_glr_plot_10kva_startup_gfl_002.png
         :alt: plot 10kva startup gfl
         :srcset: /grid_examples/grid_following/images/sphx_glr_plot_10kva_startup_gfl_002.png
         :class: sphx-glr-multi-img





.. GENERATED FROM PYTHON SOURCE LINES 62-65

Plot the DC-bus voltage and the DC current of the converter, the interval with
blocked gates shaded. The diodes charge the DC bus toward the peak line-to-line
voltage of the grid, the current pulses shrinking as the voltage approaches it.

.. GENERATED FROM PYTHON SOURCE LINES 65-85

.. code-block:: Python


    t_on = res.ctrl.t[np.flatnonzero(res.ctrl.ref.enabled)[0]]
    fig, (ax1, ax2) = plt.subplots(2, 1, sharex=True)
    for ax in (ax1, ax2):
        ax.axvspan(0, t_on, color="0.9")
    ax1.plot(res.mdl.t, res.mdl.dc_bus.u_dc, label=r"$u_\mathrm{dc}$")
    ax1.plot(
        res.ctrl.t,
        res.ctrl.ref.u_dc,
        "--",
        ds="steps-post",
        label=r"$u_\mathrm{dc}^\mathrm{ref}$",
    )
    ax1.set_ylabel("Voltage (V)")
    ax1.legend()
    ax2.plot(res.mdl.t, res.mdl.converter.i_dc_int / base.i)
    ax2.set_ylabel(r"$i_\mathrm{dc}$ (p.u.)")
    ax2.set_xlabel("Time (s)")
    ax2.set_xlim(0, 0.15)
    plt.show()



.. image-sg:: /grid_examples/grid_following/images/sphx_glr_plot_10kva_startup_gfl_003.png
   :alt: plot 10kva startup gfl
   :srcset: /grid_examples/grid_following/images/sphx_glr_plot_10kva_startup_gfl_003.png
   :class: sphx-glr-single-img






.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 1.147 seconds)


.. _sphx_glr_download_grid_examples_grid_following_plot_10kva_startup_gfl.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: plot_10kva_startup_gfl.ipynb <plot_10kva_startup_gfl.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: plot_10kva_startup_gfl.py <plot_10kva_startup_gfl.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: plot_10kva_startup_gfl.zip <plot_10kva_startup_gfl.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
