-
Notifications
You must be signed in to change notification settings - Fork 7
initial attempt at a unified interface to signal buses #193
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d915869
initial attempt at a unified interface to signal buses
superwhiskers a00aaa4
remove inheritance
superwhiskers 7c39568
Merge branch 'develop' into signal-setting
superwhiskers 36a0582
in-progress rework of signal handling
superwhiskers b57db7f
Apply pre-commmit fixes
superwhiskers 5df2fd4
modify `TwoBusTgov1` to use the component signal extension instead of…
superwhiskers 43db9bc
Apply pre-commmit fixes
superwhiskers e6869f2
differentiate documentation comments in `Tgov1` a little more
superwhiskers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| #pragma once | ||
|
|
||
| #include <array> | ||
| #include <optional> | ||
| #include <type_traits> | ||
|
|
||
| #include <Model/PhasorDynamics/SignalNode/SignalNode.hpp> | ||
|
|
||
| namespace GridKit | ||
| { | ||
| namespace PhasorDynamics | ||
| { | ||
| /// Dummy `Variables` type for components with no variables | ||
| enum class NoVariables : size_t | ||
| { | ||
| MAXIMUM | ||
| }; | ||
|
|
||
| /// Concept requiring an enum to have a `MAXIMUM` variant and that it have | ||
| /// the underlying type of `size_t`. This does not ensure the variant is | ||
| /// the actual maximum | ||
| template <typename T> | ||
| concept EnumHasMaximumValueAndIsSizeT = std::is_enum_v<T> | ||
| && std::is_same_v<std::underlying_type_t<T>, size_t> | ||
| && requires { T::MAXIMUM; }; | ||
|
|
||
| /// Extension object for `Component`s adding methods and member variables | ||
| /// related to signal bus management | ||
| /// | ||
| /// This is used by adding an instance in a field to your class and | ||
| /// exposing this field to others | ||
| template <class ScalarT, typename IdxT, typename InternalVariables, typename ExternalVariables> | ||
| requires EnumHasMaximumValueAndIsSizeT<InternalVariables> | ||
| && EnumHasMaximumValueAndIsSizeT<ExternalVariables> | ||
| class ComponentSignals | ||
| { | ||
| public: | ||
| /// Attaches a signal node to an external variable on this component | ||
| template <ExternalVariables variable> | ||
| auto attachSignalNode(SignalNode<ScalarT, IdxT>* signal) | ||
| { | ||
| external_variable_signals_[static_cast<size_t>(variable)] = signal; | ||
| } | ||
|
|
||
| /// Check if a signal node has been attached to an external variable | ||
| template <ExternalVariables variable> | ||
| auto isAttached() -> bool | ||
| { | ||
| return static_cast<bool>(external_variable_signals_[static_cast<size_t>(variable)]); | ||
| } | ||
|
|
||
| /// Check if a signal node has been assigned to an internal variable | ||
| template <InternalVariables variable> | ||
| auto isAssigned() -> bool | ||
| { | ||
| return static_cast<bool>(internal_variable_signals_[static_cast<size_t>(variable)]); | ||
| } | ||
|
|
||
| /// Returns a signal node for an internal signal variable to be | ||
| /// attached to an external variable on another component | ||
| template <InternalVariables variable> | ||
| auto getSignalNode() -> SignalNode<ScalarT, IdxT>* | ||
| { | ||
| if (!internal_variable_signals_[static_cast<size_t>(variable)]) | ||
| { | ||
| throw "A signal node has not been assigned to this internal variable"; | ||
| } | ||
|
|
||
| return *internal_variable_signals_[static_cast<size_t>(variable)]; | ||
| } | ||
|
|
||
| /// Returns the value of the specified external variable | ||
| template <ExternalVariables variable> | ||
| auto readExternalVariable() const -> ScalarT | ||
| { | ||
| if (!external_variable_signals_[static_cast<size_t>(variable)]) | ||
| { | ||
| throw "A signal node has not been assigned to this external variable"; | ||
| } | ||
|
|
||
| return (*external_variable_signals_[static_cast<size_t>(variable)])->read(); | ||
| } | ||
|
|
||
| /// Writes a value to the specified external variable | ||
| template <ExternalVariables variable> | ||
| auto writeExternalVariable(ScalarT value) | ||
| { | ||
| if (!external_variable_signals_[static_cast<size_t>(variable)]) | ||
| { | ||
| throw "A signal node has not been assigned to this external variable"; | ||
| } | ||
|
|
||
| (*external_variable_signals_[static_cast<size_t>(variable)])->init(value); | ||
| } | ||
|
|
||
| /// Assign a signal node to an internal variable | ||
| template <InternalVariables variable> | ||
| auto assignSignalNode(SignalNode<ScalarT, IdxT>* node) | ||
| { | ||
| internal_variable_signals_[static_cast<size_t>(variable)] = node; | ||
| } | ||
|
|
||
| private: | ||
| /// Internal variables which may have a signal associated with them for | ||
| /// use elsewhere | ||
| std::array<std::optional<SignalNode<ScalarT, IdxT>*>, | ||
| static_cast<size_t>(InternalVariables::MAXIMUM)> | ||
| internal_variable_signals_; | ||
|
|
||
| /// External variables which may have a signal associated with them for | ||
| /// use internally | ||
| std::array<std::optional<SignalNode<ScalarT, IdxT>*>, | ||
| static_cast<size_t>(ExternalVariables::MAXIMUM)> | ||
| external_variable_signals_; | ||
| }; | ||
| } // namespace PhasorDynamics | ||
| } // namespace GridKit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,11 @@ | ||
| # **Governor Model** | ||
|
|
||
| > [!NOTE] | ||
| > No implementation yet. | ||
| # Governor Model | ||
|
|
||
| ## Introduction | ||
|
|
||
| A governor models the control system that regulates the output power of a machine. | ||
|
|
||
| ## Types | ||
|
|
||
| There are a few standard Governor models | ||
|
|
||
| - Turbine Governor (See [TGOV1](GovernorTgov1/README.md)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.