-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run fmi2SetXXX function to initialize FMU start values (#778)
* Swapped the order of setup and do_iteration in initialize function * Added initialize start values function * Cleaned up code * Added a filtered list for modify_and_get. * Error fix * Filter function update * Filter Update * Typo fix * review follow-up * added FMU to README * Fixed dangling reference. * Revert to "Typo fix" This reverts commit 790ba4c. * Removed unused includes * Ref for scalar_value (string) * return string from the textual representations, since nullptr "short-circuits" the error message. --------- Co-authored-by: Roger Eivind Stenbro <[email protected]>
- Loading branch information
1 parent
5c6e196
commit c49ebb6
Showing
9 changed files
with
130 additions
and
7 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
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; | ||
} | ||
} |