Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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 @@ -50,6 +50,7 @@
- Added phasor dynamics application to generalize examples
- Added LoadZIP model component type.
- Added component model developer checklist to a README file.
- Added node objects to `PowerElectronics` module & updated all examples to make use of them.

## v0.1

Expand Down
19 changes: 19 additions & 0 deletions GridKit/Model/PowerElectronics/Bus/Bus.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <GridKit/Model/PowerElectronics/NodeBase.hpp>

namespace GridKit
{
namespace PowerElectronics
{
template <typename ScalarT, typename IdxT>
class Bus : public NodeBase<ScalarT, IdxT>
{
public:
Bus()
: NodeBase<ScalarT, IdxT>(1, 0)
{
}
};
} // namespace PowerElectronics
} // namespace GridKit
8 changes: 8 additions & 0 deletions GridKit/Model/PowerElectronics/Bus/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
install(
FILES
Bus.hpp
SignalNode.hpp
InfiniteBus.hpp
MicrogridBus.hpp
DESTINATION
include/GridKit/Model/PowerElectronics/Bus)
44 changes: 44 additions & 0 deletions GridKit/Model/PowerElectronics/Bus/InfiniteBus.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once

#include <GridKit/Model/PowerElectronics/NodeBase.hpp>

namespace GridKit
{
namespace PowerElectronics
{
template <typename ScalarT, typename IdxT>
class InfiniteBus : public NodeBase<ScalarT, IdxT>
{
using NodeBase<ScalarT, IdxT>::y;

public:
InfiniteBus(ScalarT voltage)
: NodeBase<ScalarT, IdxT>(0, 1), voltage_(voltage)
{
}

int initialize() final
{
if (int err_code = NodeBase<ScalarT, IdxT>::initialize())
return err_code;

y()[0] = voltage_;

return 0;
}

int allocate() final
{
if (int err_code = NodeBase<ScalarT, IdxT>::allocate())
return err_code;

this->setExternalConnectionNodes(0, INVALID_INDEX<IdxT>);

return 0;
}

private:
ScalarT voltage_;
};
} // namespace PowerElectronics
} // namespace GridKit
19 changes: 19 additions & 0 deletions GridKit/Model/PowerElectronics/Bus/MicrogridBus.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <GridKit/Model/PowerElectronics/NodeBase.hpp>

namespace GridKit
{
namespace PowerElectronics
{
template <typename ScalarT, typename IdxT>
class MicrogridBus : public NodeBase<ScalarT, IdxT>
{
public:
MicrogridBus()
: NodeBase<ScalarT, IdxT>(2, 0)
{
}
};
} // namespace PowerElectronics
} // namespace GridKit
19 changes: 19 additions & 0 deletions GridKit/Model/PowerElectronics/Bus/SignalNode.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <GridKit/Model/PowerElectronics/NodeBase.hpp>

