예제 #1
0
    def __init__(self, string, position=None, restitution_coeff=1.):
        """"
        """
        # siconos relation
        self.position = position[1] * npw.ones(1)
        self.contact_index = position[0]
        if string.modal_form:
            coeff = 1.  # string.length / string._N
            if string.use_sparse:
                hmat = sk.SimpleMatrix(1, string.ndof, sk.SPARSE, string.ndof)
                for i in xrange(string.ndof):
                    val = coeff * string.s_mat[self.contact_index, i]
                    hmat.setValue(0, i, val)
            else:
                hmat = npw.zeros((1, string.ndof))
                hmat[...] = string.s_mat[self.contact_index, :]
                hmat *= coeff
        else:
            hmat = npw.zeros((1, string.ndof))
            hmat[0, self.contact_index] = 1.

        e = restitution_coeff
        nslaw = sk.NewtonImpactNSL(e)
        relation = sk.LagrangianLinearTIR(hmat, -self.position)
        super(Fret, self).__init__(nslaw, relation)
예제 #2
0
 def __init__(self, string, contact_positions, restitution_coeff):
     """
     Parameters
     ----------
     string : :class:`StringDS`
         the dynamical system linked to this interaction
     contact_positons : tuple
         contact_positions[0] = horizontal index position
          of the contact point
         contact_positions[1] = vertical position of the fret
     restitution_coeff : double
         coefficient of restitution
     """
     # vertical positions of the contact points
     hmat = npw.zeros((1, string.n_modes))
     dx = string.space_step
     hmat[0, :] = string.s_mat[contact_positions[0], :]
     # compute contact point horizontal position
     self.contact_pos = dx * contact_positions[0]
     # set contact index (mind that boundary points
     # are not included in fret/ds)
     self.contact_index = contact_positions[0]
     # Build nslaw, relation and interaction
     e = restitution_coeff
     nslaw = sk.NewtonImpactNSL(e)
     dist = -contact_positions[1]
     relation = sk.LagrangianLinearTIR(hmat, [dist])
     super(Fret, self).__init__(nslaw, relation)
예제 #3
0
    def __init__(self, strings, frets, time_range, fs):
        """
        """
        super(Guitar, self).__init__(time_range[0], time_range[1])
        if not isinstance(strings, list):
            strings = [strings]
        if not isinstance(frets, list):
            frets = [frets]
        self.modal_form = strings[0].modal_form
        self.frets = frets
        self.strings = strings
        for string in strings:
            self.nonSmoothDynamicalSystem().insertDynamicalSystem(string)
            # link the interaction(s) and the dynamical system(s)
            for fret in frets:
                self.nonSmoothDynamicalSystem().link(fret, string)

        # -- Simulation --
        # (1) OneStepIntegrators
        theta = 0.5001
        osi = sk.MoreauJeanOSI(theta)
        t0 = time_range[0]
        tend = time_range[1]
        # (2) Time discretisation --
        self.fs = fs  # 1960
        self.time_step = 1. / fs
        t = sk.TimeDiscretisation(t0, self.time_step)
        self.nb_time_steps = (int)((tend - t0) / self.time_step)
        # (3) one step non smooth problem
        osnspb = sk.LCP()
        # (4) Simulation setup with (1) (2) (3)
        self.simu = sk.TimeStepping(t, osi, osnspb)

        # simulation initialization
        self.setSimulation(self.simu)
        self.initialize()
        ndof = strings[0].ndof
        self.fret_position = frets[0].contact_index
        self.data = npw.zeros((self.nb_time_steps + 1, 3 + ndof))
예제 #4
0
    def __init__(self,
                 strings_and_frets,
                 time_range,
                 fs,
                 output_freq=1,
                 interactions_output=0,
                 integrators=None,
                 default_integrator=None):
        """
        Parameters
        ----------
        strings_and_frets : python dictionnary
            keys = interactions (Fret). See notes below.
            values = dynamical systems (StringDS)
        time_range : list
            time range for the simulation.
        fs : double
            sampling frequency
        integrators : dictionnary, optional
            integrators[some_ds] = osi class name
            (MoreauJeanOSI or MoreauJeanBilbaoOSI).
            Default: Bilbao for all ds.
        default_integrator: sk.OneStepIntegrator
            default osi type (if integrators is not set
            or for ds not present in integrators).
            Default = Bilbao.
        output_freq: int, optional
            output frequency for times steps
        interactions_output: int, optional
            0: save nothing, 1: only y, 2: y + lambda(vel) 3: y + ydot + lambda
            default = 0
        Notes
        -----
        * strings_and_frets.keys() : interactions
        * strings_and_frets.values() : dynamical systems
        * so, strings_and_frets[some_interaction] returns the ds
        linked to some_interaction.
        * For integrators:
          - to use Bilbao for all ds : do not set
            integrators and default_integrator params
          - to choose the integrator: set default_integrator=OSI
            OSI being some siconos OneStepIntegrator class.
          - to explicitely set the integrator for each ds:
            set integrators dictionnary, with
            integrators[some_ds] = OSI (OneStepIntegrator class)
            all ds not set in integrators will be integrated
            with default_integrator.
        """
        # iterate through ds and interactions in the input dictionnary
        # - insert ds into the nonsmooth dynamical system
        # - link each ds to its interaction
        self.nsds = sk.NonSmoothDynamicalSystem(time_range[0], time_range[1])
        if None in strings_and_frets:
            # No interactions in the model
            ds = strings_and_frets[None]
            assert isinstance(ds, StringDS)
            self.nsds.insertDynamicalSystem(ds)
        else:
            #self.nsds.insertDynamicalSystem(list(strings_and_frets.values())[0])
            for interaction in strings_and_frets:
                ds = strings_and_frets[interaction]
                assert isinstance(interaction, Fret)
                assert isinstance(ds, StringDS)
                self.nsds.insertDynamicalSystem(ds)
                # link the interaction and the dynamical system
                self.nsds.link(interaction, ds)
        self.strings_and_frets = strings_and_frets
        # -- Simulation --
        moreau_bilbao = sk.MoreauJeanBilbaoOSI()
        moreau_jean = sk.MoreauJeanOSI(0.500001)
        default_integrator = moreau_bilbao
        if default_integrator == 'MoreauJean':
            default_integrator = moreau_jean

        # (2) Time discretisation --
        t0 = time_range[0]
        tend = time_range[1]
        self.fs = fs
        self.time_step = 1. / fs
        t = sk.TimeDiscretisation(t0, self.time_step)
        self.nb_time_steps = (int)((tend - t0) * fs)
        self.output_freq = output_freq
        self.nb_time_steps_output = (int)(self.nb_time_steps / output_freq)
        # (3) one step non smooth problem
        self.osnspb = sk.LCP()
        # (4) Simulation setup with (1) (2) (3)
        self.default_integrator = default_integrator
        self.simulation = sk.TimeStepping(self.nsds, t, default_integrator,
                                          self.osnspb)
        #self.simulation = sk.TimeStepping(self.nsds, t, moreau_bilbao, self.osnspb)
        if integrators is not None:
            for ds in integrators:
                self.simulation.associate(integrators[ds], ds)

        # internal buffers, used to save data for each time step.
        # A dict of buffers to save ds variables for all time steps
        self.data_ds = {}
        for ds in self.strings_and_frets.values():
            ndof = ds.dimension()
            self.data_ds[ds] = npw.zeros((ndof, self.nb_time_steps_output + 1))
        if None in self.strings_and_frets:
            self.strings_and_frets = {}

        # A dict of buffers to save interactions variables for all time steps
        self.data_interactions = {}
        self.save_interactions = interactions_output > 0
        self.interactions_output = interactions_output
        if self.save_interactions:
            for interaction in self.strings_and_frets:
                self.data_interactions[interaction] = []
                for i in range(interactions_output):
                    self.data_interactions[interaction].append(
                        npw.zeros(self.nb_time_steps_output + 1))
        # time instants
        self.time = npw.zeros(self.nb_time_steps_output + 1)

        # saved data state (modal or nodal)
        self.modal_values = True
