-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run fmi2SetXXX function to initialize FMU start values #778
Merged
Merged
Changes from 10 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1e54be8
Swapped the order of setup and do_iteration in initialize function
davidhjp01 00ced51
Added initialize start values function
davidhjp01 212f007
Cleaned up code
davidhjp01 4ec6c32
Added a filtered list for modify_and_get.
davidhjp01 7a27b47
Error fix
davidhjp01 12334a7
Filter function update
davidhjp01 c1da6f6
Filter Update
davidhjp01 790ba4c
Typo fix
davidhjp01 7bc91c8
review follow-up
restenb f79ac15
added FMU to README
restenb 68c1849
Fixed dangling reference.
davidhjp01 7e4d90b
Revert to "Typo fix"
restenb 9cb4d18
Merge remote-tracking branch 'origin/bug/fmi-start-value' into bug/fm…
davidhjp01 cc5f93d
Removed unused includes
davidhjp01 2cf995a
Ref for scalar_value (string)
davidhjp01 728c883
return string from the textual representations, since nullptr "short-…
restenb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Binary file not shown.
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,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<OspSystemStructure xmlns="http://opensimulationplatform.com/MSMI/OSPSystemStructure" version="0.1"> | ||
<StartTime>0.0</StartTime> | ||
<BaseStepSize>0.01</BaseStepSize> | ||
<Algorithm>fixedStep</Algorithm> | ||
<Simulators> | ||
<Simulator name="example" source="../fmi2/StateInitExample.fmu"> | ||
<InitialValues> | ||
<InitialValue variable="Parameters.Integrator1_x0"> | ||
<Real value="10.0" /> | ||
</InitialValue> | ||
</InitialValues> | ||
</Simulator> | ||
</Simulators> | ||
<Connections> | ||
</Connections> | ||
</OspSystemStructure> |
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,53 @@ | ||
#include <cosim/algorithm/fixed_step_algorithm.hpp> | ||
#include <cosim/osp_config_parser.hpp> | ||
#include <cosim/observer/file_observer.hpp> | ||
#include <cosim/exception.hpp> | ||
#include <cosim/execution.hpp> | ||
#include <cosim/function/linear_transformation.hpp> | ||
#include <cosim/observer/last_value_observer.hpp> | ||
#include <cosim/system_structure.hpp> | ||
#include <algorithm> | ||
#include <iostream> | ||
|
||
#define REQUIRE(test) \ | ||
if (!(test)) throw std::runtime_error("Requirement not satisfied: " #test) | ||
|
||
int main() | ||
{ | ||
try { | ||
const auto testDataDir = std::getenv("TEST_DATA_DIR"); | ||
REQUIRE(!!testDataDir); | ||
|
||
cosim::filesystem::path configPath = testDataDir; | ||
|
||
auto resolver = cosim::default_model_uri_resolver(); | ||
const auto config = cosim::load_osp_config(configPath / "msmi" / "OspSystemStructure_StateInitExample.xml", *resolver); | ||
|
||
auto execution = cosim::execution( | ||
config.start_time, | ||
std::make_shared<cosim::fixed_step_algorithm>(config.step_size)); | ||
|
||
const auto entityMaps = cosim::inject_system_structure( | ||
execution, config.system_structure, config.initial_values); | ||
auto lvObserver = std::make_shared<cosim::last_value_observer>(); | ||
|
||
execution.add_observer(lvObserver); | ||
execution.simulate_until(cosim::to_time_point(0.1)); | ||
|
||
auto sim = entityMaps.simulators.at("example"); | ||
const auto paramRef = config.system_structure.get_variable_description({"example", "Parameters.Integrator1_x0"}).reference; | ||
const auto outRef = config.system_structure.get_variable_description({"example", "Integrator_out1"}).reference; | ||
|
||
double initialValue = 0.0; | ||
double outputValue = 0.0; | ||
lvObserver->get_real(sim, gsl::make_span(¶mRef, 1), gsl::make_span(&initialValue, 1)); | ||
lvObserver->get_real(sim, gsl::make_span(&outRef, 1), gsl::make_span(&outputValue, 1)); | ||
|
||
REQUIRE(std::fabs(initialValue - 10.0) < 1.0e-9); | ||
REQUIRE(std::fabs(outputValue - 10.1) < 1.0e-9); | ||
|
||
} catch (const std::exception& e) { | ||
std::cerr << "Error: " << e.what() << std::endl; | ||
return 1; | ||
} | ||
} |
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
When adding an FMU, you should update
tests/data/fmi2/README.md
and possibly include a licence file, cf. #764.