namespace GridKit
{
namespace PowerElectronics
{
template <typename ScalarT, typename IdxT>
class SignalNode : public NodeBase<ScalarT, IdxT>
{
public:
SignalNode()
: NodeBase<ScalarT, IdxT>(1, 0)
{
}
};
} // namespace PowerElectronics
} // namespace GridKit
2 changes: 2 additions & 0 deletions GridKit/Model/PowerElectronics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ target_include_directories(power_electronics_circuit_node
add_library(GridKit::power_electronics_circuit_node
ALIAS power_electronics_circuit_node)

add_subdirectory(Bus)
add_subdirectory(Capacitor)
add_subdirectory(Resistor)
add_subdirectory(VoltageSource)
Expand All @@ -27,5 +28,6 @@ install(
CircuitNode.hpp
CircuitGraph.hpp
SystemModelPowerElectronics.hpp
NodeBase.hpp
DESTINATION
include/GridKit/Model/PowerElectronics)
2 changes: 1 addition & 1 deletion GridKit/Model/PowerElectronics/CircuitComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace GridKit
{
if (connection_nodes_ == nullptr)
{
connection_nodes_ = new IdxT[size_];
connection_nodes_ = new IdxT[static_cast<size_t>(size_)];
}

connection_nodes_[local_index] = global_index;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ namespace GridKit
template <class ScalarT, typename IdxT>
DistributedGenerator<ScalarT, IdxT>::DistributedGenerator(IdxT id,
DistributedGeneratorParameters<RealT, IdxT> parm,
bool reference_frame)
bool reference_frame,
NodeT* node_ref,
NodeT* node_bus)
: wb_(parm.wb_),
wc_(parm.wc_),
mp_(parm.mp_),
Expand All @@ -35,16 +37,28 @@ namespace GridKit
Lf_(parm.Lf_),
rLc_(parm.rLc_),
Lc_(parm.Lc_),
refframe_(reference_frame)
refframe_(reference_frame),
node_ref_(node_ref),
node_bus_(node_bus)
{
assert(refframe_ || node_ref_->size() == 1);
assert(node_bus_->size() == 2);
// internals [\delta_i, Pi, Qi, phi_di, phi_qi, gamma_di, gamma_qi, il_di, il_qi, vo_di, vo_qi, io_di, io_qi]
// externals [\omega_ref, vba_out, vbb_out]
size_ = 16;
n_intern_ = 13;
n_extern_ = 3;
extern_indices_ = {0, 1, 2};
idc_ = id;
nnz_ = refframe_ ? 80 : 78;
size_ = 16;
n_intern_ = refframe_ ? 12 : 13;
n_extern_ = refframe_ ? 4 : 3;
idc_ = id;
nnz_ = refframe_ ? 80 : 78;

if (refframe_)
{
extern_indices_ = {0, 1, 2, 3};
}
else
{
extern_indices_ = {0, 1, 2};
}
}

template <class ScalarT, typename IdxT>
Expand Down Expand Up @@ -355,6 +369,23 @@ namespace GridKit
return 0;
}

template <class ScalarT, typename IdxT>
int DistributedGenerator<ScalarT, IdxT>::allocate()
{
CircuitComponent<ScalarT, IdxT>::allocate();

this->setExternalConnectionNodes(0, node_ref_->getNodeConnection(0));
this->setExternalConnectionNodes(1, node_bus_->getNodeConnection(0));
this->setExternalConnectionNodes(2, node_bus_->getNodeConnection(1));

if (refframe_)
{
this->setExternalConnectionNodes(3, INVALID_INDEX<IdxT>);
}

return 0;
}

template <class ScalarT, typename IdxT>
int DistributedGenerator<ScalarT, IdxT>::evaluateIntegrand()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#pragma once

#include <GridKit/Model/PowerElectronics/CircuitComponent.hpp>
#include <GridKit/Model/PowerElectronics/NodeBase.hpp>

namespace GridKit
{
Expand Down Expand Up @@ -40,6 +41,7 @@ namespace GridKit
class DistributedGenerator : public CircuitComponent<ScalarT, IdxT>
{
using RealT = typename CircuitComponent<ScalarT, IdxT>::RealT;
using NodeT = typename PowerElectronics::NodeBase<ScalarT, IdxT>;

using CircuitComponent<ScalarT, IdxT>::size_;
using CircuitComponent<ScalarT, IdxT>::nnz_;
Expand All @@ -64,10 +66,13 @@ namespace GridKit
public:
DistributedGenerator(IdxT id,
DistributedGeneratorParameters<RealT, IdxT> parm,
bool reference_frame);
bool reference_frame,
NodeT* node_ref,
NodeT* node_bus);
virtual ~DistributedGenerator();

int initialize();
int allocate() final;
int tagDifferentiable();
int evaluateResidual();
int evaluateJacobian();
Expand All @@ -94,5 +99,8 @@ namespace GridKit
RealT rLc_;
RealT Lc_;
bool refframe_;

NodeT* node_ref_;
NodeT* node_bus_;
};
} // namespace GridKit
18 changes: 15 additions & 3 deletions GridKit/Model/PowerElectronics/Inductor/Inductor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "Inductor.hpp"