예제 #5
0
    def __init__(self,
                 strings_and_frets,
                 time_range,
                 fs,
                 integrators=None,
                 default_integrator=None):
        """
        Parameters
        ----------
        strings_and_frets : python dictionnary
            keys = interactions (Fret). See notes below.
            values = dynamical systems (StringDS)
        time_range : list
            time range for the simulation.
        fs : double
            sampling frequency
        integrators : dictionnary, optional
            integrators[some_ds] = osi class name
            (MoreauJeanOSI or MoreauJeanBilbaoOSI).
            Default: Bilbao for all ds.
        default_integrator: sk.OneStepIntegrator
            default osi type (if integrators is not set
            or for ds not present in integrators).
            Default = Bilbao.

        Notes
        -----
        * strings_and_frets.keys() : interactions
        * strings_and_frets.values() : dynamical systems
        * so, strings_and_frets[some_interaction] returns the ds
        linked to some_interaction.
        * For integrators:
          - to use Bilbao for all ds : do not set
            integrators and default_integrator params
          - to choose the integrator: set default_integrator=OSI
            OSI being some siconos OneStepIntegrator class.
          - to explicitely set the integrator for each ds:
            set integrators dictionnary, with
            integrators[some_ds] = OSI (OneStepIntegrator class)
            all ds not set in integrators will be integrated
            with default_integrator.
        """
        # Build siconos model object (input = time range)
        super(Guitar, self).__init__(time_range[0], time_range[1])
        # iterate through ds and interactions in the input dictionnary
        # - insert ds into the nonsmooth dynamical system
        # - link each ds to its interaction
        for interaction in strings_and_frets:
            ds = strings_and_frets[interaction]
            assert isinstance(interaction, Fret)
            assert isinstance(ds, StringDS)
            self.insertDynamicalSystem(ds)
            # link the interaction and the dynamical system
            self.link(interaction, ds)
        self.strings_and_frets = strings_and_frets
        # -- Simulation --
        moreau_bilbao = sk.MoreauJeanBilbaoOSI()
        moreau_jean = sk.MoreauJeanOSI(0.500001)
        default_integrator = moreau_bilbao
        if default_integrator is 'MoreauJean':
            default_integrator = moreau_jean

        # (2) Time discretisation --
        t0 = time_range[0]
        tend = time_range[1]
        self.fs = fs
        self.time_step = 1. / fs
        t = sk.TimeDiscretisation(t0, self.time_step)
        self.nb_time_steps = (int)((tend - t0) / self.time_step) + 1
        # (3) one step non smooth problem
        osnspb = sk.LCP()
        # (4) Simulation setup with (1) (2) (3)
        self.simu = sk.TimeStepping(self, t, default_integrator, osnspb)
        if integrators is not None:
            for ds in integrators:
                self.simu.associate(integrators[ds], ds)

        # internal buffers, used to save data for each time step.
        # A dict of buffers to save ds variables for all time steps
        self.data_ds = {}
        for ds in self.strings_and_frets.values():
            ndof = ds.dimension()
            self.data_ds[ds] = npw.zeros((self.nb_time_steps + 1, ndof))
        # A dict of buffers to save interactions variables for all time steps
        self.data_interactions = {}
        for interaction in self.strings_and_frets:
            nbc = interaction.getSizeOfY()
            self.data_interactions[interaction] = \
                npw.zeros((self.nb_time_steps + 1, 3 * nbc))
        # time instants
        self.time = npw.zeros(self.nb_time_steps + 1)