コード例 #1
0
ファイル: PHSSimulationTest.py プロジェクト: loicforma/pyphs
def simulation_rlc_cpp():
    rlc = core.__deepcopy__()
    # Define the simulation parameters
    config = {
        'fs': 48e3,  # Sample rate
        'gradient': 'discret',  # in {'discret', 'theta', 'trapez'}
        'theta': 0.5,  # theta-scheme for the structure
        'split': True,  # apply core.split_linear() beforehand
        'maxit': 10,  # Max iteration for NL solvers
        'numtol': 1e-16,  # Global numerical tolerance
        'path': None,  # Path to the results folder
        'progressbar': True,  # Display a progress bar
        'timer': True,  # Display minimal timing infos
        'language': 'python',  # in {'python', 'c++'}
        'cpp_build_and_run_script': None,  # compile and exec binary
        'eigen_path': None,  # path to Eigen library
    }

    simu = PHSSimulation(rlc, config=config)

    dur = 0.01
    u = signalgenerator(which='sin', f0=800., tsig=dur, fs=simu.fs)

    def sequ():
        for el in u():
            yield (el, )

    simu.init(sequ=sequ(), nt=int(dur * simu.fs))

    simu2cpp(simu)

    return True
コード例 #2
0
def plot_rlc_with_split():
    # Define the simulation parameters
    config = {
        'fs': 48e3,  # Sample rate
        'gradient': 'discret',  # in {'discret', 'theta', 'trapez'}
        'theta': 0.5,  # theta-scheme for the structure
        'split': False,  # apply core.split_linear() beforehand
        'maxit': 10,  # Max iteration for NL solvers
        'numtol': 1e-16,  # Global numerical tolerance
        'path': None,  # Path to the results folder
        'progressbar': True,  # Display a progress bar
        'timer': True,  # Display minimal timing infos
        'language': 'python',  # in {'python', 'c++'}
        'cpp_build_and_run_script': None,  # compile and exec binary
        'eigen_path': None,  # path to Eigen library
    }

    # retrieve the pyphs.PHSCore of a linear RLC from the examples
    from pyphs.examples.rlc.rlc import core as rlc

    print(rlc.w)
    print(rlc.z)

    simu = PHSSimulation(rlc, config=config)

    dur = 0.01
    u = signalgenerator(which='sin', f0=800., tsig=dur, fs=simu.fs)

    def sequ():
        for el in u():
            yield (el, )

    simu.init(sequ=sequ(), nt=int(dur * simu.fs))
    simu.process()

    print(simu.nums.method.core.w)
    print(simu.nums.method.core.z)

    dims = simu.nums.method.core.dims
    # plot u, y
    simu.data.plot([('u', i)
                    for i in range(dims.y())] + [('y', i)
                                                 for i in range(dims.y())],
                   show=False)
    # plot w, z
    simu.data.plot([('w', 0), ('z', 0)], show=False)

    simu.data.plot([('dtx', i)
                    for i in range(dims.x())] + [('dxH', i)
                                                 for i in range(dims.x())],
                   show=False)

    return True
コード例 #3
0
def plot_power_balance_rlc_with_split():
    # Define the simulation parameters
    config = {
        'fs': 48e3,  # Sample rate
        'gradient': 'discret',  # in {'discret', 'theta', 'trapez'}
        'theta': 0.5,  # theta-scheme for the structure
        'split': True,  # apply core.split_linear() beforehand
        'maxit': 10,  # Max iteration for NL solvers
        'numtol': 1e-16,  # Global numerical tolerance
        'path': None,  # Path to the results folder
        'progressbar': True,  # Display a progress bar
        'timer': True,  # Display minimal timing infos
        'language': 'python',  # in {'python', 'c++'}
        'cpp_build_and_run_script': None,  # compile and exec binary
        'eigen_path': None,  # path to Eigen library
    }

    # retrieve the pyphs.PHSCore of a linear RLC from the examples
    from pyphs.examples.rlc.rlc import core as rlc

    rlc_ = rlc.__copy__()
    rlc_.build_R()
    simu = PHSSimulation(rlc_, config=config)

    dur = 0.01
    u = signalgenerator(which='sin', f0=800., tsig=dur, fs=simu.fs)

    def sequ():
        for el in u():
            yield (el, )

    simu.init(sequ=sequ(), nt=int(dur * simu.fs))
    simu.process()

    simu.data.plot_powerbal(mode='single', show=False)
    simu.data.plot_powerbal(mode='multi', show=False)

    return True
