예제 #1
0
def cs_network(K=1., T1=5., Ts=1.):
    """The network is formed from slaves"""
    connections = {
        cs.Dst('PI', 'u'): cs.Src('PT2', 'y'),
        cs.Dst('PT2', 'u'): cs.Src('PI', 'y'),
    }
    return slaves(K, T1, Ts), connections
예제 #2
0
def _semiconnected_ramps(slope1=1., slope2=1.) -> cs.Network:
    """Example network used to test the defect calculation"""
    class _Ramp(cs.Simulator):
        """Used in tests to mock a simulator"""
        def __init__(self, slope: Fraction, step_size: Fraction):
            self._step_size = step_size
            self._x = Fraction(0)
            self._slope = slope

        @property
        def inputs(self):
            return {'u': sdf.InputPort(float, 1)}

        @property
        def outputs(self):
            return {'y': sdf.OutputPort(float, 1)}

        def calculate(self, input_tokens):
            self._x += self._slope * self._step_size
            return {'y': [float(self._x)]}

    def construct_ramp1(step_size):
        return _Ramp(slope1, step_size)

    def construct_ramp2(step_size):
        return _Ramp(slope2, step_size)

    slaves = {'Ramp1': construct_ramp1, 'Ramp2': construct_ramp2}

    connections = {
        cs.Dst('Ramp1', 'u'): cs.Src('Ramp2', 'y'),
        cs.Dst('Ramp2', 'u'): cs.Src('Ramp1', 'y'),
    }
    return slaves, connections
예제 #3
0
파일: engine.py 프로젝트: sglumac/sdf4sim
def rate_converters():
    """Two ZOH converters"""
    return {
        cs.Connection(cs.Src('inertia', 'omega'), cs.Dst('engine', 'omega')):
        cs.Zoh,
        cs.Connection(cs.Src('alpha', 'alpha'), cs.Dst('engine', 'alpha')):
        cs.Zoh,
        cs.Connection(cs.Src('engine', 'tau'), cs.Dst('inertia', 'tau')):
        cs.Zoh,
    }
예제 #4
0
파일: engine.py 프로젝트: sglumac/sdf4sim
def cs_network(parameters: EngineExperiment) -> cs.Network:
    """A network with an engine and a rotational inertia"""
    def construct_engine(step_size: Fraction) -> sdf.Agent:
        return Engine(parameters.engine, step_size)

    def construct_inertia(step_size: Fraction) -> sdf.Agent:
        return RotationalInertia(parameters.inertia, step_size)

    def construct_alpha(step_size: Fraction) -> sdf.Agent:
        return Alpha(parameters.alpha, step_size)

    slaves: cs.SimulatorContructors = {
        'engine': construct_engine,
        'inertia': construct_inertia,
        'alpha': construct_alpha,
    }
    connections: cs.Connections = {
        cs.Dst('engine', 'omega'): cs.Src('inertia', 'omega'),
        cs.Dst('engine', 'alpha'): cs.Src('alpha', 'alpha'),
        cs.Dst('inertia', 'tau'): cs.Src('engine', 'tau'),
    }
    return slaves, connections
예제 #5
0
파일: twomass.py 프로젝트: sglumac/sdf4sim
def cs_network(parameters: TwoMass):
    """The network of six mechanical translational elements"""
    def construct_left(step_size: Fraction):
        return SideOscillator(parameters.left, step_size)

    def construct_middle(step_size: Fraction):
        return MiddleOscillator(parameters.middle, step_size)

    def construct_right(step_size: Fraction):
        return SideOscillator(parameters.right, step_size)

    slaves = {
        'left_oscillator': construct_left,
        'middle_oscillator': construct_middle,
        'right_oscillator': construct_right,
    }
    connections = {
        cs.Dst('left_oscillator', 'F'): cs.Src('middle_oscillator', 'F_right'),
        cs.Dst('middle_oscillator', 'v_left'): cs.Src('left_oscillator', 'v'),
        cs.Dst('right_oscillator', 'F'): cs.Src('middle_oscillator', 'F_left'),
        cs.Dst('middle_oscillator', 'v_right'): cs.Src('right_oscillator',
                                                       'v'),
    }
    return slaves, connections
예제 #6
0
def rate_converters():
    """Two ZOH converters"""
    return {
        cs.Connection(cs.Src('PI', 'y'), cs.Dst('PT2', 'u')): cs.Zoh,
        cs.Connection(cs.Src('PT2', 'y'), cs.Dst('PI', 'u')): cs.Zoh,
    }