Skip to content

Commit

Permalink
#216 Add shunt connections to dyd
Browse files Browse the repository at this point in the history
  • Loading branch information
Le Courtois Florent committed Oct 5, 2021
1 parent d874f8b commit 489f5b0
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 16 deletions.
3 changes: 2 additions & 1 deletion sources/Algo/include/Algo.h
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,9 @@ struct VLShuntsDefinition {
struct ShuntHash {
size_t operator()(const inputs::Shunt& shunt) const noexcept;
};
using ShuntsSet = std::unordered_set<inputs::Shunt, ShuntHash>;

std::unordered_set<inputs::Shunt, ShuntHash> shunts;
ShuntsSet shunts;
bool dynamicModelAssociated = false;
};

Expand Down
2 changes: 1 addition & 1 deletion sources/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ Context::exportOutputs() {
file::path dydOutput(config_.outputDir());
dydOutput.append(basename_ + ".dyd");
outputs::Dyd dydWriter(outputs::Dyd::DydDefinition(basename_, dydOutput.generic_string(), generators_, loads_, slackNode_, hvdcLineDefinitions_,
busesWithDynamicModel_, dynamicDataBaseManager_, dynamicModels_, svarcsDefinitions_));
busesWithDynamicModel_, dynamicDataBaseManager_, dynamicModels_, svarcsDefinitions_, shunts_));
dydWriter.write();

// Par
Expand Down
5 changes: 5 additions & 0 deletions sources/Outputs/include/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ computeQmax(double powerFactor, double pMax) {
*/
std::string diagramFilename(const std::string& id);

static inline std::string
computeShuntRegulationId(const std::string& busId) {
return "ShuntRegulation_" + busId;
}

const std::string loadParId{"GenericRestorativeLoad"}; ///< PAR id common to all loads
const std::string diagramDirectorySuffix{"_Diagram"}; ///< Suffix for the diagram directory
const std::string diagramMaxTableSuffix{"_tableqmax"}; ///< Suffix for the table name for qmax in diagram file
Expand Down
11 changes: 9 additions & 2 deletions sources/Outputs/include/Dyd.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class Dyd {
const std::vector<algo::LoadDefinition>& loaddefs, const std::shared_ptr<inputs::Node>& slacknode,
const algo::HVDCLineDefinitions& hvdcDefinitions, const algo::GeneratorDefinitionAlgorithm::BusGenMap& busesWithDynamicModel,
const inputs::DynamicDataBaseManager& dynamicDataBaseManager, const algo::DynamicModelDefinitions& models,
const algo::StaticVarCompensatorDefinitions& svarcsDefinitions) :
const algo::StaticVarCompensatorDefinitions& svarcsDefinitions, const algo::ShuntDefinitions& shuntsDefinitions) :
basename(base),
filename(filepath),
generators(gens),
Expand All @@ -119,7 +119,8 @@ class Dyd {
busesWithDynamicModel(busesWithDynamicModel),
dynamicDataBaseManager(dynamicDataBaseManager),
dynamicModelsDefinitions(models),
svarcsDefinitions(svarcsDefinitions) {}
svarcsDefinitions(svarcsDefinitions),
shuntsDefinitions(shuntsDefinitions) {}

std::string basename; ///< basename for file
std::string filename; ///< filepath for file to write
Expand All @@ -131,6 +132,7 @@ class Dyd {
const inputs::DynamicDataBaseManager& dynamicDataBaseManager; ///< dynamic database manager
const algo::DynamicModelDefinitions& dynamicModelsDefinitions; ///< the list of dynamic models to export
const algo::StaticVarCompensatorDefinitions& svarcsDefinitions; ///< the SVarC definitions to use
const algo::ShuntDefinitions& shuntsDefinitions;
};

/**
Expand Down Expand Up @@ -186,6 +188,8 @@ class Dyd {
*/
static boost::shared_ptr<dynamicdata::BlackBoxModel> writeHvdcLine(const algo::HVDCDefinition& hvdcLine, const std::string& basename);

static boost::shared_ptr<dynamicdata::BlackBoxModel> writeShuntRegulation(const inputs::Shunt::BusId& busId, const std::string& basename);

/**
* @brief Create constant models
*
Expand Down Expand Up @@ -302,6 +306,9 @@ class Dyd {
*/
static boost::shared_ptr<dynamicdata::MacroConnect> writeSVarCMacroConnect(const inputs::StaticVarCompensator& svarc);

static std::unordered_map<inputs::Shunt::BusId, std::vector<std::reference_wrapper<const inputs::Shunt>>>
computeShuntsByIds(const algo::ShuntDefinitions& shuntDefinitions);

private:
static const std::unordered_map<algo::GeneratorDefinition::ModelType, std::string>
correspondence_lib_; ///< Correspondance between generator model type and library name in dyd file
Expand Down
58 changes: 50 additions & 8 deletions sources/Outputs/src/Dyd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,17 @@ Dyd::write() const {
dynamicModelsToConnect->addMacroConnect(writeSVarCMacroConnect(svarc));
}

dynamicModelsToConnect->addConnect(signalNModelName_, "signalN_thetaRef", "NETWORK", def_.slackNode->id + "_phi");
auto shuntsByBusId = computeShuntsByIds(def_.shuntsDefinitions);
for (const auto& shuntPair : shuntsByBusId) {
dynamicModelsToConnect->addModel(writeShuntRegulation(shuntPair.first, def_.basename));
auto modelId = constants::computeShuntRegulationId(shuntPair.first);
dynamicModelsToConnect->addConnect(modelId, "UMonitoredPu_value", networkModelName_, shuntPair.first);
for (unsigned int i = 0; i < shuntPair.second.size(); i++) {
dynamicModelsToConnect->addConnect(modelId, "section_" + std::to_string(i) + "_value", networkModelName_, shuntPair.second.at(i).get().id);
}
}

dynamicModelsToConnect->addConnect(signalNModelName_, "signalN_thetaRef", networkModelName_, def_.slackNode->id + "_phi");

for (auto it = def_.generators.cbegin(); it != def_.generators.cend(); ++it) {
writeGenConnect(dynamicModelsToConnect, *it);
Expand Down Expand Up @@ -268,6 +278,17 @@ Dyd::writeHvdcLine(const algo::HVDCDefinition& hvdcLine, const std::string& base
return model;
}

boost::shared_ptr<dynamicdata::BlackBoxModel>
Dyd::writeShuntRegulation(const inputs::Shunt::BusId& busId, const std::string& basename) {
auto id = constants::computeShuntRegulationId(busId);
auto model = dynamicdata::BlackBoxModelFactory::newModel(id);
model->setLib("DYNModelCentralizedShuntsSectionControl");
model->setParFile(basename + ".par");
model->setParId(id);

return model;
}

boost::shared_ptr<dynamicdata::BlackBoxModel>
Dyd::writeLoad(const algo::LoadDefinition& load, const std::string& basename) {
auto model = dynamicdata::BlackBoxModelFactory::newModel(load.id);
Expand Down Expand Up @@ -409,27 +430,27 @@ Dyd::writeSVarCMacroConnect(const inputs::StaticVarCompensator& svarc) {
void
Dyd::writeGenConnect(const boost::shared_ptr<dynamicdata::DynamicModelsCollection>& dynamicModelsToConnect, const algo::GeneratorDefinition& def) {
if (def.model == algo::GeneratorDefinition::ModelType::REMOTE_SIGNALN || def.model == algo::GeneratorDefinition::ModelType::REMOTE_DIAGRAM_PQ_SIGNALN) {
dynamicModelsToConnect->addConnect(def.id, "generator_URegulated", "NETWORK", def.regulatedBusId + "_U_value");
dynamicModelsToConnect->addConnect(def.id, "generator_URegulated", networkModelName_, def.regulatedBusId + "_U_value");
} else if (def.model == algo::GeneratorDefinition::ModelType::PROP_SIGNALN || def.model == algo::GeneratorDefinition::ModelType::PROP_DIAGRAM_PQ_SIGNALN) {
dynamicModelsToConnect->addConnect(def.id, "generator_NQ_value", modelSignalNQprefix_ + def.regulatedBusId, "vrremote_NQ");
}
}

void
Dyd::writeVRRemoteConnect(const boost::shared_ptr<dynamicdata::DynamicModelsCollection>& dynamicModelsToConnect, const std::string& busId) {
dynamicModelsToConnect->addConnect(modelSignalNQprefix_ + busId, "vrremote_URegulated", "NETWORK", busId + "_U_value");
dynamicModelsToConnect->addConnect(modelSignalNQprefix_ + busId, "vrremote_URegulated", networkModelName_, busId + "_U_value");
}

void
Dyd::writeHvdcLineConnect(const boost::shared_ptr<dynamicdata::DynamicModelsCollection>& dynamicModelsToConnect, const algo::HVDCDefinition& hvdcDefinition) {
const std::string vrremoteNqValue("vrremote_NQ");
if (hvdcDefinition.position == algo::HVDCDefinition::Position::SECOND_IN_MAIN_COMPONENT) {
dynamicModelsToConnect->addConnect("NETWORK", hvdcDefinition.converter1BusId + "_ACPIN", hvdcDefinition.id, "hvdc_terminal2");
dynamicModelsToConnect->addConnect("NETWORK", hvdcDefinition.converter2BusId + "_ACPIN", hvdcDefinition.id, "hvdc_terminal1");
dynamicModelsToConnect->addConnect(networkModelName_, hvdcDefinition.converter1BusId + "_ACPIN", hvdcDefinition.id, "hvdc_terminal2");
dynamicModelsToConnect->addConnect(networkModelName_, hvdcDefinition.converter2BusId + "_ACPIN", hvdcDefinition.id, "hvdc_terminal1");
} else {
// case both : 1 <-> 1 and 2 <-> 2
dynamicModelsToConnect->addConnect("NETWORK", hvdcDefinition.converter1BusId + "_ACPIN", hvdcDefinition.id, "hvdc_terminal1");
dynamicModelsToConnect->addConnect("NETWORK", hvdcDefinition.converter2BusId + "_ACPIN", hvdcDefinition.id, "hvdc_terminal2");
dynamicModelsToConnect->addConnect(networkModelName_, hvdcDefinition.converter1BusId + "_ACPIN", hvdcDefinition.id, "hvdc_terminal1");
dynamicModelsToConnect->addConnect(networkModelName_, hvdcDefinition.converter2BusId + "_ACPIN", hvdcDefinition.id, "hvdc_terminal2");
}
if (hvdcDefinition.hasPQPropModel()) {
const auto& busId1 =
Expand All @@ -439,6 +460,27 @@ Dyd::writeHvdcLineConnect(const boost::shared_ptr<dynamicdata::DynamicModelsColl
dynamicModelsToConnect->addConnect(hvdcDefinition.id, "hvdc_NQ2_value", modelSignalNQprefix_ + hvdcDefinition.converter2BusId, vrremoteNqValue);
}
}
} // namespace outputs
}

std::unordered_map<inputs::Shunt::BusId, std::vector<std::reference_wrapper<const inputs::Shunt>>>
Dyd::computeShuntsByIds(const algo::ShuntDefinitions& shuntDefinitions) {
std::unordered_map<inputs::Shunt::BusId, std::vector<std::reference_wrapper<const inputs::Shunt>>> ret;

for (const auto& shuntDefPair : shuntDefinitions.shunts) {
const auto& shuntDef = shuntDefPair.second;
if (shuntDef.dynamicModelAssociated) {
continue;
}
for (const auto& shunt : shuntDef.shunts) {
if (!shunt.voltageRegulationOn) {
continue;
}
ret[shunt.busId].push_back(std::ref(shunt));
}
}

return ret;
}

} // namespace outputs
} // namespace dfl
55 changes: 51 additions & 4 deletions tests/outputs/TestDyd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ TEST(Dyd, write) {

outputPath.append(filename);

dfl::outputs::Dyd dydWriter(dfl::outputs::Dyd::DydDefinition(basename, outputPath.generic_string(), generators, loads, node, {}, {}, manager, {}, svarcDefs));
dfl::outputs::Dyd dydWriter(
dfl::outputs::Dyd::DydDefinition(basename, outputPath.generic_string(), generators, loads, node, {}, {}, manager, {}, svarcDefs, {}));

dydWriter.write();

Expand Down Expand Up @@ -97,7 +98,7 @@ TEST(Dyd, writeRemote) {
outputPath.append(filename);
dfl::algo::GeneratorDefinitionAlgorithm::BusGenMap busesWithDynamicModel = {{bus1, "G1"}, {bus2, "G4"}};
dfl::outputs::Dyd dydWriter(
dfl::outputs::Dyd::DydDefinition(basename, outputPath.generic_string(), generators, {}, node, {}, busesWithDynamicModel, manager, {}, {}));
dfl::outputs::Dyd::DydDefinition(basename, outputPath.generic_string(), generators, {}, node, {}, busesWithDynamicModel, manager, {}, {}, {}));

dydWriter.write();

Expand Down Expand Up @@ -140,7 +141,7 @@ TEST(Dyd, writeHvdc) {

outputPath.append(filename);

dfl::outputs::Dyd dydWriter(dfl::outputs::Dyd::DydDefinition(basename, outputPath.generic_string(), {}, {}, node, hvdcDefs, {}, manager, {}, {}));
dfl::outputs::Dyd dydWriter(dfl::outputs::Dyd::DydDefinition(basename, outputPath.generic_string(), {}, {}, node, hvdcDefs, {}, manager, {}, {}, {}));

dydWriter.write();

Expand Down Expand Up @@ -193,7 +194,53 @@ TEST(Dyd, writeDynamicModel) {

outputPath.append(filename);

dfl::outputs::Dyd dydWriter(dfl::outputs::Dyd::DydDefinition(basename, outputPath.generic_string(), generators, loads, node, {}, {}, manager, models, {}));
dfl::outputs::Dyd dydWriter(
dfl::outputs::Dyd::DydDefinition(basename, outputPath.generic_string(), generators, loads, node, {}, {}, manager, models, {}, {}));

dydWriter.write();

boost::filesystem::path reference("reference");
reference.append(basename);
reference.append(filename);

dfl::test::checkFilesEqual(outputPath.generic_string(), reference.generic_string());
}

TEST(Dyd, writeShunts) {
std::string basename = "TestDydShunts";
std::string filename = basename + ".dyd";
boost::filesystem::path outputPath("results");
outputPath.append(basename);

dfl::inputs::DynamicDataBaseManager manager("", "");

if (!boost::filesystem::exists(outputPath)) {
boost::filesystem::create_directories(outputPath);
}

dfl::algo::ShuntDefinitions shuntDefs;
shuntDefs.shunts["VL"].dynamicModelAssociated = false;
shuntDefs.shunts["VL"].shunts = {
dfl::inputs::Shunt("1.1", "1", true, {}),
dfl::inputs::Shunt("1.2", "1", true, {}),
};
shuntDefs.shunts["VL2"].dynamicModelAssociated = true;
shuntDefs.shunts["VL2"].shunts = {
dfl::inputs::Shunt("2.1", "2", true, {}),
dfl::inputs::Shunt("2.2", "2", true, {}),
};
shuntDefs.shunts["VL3"].dynamicModelAssociated = false;
shuntDefs.shunts["VL3"].shunts = {
dfl::inputs::Shunt("3.1", "3", true, {}),
dfl::inputs::Shunt("3.2", "3", true, {}),
};

auto vl = std::make_shared<dfl::inputs::VoltageLevel>("VL");
auto node = dfl::inputs::Node::build("Slack", vl, 100., {});

outputPath.append(filename);

dfl::outputs::Dyd dydWriter(dfl::outputs::Dyd::DydDefinition(basename, outputPath.generic_string(), {}, {}, node, {}, {}, manager, {}, {}, shuntDefs));

dydWriter.write();

Expand Down
46 changes: 46 additions & 0 deletions tests/outputs/reference/TestDydShunts/TestDydShunts.dyd
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<dyn:dynamicModelsArchitecture xmlns:dyn="http://www.rte-france.com/dynawo">
<dyn:macroConnector id="GEN_NETWORK_CONNECTOR">
<dyn:connect var1="generator_terminal" var2="@STATIC_ID@@NODE@_ACPIN"/>
<dyn:connect var1="generator_switchOffSignal1" var2="@STATIC_ID@@NODE@_switchOff"/>
</dyn:macroConnector>
<dyn:macroConnector id="GEN_SIGNALN_CONNECTOR">
<dyn:connect var1="generator_N" var2="signalN_N"/>
</dyn:macroConnector>
<dyn:macroConnector id="LOAD_NETWORK_CONNECTOR">
<dyn:connect var1="Ui_value" var2="@STATIC_ID@@NODE@_ACPIN_V_im"/>
<dyn:connect var1="Ur_value" var2="@STATIC_ID@@NODE@_ACPIN_V_re"/>
<dyn:connect var1="Ii_value" var2="@STATIC_ID@@NODE@_ACPIN_i_im"/>
<dyn:connect var1="Ir_value" var2="@STATIC_ID@@NODE@_ACPIN_i_re"/>
<dyn:connect var1="switchOff1_value" var2="@STATIC_ID@@NODE@_switchOff_value"/>
</dyn:macroConnector>
<dyn:macroConnector id="StaticVarCompensatorMacroConnector">
<dyn:connect var1="SVarC_terminal" var2="@STATIC_ID@@NODE@_ACPIN"/>
</dyn:macroConnector>
<dyn:macroStaticReference id="GeneratorStaticRef">
<dyn:staticRef var="generator_PGenPu" staticVar="p"/>
<dyn:staticRef var="generator_QGenPu" staticVar="q"/>
<dyn:staticRef var="generator_state" staticVar="state"/>
</dyn:macroStaticReference>
<dyn:macroStaticReference id="LoadRef">
<dyn:staticRef var="PPu_value" staticVar="p"/>
<dyn:staticRef var="QPu_value" staticVar="q"/>
<dyn:staticRef var="state_value" staticVar="state"/>
</dyn:macroStaticReference>
<dyn:macroStaticReference id="StaticVarCompensatorStaticRef">
<dyn:staticRef var="SVarC_PInjPu" staticVar="p"/>
<dyn:staticRef var="SVarC_QInjPu" staticVar="q"/>
<dyn:staticRef var="SVarC_modeHandling_mode_value" staticVar="regulatingMode"/>
<dyn:staticRef var="SVarC_state" staticVar="state"/>
</dyn:macroStaticReference>
<dyn:blackBoxModel id="Model_Signal_N" lib="SignalN"/>
<dyn:blackBoxModel id="ShuntRegulation_1" lib="DYNModelCentralizedShuntsSectionControl" parFile="TestDydShunts.par" parId="ShuntRegulation_1"/>
<dyn:blackBoxModel id="ShuntRegulation_3" lib="DYNModelCentralizedShuntsSectionControl" parFile="TestDydShunts.par" parId="ShuntRegulation_3"/>
<dyn:connect id1="ShuntRegulation_1" var1="UMonitoredPu_value" id2="NETWORK" var2="1"/>
<dyn:connect id1="ShuntRegulation_1" var1="section_0_value" id2="NETWORK" var2="1.2"/>
<dyn:connect id1="ShuntRegulation_1" var1="section_1_value" id2="NETWORK" var2="1.1"/>
<dyn:connect id1="ShuntRegulation_3" var1="UMonitoredPu_value" id2="NETWORK" var2="3"/>
<dyn:connect id1="ShuntRegulation_3" var1="section_0_value" id2="NETWORK" var2="3.2"/>
<dyn:connect id1="ShuntRegulation_3" var1="section_1_value" id2="NETWORK" var2="3.1"/>
<dyn:connect id1="Model_Signal_N" var1="signalN_thetaRef" id2="NETWORK" var2="Slack_phi"/>
</dyn:dynamicModelsArchitecture>

0 comments on commit 489f5b0

Please sign in to comment.