Skip to content

Commit

Permalink
Merge pull request #62 from JTS22/attributes
Browse files Browse the repository at this point in the history
This PR introduces a new attribute system to DPsim. Attributes are variable properties that can hold some numerical value, which can then be accessed from the outside by the simulation scheduler or by other components. Attributes can be computed from other attributes, therefore forming a dependency graph which is used in the scheduler to determine the execution order of tasks.

With this PR, every attribute can either be static or dynamic. Static attributes do not have any immediate dependencies, while dynamic attributes can be entirely derived from other attributes. For more details on the distinction between dynamic and static attributes, see this comment in issue #61

The usage of attributes in the component code remains roughly the same, however there are some differences:

- Attributes are public member variables of the components they belong to and they usually have type const Attribute<T>::Ptr.
- Attributes are created in the constructors initialization list. A new attribute can be created with the Attribute<T>::create and Attribute<T>::createDynamic methods.
- To acquire a (mutable) reference to an attribute's underlying data, the dereference operator has to be used twice on the attribute member variable, resulting in **mAttribute.
- Derived attributes can be created using the various derive-functions on the attribute object.
  • Loading branch information
m-mirz authored Apr 25, 2022
2 parents c186af1 + 0465804 commit 40f126f
Show file tree
Hide file tree
Showing 414 changed files with 7,044 additions and 10,150 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_test_linux_fedora.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ jobs:
id: cppcheck
run: |
set -o pipefail
cppcheck --max-configs=32 -j 32 --inline-suppr --error-exitcode=1 -q --enable=warning,performance,portability,information,missingInclude --std=c++11 -I Include/ -I models/Include/ Source/ models/Source/ 2>&1 | tee cppcheck-output.log
cppcheck --max-configs=32 -j 32 --inline-suppr --error-exitcode=1 -q --enable=warning,performance,portability,information,missingInclude --std=c++17 -I Include/ -I models/Include/ Source/ models/Source/ 2>&1 | tee cppcheck-output.log
continue-on-error: true

- name: Print cppcheck errors
Expand Down
2 changes: 1 addition & 1 deletion Examples/Cxx/CIM/CIGRE_MV_PowerFlowTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int main(int argc, char** argv){
auto logger = DPsim::DataLogger::make(simName);
for (auto node : system.mNodes)
{
logger->addAttribute(node->name() + ".V", node->attribute("v"));
logger->logAttribute(node->name() + ".V", node->attribute("v"));
}

Simulation sim(simName, Logger::Level::info);
Expand Down
26 changes: 13 additions & 13 deletions Examples/Cxx/CIM/CIGRE_MV_PowerFlowTest_LoadProfiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int main(int argc, char** argv){
auto logger = DPsim::DataLogger::make(simName);
for (auto node : system.mNodes)
{
logger->addAttribute(node->name(), node->attribute("v"));
logger->logAttribute(node->name(), node->attribute("v"));
std::list<std::shared_ptr<CPS::SP::Ph1::PiLine>> lines;
for (auto comp : system.mComponentsAtNode[node]) {
if (std::shared_ptr<CPS::SP::Ph1::PiLine> line =
Expand All @@ -89,16 +89,16 @@ int main(int argc, char** argv){
String p_branch = (node->name() == line->node(0)->name()) ? ("p_branch") : ("p_branch_1");
String q_branch = (node->name() == line->node(0)->name()) ? ("q_branch") : ("q_branch_1");

logger->addAttribute(line->name() + "." + node->name() + ".I", line->attribute<Complex>(current));
logger->addAttribute(line->name() + "." + node->name() + ".P", line->attribute<Real>(p_branch));
logger->addAttribute(line->name() + "." + node->name() + ".Q", line->attribute<Real>(q_branch));
logger->logAttribute(line->name() + "." + node->name() + ".I", line->attribute<Complex>(current));
logger->logAttribute(line->name() + "." + node->name() + ".P", line->attribute<Real>(p_branch));
logger->logAttribute(line->name() + "." + node->name() + ".Q", line->attribute<Real>(q_branch));
lines.push_back(line);
}
else if (std::shared_ptr<CPS::SP::Ph1::NetworkInjection> extnet =
std::dynamic_pointer_cast<CPS::SP::Ph1::NetworkInjection>(comp))
{
logger->addAttribute(node->name() + ".Pinj", extnet->attribute<Real>("p_inj"));
logger->addAttribute(node->name() + ".Qinj", extnet->attribute<Real>("q_inj"));
logger->logAttribute(node->name() + ".Pinj", extnet->attribute<Real>("p_inj"));
logger->logAttribute(node->name() + ".Qinj", extnet->attribute<Real>("q_inj"));
}
else if (std::shared_ptr<CPS::SP::Ph1::Transformer> trafo =
std::dynamic_pointer_cast<CPS::SP::Ph1::Transformer>(comp))
Expand All @@ -107,26 +107,26 @@ int main(int argc, char** argv){
String p_branch = (node->name() == trafo->node(0)->name()) ? ("p_branch") : ("p_branch_1");
String q_branch = (node->name() == trafo->node(0)->name()) ? ("q_branch") : ("q_branch_1");

logger->addAttribute(trafo->name() + "." + node->name() + ".I", trafo->attribute<Complex>(current));
logger->addAttribute(trafo->name() + "." + node->name() + ".P", trafo->attribute<Real>(p_branch));
logger->addAttribute(trafo->name() + "." + node->name() + ".Q", trafo->attribute<Real>(q_branch));
logger->logAttribute(trafo->name() + "." + node->name() + ".I", trafo->attribute<Complex>(current));
logger->logAttribute(trafo->name() + "." + node->name() + ".P", trafo->attribute<Real>(p_branch));
logger->logAttribute(trafo->name() + "." + node->name() + ".Q", trafo->attribute<Real>(q_branch));

}
}
// get nodal injection from specific line or transformer
// (the first line obj connected to the node or, if none, the first trafo)
if (!lines.empty()) {
logger->addAttribute(node->name() + ".Pinj", lines.front()->attribute<Real>("p_inj"));
logger->addAttribute(node->name() + ".Qinj", lines.front()->attribute<Real>("q_inj"));
logger->logAttribute(node->name() + ".Pinj", lines.front()->attribute<Real>("p_inj"));
logger->logAttribute(node->name() + ".Qinj", lines.front()->attribute<Real>("q_inj"));
}
else
{
for (auto comp : system.mComponentsAtNode[node]) {
if (std::shared_ptr<CPS::SP::Ph1::Transformer> trafo =
std::dynamic_pointer_cast<CPS::SP::Ph1::Transformer>(comp))
{
logger->addAttribute(node->name() + ".Pinj", trafo->attribute<Real>("p_inj"));
logger->addAttribute(node->name() + ".Qinj", trafo->attribute<Real>("q_inj"));
logger->logAttribute(node->name() + ".Pinj", trafo->attribute<Real>("p_inj"));
logger->logAttribute(node->name() + ".Qinj", trafo->attribute<Real>("q_inj"));
break;
}

Expand Down
8 changes: 4 additions & 4 deletions Examples/Cxx/CIM/DP_CIGRE_MV_withDG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ int main(int argc, char** argv){
auto loggerPF = DPsim::DataLogger::make(simNamePF);
for (auto node : systemPF.mNodes)
{
loggerPF->addAttribute(node->name() + ".V", node->attribute("v"));
loggerPF->logAttribute(node->name() + ".V", node->attribute("v"));
}

// run powerflow
Expand Down Expand Up @@ -86,19 +86,19 @@ int main(int argc, char** argv){
// log node voltages
for (auto node : systemDP.mNodes)
{
logger->addAttribute(node->name() + ".V", node->attribute("v"));
logger->logAttribute(node->name() + ".V", node->attribute("v"));
}

// log line currents
for (auto comp : systemDP.mComponents) {
if (dynamic_pointer_cast<CPS::DP::Ph1::PiLine>(comp))
logger->addAttribute(comp->name() + ".I", comp->attribute("i_intf"));
logger->logAttribute(comp->name() + ".I", comp->attribute("i_intf"));
}

// log load currents
for (auto comp : systemDP.mComponents) {
if (dynamic_pointer_cast<CPS::DP::Ph1::RXLoad>(comp))
logger->addAttribute(comp->name() + ".I", comp->attribute("i_intf"));
logger->logAttribute(comp->name() + ".I", comp->attribute("i_intf"));
}

// log output of PV connected at N11
Expand Down
8 changes: 4 additions & 4 deletions Examples/Cxx/CIM/DP_CIGRE_MV_withDG_withLoadStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int main(int argc, char** argv){
// define logging
auto loggerPF = DPsim::DataLogger::make(simNamePF);
for (auto node : systemPF.mNodes) {
loggerPF->addAttribute(node->name() + ".V", node->attribute("v"));
loggerPF->logAttribute(node->name() + ".V", node->attribute("v"));
}

// run powerflow
Expand Down Expand Up @@ -82,19 +82,19 @@ int main(int argc, char** argv){
// log node voltages
for (auto node : systemDP.mNodes)
{
logger->addAttribute(node->name() + ".V", node->attribute("v"));
logger->logAttribute(node->name() + ".V", node->attribute("v"));
}

// log line currents
for (auto comp : systemDP.mComponents) {
if (dynamic_pointer_cast<CPS::DP::Ph1::PiLine>(comp))
logger->addAttribute(comp->name() + ".I", comp->attribute("i_intf"));
logger->logAttribute(comp->name() + ".I", comp->attribute("i_intf"));
}

// log load currents
for (auto comp : systemDP.mComponents) {
if (dynamic_pointer_cast<CPS::DP::Ph1::RXLoad>(comp))
logger->addAttribute(comp->name() + ".I", comp->attribute("i_intf"));
logger->logAttribute(comp->name() + ".I", comp->attribute("i_intf"));
}

// log output of PV connected at N11
Expand Down
8 changes: 4 additions & 4 deletions Examples/Cxx/CIM/DP_CIGRE_MV_withoutDG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int main(int argc, char** argv){
auto loggerPF = DPsim::DataLogger::make(simNamePF);
for (auto node : systemPF.mNodes)
{
loggerPF->addAttribute(node->name() + ".V", node->attribute("v"));
loggerPF->logAttribute(node->name() + ".V", node->attribute("v"));
}
Simulation simPF(simNamePF, Logger::Level::debug);
simPF.setSystem(systemPF);
Expand All @@ -78,19 +78,19 @@ int main(int argc, char** argv){
// log node voltages
for (auto node : systemDP.mNodes)
{
logger->addAttribute(node->name() + ".V", node->attribute("v"));
logger->logAttribute(node->name() + ".V", node->attribute("v"));
}

// log line currents
for (auto comp : systemDP.mComponents) {
if (dynamic_pointer_cast<CPS::DP::Ph1::PiLine>(comp))
logger->addAttribute(comp->name() + ".I", comp->attribute("i_intf"));
logger->logAttribute(comp->name() + ".I", comp->attribute("i_intf"));
}

// log load currents
for (auto comp : systemDP.mComponents) {
if (dynamic_pointer_cast<CPS::DP::Ph1::RXLoad>(comp))
logger->addAttribute(comp->name() + ".I", comp->attribute("i_intf"));
logger->logAttribute(comp->name() + ".I", comp->attribute("i_intf"));
}

Simulation sim(simName, Logger::Level::debug);
Expand Down
22 changes: 11 additions & 11 deletions Examples/Cxx/CIM/DP_WSCC-9bus_IdealVS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int main(int argc, char *argv[]) {
auto loggerPF = DPsim::DataLogger::make(simNamePF);
for (auto node : systemPF.mNodes)
{
loggerPF->addAttribute(node->name() + ".V", node->attribute("v"));
loggerPF->logAttribute(node->name() + ".V", node->attribute("v"));
}

// run powerflow
Expand All @@ -76,20 +76,20 @@ int main(int argc, char *argv[]) {

// Logging
auto logger = DataLogger::make(simName);
logger->addAttribute("v1", sys.node<SimNode>("BUS1")->attribute("v"));
logger->addAttribute("v2", sys.node<SimNode>("BUS2")->attribute("v"));
logger->addAttribute("v3", sys.node<SimNode>("BUS3")->attribute("v"));
logger->addAttribute("v4", sys.node<SimNode>("BUS4")->attribute("v"));
logger->addAttribute("v5", sys.node<SimNode>("BUS5")->attribute("v"));
logger->addAttribute("v6", sys.node<SimNode>("BUS6")->attribute("v"));
logger->addAttribute("v7", sys.node<SimNode>("BUS7")->attribute("v"));
logger->addAttribute("v8", sys.node<SimNode>("BUS8")->attribute("v"));
logger->addAttribute("v9", sys.node<SimNode>("BUS9")->attribute("v"));
logger->logAttribute("v1", sys.node<SimNode>("BUS1")->attribute("v"));
logger->logAttribute("v2", sys.node<SimNode>("BUS2")->attribute("v"));
logger->logAttribute("v3", sys.node<SimNode>("BUS3")->attribute("v"));
logger->logAttribute("v4", sys.node<SimNode>("BUS4")->attribute("v"));
logger->logAttribute("v5", sys.node<SimNode>("BUS5")->attribute("v"));
logger->logAttribute("v6", sys.node<SimNode>("BUS6")->attribute("v"));
logger->logAttribute("v7", sys.node<SimNode>("BUS7")->attribute("v"));
logger->logAttribute("v8", sys.node<SimNode>("BUS8")->attribute("v"));
logger->logAttribute("v9", sys.node<SimNode>("BUS9")->attribute("v"));

// log generator's current
for (auto comp : sys.mComponents) {
if (std::dynamic_pointer_cast<CPS::DP::Ph1::SynchronGeneratorIdeal>(comp))
logger->addAttribute(comp->name() + ".I", comp->attribute("i_intf"));
logger->logAttribute(comp->name() + ".I", comp->attribute("i_intf"));
}

Simulation sim(simName, Logger::Level::info);
Expand Down
8 changes: 4 additions & 4 deletions Examples/Cxx/CIM/EMT_CIGRE_MV_withDG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int main(int argc, char** argv){
auto loggerPF = DPsim::DataLogger::make(simNamePF);
for (auto node : systemPF.mNodes)
{
loggerPF->addAttribute(node->name() + ".V", node->attribute("v"));
loggerPF->logAttribute(node->name() + ".V", node->attribute("v"));
}

// run powerflow
Expand All @@ -82,18 +82,18 @@ int main(int argc, char** argv){

// log node voltages
for (auto node : systemEMT.mNodes)
logger->addAttribute(node->name() + ".V", node->attribute("v"));
logger->logAttribute(node->name() + ".V", node->attribute("v"));

// log line currents
for (auto comp : systemEMT.mComponents) {
if (dynamic_pointer_cast<CPS::EMT::Ph3::PiLine>(comp))
logger->addAttribute(comp->name() + ".I", comp->attribute("i_intf"));
logger->logAttribute(comp->name() + ".I", comp->attribute("i_intf"));
}

// log load currents
for (auto comp : systemEMT.mComponents) {
if (dynamic_pointer_cast<CPS::EMT::Ph3::RXLoad>(comp))
logger->addAttribute(comp->name() + ".I", comp->attribute("i_intf"));
logger->logAttribute(comp->name() + ".I", comp->attribute("i_intf"));
}

// log output of PV connected at N11
Expand Down
8 changes: 4 additions & 4 deletions Examples/Cxx/CIM/EMT_CIGRE_MV_withDG_withLoadStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int main(int argc, char** argv){
auto loggerPF = DPsim::DataLogger::make(simNamePF);
for (auto node : systemPF.mNodes)
{
loggerPF->addAttribute(node->name() + ".V", node->attribute("v"));
loggerPF->logAttribute(node->name() + ".V", node->attribute("v"));
}

// run powerflow
Expand All @@ -82,18 +82,18 @@ int main(int argc, char** argv){

// log node voltages
for (auto node : systemEMT.mNodes)
logger->addAttribute(node->name() + ".V", node->attribute("v"));
logger->logAttribute(node->name() + ".V", node->attribute("v"));

// log line currents
for (auto comp : systemEMT.mComponents) {
if (dynamic_pointer_cast<CPS::EMT::Ph3::PiLine>(comp))
logger->addAttribute(comp->name() + ".I", comp->attribute("i_intf"));
logger->logAttribute(comp->name() + ".I", comp->attribute("i_intf"));
}

// log load currents
for (auto comp : systemEMT.mComponents) {
if (dynamic_pointer_cast<CPS::EMT::Ph3::RXLoad>(comp))
logger->addAttribute(comp->name() + ".I", comp->attribute("i_intf"));
logger->logAttribute(comp->name() + ".I", comp->attribute("i_intf"));
}

// log output of PV connected at N11
Expand Down
8 changes: 4 additions & 4 deletions Examples/Cxx/CIM/EMT_CIGRE_MV_withoutDG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int main(int argc, char** argv){
auto loggerPF = DPsim::DataLogger::make(simNamePF);
for (auto node : systemPF.mNodes)
{
loggerPF->addAttribute(node->name() + ".V", node->attribute("v"));
loggerPF->logAttribute(node->name() + ".V", node->attribute("v"));
}
Simulation simPF(simNamePF, Logger::Level::debug);
simPF.setSystem(systemPF);
Expand All @@ -75,18 +75,18 @@ int main(int argc, char** argv){

// log node voltages
for (auto node : systemEMT.mNodes)
logger->addAttribute(node->name() + ".V", node->attribute("v"));
logger->logAttribute(node->name() + ".V", node->attribute("v"));

// log line currents
for (auto comp : systemEMT.mComponents) {
if (dynamic_pointer_cast<CPS::EMT::Ph3::PiLine>(comp))
logger->addAttribute(comp->name() + ".I", comp->attribute("i_intf"));
logger->logAttribute(comp->name() + ".I", comp->attribute("i_intf"));
}

// log load currents
for (auto comp : systemEMT.mComponents) {
if (dynamic_pointer_cast<CPS::EMT::Ph3::RXLoad>(comp))
logger->addAttribute(comp->name() + ".I", comp->attribute("i_intf"));
logger->logAttribute(comp->name() + ".I", comp->attribute("i_intf"));
}

Simulation sim(simName, Logger::Level::debug);
Expand Down
22 changes: 11 additions & 11 deletions Examples/Cxx/CIM/EMT_WSCC-9bus_FullOrderSG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int main(int argc, char *argv[]) {
auto loggerPF = DPsim::DataLogger::make(simNamePF);
for (auto node : systemPF.mNodes)
{
loggerPF->addAttribute(node->name() + ".V", node->attribute("v"));
loggerPF->logAttribute(node->name() + ".V", node->attribute("v"));
}

// run powerflow
Expand Down Expand Up @@ -83,20 +83,20 @@ int main(int argc, char *argv[]) {

// Logging
auto logger = DataLogger::make(simName);
logger->addAttribute("v1", sys.node<SimNode>("BUS1")->attribute("v"));
logger->addAttribute("v2", sys.node<SimNode>("BUS2")->attribute("v"));
logger->addAttribute("v3", sys.node<SimNode>("BUS3")->attribute("v"));
logger->addAttribute("v4", sys.node<SimNode>("BUS4")->attribute("v"));
logger->addAttribute("v5", sys.node<SimNode>("BUS5")->attribute("v"));
logger->addAttribute("v6", sys.node<SimNode>("BUS6")->attribute("v"));
logger->addAttribute("v7", sys.node<SimNode>("BUS7")->attribute("v"));
logger->addAttribute("v8", sys.node<SimNode>("BUS8")->attribute("v"));
logger->addAttribute("v9", sys.node<SimNode>("BUS9")->attribute("v"));
logger->logAttribute("v1", sys.node<SimNode>("BUS1")->attribute("v"));
logger->logAttribute("v2", sys.node<SimNode>("BUS2")->attribute("v"));
logger->logAttribute("v3", sys.node<SimNode>("BUS3")->attribute("v"));
logger->logAttribute("v4", sys.node<SimNode>("BUS4")->attribute("v"));
logger->logAttribute("v5", sys.node<SimNode>("BUS5")->attribute("v"));
logger->logAttribute("v6", sys.node<SimNode>("BUS6")->attribute("v"));
logger->logAttribute("v7", sys.node<SimNode>("BUS7")->attribute("v"));
logger->logAttribute("v8", sys.node<SimNode>("BUS8")->attribute("v"));
logger->logAttribute("v9", sys.node<SimNode>("BUS9")->attribute("v"));

// log generator's current
for (auto comp : sys.mComponents) {
if (std::dynamic_pointer_cast<CPS::EMT::Ph3::SynchronGeneratorDQTrapez>(comp))
logger->addAttribute(comp->name() + ".I", comp->attribute("i_intf"));
logger->logAttribute(comp->name() + ".I", comp->attribute("i_intf"));
}

Simulation sim(simName, Logger::Level::info);
Expand Down
22 changes: 11 additions & 11 deletions Examples/Cxx/CIM/EMT_WSCC-9bus_IdealCS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int main(int argc, char *argv[]) {
auto loggerPF = DPsim::DataLogger::make(simNamePF);
for (auto node : systemPF.mNodes)
{
loggerPF->addAttribute(node->name() + ".V", node->attribute("v"));
loggerPF->logAttribute(node->name() + ".V", node->attribute("v"));
}

// run powerflow
Expand Down Expand Up @@ -83,20 +83,20 @@ int main(int argc, char *argv[]) {

// Logging
auto logger = DataLogger::make(simName);
logger->addAttribute("v1", sys.node<SimNode>("BUS1")->attribute("v"));
logger->addAttribute("v2", sys.node<SimNode>("BUS2")->attribute("v"));
logger->addAttribute("v3", sys.node<SimNode>("BUS3")->attribute("v"));
logger->addAttribute("v4", sys.node<SimNode>("BUS4")->attribute("v"));
logger->addAttribute("v5", sys.node<SimNode>("BUS5")->attribute("v"));
logger->addAttribute("v6", sys.node<SimNode>("BUS6")->attribute("v"));
logger->addAttribute("v7", sys.node<SimNode>("BUS7")->attribute("v"));
logger->addAttribute("v8", sys.node<SimNode>("BUS8")->attribute("v"));
logger->addAttribute("v9", sys.node<SimNode>("BUS9")->attribute("v"));
logger->logAttribute("v1", sys.node<SimNode>("BUS1")->attribute("v"));
logger->logAttribute("v2", sys.node<SimNode>("BUS2")->attribute("v"));
logger->logAttribute("v3", sys.node<SimNode>("BUS3")->attribute("v"));
logger->logAttribute("v4", sys.node<SimNode>("BUS4")->attribute("v"));
logger->logAttribute("v5", sys.node<SimNode>("BUS5")->attribute("v"));
logger->logAttribute("v6", sys.node<SimNode>("BUS6")->attribute("v"));
logger->logAttribute("v7", sys.node<SimNode>("BUS7")->attribute("v"));
logger->logAttribute("v8", sys.node<SimNode>("BUS8")->attribute("v"));
logger->logAttribute("v9", sys.node<SimNode>("BUS9")->attribute("v"));

// log generator's current
for (auto comp : sys.mComponents) {
if (std::dynamic_pointer_cast<CPS::EMT::Ph3::SynchronGeneratorIdeal>(comp))
logger->addAttribute(comp->name() + ".I", comp->attribute("i_intf"));
logger->logAttribute(comp->name() + ".I", comp->attribute("i_intf"));
}

Simulation sim(simName, Logger::Level::info);
Expand Down
Loading

0 comments on commit 40f126f

Please sign in to comment.