Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SSP] Support linear transformations #451

Closed
markaren opened this issue Oct 30, 2019 · 8 comments · Fixed by #454
Closed

[SSP] Support linear transformations #451

markaren opened this issue Oct 30, 2019 · 8 comments · Fixed by #454
Labels
enhancement New feature or request

Comments

@markaren
Copy link
Contributor

No description provided.

@markaren markaren added the enhancement New feature or request label Oct 30, 2019
@markaren
Copy link
Contributor Author

markaren commented Oct 31, 2019

#378 discussed some ways of doing this, but now I'm sitting here not seeing how it should be done.
I would have used connections for this, but the general agreement was to prefer existing modifiers.

But how the heck can I access set_real_output_modifier on a simulator instance from the ssp_parser ?

@kyllingstad @eidekrist

@markaren
Copy link
Contributor Author

I'm going to make a PR using a connection type for this..

@eidekrist
Copy link
Member

I think we need to have a discussion on how to go about this. The current architecture may not be be suitable for solving this in a good way.

@markaren
Copy link
Contributor Author

And this is a use case:) We need to solve this using FMUs today.

@markaren
Copy link
Contributor Author

I still think #379 was perfect for this use case, but lets discuss this next meeting.

@kyllingstad
Copy link
Member

@eidekrist:

I think we need to have a discussion on how to go about this. The current architecture may not be be suitable for solving this in a good way.

I agree. The problem necessarily extends to the CSE config format and system_structure too. And there are other things we need to handle besides modifiers, especially connections (see this comment). IMO, it would be best if these things were handled in a somewhat consistent manner throughout the code base.

@eidekrist
Copy link
Member

I'm looking at the SSP standard now. The xml would seemingly look something like this:

<ssd:Connection startElement="A" startConnector="out" endElement="B" endConnector="in">
     <ssc:LinearTransformation factor="1.9" offset="3.5"/>
</ssd:Connection>

The standard states that (automatic) unit conversions must be performed on the output, prior to applying any linear transformations. The standard does not seem to be clear on where any linear transformation should be performed, which creates some wiggle room for us.

IMO, the concept presented in #379 tries to solve too many problems at once. Given the current architecture, implementing the transformation as a modifier function in the simulator class is not very robust and prone to disappearing at the whim of any manipulator. Introducing a specialization of scalar_connection which performs a linear transformation is a lot more robust, and does not require changing the connection API.

@markaren
Copy link
Contributor Author

markaren commented Oct 31, 2019

#include <cse/connection/linear_transformation_connection.hpp>
#include <cse/error.hpp>

namespace cse
{

linear_transformation_connection::linear_transformation_connection(variable_id source, variable_id destination, double offset, double factor)
    : scalar_connection(source, destination)
    , offset_(offset)
    , factor_(factor)
{
    CSE_INPUT_CHECK(source.type == variable_type::real);
}

void linear_transformation_connection::set_source_value(variable_id, std::variant<double, int, bool, std::string_view> value)
{
    value_ = std::get<double>(value) * factor_ + offset_;
}

} // namespace cse

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants