Skip to content

Commit

Permalink
#216 Add voltage level with association in shunt algo
Browse files Browse the repository at this point in the history
  • Loading branch information
Le Courtois Florent committed Oct 1, 2021
1 parent 3ff0ad0 commit 9a4a3d5
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 18 deletions.
14 changes: 12 additions & 2 deletions sources/Algo/include/Algo.h
Original file line number Diff line number Diff line change
Expand Up @@ -863,11 +863,20 @@ class DynModelAlgorithm : public NodeAlgorithm {
const inputs::DynamicDataBaseManager& manager_; ///< dynamic database config manager
};

struct VLShuntsDefinition {
struct ShuntHash {
size_t operator()(const inputs::Shunt& shunt) const noexcept;
};

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

/**
* @brief Shunt definitions
*/
struct ShuntDefinitions {
std::unordered_map<inputs::VoltageLevel::VoltageLevelId, unsigned int> nbShunts; ///< Number of shunts by voltage level
std::unordered_map<inputs::VoltageLevel::VoltageLevelId, VLShuntsDefinition> shunts; ///< Number of shunts by voltage level
};

/**
Expand All @@ -879,7 +888,7 @@ class ShuntDefinitionAlgorithm : public NodeAlgorithm {
* @brief Constructor
* @param shuntCounterDefs the counter definitions to update
*/
explicit ShuntDefinitionAlgorithm(ShuntDefinitions& shuntCounterDefs);
ShuntDefinitionAlgorithm(ShuntDefinitions& shuntCounterDefs, const inputs::DynamicDataBaseManager& manager);

/**
* @brief Performs the algorithm
Expand All @@ -892,6 +901,7 @@ class ShuntDefinitionAlgorithm : public NodeAlgorithm {

private:
ShuntDefinitions& shuntDefs_; ///< the counter definitions to update
std::unordered_set<inputs::VoltageLevel::VoltageLevelId> voltageLevelsWithAssociation_;
};

/**
Expand Down
15 changes: 13 additions & 2 deletions sources/Algo/src/Algo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,12 +644,23 @@ DynModelAlgorithm::MacroConnectHash::operator()(const MacroConnect& connect) con

/////////////////////////////////////////////////////////////////////////////////

ShuntDefinitionAlgorithm::ShuntDefinitionAlgorithm(ShuntDefinitions& defs) : shuntDefs_(defs) {}
ShuntDefinitionAlgorithm::ShuntDefinitionAlgorithm(ShuntDefinitions& defs, const inputs::DynamicDataBaseManager& manager) : shuntDefs_(defs) {
const auto& multiAssociations = manager.assemblingDocument().multipleAssociations();
std::transform(multiAssociations.begin(), multiAssociations.end(), std::inserter(voltageLevelsWithAssociation_, voltageLevelsWithAssociation_.begin()),
[](const inputs::AssemblingXmlDocument::MultipleAssociation& association) { return association.shunt.voltageLevel; });
}

void
ShuntDefinitionAlgorithm::operator()(const NodePtr& node) {
auto vl = node->voltageLevel.lock();
shuntDefs_.nbShunts[vl->id] += node->shunts.size();
auto& map = shuntDefs_.shunts[vl->id];
std::copy(node->shunts.begin(), node->shunts.end(), std::inserter(map.shunts, map.shunts.end()));
map.dynamicModelAssociated = (voltageLevelsWithAssociation_.count(vl->id) > 0);
}

size_t
VLShuntsDefinition::ShuntHash::operator()(const inputs::Shunt& shunt) const noexcept {
return std::hash<inputs::Shunt::ShuntId>{}(shunt.id);
}

//////////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion sources/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Context::Context(const ContextDef& def, const inputs::Configuration& config) :

networkManager_.onNode(algo::MainConnexComponentAlgorithm(mainConnexNodes_));
networkManager_.onNode(algo::DynModelAlgorithm(dynamicModels_, dynamicDataBaseManager_));
networkManager_.onNode(algo::ShuntDefinitionAlgorithm(shunts_));
networkManager_.onNode(algo::ShuntDefinitionAlgorithm(shunts_, dynamicDataBaseManager_));
networkManager_.onNode(algo::LinesByIdAlgorithm(linesById_));
}

Expand Down
5 changes: 3 additions & 2 deletions sources/Outputs/src/Par.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,12 @@ Par::writeDynamicModelParameterSet(const inputs::SettingXmlDocument::Set& set, c
LOG(debug) << "Count id " << count.id << " not found as a multiple association in assembling: Configuration error" << LOG_ENDL;
continue;
}
if (shunts.nbShunts.count(found->second.shunt.voltageLevel) == 0) {
if (shunts.shunts.count(found->second.shunt.voltageLevel) == 0) {
// case voltage level not in network, skip
continue;
}
new_set->addParameter(helper::buildParameter(count.name, static_cast<int>(shunts.nbShunts.at(found->second.shunt.voltageLevel))));
const auto& shuntsSet = shunts.shunts.at(found->second.shunt.voltageLevel).shunts;
new_set->addParameter(helper::buildParameter(count.name, static_cast<int>(shuntsSet.size())));
}

for (const auto& param : set.boolParameters) {
Expand Down
2 changes: 1 addition & 1 deletion tests/algo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# SPDX-License-Identifier: MPL-2.0
#

DEFINE_TEST(TestAlgo ALGO)
DEFINE_TEST_XML(TestAlgo ALGO)
target_link_libraries(TestAlgo DynaFlowLauncher::algo)

# Dummy Library for algo test
Expand Down
21 changes: 15 additions & 6 deletions tests/algo/TestAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
#include <tuple>
#include <vector>

// Required for testing unit tests
testing::Environment* initXmlEnvironment();

testing::Environment* const env = initXmlEnvironment();

namespace test {

/**
Expand Down Expand Up @@ -690,7 +695,7 @@ TEST(Generators, oneReactiveCurvePoint) {
testDiagramValidity(points, isDiagramValid);
}

TEST(Counter, base) {
TEST(Shunts, base) {
auto vl = std::make_shared<dfl::inputs::VoltageLevel>("VL");
auto vl2 = std::make_shared<dfl::inputs::VoltageLevel>("VL2");
auto vl3 = std::make_shared<dfl::inputs::VoltageLevel>("VL3");
Expand All @@ -708,15 +713,19 @@ TEST(Counter, base) {
dfl::inputs::Node::build("6", vl2, 0.0, shunts6),
};

dfl::inputs::DynamicDataBaseManager manager("res/setting.xml", "res/assembling.xml");
dfl::algo::ShuntDefinitions defs;
dfl::algo::ShuntDefinitionAlgorithm algo(defs);
dfl::algo::ShuntDefinitionAlgorithm algo(defs, manager);

std::for_each(nodes.begin(), nodes.end(), algo);

ASSERT_EQ(defs.nbShunts.size(), 3);
ASSERT_EQ(defs.nbShunts.at("VL"), 6);
ASSERT_EQ(defs.nbShunts.at("VL2"), 15);
ASSERT_EQ(defs.nbShunts.at("VL3"), 0);
ASSERT_EQ(defs.shunts.size(), 3);
ASSERT_EQ(defs.shunts.at("VL").shunts.size(), 6);
ASSERT_EQ(defs.shunts.at("VL").dynamicModelAssociated, true);
ASSERT_EQ(defs.shunts.at("VL2").shunts.size(), 15);
ASSERT_EQ(defs.shunts.at("VL2").dynamicModelAssociated, false);
ASSERT_EQ(defs.shunts.at("VL3").shunts.size(), 0);
ASSERT_EQ(defs.shunts.at("VL3").dynamicModelAssociated, false);
}

TEST(LinesByIds, base) {
Expand Down
11 changes: 7 additions & 4 deletions tests/outputs/TestPar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,12 @@ TEST(TestPar, DynModel) {
boost::filesystem::create_directories(outputPath);
}

dfl::algo::ShuntDefinitions counters;
counters.nbShunts["VL"] = 2;
counters.nbShunts["VL2"] = 1;
dfl::algo::ShuntDefinitions shuntsDefinitions;
shuntsDefinitions.shunts["VL"].shunts = {
dfl::inputs::Shunt("1"),
dfl::inputs::Shunt("1.1"),
};
shuntsDefinitions.shunts["VL2"].shunts = {dfl::inputs::Shunt("2")};

dfl::algo::DynamicModelDefinitions defs;
dfl::algo::DynamicModelDefinition dynModel("DM_VL61", "DummyLib");
Expand All @@ -205,7 +208,7 @@ TEST(TestPar, DynModel) {
outputPath.append(filename);
dfl::inputs::Configuration::ActivePowerCompensation activePowerCompensation(dfl::inputs::Configuration::ActivePowerCompensation::P);
dfl::outputs::Par parWriter(dfl::outputs::Par::ParDefinition(basename, dirname, outputPath.generic_string(), generators, {}, activePowerCompensation, {},
manager, counters, defs, {}, {}));
manager, shuntsDefinitions, defs, {}, {}));

parWriter.write();

Expand Down

0 comments on commit 9a4a3d5

Please sign in to comment.