Created on Sun Jun 11 11:17:07 2017 @author: Falaize """ from __future__ import absolute_import, division, print_function import os from pyphs import Netlist, Graph # --------------------------- NETLIST ------------------------------------- # label = 'piano_hammer' this_script = os.path.realpath(__file__) here = this_script[:this_script.rfind(os.sep)] netlist_filename = here + os.sep + label + '.net' netlist = Netlist(netlist_filename) # --------------------------- GRAPH --------------------------------------- # graph = Graph(netlist=netlist) # --------------------------- CORE ---------------------------------------- # core = graph.to_core() ## --------------------------- SIMULATION ---------------------------------- # #if __name__ == '__main__': # # import numpy # import matplotlib.pyplot as plt # from pyphs import Simulation # # core.reduce_z()
# electronics.resistor R1 ('A', 'B'): R=('R1', 1000.0); # electronics.inductor L1 ('B', 'C'): L=('L1', 0.05); # electronics.capacitor C1 ('C', 'ref'): C=('C1', 2e-06); # ``` # # Automated netlist generation # There is two reasons you want to automatize the generation of the netlist: # 1. It allows for easy management of sequential experiments (*e.g.* for which a single parameter take several values). # 2. It is more robust with respect to possible changes of the netlist formating in the future of `pyphs`. # # This is done by defining each component as a line of the netlist in the `pyphs.Netlist`. This structure is defined by the `pyphs.graphs.Netlist` class, and is accessible with # In[2]: from pyphs import Netlist net = Netlist('rlc.net', clear = True) # Each line is defined with the `phs.graph.netlist.add_line` command, which takes python dicitonary with the following structure as arguments: # ```python # netlist_line = {'dictionary': 'dico', # 'component': 'comp', # 'label': 'label', # 'nodes': ('node1', ..., 'nodeN'), # 'arguments': {'par1': "('lab1', val1)", # 'par2': "'lab2'", # 'par3': "val3" # } # } # ``` # As an example, the declaration of the RLC components to the above `phs` object is as follows.
def NetlistThieleSmallNL(clear=True, R=1e3, L=5e-2, Bl=50, M=0.1, K=5e3, A=1): """ Write the netlist for a nonlinear version of the thieleSmall modeling of \ loudspeakers. """ netlist = Netlist(path, clear=clear) datum = netlist.datum # input voltage source = { 'dictionary': 'electronics', 'component': 'source', 'label': 'IN', 'nodes': ('A', datum), 'arguments': { 'type': "voltage" } } netlist.add_line(source) # resistor 1 resistance = { 'dictionary': 'electronics', 'component': 'resistor', 'label': 'R', 'nodes': ('A', 'B'), 'arguments': { 'R': ('R', R) } } netlist.add_line(resistance) # inductor inductor = { 'dictionary': 'electronics', 'component': 'inductor', 'label': 'L', 'nodes': ('B', 'C'), 'arguments': { 'L': ('L', L) } } netlist.add_line(inductor) # gyrator gyrator = { 'dictionary': 'connectors', 'component': 'gyrator', 'label': 'G', 'nodes': ('C', datum, 'D', datum), 'arguments': { 'alpha': ('Bl', Bl) } } netlist.add_line(gyrator) # masse mass = { 'dictionary': 'mechanics_dual', 'component': 'mass', 'label': 'M', 'nodes': ('D', 'E'), 'arguments': { 'M': ('M', M) } } netlist.add_line(mass) # ressort cubic stifness = { 'dictionary': 'mechanics_dual', 'component': 'springcubic', 'label': 'K', 'nodes': ('E', 'F'), 'arguments': { 'K0': ('K0', K), 'K2': ('K2', 1e20) } } netlist.add_line(stifness) # amortissement damper = { 'dictionary': 'mechanics_dual', 'component': 'damper', 'label': 'A', 'nodes': ('F', datum), 'arguments': { 'A': ('A', A) } } netlist.add_line(damper) netlist.write() return netlist
""" 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)