Feedback

This module contains all classes and functions related to the approximation of distributed feedback as well as their implementation for simulation purposes.

class Feedback(feedback_law, **parse_kwargs)[source]

Bases: pyinduct.simulation.SimulationInput

Base class for all objects that want to act as an input for the time-step simulation.

The calculated values for each time-step are stored in internal memory and can be accessed by get_results() (after the simulation is finished).

Note

Due to the underlying solver, this handle may get called with time arguments, that lie outside of the specified integration domain. This should not be a problem for a feedback controller but might cause problems for a feedforward or trajectory implementation.

class ObserverFeedback(observer_law, output_error)[source]

Bases: pyinduct.feedback.Feedback

Wrapper class for all observer gains that have to interact with the simulation environment.

Note

For observer gains (observer_gain) which are constructed from different test function bases, dont forget to specify these bases when initialization the TestFunction by using the keyword argument approx_lbl.

Parameters
  • observer_law (WeakFormulation) – Variational formulation of the Observer gain. (Projected on a set of test functions.)

  • output_error (StateFeedback) – Output error

class SimulationInput(name='')[source]

Bases: object

Base class for all objects that want to act as an input for the time-step simulation.

The calculated values for each time-step are stored in internal memory and can be accessed by get_results() (after the simulation is finished).

Note

Due to the underlying solver, this handle may get called with time arguments, that lie outside of the specified integration domain. This should not be a problem for a feedback controller but might cause problems for a feedforward or trajectory implementation.

clear_cache(self)[source]

Clear the internal value storage.

When the same SimulationInput is used to perform various simulations, there is no possibility to distinguish between the different runs when get_results() gets called. Therefore this method can be used to clear the cache.

get_results(self, time_steps, result_key='output', interpolation='nearest', as_eval_data=False)[source]

Return results from internal storage for given time steps.

Raises

Error – If calling this method before a simulation was run.

Parameters
  • time_steps – Time points where values are demanded.

  • result_key – Type of values to be returned.

  • interpolation – Interpolation method to use if demanded time-steps are not covered by the storage, see scipy.interpolate.interp1d() for all possibilities.

  • as_eval_data (bool) – Return results as EvalData object for straightforward display.

Returns

Corresponding function values to the given time steps.

class StateFeedback(control_law)[source]

Bases: pyinduct.feedback.Feedback

Base class for all feedback controllers that have to interact with the simulation environment.

Parameters

control_law (WeakFormulation) – Variational formulation of the control law.

calculate_scalar_product_matrix(base_a, base_b, scalar_product=None, optimize=True)[source]

Calculates a matrix A , whose elements are the scalar products of each element from base_a and base_b, so that a_{ij} = \langle \mathrm{a}_i\,,\: \mathrm{b}_j\rangle.

Parameters
  • base_a (ApproximationBase) – Basis a

  • base_b (ApproximationBase) – Basis b

  • scalar_product – (List of) function objects that are passed the members of the given bases as pairs. Defaults to the scalar product given by base_a

  • optimize (bool) – Switch to turn on the symmetry based speed up. For development purposes only.

Returns

matrix A

Return type

numpy.ndarray

evaluate_transformations(ce, weight_label, vect_shape, is_observer=False)[source]

Transform the different feedback/observer gains in ce to the basis weight_label and accumulate them to one gain vector.

If the feedback gain u(t) = k^Tc(t) was approximated with respect to the weights from the state x(z,t) = \sum_{i=1}^{n}c_i(t)\varphi_i(z) the weight transformations the procedure is straight forward. However, in most of the time, during the simulation only the weights of some base \bar{x}(z,t) = \sum_{i=1}^{m} \bar{c}_i(t)\bar{\varphi}_i(z) are available. Therefore, a weight transformation

\begin{align*}
  c(t) = N^{-1}M\bar{c}(t), \qquad
  N_{(i,j)} = \langle \varphi_i(z), \varphi_j(z) \rangle, \qquad
  M_{(i,j)} = \langle \varphi_i(z), \bar{\varphi}_j(z) \rangle
