コード例 #1
0
ファイル: PIDs-nyquist.py プロジェクト: kdavies4/ModelicaRes
#!/usr/bin/pythont
"""Example of LinResList.nyquist()
"""

# pylint: disable=I0011, C0103, W0301

from os.path import join
from modelicares import LinResList, read_params

lins = LinResList("PID.mat", "PID/*/")

# Parameter settings aren't recorded in the files, so we'll load the
# differential time constants from the corresponding dsin.txt files.
for lin in lins:
    lin.label = "Td = %g s" % read_params("Td", join(lin.dirname, "dsin.txt"))

# and sort the results by that information:
lins.sort(key=lambda lin: lin.label)

# and finally plot:
lins.nyquist(
    title=("Nyquist plot of Modelica.Blocks.Continuous.PID\n" "with varying differential time constant"),
    freqs=(0.1, 100),
)
コード例 #2
0
ファイル: make.py プロジェクト: arnoutaertgeerts/ModelicaRes
def static():
    """Create static images for the HTML documentation and the base README.md.
    """
    import matplotlib.pyplot as plt
    from modelicares import SimRes, LinResList, read_params

    join = os.path.join

    # Options
    indir = "../examples"  # Directory with the mat files.
    outdir = "_static"  # Directory where the images should be generated
    dpi = 90  # DPI for the HTML index images
    dpi_small = 30  # DPI for the README images
    kwargs = dict(bbox_inches='tight', format='png')  # Other savefig() options

    # ThreeTanks
    # ----------
    sim = SimRes(join(indir, 'ThreeTanks.mat'))
    sim.sankey(title=("Sankey diagrams of "
                      "Modelica.Fluid.Examples.Tanks.ThreeTanks"),
               times=[0, 50, 100, 150], n_rows=2, format='%.1f ',
               names=['tank1.ports[1].m_flow', 'tank2.ports[1].m_flow',
                      'tank3.ports[1].m_flow'],
               labels=['Tank 1', 'Tank 2', 'Tank 3'],
               orientations=[-1, 0, 1],
               scale=0.1, margin=6, offset=1.5,
               pathlengths=2, trunklength=10)
    plt.savefig(join(outdir, 'ThreeTanks.png'), dpi=dpi, **kwargs)
    plt.savefig(join(outdir, 'ThreeTanks-small.png'), dpi=dpi_small, **kwargs)
    plt.close()

    # ChuaCircuit
    # -----------
    sim = SimRes(join(indir, 'ChuaCircuit.mat'))
    ax = sim.plot(ynames1='L.v', ylabel1="Voltage",
                  xname='L.i', xlabel="Current",
                  title=("Modelica.Electrical.Analog.Examples.ChuaCircuit\n"
                         "Current through and voltage across the inductor"))[0]
    # Mark the start and stop points.
    def mark(time, text):
        """Mark a frequency point.
        """
        i = sim['L.i'].values(time)
        v = sim['L.v'].values(time)
        plt.plot(i, v, 'bo')
        ax.annotate(text, xy=(i, v), xytext=(0, -4), ha='center', va='top',
                    textcoords='offset points')
    mark(0, "Start")
    mark(2500, "Stop")
    # Save and close.
    plt.savefig(join(outdir, 'ChuaCircuit.png'), dpi=dpi, **kwargs)
    plt.savefig(join(outdir, 'ChuaCircuit-small.png'), dpi=dpi_small, **kwargs)
    plt.close()

    # PIDs-bode
    # ---------
    lins = LinResList(join(indir, 'PID.mat'), join(indir, 'PID/*/'))
    for lin in lins:
        lin.label = "Td = %g s" % read_params('Td', join(lin.dirname,
                                                         'dsin.txt'))
    lins.sort(key=lambda lin: lin.label)
    lins.bode(title=("Bode plot of Modelica.Blocks.Continuous.PID\n"
                     "with varying differential time constant"))
    plt.savefig(join(outdir, 'PIDs-bode.png'), dpi=dpi, **kwargs)
    plt.savefig(join(outdir, 'PIDs-bode-small.png'), dpi=dpi_small, **kwargs)
    plt.close()
コード例 #3
0
ファイル: PIDs-bode.py プロジェクト: acquatella/ModelicaRes
#!/usr/bin/python
"""Example of LinResList.bode()
"""

# pylint: disable=I0011, C0103, R0801

from os.path import join
from modelicares import LinResList, read_params

lins = LinResList('PID.mat', 'PID/*/')

# Parameter settings aren't recorded in the files, so we'll load the
# differential time constants from the corresponding dsin.txt files.
for lin in lins:
    lin.label = "Td = %g s" % read_params('Td', join(lin.dirname, 'dsin.txt'))

# and sort the results by that information:
lins.sort(key=lambda lin: lin.label)

# and finally plot:
lins.bode(title=("Bode plot of Modelica.Blocks.Continuous.PID\n"
                 "with varying differential time constant"))