Skip to content

Commit

Permalink
dynawo#133 Minor problems fixed (doxygen, methods's names, references…
Browse files Browse the repository at this point in the history
… and const...) + optimize the critical time algorithm following advices from Florentine
  • Loading branch information
AlexPoiron authored and FredericSabot committed Apr 26, 2023
1 parent 1a78885 commit 7c37c30
Show file tree
Hide file tree
Showing 19 changed files with 81 additions and 132 deletions.
2 changes: 1 addition & 1 deletion nrt/data/IEEE14/CTC/files/fic_MULTIPLE.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
of simulation tools for power systems.
-->
<multipleJobs xmlns="http://www.rte-france.com/dynawo">
<criticalTimeCalculation accuracy="0.001" jobsFile="IEEE14.jobs" dydId="FAULT_GEN_1" startPar="fault_tBegin" endPar="fault_tEnd" minValue="1" maxValue="1.7"/>
<criticalTimeCalculation accuracy="0.001" jobsFile="IEEE14.jobs" dydId="FAULT_GEN_1" endPar="fault_tEnd" minValue="1" maxValue="1.7"/>
</multipleJobs>
2 changes: 1 addition & 1 deletion nrt/data/IEEE14/CTC/reference/aggregatedResults.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<aggregatedResults xmlns="http://www.rte-france.com/dynawo">
<criticalTimeResults criticalTime="1.6200000000000001" message="GEN____1_SM : The following assertion has been violated %sat time %f not (generator.theta &gt; 3.141592653589793 and time &gt; 0.1) 2.65546"/>
<criticalTimeResults criticalTime="1.6200000000000001" message="GEN____1_SM : The following assertion has been violated %sat time %f not (generator.theta &gt; 3.141592653589793 and time &gt; 0.1)"/>
</aggregatedResults>
4 changes: 2 additions & 2 deletions sources/API/aggregatedResults/DYNAggrResXmlExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ XmlExporter::exportLoadIncreaseResultsToStream(const vector<LoadIncreaseResult>&
}

void
XmlExporter::exportCriticalTimeResultsToFile(const double& criticalTime, std::string messageCriticalTimeError, const std::string& filePath) const {
XmlExporter::exportCriticalTimeResultsToFile(double criticalTime, const std::string& messageCriticalTimeError, std::string filePath) const {
fstream file;
file.open(filePath.c_str(), fstream::out);
if (!file.is_open()) {
Expand All @@ -114,7 +114,7 @@ XmlExporter::exportCriticalTimeResultsToFile(const double& criticalTime, std::st
}

void
XmlExporter::exportCriticalTimeResultsToStream(const double& criticalTime, std::string messageCriticalTimeError, std::ostream& stream) const {
XmlExporter::exportCriticalTimeResultsToStream(double criticalTime, const std::string& messageCriticalTimeError, std::ostream& stream) const {
FormatterPtr formatter = Formatter::createFormatter(stream, "http://www.rte-france.com/dynawo");

formatter->startDocument();
Expand Down
6 changes: 3 additions & 3 deletions sources/API/aggregatedResults/DYNAggrResXmlExporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ class XmlExporter {
* @param results aggregated results to export
* @param filePath file where the results must be exported
*/
void exportCriticalTimeResultsToFile(const double& criticalTime, std::string messageCriticalTimeError, const std::string& filePath) const;
void exportCriticalTimeResultsToFile(double criticalTime, const std::string& messageCriticalTimeError, std::string filePath) const;

/**
* @brief Export critical time calculation results into a steam
* @brief Export critical time calculation results into a stream
*
* @param results aggregated results to export
* @param stream stream where the results must be exported
*/
void exportCriticalTimeResultsToStream(const double& CriticalTime, std::string messageCriticalTimeError, std::ostream& stream) const;
void exportCriticalTimeResultsToStream(double CriticalTime, const std::string& messageCriticalTimeError, std::ostream& stream) const;

private:
/**
Expand Down
3 changes: 0 additions & 3 deletions sources/API/multipleJobs/DYNMultipleJobsXmlHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,6 @@ CriticalTimeCalculationHandler::create(attributes_type const& attributes) {
if (attributes.has("dydId"))
criticalTimeCalculation_->setDydId(attributes["dydId"]);

if (attributes.has("startPar"))
criticalTimeCalculation_->setStartPar(attributes["startPar"]);

if (attributes.has("endPar"))
criticalTimeCalculation_->setEndPar(attributes["endPar"]);

Expand Down
6 changes: 3 additions & 3 deletions sources/API/multipleJobs/DYNMultipleJobsXmlHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ class CriticalTimeCalculationHandler : public xml::sax::parser::ComposableElemen
~CriticalTimeCalculationHandler();

/**
* @brief return the margin calculation read in xml file
* @return margin calculation object build thanks to infos read in xml file
* @brief return the critical time calculation read in xml file
* @return critical time calculation object build thanks to infos read in xml file
*/
boost::shared_ptr<DYNAlgorithms::CriticalTimeCalculation> get() const;

Expand Down Expand Up @@ -257,7 +257,7 @@ class XmlHandler : public xml::sax::parser::ComposableDocumentHandler {
void addMarginCalculation();

/**
* @brief add a margin calculation element to the current MultipleJobs element
* @brief add a critical time calculation element to the current MultipleJobs element
*/
void addCriticalTimeCalculation();

Expand Down
3 changes: 1 addition & 2 deletions sources/API/multipleJobs/test/TestMultipleJobs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,8 @@ TEST(TestMultipleJobs, TestMultipleJobsXmlHanderCriticalTime) {
ASSERT_EQ(ct->getAccuracy(), 0.001);
ASSERT_EQ(ct->getJobsFile(), "Myjobs.jobs");
ASSERT_EQ(ct->getDydId(), "MyDydId");
ASSERT_EQ(ct->getStartPar(), "MyStartPar");
ASSERT_EQ(ct->getEndPar(), "MyEndPar");
ASSERT_EQ(ct->getMinValue(), 0);
ASSERT_EQ(ct->getMinValue(), 0.1);
ASSERT_EQ(ct->getMaxValue(), 1);
}
} // namespace multipleJobs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<multipleJobs xmlns="http://www.rte-france.com/dynawo">
<criticalTimeCalculation accuracy="0.001" jobsFile="Myjobs.jobs" dydId="MyDydId" startPar="MyStartPar" endPar="MyEndPar" minValue="0" maxValue="1"/>
<criticalTimeCalculation accuracy="0.001" jobsFile="Myjobs.jobs" dydId="MyDydId" endPar="MyEndPar" minValue="0.1" maxValue="1"/>
</multipleJobs>
1 change: 0 additions & 1 deletion sources/API/multipleJobs/xsd/multipleJobs.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
<xs:attribute name="accuracy" type="xs:double" use="required"/>
<xs:attribute name="jobsFile" type="xs:string" use="required"/>
<xs:attribute name="dydId" type="xs:string" use="required"/>
<xs:attribute name="startPar" type="xs:string" use="required"/>
<xs:attribute name="endPar" type="xs:string" use="required"/>
<xs:attribute name="minValue" type="xs:double" use="required"/>
<xs:attribute name="maxValue" type="xs:double" use="required"/>
Expand Down
19 changes: 3 additions & 16 deletions sources/Common/DYNCriticalTimeCalculation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@
#include "MacrosMessage.h"

namespace DYNAlgorithms {
CriticalTimeCalculation::CriticalTimeCalculation():
accuracy_(0.001) {
}

void
CriticalTimeCalculation::setAccuracy(double accuracy) {
if (accuracy <= 0 || accuracy > 1)
if (accuracy < 0 || accuracy > 1)
throw DYNAlgorithmsError(IncoherentAccuracyCriticalTime, accuracy);
accuracy_ = accuracy;
}
Expand All @@ -42,13 +39,13 @@ CriticalTimeCalculation::setJobsFile(std::string jobsFile) {
jobsFile_ = jobsFile;
}

std::string
const std::string&
CriticalTimeCalculation::getJobsFile() const {
return jobsFile_;
}

void
CriticalTimeCalculation::setDydId(std::string dydId) {
CriticalTimeCalculation::setDydId(const std::string& dydId) {
dydId_ = dydId;
}

Expand All @@ -57,16 +54,6 @@ CriticalTimeCalculation::getDydId() const {
return dydId_;
}

void
CriticalTimeCalculation::setStartPar(std::string startPar) {
startPar_ = startPar;
}

std::string
CriticalTimeCalculation::getStartPar() const {
return startPar_;
}

void
CriticalTimeCalculation::setEndPar(std::string endPar) {
endPar_ = endPar;
Expand Down
42 changes: 12 additions & 30 deletions sources/Common/DYNCriticalTimeCalculation.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ namespace DYNAlgorithms {
*/
class CriticalTimeCalculation {
public:
/**
* constructor
*/
CriticalTimeCalculation();

/**
* @brief set the accuracy of the algorithm
* @param accuracy accuracy of the algorithm
Expand All @@ -59,40 +54,28 @@ class CriticalTimeCalculation {
* @brief get the jobs file used for the simulation
* @return jobs file used for the simulation
*/
std::string getJobsFile() const;
const std::string& getJobsFile() const;

/**
* @brief set the id parameter
* @brief set the id parameter from the Dyd file.
* @param parSetId id parameter we will use
*/
void setDydId(std::string parSetId);
void setDydId(const std::string& dydId);

/**
* @brief set the id parameter
* @brief get the id parameter from the Dyd file.
* @return id parameter we will use
*/
std::string getDydId() const;

/**
* @brief set the start parameter used for the simulation
* @param startPar start parameter used for the simulation
*/
void setStartPar(std::string startPar);

/**
* @brief set the start parameter used for the simulation
* @return start parameter used for the simulation
*/
std::string getStartPar() const;

/**
* @brief set the end parameter used for the simulation
* @param endPar end parameter used for the simulation
*/
void setEndPar(std::string endPar);

/**
* @brief set the end parameter used for the simulation
* @brief get the end parameter used for the simulation
* @return end parameter used for the simulation
*/
std::string getEndPar() const;
Expand All @@ -104,7 +87,7 @@ class CriticalTimeCalculation {
void setMinValue(double minValue);

/**
* @brief set the minimum value used for the simulation
* @brief get the minimum value used for the simulation
* @return minimum value used for the simulation
*/
double getMinValue() const;
Expand All @@ -116,19 +99,18 @@ class CriticalTimeCalculation {
void setMaxValue(double maxValue);

/**
* @brief set the maximum value used for the simulation
* @brief get the maximum value used for the simulation
* @return maximum value used for the simulation
*/
double getMaxValue();

private:
double accuracy_; ///< accuracy of the algorithm
std::string jobsFile_; ///< jobs file used for the simulation
std::string dydId_; ///< dyd id in the dyd file
std::string startPar_; ///< start parameter used for the simulation
std::string endPar_; ///< end parameter used for the simulation
double minValue_; ///< minimum value for the critical time
double maxValue_; ///< maximum value for the critical time
std::string jobsFile_; ///< jobs file used for the simulation
std::string dydId_; ///< dyd id in the dyd file
std::string endPar_; ///< end parameter used for the simulation
double minValue_; ///< minimum value for the critical time
double maxValue_; ///< maximum value for the critical time
};

} // namespace DYNAlgorithms
Expand Down
4 changes: 2 additions & 2 deletions sources/Common/DYNSimulationResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ SimulationResult::setStatus(status_t status) {
}

void
SimulationResult::setCriticalTimeMessageError(std::string messageCriticalTimeError) {
SimulationResult::setCriticalTimeMessageError(const std::string& messageCriticalTimeError) {
messageCriticalTimeError_ = messageCriticalTimeError;
}

std::string
const std::string&
SimulationResult::getCriticalTimeMessageError() const {
return messageCriticalTimeError_;
}
Expand Down
4 changes: 2 additions & 2 deletions sources/Common/DYNSimulationResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ class SimulationResult {
* @brief set the message error of the last simulation failed
* @param message the message error
*/
void setCriticalTimeMessageError(std::string messageCriticalTimeError);
void setCriticalTimeMessageError(const std::string& messageCriticalTimeError);

/**
* @brief get the message error of the last simulation failed
*/
std::string getCriticalTimeMessageError() const;
const std::string& getCriticalTimeMessageError() const;

/**
* @brief getter of the timeline stream associated to the scenario
Expand Down
6 changes: 0 additions & 6 deletions sources/Common/test/TestBaseClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,21 @@ TEST(TestBaseClasses, testMarginCalculation) {

TEST(TestBaseClasses, testCriticalTimeCalculation) {
CriticalTimeCalculation ct;
ASSERT_EQ(ct.getAccuracy(), 0.001);

ct.setAccuracy(0.01);
ct.setJobsFile("Myjobs.jobs");
ct.setDydId("MyDydId");
ct.setStartPar("MyStartPar");
ct.setEndPar("MyEndPar");
ct.setMinValue(1);
ct.setMaxValue(2);
ASSERT_EQ(ct.getAccuracy(), 0.01);
ASSERT_EQ(ct.getJobsFile(), "Myjobs.jobs");
ASSERT_EQ(ct.getDydId(), "MyDydId");
ASSERT_EQ(ct.getStartPar(), "MyStartPar");
ASSERT_EQ(ct.getEndPar(), "MyEndPar");
ASSERT_EQ(ct.getMinValue(), 1);
ASSERT_EQ(ct.getMaxValue(), 2);

ASSERT_THROW_DYNAWO(ct.setAccuracy(-1), DYN::Error::GENERAL, DYNAlgorithms::KeyAlgorithmsError_t::IncoherentAccuracyCriticalTime);
ASSERT_THROW_DYNAWO(ct.setAccuracy(2), DYN::Error::GENERAL, DYNAlgorithms::KeyAlgorithmsError_t::IncoherentAccuracyCriticalTime);
ASSERT_THROW_DYNAWO(ct.setAccuracy(0), DYN::Error::GENERAL, DYNAlgorithms::KeyAlgorithmsError_t::IncoherentAccuracyCriticalTime);
}

TEST(TestBaseClasses, testSimulationResult) {
Expand Down Expand Up @@ -198,5 +193,4 @@ TEST(TestBaseClasses, testLoadIncreaseResult) {
ASSERT_FALSE(test2.getSuccess());
ASSERT_EQ(test2.getStatus(), CRITERIA_NON_RESPECTED_STATUS);
}

} // namespace DYNAlgorithms
Loading

0 comments on commit 7c37c30

Please sign in to comment.