.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/coupling/n2_chart.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_coupling_n2_chart.py: N2 chart ======== .. GENERATED FROM PYTHON SOURCE LINES 25-33 .. code-block:: Python from __future__ import annotations from numpy import ones from gemseo import generate_n2_plot from gemseo.utils.discipline import DummyDiscipline .. GENERATED FROM PYTHON SOURCE LINES 34-36 Create the disciplines ---------------------- .. GENERATED FROM PYTHON SOURCE LINES 36-64 .. code-block:: Python descriptions = { "A": ([f"a{i}" for i in range(500)], ["b"]), "B": (["c"], [f"a{i}" for i in range(500)] + ["n"]), "C": (["b", "d"], ["c", "e"]), "D": (["f"], ["d", "g"]), "E": (["e"], ["f", "h", "o"]), "F": (["g", "j"], ["i"]), "G": (["i", "h"], ["k", "l"]), "H": (["k", "m"], ["j"]), "I": (["l"], ["m", "w"]), "J": (["n", "o"], ["p", "q"]), "K": (["y"], ["x"]), "L": (["w", "x"], ["y", "z"]), "M": (["p", "s"], ["r"]), "N": (["r"], ["t", "u"]), "O": (["q", "t"], ["s", "v"]), "P": (["u", "v", "z"], ["z"]), } disciplines = [] data = ones(1) for discipline_name, (inputs, outputs) in descriptions.items(): inputs = dict.fromkeys(inputs, data) outputs = dict.fromkeys(outputs, data) discipline = DummyDiscipline(discipline_name) discipline.input_grammar.update_from_data(dict.fromkeys(inputs, data)) discipline.output_grammar.update_from_data(dict.fromkeys(outputs, data)) disciplines.append(discipline) .. GENERATED FROM PYTHON SOURCE LINES 65-81 Generate the N2 chart --------------------- The N2 chart is a tabular way to visualize multidisciplinary coupling variables. The disciplines are located on the diagonal of the chart while the coupling variables are situated on the other blocks of the matrix view. A coupling variable is outputted by a discipline horizontally and enters another vertically. In the classical representation, a blue diagonal block represents a self-coupled discipline, *i.e.* a discipline having some of its outputs as inputs. Because of its tabular structure, the N2 chart is hard to analyze when the number of disciplines increases. This is the reason why in this example, we propose to use an interactive representation in a web browser: .. GENERATED FROM PYTHON SOURCE LINES 81-83 .. code-block:: Python generate_n2_plot(disciplines, save=False, show_html=True) .. GENERATED FROM PYTHON SOURCE LINES 84-85 `Click here <../../_static/n2.html>`_ to see the rendering. .. _sphx_glr_download_examples_coupling_n2_chart.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: n2_chart.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: n2_chart.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: n2_chart.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_