-
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.
Non URI file scheme equal type name support (#688)
* Removed file scheme check * Allow proxyfmu URI scheme * Removed URI authority check * Check model relative path for OspModelDescription with fmuproxy * Fixed fmuproxy model path * File path fix * Added logging for debugging * Fix prototype * Absolute path query file support * Added some tests * Final testing implementation with logging * Temporary removal of Linux file query uri tests * Edited invalid tests * Reintroduced non Windows tests * Non Windows tests corrections * UNIX filesystem compatible function rewrite * Removed scheme assertion * Changed input parameter from baseUri to baseParentUri * Moved file_query_uri_to_path function from uri to osp_config_parser * Removed unused proxyfmu client dependency for tests Co-authored-by: msteinsto <magnus.steinsto@dnv.com>
- Loading branch information
Showing
5 changed files
with
127 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<OspSystemStructure | ||
xmlns="http://opensimulationplatform.com/MSMI/OSPSystemStructure" | ||
version="0.1"> | ||
<StartTime>0.0</StartTime> | ||
<BaseStepSize>1e-4</BaseStepSize> | ||
<Algorithm>fixedStep</Algorithm> | ||
<Simulators> | ||
<Simulator name="CraneController" source="proxyfmu://localhost?file=../ssp/demo/CraneController.fmu" stepSize="2e-4"> | ||
<InitialValues> | ||
<InitialValue variable="cl1_min"> | ||
<Real value="2.2"/> | ||
</InitialValue> | ||
<InitialValue variable="cl1_max"> | ||
<Real value="3.8"/> | ||
</InitialValue> | ||
</InitialValues> | ||
</Simulator> | ||
<Simulator name="KnuckleBoomCrane" source="proxyfmu://localhost?file=../ssp/demo/KnuckleBoomCrane.fmu" stepSize="2e-4"/> | ||
<Simulator name="TrueIdentity" source="proxyfmu://localhost?file=../fmi1/identity.fmu" stepSize="2.03e-4"> | ||
<InitialValues> | ||
<InitialValue variable="booleanIn"> | ||
<Boolean value="true"/> | ||
</InitialValue> | ||
</InitialValues> | ||
</Simulator> | ||
<Simulator name="OneIdentity" source="proxyfmu://localhost?file=../fmi1/identity.fmu" stepSize="2.03e-4"> | ||
<InitialValues> | ||
<InitialValue variable="booleanIn"> | ||
<Boolean value="1"/> | ||
</InitialValue> | ||
</InitialValues> | ||
</Simulator> | ||
</Simulators> | ||
<Connections> | ||
<VariableGroupConnection> | ||
<VariableGroup simulator="KnuckleBoomCrane" name="actuatorLimits"/> | ||
<VariableGroup simulator="CraneController" name="actuatorLimits"/> | ||
</VariableGroupConnection> | ||
<VariableGroupConnection> | ||
<VariableGroup simulator="KnuckleBoomCrane" name="linear mechanical port"/> | ||
<VariableGroup simulator="CraneController" name="linear mechanical port"/> | ||
</VariableGroupConnection> | ||
</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,58 @@ | ||
#include <cosim/algorithm/fixed_step_algorithm.hpp> | ||
#include <cosim/fs_portability.hpp> | ||
#include <cosim/log/simple.hpp> | ||
#include <cosim/observer/last_value_observer.hpp> | ||
#include <cosim/orchestration.hpp> | ||
#include <cosim/osp_config_parser.hpp> | ||
|
||
#include <cstdlib> | ||
#include <exception> | ||
|
||
|
||
#define REQUIRE(test) \ | ||
if (!(test)) throw std::runtime_error("Requirement not satisfied: " #test) | ||
|
||
void test(const cosim::filesystem::path& configPath, size_t expectedNumConnections) | ||
{ | ||
auto resolver = cosim::default_model_uri_resolver(); | ||
const auto config = cosim::load_osp_config(configPath, *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); | ||
REQUIRE(entityMaps.simulators.size() == 4); | ||
REQUIRE(boost::size(config.system_structure.connections()) == expectedNumConnections); | ||
|
||
auto obs = std::make_shared<cosim::last_value_observer>(); | ||
execution.add_observer(obs); | ||
|
||
auto result = execution.simulate_until(cosim::to_time_point(1e-3)); | ||
REQUIRE(result.get()); | ||
|
||
const auto simIndex = entityMaps.simulators.at("CraneController"); | ||
const auto varReference = | ||
config.system_structure.get_variable_description({"CraneController", "cl1_min"}).reference; | ||
double realValue = -1.0; | ||
obs->get_real(simIndex, gsl::make_span(&varReference, 1), gsl::make_span(&realValue, 1)); | ||
|
||
double magicNumberFromConf = 2.2; | ||
REQUIRE(std::fabs(realValue - magicNumberFromConf) < 1e-9); | ||
} | ||
|
||
int main() | ||
{ | ||
try { | ||
cosim::log::setup_simple_console_logging(); | ||
cosim::log::set_global_output_level(cosim::log::info); | ||
|
||
const auto testDataDir = std::getenv("TEST_DATA_DIR"); | ||
REQUIRE(testDataDir); | ||
test(cosim::filesystem::path(testDataDir) / "msmi" / "OspSystemStructure_proxyfmu.xml", 9); | ||
} catch (const std::exception& e) { | ||
std::cerr << "Error: " << e.what(); | ||
return 1; | ||
} | ||
return 0; | ||
} |