#include <cmath>
#include <iostream>
#include <vector>

namespace GridKit
Expand All @@ -16,9 +15,11 @@ namespace GridKit
*/

template <class ScalarT, typename IdxT>
Inductor<ScalarT, IdxT>::Inductor(IdxT id, RealT L)
: L_(L)
Inductor<ScalarT, IdxT>::Inductor(IdxT id, RealT L, NodeT* node1, NodeT* node2)
: L_(L), node1_(node1), node2_(node2)
{
assert(node1_->size() == 1);
assert(node2_->size() == 1);
size_ = 3;
n_intern_ = 1;
n_extern_ = 2;
Expand Down Expand Up @@ -87,6 +88,17 @@ namespace GridKit
return 0;
}

template <class ScalarT, typename IdxT>
int Inductor<ScalarT, IdxT>::allocate()
{
CircuitComponent<ScalarT, IdxT>::allocate();

this->setExternalConnectionNodes(0, node1_->getNodeConnection(0));
this->setExternalConnectionNodes(1, node2_->getNodeConnection(0));

return 0;
}

template <class ScalarT, typename IdxT>
int Inductor<ScalarT, IdxT>::evaluateIntegrand()
{
Expand Down
9 changes: 7 additions & 2 deletions GridKit/Model/PowerElectronics/Inductor/Inductor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#pragma once

#include <GridKit/Model/PowerElectronics/CircuitComponent.hpp>
#include <GridKit/Model/PowerElectronics/NodeBase.hpp>

namespace GridKit
{
Expand All @@ -20,6 +21,7 @@ namespace GridKit
class Inductor : public CircuitComponent<ScalarT, IdxT>
{
using RealT = typename CircuitComponent<ScalarT, IdxT>::RealT;
using NodeT = typename PowerElectronics::NodeBase<ScalarT, IdxT>;

using CircuitComponent<ScalarT, IdxT>::size_;
using CircuitComponent<ScalarT, IdxT>::nnz_;
Expand All @@ -42,10 +44,11 @@ namespace GridKit
using CircuitComponent<ScalarT, IdxT>::n_intern_;

public:
Inductor(IdxT id, RealT L);
Inductor(IdxT id, RealT L, NodeT* node1, NodeT* node2);
virtual ~Inductor();

int initialize();
int allocate() final;
int tagDifferentiable();
int evaluateResidual();
int evaluateJacobian();
Expand All @@ -57,6 +60,8 @@ namespace GridKit
int evaluateAdjointIntegrand();

private:
RealT L_;
RealT L_;
NodeT* node1_;
NodeT* node2_;
};
} // namespace GridKit
16 changes: 14 additions & 2 deletions GridKit/Model/PowerElectronics/MicrogridBusDQ/MicrogridBusDQ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ namespace GridKit
* Timothy C. Green, Section E
*/
template <class ScalarT, typename IdxT>
MicrogridBusDQ<ScalarT, IdxT>::MicrogridBusDQ(IdxT id, RealT RN)
: RN_(RN)
MicrogridBusDQ<ScalarT, IdxT>::MicrogridBusDQ(IdxT id, RealT RN, NodeT* node1)
: RN_(RN), node1_(node1)
{
assert(node1_->size() == 2);
// externals [vbus_d, vbus_q]
size_ = 2;
n_intern_ = 0;
Expand Down Expand Up @@ -94,6 +95,17 @@ namespace GridKit
return 0;
}

template <class ScalarT, typename IdxT>
int MicrogridBusDQ<ScalarT, IdxT>::allocate()
{
CircuitComponent<ScalarT, IdxT>::allocate();

this->setExternalConnectionNodes(0, node1_->getNodeConnection(0));
this->setExternalConnectionNodes(1, node1_->getNodeConnection(1));

return 0;
}

template <class ScalarT, typename IdxT>
int MicrogridBusDQ<ScalarT, IdxT>::evaluateIntegrand()
{
Expand Down
Loading
Loading