\end{align*}

to this basis will be computed.

The transformation of a approximated observer gain is a little bit more involved. Since, if one wants to know the transformation from the gain vector l_i = \langle l(z), \psi_i(z) \rangle, i=1,...,n to the approximation with respect to another test base \bar{l}_j = \langle l(z), \bar{\psi}_j(z) \rangle, j=1,...,m one has an additional degree of freedom with the ansatz l(z) = \sum_{i=1}^{k} c_i \varphi_i(z).

In the most cases there is a natural choice for \varphi_i(z), \,\, i=1,...,k and k, such that the the transformation to the desired projections \bar{l} can be acquired with little computational effort. However, for now these more elegant techniques are not covered in this method.

Here only one method is implemented:

\begin{align*}
  \langle l(z), \psi_j(z)\rangle =
  \langle \sum_{i=1}^{n} c_i \varphi_i(z), \psi_j(z)\rangle
  \quad \Rightarrow c = N^{-1} l,
  \quad N_{(i,j)} = \langle \varphi_i(z), \psi_j(z) \rangle\\
  \langle l(z), \bar{\psi}_j(z)\rangle =
  \langle \sum_{i=1}^{m} \bar{c}_i \bar{\psi}_i(z), \bar{\psi}_j(z)
  \quad \Rightarrow \bar{l} = M \bar{c},
  \quad M_{(i,j)} =
  \langle \bar{\psi}_i(z), \bar{\psi}_j(z) \rangle\\
\end{align*}

Finally the transformation between the weights c and \bar{c} will be computed with get_weight_transformation.

For more advanced approximation and transformation features, take a look at upcoming tools in the symbolic simulation branch of pyinduct (comment from 2019/06/27).

Warning

Since neither CanonicalEquation nor StateSpace know the target test base \bar{\psi}_j, j=1,...m, which was used in the WeakFormulation, at the moment, the observer gain transformation works only if the state approximation base and the test base coincides. Which holds for example, for standard fem approximations methods and modal approximations of self adjoint operators.

Parameters
  • ce (CanonicalEquation) – Feedback/observer gain.

  • weight_label (string) – Label of functions the weights correspond to.

  • vect_shape (tuple) – Shape of the feedback vector.

  • is_observer (bool) – The argument ce is interpreted as feedback/observer if observer is False/True. Default: False

Returns

Accumulated feedback/observer gain.

Return type

numpy.array

get_base(label)[source]

Retrieve registered set of initial functions by their label.

Parameters

label (str) – String, label of functions to retrieve.

Returns

initial_functions

get_transformation_info(source_label, destination_label, source_order=0, destination_order=0)[source]

Provide the weights transformation from one/source base to another/destination base.

Parameters
  • source_label (str) – Label from the source base.

  • destination_label (str) – Label from the destination base.

  • source_order – Order from the available time derivative of the source weights.

  • destination_order – Order from the desired time derivative of the destination weights.

Returns

Transformation info object.

Return type

TransformationInfo

get_weight_transformation(info)[source]

Create a handle that will transform weights from info.src_base into weights for info-dst_base while paying respect to the given derivative orders.

This is accomplished by recursively iterating through source and destination bases and evaluating their transformation_hints.

Parameters

info (TransformationInfo) – information about the requested transformation.

Returns

transformation function handle

Return type

callable

parse_weak_formulation(weak_form, finalize=False, is_observer=False)[source]

Parses a WeakFormulation that has been derived by projecting a partial differential equation an a set of test-functions. Within this process, the separating approximation x^n(z, t) = \sum_{i=1}^n c_i^n(t) \varphi_i^n(z) is plugged into the equation and the separated spatial terms are evaluated, leading to a ordinary equation system for the weights c_i^n(t).

Parameters
  • weak_form – Weak formulation of the pde.

  • finalize (bool) – Default: False. If you have already defined the dominant labels of the weak formulations you can set this to True. See CanonicalEquation.finalize()

Returns

The spatially approximated equation in a canonical form.

Return type

CanonicalEquation