From 53d22cdbfc6636310ba66fac3c76471bae93ef1e Mon Sep 17 00:00:00 2001 From: AlexPoiron Date: Tue, 18 Jan 2022 11:12:57 +0100 Subject: [PATCH] #133 Minor problems fixed (doxygen, methods's names, references and const...) + optimize the critical time algorithm following advices from Florentine --- nrt/data/IEEE14/CTC/files/fic_MULTIPLE.xml | 2 +- .../CTC/reference/aggregatedResults.xml | 2 +- .../DYNAggrResXmlExporter.cpp | 4 +- .../aggregatedResults/DYNAggrResXmlExporter.h | 6 +- .../DYNMultipleJobsXmlHandler.cpp | 3 - .../multipleJobs/DYNMultipleJobsXmlHandler.h | 6 +- .../multipleJobs/test/TestMultipleJobs.cpp | 3 +- .../test/res/criticalTimeCalculation.xml | 2 +- sources/API/multipleJobs/xsd/multipleJobs.xsd | 1 - sources/Common/DYNCriticalTimeCalculation.cpp | 19 +----- sources/Common/DYNCriticalTimeCalculation.h | 42 ++++-------- sources/Common/DYNSimulationResult.cpp | 4 +- sources/Common/DYNSimulationResult.h | 4 +- sources/Common/test/TestBaseClasses.cpp | 6 -- sources/Launcher/DYNCriticalTimeLauncher.cpp | 68 ++++++++----------- sources/Launcher/DYNCriticalTimeLauncher.h | 27 ++++---- .../test/TestRobustnessAnalysisLauncher.cpp | 1 - .../test/res/CriticalTime/fic_MULTIPLE.xml | 2 +- sources/main.cpp | 20 +++--- 19 files changed, 85 insertions(+), 137 deletions(-) diff --git a/nrt/data/IEEE14/CTC/files/fic_MULTIPLE.xml b/nrt/data/IEEE14/CTC/files/fic_MULTIPLE.xml index f3b7cedd..04a0245b 100644 --- a/nrt/data/IEEE14/CTC/files/fic_MULTIPLE.xml +++ b/nrt/data/IEEE14/CTC/files/fic_MULTIPLE.xml @@ -12,5 +12,5 @@ of simulation tools for power systems. --> - + diff --git a/nrt/data/IEEE14/CTC/reference/aggregatedResults.xml b/nrt/data/IEEE14/CTC/reference/aggregatedResults.xml index 9c4bba9a..9f01783d 100644 --- a/nrt/data/IEEE14/CTC/reference/aggregatedResults.xml +++ b/nrt/data/IEEE14/CTC/reference/aggregatedResults.xml @@ -1,4 +1,4 @@ - + diff --git a/sources/API/aggregatedResults/DYNAggrResXmlExporter.cpp b/sources/API/aggregatedResults/DYNAggrResXmlExporter.cpp index c4bdc0c4..c6d2d4d6 100644 --- a/sources/API/aggregatedResults/DYNAggrResXmlExporter.cpp +++ b/sources/API/aggregatedResults/DYNAggrResXmlExporter.cpp @@ -102,7 +102,7 @@ XmlExporter::exportLoadIncreaseResultsToStream(const vector& } 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()) { @@ -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(); diff --git a/sources/API/aggregatedResults/DYNAggrResXmlExporter.h b/sources/API/aggregatedResults/DYNAggrResXmlExporter.h index 19066a3e..ec3f7ea4 100644 --- a/sources/API/aggregatedResults/DYNAggrResXmlExporter.h +++ b/sources/API/aggregatedResults/DYNAggrResXmlExporter.h @@ -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: /** diff --git a/sources/API/multipleJobs/DYNMultipleJobsXmlHandler.cpp b/sources/API/multipleJobs/DYNMultipleJobsXmlHandler.cpp index 5c1fd03e..eba9825f 100644 --- a/sources/API/multipleJobs/DYNMultipleJobsXmlHandler.cpp +++ b/sources/API/multipleJobs/DYNMultipleJobsXmlHandler.cpp @@ -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"]); diff --git a/sources/API/multipleJobs/DYNMultipleJobsXmlHandler.h b/sources/API/multipleJobs/DYNMultipleJobsXmlHandler.h index ab09bad2..285c0f3a 100644 --- a/sources/API/multipleJobs/DYNMultipleJobsXmlHandler.h +++ b/sources/API/multipleJobs/DYNMultipleJobsXmlHandler.h @@ -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 get() const; @@ -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(); diff --git a/sources/API/multipleJobs/test/TestMultipleJobs.cpp b/sources/API/multipleJobs/test/TestMultipleJobs.cpp index 5f639081..9ca7d0ab 100644 --- a/sources/API/multipleJobs/test/TestMultipleJobs.cpp +++ b/sources/API/multipleJobs/test/TestMultipleJobs.cpp @@ -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 diff --git a/sources/API/multipleJobs/test/res/criticalTimeCalculation.xml b/sources/API/multipleJobs/test/res/criticalTimeCalculation.xml index afbe482d..dc812fc8 100644 --- a/sources/API/multipleJobs/test/res/criticalTimeCalculation.xml +++ b/sources/API/multipleJobs/test/res/criticalTimeCalculation.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/sources/API/multipleJobs/xsd/multipleJobs.xsd b/sources/API/multipleJobs/xsd/multipleJobs.xsd index a111a9ef..1597cda5 100644 --- a/sources/API/multipleJobs/xsd/multipleJobs.xsd +++ b/sources/API/multipleJobs/xsd/multipleJobs.xsd @@ -60,7 +60,6 @@ - diff --git a/sources/Common/DYNCriticalTimeCalculation.cpp b/sources/Common/DYNCriticalTimeCalculation.cpp index 2912eba1..60690cdd 100644 --- a/sources/Common/DYNCriticalTimeCalculation.cpp +++ b/sources/Common/DYNCriticalTimeCalculation.cpp @@ -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; } @@ -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; } @@ -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; diff --git a/sources/Common/DYNCriticalTimeCalculation.h b/sources/Common/DYNCriticalTimeCalculation.h index e7af29f1..8875b1e1 100644 --- a/sources/Common/DYNCriticalTimeCalculation.h +++ b/sources/Common/DYNCriticalTimeCalculation.h @@ -32,11 +32,6 @@ namespace DYNAlgorithms { */ class CriticalTimeCalculation { public: - /** - * constructor - */ - CriticalTimeCalculation(); - /** * @brief set the accuracy of the algorithm * @param accuracy accuracy of the algorithm @@ -59,32 +54,20 @@ 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 @@ -92,7 +75,7 @@ class CriticalTimeCalculation { 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; @@ -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; @@ -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 diff --git a/sources/Common/DYNSimulationResult.cpp b/sources/Common/DYNSimulationResult.cpp index c677f8a1..1e726470 100644 --- a/sources/Common/DYNSimulationResult.cpp +++ b/sources/Common/DYNSimulationResult.cpp @@ -81,11 +81,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_; } diff --git a/sources/Common/DYNSimulationResult.h b/sources/Common/DYNSimulationResult.h index 70a21b09..58ed92b1 100644 --- a/sources/Common/DYNSimulationResult.h +++ b/sources/Common/DYNSimulationResult.h @@ -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 diff --git a/sources/Common/test/TestBaseClasses.cpp b/sources/Common/test/TestBaseClasses.cpp index 3029a738..f9af6a22 100644 --- a/sources/Common/test/TestBaseClasses.cpp +++ b/sources/Common/test/TestBaseClasses.cpp @@ -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) { @@ -198,5 +193,4 @@ TEST(TestBaseClasses, testLoadIncreaseResult) { ASSERT_FALSE(test2.getSuccess()); ASSERT_EQ(test2.getStatus(), CRITERIA_NON_RESPECTED_STATUS); } - } // namespace DYNAlgorithms diff --git a/sources/Launcher/DYNCriticalTimeLauncher.cpp b/sources/Launcher/DYNCriticalTimeLauncher.cpp index 547ea0e9..1fa0cc66 100644 --- a/sources/Launcher/DYNCriticalTimeLauncher.cpp +++ b/sources/Launcher/DYNCriticalTimeLauncher.cpp @@ -36,29 +36,23 @@ using multipleJobs::MultipleJobs; namespace DYNAlgorithms { void -CriticalTimeLauncher::launch() { - const std::string& jobsFile = criticalTimeCalculation_->getJobsFile(); - -#ifdef WITH_OPENMP -omp_set_num_threads(nbThreads_); -#endif - - inputs_.readInputs(workingDirectory_, jobsFile, 1); +CriticalTimeLauncher::SetParametersAndLaunchSimulation() { + inputs_.readInputs(workingDirectory_, jobsFile_, 1); boost::shared_ptr job = inputs_.cloneJobEntry(); SimulationParameters params; boost::shared_ptr simulation = createAndInitSimulation(workingDirectory_, job, params, results_, inputs_); - + if (simulation) { boost::shared_ptr modelMulti = boost::dynamic_pointer_cast(simulation->model_); - std::string DDBDir = getEnvVar("DYNAWO_DDB_DIR"); const std::string& dydId = criticalTimeCalculation_->getDydId(); const std::string& endPar = criticalTimeCalculation_->getEndPar(); - subModel_ = modelMulti->findSubModelByName(dydId); - subModel_->setParameterValue(endPar, DYN::PAR, tSup_, false); - subModel_->setSubModelParameters(); - + if (modelMulti->findSubModelByName(dydId) != NULL) { + subModel_ = modelMulti->findSubModelByName(dydId); + subModel_->setParameterValue(endPar, DYN::PAR, tSup_, false); + subModel_->setSubModelParameters(); + } simulate(simulation, results_); } } @@ -69,47 +63,45 @@ CriticalTimeLauncher::updateIndexes(double& tPrevious, double& curAccuracy, cons double midDichotomy = std::round((std::abs(tSup_ - tPrevious) / 2) * multiplierRound) / multiplierRound; double tmp = tSup_; - if(results_.getSuccess()) + if (results_.getSuccess()) tSup_ += midDichotomy; - else + else tSup_ -= midDichotomy; tPrevious = tmp; } void -CriticalTimeLauncher::SearchCriticalTime() { +CriticalTimeLauncher::launch() { criticalTimeCalculation_ = multipleJobs_->getCriticalTimeCalculation(); if (!criticalTimeCalculation_) throw DYNAlgorithmsError(CriticalTimeCalculationTaskNotFound); - - const double accuracy = criticalTimeCalculation_->getAccuracy(); + + const double accuracy = criticalTimeCalculation_->getAccuracy(); double curAccuracy = 1; const double multiplierRound = 1 / accuracy; - - bool firstSimuPassed = false; - double tInf = criticalTimeCalculation_->getMinValue(); tSup_ = criticalTimeCalculation_->getMaxValue(); + jobsFile_ = criticalTimeCalculation_->getJobsFile(); + double tInf = criticalTimeCalculation_->getMinValue(); double tPrevious = tSup_; - - while(curAccuracy > accuracy) { - launch(); - if (firstSimuPassed) - updateIndexes(tPrevious, curAccuracy, multiplierRound); - else { - if (results_.getSuccess()) - tSup_ += std::round(((tSup_ - tInf) / 2) * multiplierRound) / multiplierRound; - else - tSup_ -= std::round(((tSup_ - tInf) / 2) * multiplierRound) / multiplierRound; - - firstSimuPassed = true; - } + + // First simulation case. + SetParametersAndLaunchSimulation(); + if (results_.getSuccess()) + tSup_ += std::round(((tSup_ - tInf) / 2) * multiplierRound) / multiplierRound; + else + tSup_ -= std::round(((tSup_ - tInf) / 2) * multiplierRound) / multiplierRound; + + while (curAccuracy > accuracy) { + SetParametersAndLaunchSimulation(); + updateIndexes(tPrevious, curAccuracy, multiplierRound); } + // Check if the final result is calculated with a failed simulation - if(!results_.getSuccess()) + if (!results_.getSuccess()) tSup_ -= accuracy; - + tSup_ = std::round(tSup_ * multiplierRound) / multiplierRound;; } @@ -127,4 +119,4 @@ CriticalTimeLauncher::createOutputs(std::map& mapData, } } -} // namespace DYNAlgorithms \ No newline at end of file +} // namespace DYNAlgorithms diff --git a/sources/Launcher/DYNCriticalTimeLauncher.h b/sources/Launcher/DYNCriticalTimeLauncher.h index 354acef9..95705a34 100644 --- a/sources/Launcher/DYNCriticalTimeLauncher.h +++ b/sources/Launcher/DYNCriticalTimeLauncher.h @@ -33,23 +33,24 @@ namespace DYNAlgorithms { class SimulationResults; class CriticalTimeCalculation; /** - * @brief Margin Calculation launcher class + * @brief Critical Time Calculation launcher class * - * Class for margin calculation launched by cvg + * Class for critical time calculation launched by cvg */ class CriticalTimeLauncher : public RobustnessAnalysisLauncher { public: /** - * @copydoc RobustnessAnalysisLauncher::launch() + * @brief Search critical time with a specific default in the simulation. We follow + * dichotomy's algorithm to find it. */ void launch(); /** - * @brief Search critical time with a specific default in the simulation. We follow - * dichotomy's algorithm to find it. + * @brief Launch the simulation with the new value calculted in the critical + * time algorithm */ - void SearchCriticalTime(); - + void SetParametersAndLaunchSimulation(); + /** * @brief Update superior born to find the right critical time * and calcul the next time value we want to test. @@ -61,19 +62,19 @@ class CriticalTimeLauncher : public RobustnessAnalysisLauncher { void updateIndexes(double& tPrevious, double& curAccuracy, const double& multiplierRound); protected: - double tSup_; ///< value that will be updated until we find the critical time - SimulationResult results_; ///< results of the systematic analysis - boost::shared_ptr subModel_; ///< submodel for each simulation - boost::shared_ptr criticalTimeCalculation_; ///< critical time calculation + double tSup_; ///< value that will be updated until we find the critical time + std::string jobsFile_; ///< Job file of the simulation + SimulationResult results_; ///< results of the critical time calculation + boost::shared_ptr subModel_; ///< submodel for each simulation + boost::shared_ptr criticalTimeCalculation_; ///< critical time calculation private: /** * @copydoc RobustnessAnalysisLauncher::createOutputs() */ void createOutputs(std::map& mapData, bool zipIt) const; - }; } // namespace DYNAlgorithms -#endif // LAUNCHER_DYNCRITICALTIMELAUNCHER_H_ \ No newline at end of file +#endif // LAUNCHER_DYNCRITICALTIMELAUNCHER_H_ diff --git a/sources/Launcher/test/TestRobustnessAnalysisLauncher.cpp b/sources/Launcher/test/TestRobustnessAnalysisLauncher.cpp index 14fefdb1..5cd7a721 100644 --- a/sources/Launcher/test/TestRobustnessAnalysisLauncher.cpp +++ b/sources/Launcher/test/TestRobustnessAnalysisLauncher.cpp @@ -145,7 +145,6 @@ class MyLauncher : public RobustnessAnalysisLauncher { ASSERT_EQ(ct->getAccuracy(), 0.001); ASSERT_EQ(ct->getJobsFile(), "MyJobs.jobs"); ASSERT_EQ(ct->getDydId(), "FAULT_GEN_1"); - ASSERT_EQ(ct->getStartPar(), "fault_tBegin"); ASSERT_EQ(ct->getEndPar(), "fault_tEnd"); ASSERT_EQ(ct->getMinValue(), 1); ASSERT_EQ(ct->getMaxValue(), 1.620); diff --git a/sources/Launcher/test/res/CriticalTime/fic_MULTIPLE.xml b/sources/Launcher/test/res/CriticalTime/fic_MULTIPLE.xml index 1d1555b2..49242d0f 100644 --- a/sources/Launcher/test/res/CriticalTime/fic_MULTIPLE.xml +++ b/sources/Launcher/test/res/CriticalTime/fic_MULTIPLE.xml @@ -12,5 +12,5 @@ of simulation tools for power systems. --> - + diff --git a/sources/main.cpp b/sources/main.cpp index f4c3e597..b45e2e7a 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -45,17 +45,16 @@ static void launchSimulation(const std::string& jobFile, const std::string& outp static void launchMarginCalculation(const std::string& inputFile, const std::string& outputFile, const std::string& directory, int nbThreads); static void launchSystematicAnalysis(const std::string& inputFile, const std::string& outputFile, const std::string& directory, int nbThreads); static void launchLoadVariationCalculation(const std::string& inputFile, const std::string& outputFile, const std::string& directory, int variation); -static void launchCriticalTimeCalculation(const std::string& inputFile, const std::string& outputFile, const std::string& directory, int nbThreads); +static void launchCriticalTimeCalculation(const std::string& inputFile, const std::string& outputFile, const std::string& directory); int main(int argc, char** argv) { std::string simulationType = ""; std::string inputFile = ""; std::string outputFile = ""; - std::string simulationMC_SA_CS = "Set the simulation type to launch : MC (Margin calculation), SA (systematic analysis), CS (compute simulation)"; - std::string simulationCTC = " or CTC (critical time calculation)"; - std::string allSimulationsTypeStr = simulationMC_SA_CS.append(simulationCTC); - const char* allSimulationsType = allSimulationsTypeStr.c_str(); + std::string simulationMC_SA_CS_CTC = "Set the simulation type to launch : MC (Margin calculation), SA (systematic analysis), CS (compute simulation)" + " or CTC (critical time calculation)"; + const char* allSimulationsType = simulationMC_SA_CS_CTC.c_str(); std::vector directoryVec; int nbThreads = 1; @@ -120,7 +119,7 @@ int main(int argc, char** argv) { if (simulationType == "SA" || simulationType == "MC" || simulationType == "CTC") { if (outputFile == "") { - std::cout << "An output file. (*.zip or *.xml) is required for SA and MC simulations." << std::endl; + std::cout << "An output file. (*.zip or *.xml) is required for SA, MC and CTC simulations." << std::endl; std::cout << desc << std::endl; return 1; } @@ -156,10 +155,10 @@ int main(int argc, char** argv) { boost::posix_time::time_duration diff = t1 - t0; std::cout << "Simulation finished in " << diff.total_milliseconds()/1000 << "s" << std::endl; } else if (simulationType == "CTC") { - launchCriticalTimeCalculation(inputFile, outputFile, directory, nbThreads); + launchCriticalTimeCalculation(inputFile, outputFile, directory); boost::posix_time::ptime t1 = boost::posix_time::second_clock::local_time(); boost::posix_time::time_duration diff = t1 - t0; - std::cout << "Simulation finished in " << diff.total_milliseconds()/1000 << "s" << std::endl; + std::cout << "Critical Time Calculation finished in " << diff.total_milliseconds()/1000 << "s" << std::endl; } } catch (...) { throw; @@ -237,14 +236,13 @@ void launchSystematicAnalysis(const std::string& inputFile, const std::string& o analysisLauncher->writeResults(); } -void launchCriticalTimeCalculation(const std::string& inputFile, const std::string& outputFile, const std::string& directory, int nbThreads) { +void launchCriticalTimeCalculation(const std::string& inputFile, const std::string& outputFile, const std::string& directory) { boost::shared_ptr criticalTimeLauncher = boost::shared_ptr(new CriticalTimeLauncher()); criticalTimeLauncher->setInputFile(inputFile); criticalTimeLauncher->setOutputFile(outputFile); criticalTimeLauncher->setDirectory(directory); - criticalTimeLauncher->setNbThreads(nbThreads); criticalTimeLauncher->init(); - criticalTimeLauncher->SearchCriticalTime(); + criticalTimeLauncher->launch(); criticalTimeLauncher->writeResults(); }