Exemplo n.º 1
0
    def __init__(self, s=None, **kws):
        _bmstate = kws.get('bmstate', None)
        _machine = kws.get('machine', None)
        _latfile = kws.get('latfile', None)
        self._states = None

        if s is None:
            if _bmstate is not None:
                self.state = _bmstate
            else:
                _m = machine_setter(_latfile, _machine, 'BeamState')
                if _m is not None:
                    self._states = _m.allocState({})
        else:
            self._states = s

        if self._states is not None:
            if is_zeros_states(self._states):
                _m = machine_setter(_latfile, _machine, 'BeamState')
                if _m is not None:
                    _m.propagate(self._states, 0, 1)
                else:
                    _LOGGER.warning(
                    "BeamState: " \
                     "The initial states are 0s, true values could be obtained" \
                     "by additional parameter '_latfile' or '_machine'.")
Exemplo n.º 2
0
    def __init__(self, s=None, **kws):
        _bmstate = kws.get('bmstate', None)
        _machine = kws.get('machine', None)
        _latfile = kws.get('latfile', None)
        self._states = None

        if s is None:
            if _bmstate is not None:
                self.state = _bmstate
            else:
                _m = machine_setter(_latfile, _machine, 'BeamState')
                if _m is not None:
                    self._states = _m.allocState({})
        else:
            self._states = s

        if self._states is not None:
            if is_zeros_states(self._states):
                _m = machine_setter(_latfile, _machine, 'BeamState')
                if _m is not None:
                    _m.propagate(self._states, 0, 1)
                else:
                    _LOGGER.warning(
                    "BeamState: " \
                     "Zeros initial states, get true values by " \
                     "parameter '_latfile' or '_machine'.")

        dummy_lat = {'sim_type':'MomentMatrix',
                     'elements':[{'name':'mk', 'type':'marker'}]}
        self.dm = flame.Machine(dummy_lat)
Exemplo n.º 3
0
    def run(self, bmstate=None, from_element=None, to_element=None, monitor=None):
        """Simulate model.

        Parameters
        ----------
        bmstate :
            FLAME beam state object, also could be :class:`BeamState`
            object, if not set, will use the one from ``ModelFlame`` object
            itself, usually is created at the initialization stage,
            see :func:`init_machine()`.
        from_element : int
            Element index of start point, if not set, will be the first element
            if not set, will be 0 for zero states, or 1.
        to_element : int
            Element index of end point, if not set, will be the last element.
        monitor : list[int]
            List of element indice selected as states monitors, if set -1,
            will be a list of only last element.

        Returns
        -------
        tuple
            Tuple of ``(r, s)``, where ``r`` is list of results at each monitor
            points, ``s`` is ``BeamState`` object after the last monitor
            point.

        Warning
        -------
        This method does not change the input *bmstate*, while ``propagate``
        changes.

        See Also
        --------
        BeamState : FLAME BeamState class created for ``MomentMatrix`` type.
        propagate : Propagate ``BeamState`` object for FLAME machine object.
        """
        m = self._mach_ins
        if bmstate is None:
            s = self.bmstate.clone()
        else:
            s = bmstate.clone()

        if is_zeros_states(s):
            vstart = 0 if from_element is None else from_element
        else:
            vstart = 1 if from_element is None else from_element
        vend = len(m) - 1 if to_element is None else to_element
        obs = [vend] if monitor is -1 else monitor

        vmax = vend - vstart + 1
        if isinstance(s, BeamState):
            r, s = propagate(m, s, from_element=vstart, to_element=vend, monitor=obs)
        else:
            r = m.propagate(s, start=vstart, max=vmax, observe=obs)
        r = self.convert_results(r)
        return r, s
Exemplo n.º 4
0
    def run(self,
            bmstate=None,
            from_element=None,
            to_element=None,
            monitor=None,
            include_initial_state=True):
        """Simulate model.

        Parameters
        ----------
        bmstate :
            FLAME beam state object, also could be :class:`BeamState`
            object, if not set, will use the one from ``ModelFlame`` object
            itself, usually is created at the initialization stage,
            see :func:`init_machine()`.
        from_element : int or str
            Element index or name of start point, if not set, will be the
            first element (0 for zero states, or 1).
        to_element : int or str
            Element index or name of end point, if not set, will be the last
            element.
        monitor : list[int] or list[str] or 'all'
            List of element indice or names selected as states monitors, if
            set -1, will be a list of only last element. if set 'all',
            will be a list of all elements.
        include_initial_state : bool
            Include initial beam state to the list of the results if `monitor`
            contains the initial location (default is True).

        Returns
        -------
        tuple
            Tuple of ``(r, s)``, where ``r`` is list of results at each monitor
            points, ``s`` is ``BeamState`` object after the last monitor
            point.

        Notes
        -----
        This method does not change the input *bmstate*, while ``propagate``
        changes.

        See Also
        --------
        BeamState : FLAME BeamState class created for ``MomentMatrix`` type.
        propagate : Propagate ``BeamState`` object for FLAME machine object.
        """
        m = self._mach_ins

        if isinstance(from_element, str):
            eid = m.find(from_element)
            if len(eid) == 0:
                _LOGGER.error(from_element + ' does not found.')
            from_element = min(eid)

        if isinstance(to_element, str):
            eid = m.find(to_element)
            if len(eid) == 0:
                _LOGGER.error(to_element + ' does not found.')
            to_element = min(eid)

        if bmstate is None:
            s = self.bmstate.clone()
        else:
            s = bmstate.clone()

        if is_zeros_states(s):
            vstart = 0 if from_element is None else from_element
        else:
            vstart = 1 if from_element is None else from_element
        vend = len(m) - 1 if to_element is None else to_element
        vmax = vend - vstart + 1

        obs = []
        if monitor == -1:
            obs = [vend]
        elif monitor == 'all':
            obs = range(len(m))
        elif monitor is not None:
            if isinstance(monitor, (int, str)):
                monitor = [monitor]
            for elem in monitor:
                if isinstance(elem, str):
                    obs += self._mach_ins.find(name=elem)
                    obs += self._mach_ins.find(type=elem)
                else:
                    obs.append(int(elem))

        if isinstance(s, BeamState):
            if bmstate is None and vstart > 1:
                r, s = propagate(m, s, from_element=1, to_element=vstart - 1)
            s0 = s.clone()
            r, s = propagate(m,
                             s,
                             from_element=vstart,
                             to_element=vend,
                             monitor=obs)
        else:
            if bmstate is None and vstart > 1:
                r, s = m.propagate(s, start=1, max=vstart - 1)
            s0 = s.clone()
            r = m.propagate(s, start=vstart, max=vmax, observe=obs)

        if include_initial_state and vstart != 0 and (vstart - 1) in obs:
            r0 = [(vstart - 1, s0)]
        else:
            r0 = []
        r = self.convert_results(r0 + r)
        return r, s