コード例 #4
0
config = {'fs': 48e3,           # Sample rate (Hz)
          'grad': 'discret',    # in {'discret', 'theta', 'trapez'}
          'theta': 0.5,         # theta-scheme for the structure
          'split': False,       # split implicit from explicit part
          'maxit': 10,          # Max number of iterations for NL solvers
          'eps': 1e-16,         # Global numerical tolerance
          'path': None,         # Path to the results folder
          'pbar': False,        # Display a progress bar
          'timer': False,       # Display minimal timing infos
          'lang': 'python',     # language in {'python', 'c++'}
          'script': None,       # call to C++ compiler and exec binary
          'eigen': None,        # path to Eigen C++ library
          }

# Instantiate a pyphs.PHSSimulation object associated with a given core PHS
simu = PHSSimulation(core, config=config)

# def simulation time
tmax = 0.02
nmax = int(tmax*simu.fs)
t = [n/simu.fs for n in range(nmax)]
nt = len(t)


# def input signal
def sig(tn, mode='impact'):
    freq = 1000.
    amp = 1000.
    if mode == 'sin':
        pi = numpy.pi
        sin = numpy.sin
コード例 #5
0
netlist = PHSNetlist(netlist_filename)

graph = PHSGraph(netlist=netlist)

core = graph.buildCore()

if __name__ == '__main__':
    config = {
        'fs': 48e3,
        'split': True,
        'pbar': True,
        'timer': True,
        'path': path
    }

    simu = PHSSimulation(core, config=config)

    dur = 0.01
    u = signalgenerator(which='sin', f0=800., tsig=dur, fs=simu.fs)

    def sequ():
        for el in u():
            yield (el, )

    simu.init(sequ=sequ(), nt=int(dur * simu.fs))

    simu.process()

    simu.data.plot_powerbal(mode='multi')

    simu.data.plot([('u', 0), ('x', 1), ('x', 0), ('dtx', 0), ('dxH', 2),
コード例 #6
0
ファイル: PHSSimulationTest.py プロジェクト: loicforma/pyphs
def simulation_nlcore_full():

    # Define the simulation parameters
    config = {
        'fs': 48e3,  # Sample rate
        'grad': 'discret',  # in {'discret', 'theta', 'trapez'}
        'theta': 0.5,  # theta-scheme for the structure
        'split': False,  # apply core.split_linear() beforehand
        'maxit': 10,  # Max number of iterations for NL solvers
        'eps': 1e-16,  # Global numerical tolerance
        'path': None,  # Path to the folder to save the results
        'pbar': False,  # Display a progress bar
        'timer': False,  # Display minimal timing infos
        'lang': 'python',  # in {'python', 'c++'}
        'script': None,  # call to compiler and exec binary
        'eigen': None,  # path to Eigen C++ linear algebra library
    }

    # Instantiate a pyphs.PHSSimulation object associated with a given core PHS
    simu = PHSSimulation(nlcore, config=config)

    # def simulation time
    tmax = 0.02
    nmax = int(tmax * simu.fs)
    t = [n / simu.fs for n in range(nmax)]
    nt = len(t)

    # def input signal
    def sig(tn, mode='impact'):
        freq = 1000.
        amp = 1000.
        if mode == 'sin':
            pi = numpy.pi
            sin = numpy.sin
            out = amp * sin(2 * pi * freq * tn)
        elif mode == 'impact':
            dur = 0.5 * 1e-3  # duration: 0.5ms
            start = 0.001  # start at 1ms
            out = amp if start <= tn < start + dur else 0.
        elif mode == 'const':
            out = 1.
        return out

    # def generator for sequence of inputs to feed in the PHSSimulation object
    def sequ():
        """
        generator of input sequence for PHSSimulation
        """
        for tn in t:
            u1 = sig(tn)

            # !!! must be array with shape (core.dims.u(), )
            yield numpy.array([
                u1,
            ])  # numpy.array([u1, u2, ...])

    # state initialization
    # !!! must be array with shape (core.dims.x(), )
    x0 = (0., 0.)

    # Initialize the simulation
    simu.init(sequ=sequ(), x0=x0, nt=nt)

    # Proceed
    simu.process()

    return True
コード例 #7
0
    'pbar': True,  # Display a progress bar
    'timer': False,  # Display minimal timing infos
    'lang': 'python',  # Language in {'python', 'c++'}
    #          'script': None,       # Call to C++ compiler and exec binary
    #          'eigen': None,        # Path to Eigen C++ library
    # Options for the data reader. The data are read from index imin
    # to index imax, rendering one element out of the number decim
    'load': {
        'imin': 0,
        'imax': None,
        'decim': 1
    }
}

# Instantiate a pyphs.PHSSimulation object associated with a given core PHS
simu = PHSSimulation(core, config=config)

# def simulation time
tmax = 1e-2
nmax = int(tmax * simu.fs)
t = [n / simu.fs for n in range(nmax)]
nt = len(t)


# def input signal
def sig(tn, mode='sin'):
    freq = 300.
    amp = 1000.
    if mode == 'sin':
        pi = numpy.pi
        sin = numpy.sin