Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
- Added node objects to `PowerElectronics` module & updated all examples to make use of them.
- Separated internal and external residuals of `PowerElectronics` models.
- Added `CliArgs` class for better management of command-line options.
- Added `BusToSignalAdapter` component.

## v0.1

Expand Down
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 GridKit/Model/PhasorDynamics/BusToSignalAdapter/BusToSignalAdapter.hpp
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)
Copy link
Copy Markdown
Collaborator

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.

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
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
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
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;
Comment thread
PhilipFackler marked this conversation as resolved.
}

} // namespace PhasorDynamics
} // namespace GridKit
Loading
Loading