def generate_netlist(): netlist_path = os.path.join(path, netlist_name + '.net') netlist = PHSNetlist(netlist_path, clear=True) netlist_line = {'dictionary': 'pwl', 'component': 'storage', 'label': 'stor', 'arguments': {'file': repr(data_path), 'ctrl': 'e', 'integ': True}, 'nodes': ('N1', 'N2')} netlist.add_line(netlist_line) netlist_line = {'dictionary': 'pwl', 'component': 'dissipative', 'label': 'diss', 'arguments': {'file': repr(data_path), 'ctrl': 'f'}, 'nodes': (datum, 'N1')} netlist.add_line(netlist_line) netlist_line = {'dictionary': 'electronics', 'component': 'source', 'label': 'IN', 'arguments': {'type': 'voltage', 'ctrl': 'f'}, 'nodes': (datum, 'N2')} netlist.add_line(netlist_line) netlist.write()
from __future__ import absolute_import, division, print_function import os from pyphs import (netlist2core, PHSSimulation, signalgenerator, PHSNetlist, PHSGraph) from pyphs.misc.signals.analysis import transferFunction import matplotlib.pyplot as plt import numpy as np label = 'fractional_derivator_ec' path = os.path.realpath(__file__)[:os.path.realpath(__file__).rfind(os.sep)] netlist_filename = path + os.sep + label + '.net' netlist = PHSNetlist(netlist_filename) graph = PHSGraph(netlist=netlist) core = netlist2core(netlist_filename) if __name__ == '__main__': # UNCOMMENT BELOW FOR SIMULATION and PLOT OF TRANSFER FUNCTION # !!! Very long simulation with numpy # config = {'fs': 48e3, # 'split': True, # 'pbar': True, # 'timer': True, # 'lang': 'python' # } # # simu = PHSSimulation(core, config=config)
def NetlistThieleSmallNL(label='TSnl', 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 = PHSNetlist(os.getcwd() + os.sep + label + '.net', 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) return netlist