Skip to content
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

Have @mtkmodel docs show up under the "Basics" section #2285

Merged
merged 2 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/pages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pages = [
"basics/Composition.md",
"basics/Events.md",
"basics/Linearization.md",
"basics/MTKModel_Connector.md",
"basics/Validation.md",
"basics/DependencyGraphs.md",
"basics/FAQ.md"],
Expand Down
17 changes: 7 additions & 10 deletions docs/src/basics/MTKModel_Connector.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## Defining components with `@mtkmodel`
# Defining components with `@mtkmodel`

`@mtkmodel` is a convenience macro to define ModelingToolkit components. It returns `ModelingToolkit.Model`, which includes a constructor that returns an ODESystem, a `structure` dictionary with metadata and flag `isconnector` which is set to `false`.

### What can an MTK-Model definition have?
## What can an MTK-Model definition have?

`@mtkmodel` definition contains begin blocks of

Expand Down Expand Up @@ -52,7 +52,7 @@ end
end
```

#### `@parameters` and `@variables` begin block
### `@parameters` and `@variables` begin block

- Parameters and variables are declared with respective begin blocks.
- Variables must be functions of an independent variable.
Expand All @@ -67,12 +67,12 @@ julia > ModelingToolkit.getdefault(model_c.v)
2.0
```

#### `@structural_parameters` begin block
### `@structural_parameters` begin block

- This block is for non symbolic input arguements. These are for inputs that usually are not meant to be part of components; but influence how they are defined. One can list inputs like boolean flags, functions etc... here.
- Whenever default values are specified, unlike parameters/variables, they are reflected in the keyword argument list.

#### `@extend` block
### `@extend` block

To extend a partial system,

Expand All @@ -88,7 +88,7 @@ julia> @named model_c = ModelC(; p1 = 2.0)

However, as `p2` isn't listed in the model definition, its default can't be modified by users.

#### `@components` begin block
### `@components` begin block

- Declare the subcomponents within `@components` begin block.
- The arguments in these subcomponents are promoted as keyword arguments as `subcomponent_name__argname` with `nothing` as default value.
Expand All @@ -102,7 +102,7 @@ julia> @named model_c1 = ModelC(; model_a.k1 = 1);

And as `k2` isn't listed in the sub-component definition of `ModelC`, its default value can't be modified by users.

#### `@equations` begin block
### `@equations` begin block

- List all the equations here

Expand Down Expand Up @@ -130,11 +130,8 @@ end
`@connector`s accepts begin blocks of `@components`, `@equations`, `@extend`, `@parameters`, `@structural_parameters`, `@variables`. These keywords mean the same as described above for `@mtkmodel`.

!!! note

For more examples of usage, checkout [ModelingToolkitStandardLibrary.jl](https://github.com/SciML/ModelingToolkitStandardLibrary.jl/)

* * *

### What's a `structure` dictionary?

For components defined with `@mtkmodel` or `@connector`, a dictionary with metadata is created. It lists `:components` (sub-component list), `:extend` (the extended states and base system), `:parameters`, `:variables`, ``:kwargs`` (list of keyword arguments), `:independent_variable`, `:equations`.
Expand Down