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

Replace multi-variable connections with functions #518

Merged
merged 25 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
377c23b
Add function API and example function
kyllingstad Jan 10, 2020
9ce9695
WIP
kyllingstad Jan 15, 2020
9db2b1a
Complete(?) function API
kyllingstad Jan 23, 2020
cc884d8
Remove connections
kyllingstad Jan 23, 2020
3393996
Minor fixes here and there, update tests
kyllingstad Jan 24, 2020
096571e
NOMINMAX again
kyllingstad Jan 27, 2020
5a17639
Add function unittests
kyllingstad Jan 27, 2020
cd66c82
Add forgotten function_unittests
kyllingstad Jan 28, 2020
6e90d1a
Fix some issues from code review
kyllingstad Feb 4, 2020
a80917b
Fix more review comments
kyllingstad Feb 4, 2020
837b189
Fix MSVC warning
kyllingstad Feb 4, 2020
6709168
Fix decimation factor calculation
kyllingstad Feb 4, 2020
b88a126
Calculate functions before stepping simulators
kyllingstad Feb 4, 2020
84a3d85
Revert to evaluating functions at end of step
kyllingstad Feb 20, 2020
dc25263
Documentation-o-rama
kyllingstad Feb 20, 2020
cdd29fb
Split function_type_description
kyllingstad Feb 21, 2020
0fa79d7
Rename function variable getters & setters
kyllingstad Feb 21, 2020
f9fa740
Support boolean and string variables in functions
kyllingstad Feb 21, 2020
a50059e
WIP on tests
kyllingstad Mar 5, 2020
dc0c527
Fix mock_slave and lots of magic numbers
kyllingstad Mar 16, 2020
5cd2311
Merge branch bugfix/538-... and complete tests
kyllingstad Mar 17, 2020
6dad16e
Fix MSVC warnings
kyllingstad Mar 17, 2020
0232093
Define alias for function parameter maps
kyllingstad Mar 23, 2020
b9d50a7
Public enums for function parameter indexes
kyllingstad Mar 23, 2020
5979e25
Merge remote-tracking branch 'origin/master' into feature/464-connect…
kyllingstad Mar 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 77 additions & 13 deletions include/cse/algorithm/algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#define CSECORE_ALGORITHM_ALGORITHM_HPP

#include <cse/algorithm/simulator.hpp>
#include <cse/connection.hpp>
#include <cse/execution.hpp>
#include <cse/function/function.hpp>
#include <cse/model.hpp>
#include <cse/observer/observer.hpp>

Expand Down Expand Up @@ -64,25 +64,89 @@ class algorithm
virtual void remove_simulator(simulator_index index) = 0;

/**
* Adds a connection to the co-simulation.
* Adds a function to the co-simulation.
*
* After this, the algorithm is responsible for acquiring the values of
* the connection's source variables, and distributing the connection's
* destination variable values at communication points.
* \param index
* A numerical index that will be used to identify the function
* in other function calls.
* \param fun
* A pointer to an object that is used to access the function.
* Note that the algorithm does not have resource ownership of
* the object it points to (i.e., should not try to delete it).
*/
virtual void add_function(function_index index, function* fun) = 0;

/**
* Connects a simulator output variable to a simulator input variable.
*
* After this, the algorithm is responsible for acquiring the value of
* the output variable and assigning it to the input variable at
* communication points.
*
* It is assumed that the variables contained by the connection are valid
* and that there are no existing connections to any of the connection's
* destination variables.
* \param output
* A reference to the output variable.
* \param input
* A reference to the input variable.
* \param inputAlreadyConnected
* Whether the input has already been connected in a previous
* `connect_variables()` call. If so, the previous connection must
* be broken. This is meant as an aid to subclass implementors,
* saving them from having to perform this check on every connection.
*/
virtual void add_connection(std::shared_ptr<connection> conn) = 0;
virtual void connect_variables(
variable_id output,
variable_id input,
bool inputAlreadyConnected) = 0;

/**
* Removes a connection from the co-simulation.
* Connects a simulator output variable to a function input variable.
*
* It is assumed that the connection has previously been added to the
* co-simulation with `add_connection()`.
* After this, the algorithm is responsible for acquiring the value of
* the output variable and assigning it to the input variable before
* the function is calculated.
*
* \param output
* A reference to the output variable.
* \param input
* A reference to the input variable.
* \param inputAlreadyConnected
* Whether the input has already been connected in a previous
* `connect_variables()` call. If so, the previous connection must
* be broken. This is meant as an aid to subclass implementors,
* saving them from having to perform this check on every connection.
*/
virtual void connect_variables(
variable_id output,
function_io_id input,
bool inputAlreadyConnected) = 0;

/**
* Connects a function output variable to a simulator input variable.
*
* After this, the algorithm is responsible for acquiring the value of
* the output variable and assigning it to the input variable after
* the function is calculated.
*
* \param output
* A reference to the output variable.
* \param input
* A reference to the input variable.
* \param inputAlreadyConnected
* Whether the input has already been connected in a previous
* `connect_variables()` call. If so, the previous connection must
* be broken. This is meant as an aid to subclass implementors,
* saving them from having to perform this check on every connection.
*/
virtual void remove_connection(std::shared_ptr<connection> conn) = 0;
virtual void connect_variables(
function_io_id output,
variable_id input,
bool inputAlreadyConnected) = 0;

/// Breaks any previously established connection to input variable `input`.
virtual void disconnect_variable(variable_id input) = 0;

/// Breaks any previously established connection to input variable `input`.
virtual void disconnect_variable(function_io_id input) = 0;

/**
* Performs initial setup.
Expand Down
8 changes: 6 additions & 2 deletions include/cse/algorithm/fixed_step_algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ class fixed_step_algorithm : public algorithm
// `algorithm` methods
void add_simulator(simulator_index i, simulator* s, duration stepSizeHint) override;
void remove_simulator(simulator_index i) override;
void add_connection(std::shared_ptr<connection> c) override;
void remove_connection(std::shared_ptr<connection> c) override;
void add_function(function_index i, function* f) override;
void connect_variables(variable_id output, variable_id input, bool inputAlreadyConnected) override;
void connect_variables(variable_id output, function_io_id input, bool inputAlreadyConnected) override;
void connect_variables(function_io_id output, variable_id input, bool inputAlreadyConnected) override;
void disconnect_variable(variable_id input) override;
void disconnect_variable(function_io_id input) override;
void setup(time_point startTime, std::optional<time_point> stopTime) override;
void initialize() override;
std::pair<duration, std::unordered_set<simulator_index>> do_step(time_point currentT) override;
Expand Down
14 changes: 0 additions & 14 deletions include/cse/connection.hpp

This file was deleted.

58 changes: 0 additions & 58 deletions include/cse/connection/connection.hpp

This file was deleted.

23 changes: 0 additions & 23 deletions include/cse/connection/linear_transformation_connection.hpp

This file was deleted.

32 changes: 0 additions & 32 deletions include/cse/connection/scalar_connection.hpp

This file was deleted.

34 changes: 0 additions & 34 deletions include/cse/connection/sum_connection.hpp

This file was deleted.

Loading