From 06417a8db57d99b68fda18db790e7545478b39ae Mon Sep 17 00:00:00 2001 From: Lars Ivar Hatledal Date: Tue, 27 Aug 2019 11:11:11 +0200 Subject: [PATCH 1/3] Rename cse::variable_index #265 --- include/cse.h | 66 +++++----- include/cse/algorithm.hpp | 50 +++---- include/cse/async_slave.hpp | 16 +-- include/cse/execution.hpp | 10 +- include/cse/fmi/v1/fmu.hpp | 16 +-- include/cse/fmi/v2/fmu.hpp | 16 +-- include/cse/manipulator.hpp | 12 +- include/cse/model.hpp | 6 +- include/cse/observer/last_value_observer.hpp | 8 +- include/cse/observer/last_value_provider.hpp | 8 +- include/cse/observer/observer.hpp | 10 +- include/cse/observer/time_series_observer.hpp | 8 +- include/cse/observer/time_series_provider.hpp | 16 +-- include/cse/scenario.hpp | 2 +- include/cse/slave.hpp | 16 +-- src/c/cse.cpp | 56 ++++---- src/cpp/async_slave.cpp | 56 ++++---- src/cpp/cse/fmuproxy/fmuproxy_helper.hpp | 2 +- src/cpp/cse/fmuproxy/remote_slave.hpp | 16 +-- src/cpp/cse/observer/slave_value_provider.hpp | 16 +-- src/cpp/cse/slave_simulator.hpp | 44 +++---- src/cpp/execution.cpp | 16 +-- src/cpp/fmi/v1/fmu.cpp | 16 +-- src/cpp/fmi/v2/fmu.cpp | 16 +-- src/cpp/fmuproxy/remote_slave.cpp | 16 +-- src/cpp/observer/file_observer.cpp | 8 +- src/cpp/observer/last_value_observer.cpp | 8 +- src/cpp/observer/slave_value_provider.cpp | 14 +- src/cpp/observer/time_series_observer.cpp | 40 +++--- src/cpp/override_manipulator.cpp | 14 +- src/cpp/scenario_parser.cpp | 2 +- src/cpp/slave_simulator.cpp | 124 +++++++++--------- test/c/connections_test.c | 8 +- test/c/execution_from_ssp_test.c | 2 +- test/c/multiple_fmus_execution_test.c | 16 +-- test/c/observer_can_buffer_samples.c | 2 +- test/c/observer_initial_samples_test.c | 2 +- test/c/observer_multiple_slaves_test.c | 8 +- test/c/single_fmu_execution_test.c | 8 +- test/c/time_series_observer_test.c | 2 +- test/cpp/async_slave_mockup_test.cpp | 4 +- test/cpp/async_slave_unittest.cpp | 24 ++-- test/cpp/fixed_step_algorithm_test.cpp | 4 +- test/cpp/fmi_v1_fmu_unittest.cpp | 2 +- test/cpp/last_value_observer_test.cpp | 4 +- test/cpp/mock_slave.hpp | 16 +-- test/cpp/multi_connections_test.cpp | 4 +- test/cpp/multi_fixed_step_algorithm_test.cpp | 12 +- test/cpp/ssp_parser_test.cpp | 4 +- test/cpp/synchronized_xy_series_test.cpp | 2 +- test/cpp/time_series_observer_test.cpp | 2 +- test/cpp/trend_buffer_test.cpp | 4 +- 52 files changed, 427 insertions(+), 427 deletions(-) diff --git a/include/cse.h b/include/cse.h index a53a81d8e..97dfbb958 100644 --- a/include/cse.h +++ b/include/cse.h @@ -24,8 +24,8 @@ typedef int64_t cse_time_point; /// The type used to specify (simulation) time durations. The time unit is nanoseconds. typedef int64_t cse_duration; -/// Variable index. -typedef uint32_t cse_variable_index; +/// value reference. +typedef uint32_t cse_value_reference; /// Slave index. typedef int cse_slave_index; @@ -333,8 +333,8 @@ typedef struct { /// The name of the variable. char name[SLAVE_NAME_MAX_SIZE]; - /// The variable index. - cse_variable_index index; + /// The value reference. + cse_value_reference index; /// The variable type. cse_variable_type type; /// The variable causality. @@ -384,8 +384,8 @@ typedef struct cse_slave_index slave_index; /// The type of the variable. cse_variable_type type; - /// The index of the variable. - cse_variable_index variable_index; + /// The variables value reference. + cse_value_reference value_reference; } cse_variable_id; @@ -443,7 +443,7 @@ typedef struct cse_manipulator_s cse_manipulator; int cse_manipulator_slave_set_real( cse_manipulator* manipulator, cse_slave_index slaveIndex, - const cse_variable_index variables[], + const cse_value_reference variables[], size_t nv, const double values[]); @@ -469,7 +469,7 @@ int cse_manipulator_slave_set_real( int cse_manipulator_slave_set_integer( cse_manipulator* manipulator, cse_slave_index slaveIndex, - const cse_variable_index variables[], + const cse_value_reference variables[], size_t nv, const int values[]); @@ -495,7 +495,7 @@ int cse_manipulator_slave_set_integer( int cse_manipulator_slave_set_boolean( cse_manipulator* manipulator, cse_slave_index slaveIndex, - const cse_variable_index variables[], + const cse_value_reference variables[], size_t nv, const bool values[]); @@ -521,7 +521,7 @@ int cse_manipulator_slave_set_boolean( int cse_manipulator_slave_set_string( cse_manipulator* manipulator, cse_slave_index slaveIndex, - const cse_variable_index variables[], + const cse_value_reference variables[], size_t nv, const char* values[]); @@ -547,7 +547,7 @@ int cse_manipulator_slave_reset( cse_manipulator* manipulator, cse_slave_index slaveIndex, cse_variable_type type, - const cse_variable_index variables[], + const cse_value_reference variables[], size_t nv); /** @@ -572,7 +572,7 @@ int cse_manipulator_slave_reset( int cse_observer_slave_get_real( cse_observer* observer, cse_slave_index slave, - const cse_variable_index variables[], + const cse_value_reference variables[], size_t nv, double values[]); @@ -598,7 +598,7 @@ int cse_observer_slave_get_real( int cse_observer_slave_get_integer( cse_observer* observer, cse_slave_index slave, - const cse_variable_index variables[], + const cse_value_reference variables[], size_t nv, int values[]); @@ -624,7 +624,7 @@ int cse_observer_slave_get_integer( int cse_observer_slave_get_boolean( cse_observer* observer, cse_slave_index slave, - const cse_variable_index variables[], + const cse_value_reference variables[], size_t nv, bool values[]); @@ -651,7 +651,7 @@ int cse_observer_slave_get_boolean( int cse_observer_slave_get_string( cse_observer* observer, cse_slave_index slave, - const cse_variable_index variables[], + const cse_value_reference variables[], size_t nv, const char* values[]); @@ -660,7 +660,7 @@ int cse_observer_slave_get_string( * * \param [in] observer the observer * \param [in] slave index of the slave - * \param [in] variableIndex the variable index + * \param [in] valueReference the value reference * \param [in] fromStep the step number to start from * \param [in] nSamples the number of samples to read * \param [out] values the series of observed values @@ -673,7 +673,7 @@ int cse_observer_slave_get_string( int64_t cse_observer_slave_get_real_samples( cse_observer* observer, cse_slave_index slave, - cse_variable_index variableIndex, + cse_value_reference valueReference, cse_step_number fromStep, size_t nSamples, double values[], @@ -685,7 +685,7 @@ int64_t cse_observer_slave_get_real_samples( * * \param [in] observer the observer * \param [in] slave index of the slave - * \param [in] variableIndex the variable index + * \param [in] valueReference the value reference * \param [in] fromStep the step number to start from * \param [in] nSamples the number of samples to read * \param [out] values the series of observed values @@ -698,7 +698,7 @@ int64_t cse_observer_slave_get_real_samples( int64_t cse_observer_slave_get_integer_samples( cse_observer* observer, cse_slave_index slave, - cse_variable_index variableIndex, + cse_value_reference valueReference, cse_step_number fromStep, size_t nSamples, int values[], @@ -710,9 +710,9 @@ int64_t cse_observer_slave_get_integer_samples( * * \param [in] observer the observer * \param [in] slave1 index of the first slave - * \param [in] variableIndex1 the first variable index + * \param [in] valueReference the first value reference * \param [in] slave2 index of the second slave - * \param [in] variableIndex2 the second variable index + * \param [in] valueReference the second value reference * \param [in] fromStep the step number to start from * \param [in] nSamples the number of samples to read * \param [out] values1 the first series of observed values @@ -724,9 +724,9 @@ int64_t cse_observer_slave_get_integer_samples( int64_t cse_observer_slave_get_real_synchronized_series( cse_observer* observer, cse_slave_index slave1, - cse_variable_index variableIndex1, + cse_value_reference valueReference1, cse_slave_index slave2, - cse_variable_index variableIndex2, + cse_value_reference valueReference2, cse_step_number fromStep, size_t nSamples, double values1[], @@ -781,11 +781,11 @@ int cse_observer_get_step_numbers( * The execution. * \param [in] outputSlaveIndex * The source slave. - * \param [in] outputVariableIndex + * \param [in] outputValueReference * The source variable. * \param [in] inputSlaveIndex * The destination slave. - * \param [in] inputVariableIndex + * \param [in] inputValueReference * The destination variable. * * \returns @@ -794,9 +794,9 @@ int cse_observer_get_step_numbers( int cse_execution_connect_real_variables( cse_execution* execution, cse_slave_index outputSlaveIndex, - cse_variable_index outputVariableIndex, + cse_value_reference outputValueReference, cse_slave_index inputSlaveIndex, - cse_variable_index inputVariableIndex); + cse_value_reference inputValueReference); /** * Connects one integer output variable to one integer input variable. @@ -805,11 +805,11 @@ int cse_execution_connect_real_variables( * The execution. * \param [in] outputSlaveIndex * The source slave. - * \param [in] outputVariableIndex + * \param [in] outputValueReference * The source variable. * \param [in] inputSlaveIndex * The destination slave. - * \param [in] inputVariableIndex + * \param [in] inputValueReference * The destination variable. * * \returns @@ -818,9 +818,9 @@ int cse_execution_connect_real_variables( int cse_execution_connect_integer_variables( cse_execution* execution, cse_slave_index outputSlaveIndex, - cse_variable_index outputVariableIndex, + cse_value_reference outputValueReference, cse_slave_index inputSlaveIndex, - cse_variable_index inputVariableIndex); + cse_value_reference inputValueReference); /// Creates an observer which stores the last observed value for all variables. @@ -864,10 +864,10 @@ cse_observer* cse_time_series_observer_create(); cse_observer* cse_buffered_time_series_observer_create(size_t bufferSize); /// Start observing a variable with a `time_series_observer`. -int cse_observer_start_observing(cse_observer* observer, cse_slave_index slave, cse_variable_type type, cse_variable_index index); +int cse_observer_start_observing(cse_observer* observer, cse_slave_index slave, cse_variable_type type, cse_value_reference index); /// Stop observing a variable with a `time_series_observer`. -int cse_observer_stop_observing(cse_observer* observer, cse_slave_index slave, cse_variable_type type, cse_variable_index index); +int cse_observer_stop_observing(cse_observer* observer, cse_slave_index slave, cse_variable_type type, cse_value_reference index); /// Destroys an observer int cse_observer_destroy(cse_observer* observer); diff --git a/include/cse/algorithm.hpp b/include/cse/algorithm.hpp index 9c4e74faf..85c800775 100644 --- a/include/cse/algorithm.hpp +++ b/include/cse/algorithm.hpp @@ -52,35 +52,35 @@ class simulator : public observable * Calling this function more than once for the same variable has no * effect. */ - virtual void expose_for_setting(variable_type type, variable_index index) = 0; + virtual void expose_for_setting(variable_type type, value_reference index) = 0; /** * Sets the value of a real variable. * * The variable must previously have been exposed with `expose_for_setting()`. */ - virtual void set_real(variable_index index, double value) = 0; + virtual void set_real(value_reference index, double value) = 0; /** * Sets the value of an integer variable. * * The variable must previously have been exposed with `expose_for_setting()`. */ - virtual void set_integer(variable_index index, int value) = 0; + virtual void set_integer(value_reference index, int value) = 0; /** * Sets the value of a boolean variable. * * The variable must previously have been exposed with `expose_for_setting()`. */ - virtual void set_boolean(variable_index index, bool value) = 0; + virtual void set_boolean(value_reference index, bool value) = 0; /** * Sets the value of a string variable. * * The variable must previously have been exposed with `expose_for_setting()`. */ - virtual void set_string(variable_index index, std::string_view value) = 0; + virtual void set_string(value_reference index, std::string_view value) = 0; /** * Sets a modifier for the value of a real input variable. @@ -88,7 +88,7 @@ class simulator : public observable * The variable must previously have been exposed with `expose_for_setting()`. */ virtual void set_real_input_modifier( - variable_index index, + value_reference index, std::function modifier) = 0; /** @@ -97,7 +97,7 @@ class simulator : public observable * The variable must previously have been exposed with `expose_for_setting()`. */ virtual void set_integer_input_modifier( - variable_index index, + value_reference index, std::function modifier) = 0; /** @@ -106,7 +106,7 @@ class simulator : public observable * The variable must previously have been exposed with `expose_for_setting()`. */ virtual void set_boolean_input_modifier( - variable_index index, + value_reference index, std::function modifier) = 0; /** @@ -115,7 +115,7 @@ class simulator : public observable * The variable must previously have been exposed with `expose_for_setting()`. */ virtual void set_string_input_modifier( - variable_index index, + value_reference index, std::function modifier) = 0; /** @@ -124,7 +124,7 @@ class simulator : public observable * The variable must previously have been exposed with `expose_for_setting()`. */ virtual void set_real_output_modifier( - variable_index index, + value_reference index, std::function modifier) = 0; /** @@ -133,7 +133,7 @@ class simulator : public observable * The variable must previously have been exposed with `expose_for_setting()`. */ virtual void set_integer_output_modifier( - variable_index index, + value_reference index, std::function modifier) = 0; /** @@ -142,7 +142,7 @@ class simulator : public observable * The variable must previously have been exposed with `expose_for_setting()`. */ virtual void set_boolean_output_modifier( - variable_index index, + value_reference index, std::function modifier) = 0; /** @@ -151,7 +151,7 @@ class simulator : public observable * The variable must previously have been exposed with `expose_for_setting()`. */ virtual void set_string_output_modifier( - variable_index index, + value_reference index, std::function modifier) = 0; /** @@ -183,39 +183,39 @@ class simulator : public observable /** * - * Returns all variable_indexes of real type with an active modifier. + * Returns all value_reference of real type with an active modifier. * * @return modifiedRealIndexes - * Unordered set of all variable_indexes that currently have an active modifier. + * Unordered set of all value_reference that currently have an active modifier. */ - virtual const std::unordered_set& get_modified_real_indexes() const = 0; + virtual const std::unordered_set& get_modified_real_indexes() const = 0; /** * - * Returns all variable_indexes of integer type with an active modifier. + * Returns all value_references of integer type with an active modifier. * * @return modifiedIntegerIndexes - * Unordered set of all variable_indexes that currently have an active modifier. + * Unordered set of all value_references that currently have an active modifier. */ - virtual const std::unordered_set& get_modified_integer_indexes() const = 0; + virtual const std::unordered_set& get_modified_integer_indexes() const = 0; /** * - * Returns all variable_indexes of boolean type with an active modifier. + * Returns all value_references of boolean type with an active modifier. * * @return modifiedBooleanIndexes - * Unordered set of all variable_indexes that currently have an active modifier. + * Unordered set of all value_references that currently have an active modifier. */ - virtual const std::unordered_set& get_modified_boolean_indexes() const = 0; + virtual const std::unordered_set& get_modified_boolean_indexes() const = 0; /** * - * Returns all variable_indexes of string type with an active modifier. + * Returns all value_references of string type with an active modifier. * * @return modifiedStringIndexes - * Unordered set of all variable_indexes that currently have an active modifier. + * Unordered set of all value_references that currently have an active modifier. */ - virtual const std::unordered_set& get_modified_string_indexes() const = 0; + virtual const std::unordered_set& get_modified_string_indexes() const = 0; /** * Updates the simulator with new input values and makes it calculate diff --git a/include/cse/async_slave.hpp b/include/cse/async_slave.hpp index 6fd4513bd..9caccc125 100644 --- a/include/cse/async_slave.hpp +++ b/include/cse/async_slave.hpp @@ -230,10 +230,10 @@ class async_slave * \see slave::get_string_variables() */ virtual boost::fibers::future get_variables( - gsl::span realVariables, - gsl::span integerVariables, - gsl::span booleanVariables, - gsl::span stringVariables) = 0; + gsl::span realVariables, + gsl::span integerVariables, + gsl::span booleanVariables, + gsl::span stringVariables) = 0; /** * Sets variable values. @@ -262,13 +262,13 @@ class async_slave * \see slave::set_string_variables() */ virtual boost::fibers::future set_variables( - gsl::span realVariables, + gsl::span realVariables, gsl::span realValues, - gsl::span integerVariables, + gsl::span integerVariables, gsl::span integerValues, - gsl::span booleanVariables, + gsl::span booleanVariables, gsl::span booleanValues, - gsl::span stringVariables, + gsl::span stringVariables, gsl::span stringValues) = 0; }; diff --git a/include/cse/execution.hpp b/include/cse/execution.hpp index 60f7d311f..c3d304745 100644 --- a/include/cse/execution.hpp +++ b/include/cse/execution.hpp @@ -35,7 +35,7 @@ struct variable_id variable_type type; /// The variable index. - variable_index index; + value_reference index; }; /// Equality operator for `variable_id`. @@ -234,16 +234,16 @@ class execution std::vector get_modified_variables(); /// Set initial value for a variable of type real. Must be called before simulation is started. - void set_real_initial_value(simulator_index sim, variable_index var, double value); + void set_real_initial_value(simulator_index sim, value_reference var, double value); /// Set initial value for a variable of type integer. Must be called before simulation is started. - void set_integer_initial_value(simulator_index sim, variable_index var, int value); + void set_integer_initial_value(simulator_index sim, value_reference var, int value); /// Set initial value for a variable of type boolean. Must be called before simulation is started. - void set_boolean_initial_value(simulator_index sim, variable_index var, bool value); + void set_boolean_initial_value(simulator_index sim, value_reference var, bool value); /// Set initial value for a variable of type string. Must be called before simulation is started. - void set_string_initial_value(simulator_index sim, variable_index var, const std::string& value); + void set_string_initial_value(simulator_index sim, value_reference var, const std::string& value); private: diff --git a/include/cse/fmi/v1/fmu.hpp b/include/cse/fmi/v1/fmu.hpp index 654c41c60..3346169fa 100644 --- a/include/cse/fmi/v1/fmu.hpp +++ b/include/cse/fmi/v1/fmu.hpp @@ -134,29 +134,29 @@ class slave_instance : public fmi::slave_instance step_result do_step(time_point currentT, duration deltaT) override; void get_real_variables( - gsl::span variables, + gsl::span variables, gsl::span values) const override; void get_integer_variables( - gsl::span variables, + gsl::span variables, gsl::span values) const override; void get_boolean_variables( - gsl::span variables, + gsl::span variables, gsl::span values) const override; void get_string_variables( - gsl::span variables, + gsl::span variables, gsl::span values) const override; void set_real_variables( - gsl::span variables, + gsl::span variables, gsl::span values) override; void set_integer_variables( - gsl::span variables, + gsl::span variables, gsl::span values) override; void set_boolean_variables( - gsl::span variables, + gsl::span variables, gsl::span values) override; void set_string_variables( - gsl::span variables, + gsl::span variables, gsl::span values) override; // fmi::slave_instance methods diff --git a/include/cse/fmi/v2/fmu.hpp b/include/cse/fmi/v2/fmu.hpp index 11760d25e..ef6eb69b4 100644 --- a/include/cse/fmi/v2/fmu.hpp +++ b/include/cse/fmi/v2/fmu.hpp @@ -134,29 +134,29 @@ class slave_instance : public fmi::slave_instance step_result do_step(time_point currentT, duration deltaT) override; void get_real_variables( - gsl::span variables, + gsl::span variables, gsl::span values) const override; void get_integer_variables( - gsl::span variables, + gsl::span variables, gsl::span values) const override; void get_boolean_variables( - gsl::span variables, + gsl::span variables, gsl::span values) const override; void get_string_variables( - gsl::span variables, + gsl::span variables, gsl::span values) const override; void set_real_variables( - gsl::span variables, + gsl::span variables, gsl::span values) override; void set_integer_variables( - gsl::span variables, + gsl::span variables, gsl::span values) override; void set_boolean_variables( - gsl::span variables, + gsl::span variables, gsl::span values) override; void set_string_variables( - gsl::span variables, + gsl::span variables, gsl::span values) override; // fmi::slave_instance methods diff --git a/include/cse/manipulator.hpp b/include/cse/manipulator.hpp index 3dc9facee..f4b46b5bd 100644 --- a/include/cse/manipulator.hpp +++ b/include/cse/manipulator.hpp @@ -112,22 +112,22 @@ class override_manipulator : public manipulator void step_commencing(time_point currentTime) override; /// Override the value of a variable with type `real` - void override_real_variable(simulator_index, variable_index, double value); + void override_real_variable(simulator_index, value_reference, double value); /// Override the value of a variable with type `integer` - void override_integer_variable(simulator_index, variable_index, int value); + void override_integer_variable(simulator_index, value_reference, int value); /// Override the value of a variable with type `boolean` - void override_boolean_variable(simulator_index, variable_index, bool value); + void override_boolean_variable(simulator_index, value_reference, bool value); /// Override the value of a variable with type `string` - void override_string_variable(simulator_index, variable_index, const std::string& value); + void override_string_variable(simulator_index, value_reference, const std::string& value); /// Reset override of a variable - void reset_variable(simulator_index, variable_type, variable_index); + void reset_variable(simulator_index, variable_type, value_reference); ~override_manipulator() noexcept override; private: void add_action( simulator_index index, - variable_index variable, + value_reference variable, variable_type type, const std::variant< scenario::real_modifier, diff --git a/include/cse/model.hpp b/include/cse/model.hpp index 323bd8ad2..aa6502b42 100644 --- a/include/cse/model.hpp +++ b/include/cse/model.hpp @@ -154,7 +154,7 @@ constexpr double to_double_duration(duration d, time_point startTime) /// Unsigned integer type used for variable identifiers. -using variable_index = std::uint32_t; +using value_reference = std::uint32_t; /// Variable data types. @@ -272,7 +272,7 @@ struct variable_description * variables of the same type have the same value reference, they will * be considered as aliases of each other. */ - variable_index index; + value_reference index; /// The variable's data type. variable_type type; @@ -314,7 +314,7 @@ struct model_description const variable_description find_variable(const model_description& description, const std::string& variable_name); /// Getter for returning a variable description. -const variable_description find_variable(const model_description& description, variable_type type, variable_index index); +const variable_description find_variable(const model_description& description, variable_type type, value_reference index); /// Getter for returning all variable descriptions of the given datatype. const std::vector find_variables_of_type(const model_description& description, variable_type type); diff --git a/include/cse/observer/last_value_observer.hpp b/include/cse/observer/last_value_observer.hpp index a00ab18e3..ceb1e3b22 100644 --- a/include/cse/observer/last_value_observer.hpp +++ b/include/cse/observer/last_value_observer.hpp @@ -48,22 +48,22 @@ class last_value_observer : public last_value_provider void get_real( simulator_index sim, - gsl::span variables, + gsl::span variables, gsl::span values) override; void get_integer( simulator_index sim, - gsl::span variables, + gsl::span variables, gsl::span values) override; void get_boolean( simulator_index sim, - gsl::span variables, + gsl::span variables, gsl::span values) override; void get_string( simulator_index sim, - gsl::span variables, + gsl::span variables, gsl::span values) override; ~last_value_observer() noexcept override; diff --git a/include/cse/observer/last_value_provider.hpp b/include/cse/observer/last_value_provider.hpp index 39b217266..d65cea1f0 100644 --- a/include/cse/observer/last_value_provider.hpp +++ b/include/cse/observer/last_value_provider.hpp @@ -30,7 +30,7 @@ class last_value_provider : public observer */ virtual void get_real( simulator_index sim, - gsl::span variables, + gsl::span variables, gsl::span values) = 0; /** @@ -42,7 +42,7 @@ class last_value_provider : public observer */ virtual void get_integer( simulator_index sim, - gsl::span variables, + gsl::span variables, gsl::span values) = 0; /** @@ -54,7 +54,7 @@ class last_value_provider : public observer */ virtual void get_boolean( simulator_index sim, - gsl::span variables, + gsl::span variables, gsl::span values) = 0; /** @@ -66,7 +66,7 @@ class last_value_provider : public observer */ virtual void get_string( simulator_index sim, - gsl::span variables, + gsl::span variables, gsl::span values) = 0; }; diff --git a/include/cse/observer/observer.hpp b/include/cse/observer/observer.hpp index 30098b5f1..2b59187d4 100644 --- a/include/cse/observer/observer.hpp +++ b/include/cse/observer/observer.hpp @@ -32,28 +32,28 @@ class observable * from remote simulators at each step, so that each individual `get_xxx()` * function call doesn't trigger a separate RPC operation. */ - virtual void expose_for_getting(variable_type, variable_index) = 0; + virtual void expose_for_getting(variable_type, value_reference) = 0; /** * Returns the value of a real variable. * * The variable must previously have been exposed with `expose_for_getting()`. */ - virtual double get_real(variable_index) const = 0; + virtual double get_real(value_reference) const = 0; /** * Returns the value of an integer variable. * * The variable must previously have been exposed with `expose_for_getting()`. */ - virtual int get_integer(variable_index) const = 0; + virtual int get_integer(value_reference) const = 0; /** * Returns the value of a boolean variable. * * The variable must previously have been exposed with `expose_for_getting()`. */ - virtual bool get_boolean(variable_index) const = 0; + virtual bool get_boolean(value_reference) const = 0; /** * Returns the value of a string variable. @@ -63,7 +63,7 @@ class observable * The returned `std::string_view` is only guaranteed to remain valid * until the next call of this or any other of the object's methods. */ - virtual std::string_view get_string(variable_index) const = 0; + virtual std::string_view get_string(value_reference) const = 0; virtual ~observable() noexcept {} }; diff --git a/include/cse/observer/time_series_observer.hpp b/include/cse/observer/time_series_observer.hpp index af1f004f0..d6b7fb1ef 100644 --- a/include/cse/observer/time_series_observer.hpp +++ b/include/cse/observer/time_series_observer.hpp @@ -72,7 +72,7 @@ class time_series_observer : public time_series_provider std::size_t get_real_samples( simulator_index sim, - variable_index variableIndex, + value_reference valueReference, step_number fromStep, gsl::span values, gsl::span steps, @@ -80,7 +80,7 @@ class time_series_observer : public time_series_provider std::size_t get_integer_samples( simulator_index sim, - variable_index variableIndex, + value_reference valueReference, step_number fromStep, gsl::span values, gsl::span steps, @@ -99,9 +99,9 @@ class time_series_observer : public time_series_provider std::size_t get_synchronized_real_series( simulator_index sim1, - variable_index variableIndex1, + value_reference valueReference1, simulator_index sim2, - variable_index variableIndex2, + value_reference valueReference2, step_number fromStep, gsl::span values1, gsl::span values2) override; diff --git a/include/cse/observer/time_series_provider.hpp b/include/cse/observer/time_series_provider.hpp index 9baba612b..ea5cac379 100644 --- a/include/cse/observer/time_series_provider.hpp +++ b/include/cse/observer/time_series_provider.hpp @@ -29,7 +29,7 @@ class time_series_provider : public observer * Retrieves a series of observed values, step numbers and times for a real variable. * * \param [in] sim index of the simulator - * \param [in] variableIndex the variable index + * \param [in] valueReference the variable index * \param [in] fromStep the step number to start from * \param [out] values the series of observed values * \param [out] steps the corresponding step numbers @@ -40,7 +40,7 @@ class time_series_provider : public observer */ virtual std::size_t get_real_samples( simulator_index sim, - variable_index variableIndex, + value_reference valueReference, step_number fromStep, gsl::span values, gsl::span steps, @@ -50,7 +50,7 @@ class time_series_provider : public observer * Retrieves a series of observed values, step numbers and times for an integer variable. * * \param [in] sim index of the simulator - * \param [in] variableIndex the variable index + * \param [in] valueReference the variable index * \param [in] fromStep the step number to start from * \param [out] values the series of observed values * \param [out] steps the corresponding step numbers @@ -61,7 +61,7 @@ class time_series_provider : public observer */ virtual std::size_t get_integer_samples( simulator_index sim, - variable_index variableIndex, + value_reference valueReference, step_number fromStep, gsl::span values, gsl::span steps, @@ -103,9 +103,9 @@ class time_series_provider : public observer * Retrieves two time-synchronized series of observed values for two real variables. * * \param [in] sim1 index of the first simulator - * \param [in] variableIndex1 the first variable index + * \param [in] valueReference1 the first variable index * \param [in] sim2 index of the second simulator - * \param [in] variableIndex2 the second variable index + * \param [in] valueReference2 the second variable index * \param [in] fromStep the step number to start from * \param [out] values1 the first series of observed values * \param [out] values2 the second series of observed values @@ -115,9 +115,9 @@ class time_series_provider : public observer */ virtual std::size_t get_synchronized_real_series( simulator_index sim1, - variable_index variableIndex1, + value_reference valueReference1, simulator_index sim2, - variable_index variableIndex2, + value_reference valueReference2, step_number fromStep, gsl::span values1, gsl::span values2) = 0; diff --git a/include/cse/scenario.hpp b/include/cse/scenario.hpp index f740b2f62..ae3504cda 100644 --- a/include/cse/scenario.hpp +++ b/include/cse/scenario.hpp @@ -49,7 +49,7 @@ struct variable_action /// The simulator index. simulator_index simulator; /// The variable index. - variable_index variable; + value_reference variable; /// The modification to be done to the variable's value. std::variant< real_modifier, diff --git a/include/cse/slave.hpp b/include/cse/slave.hpp index c8a844f31..a1c8cc695 100644 --- a/include/cse/slave.hpp +++ b/include/cse/slave.hpp @@ -113,7 +113,7 @@ class slave * \pre `variables.size() == values.size()` */ virtual void get_real_variables( - gsl::span variables, + gsl::span variables, gsl::span values) const = 0; /** @@ -125,7 +125,7 @@ class slave * \pre `variables.size() == values.size()` */ virtual void get_integer_variables( - gsl::span variables, + gsl::span variables, gsl::span values) const = 0; /** @@ -137,7 +137,7 @@ class slave * \pre `variables.size() == values.size()` */ virtual void get_boolean_variables( - gsl::span variables, + gsl::span variables, gsl::span values) const = 0; /** @@ -149,7 +149,7 @@ class slave * \pre `variables.size() == values.size()` */ virtual void get_string_variables( - gsl::span variables, + gsl::span variables, gsl::span values) const = 0; /** @@ -165,7 +165,7 @@ class slave * \pre `variables.size() == values.size()` */ virtual void set_real_variables( - gsl::span variables, + gsl::span variables, gsl::span values) = 0; /** @@ -181,7 +181,7 @@ class slave * \pre `variables.size() == values.size()` */ virtual void set_integer_variables( - gsl::span variables, + gsl::span variables, gsl::span values) = 0; /** @@ -197,7 +197,7 @@ class slave * \pre `variables.size() == values.size()` */ virtual void set_boolean_variables( - gsl::span variables, + gsl::span variables, gsl::span values) = 0; /** @@ -213,7 +213,7 @@ class slave * \pre `variables.size() == values.size()` */ virtual void set_string_variables( - gsl::span variables, + gsl::span variables, gsl::span values) = 0; }; diff --git a/src/c/cse.cpp b/src/c/cse.cpp index e435dd6af..118218b08 100644 --- a/src/c/cse.cpp +++ b/src/c/cse.cpp @@ -500,9 +500,9 @@ int cse_observer_destroy(cse_observer* observer) int connect_variables( cse_execution* execution, cse::simulator_index outputSimulator, - cse::variable_index outputVariable, + cse::value_reference outputVariable, cse::simulator_index inputSimulator, - cse::variable_index inputVariable, + cse::value_reference inputVariable, cse::variable_type type) { try { @@ -520,29 +520,29 @@ int connect_variables( int cse_execution_connect_real_variables( cse_execution* execution, cse_slave_index outputSlaveIndex, - cse_variable_index outputVariableIndex, + cse_value_reference outputValueReference, cse_slave_index inputSlaveIndex, - cse_variable_index inputVariableIndex) + cse_value_reference inputValueReference) { - return connect_variables(execution, outputSlaveIndex, outputVariableIndex, inputSlaveIndex, inputVariableIndex, + return connect_variables(execution, outputSlaveIndex, outputValueReference, inputSlaveIndex, inputValueReference, cse::variable_type::real); } int cse_execution_connect_integer_variables( cse_execution* execution, cse_slave_index outputSlaveIndex, - cse_variable_index outputVariableIndex, + cse_value_reference outputValueReference, cse_slave_index inputSlaveIndex, - cse_variable_index inputVariableIndex) + cse_value_reference inputValueReference) { - return connect_variables(execution, outputSlaveIndex, outputVariableIndex, inputSlaveIndex, inputVariableIndex, + return connect_variables(execution, outputSlaveIndex, outputValueReference, inputSlaveIndex, inputValueReference, cse::variable_type::integer); } int cse_observer_slave_get_real( cse_observer* observer, cse_slave_index slave, - const cse_variable_index variables[], + const cse_value_reference variables[], size_t nv, double values[]) { @@ -562,7 +562,7 @@ int cse_observer_slave_get_real( int cse_observer_slave_get_integer( cse_observer* observer, cse_slave_index slave, - const cse_variable_index variables[], + const cse_value_reference variables[], size_t nv, int values[]) { @@ -582,7 +582,7 @@ int cse_observer_slave_get_integer( int cse_observer_slave_get_boolean( cse_observer* observer, cse_slave_index slave, - const cse_variable_index variables[], + const cse_value_reference variables[], size_t nv, bool values[]) { @@ -606,7 +606,7 @@ thread_local std::vector g_stringVariableBuffer; int cse_observer_slave_get_string( cse_observer* observer, cse_slave_index slave, - const cse_variable_index variables[], + const cse_value_reference variables[], size_t nv, const char* values[]) { @@ -631,7 +631,7 @@ int cse_observer_slave_get_string( int64_t cse_observer_slave_get_real_samples( cse_observer* observer, cse_slave_index slave, - cse_variable_index variableIndex, + cse_value_reference ValueReference, cse_step_number fromStep, size_t nSamples, double values[], @@ -644,7 +644,7 @@ int64_t cse_observer_slave_get_real_samples( if (!obs) { throw std::invalid_argument("Invalid observer! The provided observer must be a time_series_observer."); } - size_t samplesRead = obs->get_real_samples(slave, variableIndex, fromStep, + size_t samplesRead = obs->get_real_samples(slave, ValueReference, fromStep, gsl::make_span(values, nSamples), gsl::make_span(steps, nSamples), timePoints); for (size_t i = 0; i < samplesRead; ++i) { @@ -660,9 +660,9 @@ int64_t cse_observer_slave_get_real_samples( int64_t cse_observer_slave_get_real_synchronized_series( cse_observer* observer, cse_slave_index slave1, - cse_variable_index variableIndex1, + cse_value_reference ValueReference1, cse_slave_index slave2, - cse_variable_index variableIndex2, + cse_value_reference ValueReference2, cse_step_number fromStep, size_t nSamples, double values1[], @@ -676,9 +676,9 @@ int64_t cse_observer_slave_get_real_synchronized_series( } size_t samplesRead = obs->get_synchronized_real_series( slave1, - variableIndex1, + ValueReference1, slave2, - variableIndex2, + ValueReference2, fromStep, gsl::make_span(values1, nSamples), gsl::make_span(values2, nSamples)); @@ -692,7 +692,7 @@ int64_t cse_observer_slave_get_real_synchronized_series( int64_t cse_observer_slave_get_integer_samples( cse_observer* observer, cse_slave_index slave, - cse_variable_index variableIndex, + cse_value_reference ValueReference, cse_step_number fromStep, size_t nSamples, int values[], @@ -705,7 +705,7 @@ int64_t cse_observer_slave_get_integer_samples( if (!obs) { throw std::invalid_argument("Invalid observer! The provided observer must be a time_series_observer."); } - size_t samplesRead = obs->get_integer_samples(slave, variableIndex, fromStep, + size_t samplesRead = obs->get_integer_samples(slave, ValueReference, fromStep, gsl::make_span(values, nSamples), gsl::make_span(steps, nSamples), timePoints); for (size_t i = 0; i < samplesRead; ++i) { @@ -812,7 +812,7 @@ cse::variable_type to_cpp_variable_type(cse_variable_type type) } } -int cse_observer_start_observing(cse_observer* observer, cse_slave_index slave, cse_variable_type type, cse_variable_index index) +int cse_observer_start_observing(cse_observer* observer, cse_slave_index slave, cse_variable_type type, cse_value_reference index) { try { const auto timeSeriesObserver = std::dynamic_pointer_cast(observer->cpp_observer); @@ -828,7 +828,7 @@ int cse_observer_start_observing(cse_observer* observer, cse_slave_index slave, } } -int cse_observer_stop_observing(cse_observer* observer, cse_slave_index slave, cse_variable_type type, cse_variable_index index) +int cse_observer_stop_observing(cse_observer* observer, cse_slave_index slave, cse_variable_type type, cse_value_reference index) { try { const auto timeSeriesObserver = std::dynamic_pointer_cast(observer->cpp_observer); @@ -897,7 +897,7 @@ int cse_execution_add_manipulator( int cse_manipulator_slave_set_real( cse_manipulator* manipulator, cse_slave_index slaveIndex, - const cse_variable_index variables[], + const cse_value_reference variables[], size_t nv, const double values[]) { @@ -919,7 +919,7 @@ int cse_manipulator_slave_set_real( int cse_manipulator_slave_set_integer( cse_manipulator* manipulator, cse_slave_index slaveIndex, - const cse_variable_index variables[], + const cse_value_reference variables[], size_t nv, const int values[]) { @@ -941,7 +941,7 @@ int cse_manipulator_slave_set_integer( int cse_manipulator_slave_set_boolean( cse_manipulator* manipulator, cse_slave_index slaveIndex, - const cse_variable_index variables[], + const cse_value_reference variables[], size_t nv, const bool values[]) { @@ -963,7 +963,7 @@ int cse_manipulator_slave_set_boolean( int cse_manipulator_slave_set_string( cse_manipulator* manipulator, cse_slave_index slaveIndex, - const cse_variable_index variables[], + const cse_value_reference variables[], size_t nv, const char* values[]) { @@ -986,7 +986,7 @@ int cse_manipulator_slave_reset( cse_manipulator* manipulator, cse_slave_index slaveIndex, cse_variable_type type, - const cse_variable_index variables[], + const cse_value_reference variables[], size_t nv) { try { @@ -1070,7 +1070,7 @@ int cse_get_modified_variables(cse_execution* execution, cse_variable_id ids[], for (; counter < std::min(numVariables, modified_vars.size()); counter++) { ids[counter].slave_index = modified_vars[counter].simulator; ids[counter].type = to_c_variable_type(modified_vars[counter].type); - ids[counter].variable_index = modified_vars[counter].index; + ids[counter].value_reference = modified_vars[counter].index; } } diff --git a/src/cpp/async_slave.cpp b/src/cpp/async_slave.cpp index 778d837d3..e9b56744b 100644 --- a/src/cpp/async_slave.cpp +++ b/src/cpp/async_slave.cpp @@ -131,13 +131,13 @@ auto big_stack_async(F&& f) */ void set_all_variables( slave& slave, - gsl::span realVariables, + gsl::span realVariables, gsl::span realValues, - gsl::span integerVariables, + gsl::span integerVariables, gsl::span integerValues, - gsl::span booleanVariables, + gsl::span booleanVariables, gsl::span booleanValues, - gsl::span stringVariables, + gsl::span stringVariables, gsl::span stringValues) { bool nonfatalBadValue = false; @@ -254,10 +254,10 @@ class pseudo_async_slave : public cse::async_slave // clang-format off boost::fibers::future get_variables( - gsl::span realVariables, - gsl::span integerVariables, - gsl::span booleanVariables, - gsl::span stringVariables) + gsl::span realVariables, + gsl::span integerVariables, + gsl::span booleanVariables, + gsl::span stringVariables) override { CSE_PRECONDITION( @@ -291,13 +291,13 @@ class pseudo_async_slave : public cse::async_slave } boost::fibers::future set_variables( - gsl::span realVariables, + gsl::span realVariables, gsl::span realValues, - gsl::span integerVariables, + gsl::span integerVariables, gsl::span integerValues, - gsl::span booleanVariables, + gsl::span booleanVariables, gsl::span booleanValues, - gsl::span stringVariables, + gsl::span stringVariables, gsl::span stringValues) override { @@ -387,24 +387,24 @@ struct do_step_request }; struct get_variables_request { - gsl::span realVariables; + gsl::span realVariables; gsl::span realValues; - gsl::span integerVariables; + gsl::span integerVariables; gsl::span integerValues; - gsl::span booleanVariables; + gsl::span booleanVariables; gsl::span booleanValues; - gsl::span stringVariables; + gsl::span stringVariables; gsl::span stringValues; }; struct set_variables_request { - gsl::span realVariables; + gsl::span realVariables; gsl::span realValues; - gsl::span integerVariables; + gsl::span integerVariables; gsl::span integerValues; - gsl::span booleanVariables; + gsl::span booleanVariables; gsl::span booleanValues; - gsl::span stringVariables; + gsl::span stringVariables; gsl::span stringValues; }; @@ -626,10 +626,10 @@ class background_thread_slave_frontend : public async_slave // clang-format off boost::fibers::future get_variables( - gsl::span realVariables, - gsl::span integerVariables, - gsl::span booleanVariables, - gsl::span stringVariables) + gsl::span realVariables, + gsl::span integerVariables, + gsl::span booleanVariables, + gsl::span stringVariables) override { CSE_PRECONDITION( @@ -671,13 +671,13 @@ class background_thread_slave_frontend : public async_slave } boost::fibers::future set_variables( - gsl::span realVariables, + gsl::span realVariables, gsl::span realValues, - gsl::span integerVariables, + gsl::span integerVariables, gsl::span integerValues, - gsl::span booleanVariables, + gsl::span booleanVariables, gsl::span booleanValues, - gsl::span stringVariables, + gsl::span stringVariables, gsl::span stringValues) override { diff --git a/src/cpp/cse/fmuproxy/fmuproxy_helper.hpp b/src/cpp/cse/fmuproxy/fmuproxy_helper.hpp index 67d95f94d..00d82a3c3 100644 --- a/src/cpp/cse/fmuproxy/fmuproxy_helper.hpp +++ b/src/cpp/cse/fmuproxy/fmuproxy_helper.hpp @@ -70,7 +70,7 @@ inline cse::variable_description convert(const fmuproxy::thrift::ScalarVariable& { cse::variable_description var; var.name = v.name; - var.index = (cse::variable_index)v.value_reference; + var.index = (cse::value_reference)v.value_reference; var.causality = parse_causality(v.causality); var.variability = parse_variability(v.variability); var.type = get_type(v); diff --git a/src/cpp/cse/fmuproxy/remote_slave.hpp b/src/cpp/cse/fmuproxy/remote_slave.hpp index 8bb0fb11d..12240c36b 100644 --- a/src/cpp/cse/fmuproxy/remote_slave.hpp +++ b/src/cpp/cse/fmuproxy/remote_slave.hpp @@ -34,22 +34,22 @@ class remote_slave : public slave cse::step_result do_step(time_point currentT, duration deltaT) override; - void get_real_variables(gsl::span variables, gsl::span values) const override; + void get_real_variables(gsl::span variables, gsl::span values) const override; - void get_integer_variables(gsl::span variables, gsl::span values) const override; + void get_integer_variables(gsl::span variables, gsl::span values) const override; - void get_boolean_variables(gsl::span variables, gsl::span values) const override; + void get_boolean_variables(gsl::span variables, gsl::span values) const override; - void get_string_variables(gsl::span variables, + void get_string_variables(gsl::span variables, gsl::span values) const override; - void set_real_variables(gsl::span variables, gsl::span values) override; + void set_real_variables(gsl::span variables, gsl::span values) override; - void set_integer_variables(gsl::span variables, gsl::span values) override; + void set_integer_variables(gsl::span variables, gsl::span values) override; - void set_boolean_variables(gsl::span variables, gsl::span values) override; + void set_boolean_variables(gsl::span variables, gsl::span values) override; - void set_string_variables(gsl::span variables, + void set_string_variables(gsl::span variables, gsl::span values) override; ~remote_slave() override; diff --git a/src/cpp/cse/observer/slave_value_provider.hpp b/src/cpp/cse/observer/slave_value_provider.hpp index d7e5d4e48..90e9e4707 100644 --- a/src/cpp/cse/observer/slave_value_provider.hpp +++ b/src/cpp/cse/observer/slave_value_provider.hpp @@ -22,16 +22,16 @@ class slave_value_provider slave_value_provider(observable* obs); ~slave_value_provider() noexcept; void observe(); - void get_real(gsl::span variables, gsl::span values); - void get_int(gsl::span variables, gsl::span values); - void get_boolean(gsl::span variables, gsl::span values); - void get_string(gsl::span variables, gsl::span values); + void get_real(gsl::span variables, gsl::span values); + void get_int(gsl::span variables, gsl::span values); + void get_boolean(gsl::span variables, gsl::span values); + void get_string(gsl::span variables, gsl::span values); private: - std::unordered_map realSamples_; - std::unordered_map intSamples_; - std::unordered_map boolSamples_; - std::unordered_map stringSamples_; + std::unordered_map realSamples_; + std::unordered_map intSamples_; + std::unordered_map boolSamples_; + std::unordered_map stringSamples_; observable* observable_; std::mutex lock_; }; diff --git a/src/cpp/cse/slave_simulator.hpp b/src/cpp/cse/slave_simulator.hpp index 853d08136..d7e9d0976 100644 --- a/src/cpp/cse/slave_simulator.hpp +++ b/src/cpp/cse/slave_simulator.hpp @@ -33,48 +33,48 @@ class slave_simulator : public simulator std::string name() const override; cse::model_description model_description() const override; - void expose_for_getting(variable_type type, variable_index index) override; - double get_real(variable_index index) const override; - int get_integer(variable_index index) const override; - bool get_boolean(variable_index index) const override; - std::string_view get_string(variable_index index) const override; + void expose_for_getting(variable_type type, value_reference index) override; + double get_real(value_reference index) const override; + int get_integer(value_reference index) const override; + bool get_boolean(value_reference index) const override; + std::string_view get_string(value_reference index) const override; // `simulator` methods - void expose_for_setting(variable_type type, variable_index index) override; - void set_real(variable_index index, double value) override; - void set_integer(variable_index index, int value) override; - void set_boolean(variable_index index, bool value) override; - void set_string(variable_index index, std::string_view value) override; + void expose_for_setting(variable_type type, value_reference index) override; + void set_real(value_reference index, double value) override; + void set_integer(value_reference index, int value) override; + void set_boolean(value_reference index, bool value) override; + void set_string(value_reference index, std::string_view value) override; void set_real_input_modifier( - variable_index index, + value_reference index, std::function modifier) override; void set_integer_input_modifier( - variable_index index, + value_reference index, std::function modifier) override; void set_boolean_input_modifier( - variable_index index, + value_reference index, std::function modifier) override; void set_string_input_modifier( - variable_index index, + value_reference index, std::function modifier) override; void set_real_output_modifier( - variable_index index, + value_reference index, std::function modifier) override; void set_integer_output_modifier( - variable_index index, + value_reference index, std::function modifier) override; void set_boolean_output_modifier( - variable_index index, + value_reference index, std::function modifier) override; void set_string_output_modifier( - variable_index index, + value_reference index, std::function modifier) override; - std::unordered_set& get_modified_real_indexes() const override; - std::unordered_set& get_modified_integer_indexes() const override; - std::unordered_set& get_modified_boolean_indexes() const override; - std::unordered_set& get_modified_string_indexes() const override; + std::unordered_set& get_modified_real_indexes() const override; + std::unordered_set& get_modified_integer_indexes() const override; + std::unordered_set& get_modified_boolean_indexes() const override; + std::unordered_set& get_modified_string_indexes() const override; boost::fibers::future setup( time_point startTime, diff --git a/src/cpp/execution.cpp b/src/cpp/execution.cpp index ce6c987d1..2f7ad3fdf 100644 --- a/src/cpp/execution.cpp +++ b/src/cpp/execution.cpp @@ -235,7 +235,7 @@ class execution::impl return modifiedVariables; } - void set_real_initial_value(simulator_index sim, variable_index var, double value) + void set_real_initial_value(simulator_index sim, value_reference var, double value) { if (initialized_) { throw error(make_error_code(errc::unsupported_feature), "Initial values must be set before simulation is started"); @@ -244,7 +244,7 @@ class execution::impl simulators_.at(sim)->set_real(var, value); } - void set_integer_initial_value(simulator_index sim, variable_index var, int value) + void set_integer_initial_value(simulator_index sim, value_reference var, int value) { if (initialized_) { throw error(make_error_code(errc::unsupported_feature), "Initial values must be set before simulation is started"); @@ -253,7 +253,7 @@ class execution::impl simulators_.at(sim)->set_integer(var, value); } - void set_boolean_initial_value(simulator_index sim, variable_index var, bool value) + void set_boolean_initial_value(simulator_index sim, value_reference var, bool value) { if (initialized_) { throw error(make_error_code(errc::unsupported_feature), "Initial values must be set before simulation is started"); @@ -262,7 +262,7 @@ class execution::impl simulators_.at(sim)->set_boolean(var, value); } - void set_string_initial_value(simulator_index sim, variable_index var, const std::string& value) + void set_string_initial_value(simulator_index sim, value_reference var, const std::string& value) { if (initialized_) { throw error(make_error_code(errc::unsupported_feature), "Initial values must be set before simulation is started"); @@ -426,22 +426,22 @@ std::vector execution::get_modified_variables() return pimpl_->get_modified_variables(); } -void execution::set_real_initial_value(simulator_index sim, variable_index var, double value) +void execution::set_real_initial_value(simulator_index sim, value_reference var, double value) { pimpl_->set_real_initial_value(sim, var, value); } -void execution::set_integer_initial_value(simulator_index sim, variable_index var, int value) +void execution::set_integer_initial_value(simulator_index sim, value_reference var, int value) { pimpl_->set_integer_initial_value(sim, var, value); } -void execution::set_boolean_initial_value(simulator_index sim, variable_index var, bool value) +void execution::set_boolean_initial_value(simulator_index sim, value_reference var, bool value) { pimpl_->set_boolean_initial_value(sim, var, value); } -void execution::set_string_initial_value(simulator_index sim, variable_index var, const std::string& value) +void execution::set_string_initial_value(simulator_index sim, value_reference var, const std::string& value) { pimpl_->set_string_initial_value(sim, var, value); } diff --git a/src/cpp/fmi/v1/fmu.cpp b/src/cpp/fmi/v1/fmu.cpp index 744698aa5..71ebce822 100644 --- a/src/cpp/fmi/v1/fmu.cpp +++ b/src/cpp/fmi/v1/fmu.cpp @@ -376,7 +376,7 @@ step_result slave_instance::do_step(time_point currentT, duration deltaT) void slave_instance::get_real_variables( - gsl::span variables, + gsl::span variables, gsl::span values) const { CSE_INPUT_CHECK(variables.size() == values.size()); @@ -392,7 +392,7 @@ void slave_instance::get_real_variables( void slave_instance::get_integer_variables( - gsl::span variables, + gsl::span variables, gsl::span values) const { CSE_INPUT_CHECK(variables.size() == values.size()); @@ -408,7 +408,7 @@ void slave_instance::get_integer_variables( void slave_instance::get_boolean_variables( - gsl::span variables, + gsl::span variables, gsl::span values) const { CSE_INPUT_CHECK(variables.size() == values.size()); @@ -428,7 +428,7 @@ void slave_instance::get_boolean_variables( void slave_instance::get_string_variables( - gsl::span variables, + gsl::span variables, gsl::span values) const { CSE_INPUT_CHECK(variables.size() == values.size()); @@ -449,7 +449,7 @@ void slave_instance::get_string_variables( void slave_instance::set_real_variables( - gsl::span variables, + gsl::span variables, gsl::span values) { CSE_INPUT_CHECK(variables.size() == values.size()); @@ -469,7 +469,7 @@ void slave_instance::set_real_variables( void slave_instance::set_integer_variables( - gsl::span variables, + gsl::span variables, gsl::span values) { CSE_INPUT_CHECK(variables.size() == values.size()); @@ -489,7 +489,7 @@ void slave_instance::set_integer_variables( void slave_instance::set_boolean_variables( - gsl::span variables, + gsl::span variables, gsl::span values) { CSE_INPUT_CHECK(variables.size() == values.size()); @@ -514,7 +514,7 @@ void slave_instance::set_boolean_variables( void slave_instance::set_string_variables( - gsl::span variables, + gsl::span variables, gsl::span values) { CSE_INPUT_CHECK(variables.size() == values.size()); diff --git a/src/cpp/fmi/v2/fmu.cpp b/src/cpp/fmi/v2/fmu.cpp index a8a977962..0f06ca869 100644 --- a/src/cpp/fmi/v2/fmu.cpp +++ b/src/cpp/fmi/v2/fmu.cpp @@ -396,7 +396,7 @@ step_result slave_instance::do_step(time_point currentT, duration deltaT) void slave_instance::get_real_variables( - gsl::span variables, + gsl::span variables, gsl::span values) const { CSE_INPUT_CHECK(variables.size() == values.size()); @@ -412,7 +412,7 @@ void slave_instance::get_real_variables( void slave_instance::get_integer_variables( - gsl::span variables, + gsl::span variables, gsl::span values) const { CSE_INPUT_CHECK(variables.size() == values.size()); @@ -428,7 +428,7 @@ void slave_instance::get_integer_variables( void slave_instance::get_boolean_variables( - gsl::span variables, + gsl::span variables, gsl::span values) const { CSE_INPUT_CHECK(variables.size() == values.size()); @@ -448,7 +448,7 @@ void slave_instance::get_boolean_variables( void slave_instance::get_string_variables( - gsl::span variables, + gsl::span variables, gsl::span values) const { CSE_INPUT_CHECK(variables.size() == values.size()); @@ -469,7 +469,7 @@ void slave_instance::get_string_variables( void slave_instance::set_real_variables( - gsl::span variables, + gsl::span variables, gsl::span values) { CSE_INPUT_CHECK(variables.size() == values.size()); @@ -489,7 +489,7 @@ void slave_instance::set_real_variables( void slave_instance::set_integer_variables( - gsl::span variables, + gsl::span variables, gsl::span values) { CSE_INPUT_CHECK(variables.size() == values.size()); @@ -509,7 +509,7 @@ void slave_instance::set_integer_variables( void slave_instance::set_boolean_variables( - gsl::span variables, + gsl::span variables, gsl::span values) { CSE_INPUT_CHECK(variables.size() == values.size()); @@ -534,7 +534,7 @@ void slave_instance::set_boolean_variables( void slave_instance::set_string_variables( - gsl::span variables, + gsl::span variables, gsl::span values) { CSE_INPUT_CHECK(variables.size() == values.size()); diff --git a/src/cpp/fmuproxy/remote_slave.cpp b/src/cpp/fmuproxy/remote_slave.cpp index a22ae34ed..768ba6fd9 100644 --- a/src/cpp/fmuproxy/remote_slave.cpp +++ b/src/cpp/fmuproxy/remote_slave.cpp @@ -71,7 +71,7 @@ cse::step_result cse::fmuproxy::remote_slave::do_step(cse::time_point, cse::dura return cse::step_result::complete; } -void cse::fmuproxy::remote_slave::get_real_variables(gsl::span variables, +void cse::fmuproxy::remote_slave::get_real_variables(gsl::span variables, gsl::span values) const { CSE_INPUT_CHECK(variables.size() == values.size()); @@ -87,7 +87,7 @@ void cse::fmuproxy::remote_slave::get_real_variables(gsl::span variables, +void cse::fmuproxy::remote_slave::get_integer_variables(gsl::span variables, gsl::span values) const { CSE_INPUT_CHECK(variables.size() == values.size()); @@ -103,7 +103,7 @@ void cse::fmuproxy::remote_slave::get_integer_variables(gsl::span variables, +void cse::fmuproxy::remote_slave::get_boolean_variables(gsl::span variables, gsl::span values) const { CSE_INPUT_CHECK(variables.size() == values.size()); @@ -119,7 +119,7 @@ void cse::fmuproxy::remote_slave::get_boolean_variables(gsl::span variables, +void cse::fmuproxy::remote_slave::get_string_variables(gsl::span variables, gsl::span values) const { CSE_INPUT_CHECK(variables.size() == values.size()); @@ -132,7 +132,7 @@ void cse::fmuproxy::remote_slave::get_string_variables(gsl::span variables, +void cse::fmuproxy::remote_slave::set_real_variables(gsl::span variables, gsl::span values) { CSE_INPUT_CHECK(variables.size() == values.size()); @@ -144,7 +144,7 @@ void cse::fmuproxy::remote_slave::set_real_variables(gsl::span variables, +void cse::fmuproxy::remote_slave::set_integer_variables(gsl::span variables, gsl::span values) { CSE_INPUT_CHECK(variables.size() == values.size()); @@ -156,7 +156,7 @@ void cse::fmuproxy::remote_slave::set_integer_variables(gsl::span variables, +void cse::fmuproxy::remote_slave::set_boolean_variables(gsl::span variables, gsl::span values) { CSE_INPUT_CHECK(variables.size() == values.size()); @@ -168,7 +168,7 @@ void cse::fmuproxy::remote_slave::set_boolean_variables(gsl::span variables, +void cse::fmuproxy::remote_slave::set_string_variables(gsl::span variables, gsl::span values) { CSE_INPUT_CHECK(variables.size() == values.size()); diff --git a/src/cpp/observer/file_observer.cpp b/src/cpp/observer/file_observer.cpp index d758b8251..3442238c8 100644 --- a/src/cpp/observer/file_observer.cpp +++ b/src/cpp/observer/file_observer.cpp @@ -228,10 +228,10 @@ class file_observer::slave_value_writer std::map> intSamples_; std::map> boolSamples_; std::map> stringSamples_; - std::vector realIndexes_; - std::vector intIndexes_; - std::vector boolIndexes_; - std::vector stringIndexes_; + std::vector realIndexes_; + std::vector intIndexes_; + std::vector boolIndexes_; + std::vector stringIndexes_; std::map timeSamples_; std::vector realVars_; std::vector intVars_; diff --git a/src/cpp/observer/last_value_observer.cpp b/src/cpp/observer/last_value_observer.cpp index fed20352f..fab3fa100 100644 --- a/src/cpp/observer/last_value_observer.cpp +++ b/src/cpp/observer/last_value_observer.cpp @@ -49,7 +49,7 @@ void last_value_observer::simulator_step_complete( void last_value_observer::get_real( simulator_index sim, - gsl::span variables, + gsl::span variables, gsl::span values) { CSE_INPUT_CHECK(variables.size() == values.size()); @@ -58,7 +58,7 @@ void last_value_observer::get_real( void last_value_observer::get_integer( simulator_index sim, - gsl::span variables, + gsl::span variables, gsl::span values) { CSE_INPUT_CHECK(variables.size() == values.size()); @@ -67,7 +67,7 @@ void last_value_observer::get_integer( void last_value_observer::get_boolean( simulator_index sim, - gsl::span variables, + gsl::span variables, gsl::span values) { CSE_INPUT_CHECK(variables.size() == values.size()); @@ -76,7 +76,7 @@ void last_value_observer::get_boolean( void last_value_observer::get_string( simulator_index sim, - gsl::span variables, + gsl::span variables, gsl::span values) { CSE_INPUT_CHECK(variables.size() == values.size()); diff --git a/src/cpp/observer/slave_value_provider.cpp b/src/cpp/observer/slave_value_provider.cpp index bc2dcc921..12286ca4a 100644 --- a/src/cpp/observer/slave_value_provider.cpp +++ b/src/cpp/observer/slave_value_provider.cpp @@ -12,15 +12,15 @@ namespace template void get( - gsl::span variables, - const std::unordered_map& samples, + gsl::span variables, + const std::unordered_map& samples, gsl::span values) { if (samples.empty()) { throw std::out_of_range("no samples available"); } for (int i = 0; i < values.size(); i++) { - variable_index valueRef = variables[i]; + value_reference valueRef = variables[i]; values[i] = samples.at(valueRef); } } @@ -72,25 +72,25 @@ void slave_value_provider::observe() } } -void slave_value_provider::get_real(gsl::span variables, gsl::span values) +void slave_value_provider::get_real(gsl::span variables, gsl::span values) { std::lock_guard lock(lock_); get(variables, realSamples_, values); } -void slave_value_provider::get_int(gsl::span variables, gsl::span values) +void slave_value_provider::get_int(gsl::span variables, gsl::span values) { std::lock_guard lock(lock_); get(variables, intSamples_, values); } -void slave_value_provider::get_boolean(gsl::span variables, gsl::span values) +void slave_value_provider::get_boolean(gsl::span variables, gsl::span values) { std::lock_guard lock(lock_); get(variables, boolSamples_, values); } -void slave_value_provider::get_string(gsl::span variables, gsl::span values) +void slave_value_provider::get_string(gsl::span variables, gsl::span values) { std::lock_guard lock(lock_); get(variables, stringSamples_, values); diff --git a/src/cpp/observer/time_series_observer.cpp b/src/cpp/observer/time_series_observer.cpp index 5f8f26ec8..ff4521c42 100644 --- a/src/cpp/observer/time_series_observer.cpp +++ b/src/cpp/observer/time_series_observer.cpp @@ -14,8 +14,8 @@ namespace { template size_t get_samples( - variable_index variableIndex, - const std::map>& variables, + value_reference valueReference, + const std::map>& variables, std::map timeSamples, step_number fromStep, gsl::span values, @@ -23,7 +23,7 @@ size_t get_samples( gsl::span times) { size_t samplesRead = 0; - const auto& samplesIt = variables.find(variableIndex); + const auto& samplesIt = variables.find(valueReference); if (samplesIt != variables.end()) { const auto& samples = samplesIt->second; if (samples.empty()) { @@ -88,7 +88,7 @@ class time_series_observer::single_slave_observer adjustIfFull(timeSamples_, bufSize_); } - void start_observing(variable_type type, variable_index index) + void start_observing(variable_type type, value_reference index) { std::lock_guard lock(lock_); switch (type) { @@ -108,7 +108,7 @@ class time_series_observer::single_slave_observer } } - void stop_observing(variable_type type, variable_index index) + void stop_observing(variable_type type, value_reference index) { std::lock_guard lock(lock_); switch (type) { @@ -126,16 +126,16 @@ class time_series_observer::single_slave_observer } } - size_t get_real_samples(variable_index variableIndex, step_number fromStep, gsl::span values, gsl::span steps, gsl::span times) + size_t get_real_samples(value_reference valueReference, step_number fromStep, gsl::span values, gsl::span steps, gsl::span times) { std::lock_guard lock(lock_); - return get_samples(variableIndex, realSamples_, timeSamples_, fromStep, values, steps, times); + return get_samples(valueReference, realSamples_, timeSamples_, fromStep, values, steps, times); } - size_t get_int_samples(variable_index variableIndex, step_number fromStep, gsl::span values, gsl::span steps, gsl::span times) + size_t get_int_samples(value_reference valueReference, step_number fromStep, gsl::span values, gsl::span steps, gsl::span times) { std::lock_guard lock(lock_); - return get_samples(variableIndex, intSamples_, timeSamples_, fromStep, values, steps, times); + return get_samples(valueReference, intSamples_, timeSamples_, fromStep, values, steps, times); } void get_step_numbers(time_point tBegin, time_point tEnd, gsl::span steps) @@ -183,15 +183,15 @@ class time_series_observer::single_slave_observer steps[1] = lastStep; } - const std::map get_real_samples_map(variable_index idx) + const std::map get_real_samples_map(value_reference idx) { std::lock_guard lock(lock_); return realSamples_.at(idx); } private: - std::map> realSamples_; - std::map> intSamples_; + std::map> realSamples_; + std::map> intSamples_; std::map timeSamples_; observable* observable_; size_t bufSize_; @@ -254,7 +254,7 @@ void time_series_observer::stop_observing(variable_id id) std::size_t time_series_observer::get_real_samples( simulator_index sim, - variable_index variableIndex, + value_reference valueReference, step_number fromStep, gsl::span values, gsl::span steps, @@ -262,12 +262,12 @@ std::size_t time_series_observer::get_real_samples( { CSE_INPUT_CHECK(values.size() == steps.size()); CSE_INPUT_CHECK(times.size() == values.size()); - return slaveObservers_.at(sim)->get_real_samples(variableIndex, fromStep, values, steps, times); + return slaveObservers_.at(sim)->get_real_samples(valueReference, fromStep, values, steps, times); } std::size_t time_series_observer::get_integer_samples( simulator_index sim, - variable_index variableIndex, + value_reference valueReference, step_number fromStep, gsl::span values, gsl::span steps, @@ -275,7 +275,7 @@ std::size_t time_series_observer::get_integer_samples( { CSE_INPUT_CHECK(values.size() == steps.size()); CSE_INPUT_CHECK(times.size() == values.size()); - return slaveObservers_.at(sim)->get_int_samples(variableIndex, fromStep, values, steps, times); + return slaveObservers_.at(sim)->get_int_samples(valueReference, fromStep, values, steps, times); } void time_series_observer::get_step_numbers( @@ -297,17 +297,17 @@ void time_series_observer::get_step_numbers( std::size_t time_series_observer::get_synchronized_real_series( simulator_index sim1, - variable_index variableIndex1, + value_reference valueReference1, simulator_index sim2, - variable_index variableIndex2, + value_reference valueReference2, step_number fromStep, gsl::span values1, gsl::span values2) { CSE_INPUT_CHECK(values1.size() == values2.size()); - const auto realSamples1 = slaveObservers_.at(sim1)->get_real_samples_map(variableIndex1); - const auto realSamples2 = slaveObservers_.at(sim2)->get_real_samples_map(variableIndex2); + const auto realSamples1 = slaveObservers_.at(sim1)->get_real_samples_map(valueReference1); + const auto realSamples2 = slaveObservers_.at(sim2)->get_real_samples_map(valueReference2); if (realSamples1.empty() || realSamples2.empty()) { throw std::out_of_range("Samples for both variables not recorded yet!"); diff --git a/src/cpp/override_manipulator.cpp b/src/cpp/override_manipulator.cpp index d9db10ced..0146b6b1f 100644 --- a/src/cpp/override_manipulator.cpp +++ b/src/cpp/override_manipulator.cpp @@ -23,7 +23,7 @@ struct visitor : Functors... cse::variable_causality find_variable_causality( const std::vector& variables, const cse::variable_type type, - const cse::variable_index index) + const cse::value_reference index) { for (const auto& vd : variables) { if ((vd.index == index) && (vd.type == type)) { @@ -121,7 +121,7 @@ void override_manipulator::step_commencing(time_point /*currentTime*/) void override_manipulator::add_action( simulator_index index, - variable_index variable, + value_reference variable, variable_type type, const std::variant< scenario::real_modifier, @@ -139,7 +139,7 @@ void override_manipulator::add_action( void override_manipulator::override_real_variable( simulator_index index, - variable_index variable, + value_reference variable, double value) { auto f = [value](double /*original*/) { return value; }; @@ -148,7 +148,7 @@ void override_manipulator::override_real_variable( void override_manipulator::override_integer_variable( simulator_index index, - variable_index variable, + value_reference variable, int value) { auto f = [value](int /*original*/) { return value; }; @@ -157,7 +157,7 @@ void override_manipulator::override_integer_variable( void override_manipulator::override_boolean_variable( simulator_index index, - variable_index variable, + value_reference variable, bool value) { auto f = [value](bool /*original*/) { return value; }; @@ -166,7 +166,7 @@ void override_manipulator::override_boolean_variable( void override_manipulator::override_string_variable( simulator_index index, - variable_index variable, + value_reference variable, const std::string& value) { auto f = [value](std::string_view /*original*/) { return value; }; @@ -176,7 +176,7 @@ void override_manipulator::override_string_variable( void override_manipulator::reset_variable( simulator_index index, variable_type type, - variable_index variable) + value_reference variable) { switch (type) { case variable_type::real: diff --git a/src/cpp/scenario_parser.cpp b/src/cpp/scenario_parser.cpp index fac682c3f..0654d4205 100644 --- a/src/cpp/scenario_parser.cpp +++ b/src/cpp/scenario_parser.cpp @@ -86,7 +86,7 @@ cse::scenario::variable_action generate_action( cse::simulator_index sim, cse::variable_type type, bool isInput, - cse::variable_index var) + cse::value_reference var) { switch (type) { case cse::variable_type::real: { diff --git a/src/cpp/slave_simulator.cpp b/src/cpp/slave_simulator.cpp index aa323faf5..b9cca250c 100644 --- a/src/cpp/slave_simulator.cpp +++ b/src/cpp/slave_simulator.cpp @@ -34,13 +34,13 @@ struct var_view_type template struct get_variable_cache { - std::vector indexes; + std::vector indexes; boost::container::vector originalValues; boost::container::vector modifiedValues; std::vector> modifiers; - std::unordered_map indexMapping; + std::unordered_map indexMapping; - void expose(variable_index i) + void expose(value_reference i) { if (indexMapping.count(i)) return; indexes.push_back(i); @@ -50,7 +50,7 @@ struct get_variable_cache indexMapping[i] = indexes.size() - 1; } - typename var_view_type::type get(variable_index i) const + typename var_view_type::type get(value_reference i) const { const auto it = indexMapping.find(i); if (it != indexMapping.end()) { @@ -63,7 +63,7 @@ struct get_variable_cache } } - void set_modifier(variable_index i, std::function m) + void set_modifier(value_reference i, std::function m) { modifiers[indexMapping[i]] = m; } @@ -85,12 +85,12 @@ template class set_variable_cache { public: - void expose(variable_index i, T startValue) + void expose(value_reference i, T startValue) { exposedVariables_.emplace(i, exposed_variable{startValue, -1}); } - void set_value(variable_index i, typename var_view_type::type v) + void set_value(value_reference i, typename var_view_type::type v) { assert(!hasRunModifiers_); const auto it = exposedVariables_.find(i); @@ -112,7 +112,7 @@ class set_variable_cache } } - void set_modifier(variable_index i, std::function m) + void set_modifier(value_reference i, std::function m) { assert(!hasRunModifiers_); const auto it = exposedVariables_.find(i); @@ -136,7 +136,7 @@ class set_variable_cache } } - std::pair, gsl::span> modify_and_get() + std::pair, gsl::span> modify_and_get() { if (!hasRunModifiers_) { assert(indexes_.size() == values_.size()); @@ -172,16 +172,16 @@ class set_variable_cache std::ptrdiff_t arrayIndex = -1; }; - std::unordered_map exposedVariables_; + std::unordered_map exposedVariables_; // The modifiers associated with certain variables, and a flag that // specifies whether they have been run on the values currently in // `values_`. - std::unordered_map> modifiers_; + std::unordered_map> modifiers_; bool hasRunModifiers_ = false; // The indexes and values of the variables that will be set next. - std::vector indexes_; + std::vector indexes_; boost::container::vector values_; }; @@ -236,7 +236,7 @@ class slave_simulator::impl } - void expose_for_getting(variable_type type, variable_index index) + void expose_for_getting(variable_type type, value_reference index) { switch (type) { case variable_type::real: @@ -256,27 +256,27 @@ class slave_simulator::impl } } - double get_real(variable_index index) const + double get_real(value_reference index) const { return realGetCache_.get(index); } - int get_integer(variable_index index) const + int get_integer(value_reference index) const { return integerGetCache_.get(index); } - bool get_boolean(variable_index index) const + bool get_boolean(value_reference index) const { return booleanGetCache_.get(index); } - std::string_view get_string(variable_index index) const + std::string_view get_string(value_reference index) const { return stringGetCache_.get(index); } - void expose_for_setting(variable_type type, variable_index index) + void expose_for_setting(variable_type type, value_reference index) { const auto vd = find_variable_description(index, type); switch (type) { @@ -297,28 +297,28 @@ class slave_simulator::impl } } - void set_real(variable_index index, double value) + void set_real(value_reference index, double value) { realSetCache_.set_value(index, value); } - void set_integer(variable_index index, int value) + void set_integer(value_reference index, int value) { integerSetCache_.set_value(index, value); } - void set_boolean(variable_index index, bool value) + void set_boolean(value_reference index, bool value) { booleanSetCache_.set_value(index, value); } - void set_string(variable_index index, std::string_view value) + void set_string(value_reference index, std::string_view value) { stringSetCache_.set_value(index, value); } void set_real_input_modifier( - variable_index index, + value_reference index, std::function modifier) { realSetCache_.set_modifier(index, modifier); @@ -326,7 +326,7 @@ class slave_simulator::impl } void set_integer_input_modifier( - variable_index index, + value_reference index, std::function modifier) { integerSetCache_.set_modifier(index, modifier); @@ -334,7 +334,7 @@ class slave_simulator::impl } void set_boolean_input_modifier( - variable_index index, + value_reference index, std::function modifier) { booleanSetCache_.set_modifier(index, modifier); @@ -342,7 +342,7 @@ class slave_simulator::impl } void set_string_input_modifier( - variable_index index, + value_reference index, std::function modifier) { stringSetCache_.set_modifier(index, modifier); @@ -350,7 +350,7 @@ class slave_simulator::impl } void set_real_output_modifier( - variable_index index, + value_reference index, std::function modifier) { realGetCache_.set_modifier(index, modifier); @@ -358,7 +358,7 @@ class slave_simulator::impl } void set_integer_output_modifier( - variable_index index, + value_reference index, std::function modifier) { integerGetCache_.set_modifier(index, modifier); @@ -366,7 +366,7 @@ class slave_simulator::impl } void set_boolean_output_modifier( - variable_index index, + value_reference index, std::function modifier) { booleanGetCache_.set_modifier(index, modifier); @@ -374,29 +374,29 @@ class slave_simulator::impl } void set_string_output_modifier( - variable_index index, + value_reference index, std::function modifier) { stringGetCache_.set_modifier(index, modifier); set_modified_index(modifiedStringIndexes_, index, modifier ? true : false); } - std::unordered_set& get_modified_real_indexes() + std::unordered_set& get_modified_real_indexes() { return modifiedRealIndexes_; } - std::unordered_set& get_modified_integer_indexes() + std::unordered_set& get_modified_integer_indexes() { return modifiedIntegerIndexes_; } - std::unordered_set& get_modified_boolean_indexes() + std::unordered_set& get_modified_boolean_indexes() { return modifiedBooleanIndexes_; } - std::unordered_set& get_modified_string_indexes() + std::unordered_set& get_modified_string_indexes() { return modifiedStringIndexes_; } @@ -477,7 +477,7 @@ class slave_simulator::impl stringGetCache_.run_modifiers(); } - variable_description find_variable_description(variable_index index, variable_type type) + variable_description find_variable_description(value_reference index, variable_type type) { auto it = std::find_if( modelDescription_.variables.begin(), @@ -493,7 +493,7 @@ class slave_simulator::impl return *it; } - void set_modified_index(std::unordered_set& modifiedIndexes, variable_index& index, bool modifier) + void set_modified_index(std::unordered_set& modifiedIndexes, value_reference& index, bool modifier) { if (modifier) { modifiedIndexes.insert(index); @@ -517,10 +517,10 @@ class slave_simulator::impl set_variable_cache booleanSetCache_; set_variable_cache stringSetCache_; - std::unordered_set modifiedRealIndexes_; - std::unordered_set modifiedIntegerIndexes_; - std::unordered_set modifiedBooleanIndexes_; - std::unordered_set modifiedStringIndexes_; + std::unordered_set modifiedRealIndexes_; + std::unordered_set modifiedIntegerIndexes_; + std::unordered_set modifiedBooleanIndexes_; + std::unordered_set modifiedStringIndexes_; }; @@ -551,137 +551,137 @@ cse::model_description slave_simulator::model_description() const } -void slave_simulator::expose_for_getting(variable_type type, variable_index index) +void slave_simulator::expose_for_getting(variable_type type, value_reference index) { pimpl_->expose_for_getting(type, index); } -double slave_simulator::get_real(variable_index index) const +double slave_simulator::get_real(value_reference index) const { return pimpl_->get_real(index); } -int slave_simulator::get_integer(variable_index index) const +int slave_simulator::get_integer(value_reference index) const { return pimpl_->get_integer(index); } -bool slave_simulator::get_boolean(variable_index index) const +bool slave_simulator::get_boolean(value_reference index) const { return pimpl_->get_boolean(index); } -std::string_view slave_simulator::get_string(variable_index index) const +std::string_view slave_simulator::get_string(value_reference index) const { return pimpl_->get_string(index); } -void slave_simulator::expose_for_setting(variable_type type, variable_index index) +void slave_simulator::expose_for_setting(variable_type type, value_reference index) { pimpl_->expose_for_setting(type, index); } -void slave_simulator::set_real(variable_index index, double value) +void slave_simulator::set_real(value_reference index, double value) { pimpl_->set_real(index, value); } -void slave_simulator::set_integer(variable_index index, int value) +void slave_simulator::set_integer(value_reference index, int value) { pimpl_->set_integer(index, value); } -void slave_simulator::set_boolean(variable_index index, bool value) +void slave_simulator::set_boolean(value_reference index, bool value) { pimpl_->set_boolean(index, value); } -void slave_simulator::set_string(variable_index index, std::string_view value) +void slave_simulator::set_string(value_reference index, std::string_view value) { pimpl_->set_string(index, value); } void slave_simulator::set_real_input_modifier( - variable_index index, + value_reference index, std::function modifier) { pimpl_->set_real_input_modifier(index, modifier); } void slave_simulator::set_integer_input_modifier( - variable_index index, + value_reference index, std::function modifier) { pimpl_->set_integer_input_modifier(index, modifier); } void slave_simulator::set_boolean_input_modifier( - variable_index index, + value_reference index, std::function modifier) { pimpl_->set_boolean_input_modifier(index, modifier); } void slave_simulator::set_string_input_modifier( - variable_index index, + value_reference index, std::function modifier) { pimpl_->set_string_input_modifier(index, modifier); } void slave_simulator::set_real_output_modifier( - variable_index index, + value_reference index, std::function modifier) { pimpl_->set_real_output_modifier(index, modifier); } void slave_simulator::set_integer_output_modifier( - variable_index index, + value_reference index, std::function modifier) { pimpl_->set_integer_output_modifier(index, modifier); } void slave_simulator::set_boolean_output_modifier( - variable_index index, + value_reference index, std::function modifier) { pimpl_->set_boolean_output_modifier(index, modifier); } void slave_simulator::set_string_output_modifier( - variable_index index, + value_reference index, std::function modifier) { pimpl_->set_string_output_modifier(index, modifier); } -std::unordered_set& slave_simulator::get_modified_real_indexes() const +std::unordered_set& slave_simulator::get_modified_real_indexes() const { return pimpl_->get_modified_real_indexes(); } -std::unordered_set& slave_simulator::get_modified_integer_indexes() const +std::unordered_set& slave_simulator::get_modified_integer_indexes() const { return pimpl_->get_modified_integer_indexes(); } -std::unordered_set& slave_simulator::get_modified_boolean_indexes() const +std::unordered_set& slave_simulator::get_modified_boolean_indexes() const { return pimpl_->get_modified_boolean_indexes(); } -std::unordered_set& slave_simulator::get_modified_string_indexes() const +std::unordered_set& slave_simulator::get_modified_string_indexes() const { return pimpl_->get_modified_string_indexes(); } diff --git a/test/c/connections_test.c b/test/c/connections_test.c index 468d6146b..65dc6878c 100644 --- a/test/c/connections_test.c +++ b/test/c/connections_test.c @@ -76,12 +76,12 @@ int main() rc = cse_execution_add_manipulator(execution, manipulator); if (rc < 0) { goto Lerror; } - cse_variable_index realInVar = 0; + cse_value_reference realInVar = 0; const double realInVal = 5.0; rc = cse_manipulator_slave_set_real(manipulator, slaveIndex1, &realInVar, 1, &realInVal); if (rc < 0) { goto Lerror; } - cse_variable_index intInVar = 0; + cse_value_reference intInVar = 0; const int intInVal = 42; rc = cse_manipulator_slave_set_integer(manipulator, slaveIndex1, &intInVar, 1, &intInVal); if (rc < 0) { goto Lerror; } @@ -89,12 +89,12 @@ int main() rc = cse_execution_step(execution, 10); if (rc < 0) { goto Lerror; } - cse_variable_index realOutVar = 0; + cse_value_reference realOutVar = 0; double realOutVal = -1.0; rc = cse_observer_slave_get_real(observer, slaveIndex2, &realOutVar, 1, &realOutVal); if (rc < 0) { goto Lerror; } - cse_variable_index intOutVar = 0; + cse_value_reference intOutVar = 0; int intOutVal = -1; rc = cse_observer_slave_get_integer(observer, slaveIndex2, &intOutVar, 1, &intOutVal); if (rc < 0) { goto Lerror; } diff --git a/test/c/execution_from_ssp_test.c b/test/c/execution_from_ssp_test.c index 81ee4636c..134d510f0 100644 --- a/test/c/execution_from_ssp_test.c +++ b/test/c/execution_from_ssp_test.c @@ -62,7 +62,7 @@ int main() if (0 == strncmp(infos[i].name, "KnuckleBoomCrane", SLAVE_NAME_MAX_SIZE)) { double value = -1; cse_slave_index slaveIndex = infos[i].index; - cse_variable_index varIndex = 2; + cse_value_reference varIndex = 2; rc = cse_observer_slave_get_real(observer, slaveIndex, &varIndex, 1, &value); if (rc < 0) { goto Lerror; diff --git a/test/c/multiple_fmus_execution_test.c b/test/c/multiple_fmus_execution_test.c index 185cea7b6..b81977dea 100644 --- a/test/c/multiple_fmus_execution_test.c +++ b/test/c/multiple_fmus_execution_test.c @@ -81,22 +81,22 @@ int main() if (rc < 0) { goto Lerror; } - cse_variable_index realInVar = 0; + cse_value_reference realInVar = 0; const double realInVal = 5.0; rc = cse_manipulator_slave_set_real(manipulator, slave_index1, &realInVar, 1, &realInVal); if (rc < 0) { goto Lerror; } - cse_variable_index intInVar = 0; + cse_value_reference intInVar = 0; const int intInVal = 42; rc = cse_manipulator_slave_set_integer(manipulator, slave_index1, &intInVar, 1, &intInVal); if (rc < 0) { goto Lerror; } - cse_variable_index boolInVar = 0; + cse_value_reference boolInVar = 0; const bool boolInVal = true; rc = cse_manipulator_slave_set_boolean(manipulator, slave_index1, &boolInVar, 1, &boolInVal); if (rc < 0) { goto Lerror; } - cse_variable_index strInVar = 0; + cse_value_reference strInVar = 0; const char* strInVal = "foo"; rc = cse_manipulator_slave_set_string(manipulator, slave_index1, &strInVar, 1, &strInVal); if (rc < 0) { goto Lerror; } @@ -125,7 +125,7 @@ int main() goto Lfailure; } - cse_variable_index realOutVar = 0; + cse_value_reference realOutVar = 0; double realOutVal = -1.0; rc = cse_observer_slave_get_real(observer1, slave_index1, &realOutVar, 1, &realOutVal); if (rc < 0) { goto Lerror; } @@ -135,7 +135,7 @@ int main() goto Lfailure; } - cse_variable_index intOutVar = 0; + cse_value_reference intOutVar = 0; int intOutVal = 10; rc = cse_observer_slave_get_integer(observer1, slave_index1, &intOutVar, 1, &intOutVal); if (rc < 0) { goto Lerror; } @@ -145,7 +145,7 @@ int main() goto Lfailure; } - cse_variable_index boolOutVar = 0; + cse_value_reference boolOutVar = 0; bool boolOutVal = false; rc = cse_observer_slave_get_boolean(observer1, slave_index1, &boolOutVar, 1, &boolOutVal); if (rc < 0) { goto Lerror; } @@ -155,7 +155,7 @@ int main() goto Lfailure; } - cse_variable_index strOutVar = 0; + cse_value_reference strOutVar = 0; const char* strOutVal; rc = cse_observer_slave_get_string(observer1, slave_index1, &strOutVar, 1, &strOutVal); if (rc < 0) { goto Lerror; } diff --git a/test/c/observer_can_buffer_samples.c b/test/c/observer_can_buffer_samples.c index 7c892739d..43ef8dccb 100644 --- a/test/c/observer_can_buffer_samples.c +++ b/test/c/observer_can_buffer_samples.c @@ -70,7 +70,7 @@ int main() double inputRealSamples[10] = {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0}; int inputIntSamples[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - cse_variable_index index = 0; + cse_value_reference index = 0; rc = cse_observer_start_observing(observer, slaveIndex, CSE_VARIABLE_TYPE_REAL, index); if (rc < 0) { goto Lerror; } diff --git a/test/c/observer_initial_samples_test.c b/test/c/observer_initial_samples_test.c index 71c42e67d..f41ddf4d7 100644 --- a/test/c/observer_initial_samples_test.c +++ b/test/c/observer_initial_samples_test.c @@ -68,7 +68,7 @@ int main() // ===== Getting real before step - cse_variable_index realOutVar = 0; + cse_value_reference realOutVar = 0; double realOutVal = -1.0; rc = cse_observer_slave_get_real(observer, slave_index, &realOutVar, 1, &realOutVal); if (rc < 0) { goto Lerror; } diff --git a/test/c/observer_multiple_slaves_test.c b/test/c/observer_multiple_slaves_test.c index 6395861f1..60ad525d5 100644 --- a/test/c/observer_multiple_slaves_test.c +++ b/test/c/observer_multiple_slaves_test.c @@ -71,12 +71,12 @@ int main() rc = cse_execution_add_manipulator(execution, manipulator); if (rc < 0) { goto Lerror; } - cse_variable_index realInVar = 0; + cse_value_reference realInVar = 0; const double realInVal = 5.0; rc = cse_manipulator_slave_set_real(manipulator, slaveIndex1, &realInVar, 1, &realInVal); if (rc < 0) { goto Lerror; } - cse_variable_index intInVar = 0; + cse_value_reference intInVar = 0; const int intInVal = 42; rc = cse_manipulator_slave_set_integer(manipulator, slaveIndex1, &intInVar, 1, &intInVal); if (rc < 0) { goto Lerror; } @@ -105,12 +105,12 @@ int main() goto Lfailure; } - cse_variable_index realOutVar = 0; + cse_value_reference realOutVar = 0; double realOutVal = -1.0; rc = cse_observer_slave_get_real(observer, slaveIndex1, &realOutVar, 1, &realOutVal); if (rc < 0) { goto Lerror; } - cse_variable_index intOutVar = 0; + cse_value_reference intOutVar = 0; int intOutVal = 10; rc = cse_observer_slave_get_integer(observer, slaveIndex1, &intOutVar, 1, &intOutVal); if (rc < 0) { goto Lerror; } diff --git a/test/c/single_fmu_execution_test.c b/test/c/single_fmu_execution_test.c index e5b5b7c8b..7af2d93b0 100644 --- a/test/c/single_fmu_execution_test.c +++ b/test/c/single_fmu_execution_test.c @@ -92,12 +92,12 @@ int main() if (rc < 0) { goto Lerror; } // ===== Can start/stop execution and get status - cse_variable_index realInVar = 0; + cse_value_reference realInVar = 0; const double realInVal = 5.0; rc = cse_manipulator_slave_set_real(manipulator, slave_index, &realInVar, 1, &realInVal); if (rc < 0) { goto Lerror; } - cse_variable_index intInVar = 0; + cse_value_reference intInVar = 0; const int intInVal = 42; rc = cse_manipulator_slave_set_integer(manipulator, slave_index, &intInVar, 1, &intInVal); if (rc < 0) { goto Lerror; } @@ -136,13 +136,13 @@ int main() goto Lfailure; } - cse_variable_index realOutVar = 0; + cse_value_reference realOutVar = 0; double realOutVal = -1.0; rc = cse_observer_slave_get_real(observer, slave_index, &realOutVar, 1, &realOutVal); if (rc < 0) { goto Lerror; } - cse_variable_index intOutVar = 0; + cse_value_reference intOutVar = 0; int intOutVal = 10; rc = cse_observer_slave_get_integer(observer, slave_index, &intOutVar, 1, &intOutVal); if (rc < 0) { goto Lerror; } diff --git a/test/c/time_series_observer_test.c b/test/c/time_series_observer_test.c index ba843dab6..aed7f2a75 100644 --- a/test/c/time_series_observer_test.c +++ b/test/c/time_series_observer_test.c @@ -61,7 +61,7 @@ int main() double inputRealSamples[10] = {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0}; int inputIntSamples[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - cse_variable_index index = 0; + cse_value_reference index = 0; rc = cse_observer_start_observing(observer, 0, CSE_VARIABLE_TYPE_INTEGER, index); if (rc < 0) { goto Lerror; } diff --git a/test/cpp/async_slave_mockup_test.cpp b/test/cpp/async_slave_mockup_test.cpp index d8515801b..169c1082b 100644 --- a/test/cpp/async_slave_mockup_test.cpp +++ b/test/cpp/async_slave_mockup_test.cpp @@ -74,7 +74,7 @@ void run_test(std::shared_ptr (*make_async)(std::shared_ptr> getResults; for (const auto& slave : asyncSlaves) { - const cse::variable_index realOutIndex = 0; + const cse::value_reference realOutIndex = 0; getResults.push_back( slave->get_variables({&realOutIndex, 1}, {}, {}, {})); } @@ -90,7 +90,7 @@ void run_test(std::shared_ptr (*make_async)(std::shared_ptr> setResults; for (int i = 0; i < numSlaves; ++i) { - const cse::variable_index realInIndex = 1; + const cse::value_reference realInIndex = 1; setResults.push_back( asyncSlaves[i]->set_variables( {&realInIndex, 1}, {&values[i], 1}, diff --git a/test/cpp/async_slave_unittest.cpp b/test/cpp/async_slave_unittest.cpp index 8b7d7527e..381d237e8 100644 --- a/test/cpp/async_slave_unittest.cpp +++ b/test/cpp/async_slave_unittest.cpp @@ -23,19 +23,19 @@ class test_slave : public slave void end_simulation() override {} step_result do_step(time_point, duration) override { return step_result::complete; } - void get_real_variables(gsl::span, gsl::span) const override {} - void get_integer_variables(gsl::span, gsl::span) const override {} - void get_boolean_variables(gsl::span, gsl::span) const override {} - void get_string_variables(gsl::span, gsl::span) const override {} + void get_real_variables(gsl::span, gsl::span) const override {} + void get_integer_variables(gsl::span, gsl::span) const override {} + void get_boolean_variables(gsl::span, gsl::span) const override {} + void get_string_variables(gsl::span, gsl::span) const override {} void set_real_variables( - gsl::span, + gsl::span, gsl::span values) override { if (!values.empty() && values[0] == 0.0) throw nonfatal_bad_value("real"); } void set_integer_variables( - gsl::span variables, + gsl::span variables, gsl::span values) override { if (!values.empty()) { @@ -44,13 +44,13 @@ class test_slave : public slave } } void set_boolean_variables( - gsl::span, + gsl::span, gsl::span values) override { if (!values.empty() && !values[0]) throw nonfatal_bad_value("boolean"); } void set_string_variables( - gsl::span, + gsl::span, gsl::span values) override { if (!values.empty() && values[0].empty()) throw nonfatal_bad_value("string"); @@ -75,13 +75,13 @@ void test_error_handling_2(async_slave& as) f2.get(); BOOST_REQUIRE(as.state() == slave_state::simulation); - variable_index realIndex = 0; + value_reference realIndex = 0; double realValue = 1.0; - variable_index integerIndex = 0; + value_reference integerIndex = 0; int integerValue = 1; - variable_index booleanIndex = 0; + value_reference booleanIndex = 0; bool booleanValue = true; - variable_index stringIndex = 0; + value_reference stringIndex = 0; std::string stringValue = "foo"; auto f3 = as.set_variables( gsl::make_span(&realIndex, 1), gsl::make_span(&realValue, 1), diff --git a/test/cpp/fixed_step_algorithm_test.cpp b/test/cpp/fixed_step_algorithm_test.cpp index dedc2978e..181e1a64d 100644 --- a/test/cpp/fixed_step_algorithm_test.cpp +++ b/test/cpp/fixed_step_algorithm_test.cpp @@ -40,8 +40,8 @@ int main() auto observer = std::make_shared(); execution.add_observer(observer); - const cse::variable_index realOutIndex = 0; - const cse::variable_index realInIndex = 1; + const cse::value_reference realOutIndex = 0; + const cse::value_reference realInIndex = 1; // Add slaves to it diff --git a/test/cpp/fmi_v1_fmu_unittest.cpp b/test/cpp/fmi_v1_fmu_unittest.cpp index 78316d3e0..8bf38093e 100644 --- a/test/cpp/fmi_v1_fmu_unittest.cpp +++ b/test/cpp/fmi_v1_fmu_unittest.cpp @@ -29,7 +29,7 @@ void run_tests(std::shared_ptr fmu) BOOST_TEST(d->version == "0.3"); BOOST_TEST(std::static_pointer_cast(fmu)->fmilib_handle() != nullptr); - cse::variable_index + cse::value_reference realIn = 0, integerIn = 0, booleanIn = 0, stringIn = 0, realOut = 0, integerOut = 0, booleanOut = 0, stringOut = 0; diff --git a/test/cpp/last_value_observer_test.cpp b/test/cpp/last_value_observer_test.cpp index 097249210..3b69e8dc4 100644 --- a/test/cpp/last_value_observer_test.cpp +++ b/test/cpp/last_value_observer_test.cpp @@ -44,8 +44,8 @@ int main() execution.step(); - const cse::variable_index outIndex = 0; - const cse::variable_index inIndex = 1; + const cse::value_reference outIndex = 0; + const cse::value_reference inIndex = 1; double realInValue = -1.0; double realOutValue = -1.0; diff --git a/test/cpp/mock_slave.hpp b/test/cpp/mock_slave.hpp index cf20b724b..84f2a8a30 100644 --- a/test/cpp/mock_slave.hpp +++ b/test/cpp/mock_slave.hpp @@ -85,7 +85,7 @@ class mock_slave : public cse::slave } void get_real_variables( - gsl::span variables, + gsl::span variables, gsl::span values) const override { for (int i = 0; i < variables.size(); ++i) { @@ -100,7 +100,7 @@ class mock_slave : public cse::slave } void get_integer_variables( - gsl::span variables, + gsl::span variables, gsl::span values) const override { for (int i = 0; i < variables.size(); ++i) { @@ -115,7 +115,7 @@ class mock_slave : public cse::slave } void get_boolean_variables( - gsl::span variables, + gsl::span variables, gsl::span values) const override { for (int i = 0; i < variables.size(); ++i) { @@ -130,7 +130,7 @@ class mock_slave : public cse::slave } void get_string_variables( - gsl::span variables, + gsl::span variables, gsl::span values) const override { for (int i = 0; i < variables.size(); ++i) { @@ -145,7 +145,7 @@ class mock_slave : public cse::slave } void set_real_variables( - gsl::span variables, + gsl::span variables, gsl::span values) override { for (int i = 0; i < variables.size(); ++i) { @@ -158,7 +158,7 @@ class mock_slave : public cse::slave } void set_integer_variables( - gsl::span variables, + gsl::span variables, gsl::span values) override { for (int i = 0; i < variables.size(); ++i) { @@ -171,7 +171,7 @@ class mock_slave : public cse::slave } void set_boolean_variables( - gsl::span variables, + gsl::span variables, gsl::span values) override { for (int i = 0; i < variables.size(); ++i) { @@ -184,7 +184,7 @@ class mock_slave : public cse::slave } void set_string_variables( - gsl::span variables, + gsl::span variables, gsl::span values) override { for (int i = 0; i < variables.size(); ++i) { diff --git a/test/cpp/multi_connections_test.cpp b/test/cpp/multi_connections_test.cpp index bcc1bf7fe..84477c998 100644 --- a/test/cpp/multi_connections_test.cpp +++ b/test/cpp/multi_connections_test.cpp @@ -36,8 +36,8 @@ int main() auto observer = std::make_shared(); execution.add_observer(observer); - const cse::variable_index realOutIndex = 0; - const cse::variable_index realInIndex = 1; + const cse::value_reference realOutIndex = 0; + const cse::value_reference realInIndex = 1; // Add slaves to it for (int i = 0; i < numSlaves; ++i) { diff --git a/test/cpp/multi_fixed_step_algorithm_test.cpp b/test/cpp/multi_fixed_step_algorithm_test.cpp index 4bbc87594..b447fc0f8 100644 --- a/test/cpp/multi_fixed_step_algorithm_test.cpp +++ b/test/cpp/multi_fixed_step_algorithm_test.cpp @@ -34,7 +34,7 @@ class set_logging_mock_slave : public mock_slave } void set_real_variables( - gsl::span variables, + gsl::span variables, gsl::span values) override { if (!variables.empty()) setRealLog_.insert(time_); @@ -42,7 +42,7 @@ class set_logging_mock_slave : public mock_slave } void set_integer_variables( - gsl::span variables, + gsl::span variables, gsl::span values) override { if (!variables.empty()) setIntegerLog_.insert(time_); @@ -79,10 +79,10 @@ int main() auto observer = std::make_shared(); execution.add_observer(observer); - const cse::variable_index realOutIndex = 0; - const cse::variable_index realInIndex = 1; - const cse::variable_index integerOutIndex = 0; - const cse::variable_index integerInIndex = 1; + const cse::value_reference realOutIndex = 0; + const cse::value_reference realInIndex = 1; + const cse::value_reference integerOutIndex = 0; + const cse::value_reference integerInIndex = 1; double v = 0.0; auto slave0 = std::make_shared([&v](double /*x*/) { return ++v; }); diff --git a/test/cpp/ssp_parser_test.cpp b/test/cpp/ssp_parser_test.cpp index 5c882fd7c..905ad2342 100644 --- a/test/cpp/ssp_parser_test.cpp +++ b/test/cpp/ssp_parser_test.cpp @@ -36,13 +36,13 @@ int main() cse::simulator_index i = simulator_map.at("KnuckleBoomCrane").index; double realValue = -1.0; - cse::variable_index index = cse::find_variable(simulator_map.at("KnuckleBoomCrane").description, "Spring_Joint.k").index; + cse::value_reference index = cse::find_variable(simulator_map.at("KnuckleBoomCrane").description, "Spring_Joint.k").index; obs->get_real(i, gsl::make_span(&index, 1), gsl::make_span(&realValue, 1)); double magicNumberFromSsdFile = 0.005; REQUIRE(std::fabs(realValue - magicNumberFromSsdFile) < 1e-9); - cse::variable_index index2 = cse::find_variable(simulator_map.at("KnuckleBoomCrane").description, "mt0_init").index; + cse::value_reference index2 = cse::find_variable(simulator_map.at("KnuckleBoomCrane").description, "mt0_init").index; obs->get_real(i, gsl::make_span(&index2, 1), gsl::make_span(&realValue, 1)); magicNumberFromSsdFile = 69.0; diff --git a/test/cpp/synchronized_xy_series_test.cpp b/test/cpp/synchronized_xy_series_test.cpp index 8b822db31..8f5bda97c 100644 --- a/test/cpp/synchronized_xy_series_test.cpp +++ b/test/cpp/synchronized_xy_series_test.cpp @@ -55,7 +55,7 @@ int main() REQUIRE(simResult.get()); const int numSamples = 20; - const cse::variable_index varIndex = 0; + const cse::value_reference varIndex = 0; double realValues1[numSamples]; double realValues2[numSamples]; diff --git a/test/cpp/time_series_observer_test.cpp b/test/cpp/time_series_observer_test.cpp index 9e5b52805..b5b5f5397 100644 --- a/test/cpp/time_series_observer_test.cpp +++ b/test/cpp/time_series_observer_test.cpp @@ -55,7 +55,7 @@ int main() REQUIRE(simResult.get()); const int numSamples = 15; - const cse::variable_index varIndex = 0; + const cse::value_reference varIndex = 0; double realValues[numSamples]; cse::step_number steps[numSamples]; cse::time_point times[numSamples]; diff --git a/test/cpp/trend_buffer_test.cpp b/test/cpp/trend_buffer_test.cpp index 31437d9ef..86d26bdcc 100644 --- a/test/cpp/trend_buffer_test.cpp +++ b/test/cpp/trend_buffer_test.cpp @@ -36,8 +36,8 @@ int main() auto observer = std::make_shared(); execution.add_observer(observer); - const cse::variable_index realOutIndex = 0; - const cse::variable_index realInIndex = 1; + const cse::value_reference realOutIndex = 0; + const cse::value_reference realInIndex = 1; // Add slaves to it for (int i = 0; i < numSlaves; ++i) { From fb464ade46acce6af2658c90beb75cf104036761 Mon Sep 17 00:00:00 2001 From: eidekrist Date: Tue, 27 Aug 2019 15:47:27 +0200 Subject: [PATCH 2/3] #265 Rename local variables --- include/cse.h | 24 +- include/cse/algorithm.hpp | 66 ++-- include/cse/execution.hpp | 10 +- include/cse/model.hpp | 4 +- include/cse/scenario.hpp | 2 +- src/c/cse.cpp | 16 +- src/cpp/algorithm.cpp | 22 +- src/cpp/cse/fmuproxy/fmuproxy_helper.hpp | 2 +- src/cpp/cse/slave_simulator.hpp | 44 +-- src/cpp/execution.cpp | 30 +- src/cpp/fmuproxy/service_types.cpp | 4 +- src/cpp/observer/file_observer.cpp | 58 ++-- src/cpp/observer/slave_value_provider.cpp | 10 +- src/cpp/observer/time_series_observer.cpp | 24 +- src/cpp/override_manipulator.cpp | 6 +- src/cpp/scenario_parser.cpp | 2 +- src/cpp/slave_simulator.cpp | 324 +++++++++---------- src/cpp/ssp_parser.cpp | 14 +- test/c/observer_can_buffer_samples.c | 14 +- test/c/time_series_observer_test.c | 20 +- test/c/variable_metadata_test.c | 8 +- test/cpp/async_slave_unittest.cpp | 2 +- test/cpp/fixed_step_algorithm_test.cpp | 16 +- test/cpp/fmi_v1_fmu_unittest.cpp | 16 +- test/cpp/fmi_v2_fmu_unittest.cpp | 4 +- test/cpp/mock_slave.hpp | 16 +- test/cpp/monitor_modified_variables_test.cpp | 2 +- test/cpp/ssp_parser_test.cpp | 8 +- 28 files changed, 372 insertions(+), 396 deletions(-) diff --git a/include/cse.h b/include/cse.h index 97dfbb958..770cbec52 100644 --- a/include/cse.h +++ b/include/cse.h @@ -334,7 +334,7 @@ typedef struct /// The name of the variable. char name[SLAVE_NAME_MAX_SIZE]; /// The value reference. - cse_value_reference index; + cse_value_reference reference; /// The variable type. cse_variable_type type; /// The variable causality. @@ -430,7 +430,7 @@ typedef struct cse_manipulator_s cse_manipulator; * The slave. * \param [in] variables * A pointer to an array of length `nv` that contains the (slave-specific) - * indices of variables to set. + * value references of variables to set. * \param [in] nv * The length of the `variables` and `values` arrays. * \param [out] values @@ -456,7 +456,7 @@ int cse_manipulator_slave_set_real( * The slave. * \param [in] variables * A pointer to an array of length `nv` that contains the (slave-specific) - * indices of variables to set. + * value references of variables to set. * \param [in] nv * The length of the `variables` and `values` arrays. * \param [out] values @@ -482,7 +482,7 @@ int cse_manipulator_slave_set_integer( * The slave. * \param [in] variables * A pointer to an array of length `nv` that contains the (slave-specific) - * indices of variables to set. + * value references of variables to set. * \param [in] nv * The length of the `variables` and `values` arrays. * \param [out] values @@ -508,7 +508,7 @@ int cse_manipulator_slave_set_boolean( * The slave. * \param [in] variables * A pointer to an array of length `nv` that contains the (slave-specific) - * indices of variables to set. + * value references of variables to set. * \param [in] nv * The length of the `variables` and `values` arrays. * \param [out] values @@ -536,7 +536,7 @@ int cse_manipulator_slave_set_string( * The variable type. * \param [in] variables * A pointer to an array of length `nv` that contains the (slave-specific) - * indices of variables to reset. + * value references of variables to reset. * \param [in] nv * The length of the `variables` array. * @@ -559,7 +559,7 @@ int cse_manipulator_slave_reset( * The slave. * \param [in] variables * A pointer to an array of length `nv` that contains the (slave-specific) - * indices of variables to retrieve. + * value references of variables to retrieve. * \param [in] nv * The length of the `variables` and `values` arrays. * \param [out] values @@ -585,7 +585,7 @@ int cse_observer_slave_get_real( * The slave index. * \param [in] variables * A pointer to an array of length `nv` that contains the (slave-specific) - * indices of variables to retrieve. + * value references of variables to retrieve. * \param [in] nv * The length of the `variables` and `values` arrays. * \param [out] values @@ -611,7 +611,7 @@ int cse_observer_slave_get_integer( * The slave index. * \param [in] variables * A pointer to an array of length `nv` that contains the (slave-specific) - * indices of variables to retrieve. + * value references of variables to retrieve. * \param [in] nv * The length of the `variables` and `values` arrays. * \param [out] values @@ -637,7 +637,7 @@ int cse_observer_slave_get_boolean( * The slave index. * \param [in] variables * A pointer to an array of length `nv` that contains the (slave-specific) - * indices of variables to retrieve. + * value references of variables to retrieve. * \param [in] nv * The length of the `variables` and `values` arrays. * \param [out] values @@ -864,10 +864,10 @@ cse_observer* cse_time_series_observer_create(); cse_observer* cse_buffered_time_series_observer_create(size_t bufferSize); /// Start observing a variable with a `time_series_observer`. -int cse_observer_start_observing(cse_observer* observer, cse_slave_index slave, cse_variable_type type, cse_value_reference index); +int cse_observer_start_observing(cse_observer* observer, cse_slave_index slave, cse_variable_type type, cse_value_reference reference); /// Stop observing a variable with a `time_series_observer`. -int cse_observer_stop_observing(cse_observer* observer, cse_slave_index slave, cse_variable_type type, cse_value_reference index); +int cse_observer_stop_observing(cse_observer* observer, cse_slave_index slave, cse_variable_type type, cse_value_reference reference); /// Destroys an observer int cse_observer_destroy(cse_observer* observer); diff --git a/include/cse/algorithm.hpp b/include/cse/algorithm.hpp index 85c800775..f137b2571 100644 --- a/include/cse/algorithm.hpp +++ b/include/cse/algorithm.hpp @@ -52,35 +52,35 @@ class simulator : public observable * Calling this function more than once for the same variable has no * effect. */ - virtual void expose_for_setting(variable_type type, value_reference index) = 0; + virtual void expose_for_setting(variable_type type, value_reference reference) = 0; /** * Sets the value of a real variable. * * The variable must previously have been exposed with `expose_for_setting()`. */ - virtual void set_real(value_reference index, double value) = 0; + virtual void set_real(value_reference reference, double value) = 0; /** * Sets the value of an integer variable. * * The variable must previously have been exposed with `expose_for_setting()`. */ - virtual void set_integer(value_reference index, int value) = 0; + virtual void set_integer(value_reference reference, int value) = 0; /** * Sets the value of a boolean variable. * * The variable must previously have been exposed with `expose_for_setting()`. */ - virtual void set_boolean(value_reference index, bool value) = 0; + virtual void set_boolean(value_reference reference, bool value) = 0; /** * Sets the value of a string variable. * * The variable must previously have been exposed with `expose_for_setting()`. */ - virtual void set_string(value_reference index, std::string_view value) = 0; + virtual void set_string(value_reference reference, std::string_view value) = 0; /** * Sets a modifier for the value of a real input variable. @@ -88,7 +88,7 @@ class simulator : public observable * The variable must previously have been exposed with `expose_for_setting()`. */ virtual void set_real_input_modifier( - value_reference index, + value_reference reference, std::function modifier) = 0; /** @@ -97,7 +97,7 @@ class simulator : public observable * The variable must previously have been exposed with `expose_for_setting()`. */ virtual void set_integer_input_modifier( - value_reference index, + value_reference reference, std::function modifier) = 0; /** @@ -106,7 +106,7 @@ class simulator : public observable * The variable must previously have been exposed with `expose_for_setting()`. */ virtual void set_boolean_input_modifier( - value_reference index, + value_reference reference, std::function modifier) = 0; /** @@ -115,7 +115,7 @@ class simulator : public observable * The variable must previously have been exposed with `expose_for_setting()`. */ virtual void set_string_input_modifier( - value_reference index, + value_reference reference, std::function modifier) = 0; /** @@ -124,7 +124,7 @@ class simulator : public observable * The variable must previously have been exposed with `expose_for_setting()`. */ virtual void set_real_output_modifier( - value_reference index, + value_reference reference, std::function modifier) = 0; /** @@ -133,7 +133,7 @@ class simulator : public observable * The variable must previously have been exposed with `expose_for_setting()`. */ virtual void set_integer_output_modifier( - value_reference index, + value_reference reference, std::function modifier) = 0; /** @@ -142,7 +142,7 @@ class simulator : public observable * The variable must previously have been exposed with `expose_for_setting()`. */ virtual void set_boolean_output_modifier( - value_reference index, + value_reference reference, std::function modifier) = 0; /** @@ -151,7 +151,7 @@ class simulator : public observable * The variable must previously have been exposed with `expose_for_setting()`. */ virtual void set_string_output_modifier( - value_reference index, + value_reference reference, std::function modifier) = 0; /** @@ -181,41 +181,17 @@ class simulator : public observable std::optional stopTime, std::optional relativeTolerance) = 0; - /** - * - * Returns all value_reference of real type with an active modifier. - * - * @return modifiedRealIndexes - * Unordered set of all value_reference that currently have an active modifier. - */ - virtual const std::unordered_set& get_modified_real_indexes() const = 0; + /// Returns all value references of real type that currently have an active modifier. + virtual const std::unordered_set& get_modified_real_references() const = 0; - /** - * - * Returns all value_references of integer type with an active modifier. - * - * @return modifiedIntegerIndexes - * Unordered set of all value_references that currently have an active modifier. - */ - virtual const std::unordered_set& get_modified_integer_indexes() const = 0; + /// Returns all value references of integer type that currently have an active modifier. + virtual const std::unordered_set& get_modified_integer_references() const = 0; - /** - * - * Returns all value_references of boolean type with an active modifier. - * - * @return modifiedBooleanIndexes - * Unordered set of all value_references that currently have an active modifier. - */ - virtual const std::unordered_set& get_modified_boolean_indexes() const = 0; + /// Returns all value references of boolean type that currently have an active modifier. + virtual const std::unordered_set& get_modified_boolean_references() const = 0; - /** - * - * Returns all value_references of string type with an active modifier. - * - * @return modifiedStringIndexes - * Unordered set of all value_references that currently have an active modifier. - */ - virtual const std::unordered_set& get_modified_string_indexes() const = 0; + /// Returns all value references of string type that currently have an active modifier. + virtual const std::unordered_set& get_modified_string_references() const = 0; /** * Updates the simulator with new input values and makes it calculate diff --git a/include/cse/execution.hpp b/include/cse/execution.hpp index c3d304745..1b6c668ba 100644 --- a/include/cse/execution.hpp +++ b/include/cse/execution.hpp @@ -34,14 +34,14 @@ struct variable_id /// The variable data type. variable_type type; - /// The variable index. - value_reference index; + /// The variable value reference. + value_reference reference; }; /// Equality operator for `variable_id`. inline bool operator==(const variable_id& a, const variable_id& b) noexcept { - return a.simulator == b.simulator && a.type == b.type && a.index == b.index; + return a.simulator == b.simulator && a.type == b.type && a.reference == b.reference; } /// Inequality operator for `variable_id`. @@ -55,7 +55,7 @@ inline std::ostream& operator<<(std::ostream& stream, variable_id v) { return stream << "(simulator " << v.simulator << ", type " << v.type - << ", variable " << v.index << ")"; + << ", variable " << v.reference << ")"; } } // namespace cse @@ -72,7 +72,7 @@ class hash std::size_t seed = 0; boost::hash_combine(seed, v.simulator); boost::hash_combine(seed, v.type); - boost::hash_combine(seed, v.index); + boost::hash_combine(seed, v.reference); return seed; } }; diff --git a/include/cse/model.hpp b/include/cse/model.hpp index aa6502b42..2ca7e308a 100644 --- a/include/cse/model.hpp +++ b/include/cse/model.hpp @@ -272,7 +272,7 @@ struct variable_description * variables of the same type have the same value reference, they will * be considered as aliases of each other. */ - value_reference index; + value_reference reference; /// The variable's data type. variable_type type; @@ -314,7 +314,7 @@ struct model_description const variable_description find_variable(const model_description& description, const std::string& variable_name); /// Getter for returning a variable description. -const variable_description find_variable(const model_description& description, variable_type type, value_reference index); +const variable_description find_variable(const model_description& description, variable_type type, value_reference reference); /// Getter for returning all variable descriptions of the given datatype. const std::vector find_variables_of_type(const model_description& description, variable_type type); diff --git a/include/cse/scenario.hpp b/include/cse/scenario.hpp index ae3504cda..fc3e54679 100644 --- a/include/cse/scenario.hpp +++ b/include/cse/scenario.hpp @@ -48,7 +48,7 @@ struct variable_action { /// The simulator index. simulator_index simulator; - /// The variable index. + /// The variable value reference. value_reference variable; /// The modification to be done to the variable's value. std::variant< diff --git a/src/c/cse.cpp b/src/c/cse.cpp index 118218b08..82415ea28 100644 --- a/src/c/cse.cpp +++ b/src/c/cse.cpp @@ -224,7 +224,7 @@ int cse_slave_get_num_variables(cse_execution* execution, cse_slave_index slave) return static_cast(entry.second.description.variables.size()); } } - set_last_error(CSE_ERRC_OUT_OF_RANGE, "Invalid slave index"); + set_last_error(CSE_ERRC_OUT_OF_RANGE, "Invalid slave reference"); return -1; } @@ -288,7 +288,7 @@ cse_variable_type to_c_variable_type(const cse::variable_type& vt) void translate_variable_description(const cse::variable_description& vd, cse_variable_description& cvd) { std::strncpy(cvd.name, vd.name.c_str(), SLAVE_NAME_MAX_SIZE); - cvd.index = vd.index; + cvd.reference = vd.reference; cvd.type = to_c_variable_type(vd.type); cvd.causality = to_variable_causality(vd.causality); cvd.variability = to_variable_variability(vd.variability); @@ -309,7 +309,7 @@ int cse_slave_get_variables(cse_execution* execution, cse_slave_index slave, cse } std::ostringstream oss; - oss << "Slave with index " << slave + oss << "Slave with reference " << slave << " was not found among loaded slaves."; throw std::invalid_argument(oss.str()); } catch (...) { @@ -812,14 +812,14 @@ cse::variable_type to_cpp_variable_type(cse_variable_type type) } } -int cse_observer_start_observing(cse_observer* observer, cse_slave_index slave, cse_variable_type type, cse_value_reference index) +int cse_observer_start_observing(cse_observer* observer, cse_slave_index slave, cse_variable_type type, cse_value_reference reference) { try { const auto timeSeriesObserver = std::dynamic_pointer_cast(observer->cpp_observer); if (!timeSeriesObserver) { throw std::invalid_argument("Invalid observer! The provided observer must be a time_series_observer."); } - const auto variableId = cse::variable_id{slave, to_cpp_variable_type(type), index}; + const auto variableId = cse::variable_id{slave, to_cpp_variable_type(type), reference}; timeSeriesObserver->start_observing(variableId); return success; } catch (...) { @@ -828,14 +828,14 @@ int cse_observer_start_observing(cse_observer* observer, cse_slave_index slave, } } -int cse_observer_stop_observing(cse_observer* observer, cse_slave_index slave, cse_variable_type type, cse_value_reference index) +int cse_observer_stop_observing(cse_observer* observer, cse_slave_index slave, cse_variable_type type, cse_value_reference reference) { try { const auto timeSeriesObserver = std::dynamic_pointer_cast(observer->cpp_observer); if (!timeSeriesObserver) { throw std::invalid_argument("Invalid observer! The provided observer must be a time_series_observer."); } - const auto variableId = cse::variable_id{slave, to_cpp_variable_type(type), index}; + const auto variableId = cse::variable_id{slave, to_cpp_variable_type(type), reference}; timeSeriesObserver->stop_observing(variableId); return success; } catch (...) { @@ -1070,7 +1070,7 @@ int cse_get_modified_variables(cse_execution* execution, cse_variable_id ids[], for (; counter < std::min(numVariables, modified_vars.size()); counter++) { ids[counter].slave_index = modified_vars[counter].simulator; ids[counter].type = to_c_variable_type(modified_vars[counter].type); - ids[counter].value_reference = modified_vars[counter].index; + ids[counter].value_reference = modified_vars[counter].reference; } } diff --git a/src/cpp/algorithm.cpp b/src/cpp/algorithm.cpp index bf0a4ab38..cf7b01330 100644 --- a/src/cpp/algorithm.cpp +++ b/src/cpp/algorithm.cpp @@ -66,12 +66,12 @@ class fixed_step_algorithm::impl { for (const auto& source : c->get_sources()) { auto& simInfo = find_simulator(source.simulator); - simInfo.sim->expose_for_getting(source.type, source.index); + simInfo.sim->expose_for_getting(source.type, source.reference); simInfo.outgoingConnections[source].push_back(c); } for (const auto& destination : c->get_destinations()) { auto& simInfo = find_simulator(destination.simulator); - simInfo.sim->expose_for_setting(destination.type, destination.index); + simInfo.sim->expose_for_setting(destination.type, destination.reference); simInfo.incomingConnections[destination] = c; } } @@ -235,7 +235,7 @@ class fixed_step_algorithm::impl auto sim = simulators_.find(i); if (sim == simulators_.end()) { std::ostringstream oss; - oss << "Cannot find simulator with index " << i; + oss << "Cannot find simulator with reference " << i; throw std::out_of_range(oss.str()); } return sim->second; @@ -247,16 +247,16 @@ class fixed_step_algorithm::impl for (const auto& c : connections) { switch (sourceVar.type) { case variable_type::real: - c->set_source_value(sourceVar, simulators_.at(i).sim->get_real(sourceVar.index)); + c->set_source_value(sourceVar, simulators_.at(i).sim->get_real(sourceVar.reference)); break; case variable_type::integer: - c->set_source_value(sourceVar, simulators_.at(i).sim->get_integer(sourceVar.index)); + c->set_source_value(sourceVar, simulators_.at(i).sim->get_integer(sourceVar.reference)); break; case variable_type::boolean: - c->set_source_value(sourceVar, simulators_.at(i).sim->get_boolean(sourceVar.index)); + c->set_source_value(sourceVar, simulators_.at(i).sim->get_boolean(sourceVar.reference)); break; case variable_type::string: - c->set_source_value(sourceVar, simulators_.at(i).sim->get_string(sourceVar.index)); + c->set_source_value(sourceVar, simulators_.at(i).sim->get_string(sourceVar.reference)); break; default: CSE_PANIC(); @@ -282,16 +282,16 @@ class fixed_step_algorithm::impl if (decimation_factor_match(destVar, conn->get_sources())) { switch (destVar.type) { case variable_type::real: - simulators_.at(i).sim->set_real(destVar.index, std::get(conn->get_destination_value(destVar))); + simulators_.at(i).sim->set_real(destVar.reference, std::get(conn->get_destination_value(destVar))); break; case variable_type::integer: - simulators_.at(i).sim->set_integer(destVar.index, std::get(conn->get_destination_value(destVar))); + simulators_.at(i).sim->set_integer(destVar.reference, std::get(conn->get_destination_value(destVar))); break; case variable_type::boolean: - simulators_.at(i).sim->set_boolean(destVar.index, std::get(conn->get_destination_value(destVar))); + simulators_.at(i).sim->set_boolean(destVar.reference, std::get(conn->get_destination_value(destVar))); break; case variable_type::string: - simulators_.at(i).sim->set_string(destVar.index, std::get(conn->get_destination_value(destVar))); + simulators_.at(i).sim->set_string(destVar.reference, std::get(conn->get_destination_value(destVar))); break; default: CSE_PANIC(); diff --git a/src/cpp/cse/fmuproxy/fmuproxy_helper.hpp b/src/cpp/cse/fmuproxy/fmuproxy_helper.hpp index 00d82a3c3..b672d4b4d 100644 --- a/src/cpp/cse/fmuproxy/fmuproxy_helper.hpp +++ b/src/cpp/cse/fmuproxy/fmuproxy_helper.hpp @@ -70,7 +70,7 @@ inline cse::variable_description convert(const fmuproxy::thrift::ScalarVariable& { cse::variable_description var; var.name = v.name; - var.index = (cse::value_reference)v.value_reference; + var.reference = (cse::value_reference)v.value_reference; var.causality = parse_causality(v.causality); var.variability = parse_variability(v.variability); var.type = get_type(v); diff --git a/src/cpp/cse/slave_simulator.hpp b/src/cpp/cse/slave_simulator.hpp index d7e9d0976..a826e5955 100644 --- a/src/cpp/cse/slave_simulator.hpp +++ b/src/cpp/cse/slave_simulator.hpp @@ -33,48 +33,48 @@ class slave_simulator : public simulator std::string name() const override; cse::model_description model_description() const override; - void expose_for_getting(variable_type type, value_reference index) override; - double get_real(value_reference index) const override; - int get_integer(value_reference index) const override; - bool get_boolean(value_reference index) const override; - std::string_view get_string(value_reference index) const override; + void expose_for_getting(variable_type type, value_reference ref) override; + double get_real(value_reference reference) const override; + int get_integer(value_reference reference) const override; + bool get_boolean(value_reference reference) const override; + std::string_view get_string(value_reference reference) const override; // `simulator` methods - void expose_for_setting(variable_type type, value_reference index) override; - void set_real(value_reference index, double value) override; - void set_integer(value_reference index, int value) override; - void set_boolean(value_reference index, bool value) override; - void set_string(value_reference index, std::string_view value) override; + void expose_for_setting(variable_type type, value_reference ref) override; + void set_real(value_reference reference, double value) override; + void set_integer(value_reference reference, int value) override; + void set_boolean(value_reference reference, bool value) override; + void set_string(value_reference reference, std::string_view value) override; void set_real_input_modifier( - value_reference index, + value_reference reference, std::function modifier) override; void set_integer_input_modifier( - value_reference index, + value_reference reference, std::function modifier) override; void set_boolean_input_modifier( - value_reference index, + value_reference reference, std::function modifier) override; void set_string_input_modifier( - value_reference index, + value_reference reference, std::function modifier) override; void set_real_output_modifier( - value_reference index, + value_reference reference, std::function modifier) override; void set_integer_output_modifier( - value_reference index, + value_reference reference, std::function modifier) override; void set_boolean_output_modifier( - value_reference index, + value_reference reference, std::function modifier) override; void set_string_output_modifier( - value_reference index, + value_reference reference, std::function modifier) override; - std::unordered_set& get_modified_real_indexes() const override; - std::unordered_set& get_modified_integer_indexes() const override; - std::unordered_set& get_modified_boolean_indexes() const override; - std::unordered_set& get_modified_string_indexes() const override; + std::unordered_set& get_modified_real_references() const override; + std::unordered_set& get_modified_integer_references() const override; + std::unordered_set& get_modified_boolean_references() const override; + std::unordered_set& get_modified_string_references() const override; boost::fibers::future setup( time_point startTime, diff --git a/src/cpp/execution.cpp b/src/cpp/execution.cpp index 2f7ad3fdf..5ab99f31a 100644 --- a/src/cpp/execution.cpp +++ b/src/cpp/execution.cpp @@ -204,28 +204,28 @@ class execution::impl auto index = 0; for (const auto& sim : simulators_) { - const auto& realIndexes = sim->get_modified_real_indexes(); - const auto& intIndexes = sim->get_modified_integer_indexes(); - const auto& boolIndexes = sim->get_modified_boolean_indexes(); - const auto& stringIndexes = sim->get_modified_string_indexes(); + const auto& realRefs = sim->get_modified_real_references(); + const auto& integerRefs = sim->get_modified_integer_references(); + const auto& booleanRefs = sim->get_modified_boolean_references(); + const auto& stringRefs = sim->get_modified_string_references(); - for (const auto& varIndex : realIndexes) { - variable_id var = {index, variable_type::real, varIndex}; + for (const auto& ref : realRefs) { + variable_id var = {index, variable_type::real, ref}; modifiedVariables.push_back(var); } - for (const auto& varIndex : intIndexes) { - variable_id var = {index, variable_type::integer, varIndex}; + for (const auto& ref : integerRefs) { + variable_id var = {index, variable_type::integer, ref}; modifiedVariables.push_back(var); } - for (const auto& varIndex : boolIndexes) { - variable_id var = {index, variable_type::boolean, varIndex}; + for (const auto& ref : booleanRefs) { + variable_id var = {index, variable_type::boolean, ref}; modifiedVariables.push_back(var); } - for (const auto& varIndex : stringIndexes) { - variable_id var = {index, variable_type::string, varIndex}; + for (const auto& ref : stringRefs) { + variable_id var = {index, variable_type::string, ref}; modifiedVariables.push_back(var); } @@ -278,13 +278,13 @@ class execution::impl const auto it = std::find_if( variables.begin(), variables.end(), - [=](const auto& var) { return var.causality == causality && var.type == variable.type && var.index == variable.index; }); + [=](const auto& var) { return var.causality == causality && var.type == variable.type && var.reference == variable.reference; }); if (it == variables.end()) { std::ostringstream oss; - oss << "Cannot find variable with index " << variable.index + oss << "Cannot find variable with reference " << variable.reference << ", causality " << cse::to_text(causality) << " and type " << cse::to_text(variable.type) - << " for simulator with index " << variable.simulator + << " for simulator with reference " << variable.simulator << " and name " << simulators_.at(variable.simulator)->name(); throw std::out_of_range(oss.str()); } diff --git a/src/cpp/fmuproxy/service_types.cpp b/src/cpp/fmuproxy/service_types.cpp index 80d62f801..0799427c7 100644 --- a/src/cpp/fmuproxy/service_types.cpp +++ b/src/cpp/fmuproxy/service_types.cpp @@ -1192,7 +1192,7 @@ uint32_t Unknown::write(::apache::thrift::protocol::TProtocol* oprot) const { ::apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); xfer += oprot->writeStructBegin("Unknown"); - xfer += oprot->writeFieldBegin("index", ::apache::thrift::protocol::T_I32, 1); + xfer += oprot->writeFieldBegin("reference", ::apache::thrift::protocol::T_I32, 1); xfer += oprot->writeI32(this->index); xfer += oprot->writeFieldEnd(); @@ -1249,7 +1249,7 @@ Unknown& Unknown::operator=(const Unknown& other27) { void Unknown::printTo(std::ostream& out) const { using ::apache::thrift::to_string; out << "Unknown("; - out << "index=" << to_string(index); + out << "reference=" << to_string(index); out << ", " << "dependencies=" << to_string(dependencies); out << ", " << "dependencies_kind=" << to_string(dependencies_kind); out << ")"; diff --git a/src/cpp/observer/file_observer.cpp b/src/cpp/observer/file_observer.cpp index 3442238c8..0cba39e1f 100644 --- a/src/cpp/observer/file_observer.cpp +++ b/src/cpp/observer/file_observer.cpp @@ -47,21 +47,21 @@ class file_observer::slave_value_writer { if (++counter_ % decimationFactor_ == 0) { - if (!realIndexes_.empty()) realSamples_[timeStep].reserve(realIndexes_.size()); - if (!intIndexes_.empty()) intSamples_[timeStep].reserve(intIndexes_.size()); - if (!boolIndexes_.empty()) boolSamples_[timeStep].reserve(boolIndexes_.size()); - if (!stringIndexes_.empty()) stringSamples_[timeStep].reserve(stringIndexes_.size()); + if (!realReferences_.empty()) realSamples_[timeStep].reserve(realReferences_.size()); + if (!intReferences_.empty()) intSamples_[timeStep].reserve(intReferences_.size()); + if (!boolReferences_.empty()) boolSamples_[timeStep].reserve(boolReferences_.size()); + if (!stringReferences_.empty()) stringSamples_[timeStep].reserve(stringReferences_.size()); - for (const auto idx : realIndexes_) { + for (const auto idx : realReferences_) { realSamples_[timeStep].push_back(observable_->get_real(idx)); } - for (const auto idx : intIndexes_) { + for (const auto idx : intReferences_) { intSamples_[timeStep].push_back(observable_->get_integer(idx)); } - for (const auto idx : boolIndexes_) { + for (const auto idx : boolReferences_) { boolSamples_[timeStep].push_back(observable_->get_boolean(idx)); } - for (const auto idx : stringIndexes_) { + for (const auto idx : stringReferences_) { stringSamples_[timeStep].push_back(observable_->get_string(idx)); } timeSamples_[timeStep] = to_double_time_point(currentTime); @@ -96,19 +96,19 @@ class file_observer::slave_value_writer for (const auto& vd : observable_->model_description().variables) { if (vd.causality != variable_causality::local) { - observable_->expose_for_getting(vd.type, vd.index); + observable_->expose_for_getting(vd.type, vd.reference); if (vd.type == variable_type::real) { - realIndexes_.push_back(vd.index); + realReferences_.push_back(vd.reference); } if (vd.type == variable_type::integer) { - intIndexes_.push_back(vd.index); + intReferences_.push_back(vd.reference); } if (vd.type == variable_type::boolean) { - boolIndexes_.push_back(vd.index); + boolReferences_.push_back(vd.reference); } if (vd.type == variable_type::string) { - stringIndexes_.push_back(vd.index); + stringReferences_.push_back(vd.reference); } switch (vd.type) { @@ -138,26 +138,26 @@ class file_observer::slave_value_writer void initialize_config(time_point currentTime) { for (const auto& variable : loggableRealVariables_) { - realIndexes_.push_back(variable.index); - observable_->expose_for_getting(variable_type::real, variable.index); + realReferences_.push_back(variable.reference); + observable_->expose_for_getting(variable_type::real, variable.reference); realVars_.push_back(variable); } for (const auto& variable : loggableIntVariables_) { - intIndexes_.push_back(variable.index); - observable_->expose_for_getting(variable_type::integer, variable.index); + intReferences_.push_back(variable.reference); + observable_->expose_for_getting(variable_type::integer, variable.reference); intVars_.push_back(variable); } for (const auto& variable : loggableBoolVariables_) { - boolIndexes_.push_back(variable.index); - observable_->expose_for_getting(variable_type::boolean, variable.index); + boolReferences_.push_back(variable.reference); + observable_->expose_for_getting(variable_type::boolean, variable.reference); boolVars_.push_back(variable); } for (const auto& variable : loggableStringVariables_) { - stringIndexes_.push_back(variable.index); - observable_->expose_for_getting(variable_type::string, variable.index); + stringReferences_.push_back(variable.reference); + observable_->expose_for_getting(variable_type::string, variable.reference); stringVars_.push_back(variable); } @@ -177,16 +177,16 @@ class file_observer::slave_value_writer ss_ << "Time,StepCount"; for (const auto& vd : realVars_) { - ss_ << "," << vd.name << " [" << vd.index << " " << vd.type << " " << vd.causality << "]"; + ss_ << "," << vd.name << " [" << vd.reference << " " << vd.type << " " << vd.causality << "]"; } for (const auto& vd : intVars_) { - ss_ << "," << vd.name << " [" << vd.index << " " << vd.type << " " << vd.causality << "]"; + ss_ << "," << vd.name << " [" << vd.reference << " " << vd.type << " " << vd.causality << "]"; } for (const auto& vd : boolVars_) { - ss_ << "," << vd.name << " [" << vd.index << " " << vd.type << " " << vd.causality << "]"; + ss_ << "," << vd.name << " [" << vd.reference << " " << vd.type << " " << vd.causality << "]"; } for (const auto& vd : stringVars_) { - ss_ << "," << vd.name << " [" << vd.index << " " << vd.type << " " << vd.causality << "]"; + ss_ << "," << vd.name << " [" << vd.reference << " " << vd.type << " " << vd.causality << "]"; } ss_ << std::endl; @@ -228,10 +228,10 @@ class file_observer::slave_value_writer std::map> intSamples_; std::map> boolSamples_; std::map> stringSamples_; - std::vector realIndexes_; - std::vector intIndexes_; - std::vector boolIndexes_; - std::vector stringIndexes_; + std::vector realReferences_; + std::vector intReferences_; + std::vector boolReferences_; + std::vector stringReferences_; std::map timeSamples_; std::vector realVars_; std::vector intVars_; diff --git a/src/cpp/observer/slave_value_provider.cpp b/src/cpp/observer/slave_value_provider.cpp index 12286ca4a..53abec889 100644 --- a/src/cpp/observer/slave_value_provider.cpp +++ b/src/cpp/observer/slave_value_provider.cpp @@ -31,19 +31,19 @@ slave_value_provider::slave_value_provider(observable* observable) : observable_(observable) { for (const auto& vd : observable->model_description().variables) { - observable->expose_for_getting(vd.type, vd.index); + observable->expose_for_getting(vd.type, vd.reference); switch (vd.type) { case cse::variable_type::real: - realSamples_[vd.index] = double(); + realSamples_[vd.reference] = double(); break; case cse::variable_type::integer: - intSamples_[vd.index] = int(); + intSamples_[vd.reference] = int(); break; case cse::variable_type::boolean: - boolSamples_[vd.index] = bool(); + boolSamples_[vd.reference] = bool(); break; case cse::variable_type::string: - stringSamples_[vd.index] = std::string(); + stringSamples_[vd.reference] = std::string(); break; default: CSE_PANIC(); diff --git a/src/cpp/observer/time_series_observer.cpp b/src/cpp/observer/time_series_observer.cpp index ff4521c42..6819b5e58 100644 --- a/src/cpp/observer/time_series_observer.cpp +++ b/src/cpp/observer/time_series_observer.cpp @@ -88,40 +88,40 @@ class time_series_observer::single_slave_observer adjustIfFull(timeSamples_, bufSize_); } - void start_observing(variable_type type, value_reference index) + void start_observing(variable_type type, value_reference reference) { std::lock_guard lock(lock_); switch (type) { case variable_type::real: - realSamples_[index] = std::map(); - observable_->expose_for_getting(type, index); + realSamples_[reference] = std::map(); + observable_->expose_for_getting(type, reference); break; case variable_type::integer: - intSamples_[index] = std::map(); - observable_->expose_for_getting(type, index); + intSamples_[reference] = std::map(); + observable_->expose_for_getting(type, reference); break; default: std::ostringstream oss; oss << "No support for observing variable with type " << type - << " and index " << index; + << " and reference " << reference; throw std::invalid_argument(oss.str()); } } - void stop_observing(variable_type type, value_reference index) + void stop_observing(variable_type type, value_reference reference) { std::lock_guard lock(lock_); switch (type) { case variable_type::real: - realSamples_.erase(index); + realSamples_.erase(reference); break; case variable_type::integer: - intSamples_.erase(index); + intSamples_.erase(reference); break; default: std::ostringstream oss; oss << "Could not stop observing variable with type " << type - << " and index " << index; + << " and reference " << reference; throw std::invalid_argument(oss.str()); } } @@ -244,12 +244,12 @@ void time_series_observer::simulator_step_complete( void time_series_observer::start_observing(variable_id id) { - slaveObservers_.at(id.simulator)->start_observing(id.type, id.index); + slaveObservers_.at(id.simulator)->start_observing(id.type, id.reference); } void time_series_observer::stop_observing(variable_id id) { - slaveObservers_.at(id.simulator)->stop_observing(id.type, id.index); + slaveObservers_.at(id.simulator)->stop_observing(id.type, id.reference); } std::size_t time_series_observer::get_real_samples( diff --git a/src/cpp/override_manipulator.cpp b/src/cpp/override_manipulator.cpp index 0146b6b1f..9080eee0b 100644 --- a/src/cpp/override_manipulator.cpp +++ b/src/cpp/override_manipulator.cpp @@ -23,15 +23,15 @@ struct visitor : Functors... cse::variable_causality find_variable_causality( const std::vector& variables, const cse::variable_type type, - const cse::value_reference index) + const cse::value_reference reference) { for (const auto& vd : variables) { - if ((vd.index == index) && (vd.type == type)) { + if ((vd.reference == reference) && (vd.type == type)) { return vd.causality; } } std::ostringstream oss; - oss << "Can't find variable with index: " << index + oss << "Can't find variable with reference: " << reference << " and type: " << to_text(type); throw std::invalid_argument(oss.str()); } diff --git a/src/cpp/scenario_parser.cpp b/src/cpp/scenario_parser.cpp index 0654d4205..2730b97b4 100644 --- a/src/cpp/scenario_parser.cpp +++ b/src/cpp/scenario_parser.cpp @@ -194,7 +194,7 @@ scenario::scenario parse_scenario( auto mode = specified_or_default(event, "action", defaultOpts.action); bool isInput = is_input(var.causality); - scenario::variable_action a = generate_action(event, mode, index, var.type, isInput, var.index); + scenario::variable_action a = generate_action(event, mode, index, var.type, isInput, var.reference); events.emplace_back(scenario::event{time, a}); } diff --git a/src/cpp/slave_simulator.cpp b/src/cpp/slave_simulator.cpp index b9cca250c..f83aaf2b6 100644 --- a/src/cpp/slave_simulator.cpp +++ b/src/cpp/slave_simulator.cpp @@ -34,38 +34,38 @@ struct var_view_type template struct get_variable_cache { - std::vector indexes; + std::vector references; boost::container::vector originalValues; boost::container::vector modifiedValues; std::vector> modifiers; std::unordered_map indexMapping; - void expose(value_reference i) + void expose(value_reference r) { - if (indexMapping.count(i)) return; - indexes.push_back(i); + if (indexMapping.count(r)) return; + references.push_back(r); originalValues.push_back(T()); // TODO: Use start value from model description modifiedValues.push_back(T()); modifiers.emplace_back(); - indexMapping[i] = indexes.size() - 1; + indexMapping[r] = references.size() - 1; } - typename var_view_type::type get(value_reference i) const + typename var_view_type::type get(value_reference r) const { - const auto it = indexMapping.find(i); + const auto it = indexMapping.find(r); if (it != indexMapping.end()) { return modifiedValues[it->second]; } else { std::ostringstream oss; - oss << "Variable with index " << i + oss << "Variable with reference " << r << " not found in exposed variables. Variables must be exposed before calling get()"; throw std::out_of_range(oss.str()); } } - void set_modifier(value_reference i, std::function m) + void set_modifier(value_reference r, std::function m) { - modifiers[indexMapping[i]] = m; + modifiers[indexMapping[r]] = m; } void run_modifiers() @@ -85,78 +85,78 @@ template class set_variable_cache { public: - void expose(value_reference i, T startValue) + void expose(value_reference r, T startValue) { - exposedVariables_.emplace(i, exposed_variable{startValue, -1}); + exposedVariables_.emplace(r, exposed_variable{startValue, -1}); } - void set_value(value_reference i, typename var_view_type::type v) + void set_value(value_reference r, typename var_view_type::type v) { assert(!hasRunModifiers_); - const auto it = exposedVariables_.find(i); + const auto it = exposedVariables_.find(r); if (it == exposedVariables_.end()) { std::ostringstream oss; - oss << "Variable with index " << i + oss << "Variable with value reference " << r << " not found in exposed variables. Variables must be exposed before calling set_value()"; throw std::out_of_range(oss.str()); } it->second.lastValue = v; if (it->second.arrayIndex < 0) { - it->second.arrayIndex = indexes_.size(); - assert(indexes_.size() == values_.size()); - indexes_.emplace_back(i); + it->second.arrayIndex = references_.size(); + assert(references_.size() == values_.size()); + references_.emplace_back(r); values_.emplace_back(v); } else { - assert(indexes_[it->second.arrayIndex] == i); + assert(references_[it->second.arrayIndex] == r); values_[it->second.arrayIndex] = v; } } - void set_modifier(value_reference i, std::function m) + void set_modifier(value_reference r, std::function m) { assert(!hasRunModifiers_); - const auto it = exposedVariables_.find(i); + const auto it = exposedVariables_.find(r); if (it == exposedVariables_.end()) { std::ostringstream oss; - oss << "Variable with index " << i + oss << "Variable with value reference " << r << " not found in exposed variables. Variables must be exposed before calling set_modifier()"; throw std::out_of_range(oss.str()); } if (it->second.arrayIndex < 0) { // Ensure that the simulator receives an updated value. - it->second.arrayIndex = indexes_.size(); - assert(indexes_.size() == values_.size()); - indexes_.emplace_back(i); + it->second.arrayIndex = references_.size(); + assert(references_.size() == values_.size()); + references_.emplace_back(r); values_.emplace_back(it->second.lastValue); } if (m) { - modifiers_[i] = m; + modifiers_[r] = m; } else { - modifiers_.erase(i); + modifiers_.erase(r); } } std::pair, gsl::span> modify_and_get() { if (!hasRunModifiers_) { - assert(indexes_.size() == values_.size()); - for (std::size_t i = 0; i < indexes_.size(); ++i) { - const auto iterator = modifiers_.find(indexes_[i]); + assert(references_.size() == values_.size()); + for (std::size_t i = 0; i < references_.size(); ++i) { + const auto iterator = modifiers_.find(references_[i]); if (iterator != modifiers_.end()) { values_[i] = iterator->second(values_[i]); } } hasRunModifiers_ = true; } - return std::pair(gsl::make_span(indexes_), gsl::make_span(values_)); + return std::pair(gsl::make_span(references_), gsl::make_span(values_)); } void reset() { - for (auto index : indexes_) { - exposedVariables_.at(index).arrayIndex = -1; + for (auto ref : references_) { + exposedVariables_.at(ref).arrayIndex = -1; } - indexes_.clear(); + references_.clear(); values_.clear(); hasRunModifiers_ = false; } @@ -167,7 +167,7 @@ class set_variable_cache // The last set value of the variable. T lastValue = T(); - // The variable's index in the `indexes_` and `values_` arrays, or + // The variable's reference in the `references_` and `values_` arrays, or // -1 if it hasn't been added to them yet. std::ptrdiff_t arrayIndex = -1; }; @@ -180,8 +180,8 @@ class set_variable_cache std::unordered_map> modifiers_; bool hasRunModifiers_ = false; - // The indexes and values of the variables that will be set next. - std::vector indexes_; + // The references and values of the variables that will be set next. + std::vector references_; boost::container::vector values_; }; @@ -236,169 +236,169 @@ class slave_simulator::impl } - void expose_for_getting(variable_type type, value_reference index) + void expose_for_getting(variable_type type, value_reference ref) { switch (type) { case variable_type::real: - realGetCache_.expose(index); + realGetCache_.expose(ref); break; case variable_type::integer: - integerGetCache_.expose(index); + integerGetCache_.expose(ref); break; case variable_type::boolean: - booleanGetCache_.expose(index); + booleanGetCache_.expose(ref); break; case variable_type::string: - stringGetCache_.expose(index); + stringGetCache_.expose(ref); break; case variable_type::enumeration: CSE_PANIC(); } } - double get_real(value_reference index) const + double get_real(value_reference ref) const { - return realGetCache_.get(index); + return realGetCache_.get(ref); } - int get_integer(value_reference index) const + int get_integer(value_reference ref) const { - return integerGetCache_.get(index); + return integerGetCache_.get(ref); } - bool get_boolean(value_reference index) const + bool get_boolean(value_reference ref) const { - return booleanGetCache_.get(index); + return booleanGetCache_.get(ref); } - std::string_view get_string(value_reference index) const + std::string_view get_string(value_reference ref) const { - return stringGetCache_.get(index); + return stringGetCache_.get(ref); } - void expose_for_setting(variable_type type, value_reference index) + void expose_for_setting(variable_type type, value_reference ref) { - const auto vd = find_variable_description(index, type); + const auto vd = find_variable_description(ref, type); switch (type) { case variable_type::real: - realSetCache_.expose(index, get_start_value(vd)); + realSetCache_.expose(ref, get_start_value(vd)); break; case variable_type::integer: - integerSetCache_.expose(index, get_start_value(vd)); + integerSetCache_.expose(ref, get_start_value(vd)); break; case variable_type::boolean: - booleanSetCache_.expose(index, get_start_value(vd)); + booleanSetCache_.expose(ref, get_start_value(vd)); break; case variable_type::string: - stringSetCache_.expose(index, get_start_value(vd)); + stringSetCache_.expose(ref, get_start_value(vd)); break; case variable_type::enumeration: CSE_PANIC(); } } - void set_real(value_reference index, double value) + void set_real(value_reference ref, double value) { - realSetCache_.set_value(index, value); + realSetCache_.set_value(ref, value); } - void set_integer(value_reference index, int value) + void set_integer(value_reference ref, int value) { - integerSetCache_.set_value(index, value); + integerSetCache_.set_value(ref, value); } - void set_boolean(value_reference index, bool value) + void set_boolean(value_reference ref, bool value) { - booleanSetCache_.set_value(index, value); + booleanSetCache_.set_value(ref, value); } - void set_string(value_reference index, std::string_view value) + void set_string(value_reference ref, std::string_view value) { - stringSetCache_.set_value(index, value); + stringSetCache_.set_value(ref, value); } void set_real_input_modifier( - value_reference index, + value_reference ref, std::function modifier) { - realSetCache_.set_modifier(index, modifier); - set_modified_index(modifiedRealIndexes_, index, modifier ? true : false); + realSetCache_.set_modifier(ref, modifier); + set_modified_reference(modifiedRealReferences_, ref, modifier ? true : false); } void set_integer_input_modifier( - value_reference index, + value_reference ref, std::function modifier) { - integerSetCache_.set_modifier(index, modifier); - set_modified_index(modifiedIntegerIndexes_, index, modifier ? true : false); + integerSetCache_.set_modifier(ref, modifier); + set_modified_reference(modifiedIntegerReferences_, ref, modifier ? true : false); } void set_boolean_input_modifier( - value_reference index, + value_reference ref, std::function modifier) { - booleanSetCache_.set_modifier(index, modifier); - set_modified_index(modifiedBooleanIndexes_, index, modifier ? true : false); + booleanSetCache_.set_modifier(ref, modifier); + set_modified_reference(modifiedBooleanReferences_, ref, modifier ? true : false); } void set_string_input_modifier( - value_reference index, + value_reference ref, std::function modifier) { - stringSetCache_.set_modifier(index, modifier); - set_modified_index(modifiedStringIndexes_, index, modifier ? true : false); + stringSetCache_.set_modifier(ref, modifier); + set_modified_reference(modifiedStringReferences_, ref, modifier ? true : false); } void set_real_output_modifier( - value_reference index, + value_reference ref, std::function modifier) { - realGetCache_.set_modifier(index, modifier); - set_modified_index(modifiedRealIndexes_, index, modifier ? true : false); + realGetCache_.set_modifier(ref, modifier); + set_modified_reference(modifiedRealReferences_, ref, modifier ? true : false); } void set_integer_output_modifier( - value_reference index, + value_reference ref, std::function modifier) { - integerGetCache_.set_modifier(index, modifier); - set_modified_index(modifiedIntegerIndexes_, index, modifier ? true : false); + integerGetCache_.set_modifier(ref, modifier); + set_modified_reference(modifiedIntegerReferences_, ref, modifier ? true : false); } void set_boolean_output_modifier( - value_reference index, + value_reference ref, std::function modifier) { - booleanGetCache_.set_modifier(index, modifier); - set_modified_index(modifiedBooleanIndexes_, index, modifier ? true : false); + booleanGetCache_.set_modifier(ref, modifier); + set_modified_reference(modifiedBooleanReferences_, ref, modifier ? true : false); } void set_string_output_modifier( - value_reference index, + value_reference ref, std::function modifier) { - stringGetCache_.set_modifier(index, modifier); - set_modified_index(modifiedStringIndexes_, index, modifier ? true : false); + stringGetCache_.set_modifier(ref, modifier); + set_modified_reference(modifiedStringReferences_, ref, modifier ? true : false); } - std::unordered_set& get_modified_real_indexes() + std::unordered_set& get_modified_real_references() { - return modifiedRealIndexes_; + return modifiedRealReferences_; } - std::unordered_set& get_modified_integer_indexes() + std::unordered_set& get_modified_integer_references() { - return modifiedIntegerIndexes_; + return modifiedIntegerReferences_; } - std::unordered_set& get_modified_boolean_indexes() + std::unordered_set& get_modified_boolean_references() { - return modifiedBooleanIndexes_; + return modifiedBooleanReferences_; } - std::unordered_set& get_modified_string_indexes() + std::unordered_set& get_modified_string_references() { - return modifiedStringIndexes_; + return modifiedStringReferences_; } boost::fibers::future setup( @@ -439,18 +439,18 @@ class slave_simulator::impl private: void set_variables() { - const auto [realIndexes, realValues] = realSetCache_.modify_and_get(); - const auto [integerIndexes, integerValues] = integerSetCache_.modify_and_get(); - const auto [booleanIndexes, booleanValues] = booleanSetCache_.modify_and_get(); - const auto [stringIndexes, stringValues] = stringSetCache_.modify_and_get(); + const auto [realRefs, realValues] = realSetCache_.modify_and_get(); + const auto [integerRefs, integerValues] = integerSetCache_.modify_and_get(); + const auto [booleanRefs, booleanValues] = booleanSetCache_.modify_and_get(); + const auto [stringRefs, stringValues] = stringSetCache_.modify_and_get(); slave_->set_variables( - gsl::make_span(realIndexes), + gsl::make_span(realRefs), gsl::make_span(realValues), - gsl::make_span(integerIndexes), + gsl::make_span(integerRefs), gsl::make_span(integerValues), - gsl::make_span(booleanIndexes), + gsl::make_span(booleanRefs), gsl::make_span(booleanValues), - gsl::make_span(stringIndexes), + gsl::make_span(stringRefs), gsl::make_span(stringValues)) .get(); realSetCache_.reset(); @@ -462,10 +462,10 @@ class slave_simulator::impl void get_variables() { const auto values = slave_->get_variables( - gsl::make_span(realGetCache_.indexes), - gsl::make_span(integerGetCache_.indexes), - gsl::make_span(booleanGetCache_.indexes), - gsl::make_span(stringGetCache_.indexes)) + gsl::make_span(realGetCache_.references), + gsl::make_span(integerGetCache_.references), + gsl::make_span(booleanGetCache_.references), + gsl::make_span(stringGetCache_.references)) .get(); copy_contents(values.real, realGetCache_.originalValues); copy_contents(values.integer, integerGetCache_.originalValues); @@ -477,15 +477,15 @@ class slave_simulator::impl stringGetCache_.run_modifiers(); } - variable_description find_variable_description(value_reference index, variable_type type) + variable_description find_variable_description(value_reference ref, variable_type type) { auto it = std::find_if( modelDescription_.variables.begin(), modelDescription_.variables.end(), - [type, index](const auto& vd) { return vd.type == type && vd.index == index; }); + [type, ref](const auto& vd) { return vd.type == type && vd.reference == ref; }); if (it == modelDescription_.variables.end()) { std::ostringstream oss; - oss << "Variable with index " << index + oss << "Variable with value reference " << ref << " and type " << type << " not found in model description for " << name_; throw std::out_of_range(oss.str()); @@ -493,12 +493,12 @@ class slave_simulator::impl return *it; } - void set_modified_index(std::unordered_set& modifiedIndexes, value_reference& index, bool modifier) + void set_modified_reference(std::unordered_set& modifiedRefs, value_reference& ref, bool modifier) { if (modifier) { - modifiedIndexes.insert(index); + modifiedRefs.insert(ref); } else { - modifiedIndexes.erase(index); + modifiedRefs.erase(ref); } } @@ -517,10 +517,10 @@ class slave_simulator::impl set_variable_cache booleanSetCache_; set_variable_cache stringSetCache_; - std::unordered_set modifiedRealIndexes_; - std::unordered_set modifiedIntegerIndexes_; - std::unordered_set modifiedBooleanIndexes_; - std::unordered_set modifiedStringIndexes_; + std::unordered_set modifiedRealReferences_; + std::unordered_set modifiedIntegerReferences_; + std::unordered_set modifiedBooleanReferences_; + std::unordered_set modifiedStringReferences_; }; @@ -551,139 +551,139 @@ cse::model_description slave_simulator::model_description() const } -void slave_simulator::expose_for_getting(variable_type type, value_reference index) +void slave_simulator::expose_for_getting(variable_type type, value_reference ref) { - pimpl_->expose_for_getting(type, index); + pimpl_->expose_for_getting(type, ref); } -double slave_simulator::get_real(value_reference index) const +double slave_simulator::get_real(value_reference ref) const { - return pimpl_->get_real(index); + return pimpl_->get_real(ref); } -int slave_simulator::get_integer(value_reference index) const +int slave_simulator::get_integer(value_reference ref) const { - return pimpl_->get_integer(index); + return pimpl_->get_integer(ref); } -bool slave_simulator::get_boolean(value_reference index) const +bool slave_simulator::get_boolean(value_reference ref) const { - return pimpl_->get_boolean(index); + return pimpl_->get_boolean(ref); } -std::string_view slave_simulator::get_string(value_reference index) const +std::string_view slave_simulator::get_string(value_reference ref) const { - return pimpl_->get_string(index); + return pimpl_->get_string(ref); } -void slave_simulator::expose_for_setting(variable_type type, value_reference index) +void slave_simulator::expose_for_setting(variable_type type, value_reference ref) { - pimpl_->expose_for_setting(type, index); + pimpl_->expose_for_setting(type, ref); } -void slave_simulator::set_real(value_reference index, double value) +void slave_simulator::set_real(value_reference ref, double value) { - pimpl_->set_real(index, value); + pimpl_->set_real(ref, value); } -void slave_simulator::set_integer(value_reference index, int value) +void slave_simulator::set_integer(value_reference ref, int value) { - pimpl_->set_integer(index, value); + pimpl_->set_integer(ref, value); } -void slave_simulator::set_boolean(value_reference index, bool value) +void slave_simulator::set_boolean(value_reference ref, bool value) { - pimpl_->set_boolean(index, value); + pimpl_->set_boolean(ref, value); } -void slave_simulator::set_string(value_reference index, std::string_view value) +void slave_simulator::set_string(value_reference ref, std::string_view value) { - pimpl_->set_string(index, value); + pimpl_->set_string(ref, value); } void slave_simulator::set_real_input_modifier( - value_reference index, + value_reference ref, std::function modifier) { - pimpl_->set_real_input_modifier(index, modifier); + pimpl_->set_real_input_modifier(ref, modifier); } void slave_simulator::set_integer_input_modifier( - value_reference index, + value_reference ref, std::function modifier) { - pimpl_->set_integer_input_modifier(index, modifier); + pimpl_->set_integer_input_modifier(ref, modifier); } void slave_simulator::set_boolean_input_modifier( - value_reference index, + value_reference ref, std::function modifier) { - pimpl_->set_boolean_input_modifier(index, modifier); + pimpl_->set_boolean_input_modifier(ref, modifier); } void slave_simulator::set_string_input_modifier( - value_reference index, + value_reference ref, std::function modifier) { - pimpl_->set_string_input_modifier(index, modifier); + pimpl_->set_string_input_modifier(ref, modifier); } void slave_simulator::set_real_output_modifier( - value_reference index, + value_reference ref, std::function modifier) { - pimpl_->set_real_output_modifier(index, modifier); + pimpl_->set_real_output_modifier(ref, modifier); } void slave_simulator::set_integer_output_modifier( - value_reference index, + value_reference ref, std::function modifier) { - pimpl_->set_integer_output_modifier(index, modifier); + pimpl_->set_integer_output_modifier(ref, modifier); } void slave_simulator::set_boolean_output_modifier( - value_reference index, + value_reference ref, std::function modifier) { - pimpl_->set_boolean_output_modifier(index, modifier); + pimpl_->set_boolean_output_modifier(ref, modifier); } void slave_simulator::set_string_output_modifier( - value_reference index, + value_reference ref, std::function modifier) { - pimpl_->set_string_output_modifier(index, modifier); + pimpl_->set_string_output_modifier(ref, modifier); } -std::unordered_set& slave_simulator::get_modified_real_indexes() const +std::unordered_set& slave_simulator::get_modified_real_references() const { - return pimpl_->get_modified_real_indexes(); + return pimpl_->get_modified_real_references(); } -std::unordered_set& slave_simulator::get_modified_integer_indexes() const +std::unordered_set& slave_simulator::get_modified_integer_references() const { - return pimpl_->get_modified_integer_indexes(); + return pimpl_->get_modified_integer_references(); } -std::unordered_set& slave_simulator::get_modified_boolean_indexes() const +std::unordered_set& slave_simulator::get_modified_boolean_references() const { - return pimpl_->get_modified_boolean_indexes(); + return pimpl_->get_modified_boolean_references(); } -std::unordered_set& slave_simulator::get_modified_string_indexes() const +std::unordered_set& slave_simulator::get_modified_string_references() const { - return pimpl_->get_modified_string_indexes(); + return pimpl_->get_modified_string_references(); } boost::fibers::future slave_simulator::setup( diff --git a/src/cpp/ssp_parser.cpp b/src/cpp/ssp_parser.cpp index ce0ae9283..f479a24a6 100644 --- a/src/cpp/ssp_parser.cpp +++ b/src/cpp/ssp_parser.cpp @@ -289,21 +289,21 @@ std::pair load_ssp( } for (const auto& p : component.parameters) { - auto varIndex = find_variable(*model->description(), p.name).index; + auto reference = find_variable(*model->description(), p.name).reference; BOOST_LOG_SEV(log::logger(), log::info) << "Initializing variable " << component.name << ":" << p.name << " with value " << streamer{p.value}; switch (p.type) { case variable_type::real: - execution.set_real_initial_value(index, varIndex, std::get(p.value)); + execution.set_real_initial_value(index, reference, std::get(p.value)); break; case variable_type::integer: - execution.set_integer_initial_value(index, varIndex, std::get(p.value)); + execution.set_integer_initial_value(index, reference, std::get(p.value)); break; case variable_type::boolean: - execution.set_boolean_initial_value(index, varIndex, std::get(p.value)); + execution.set_boolean_initial_value(index, reference, std::get(p.value)); break; case variable_type::string: - execution.set_string_initial_value(index, varIndex, std::get(p.value)); + execution.set_string_initial_value(index, reference, std::get(p.value)); break; default: throw error(make_error_code(errc::unsupported_feature), "Variable type not supported yet"); @@ -314,11 +314,11 @@ std::pair load_ssp( for (const auto& connection : parser.get_connections()) { cse::variable_id output = {slaves[connection.startElement].index, slaves[connection.startElement].variables[connection.startConnector].type, - slaves[connection.startElement].variables[connection.startConnector].index}; + slaves[connection.startElement].variables[connection.startConnector].reference}; cse::variable_id input = {slaves[connection.endElement].index, slaves[connection.endElement].variables[connection.endConnector].type, - slaves[connection.endElement].variables[connection.endConnector].index}; + slaves[connection.endElement].variables[connection.endConnector].reference}; const auto c = std::make_shared(output, input); execution.add_connection(c); diff --git a/test/c/observer_can_buffer_samples.c b/test/c/observer_can_buffer_samples.c index 43ef8dccb..7aa8ca02c 100644 --- a/test/c/observer_can_buffer_samples.c +++ b/test/c/observer_can_buffer_samples.c @@ -70,17 +70,17 @@ int main() double inputRealSamples[10] = {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0}; int inputIntSamples[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - cse_value_reference index = 0; + cse_value_reference reference = 0; - rc = cse_observer_start_observing(observer, slaveIndex, CSE_VARIABLE_TYPE_REAL, index); + rc = cse_observer_start_observing(observer, slaveIndex, CSE_VARIABLE_TYPE_REAL, reference); if (rc < 0) { goto Lerror; } - rc = cse_observer_start_observing(observer, slaveIndex, CSE_VARIABLE_TYPE_INTEGER, index); + rc = cse_observer_start_observing(observer, slaveIndex, CSE_VARIABLE_TYPE_INTEGER, reference); if (rc < 0) { goto Lerror; } for (int i = 0; i < 10; i++) { - rc = cse_manipulator_slave_set_real(manipulator, 0, &index, 1, &inputRealSamples[i]); + rc = cse_manipulator_slave_set_real(manipulator, 0, &reference, 1, &inputRealSamples[i]); if (rc < 0) { goto Lerror; } - rc = cse_manipulator_slave_set_integer(manipulator, 0, &index, 1, &inputIntSamples[i]); + rc = cse_manipulator_slave_set_integer(manipulator, 0, &reference, 1, &inputIntSamples[i]); if (rc < 0) { goto Lerror; } rc = cse_execution_step(execution, 1); if (rc < 0) { goto Lerror; } @@ -93,14 +93,14 @@ int main() cse_time_point times[10]; cse_step_number steps[10]; - int64_t readRealSamples = cse_observer_slave_get_real_samples(observer, slaveIndex, index, fromStep, nSamples, realSamples, steps, times); + int64_t readRealSamples = cse_observer_slave_get_real_samples(observer, slaveIndex, reference, fromStep, nSamples, realSamples, steps, times); if (readRealSamples != (int64_t)nSamples) { print_last_error(); fprintf(stderr, "Expected to read 10 real samples, got %" PRId64 "\n", readRealSamples); goto Lfailure; } - int64_t readIntSamples = cse_observer_slave_get_integer_samples(observer, slaveIndex, index, fromStep, nSamples, intSamples, steps, times); + int64_t readIntSamples = cse_observer_slave_get_integer_samples(observer, slaveIndex, reference, fromStep, nSamples, intSamples, steps, times); if (readIntSamples != (int64_t)nSamples) { print_last_error(); fprintf(stderr, "Expected to read 10 int samples, got %" PRId64 "\n", readIntSamples); diff --git a/test/c/time_series_observer_test.c b/test/c/time_series_observer_test.c index aed7f2a75..16bf63fd0 100644 --- a/test/c/time_series_observer_test.c +++ b/test/c/time_series_observer_test.c @@ -61,9 +61,9 @@ int main() double inputRealSamples[10] = {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0}; int inputIntSamples[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - cse_value_reference index = 0; + cse_value_reference reference = 0; - rc = cse_observer_start_observing(observer, 0, CSE_VARIABLE_TYPE_INTEGER, index); + rc = cse_observer_start_observing(observer, 0, CSE_VARIABLE_TYPE_INTEGER, reference); if (rc < 0) { goto Lerror; } manipulator = cse_override_manipulator_create(); @@ -73,23 +73,23 @@ int main() if (rc < 0) { goto Lerror; } for (int i = 0; i < 5; i++) { - rc = cse_manipulator_slave_set_real(manipulator, 0, &index, 1, &inputRealSamples[i]); + rc = cse_manipulator_slave_set_real(manipulator, 0, &reference, 1, &inputRealSamples[i]); if (rc < 0) { goto Lerror; } - rc = cse_manipulator_slave_set_integer(manipulator, 0, &index, 1, &inputIntSamples[i]); + rc = cse_manipulator_slave_set_integer(manipulator, 0, &reference, 1, &inputIntSamples[i]); if (rc < 0) { goto Lerror; } rc = cse_execution_step(execution, 1); if (rc < 0) { goto Lerror; } } - rc = cse_observer_stop_observing(observer, 0, CSE_VARIABLE_TYPE_INTEGER, index); + rc = cse_observer_stop_observing(observer, 0, CSE_VARIABLE_TYPE_INTEGER, reference); if (rc < 0) { goto Lerror; } - rc = cse_observer_start_observing(observer, 0, CSE_VARIABLE_TYPE_REAL, index); + rc = cse_observer_start_observing(observer, 0, CSE_VARIABLE_TYPE_REAL, reference); if (rc < 0) { goto Lerror; } for (int i = 5; i < 10; i++) { - rc = cse_manipulator_slave_set_real(manipulator, 0, &index, 1, &inputRealSamples[i]); + rc = cse_manipulator_slave_set_real(manipulator, 0, &reference, 1, &inputRealSamples[i]); if (rc < 0) { goto Lerror; } - rc = cse_manipulator_slave_set_integer(manipulator, 0, &index, 1, &inputIntSamples[i]); + rc = cse_manipulator_slave_set_integer(manipulator, 0, &reference, 1, &inputIntSamples[i]); if (rc < 0) { goto Lerror; } rc = cse_execution_step(execution, 1); if (rc < 0) { goto Lerror; } @@ -102,13 +102,13 @@ int main() cse_time_point times[10]; cse_step_number steps[10]; - int64_t readRealSamples = cse_observer_slave_get_real_samples(observer, slaveIndex, index, fromStep, nSamples, realSamples, steps, times); + int64_t readRealSamples = cse_observer_slave_get_real_samples(observer, slaveIndex, reference, fromStep, nSamples, realSamples, steps, times); if (readRealSamples != 5) { fprintf(stderr, "Expected to read 5 real samples, got %" PRId64 "\n", readRealSamples); goto Lfailure; } - int64_t readIntSamples = cse_observer_slave_get_integer_samples(observer, slaveIndex, index, fromStep, nSamples, intSamples, steps, times); + int64_t readIntSamples = cse_observer_slave_get_integer_samples(observer, slaveIndex, reference, fromStep, nSamples, intSamples, steps, times); if (readIntSamples != 0) { fprintf(stderr, "Expected to read 0 int samples, got %" PRId64 "\n", readIntSamples); goto Lfailure; diff --git a/test/c/variable_metadata_test.c b/test/c/variable_metadata_test.c index 88d72bfc9..7504f30f0 100644 --- a/test/c/variable_metadata_test.c +++ b/test/c/variable_metadata_test.c @@ -79,8 +79,8 @@ int main() fprintf(stderr, "Expected type to be string\n"); goto Lfailure; } - if (vd[i].index != 0) { - fprintf(stderr, "Expected variable index to be 0, got %i\n", vd[i].index); + if (vd[i].reference != 0) { + fprintf(stderr, "Expected variable reference to be 0, got %i\n", vd[i].reference); goto Lfailure; } } @@ -97,8 +97,8 @@ int main() fprintf(stderr, "Expected type to be real\n"); goto Lfailure; } - if (vd[i].index != 0) { - fprintf(stderr, "Expected variable index to be 0, got %i\n", vd[i].index); + if (vd[i].reference != 0) { + fprintf(stderr, "Expected variable reference to be 0, got %i\n", vd[i].reference); goto Lfailure; } } diff --git a/test/cpp/async_slave_unittest.cpp b/test/cpp/async_slave_unittest.cpp index 381d237e8..f0513fcee 100644 --- a/test/cpp/async_slave_unittest.cpp +++ b/test/cpp/async_slave_unittest.cpp @@ -39,7 +39,7 @@ class test_slave : public slave gsl::span values) override { if (!values.empty()) { - if (variables[0] != 0) throw std::logic_error("Invalid variable index"); + if (variables[0] != 0) throw std::logic_error("Invalid variable reference"); if (values[0] == 0) throw nonfatal_bad_value("integer"); } } diff --git a/test/cpp/fixed_step_algorithm_test.cpp b/test/cpp/fixed_step_algorithm_test.cpp index 181e1a64d..eb39982a4 100644 --- a/test/cpp/fixed_step_algorithm_test.cpp +++ b/test/cpp/fixed_step_algorithm_test.cpp @@ -40,8 +40,8 @@ int main() auto observer = std::make_shared(); execution.add_observer(observer); - const cse::value_reference realOutIndex = 0; - const cse::value_reference realInIndex = 1; + const cse::value_reference realOutRef = 0; + const cse::value_reference realInRef = 1; // Add slaves to it @@ -52,14 +52,14 @@ int main() if (i > 0) { execution.add_connection( std::make_shared( - cse::variable_id{i - 1, cse::variable_type::real, realOutIndex}, - cse::variable_id{i, cse::variable_type::real, realInIndex})); + cse::variable_id{i - 1, cse::variable_type::real, realOutRef}, + cse::variable_id{i, cse::variable_type::real, realInRef})); } } auto observer2 = std::make_shared(); execution.add_observer(observer2); - observer2->start_observing(cse::variable_id{9, cse::variable_type::real, realOutIndex}); + observer2->start_observing(cse::variable_id{9, cse::variable_type::real, realOutRef}); // Run simulation auto simResult = execution.simulate_until(midTime); @@ -81,8 +81,8 @@ int main() for (int j = 0; j < numSlaves; j++) { double lastRealOutValue = realOutValue; - observer->get_real(j, gsl::make_span(&realOutIndex, 1), gsl::make_span(&realOutValue, 1)); - observer->get_real(j, gsl::make_span(&realInIndex, 1), gsl::make_span(&realInValue, 1)); + observer->get_real(j, gsl::make_span(&realOutRef, 1), gsl::make_span(&realOutValue, 1)); + observer->get_real(j, gsl::make_span(&realInRef, 1), gsl::make_span(&realInValue, 1)); if (j > 0) { // Check that real input of slave j has same value as real output of slave j - 1 REQUIRE(std::fabs(realInValue - lastRealOutValue) < 1.0e-9); @@ -93,7 +93,7 @@ int main() double realValues[numSamples]; cse::step_number steps[numSamples]; cse::time_point timeValues[numSamples]; - observer2->get_real_samples(9, realOutIndex, 1, gsl::make_span(realValues, numSamples), gsl::make_span(steps, numSamples), gsl::make_span(timeValues, numSamples)); + observer2->get_real_samples(9, realOutRef, 1, gsl::make_span(realValues, numSamples), gsl::make_span(steps, numSamples), gsl::make_span(timeValues, numSamples)); cse::step_number lastStep = -1; double lastValue = -1.0; for (int k = 0; k < numSamples; k++) { diff --git a/test/cpp/fmi_v1_fmu_unittest.cpp b/test/cpp/fmi_v1_fmu_unittest.cpp index 8bf38093e..9675f7f84 100644 --- a/test/cpp/fmi_v1_fmu_unittest.cpp +++ b/test/cpp/fmi_v1_fmu_unittest.cpp @@ -35,21 +35,21 @@ void run_tests(std::shared_ptr fmu) realOut = 0, integerOut = 0, booleanOut = 0, stringOut = 0; for (const auto& v : d->variables) { if (v.name == "realIn") { - realIn = v.index; + realIn = v.reference; } else if (v.name == "integerIn") { - integerIn = v.index; + integerIn = v.reference; } else if (v.name == "booleanIn") { - booleanIn = v.index; + booleanIn = v.reference; } else if (v.name == "stringIn") { - stringIn = v.index; + stringIn = v.reference; } else if (v.name == "realOut") { - realOut = v.index; + realOut = v.reference; } else if (v.name == "integerOut") { - integerOut = v.index; + integerOut = v.reference; } else if (v.name == "booleanOut") { - booleanOut = v.index; + booleanOut = v.reference; } else if (v.name == "stringOut") { - stringOut = v.index; + stringOut = v.reference; } if (v.name == "realIn") { diff --git a/test/cpp/fmi_v2_fmu_unittest.cpp b/test/cpp/fmi_v2_fmu_unittest.cpp index ccf6fc89e..e8547d16b 100644 --- a/test/cpp/fmi_v2_fmu_unittest.cpp +++ b/test/cpp/fmi_v2_fmu_unittest.cpp @@ -44,7 +44,7 @@ BOOST_AUTO_TEST_CASE(v2_fmu) BOOST_TEST(v.causality == variable_causality::output); double start = std::get(*v.start); BOOST_TEST(start == 0.0); - const auto varID = v.index; + const auto varID = v.reference; double varVal = -1.0; instance->get_real_variables(gsl::make_span(&varID, 1), gsl::make_span(&varVal, 1)); BOOST_TEST(varVal == 0.0); @@ -54,7 +54,7 @@ BOOST_AUTO_TEST_CASE(v2_fmu) BOOST_TEST(v.causality == variable_causality::parameter); double start = std::get(*v.start); BOOST_TEST(start == 1.0); - const auto varID = v.index; + const auto varID = v.reference; double varVal = -1.0; instance->get_real_variables(gsl::make_span(&varID, 1), gsl::make_span(&varVal, 1)); BOOST_TEST(varVal == 1.0); diff --git a/test/cpp/mock_slave.hpp b/test/cpp/mock_slave.hpp index 84f2a8a30..9b8a22bc3 100644 --- a/test/cpp/mock_slave.hpp +++ b/test/cpp/mock_slave.hpp @@ -94,7 +94,7 @@ class mock_slave : public cse::slave } else if (variables[i] == 1) { values[i] = realIn_; } else { - throw std::out_of_range("bad index"); + throw std::out_of_range("bad reference"); } } } @@ -109,7 +109,7 @@ class mock_slave : public cse::slave } else if (variables[i] == 1) { values[i] = intIn_; } else { - throw std::out_of_range("bad index"); + throw std::out_of_range("bad reference"); } } } @@ -124,7 +124,7 @@ class mock_slave : public cse::slave } else if (variables[i] == 1) { values[i] = boolIn_; } else { - throw std::out_of_range("bad index"); + throw std::out_of_range("bad reference"); } } } @@ -139,7 +139,7 @@ class mock_slave : public cse::slave } else if (variables[i] == 1) { values[i] = stringIn_; } else { - throw std::out_of_range("bad index"); + throw std::out_of_range("bad reference"); } } } @@ -152,7 +152,7 @@ class mock_slave : public cse::slave if (variables[i] == 1) { realIn_ = values[i]; } else { - throw std::out_of_range("bad index"); + throw std::out_of_range("bad reference"); } } } @@ -165,7 +165,7 @@ class mock_slave : public cse::slave if (variables[i] == 1) { intIn_ = values[i]; } else { - throw std::out_of_range("bad index"); + throw std::out_of_range("bad reference"); } } } @@ -178,7 +178,7 @@ class mock_slave : public cse::slave if (variables[i] == 1) { boolIn_ = values[i]; } else { - throw std::out_of_range("bad index"); + throw std::out_of_range("bad reference"); } } } @@ -191,7 +191,7 @@ class mock_slave : public cse::slave if (variables[i] == 1) { stringIn_ = values[i]; } else { - throw std::out_of_range("bad index"); + throw std::out_of_range("bad reference"); } } } diff --git a/test/cpp/monitor_modified_variables_test.cpp b/test/cpp/monitor_modified_variables_test.cpp index 782667e3d..7585d07cb 100644 --- a/test/cpp/monitor_modified_variables_test.cpp +++ b/test/cpp/monitor_modified_variables_test.cpp @@ -63,7 +63,7 @@ int main() for (auto var : modifiedVariables) { REQUIRE(var.type == cse::variable_type::integer); - REQUIRE(var.index == 0); + REQUIRE(var.reference == 0); } } catch (const std::exception& e) { diff --git a/test/cpp/ssp_parser_test.cpp b/test/cpp/ssp_parser_test.cpp index 905ad2342..3d96ce3ad 100644 --- a/test/cpp/ssp_parser_test.cpp +++ b/test/cpp/ssp_parser_test.cpp @@ -36,14 +36,14 @@ int main() cse::simulator_index i = simulator_map.at("KnuckleBoomCrane").index; double realValue = -1.0; - cse::value_reference index = cse::find_variable(simulator_map.at("KnuckleBoomCrane").description, "Spring_Joint.k").index; - obs->get_real(i, gsl::make_span(&index, 1), gsl::make_span(&realValue, 1)); + cse::value_reference reference = cse::find_variable(simulator_map.at("KnuckleBoomCrane").description, "Spring_Joint.k").reference; + obs->get_real(i, gsl::make_span(&reference, 1), gsl::make_span(&realValue, 1)); double magicNumberFromSsdFile = 0.005; REQUIRE(std::fabs(realValue - magicNumberFromSsdFile) < 1e-9); - cse::value_reference index2 = cse::find_variable(simulator_map.at("KnuckleBoomCrane").description, "mt0_init").index; - obs->get_real(i, gsl::make_span(&index2, 1), gsl::make_span(&realValue, 1)); + cse::value_reference reference2 = cse::find_variable(simulator_map.at("KnuckleBoomCrane").description, "mt0_init").reference; + obs->get_real(i, gsl::make_span(&reference2, 1), gsl::make_span(&realValue, 1)); magicNumberFromSsdFile = 69.0; REQUIRE(std::fabs(realValue - magicNumberFromSsdFile) < 1e-9); From b4f8e465056faf0c607149c180fd7421f0f43bdf Mon Sep 17 00:00:00 2001 From: eidekrist Date: Wed, 28 Aug 2019 08:32:07 +0200 Subject: [PATCH 3/3] #265 Review followup. Fix stragglers, rename methods in simulator class. --- include/cse.h | 2 +- include/cse/algorithm.hpp | 8 +-- include/cse/observer/time_series_provider.hpp | 8 +-- src/c/cse.cpp | 10 ++-- src/cpp/cse/slave_simulator.hpp | 8 +-- src/cpp/execution.cpp | 8 +-- src/cpp/slave_simulator.cpp | 56 +++++++++---------- 7 files changed, 50 insertions(+), 50 deletions(-) diff --git a/include/cse.h b/include/cse.h index 770cbec52..27e728fc6 100644 --- a/include/cse.h +++ b/include/cse.h @@ -384,7 +384,7 @@ typedef struct cse_slave_index slave_index; /// The type of the variable. cse_variable_type type; - /// The variables value reference. + /// The variable's value reference. cse_value_reference value_reference; } cse_variable_id; diff --git a/include/cse/algorithm.hpp b/include/cse/algorithm.hpp index f137b2571..6ec75210d 100644 --- a/include/cse/algorithm.hpp +++ b/include/cse/algorithm.hpp @@ -182,16 +182,16 @@ class simulator : public observable std::optional relativeTolerance) = 0; /// Returns all value references of real type that currently have an active modifier. - virtual const std::unordered_set& get_modified_real_references() const = 0; + virtual const std::unordered_set& get_modified_real_variables() const = 0; /// Returns all value references of integer type that currently have an active modifier. - virtual const std::unordered_set& get_modified_integer_references() const = 0; + virtual const std::unordered_set& get_modified_integer_variables() const = 0; /// Returns all value references of boolean type that currently have an active modifier. - virtual const std::unordered_set& get_modified_boolean_references() const = 0; + virtual const std::unordered_set& get_modified_boolean_variables() const = 0; /// Returns all value references of string type that currently have an active modifier. - virtual const std::unordered_set& get_modified_string_references() const = 0; + virtual const std::unordered_set& get_modified_string_variables() const = 0; /** * Updates the simulator with new input values and makes it calculate diff --git a/include/cse/observer/time_series_provider.hpp b/include/cse/observer/time_series_provider.hpp index ea5cac379..627fba520 100644 --- a/include/cse/observer/time_series_provider.hpp +++ b/include/cse/observer/time_series_provider.hpp @@ -29,7 +29,7 @@ class time_series_provider : public observer * Retrieves a series of observed values, step numbers and times for a real variable. * * \param [in] sim index of the simulator - * \param [in] valueReference the variable index + * \param [in] valueReference the value reference * \param [in] fromStep the step number to start from * \param [out] values the series of observed values * \param [out] steps the corresponding step numbers @@ -50,7 +50,7 @@ class time_series_provider : public observer * Retrieves a series of observed values, step numbers and times for an integer variable. * * \param [in] sim index of the simulator - * \param [in] valueReference the variable index + * \param [in] valueReference the value reference * \param [in] fromStep the step number to start from * \param [out] values the series of observed values * \param [out] steps the corresponding step numbers @@ -103,9 +103,9 @@ class time_series_provider : public observer * Retrieves two time-synchronized series of observed values for two real variables. * * \param [in] sim1 index of the first simulator - * \param [in] valueReference1 the first variable index + * \param [in] valueReference1 the first value reference * \param [in] sim2 index of the second simulator - * \param [in] valueReference2 the second variable index + * \param [in] valueReference2 the second value reference * \param [in] fromStep the step number to start from * \param [out] values1 the first series of observed values * \param [out] values2 the second series of observed values diff --git a/src/c/cse.cpp b/src/c/cse.cpp index 82415ea28..7fff7c7fd 100644 --- a/src/c/cse.cpp +++ b/src/c/cse.cpp @@ -224,7 +224,7 @@ int cse_slave_get_num_variables(cse_execution* execution, cse_slave_index slave) return static_cast(entry.second.description.variables.size()); } } - set_last_error(CSE_ERRC_OUT_OF_RANGE, "Invalid slave reference"); + set_last_error(CSE_ERRC_OUT_OF_RANGE, "Invalid slave index"); return -1; } @@ -631,7 +631,7 @@ int cse_observer_slave_get_string( int64_t cse_observer_slave_get_real_samples( cse_observer* observer, cse_slave_index slave, - cse_value_reference ValueReference, + cse_value_reference valueReference, cse_step_number fromStep, size_t nSamples, double values[], @@ -644,7 +644,7 @@ int64_t cse_observer_slave_get_real_samples( if (!obs) { throw std::invalid_argument("Invalid observer! The provided observer must be a time_series_observer."); } - size_t samplesRead = obs->get_real_samples(slave, ValueReference, fromStep, + size_t samplesRead = obs->get_real_samples(slave, valueReference, fromStep, gsl::make_span(values, nSamples), gsl::make_span(steps, nSamples), timePoints); for (size_t i = 0; i < samplesRead; ++i) { @@ -692,7 +692,7 @@ int64_t cse_observer_slave_get_real_synchronized_series( int64_t cse_observer_slave_get_integer_samples( cse_observer* observer, cse_slave_index slave, - cse_value_reference ValueReference, + cse_value_reference valueReference, cse_step_number fromStep, size_t nSamples, int values[], @@ -705,7 +705,7 @@ int64_t cse_observer_slave_get_integer_samples( if (!obs) { throw std::invalid_argument("Invalid observer! The provided observer must be a time_series_observer."); } - size_t samplesRead = obs->get_integer_samples(slave, ValueReference, fromStep, + size_t samplesRead = obs->get_integer_samples(slave, valueReference, fromStep, gsl::make_span(values, nSamples), gsl::make_span(steps, nSamples), timePoints); for (size_t i = 0; i < samplesRead; ++i) { diff --git a/src/cpp/cse/slave_simulator.hpp b/src/cpp/cse/slave_simulator.hpp index a826e5955..85eafca2f 100644 --- a/src/cpp/cse/slave_simulator.hpp +++ b/src/cpp/cse/slave_simulator.hpp @@ -71,10 +71,10 @@ class slave_simulator : public simulator value_reference reference, std::function modifier) override; - std::unordered_set& get_modified_real_references() const override; - std::unordered_set& get_modified_integer_references() const override; - std::unordered_set& get_modified_boolean_references() const override; - std::unordered_set& get_modified_string_references() const override; + std::unordered_set& get_modified_real_variables() const override; + std::unordered_set& get_modified_integer_variables() const override; + std::unordered_set& get_modified_boolean_variables() const override; + std::unordered_set& get_modified_string_variables() const override; boost::fibers::future setup( time_point startTime, diff --git a/src/cpp/execution.cpp b/src/cpp/execution.cpp index 5ab99f31a..f00d4edc1 100644 --- a/src/cpp/execution.cpp +++ b/src/cpp/execution.cpp @@ -204,10 +204,10 @@ class execution::impl auto index = 0; for (const auto& sim : simulators_) { - const auto& realRefs = sim->get_modified_real_references(); - const auto& integerRefs = sim->get_modified_integer_references(); - const auto& booleanRefs = sim->get_modified_boolean_references(); - const auto& stringRefs = sim->get_modified_string_references(); + const auto& realRefs = sim->get_modified_real_variables(); + const auto& integerRefs = sim->get_modified_integer_variables(); + const auto& booleanRefs = sim->get_modified_boolean_variables(); + const auto& stringRefs = sim->get_modified_string_variables(); for (const auto& ref : realRefs) { variable_id var = {index, variable_type::real, ref}; diff --git a/src/cpp/slave_simulator.cpp b/src/cpp/slave_simulator.cpp index f83aaf2b6..3f32f3ccc 100644 --- a/src/cpp/slave_simulator.cpp +++ b/src/cpp/slave_simulator.cpp @@ -322,7 +322,7 @@ class slave_simulator::impl std::function modifier) { realSetCache_.set_modifier(ref, modifier); - set_modified_reference(modifiedRealReferences_, ref, modifier ? true : false); + set_modified_reference(modifiedRealVariables_, ref, modifier ? true : false); } void set_integer_input_modifier( @@ -330,7 +330,7 @@ class slave_simulator::impl std::function modifier) { integerSetCache_.set_modifier(ref, modifier); - set_modified_reference(modifiedIntegerReferences_, ref, modifier ? true : false); + set_modified_reference(modifiedIntegerVariables_, ref, modifier ? true : false); } void set_boolean_input_modifier( @@ -338,7 +338,7 @@ class slave_simulator::impl std::function modifier) { booleanSetCache_.set_modifier(ref, modifier); - set_modified_reference(modifiedBooleanReferences_, ref, modifier ? true : false); + set_modified_reference(modifiedBooleanVariables_, ref, modifier ? true : false); } void set_string_input_modifier( @@ -346,7 +346,7 @@ class slave_simulator::impl std::function modifier) { stringSetCache_.set_modifier(ref, modifier); - set_modified_reference(modifiedStringReferences_, ref, modifier ? true : false); + set_modified_reference(modifiedStringVariables_, ref, modifier ? true : false); } void set_real_output_modifier( @@ -354,7 +354,7 @@ class slave_simulator::impl std::function modifier) { realGetCache_.set_modifier(ref, modifier); - set_modified_reference(modifiedRealReferences_, ref, modifier ? true : false); + set_modified_reference(modifiedRealVariables_, ref, modifier ? true : false); } void set_integer_output_modifier( @@ -362,7 +362,7 @@ class slave_simulator::impl std::function modifier) { integerGetCache_.set_modifier(ref, modifier); - set_modified_reference(modifiedIntegerReferences_, ref, modifier ? true : false); + set_modified_reference(modifiedIntegerVariables_, ref, modifier ? true : false); } void set_boolean_output_modifier( @@ -370,7 +370,7 @@ class slave_simulator::impl std::function modifier) { booleanGetCache_.set_modifier(ref, modifier); - set_modified_reference(modifiedBooleanReferences_, ref, modifier ? true : false); + set_modified_reference(modifiedBooleanVariables_, ref, modifier ? true : false); } void set_string_output_modifier( @@ -378,27 +378,27 @@ class slave_simulator::impl std::function modifier) { stringGetCache_.set_modifier(ref, modifier); - set_modified_reference(modifiedStringReferences_, ref, modifier ? true : false); + set_modified_reference(modifiedStringVariables_, ref, modifier ? true : false); } - std::unordered_set& get_modified_real_references() + std::unordered_set& get_modified_real_variables() { - return modifiedRealReferences_; + return modifiedRealVariables_; } - std::unordered_set& get_modified_integer_references() + std::unordered_set& get_modified_integer_variables() { - return modifiedIntegerReferences_; + return modifiedIntegerVariables_; } - std::unordered_set& get_modified_boolean_references() + std::unordered_set& get_modified_boolean_variables() { - return modifiedBooleanReferences_; + return modifiedBooleanVariables_; } - std::unordered_set& get_modified_string_references() + std::unordered_set& get_modified_string_variables() { - return modifiedStringReferences_; + return modifiedStringVariables_; } boost::fibers::future setup( @@ -517,10 +517,10 @@ class slave_simulator::impl set_variable_cache booleanSetCache_; set_variable_cache stringSetCache_; - std::unordered_set modifiedRealReferences_; - std::unordered_set modifiedIntegerReferences_; - std::unordered_set modifiedBooleanReferences_; - std::unordered_set modifiedStringReferences_; + std::unordered_set modifiedRealVariables_; + std::unordered_set modifiedIntegerVariables_; + std::unordered_set modifiedBooleanVariables_; + std::unordered_set modifiedStringVariables_; }; @@ -666,24 +666,24 @@ void slave_simulator::set_string_output_modifier( pimpl_->set_string_output_modifier(ref, modifier); } -std::unordered_set& slave_simulator::get_modified_real_references() const +std::unordered_set& slave_simulator::get_modified_real_variables() const { - return pimpl_->get_modified_real_references(); + return pimpl_->get_modified_real_variables(); } -std::unordered_set& slave_simulator::get_modified_integer_references() const +std::unordered_set& slave_simulator::get_modified_integer_variables() const { - return pimpl_->get_modified_integer_references(); + return pimpl_->get_modified_integer_variables(); } -std::unordered_set& slave_simulator::get_modified_boolean_references() const +std::unordered_set& slave_simulator::get_modified_boolean_variables() const { - return pimpl_->get_modified_boolean_references(); + return pimpl_->get_modified_boolean_variables(); } -std::unordered_set& slave_simulator::get_modified_string_references() const +std::unordered_set& slave_simulator::get_modified_string_variables() const { - return pimpl_->get_modified_string_references(); + return pimpl_->get_modified_string_variables(); } boost::fibers::future slave_simulator::setup(