-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactoring, new features, more examples * v0.2.0 edit * fixed project.toml in test * removed fmizoo-version-dep * fixed dependencies * minor modification at bouncng ball * removed FMI.jl testing dependency * minor modification in examples * excluding tests that fail in CI (working locally) * added dependencies in example projects * minor test modification
- Loading branch information
Showing
18 changed files
with
1,023 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "FMIExport" | ||
uuid = "31b88311-cab6-44ed-ba9c-fe5a9abbd67a" | ||
authors = ["TT <[email protected]>", "LM <[email protected]>"] | ||
version = "0.1.13" | ||
version = "0.2.0" | ||
|
||
[deps] | ||
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" | ||
|
@@ -11,5 +11,5 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" | |
|
||
[compat] | ||
EzXML = "1.1.0" | ||
FMICore = "0.16" | ||
FMICore = "0.17.1" | ||
julia = "1.6" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name = "Manipulation" | ||
uuid = "a60229a6-2119-4702-9088-6d2bb886a221" | ||
authors = ["TT <[email protected]>"] | ||
version = "0.1.0" | ||
|
||
[deps] | ||
FMIBuild = "226f0e26-6dd6-4589-ada7-1d32f6e1d800" | ||
FMIExport = "31b88311-cab6-44ed-ba9c-fe5a9abbd67a" | ||
FMIImport = "9fcbc62e-52a0-44e9-a616-1359a0008194" | ||
FMIZoo = "724179cf-c260-40a9-bd27-cccc6fe2f195" | ||
|
||
[compat] | ||
FMIBuild = "0.1.15" | ||
FMIExport = "0.2.0" | ||
julia = "1.6" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# | ||
# Copyright (c) 2021 Tobias Thummerer, Lars Mikelsons | ||
# Licensed under the MIT license. See LICENSE file in the project root for details. | ||
# | ||
|
||
using FMIExport: fmi2SetFctGetReal, fmi2CreateEmbedded | ||
using FMIExport.FMICore: fmi2Real, fmi2Component, fmi2StatusOK, fmi2ValueReference | ||
using FMIExport.FMICore: fmi2CausalityParameter, fmi2VariabilityTunable, fmi2InitialExact | ||
using FMIImport: fmi2Load | ||
import FMIExport | ||
|
||
originalGetReal = nothing # function pointer to the original fmi2GetReal c-function | ||
|
||
# custom function for fmi2GetReal!(fmi2Component, Union{Array{fmi2ValueReference}, Ptr{fmi2ValueReference}}, Csize_t, value::Union{Array{fmi2Real}, Ptr{fmi2Real}}::fmi2Status | ||
# for information on how the FMI2-functions are structured, have a look inside FMICore.jl/src/FMI2_c.jl or the FMI2.0.3-specification on fmi-standard.org | ||
function myGetReal!(c::fmi2Component, vr::Union{Array{fmi2ValueReference}, Ptr{fmi2ValueReference}}, nvr::Csize_t, value::Union{Array{fmi2Real}, Ptr{fmi2Real}}) | ||
global originalGetReal | ||
|
||
# first, we do what the original function does | ||
status = FMIExport.FMICore.fmi2GetReal!(originalGetReal, c, vr, nvr, value) | ||
|
||
# if we have a pointer to an array, we must interprete it as array to access elements | ||
if isa(value, Ptr{fmi2Real}) | ||
value = unsafe_wrap(Array{fmi2Real}, value, nvr, own=false) | ||
end | ||
if isa(vr, Ptr{fmi2ValueReference}) | ||
vr = unsafe_wrap(Array{fmi2ValueReference}, vr, nvr, own=false) | ||
end | ||
|
||
# now, we add noise (just for fun!) | ||
for i in 1:nvr | ||
if vr[i] == 335544320 # value reference for "positionSensor.s" | ||
value[i] += (-0.5 + rand())*0.25 | ||
end | ||
end | ||
|
||
# ... and we return the original status | ||
return status | ||
end | ||
|
||
# this function is called, as soon as the DLL is loaded and Julia is initialized | ||
# must return a FMU2-instance to work with | ||
FMIBUILD_CONSTRUCTOR = function(resPath) | ||
global originalGetReal | ||
|
||
# loads an existing FMU inside the FMU | ||
fmu = fmi2Load(joinpath(resPath, "SpringDamperPendulum1D.fmu")) | ||
|
||
# create a FMU that embedds the existing FMU | ||
fmu = fmi2CreateEmbedded(fmu) | ||
|
||
fmu.modelDescription.modelName = "Manipulation" | ||
fmu.modelDescription.modelExchange.modelIdentifier = "Manipulation" | ||
fmu.modelDescription.coSimulation = nothing | ||
|
||
# deactivate special features, because they are not implemented yet | ||
fmu.modelDescription.modelExchange.canGetAndSetFMUstate=false | ||
fmu.modelDescription.modelExchange.canSerializeFMUstate=false | ||
fmu.modelDescription.modelExchange.providesDirectionalDerivative=false | ||
|
||
# save, where the original `fmi2GetReal` function was stored, so we can access it in our new function | ||
originalGetReal = fmu.cGetReal | ||
|
||
# now we overwrite the original function | ||
fmi2SetFctGetReal(fmu, myGetReal!) | ||
|
||
return fmu | ||
end | ||
|
||
### FMIBUILD_NO_EXPORT_BEGIN ### | ||
# The line above is a start-marker for excluded code for the FMU compilation process! | ||
|
||
import FMIZoo | ||
|
||
tmpDir = mktempdir(; prefix="fmibuildjl_test_", cleanup=false) | ||
@info "Saving example files at: $(tmpDir)" | ||
fmu_save_path = joinpath(tmpDir, "Manipulation.fmu") | ||
|
||
sourceFMU = FMIZoo.get_model_filename("SpringDamperPendulum1D", "Dymola", "2022x") | ||
fmu = FMIBUILD_CONSTRUCTOR(dirname(sourceFMU)) | ||
import FMIBuild:fmi2Save # <= this must be excluded during export, because FMIBuild cannot execute itself (but it is able to build) | ||
fmi2Save(fmu, fmu_save_path; resources=Dict(sourceFMU=>"SpringDamperPendulum1D.fmu")) # <= this must be excluded during export, because fmi2Save would start an infinte build loop with itself | ||
|
||
# some tests | ||
# using FMI | ||
# fmu.executionConfig.loggingOn = true | ||
# solution = fmiSimulateME(fmu, (0.0, 5.0); dtmax=0.1, recordValues=[fmi2ValueReference(335544320)]) | ||
# using Plots | ||
# fmiPlot(solution) | ||
|
||
# The following line is a end-marker for excluded code for the FMU compilation process! | ||
### FMIBUILD_NO_EXPORT_END ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name = "NeuralFMU" | ||
uuid = "a60229a6-2119-4702-9088-6d2bb886a221" | ||
authors = ["TT <[email protected]>"] | ||
version = "0.1.0" | ||
|
||
[deps] | ||
FMIBuild = "226f0e26-6dd6-4589-ada7-1d32f6e1d800" | ||
FMIExport = "31b88311-cab6-44ed-ba9c-fe5a9abbd67a" | ||
FMIImport = "9fcbc62e-52a0-44e9-a616-1359a0008194" | ||
FMIZoo = "724179cf-c260-40a9-bd27-cccc6fe2f195" | ||
|
||
[compat] | ||
FMIBuild = "0.1.15" | ||
FMIExport = "0.2.0" | ||
julia = "1.6" |
Oops, something went wrong.
3482e5d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
3482e5d
There was a problem hiding this comment.
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/82842
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: