Skip to content

Commit

Permalink
fixed dtmin issue (#159)
Browse files Browse the repository at this point in the history
* fixed dtmin issue

* version inc
  • Loading branch information
ThummeTo authored Dec 9, 2022
1 parent 2d5624e commit 3be84f1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "FMI"
uuid = "14a09403-18e3-468f-ad8a-74f8dda2d9ac"
authors = ["TT <[email protected]>", "LM <[email protected]>", "JK <[email protected]>"]
version = "0.11.0"
version = "0.11.1"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
19 changes: 10 additions & 9 deletions test/FMI2/sim_ME.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ abstol = 0.0001 / 10.0
solver = FBDF(autodiff=false)
solver_ad = FBDF(autodiff=true)
dtmax_inputs = 0.01
dtmin = 1e-64

# case 1: ME-FMU with state events

Expand All @@ -29,7 +30,7 @@ elseif envFMUSTRUCT == "FMUCOMPONENT"
end
@assert fmuStruct != nothing "Unknown fmuStruct, environment variable `FMUSTRUCT` = `$envFMUSTRUCT`"

solution = fmiSimulateME(fmuStruct, (t_start, t_stop); abstol=abstol, solver=solver)
solution = fmiSimulateME(fmuStruct, (t_start, t_stop); abstol=abstol, solver=solver, dtmin=dtmin)
@test length(solution.states.u) > 0
@test length(solution.states.t) > 0

Expand Down Expand Up @@ -60,7 +61,7 @@ end

### test without recording values

solution = fmiSimulateME(fmuStruct, (t_start, t_stop); abstol=abstol, solver=solver)
solution = fmiSimulateME(fmuStruct, (t_start, t_stop); abstol=abstol, solver=solver, dtmin=dtmin)
@test length(solution.states.u) > 0
@test length(solution.states.t) > 0

Expand All @@ -73,7 +74,7 @@ solution = fmiSimulateME(fmuStruct, (t_start, t_stop); abstol=abstol, solver=sol

### test with recording values (variable step record values)

solution = fmiSimulateME(fmuStruct, (t_start, t_stop); recordValues="mass.f", abstol=abstol, solver=solver)
solution = fmiSimulateME(fmuStruct, (t_start, t_stop); recordValues="mass.f", abstol=abstol, solver=solver, dtmin=dtmin)
dataLength = length(solution.states.u)
@test dataLength > 0
@test length(solution.states.t) == dataLength
Expand All @@ -94,7 +95,7 @@ dataLength = length(solution.states.u)
### test with recording values (fixed step record values)

tData = t_start:0.1:t_stop
solution = fmiSimulateME(fmuStruct, (t_start, t_stop); recordValues="mass.f", saveat=tData, abstol=abstol, solver=solver)
solution = fmiSimulateME(fmuStruct, (t_start, t_stop); recordValues="mass.f", saveat=tData, abstol=abstol, solver=solver, dtmin=dtmin)
@test length(solution.states.u) == length(tData)
@test length(solution.states.t) == length(tData)
@test length(solution.values.saveval) == length(tData)
Expand Down Expand Up @@ -145,7 +146,7 @@ end
for inpfct in [extForce_cxt, extForce_t]
global solution

solution = fmiSimulateME(fmuStruct, (t_start, t_stop); inputValueReferences=["extForce"], inputFunction=inpfct, abstol=abstol, solver=solver, dtmax=dtmax_inputs) # dtmax to force resolution
solution = fmiSimulateME(fmuStruct, (t_start, t_stop); inputValueReferences=["extForce"], inputFunction=inpfct, abstol=abstol, solver=solver, dtmin=dtmin, dtmax=dtmax_inputs) # dtmax to force resolution
@test length(solution.states.u) > 0
@test length(solution.states.t) > 0

Expand Down Expand Up @@ -175,7 +176,7 @@ elseif envFMUSTRUCT == "FMUCOMPONENT"
end
@assert fmuStruct != nothing "Unknown fmuStruct, environment variable `FMUSTRUCT` = `$envFMUSTRUCT`"

solution = fmiSimulateME(fmuStruct, (t_start, t_stop); abstol=abstol, solver=solver_ad, dtmax=dtmax_inputs) # dtmax to force resolution
solution = fmiSimulateME(fmuStruct, (t_start, t_stop); abstol=abstol, solver=solver_ad, dtmin=dtmin, dtmax=dtmax_inputs) # dtmax to force resolution
@test length(solution.states.u) > 0
@test length(solution.states.t) > 0

Expand Down Expand Up @@ -204,7 +205,7 @@ elseif envFMUSTRUCT == "FMUCOMPONENT"
end
@assert fmuStruct != nothing "Unknown fmuStruct, environment variable `FMUSTRUCT` = `$envFMUSTRUCT`"

solution = fmiSimulateME(fmuStruct, (t_start, t_stop); inputValueReferences=["extForce"], inputFunction=extForce_t, abstol=abstol, solver=solver, dtmax=dtmax_inputs) # dtmax to force resolution
solution = fmiSimulateME(fmuStruct, (t_start, t_stop); inputValueReferences=["extForce"], inputFunction=extForce_t, abstol=abstol, solver=solver, dtmin=dtmin, dtmax=dtmax_inputs) # dtmax to force resolution
@test length(solution.states.u) > 0
@test length(solution.states.t) > 0

Expand Down Expand Up @@ -233,7 +234,7 @@ elseif envFMUSTRUCT == "FMUCOMPONENT"
end
@assert fmuStruct != nothing "Unknown fmuStruct, environment variable `FMUSTRUCT` = `$envFMUSTRUCT`"

solution = fmiSimulateME(fmuStruct, (t_start, t_stop); saveat=tData, recordValues=:states, abstol=abstol, solver=solver)
solution = fmiSimulateME(fmuStruct, (t_start, t_stop); saveat=tData, recordValues=:states, abstol=abstol, solver=solver, dtmin=dtmin)
@test length(solution.states.u) == length(tData)
@test length(solution.states.t) == length(tData)
@test length(solution.values.saveval) == length(tData)
Expand Down Expand Up @@ -265,7 +266,7 @@ end
@assert fmuStruct != nothing "Unknown fmuStruct, environment variable `FMUSTRUCT` = `$envFMUSTRUCT`"

rand_x0 = rand(2)
solution = fmiSimulateME(fmuStruct, (t_start, t_stop); x0=rand_x0, abstol=abstol, solver=solver)
solution = fmiSimulateME(fmuStruct, (t_start, t_stop); x0=rand_x0, abstol=abstol, solver=solver, dtmin=dtmin)
@test length(solution.states.u) > 0
@test length(solution.states.t) > 0

Expand Down

2 comments on commit 3be84f1

@ThummeTo
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/73791

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.11.1 -m "<description of version>" 3be84f1c36d8525c6e48849b30ebbac9b79e542e
git push origin v0.11.1

Please sign in to comment.