Skip to content

Commit dde4bf4

Browse files
committed
EMT 1
1 parent 0fb771c commit dde4bf4

52 files changed

Lines changed: 3128 additions & 24 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- Added a `TwoArea` integration test comparing flat and hierarchical PhasorDynamics systems.
2929
- Added rate feedback (`Kf`, `Tf`) to the IEEET1 exciters in the `TwoArea` case, whose generators lost synchronism without a fault.
3030
- Added the `state_file` solver option, which sets PhasorDynamics initial bus voltages from a state file.
31+
- Added the EMT model family with `Bus`, `LoadZ` and the `VectorFit` operator, and `Testing::jacobianMatchesResidual`.
3132

3233
## v0.2
3334

‎GridKit/Constants.hpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,8 @@ namespace GridKit
3131

3232
template <typename RealT>
3333
inline constexpr RealT MINUS_ONE = -1.0;
34+
35+
/// SI prefix kilo
36+
template <typename RealT>
37+
inline constexpr RealT KILO = 1.0e3;
3438
} // namespace GridKit

‎GridKit/Model/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# - Cameron Rutherford <cameron.rutherford@pnnl.gov>
66
#]]
77

8+
add_subdirectory(EMT)
89
add_subdirectory(PhasorDynamics)
910
add_subdirectory(PowerFlow)
1011
add_subdirectory(PowerElectronics)

‎GridKit/Model/EMT/Bus/Bus.cpp‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @file Bus.cpp
3+
* @author Luke Lowery (lukel@tamu.edu)
4+
* @brief EMT bus instantiation.
5+
*/
6+
7+
#include "BusImpl.hpp"
8+
9+
namespace GridKit
10+
{
11+
namespace EMT
12+
{
13+
// Available template instantiations
14+
template class Bus<double, size_t>;
15+
} // namespace EMT
16+
} // namespace GridKit

‎GridKit/Model/EMT/Bus/Bus.hpp‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* @file Bus.hpp
3+
* @author Luke Lowery (lukel@tamu.edu)
4+
* @brief Declaration of an EMT bus.
5+
*/
6+
7+
#pragma once
8+
9+
#include <cstddef>
10+
#include <string_view>
11+
12+
#include <GridKit/Model/EMT/Bus/BusData.hpp>
13+
#include <GridKit/Model/EMT/Component.hpp>
14+
15+
namespace GridKit
16+
{
17+
namespace EMT
18+
{
19+
/// Internal variables of a `Bus`, each of size N
20+
enum class BusInternalVariables : size_t
21+
{
22+
v, ///< \f$\mathbf{v}\f$ Bus voltage [V]
23+
};
24+
25+
/// N-phase bus, whose residuals collect the injected currents
26+
template <typename scalar_type, typename index_type>
27+
class Bus final : public Component<scalar_type, index_type>
28+
{
29+
using ComponentT = Component<scalar_type, index_type>;
30+
using IdxT = index_type;
31+
using RealT = typename ComponentT::RealT;
32+
33+
public:
34+
using ModelDataT = BusData<RealT, IdxT>;
35+
using InternalVariablesT = BusInternalVariables;
36+
using PortsT = Utilities::EmptyEnum;
37+
38+
static constexpr std::string_view CLASS_NAME = "Bus";
39+
40+
explicit Bus(const ModelDataT& data);
41+
42+
Model::ConfigurationChecks verify() const override;
43+
int setAbsoluteTolerance(RealT rel_tol) override;
44+
45+
private:
46+
IdxT N_{0};
47+
RealT kv_{ZERO<RealT>};
48+
};
49+
} // namespace EMT
50+
} // namespace GridKit

‎GridKit/Model/EMT/Bus/BusData.hpp‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* @file BusData.hpp
3+
* @author Luke Lowery (lukel@tamu.edu)
4+
* @brief Modeling data for EMT buses.
5+
*/
6+
7+
#pragma once
8+
9+
#include <cstddef>
10+
#include <tuple>
11+
12+
#include <GridKit/Model/EMT/ComponentData.hpp>
13+
14+
namespace GridKit
15+
{
16+
namespace EMT
17+
{
18+
/// Parameters of a `Bus`
19+
enum class BusParameters : size_t
20+
{
21+
N, ///< \f$N\f$ Number of phases
22+
kv, ///< \f$V^\mathrm{base}\f$ Base voltage [kV]
23+
};
24+
25+
/// Data of a `Bus`
26+
template <typename RealT, typename IdxT>
27+
struct BusData
28+
{
29+
using Parameters = BusParameters;
30+
31+
IdxT N{0};
32+
RealT kv{ZERO<RealT>};
33+
34+
static constexpr std::tuple PARAMETERS{Parameter{Parameters::N, &BusData::N}, Parameter{Parameters::kv, &BusData::kv}};
35+
};
36+
} // namespace EMT
37+
} // namespace GridKit

‎GridKit/Model/EMT/Bus/BusImpl.hpp‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* @file BusImpl.hpp
3+
* @author Luke Lowery (lukel@tamu.edu)
4+
* @brief Definition of an EMT bus.
5+
*/
6+
7+
#pragma once
8+
9+
#include <algorithm>
10+
11+
#include <GridKit/Model/EMT/Bus/Bus.hpp>
12+
#include <GridKit/Model/EMT/ComponentImpl.hpp>
13+
14+
namespace GridKit
15+
{
16+
namespace EMT
17+
{
18+
template <typename scalar_type, typename index_type>
19+
Bus<scalar_type, index_type>::Bus(const ModelDataT& data)
20+
: N_(data.N),
21+
kv_(data.kv)
22+
{
23+
this->setLayout({N_}, {});
24+
}
25+
26+
template <typename scalar_type, typename index_type>
27+
Model::ConfigurationChecks Bus<scalar_type, index_type>::verify() const
28+
{
29+
Model::ConfigurationChecks checks("Bus");
30+
checks.check(N_ > 0, "N must be positive");
31+
checks.check(kv_ > ZERO<RealT>, "kv must be positive");
32+
return checks;
33+
}
34+
35+
/// Voltages at the bus base voltage
36+
template <typename scalar_type, typename index_type>
37+
int Bus<scalar_type, index_type>::setAbsoluteTolerance(RealT rel_tol)
38+
{
39+
std::ranges::fill(this->absoluteTolerance(BusInternalVariables::v), rel_tol * KILO<RealT> * kv_);
40+
return 0;
41+
}
42+
} // namespace EMT
43+
} // namespace GridKit
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
gridkit_add_library(
2+
emt_bus
3+
SOURCES Bus.cpp
4+
HEADERS Bus.hpp BusData.hpp
5+
LINK_LIBRARIES PUBLIC GridKit::emt_core)
6+
7+
target_link_libraries(
8+
emt_components
9+
INTERFACE GridKit::emt_bus)

‎GridKit/Model/EMT/Bus/README.md‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ Figure 1: Bus model
1717
Symbol | Units | JSON | Description | Note
1818
------ | ----- | ---- | ----------- | ----
1919
$N$ | [-] | `N` | Number of phases | Required, positive integer
20+
$V^\mathrm{base}$ | [kV] | `kv` | Base voltage | Required, positive
2021

2122
### Parameter Validation
2223

2324
```math
24-
N \in \mathbb{Z}_{>0}
25+
\begin{aligned}
26+
N &\in \mathbb{Z}_{>0} \\
27+
V^\mathrm{base} &\in \mathbb{R}_{>0}
28+
\end{aligned}
2529
```
2630

2731
### Model Derived Parameters
@@ -30,10 +34,7 @@ None.
3034

3135
## Model Ports
3236

33-
Symbol | Port | Type | Units | Description | Note
34-
------ | ---- | ---- | ----- | ----------- | ----
35-
$\mathbf{i}_d$ | `i` | Input | [A] | Current from connected device $d$ | One port per $d \in \mathcal{D}$, $\mathbf{i}_d \in \mathbb{R}^N$
36-
$\mathbf{v}$ | `v` | Output | [V] | Bus voltage supplied to connected devices | $\mathbf{v} \in \mathbb{R}^N$
37+
None.
3738

3839
## Submodels
3940

‎GridKit/Model/EMT/CMakeLists.txt‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
if(GRIDKIT_ENABLE_ENZYME)
2+
add_library(emt_components INTERFACE)
3+
4+
gridkit_add_library(
5+
emt_core
6+
INTERFACE_TARGET
7+
HEADERS Component.hpp ComponentData.hpp
8+
LINK_LIBRARIES
9+
INTERFACE
10+
GridKit::definitions
11+
INTERFACE
12+
GridKit::Utilities
13+
INTERFACE
14+
GridKit::dense_vector
15+
INTERFACE
16+
GridKit::sparse_matrix
17+
INTERFACE
18+
GridKit::utilities_logger)
19+
20+
target_link_libraries(emt_components INTERFACE GridKit::emt_core)
21+
22+
add_subdirectory(Bus)
23+
add_subdirectory(Component)
24+
add_subdirectory(Operators)
25+
26+
add_library(GridKit::emt_components ALIAS emt_components)
27+
28+
gridkit_add_library(
29+
emt_systemmodel
30+
SOURCES SystemModel.cpp SystemModelData.cpp
31+
HEADERS SystemModel.hpp
32+
SystemModelData.hpp
33+
ComponentLibrary.hpp
34+
Monitor.hpp
35+
StateJSONParser.hpp
36+
LINK_LIBRARIES
37+
PUBLIC
38+
GridKit::emt_components
39+
PUBLIC
40+
GridKit::dense_vector
41+
PUBLIC
42+
GridKit::sparse_matrix
43+
INCLUDE_DIRECTORIES PRIVATE ${GRIDKIT_THIRD_PARTY_DIR}/nlohmann-json/include)
44+
45+
install(TARGETS emt_components EXPORT gridkit-targets)
46+
endif()

0 commit comments

Comments
 (0)