Skip to content

Commit 7c377de

Browse files
committed
docs: constants in the mtkmodel
1 parent fd8fd7f commit 7c377de

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

docs/src/basics/ContextualVariables.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ All modeling projects have some form of parameters. `@parameters` marks a variab
2020
as being the parameter of some system, which allows automatic detection algorithms
2121
to ignore such variables when attempting to find the unknowns of a system.
2222

23-
## Constants
23+
## [Constants](@id constants)
2424

2525
Constants, defined by e.g. `@constants myconst1` are like parameters that:
2626

docs/src/basics/MTKModel_Connector.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ equations.
2424
`@mtkmodel` definition contains begin blocks of
2525

2626
- `@components`: for listing sub-components of the system
27+
- `@constants`: for declaring constants
2728
- `@equations`: for the list of equations
2829
- `@extend`: for extending a base system and unpacking its unknowns
2930
- `@icon` : for embedding the model icon
@@ -52,6 +53,9 @@ end
5253
5354
@mtkmodel ModelC begin
5455
@icon "https://github.com/SciML/SciMLDocs/blob/main/docs/src/assets/logo.png"
56+
@constants begin
57+
c::Int = 1, [description = "Example constant."]
58+
end
5559
@structural_parameters begin
5660
f = sin
5761
end
@@ -107,6 +111,12 @@ end
107111
- This block is for non symbolic input arguments. 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.
108112
- Whenever default values are specified, unlike parameters/variables, they are reflected in the keyword argument list.
109113

114+
#### `@constants` begin block
115+
116+
- Declare constants in the model definition.
117+
- The values of these can't be changed by the user.
118+
- This works similar to symbolic constants described [here](@ref constants)
119+
110120
#### `@parameters` and `@variables` begin block
111121

112122
- Parameters and variables are declared with respective begin blocks.
@@ -220,7 +230,8 @@ end
220230

221231
`structure` stores metadata that describes composition of a model. It includes:
222232

223-
- `:components`: List of sub-components in the form of [[name, sub_component_name],...].
233+
- `:components`: The list of sub-components in the form of [[name, sub_component_name],...].
234+
- `:constants`: Dictionary of constants mapped to its metadata.
224235
- `:extend`: The list of extended unknowns, name given to the base system, and name of the base system.
225236
- `:structural_parameters`: Dictionary of structural parameters mapped to their metadata.
226237
- `:parameters`: Dictionary of symbolic parameters mapped to their metadata. For
@@ -239,6 +250,7 @@ Dict{Symbol, Any} with 9 entries:
239250
:components => Any[Union{Expr, Symbol}[:model_a, :ModelA]]
240251
:variables => Dict{Symbol, Dict{Symbol, Any}}(:v=>Dict(:default=>:v_var, :type=>Real), :v_array=>Dict(:type=>Real, :size=>(2, 3)))
241252
:icon => URI("https://github.com/SciML/SciMLDocs/blob/main/docs/src/assets/logo.png")
253+
:constants => Dict{Symbol, Dict}(:c=>Dict{Symbol, Any}(:value=>1, :type=>Int64, :description=>"Example constant."))
242254
:kwargs => Dict{Symbol, Dict}(:f=>Dict(:value=>:sin), :v=>Dict{Symbol, Union{Nothing, Symbol}}(:value=>:v_var, :type=>Real), :v_array=>Dict(:value=>nothing, :type=>Real), :p1=>Dict(:value=>nothing))
243255
:structural_parameters => Dict{Symbol, Dict}(:f=>Dict(:value=>:sin))
244256
:independent_variable => t

0 commit comments

Comments
 (0)