-
Notifications
You must be signed in to change notification settings - Fork 7
Introduce cosimulation interface component #401
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
Open
PhilipFackler
wants to merge
5
commits into
develop
Choose a base branch
from
PhilipFackler/cosim
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
67b3501
Introduce cosimulation interface component
PhilipFackler 2bd6e2d
Address PR comments
PhilipFackler b2e6c76
Address incorrect terms
PhilipFackler 15d9961
Update values for index placeholders
PhilipFackler 170747d
Add README and update comments
PhilipFackler 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
20 changes: 20 additions & 0 deletions
20
GridKit/Model/PhasorDynamics/BusToSignalAdapter/BusToSignalAdapter.cpp
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,20 @@ | ||
| /** | ||
| * @file BusToSignalAdapter.cpp | ||
| * @author Philip Fackler (facklerpw@ornl.gov) | ||
| * | ||
| * @brief Definition of BusToSignalAdapter component | ||
| * | ||
| */ | ||
|
|
||
| #include "BusToSignalAdapterImpl.hpp" | ||
|
|
||
| namespace GridKit | ||
| { | ||
| namespace PhasorDynamics | ||
| { | ||
| // Available template instantiations | ||
| template class BusToSignalAdapter<double, long int>; | ||
| template class BusToSignalAdapter<double, size_t>; | ||
|
|
||
| } // namespace PhasorDynamics | ||
| } // namespace GridKit |
104 changes: 104 additions & 0 deletions
104
GridKit/Model/PhasorDynamics/BusToSignalAdapter/BusToSignalAdapter.hpp
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,104 @@ | ||
| /** | ||
| * @file BusToSignalAdapter.hpp | ||
| * @author Philip Fackler (facklerpw@ornl.gov) | ||
| * | ||
| * @brief Declaration of a BusToSignalAdapter component | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <GridKit/Constants.hpp> | ||
| #include <GridKit/Model/PhasorDynamics/Component.hpp> | ||
| #include <GridKit/Model/PhasorDynamics/ComponentSignals.hpp> | ||
|
|
||
| // Forward declarations | ||
| namespace GridKit | ||
| { | ||
| namespace PhasorDynamics | ||
| { | ||
| template <typename RealT, typename IdxT> | ||
| struct BusToSignalAdapterData; | ||
|
|
||
| template <class ScalarT, typename IdxT> | ||
| class BusBase; | ||
|
|
||
| template <class ScalarT, typename IdxT> | ||
| class SignalNode; | ||
| } // namespace PhasorDynamics | ||
| } // namespace GridKit | ||
|
|
||
| namespace GridKit | ||
| { | ||
| namespace PhasorDynamics | ||
| { | ||
| /** | ||
| * @brief Internal variables of a `BusToSignalAdapter` | ||
| * | ||
| * @note Technically these are not owned by this component, but they must | ||
| * be classified as internal so that they can be written to signal nodes | ||
| * in `ComponentSignals` | ||
| */ | ||
| enum class BusToSignalAdapterInternalVariables : size_t | ||
| { | ||
| VREAL, | ||
| VIMAG, | ||
| MAXIMUM, | ||
| }; | ||
|
|
||
| /// External variables of a `BusToSignalAdapter` | ||
| enum class BusToSignalAdapterExternalVariables : size_t | ||
| { | ||
| IREAL, | ||
| IIMAG, | ||
| MAXIMUM, | ||
| }; | ||
|
|
||
| template <class ScalarT, typename IdxT> | ||
| class BusToSignalAdapter : public Component<ScalarT, IdxT> | ||
| { | ||
| using Component<ScalarT, IdxT>::gridkit_component_id_; | ||
| using Component<ScalarT, IdxT>::size_; | ||
|
|
||
| public: | ||
| using RealT = typename Component<ScalarT, IdxT>::RealT; | ||
| using model_data_type = BusToSignalAdapterData<RealT, IdxT>; | ||
| using signal_type = SignalNode<ScalarT, IdxT>; | ||
| using bus_type = BusBase<ScalarT, IdxT>; | ||
|
|
||
| BusToSignalAdapter(bus_type* bus); | ||
| ~BusToSignalAdapter(); | ||
|
|
||
| int setGridKitComponentID(IdxT) override final; | ||
| int allocate() override final; | ||
| int verify() const override final; | ||
| int initialize() override final; | ||
| int tagDifferentiable() override final; | ||
| int evaluateResidual() override final; | ||
| int evaluateJacobian() override final; | ||
|
|
||
| /// Get the `ComponentSignals` from this `BusToSignalAdapter` | ||
| auto getSignals() | ||
| -> ComponentSignals<ScalarT, | ||
| IdxT, | ||
| BusToSignalAdapterInternalVariables, | ||
| BusToSignalAdapterExternalVariables>& | ||
| { | ||
| return signals_; | ||
| } | ||
|
|
||
| private: | ||
| // Placeholders for variable indices (see note in allocate() method) | ||
| IdxT vr_index_{INVALID_INDEX<IdxT>}; | ||
| IdxT vi_index_{INVALID_INDEX<IdxT>}; | ||
|
|
||
| // Signal pointers | ||
| signal_type* ir_signal_; | ||
| signal_type* ii_signal_; | ||
| bus_type* bus_; | ||
|
|
||
| /// Component signal extension | ||
| ComponentSignals<ScalarT, IdxT, BusToSignalAdapterInternalVariables, BusToSignalAdapterExternalVariables> signals_; | ||
| }; | ||
|
|
||
| } // namespace PhasorDynamics | ||
| } // namespace GridKit | ||
68 changes: 68 additions & 0 deletions
68
GridKit/Model/PhasorDynamics/BusToSignalAdapter/BusToSignalAdapterData.hpp
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,68 @@ | ||
| /** | ||
| * @file BusToSignalAdapterData.hpp | ||
| * @author Philip Fackler (facklerpw@ornl.gov) | ||
| * | ||
| * @brief Data structure for BusToSignalAdapter Data | ||
| * | ||
| */ | ||
| #pragma once | ||
|
|
||
| #include <GridKit/Model/PhasorDynamics/ComponentData.hpp> | ||
|
|
||
| namespace GridKit | ||
| { | ||
| namespace PhasorDynamics | ||
| { | ||
| /** | ||
| * @brief Parameter keys for BusToSignalAdapter component | ||
| * | ||
| * These enum values serve as keys for the parameters map in ComponentData. | ||
| */ | ||
| enum class BusToSignalAdapterParameters | ||
| { | ||
| NONE, | ||
| }; | ||
|
|
||
| /** | ||
| * @brief BusToSignalAdapter ports | ||
| */ | ||
| enum class BusToSignalAdapterPorts | ||
| { | ||
| bus, | ||
| vr, | ||
| vi, | ||
| ir, | ||
| ii, | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Placeholder enum for BusToSignalAdapter monitorable variables | ||
| */ | ||
| enum class BusToSignalAdapterMonitorableVariables | ||
| { | ||
| NONE, | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Modeling data for BusToSignalAdapter using ComponentData base | ||
| * | ||
| * @tparam RealT Real number type (e.g., double) | ||
| * @tparam IdxT Index type (e.g., size_t) | ||
| */ | ||
| template <typename RealT, typename IdxT> | ||
| struct BusToSignalAdapterData | ||
| : public ComponentData<RealT, | ||
| IdxT, | ||
| BusToSignalAdapterParameters, | ||
| BusToSignalAdapterPorts, | ||
| BusToSignalAdapterMonitorableVariables> | ||
| { | ||
| BusToSignalAdapterData() = default; | ||
|
|
||
| using Parameters = BusToSignalAdapterParameters; | ||
| using Ports = BusToSignalAdapterPorts; | ||
| using MonitorableVariables = BusToSignalAdapterMonitorableVariables; | ||
| }; | ||
|
|
||
| } // namespace PhasorDynamics | ||
| } // namespace GridKit |
20 changes: 20 additions & 0 deletions
20
GridKit/Model/PhasorDynamics/BusToSignalAdapter/BusToSignalAdapterDependencyTracking.cpp
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,20 @@ | ||
| /** | ||
| * @file BusToSignalAdapterDependencyTracking.cpp | ||
| * @author Philip Fackler (facklerpw@ornl.gov) | ||
| * | ||
| * @brief Deinition of BusToSignalAdapter connector interface. | ||
| * | ||
| */ | ||
|
|
||
| #include "BusToSignalAdapterImpl.hpp" | ||
|
|
||
| namespace GridKit | ||
| { | ||
| namespace PhasorDynamics | ||
| { | ||
| // Available template instantiations | ||
| template class BusToSignalAdapter<DependencyTracking::Variable, long int>; | ||
| template class BusToSignalAdapter<DependencyTracking::Variable, size_t>; | ||
|
|
||
| } // namespace PhasorDynamics | ||
| } // namespace GridKit |
154 changes: 154 additions & 0 deletions
154
GridKit/Model/PhasorDynamics/BusToSignalAdapter/BusToSignalAdapterImpl.hpp
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,154 @@ | ||
| /** | ||
| * @file BusToSignalAdapterImpl.cpp | ||
| * @author Philip Fackler (facklerpw@ornl.gov) | ||
| * | ||
| * @brief Definition of a BusToSignalAdapter component. | ||
| * | ||
| */ | ||
|
|
||
| #include <GridKit/Model/PhasorDynamics/Bus/Bus.hpp> | ||
| #include <GridKit/Model/PhasorDynamics/BusToSignalAdapter/BusToSignalAdapter.hpp> | ||
| #include <GridKit/Model/PhasorDynamics/BusToSignalAdapter/BusToSignalAdapterData.hpp> | ||
| #include <GridKit/Model/PhasorDynamics/SignalNode/SignalNode.hpp> | ||
| #include <GridKit/Utilities/Logger/Logger.hpp> | ||
|
|
||
| namespace GridKit | ||
| { | ||
| namespace PhasorDynamics | ||
| { | ||
| using Log = ::GridKit::Utilities::Logger; | ||
|
|
||
| /** | ||
| * @brief Constructor for BusToSignalAdapter component | ||
| * | ||
| * @param bus Signal used for voltage | ||
| * @param data Data object | ||
| */ | ||
| template <typename ScalarT, typename IdxT> | ||
| BusToSignalAdapter<ScalarT, IdxT>::BusToSignalAdapter(bus_type* bus) | ||
| : bus_(bus) | ||
| { | ||
| size_ = 0; | ||
| } | ||
|
|
||
| template <class ScalarT, typename IdxT> | ||
| BusToSignalAdapter<ScalarT, IdxT>::~BusToSignalAdapter() | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * @brief Set the component ID | ||
| */ | ||
| template <class ScalarT, typename IdxT> | ||
| int BusToSignalAdapter<ScalarT, IdxT>::setGridKitComponentID(IdxT component_id) | ||
| { | ||
| gridkit_component_id_ = component_id; | ||
| return 0; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Allocate memory for model | ||
| */ | ||
| template <class ScalarT, typename IdxT> | ||
| int BusToSignalAdapter<ScalarT, IdxT>::allocate() | ||
| { | ||
| static constexpr auto VREAL = BusToSignalAdapterInternalVariables::VREAL; | ||
| static constexpr auto VIMAG = BusToSignalAdapterInternalVariables::VIMAG; | ||
|
|
||
| // vr_index_ and vi_index_ are both set to INVALID_INDEX. This component | ||
| // simply passes voltage from bus to output signal, so indices are | ||
| // ignored. | ||
| if (signals_.template isAssigned<VREAL>()) | ||
| { | ||
| signals_.template getSignalNode<VREAL>()->set(&bus_->Vr(), &vr_index_); | ||
| } | ||
| if (signals_.template isAssigned<VIMAG>()) | ||
| { | ||
| signals_.template getSignalNode<VIMAG>()->set(&bus_->Vi(), &vi_index_); | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| /** | ||
| * @brief verify method checks that attached signals are also linked | ||
| */ | ||
| template <class ScalarT, typename IdxT> | ||
| int BusToSignalAdapter<ScalarT, IdxT>::verify() const | ||
| { | ||
| static constexpr auto IREAL = BusToSignalAdapterExternalVariables::IREAL; | ||
| static constexpr auto IIMAG = BusToSignalAdapterExternalVariables::IIMAG; | ||
|
|
||
| int ret = 0; | ||
|
|
||
| if (signals_.template isAttached<IREAL>()) | ||
| { | ||
| if (!signals_.template isLinked<IREAL>()) | ||
| { | ||
| Log::error() << "BusToSignalAdapter: Ir signal attached with no linked source\n"; | ||
| ret += 1; | ||
| } | ||
| } | ||
|
|
||
| if (signals_.template isAttached<IIMAG>()) | ||
| { | ||
| if (!signals_.template isLinked<IIMAG>()) | ||
| { | ||
| Log::error() << "BusToSignalAdapter: Ii signal attached with no linked source\n"; | ||
| ret += 1; | ||
| } | ||
| } | ||
|
|
||
| return ret; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Initialize the adapter | ||
| */ | ||
| template <class ScalarT, typename IdxT> | ||
| int BusToSignalAdapter<ScalarT, IdxT>::initialize() | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| /** | ||
| * @brief No variables to differentiate | ||
| */ | ||
| template <class ScalarT, typename IdxT> | ||
| int BusToSignalAdapter<ScalarT, IdxT>::tagDifferentiable() | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Residual evaluation | ||
| */ | ||
| template <class ScalarT, typename IdxT> | ||
| int BusToSignalAdapter<ScalarT, IdxT>::evaluateResidual() | ||
| { | ||
| static constexpr auto IREAL = BusToSignalAdapterExternalVariables::IREAL; | ||
| static constexpr auto IIMAG = BusToSignalAdapterExternalVariables::IIMAG; | ||
|
|
||
| if (signals_.template isAttached<IREAL>()) | ||
| { | ||
| bus_->Ir() += signals_.template readExternalVariable<IREAL>(); | ||
| } | ||
| if (signals_.template isAttached<IIMAG>()) | ||
| { | ||
| bus_->Ii() += signals_.template readExternalVariable<IIMAG>(); | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Jacobian evaluation | ||
| */ | ||
| template <class ScalarT, typename IdxT> | ||
| int BusToSignalAdapter<ScalarT, IdxT>::evaluateJacobian() | ||
| { | ||
| return 0; | ||
|
PhilipFackler marked this conversation as resolved.
|
||
| } | ||
|
|
||
| } // namespace PhasorDynamics | ||
| } // namespace GridKit | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the comments. I would include somewhere in those comments that this component only passes bus voltages and updates residual information, which justifies ignoring the indices.