N2 chart#

from __future__ import annotations

from numpy import ones

from gemseo import generate_n2_plot
from gemseo.utils.discipline import DummyDiscipline

Create the disciplines#

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)

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:

generate_n2_plot(disciplines, save=False, show_html=True)

Click here to see the rendering.

Gallery generated by Sphinx-Gallery