Skip to content

Commit

Permalink
Merge branch 'main' into test-fmPy
Browse files Browse the repository at this point in the history
  • Loading branch information
ThummeTo authored Dec 9, 2024
2 parents 39b27b8 + 74eadc3 commit 40792ad
Show file tree
Hide file tree
Showing 8 changed files with 381 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/TestLTS.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test v1.6 (LTS)
name: Test v1.10 (LTS)

on:
workflow_dispatch:
Expand All @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: true
matrix:
julia-version: ['1.6']
julia-version: ['lts']
julia-arch: [x64]
os: [windows-latest] # ubuntu-latest,
experimental: [false]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/TestLatest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:

# Run codecov
- name: "Run CodeCov"
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v5
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "FMIExport"
uuid = "31b88311-cab6-44ed-ba9c-fe5a9abbd67a"
authors = ["TT <tobias.thummerer@informatik.uni-augsburg.de>", "LM <lars.mikelsons@informatik.uni-augsburg.de>"]
version = "0.4.0"
version = "0.4.1"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## What is FMIExport.jl?
[*FMIExport.jl*](https://github.com/ThummeTo/FMIExport.jl) is a free-to-use software library for the Julia programming language which allows for the export of FMUs ([fmi-standard.org](http://fmi-standard.org/)) from any Julia-Code. [*FMIExport.jl*](https://github.com/ThummeTo/FMIExport.jl) is completely integrated into [*FMI.jl*](https://github.com/ThummeTo/FMI.jl).

[![Dev Docs](https://img.shields.io/badge/docs-dev-blue.svg)](https://ThummeTo.github.io/FMIExport.jl/dev)
[![Dev Docs](https://img.shields.io/badge/docs-dev-blue.svg)](https://thummeto.github.io/FMI.jl/dev/)
[![Test (latest)](https://github.com/ThummeTo/FMIExport.jl/actions/workflows/TestLatest.yml/badge.svg)](https://github.com/ThummeTo/FMIExport.jl/actions/workflows/TestLatest.yml)
[![Test (LTS)](https://github.com/ThummeTo/FMIExport.jl/actions/workflows/TestLTS.yml/badge.svg)](https://github.com/ThummeTo/FMIExport.jl/actions/workflows/TestLTS.yml)
[![Run Examples](https://github.com/ThummeTo/FMIExport.jl/actions/workflows/Example.yml/badge.svg)](https://github.com/ThummeTo/FMIExport.jl/actions/workflows/Example.yml)
Expand Down
41 changes: 27 additions & 14 deletions examples/FMI2/BouncingBall/src/BouncingBall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
# Licensed under the MIT license. See LICENSE file in the project root for details.
#

# equations are a modified version of the Modelica reference FMUs:
# https://github.com/modelica/Reference-FMUs/blob/main/BouncingBall/model.c

using FMIExport
using FMIExport.FMIBase.FMICore: fmi2True, fmi2False

EPS = 1e-6
EPS = 1e-8

FMU_FCT_INIT = function()
m = 1.0 # ball mass
Expand Down Expand Up @@ -39,19 +42,20 @@ FMU_FCT_EVALUATE = function(t, x_c, ẋ_c, x_d, u, p, eventMode)
if sticking == fmi2True
a = 0.0
elseif sticking == fmi2False

if eventMode
if s < r && v < 0.0
h = s-r
if h <= 0 && v < 0
s = r + EPS # so that indicator is not triggered again
v = -v*d

# stop bouncing to prevent high frequency bouncing (and maybe tunneling the floor)
if abs(v) < v_min
sticking = fmi2True
v = 0.0
end
end
else
# no specials in continuos time mode

end

a = (m * -g) / m # the system's physical equation (a little longer than necessary)
Expand All @@ -60,12 +64,13 @@ FMU_FCT_EVALUATE = function(t, x_c, ẋ_c, x_d, u, p, eventMode)
return (x_c, ẋ_c, x_d, p)
end

# Todo: Remove these allocations. Make it inplace.
x_c = [s, v]
ẋ_c = [v, a]
x_d = [sticking]
p = [m, r, d, v_min, g]

return (x_c, ẋ_c, x_d, p) # evaluation can't change discrete state!
return (x_c, ẋ_c, x_d, p)
end

FMU_FCT_OUTPUT = function(t, x_c, ẋ_c, x_d, u, p)
Expand All @@ -84,11 +89,19 @@ FMU_FCT_EVENT = function(t, x_c, ẋ_c, x_d, u, p)
s, v = x_c
_, a = ẋ_c
sticking = x_d[1]


# helpers
z1 = 0.0 # first event indicator
h = s-r # ball height

if sticking == fmi2True
z1 = 1.0 # event 1: ball stay-on-ground
else
z1 = (s-r) # event 1: ball hits ground
if h > -EPS && h <= 0 && v > 0
z1 = -EPS
else
z1 = h
end
end

z = [z1]
Expand Down Expand Up @@ -140,14 +153,14 @@ fmu_save_path = joinpath(tmpDir, "BouncingBall.fmu")

fmu = FMIBUILD_CONSTRUCTOR()
using FMIBuild: saveFMU # <= this must be excluded during export, because FMIBuild cannot execute itself (but it is able to build)
saveFMU(fmu, fmu_save_path; debug=true, compress=false) # <= this must be excluded during export, because fmi2Save would start an infinte build loop with itself (debug=true allows debug messages, but is slow during execution!)
saveFMU(fmu, fmu_save_path; debug=true, compress=false) # <= this must be excluded during export, because saveFMU would start an infinite build loop with itself (debug=true allows debug messages, but is slow during execution!)

### some tests ###
# using FMI
# fmu.executionConfig.loggingOn = true
# solution = fmiSimulateME(fmu, (0.0, 5.0); dtmax=0.1)
# using Plots
# fmiPlot(solution)
using FMI, DifferentialEquations
fmu.executionConfig.loggingOn = true
solution = simulate(fmu, (0.0, 3.0); recordValues=["sticking"])
using Plots
plot(solution)

# The following line is a end-marker for excluded code for the FMU compilation process!
### FMIBUILD_NO_EXPORT_END ###
Loading

0 comments on commit 40792ad

Please sign in to comment.