Simulation¶
This module consist of three parts.
- Simulation:
- Simulation infrastructure with helpers and data structures for preprocessing of the given equations and functions for postprocessing of simulation data.
- Control:
- All classes and functions related to the creation of controllers as well as the implementation for simulation purposes.
- Observer:
- Some objects for observer implementation which are mostly a combination from the objects for simulation and control tasks.
Simulation¶
-
class
Domain(bounds=None, num=None, step=None, points=None)[source]¶ Bases:
objectHelper class that manages ranges for data evaluation, containing parameters.
Parameters: - bounds (tuple) – Interval bounds.
- num (int) – Number of points in interval.
- step (numbers.Number) – Distance between points (if homogeneous).
- points (array_like) – Points themselves.
Note
If num and step are given, num will take precedence.
-
class
SimulationInput(name='')[source]¶ Bases:
objectBase 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).-
get_results(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 running.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
pyinduct.visualization.EvalDataobject for straightforward display.
Returns: Corresponding function values to the given time steps.
-
-
class
SimulationInputSum(inputs)[source]¶ Bases:
pyinduct.simulation.SimulationInputHelper that represents a signal mixer.
-
class
SimulationInputVector(input_vector)[source]¶ Bases:
pyinduct.simulation.SimulationInputClass that represent the input vector
from a state space
system (StateSpace) like
Parameters: input_vector (list) – List which holds (in sum)
SimulationInputand/orObserverErrorinstances.
-
class
WeakFormulation(terms, dynamic_weights=None, name=None)[source]¶ Bases:
objectThis class represents the weak formulation of a spatial problem. It can be initialized with several terms (see children of
pyinduct.placeholder.EquationTerm). The equation is interpreted as
Parameters: - terms (list) – List of object(s) of type EquationTerm.
- dynamic_weights (str) – Only for multi-pde systems. Weights (weight label) which occur temporal derived. It is only one kind of weight
labels (one pde) allowed in the weak formulation if
dynamic_weightswill not provided.
-
class
CanonicalForm(name=None)[source]¶ Bases:
objectThe canonical form of an ordinary differential equation system of order n.
-
add_to(term, value, column=None)[source]¶ Adds the value
valueto termterm.termis a dict that describes which coefficient matrix of the canonical form the value shall be added to.Parameters: - term (dict) –
Targeted term in the canonical form h. It has to contain:
- name: Type of the coefficient matrix: ‘E’, ‘f’, or ‘G’.
- order: Temporal derivative order of the assigned weights.
- exponent: Exponent of the assigned weights.
- value (
numpy.ndarray) – Value to add. It is converted in numpy.matrix if it is not already a numpy.matrix instance. - column (int) – Add the value only to one column of term (useful if only one dimension of term is known).
- term (dict) –
-
convert_to_state_space()[source]¶ Convert the canonical ode system of order n a into an ode system of order 1. This will only work if the highest derivative of the given FieldVariable can be isolated!
Returns: Return type: StateSpaceobject
-
-
class
CanonicalForms(dynamic_weight_label)[source]¶ Bases:
objectWrapper that holds several entities of canonical forms for different sets of weights.
-
add_to(weight_label, term, val, column=None)[source]¶ Add val to the canonical form for weight_label, see
CanonicalForm.add_to()for further information.Parameters: - weight_label (str) – Basis to add onto.
- term – Coefficient to add onto, see
CanonicalForm.add_to(). - val – Values to add.
-
get_dynamic_terms()[source]¶ Returns: Terms of the dynamic CanonicalForm.Return type: dict
-
get_static_terms()[source]¶ Returns: Dictionary of terms for each static CanonicalForm.Return type: dict
-
-
class
StateSpace(weight_label, a_matrices, b_matrices, input_handle=None, f_vector=None, c_matrix=None, d_matrix=None, family_tree=None)[source]¶ Bases:
objectStandard state space implementation for a dynamic system with

The corresponding infinite dimensional system has been approximated by a base given by weight_label.
Parameters: - weight_label – Label that has been used for approximation.
- a_matrices –

- b_matrices –

- input_handle –

- f_vector –
- c_matrix –

- d_matrix –

- family_tree (collections.OrderedDict or NoneType) – Ordered dictionary which hold informations about nesting of the original weights. Is None if the state space derived from only one weak formulation.
-
simulate_system(weak_form, initial_states, temporal_domain, spatial_domain, settings=None, der_orders=(0, 0))[source]¶ Convenience wrapper that encapsulates the whole simulation process.
Parameters: - weak_form (
WeakFormulation) – Weak formulation of the system to simulate. - initial_states (callable or numpy.ndarray) – Array of core.Functions for
. - temporal_domain (
Domain) – Domain object holding information for time evaluation. - spatial_domain (
Domain) – Domain object holding information for spatial evaluation. - der_orders (tuple) – Tuple of derivative orders (time, spat) that shall be evaluated additionally.
- settings – Integrator settings, see
simulate_state_space().
Returns: - List of
pyinduct.visualization.EvalDataobjects,holding the results for the FieldVariable and asked derivatives.
Return type: list
- weak_form (
-
simulate_systems(weak_forms, initial_states, time_interval, time_step, spatial_interval, spatial_step)[source]¶ Convenience wrapper for simulate system, see
simulate_system()for parameters.Parameters: - weak_forms (
WeakFormulation) – - initial_states –
- time_interval –
- time_step –
- spatial_interval –
- spatial_step –
- weak_forms (
-
process_sim_data(weight_lbl, q, temp_domain, spat_domain, temp_order, spat_order, name='')[source]¶ Create handles and evaluate at given points.
Parameters: - weight_lbl (str) – Label of Basis for reconstruction.
- temp_order – Order or temporal derivatives to evaluate additionally.
- spat_order – Order or spatial derivatives to evaluate additionally.
- q – weights
- spat_domain (
Domain) – Domain object providing values for spatial evaluation. - temp_domain (
Domain) – Timesteps on which rows of q are given. - name (str) – Name of the WeakForm, used to generate the dataset.
-
parse_weak_formulation(weak_form)[source]¶ Creates an ode system for the weights x_i based on the weak formulation.
Parameters: weak_form ( WeakFormulation) – Weak formulation of the pde.Returns: - n’th-order ode system. If the desired canonical form
- should be from type
CanonicalForms(as a part of multi-pde system) then the label of the dynamic weights must be defined inweak_form.dynamic_weightsotherwise you get aCanonicalFormobject.
Return type: CanonicalFormorCanonicalForms
-
convert_cfs_to_state_space(list_of_cfs)[source]¶ Create
StateSpacefrom listlist_of_cfswith elements from typeCanonicalForms. In the common case the
list elements are derived from
WeakFormulation`s which represent :math:`Ncoupled pde’s with boundary conditions.Parameters: list_of_cfs (list) – List with elements from type CanonicalForms.Returns: State space approximation for the time dynamic of (basically) coupled pde’s. Return type: StateSpace
-
simulate_state_space(sys_ss, sys_init_state, temp_domain, obs_ss=None, obs_init_state=None, settings=None)[source]¶ Wrapper to simulate a system given in state space form:

Parameters: - sys_ss (
StateSpace) – State space formulation of the system. - sys_init_state (numpy.array) – Initial state vector of the system.
- temp_domain (
Domain) – Temporal domain object. - obs_ss (
Observer) – State space formulation of the observer. - obs_init_state (numpy.array) – Initial state vector of the observer.
- settings (dict) – Parameters to pass to the
set_integrator()method of thescipy.odeclass, with the integrator name included under the keyname.
Returns: Time
Domainobject and weights matrix/matrices.Return type: tuple
- sys_ss (
-
evaluate_approximation(base_label, weights, temp_domain, spat_domain, spat_order=0, name='')[source]¶ Evaluate an approximation given by weights and functions at the points given in spatial and temporal steps.
Parameters: - weights – 2d np.ndarray where axis 1 is the weight index and axis 0 the temporal index.
- base_label (str) – Functions to use for back-projection.
- temp_domain (
Domain) – For steps to evaluate at. - spat_domain (
Domain) – For points to evaluate at (or in). - spat_order – Spatial derivative order to use.
- name – Name to use.
Returns:
Control¶
-
class
FeedbackLaw(terms, name='')[source]¶ Bases:
objectThis class represents the approximated formulation of a control law or observer error. It can be initialized with several terms (see children of
pyinduct.placeholder.EquationTerm). The equation is interpreted as
where
is the control output.Parameters: terms (list) – List with object(s) of type pyinduct.placeholder.EquationTerm.
-
class
Feedback(feedback_law)[source]¶ Bases:
pyinduct.simulation.SimulationInputWrapper class for all state feedbacks that have to interact with the simulation environment.
Parameters: feedback_law ( FeedbackLaw) – Function handle that calculates the state feedback if provided with correct weights.
-
class
FeedbackCanonicalForms(name)[source]¶ Bases:
objectWrapper that holds several entities of canonical forms for different sets of weights.
-
add_to(weight_label, term, val)[source]¶ Add val to the canonical form for weight_label, see
CanonicalForm.add_to()for further information.Parameters: - weight_label (str) – Basis to add onto.
- term – Coefficient to add onto, see
CanonicalForm.add_to(). - val – Values to add.
-
-
class
LawEvaluator(cfs, storage=None)[source]¶ Bases:
objectObject that evaluates the feedback law approximation given by a
pyinduct.simulation.CanonicalFormsobject.Parameters: cfs ( pyinduct.simulation.FeedbackCanonicalForms) – evaluation handle
-
approximate_feedback_law(feedback_law)[source]¶ Function that approximates the feedback law, given by a list of sum terms that equal u. The result is a function handle that contains pre-evaluated terms and only needs the current weights (and their respective label) to be applied.
Parameters: feedback_law ( FeedbackLaw) – Function handle that calculates the feedback law output if provided with correct weights.Returns: evaluation handle Return type: pyinduct.simulation.FeedbackCanonicalForms
-
_parse_feedback_law(law)[source]¶ Parses the given feedback law by approximating given terms.
Parameters: law (list) – List of pyinduct.placeholders.EquationTerm‘sReturns: evaluation handle Return type: pyinduct.simulation.FeedbackCanonicalForms
Observer¶
-
class
ObserverError(sys_part, obs_part, weighted_initial_error=None)[source]¶ Bases:
pyinduct.simulation.SimulationInputWrapper class for all observer errors that have to interact with the simulation environment. The terms which have to approximated on the basis of the system weights have to provided through the argument
sys_partand the terms which have to approximated on the basis of the observer weights have to provided through the argumentobs_part. The observer error is provided as sum of theFeedbackLaw‘ssys_partandobs_part.Parameters: - sys_part (
FeedbackLaw) – Hold the terms which approximated from system weights. - obs_part (
FeedbackLaw) – Hold the terms which approximated from observer weights.
Keyword Arguments: weighted_initial_error (numbers.Number) –
Time
(default: None). If the kwarg is given
the observer error will be weighted
with the function![\begin{align*}
\varphi(t) = \left\{\begin{array}{lll}
0 & \forall & t < 0 \\
(1-\cos\pi\frac{t}{t^*}) / 2 & \forall & t \in [0, 1] \\
1 & \forall & t > 1.
\end{array}\right.
\end{align*}](../_images/math/6d1c5e5907ea8ef7915258176defa36446078f1f.png)
- sys_part (
-
class
Observer(weight_label, a_matrices, b_matrices, input_handle=None, f_vector=None, c_matrix=None, d_matrix=None, family_tree=None, l_matrices=None)[source]¶ Bases:
pyinduct.simulation.StateSpaceStandard observer class which correspond structurally to the standard state space implementation
StateSpace(from which it is derived).
Where
is the observer error.
The corresponding infinite dimensional observer has been approximated by a base given by weight_label.Parameters: - weight_label – Label that has been used for approximation.
- a_matrices –

- b_matrices –

- input_handle –

- f_vector –
- c_matrix –

- d_matrix –

- family_tree –
- l_matrices –
-
build_observer_from_state_space(state_space)[source]¶ Return a
Observerobject based on the givenStateSpaceobject. The method returnNoneif state_space.input is not a instance ofObserverErroror if self._input_function is a instance ofSimulationInputSumwhich not hold anyObserverErrorinstance.Parameters: state_space ( StateSpace) – State space to be convert.Returns: See docstring. Return type: pyinduct.simulation.Observeror None