Repository navigation
Add BusSignalVoltageOut and BusSignalVoltageIn bus models #602
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
6ced8de
Add BusSignalVoltageOut class
pelesh caa6d05
Add BusSignalVoltageIn class
pelesh 6e16768
Apply pre-commit fixes
pelesh 6086963
[skip ci] Update comment in GridKit/Model/PhasorDynamics/SignalIn.hpp
pelesh 6e5211e
Reuse SignalPorts struct instead of creating a custom one.
pelesh afcdb8e
Do not allow BusSignalVoltageIn object to operate without voltage sig…
pelesh 8432186
Don't allow disconnected signal inlets. Throw instead of returning er…
pelesh b3a268a
[skip ci] Use more precise language in code comments.
pelesh 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
17 changes: 17 additions & 0 deletions
17
GridKit/Model/PhasorDynamics/Bus/BusSignalVoltageIn/BusSignalVoltageIn.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,17 @@ | ||
| /** | ||
| * @file BusSignalVoltageIn.cpp | ||
| * @author Slaven Peles (peless@ornl.gov) | ||
| */ | ||
|
|
||
| #include "BusSignalVoltageInImpl.hpp" | ||
|
|
||
| namespace GridKit | ||
| { | ||
| namespace PhasorDynamics | ||
| { | ||
| // Available template instantiations | ||
| template class BusSignalVoltageIn<double, long int>; | ||
| template class BusSignalVoltageIn<double, size_t>; | ||
|
|
||
| } // namespace PhasorDynamics | ||
| } // namespace GridKit |
175 changes: 175 additions & 0 deletions
175
GridKit/Model/PhasorDynamics/Bus/BusSignalVoltageIn/BusSignalVoltageIn.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,175 @@ | ||
| /** | ||
| * @file BusSignalVoltageIn.hpp | ||
| * @author Slaven Peles (peless@ornl.gov) | ||
| * @brief Declaration of a bus whose voltage is set by input signals. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <stdexcept> | ||
| #include <utility> | ||
|
|
||
| #include <GridKit/Constants.hpp> | ||
| #include <GridKit/Model/PhasorDynamics/Bus/BusSignalVoltageIn/BusSignalVoltageInData.hpp> | ||
| #include <GridKit/Model/PhasorDynamics/BusBase.hpp> | ||
| #include <GridKit/Model/PhasorDynamics/SignalPorts.hpp> | ||
|
|
||
| namespace GridKit | ||
| { | ||
| namespace PhasorDynamics | ||
| { | ||
| /*! | ||
| * @brief Bus whose voltage is set by input signals. | ||
| * | ||
| * This is the mirror image of @ref BusSignalVoltageOut. The bus voltage | ||
| * components _Vr_ and _Vi_ are read directly from signal inlets | ||
| * `vr` and `vi` whenever Vr() or Vi() is called; the bus stores no | ||
| * voltage of its own and never modifies it. Both voltage inlets are | ||
| * mandatory: verify() logs an error and throws for an inlet that is not | ||
| * connected to a linked signal, and reading the voltage through an | ||
| * unlinked inlet throws. No default voltage is ever used. The bus has | ||
| * no unknowns and no equations (size() == 0, like @ref BusInfinite). | ||
| * Components attached to the bus add their current injections to Ir() | ||
| * and Ii(); the resulting sums are published on signal outlets `ir` | ||
| * and `ii`. | ||
| * | ||
| * @note Signal ports have to be connected before allocate() is called, since | ||
| * the output signals are linked there. | ||
| * | ||
| * @warning The current sums are complete only after all attached | ||
| * components have evaluated their residuals. A consumer of the | ||
| * `ir` and `ii` signals must be evaluated after them. | ||
| */ | ||
| template <typename scalar_type, typename index_type> | ||
| class BusSignalVoltageIn : public BusBase<scalar_type, index_type> | ||
| { | ||
| using BusBase<scalar_type, index_type>::bus_id_; | ||
| using BusBase<scalar_type, index_type>::size_; | ||
| using BusBase<scalar_type, index_type>::nnz_; | ||
| using BusBase<scalar_type, index_type>::variable_indices_; | ||
| using BusBase<scalar_type, index_type>::residual_indices_; | ||
| using BusBase<scalar_type, index_type>::coo_jac_; | ||
| using BusBase<scalar_type, index_type>::monitor_; | ||
| using BusBase<scalar_type, index_type>::allocated_; | ||
|
|
||
| public: | ||
| using ScalarT = scalar_type; | ||
| using IdxT = index_type; | ||
| using RealT = typename BusBase<ScalarT, IdxT>::RealT; | ||
| using CooMatrixT = typename BusBase<ScalarT, IdxT>::CooMatrixT; | ||
| using MonitorT = typename BusBase<ScalarT, IdxT>::MonitorT; | ||
| using ModelDataT = BusData<RealT, IdxT>; | ||
| using BusTypeT = typename BusData<RealT, IdxT>::BusType; | ||
| using SignalDataT = BusSignalVoltageInData<RealT, IdxT>; | ||
| using SignalPortsT = SignalPorts<ScalarT, SignalDataT>; | ||
|
|
||
| BusSignalVoltageIn(); | ||
| /// Initial voltage arguments are ignored; the voltage comes from signals. | ||
| BusSignalVoltageIn(ScalarT Vr, ScalarT Vi); | ||
| /// Initial voltage in `data` is ignored; the voltage comes from signals. | ||
| BusSignalVoltageIn(const ModelDataT& data); | ||
| virtual ~BusSignalVoltageIn(); | ||
|
|
||
| virtual int setBusID(IdxT) override final; | ||
| virtual int allocate() override final; | ||
| virtual int verify() const override final; | ||
| virtual int tagDifferentiable() override final; | ||
| virtual int setAbsoluteTolerance(RealT rel_tol) override final; | ||
| virtual int initialize() override final; | ||
| virtual int evaluateResidual() override final; | ||
| virtual int evaluateJacobian() override final; | ||
|
|
||
| virtual BusTypeT BusType() const override final | ||
| { | ||
| return BusTypeT::SIGNAL_VOLTAGE_IN; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Bus voltage, real component, read from the `vr` inlet. | ||
| * | ||
| * The BusBase interface requires a mutable reference, but the voltage | ||
| * is owned by the signal source. Callers must not write through it. | ||
| */ | ||
| virtual ScalarT& Vr() override final | ||
| { | ||
| return const_cast<ScalarT&>(std::as_const(*this).Vr()); | ||
| } | ||
|
|
||
| virtual const ScalarT& Vr() const override final | ||
| { | ||
| return readVoltage<BusSignalVoltageInInputs::vr>("vr"); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Bus voltage, imaginary component, read from the `vi` inlet. | ||
| * | ||
| * See Vr() for the note on the mutable overload. | ||
| */ | ||
| virtual ScalarT& Vi() override final | ||
| { | ||
| return const_cast<ScalarT&>(std::as_const(*this).Vi()); | ||
| } | ||
|
|
||
| virtual const ScalarT& Vi() const override final | ||
| { | ||
| return readVoltage<BusSignalVoltageInInputs::vi>("vi"); | ||
| } | ||
|
|
||
| virtual ScalarT& Ir() override final | ||
| { | ||
| return Ir_; | ||
| } | ||
|
|
||
| virtual const ScalarT& Ir() const override final | ||
| { | ||
| return Ir_; | ||
| } | ||
|
|
||
| virtual ScalarT& Ii() override final | ||
| { | ||
| return Ii_; | ||
| } | ||
|
|
||
| virtual const ScalarT& Ii() const override final | ||
| { | ||
| return Ii_; | ||
| } | ||
|
|
||
| SignalPortsT& getPorts() | ||
| { | ||
| return ports_; | ||
| } | ||
|
|
||
| const SignalPortsT& getPorts() const | ||
| { | ||
| return ports_; | ||
| } | ||
|
|
||
| private: | ||
| /// Read a voltage inlet, throwing if it has no linked signal. | ||
| template <BusSignalVoltageInInputs input> | ||
| const ScalarT& readVoltage(const char* name) const | ||
| { | ||
| const auto& port = ports_.in.template port<input>(); | ||
| if (!port.linked()) | ||
| { | ||
| Log::error() << "BusSignalVoltageIn: voltage inlet " << name | ||
| << " read without a linked signal\n"; | ||
| throw std::runtime_error("BusSignalVoltageIn: voltage inlet has no linked signal"); | ||
| } | ||
| return port.readSignal(); | ||
| } | ||
|
|
||
| ScalarT Ir_{0.0}; | ||
| ScalarT Ii_{0.0}; | ||
|
|
||
| /// Current sums are not system variables; the output signals carry no valid index. | ||
| IdxT ir_index_{INVALID_INDEX<IdxT>}; | ||
| IdxT ii_index_{INVALID_INDEX<IdxT>}; | ||
|
|
||
| /// Signal ports (inlets and outlets) | ||
| SignalPortsT ports_; | ||
| }; | ||
|
|
||
| } // namespace PhasorDynamics | ||
| } // namespace GridKit | ||
57 changes: 57 additions & 0 deletions
57
GridKit/Model/PhasorDynamics/Bus/BusSignalVoltageIn/BusSignalVoltageInData.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,57 @@ | ||
| /** | ||
| * @file BusSignalVoltageInData.hpp | ||
| * @author Slaven Peles (peless@ornl.gov) | ||
| * @brief Signal port definitions for BusSignalVoltageIn. | ||
| * | ||
| * BusSignalVoltageIn is constructed from BusData like other buses. This header adds | ||
| * the port enumerations and a ComponentData alias that satisfies the | ||
| * ModelData concept, so the generic SignalPorts container can be reused for | ||
| * the bus's signal ports and connected from component-style data. | ||
| */ | ||
| #pragma once | ||
|
|
||
| #include <cstddef> | ||
|
|
||
| #include <GridKit/Model/PhasorDynamics/Bus/BusData.hpp> | ||
| #include <GridKit/Model/PhasorDynamics/ComponentData.hpp> | ||
|
|
||
| namespace GridKit | ||
| { | ||
| namespace PhasorDynamics | ||
| { | ||
| /// BusSignalVoltageIn has no bus terminals of its own; it is a bus. | ||
| enum class BusSignalVoltageInBuses : size_t | ||
| { | ||
| }; | ||
|
|
||
| /// Signal inlets of a bus with voltage signal inlets and current signal outlets (see BusSignalVoltageIn) | ||
| enum class BusSignalVoltageInInputs : size_t | ||
| { | ||
| vr, ///< Bus voltage, real component | ||
| vi, ///< Bus voltage, imaginary component | ||
| }; | ||
|
|
||
| /// Signal outlets of a bus with voltage signal inlets and current signal outlets (see BusSignalVoltageIn) | ||
| enum class BusSignalVoltageInOutputs : size_t | ||
| { | ||
| ir, ///< Sum of real current injections from attached components | ||
| ii, ///< Sum of imaginary current injections from attached components | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Component-style data for BusSignalVoltageIn signal ports | ||
| * | ||
| * Reuses the bus parameter and monitorable-variable enumerations from | ||
| * BusData. Only the signal maps are used by the bus. | ||
| */ | ||
| template <typename real_type, typename index_type> | ||
| using BusSignalVoltageInData = | ||
| ComponentData<real_type, | ||
| index_type, | ||
| BusParameters, | ||
| BusSignalVoltageInBuses, | ||
| BusSignalVoltageInInputs, | ||
| BusSignalVoltageInOutputs, | ||
| BusMonitorableVariables>; | ||
| } // namespace PhasorDynamics | ||
| } // namespace GridKit |
17 changes: 17 additions & 0 deletions
17
GridKit/Model/PhasorDynamics/Bus/BusSignalVoltageIn/BusSignalVoltageInDependencyTracking.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,17 @@ | ||
| /** | ||
| * @file BusSignalVoltageInDependencyTracking.cpp | ||
| * @author Slaven Peles (peless@ornl.gov) | ||
| */ | ||
|
|
||
| #include "BusSignalVoltageInImpl.hpp" | ||
|
|
||
| namespace GridKit | ||
| { | ||
| namespace PhasorDynamics | ||
| { | ||
| // Available template instantiations | ||
| template class BusSignalVoltageIn<DependencyTracking::Variable, long int>; | ||
| template class BusSignalVoltageIn<DependencyTracking::Variable, size_t>; | ||
|
|
||
| } // namespace PhasorDynamics | ||
| } // namespace GridKit |
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.