Skip to content

Commit a3f179f

Browse files
authored
Merge pull request #167 from ModiaSim/Release0.12.0
Release0.12.0
2 parents 572ab57 + 0525c50 commit a3f179f

20 files changed

+266
-222
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
authors = ["Hilding Elmqvist <[email protected]>", "Martin Otter <[email protected]>"]
22
name = "Modia"
33
uuid = "cb905087-75eb-5f27-8515-1ce0ec8e839e"
4-
version = "0.11.0"
4+
version = "0.12.0"
55

66
[deps]
77
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"

docs/src/Functions.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ showEvaluatedParameters
6060
CurrentModule = Modia
6161
```
6262

63-
The simulation result of a model `instantiatedModel` are provided as a *signal table*,
63+
The simulation result of a model `instantiatedModel` are provided as a *signal table*,
6464
see [SignalTables.jl](https://github.com/ModiaSim/SignalTables.jl).
6565

6666
Therefore, all [signal table functions](https://modiasim.github.io/SignalTables.jl/stable/Functions/OverviewOfFunctions.html)
6767
can be used on a simulated model
6868

6969
To activate the defined plot package, use
7070

71-
- [`@usingModiaPlot`](@ref)
71+
- [`@usingModiaPlot`](@ref)
7272

7373
Alternatively, `usingPlotPackage` (from Modia reexported macro of SignalTables) can be used,
7474
but then package `SignalTables` must be in your current environment.
@@ -87,11 +87,11 @@ FirstOrder = Model(
8787
)
8888
simulate!(firstOrder, stopTime=10)
8989
showInfo(firstOrder) # list info about the result
90-
t = getValues(firstOrder, "time")
90+
t = getValues(firstOrder, "time")
9191
y = getValues(firstOrder, "y") # use any plot program: plot(t,y)
9292
9393
# Write result on file
94-
writeSignalTable("firstOrder.json", firstOrder, indent=2, log=true)
94+
writeSignalTable("firstOrder.json", firstOrder, indent=2, log=true)
9595
```
9696

9797
See the generated [json-file](../resources/fileio/firstOrder.json).

docs/src/Internal.md

+58-36
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,91 @@
11
# Internal
22

33
This chapter documents internal functions that are typically only
4-
for use of the developers of package Modia.
4+
for use of the developers of a model library or of Modia.
55

6-
## Code Generation
7-
8-
This section provides functions to **generate Julia code** of the
9-
transformed equations.
6+
## Variables of built-in Components
107

118
```@meta
129
CurrentModule = Modia
1310
```
1411

12+
The following functions are provided to define and access new variables
13+
in built-in components (seee for example model `InsulatedRod2` in `Modia/models/HeatTransfer.jl`).
14+
15+
| Functions | Description |
16+
|:--------------------------------------------------------|:----------------------------------------------------------------------------------|
17+
| [`new_x_segmented_variable!`](@ref) | Generate new state variable (`x_segmented` and `der_x_segmented` variables) |
18+
| [`new_w_segmented_variable!`](@ref) | Generate new local variable (`w_segmented` variable) |
19+
| [`new_alias_segmented_variable!`](@ref) | Generate new alias variable |
20+
| [`new_z_segmented_variable!`](@ref) | Generate new zero crossing variables (`z_segmented` variables) |
21+
| [`get_x_startIndex_from_x_segmented_startIndex`](@ref) | Return start index of `x_segmented` variable with respect to state vector `x` |
22+
| [`copy_scalar_x_segmented_value_from_state`](@ref) | Return value of scalar `x_segmented` variable from state vector `x` |
23+
| [`copy_SVector3_x_segmented_value_from_state`](@ref) | Return value of `SVector{3,FloatType}` x_segmented variable from state vector `x` |
24+
| [`copy_Vector_x_segmented_value_from_state`](@ref) | Return value of `Vector{FloatType}` x_segmented variable from state vector `x` |
25+
| [`copy_der_x_segmented_value_to_state`](@ref) | Copy value of `der_x_segmented` variable to state derivative vector `der(x)` |
26+
| [`copy_w_segmented_value_to_result`](@ref) | Copy value of local variable (`w-segmented`) to result |
27+
28+
1529
```@docs
16-
SimulationModel
17-
generate_getDerivatives!
18-
init!
19-
outputs!
20-
terminate!
21-
derivatives!
22-
DAEresidualsForODE!
23-
affectEvent!
24-
zeroCrossings!
25-
affectStateEvent!
26-
timeEventCondition!
27-
affectTimeEvent!
28-
addToResult!
29-
getFloatType
30-
measurementToString
30+
new_x_segmented_variable!
31+
new_w_segmented_variable!
32+
new_alias_segmented_variable!
33+
new_z_segmented_variable!
34+
get_x_startIndex_from_x_segmented_startIndex
35+
copy_scalar_x_segmented_value_from_state
36+
copy_SVector3_x_segmented_value_from_state
37+
copy_Vector_x_segmented_value_from_state
38+
copy_der_x_segmented_value_to_state
39+
copy_w_segmented_value_to_result
3140
```
3241

33-
## Inquiries in Model
42+
## Inquiries in built-in Components
3443

35-
The functions in this section can be called in the model code or in
36-
functions that are called from the model code.
44+
The following functions are provided to inquire properties
45+
in built-in components at the current state of the simulation
46+
(see for example model `InsulatedRod2` in `Modia/models/HeatTransfer.jl`).
3747

3848
```@docs
3949
isInitial
50+
isFirstInitialOfAllSegments
4051
isTerminal
52+
isTerminalOfAllSegments
4153
isEvent
4254
isFirstEventIteration
4355
isFirstEventIterationDirectlyAfterInitial
56+
isFullRestart
4457
isAfterSimulationStart
4558
isZeroCrossing
4659
storeResults
4760
getTime
4861
```
4962

50-
## Variable definitions in functions
63+
## Code Generation
5164

52-
The following functions can be used to define states and algebraic variables inside functions:
65+
This section lists internal functions to **generate Julia code** of the
66+
transformed equations.
5367

54-
```@docs
55-
new_x_segmented_variable!
56-
new_w_segmented_variable!
57-
new_alias_segmented_variable!
58-
new_z_segmented_variable!
59-
get_x_startIndex_from_x_segmented_startIndex
60-
get_scalar_x_segmented_value
61-
get_SVector3_x_segmented_value
62-
get_Vector_x_segmented_value!
63-
add_der_x_segmented_value!
64-
add_w_segmented_value!
68+
```@meta
69+
CurrentModule = Modia
6570
```
6671

72+
```@docs
73+
InstantiatedModel
74+
generate_getDerivatives!
75+
init!
76+
outputs!
77+
terminate!
78+
derivatives!
79+
DAEresidualsForODE!
80+
affectEvent!
81+
zeroCrossings!
82+
affectStateEvent!
83+
timeEventCondition!
84+
affectTimeEvent!
85+
addToResult!
86+
getFloatType
87+
measurementToString
88+
```
6789

6890

6991

docs/src/index.md

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
activ# Modia Documentation
1+
# Modia Documentation
22

33
[Modia](https://github.com/ModiaSim/Modia.jl) is an environment in form of a Julia package to model and simulate physical systems (electrical, mechanical, thermo-dynamical, etc.) described by differential and algebraic equations. A user defines a model on a high level with model components (like a mechanical body, an electrical resistance, or a pipe) that are physically connected together. A model component is constructed by **`expression = expression` equations** or by Julia structs/functions, such as the pre-defined [Modia3D] (https://github.com/ModiaSim/Modia3D.jl) multibody components. The defined model is symbolically processed (for example, equations might be analytically differentiated) with algorithms from package [ModiaBase.jl](https://github.com/ModiaSim/ModiaBase.jl). From the transformed model a Julia function is generated that is used to simulate the model with integrators from [DifferentialEquations.jl](https://github.com/SciML/DifferentialEquations.jl).
44
The basic type of the floating point variables is usually `Float64`, but can be set to any
@@ -42,6 +42,20 @@ functionalities of these packages.
4242

4343
## Release Notes
4444

45+
### Version 0.12.0
46+
47+
- Improved documentation of built-in component functions.
48+
49+
**Non-backwards** compatible changes
50+
51+
- Renamed struct `SimulationModel` to `InstantiatedModel`.
52+
- Renamed function `get_scalar_x_segmented_value` to `copy_scalar_x_segmented_value_from_state`
53+
- Renamed function `get_SVector3_x_segmented_value` to `copy_SVector3_x_segmented_value_from_state`
54+
- Renamed function `get_Vector_x_segmented_value!` to `copy_Vector_x_segmented_value_from_state`
55+
- Renamed function `add_der_x_segmented_value!` to `copy_der_x_segmented_value_to_state`
56+
- Renamed function `add_w_segmented_value!` to `copy_w_segmented_value_to_result`
57+
58+
4559
### Version 0.11.0
4660

4761
- Require ModiaBase 0.11.1
@@ -140,7 +154,7 @@ These changes should usually not influence user models.
140154
show all parameters.
141155

142156
- New functions to add states and algebraic variables from within functions that are not visible in the generated code
143-
(see [Variable definitions in functions](@ref) and example `Modia/test/TestLinearSystems.jl`).
157+
(see [Variables of built-in Components](@ref) and example `Modia/test/TestLinearSystems.jl`).
144158
This feature is used in the next version of
145159
Modia3D to allow (Modia3D) model changes after code generation and to get more light weight code.
146160

@@ -471,7 +485,7 @@ Bug fixes
471485
- @reexport using Unitful
472486
- @reexport using DifferentialEquations
473487
- Cleanup of test files (besides ModiaLang, no other package needed in the environment to run the tests).
474-
- Change `SimulationModel{FloatType,ParType,EvaluatedParType,TimeType}` to `SimulationModel{FloatType,TimeType}`
488+
- Change `InstantiatedModel{FloatType,ParType,EvaluatedParType,TimeType}` to `InstantiatedModel{FloatType,TimeType}`
475489

476490

477491
#### Version 0.9.1

docs/src/tutorial/Modeling.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ testArray1 = @instantiateModel(TestArray1, logCode=true)
528528
Note, the generated code is shown in the REPL if `logCode=true` is defined:
529529

530530
```julia
531-
function getDerivatives(_x, _m::Modia.SimulationModel{_FloatType,_TimeType} ...
531+
function getDerivatives(_x, _m::Modia.InstantiatedModel{_FloatType,_TimeType} ...
532532
...
533533
v::ModiaBase.SVector{3,_FloatType} = ModiaBase.SVector{3,_FloatType}(_x[1:3])
534534
var"der(v)" = -v

docs/src/tutorial/Simulation.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ modelInstance = @instantiateModel(model; FloatType = Float64, aliasReduction=tru
2424

2525
The macro performs structural and symbolic transformations, generates a function for
2626
calculation of derivatives suitable for use with [DifferentialEquations.jl](https://github.com/SciML/DifferentialEquations.jl)
27-
and returns [`SimulationModel`](@ref) that can be used in other functions,
27+
and returns [`InstantiatedModel`](@ref) that can be used in other functions,
2828
for example to simulate or plot results. Explanation of the arguments:
2929

3030
* `model`: model (declarations and equations)

examples/Pendulum.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ println("\n... Numerically linearize at stopTime = 10 with Float64 and Double64:
4141

4242
#= DoubleFloats is not necessarily defined in the environment
4343
using Modia.DoubleFloats
44-
pendulum3 = SimulationModel{Measurement{Double64}}(pendulum2)
44+
pendulum3 = InstantiatedModel{Measurement{Double64}}(pendulum2)
4545
(A_10_Double64, x_10_Double64) = linearize!(pendulum3, stopTime=10)
4646
=#
4747

models/HeatTransfer/InsulatedRod2.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ end
8484

8585

8686
# Called once before initialization of a new simulation segment
87-
function initSegment_InsulatedRod2!(instantiatedModel::SimulationModel{FloatType,TimeType}, path::String, ID,
87+
function initSegment_InsulatedRod2!(instantiatedModel::InstantiatedModel{FloatType,TimeType}, path::String, ID,
8888
parameters::AbstractDict; log=false)::Nothing where {FloatType,TimeType}
8989
obj::InsulatedRodStruct{FloatType} = Modia.get_instantiatedSubmodel(instantiatedModel, ID)
9090

@@ -99,9 +99,9 @@ end
9999

100100

101101
# Open an initialized InsulatedRod2 model and return a reference to it
102-
function openInsulatedRod!(instantiatedModel::SimulationModel{FloatType,TimeType}, ID)::InsulatedRodStruct{FloatType} where {FloatType,TimeType}
102+
function openInsulatedRod!(instantiatedModel::InstantiatedModel{FloatType,TimeType}, ID)::InsulatedRodStruct{FloatType} where {FloatType,TimeType}
103103
obj::InsulatedRodStruct{FloatType} = Modia.get_instantiatedSubmodel(instantiatedModel, ID)
104-
Modia.get_Vector_x_segmented_value!(instantiatedModel, obj.T_startIndex, obj.T)
104+
Modia.copy_Vector_x_segmented_value_from_state(instantiatedModel, obj.T_startIndex, obj.T)
105105
return obj
106106
end
107107

@@ -127,6 +127,6 @@ function computeInsulatedRodDerivatives!(instantiatedModel, obj::InsulatedRodStr
127127
for i in 1:length(T)
128128
obj.der_T[i] = k*(T_grad1(T,Ta,i) - T_grad2(T,Tb,i))
129129
end
130-
Modia.add_der_x_segmented_value!(instantiatedModel, obj.T_startIndex, obj.der_T)
130+
Modia.copy_der_x_segmented_value_to_state(instantiatedModel, obj.T_startIndex, obj.der_T)
131131
return true
132132
end

0 commit comments

Comments
 (0)