Beispiel #1
0
this_script = os.path.realpath(__file__)
here = this_script[:this_script.rfind(os.sep)]


def netlist_path(label):
    return here + os.sep + label + '.net'


def sort_outputs(core):
    for i in range(core.dims.y()):
        if not str(core.y[i]).endswith(str(i+1)):
            core.move_port([str(y).endswith(str(i+1)) for y in core.y].index(True), i)

# build simple Cores
net1 = Netlist(netlist_path('phs1'))
c1 = net1.to_core()
sort_outputs(c1)
net2 = Netlist(netlist_path('phs2'))
c2 = net2.to_core()
sort_outputs(c2)

# concatenate c1 and c2 into a new Core
core = c1 + c2
# define the connection
core.add_connector((core.y.index(c1.y[1]), core.y.index(c2.y[1])),
                alpha=1)

# apply the connection
core.connect()

# target structure matrix
@author: Falaize
"""

from __future__ import absolute_import, division, print_function

import os
from pyphs import Netlist

label = 'fractional_integrator_fc'

path = os.path.realpath(__file__)[:os.path.realpath(__file__).rfind(os.sep)]

netlist_filename = path + os.sep + label + '.net'
netlist = Netlist(netlist_filename)
core = netlist.to_core()


# %% ------------------------------ SIMULATION ------------------------------ #

# UNCOMMENT BELOW FOR SIMULATION and PLOT OF TRANSFER FUNCTION
# !!! Very long simulation with numpy (use c++ if possible)

#if __name__ == '__main__':
#    from pyphs import Simulation, signalgenerator
#    from pyphs.misc.signals.analysis import transferFunction
#    import matplotlib.pyplot as plt
#    import numpy as np
#
#    config = {'fs': 48e3,
#              'split': True,
Beispiel #3
0

# The netlist is written in the current working directory with:

# In[9]:

net.write()


# This generates the following [RLC.net](/pyphs_outputs/RLC_auto/RLC.net) file.
# # Graph analysis
# The differential-algebraic equations that govern the system are obtained with the `phs.build_from_netlist` method as follows:

# In[10]:

core = net.to_core()


# Voila.
#
# Now, we can *e.g.* generate a latex description of the system with:

# In[11]:

core.texwrite()


# which generates that [RLC.tex](/pyphs_outputs/rlc.tex) in the folder pointed by `phs.paths['tex']`. Compiling this file yields the following [RLC.pdf](/pyphs_outputs/rlc.pdf).
#
# The elements of the system structure are accessed as follows. First, we activate nice representations of symbolic relations with `mathjax` from `sympy.init_printing`:
@author: Falaize
"""

from __future__ import absolute_import, division, print_function

import os
from pyphs import Netlist

label = 'fractional_intergrator_ec'

path = os.path.realpath(__file__)[:os.path.realpath(__file__).rfind(os.sep)]

netlist_filename = path + os.sep + label + '.net'
netlist = Netlist(netlist_filename)
core = netlist.to_core()
# UNCOMMENT BELOW FOR SIMULATION and PLOT OF TRANSFER FUNCTION
# !!! Very long simulation with numpy
#
#if __name__ == '__main__':
#
#    from pyphs import  Simulation, signalgenerator
#    from pyphs.misc.signals.analysis import transferFunction
#    import matplotlib.pyplot as plt
#    import numpy as np
#
#    config = {'fs': 48e3,
#              'split': True,
#              'pbar': True,
#              'timer': True,
#              'lang': 'python'
Beispiel #5
0
    return here + os.sep + label + '.net'


def sort_outputs(core):
    """
    Build netlist file name from label.
    """
    for i in range(core.dims.y()):
        if not str(core.y[i]).endswith(str(i + 1)):
            core.move_port([str(y).endswith(str(i + 1))
                            for y in core.y].index(True), i)


# build simple Cores
net1 = Netlist(netlist_path('phs1'))
c1 = net1.to_core()
sort_outputs(c1)

net2 = Netlist(netlist_path('phs2'))
c2 = net2.to_core()
sort_outputs(c2)

# -----------------------------  CONNECT  ----------------------------------- #

# concatenate c1 and c2 into a new Core
core = c1 + c2

# define the connection
core.add_connector((core.y.index(c1.y[1]), core.y.index(c2.y[1])), alpha=1)

# apply the connection
Beispiel #6
0

# The netlist is written in the current working directory with:

# In[9]:

net.write()


# This generates the following [RLC.net](/pyphs_outputs/RLC_auto/RLC.net) file.
# # Graph analysis
# The differential-algebraic equations that govern the system are obtained with the `phs.build_from_netlist` method as follows:

# In[10]:

core = net.to_core()


# Voila.
#
# Now, we can *e.g.* generate a latex description of the system with:

# In[11]:

core.texwrite()


# which generates that [RLC.tex](/pyphs_outputs/rlc.tex) in the folder pointed by `phs.paths['tex']`. Compiling this file yields the following [RLC.pdf](/pyphs_outputs/rlc.pdf).
#
# The elements of the system structure are accessed as follows. First, we activate nice representations of symbolic relations with `mathjax` from `sympy.init_printing`: