From 016daf5370f343dc78ad7338d818f538ecea0cb5 Mon Sep 17 00:00:00 2001 From: Le Courtois Florent Date: Wed, 8 Dec 2021 10:45:47 +0100 Subject: [PATCH] #216 Update par for shunts --- sources/Outputs/include/Constants.h | 1 + sources/Outputs/include/Par.h | 3 +++ sources/Outputs/src/Diagram.cpp | 2 +- sources/Outputs/src/Par.cpp | 21 ++++++++++++++++ .../reference/TestParShunts/TestParShunts.par | 24 +++++++++++++++++++ 5 files changed, 50 insertions(+), 1 deletion(-) diff --git a/sources/Outputs/include/Constants.h b/sources/Outputs/include/Constants.h index 73198b587..602081d72 100644 --- a/sources/Outputs/include/Constants.h +++ b/sources/Outputs/include/Constants.h @@ -97,6 +97,7 @@ const std::string propSignalNGeneratorFixedPParId{"propSignalNGeneratorFixedP"}; const std::string remoteVControlParId{"remoteVControl"}; ///< PAR id for using remote voltage control const std::string remoteSignalNGeneratorFixedP{"remoteSignalNFixedP"}; ///< PAR id for using remote signal N with fixed P const std::string xmlEncoding{"UTF-8"}; ///< Default encoding for XML outputs files +const std::string diagramTableBPu{"tableBPu"}; constexpr double powerValueMax = std::numeric_limits::max(); ///< Maximum value for powers, meaning infinite diff --git a/sources/Outputs/include/Par.h b/sources/Outputs/include/Par.h index bd718250c..b45f77e4a 100644 --- a/sources/Outputs/include/Par.h +++ b/sources/Outputs/include/Par.h @@ -175,6 +175,9 @@ class Par { static boost::shared_ptr writeShuntRegulation(const inputs::Shunt::BusId& busId, const std::vector>& shunts); + static boost::shared_ptr writeShuntBSection(const inputs::Shunt& shunt, unsigned int index, const std::string& basename, + const boost::filesystem::path& dirname); + /** * @brief Write remote voltage regulators parameter set * diff --git a/sources/Outputs/src/Diagram.cpp b/sources/Outputs/src/Diagram.cpp index f794cd9dc..927bbf285 100644 --- a/sources/Outputs/src/Diagram.cpp +++ b/sources/Outputs/src/Diagram.cpp @@ -122,7 +122,7 @@ Diagram::writeShunt(const inputs::Shunt& shunt) const { std::stringstream buffer; // Modelica requires this file to start with "#1", if it is not present, problems occurs buffer << "#1" << std::endl; - buffer << "double tableBPu(" << shunt.bSections.size() << ", 2)" << std::endl; + buffer << "double " << constants::diagramTableBPu << "(" << shunt.bSections.size() << ", 2)" << std::endl; for (auto it = shunt.bSections.begin(); it != shunt.bSections.end(); ++it) { unsigned int index = it - shunt.bSections.begin(); diff --git a/sources/Outputs/src/Par.cpp b/sources/Outputs/src/Par.cpp index d4772a5e3..4e0f2e55d 100644 --- a/sources/Outputs/src/Par.cpp +++ b/sources/Outputs/src/Par.cpp @@ -225,6 +225,10 @@ Par::write() const { auto shuntsByIds = constants::computeFilteredShuntsByIds(def_.shuntsDefinitions); for (const auto& shuntDefPair : shuntsByIds) { dynamicModelsToConnect->addParametersSet(writeShuntRegulation(shuntDefPair.first, shuntDefPair.second)); + for (auto it = shuntDefPair.second.begin(); it != shuntDefPair.second.end(); ++it) { + unsigned int index = it - shuntDefPair.second.begin(); + dynamicModelsToConnect->addParametersSet(writeShuntBSection(*it, index, def_.basename, def_.dirname)); + } } exporter.exportToFile(dynamicModelsToConnect, def_.filepath.generic_string(), constants::xmlEncoding); @@ -551,6 +555,23 @@ Par::writeShuntRegulation(const inputs::Shunt::BusId& busId, const std::vector +Par::writeShuntBSection(const inputs::Shunt& shunt, unsigned int index, const std::string& basename, const boost::filesystem::path& dirname) { + auto set = boost::shared_ptr(new parameters::ParametersSet(shunt.id)); + + auto tableFilename = dirname; + tableFilename.append(basename + constants::diagramDirectorySuffix).append(constants::diagramFilename(shunt.id)); + + set->addParameter(helper::buildParameter("shunt_Section0", static_cast(index))); + set->addParameter(helper::buildParameter("shunt_TableBPuName", constants::diagramTableBPu)); + set->addParameter(helper::buildParameter("shunt_TableBPuFile", tableFilename.generic_string())); + set->addParameter(helper::buildParameter("shunt_Q0Pu", 0.)); + set->addReference(helper::buildReference("shunt_U0Pu", "v_pu", "DOUBLE", shunt.busId)); + set->addReference(helper::buildReference("shunt_UPhase0", "angle_pu", "DOUBLE", shunt.busId)); + + return set; +} + boost::shared_ptr Par::writeGenerator(const algo::GeneratorDefinition& def, const std::string& basename, const boost::filesystem::path& dirname) { std::size_t hashId = constants::hash(def.id); diff --git a/tests/outputs/reference/TestParShunts/TestParShunts.par b/tests/outputs/reference/TestParShunts/TestParShunts.par index 6843af17a..e74019297 100644 --- a/tests/outputs/reference/TestParShunts/TestParShunts.par +++ b/tests/outputs/reference/TestParShunts/TestParShunts.par @@ -1,5 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + +