Skip to content

Commit bd52074

Browse files
authored
Merge pull request #139 from ModiaSim/reduce_alloc
Reduce memory allocation if states or tearing variables are SVectors …
2 parents cfaae15 + 6b94432 commit bd52074

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

Project.toml

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

66
[deps]
77
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"

docs/src/index.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@ functionalities of these packages.
3636

3737
## Release Notes
3838

39+
### Version 0.8.2
40+
41+
- Memory allocation reduced if states or tearing variables are SVectors.
42+
3943
### Version 0.8.1
4044

4145
- Missing file Modia/test/TestLinearEquations.jl added.
4246

43-
4447
### Version 0.8.0
4548

4649
**Non-backwards** compatible changes

src/CodeGeneration.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,11 +1561,15 @@ function generate_getDerivatives!(AST::Vector{Expr}, equationInfo::Modia.Equatio
15611561
# x-element is a static vector
15621562
i2 = i1 + xe.length - 1
15631563
v_length = xe.length
1564+
x_elements = Expr[]
1565+
for i in i1:i2
1566+
push!(x_elements, :( _x[$i] ))
1567+
end
15641568
if !hasUnits || xe.unit == ""
1565-
push!(code_x, :( $x_name::Modia.SVector{$v_length,_FloatType} = Modia.SVector{$v_length,_FloatType}(_x[$i1:$i2])) )
1569+
push!(code_x, :( $x_name = Modia.SVector{$v_length,_FloatType}($(x_elements...)) ))
15661570
else
15671571
x_unit = xe.unit
1568-
push!(code_x, :( $x_name = Modia.SVector{$v_length,_FloatType}(_x[$i1:$i2])::Modia.SVector{$v_length,_FloatType}*@u_str($x_unit)) )
1572+
push!(code_x, :( $x_name = Modia.SVector{$v_length,_FloatType}($(x_elements...))*@u_str($x_unit)) )
15691573
end
15701574
i1 = i2 + 1
15711575
end

src/Modia.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Main module of Modia.
99
module Modia
1010

1111
const path = dirname(dirname(@__FILE__)) # Absolute path of package directory
12-
const Version = "0.8.0"
13-
const Date = "2022-03-01"
12+
const Version = "0.8.2"
13+
const Date = "2022-03-04"
1414
const modelsPath = joinpath(Modia.path, "models")
1515

1616
print(" \n\nWelcome to ")

src/StateSelection.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -901,10 +901,14 @@ function addLinearEquations!(eq::EquationGraph, hasConstantCoefficients::Bool, u
901901
i2 = i1 + v_length - 1
902902
if v_startOrInit isa AbstractVector
903903
# v is a vector
904+
x_elements = Expr[]
905+
for i in i1:i2
906+
push!(x_elements, :( _leq_mode.x[$i] ))
907+
end
904908
if v_unit == ""
905-
push!(while_body, :( $v_julia_name::Modia.SVector{$v_length,_FloatType} = Modia.SVector{$v_length,_FloatType}(_leq_mode.x[$i1:$i2])) )
909+
push!(while_body, :( $v_julia_name = Modia.SVector{$v_length,_FloatType}($(x_elements...))) )
906910
else
907-
push!(while_body, :( $v_julia_name = Modia.SVector{$v_length}(_leq_mode.x[$i1:$i2])::Modia.SVector{$v_length,_FloatType}*@u_str($v_unit)) )
911+
push!(while_body, :( $v_julia_name = Modia.SVector{$v_length,_FloatType}($(x_elements...))*@u_str($v_unit)) )
908912
end
909913
elseif v_startOrInit isa Number || v_startOrInit isa Nothing
910914
# v is a scalar or nothing (= assumed to be a scalar)

0 commit comments

Comments
 (0)