-
-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add docs for input-output handling #2918
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
cfcfaa3
add docs for input-output handling
baggepinnen b2fc08d
Update docs/src/basics/InputOutput.md
ChrisRackauckas 36f1cf9
Update docs/src/basics/InputOutput.md
ChrisRackauckas e3ae953
Update docs/src/basics/Linearization.md
ChrisRackauckas d9e9fb1
Update docs/src/basics/InputOutput.md
ChrisRackauckas fcb78f8
Update docs/src/basics/InputOutput.md
ChrisRackauckas 34a377f
Update docs/src/basics/InputOutput.md
ChrisRackauckas 2047f03
Update docs/src/basics/Linearization.md
ChrisRackauckas a79c20c
Update docs/src/basics/InputOutput.md
ChrisRackauckas b3152fc
Update docs/src/basics/InputOutput.md
ChrisRackauckas 6cb7c76
Update docs/src/basics/InputOutput.md
ChrisRackauckas fdca162
Update docs/src/basics/Linearization.md
ChrisRackauckas 9acb0e0
Update docs/src/basics/InputOutput.md
ChrisRackauckas 33efba8
Update docs/src/basics/Linearization.md
ChrisRackauckas 8085d76
Update docs/src/basics/InputOutput.md
ChrisRackauckas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# [Input output](@id inputoutput) | ||
|
||
An input-output system is a system on the form | ||
|
||
```math | ||
\begin{aligned} | ||
M \dot x &= f(x, u, p, t) \\ | ||
y &= g(x, u, p, t) | ||
``` | ||
|
||
where ``x`` is the state, ``u`` is the input and ``y`` is an output (in some contexts called an _observed variables_ in MTK). | ||
|
||
While many uses of ModelingToolkit for simulation do not require the user to think about inputs and outputs (IO), there are certain situations in which handling IO explicitly may be important, such as | ||
|
||
- Linearization | ||
- Control design | ||
- System identification | ||
- FMU export | ||
- Real-time simulation with external data inputs | ||
- Custom interfacing with other simulation tools | ||
|
||
This documentation page lists utilities that are useful for working with inputs and outputs in ModelingToolkit. | ||
|
||
## Generating a dynamics function with inputs, ``f`` | ||
|
||
ModelingToolkit can generate the dynamics of a system, the function ``M\dot X = f(x, u, p, t)`` above, such that the user can pass not only the state ``x`` and parameters ``p`` but also an external input ``u``. To this end, the function [`generate_control_function`](@ref) exists. | ||
|
||
This function takes a vector of variables that are to be considered inputs, i.e., part of the vector ``u``. Alongside returning the function ``f``, [`generate_control_function`](@ref) also returns the chosen state realization of the system after simplification. This vector specifies the order of the state variables ``x``, while the user-specified vector `u` specifies the order of the input variables ``u``. | ||
|
||
!!! note "Un-simplified system" | ||
|
||
This function expects `sys` to be un-simplified, i.e., `structural_simplify` or `@mtkbuild` should not be called on the system before passing it into this function. `generate_control_function` calls a special version of `structural_simplify` internally. | ||
|
||
## Generating an output function, ``g`` | ||
|
||
ModelingToolkit can also generate a function that computes a specified output of a system, the function ``y = g(x, u, p, t)`` above. This is done using the function [`build_explicit_observed_function`](@ref). When generating an output function, the user must specify the output variable(s) of interest, as well as any inputs if inputs are relevant to compute the output. | ||
|
||
The order of the user-specified output variables determines the order of the output vector ``y``. | ||
|
||
## Input-output variable metadata | ||
|
||
See [Symbolic Metadata](@ref symbolic_metadata). Metadata specified when creating variables is not directly used by any of the functions above, but the user can use the accessor functions `ModelingToolkit.inputs(sys)` and `ModelingToolkit.outputs(sys)` to obtain all variables with such metadata for passing to the functions above. The presence of this metadata is not required for any IO functionality and may be omitted. | ||
|
||
## Linearization | ||
|
||
See [Linearization](@ref linearization). | ||
|
||
## Docstrings | ||
|
||
```@index | ||
Pages = ["InputOutput.md"] | ||
``` | ||
|
||
```@docs | ||
ModelingToolkit.generate_control_function | ||
ModelingToolkit.build_explicit_observed_function | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I'm not the intended audience for this, but I've been reading and studying and rereading and I'm still completely lost on this bit. What does "chosen state realization" mean? What is the order of a state variable, why does it matter?
A simple example of
generate_control_function
usage would help tremendously.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a simple scenario, an MTK model may contain 100's of variables, but MTK chooses only$x$ for simulation. You need to know that MTK chose
position, velocity
to be part of the stateposition, velocity
as the state, and that they appear in that order, so that you can pass numerical valuesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#2926