
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "grid_examples/grid_forming/plot_13kva_do_gfm_negseq.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_forming_plot_13kva_do_gfm_negseq.py>`
        to download the full example code.

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

.. _sphx_glr_grid_examples_grid_forming_plot_13kva_do_gfm_negseq.py:


12.5-kVA, DO-GFM with sequence separation
=========================================

This example simulates a 12.5-kVA disturbance-observer-based grid-forming (DO-GFM)
converter, connected to a weak grid. The control method is designed to take into account
negative-sequence grid voltage. The positive-sequence converter output voltage and the
positive-sequence active power are directly controlled. Grid synchronization is provided
by the disturbance observer. A transparent current controller is included for current
limitation.

.. GENERATED FROM PYTHON SOURCE LINES 15-19

.. code-block:: Python

    from math import pi

    from motulator.grid import control, model, utils








.. GENERATED FROM PYTHON SOURCE LINES 20-21

Compute base values based on the nominal values.

.. GENERATED FROM PYTHON SOURCE LINES 21-25

.. code-block:: Python


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








.. GENERATED FROM PYTHON SOURCE LINES 26-31

Configure the system model. An unbalanced fault is simulated, where the phase-a grid
voltage drops to 0.5 p.u. at 0.4 s, rises to 0.75 p.u. at 0.5 s, and finally rises to
1 p.u. at 0.6 s. The zero-sequence component of the fault is omitted, since it does
not affect the three-wire system. Therefore, the phase-a voltage of the model drops
to 2/3 p.u. and then rises to 5/6 p.u.

.. GENERATED FROM PYTHON SOURCE LINES 31-46

.. code-block:: Python


    ac_filter = model.LFilter(L_f=0.15 * base.L, L_g=0.62 * base.L)
    ac_source = model.ThreePhaseSource(
        w_g=base.w,
        e_g=lambda t: (
            (1 - (t > 0.4) * 1 / 6 + (t > 0.5) * 1 / 12 + (t > 0.6) * 1 / 12) * base.u
        ),
        e_g_neg=lambda t: (
            ((t > 0.4) * 1 / 6 - (t > 0.5) * 1 / 12 - (t > 0.6) * 1 / 12) * base.u
        ),
        phi_neg=pi,
    )
    converter = model.VoltageSourceConverter(u_dc=660)
    mdl = model.GridConverterSystem(converter, ac_filter, ac_source)








.. GENERATED FROM PYTHON SOURCE LINES 47-48

Configure the control system.

.. GENERATED FROM PYTHON SOURCE LINES 48-55

.. code-block:: Python


    cfg = control.SequenceObserverBasedGridFormingControllerCfg(
        i_max=1.3 * base.i, i_d_max=1.1 * base.i, L=0.2 * base.L, T_s=1 / 16e3
    )
    inner_ctrl = control.SequenceObserverBasedGridFormingController(cfg)
    ctrl = control.GridConverterControlSystem(inner_ctrl)








.. GENERATED FROM PYTHON SOURCE LINES 56-57

Set the references for converter output voltage magnitude and active power.

.. GENERATED FROM PYTHON SOURCE LINES 57-72

.. code-block:: Python


    ctrl.set_ac_voltage_ref(base.u)
    ctrl.set_power_ref(lambda t: (t > 0.1) * nom.P)

    # Uncomment lines below to simulate a three-phase grid-voltage sag to 0.5 p.u.
    # mdl.ac_source.e_g = lambda t: (1 - (t > 0.4) * 0.5 + (t > 0.6) * 0.5) * base.u
    # mdl.ac_source.e_g_neg = 0

    # Uncomment lines below to simulate active-power reference tracking
    # mdl.ac_source.e_g = base.u
    # mdl.ac_source.e_g_neg = 0
    # ctrl.set_power_ref(
    #     lambda t: ((t > 0.1) - (t > 0.25) - (t > 0.4) + (t > 0.55)) * nom.P
    # )








.. GENERATED FROM PYTHON SOURCE LINES 73-74

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

.. GENERATED FROM PYTHON SOURCE LINES 74-79

.. code-block:: Python


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



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


    *

      .. image-sg:: /grid_examples/grid_forming/images/sphx_glr_plot_13kva_do_gfm_negseq_001.png
         :alt: plot 13kva do gfm negseq
         :srcset: /grid_examples/grid_forming/images/sphx_glr_plot_13kva_do_gfm_negseq_001.png
         :class: sphx-glr-multi-img

    *

      .. image-sg:: /grid_examples/grid_forming/images/sphx_glr_plot_13kva_do_gfm_negseq_002.png
         :alt: plot 13kva do gfm negseq
         :srcset: /grid_examples/grid_forming/images/sphx_glr_plot_13kva_do_gfm_negseq_002.png
         :class: sphx-glr-multi-img






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

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


.. _sphx_glr_download_grid_examples_grid_forming_plot_13kva_do_gfm_negseq.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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