Skip to content

Commit

Permalink
#453 Update following DYN-2455 (following Part. 8)
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitri Baron <[email protected]>
  • Loading branch information
barondim authored and rosiereflo committed Feb 11, 2025
1 parent 5d02907 commit cd76276
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 45 deletions.
2 changes: 1 addition & 1 deletion sources/Launcher/DYNComputeLoadVariationLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ComputeLoadVariationLauncher::launch() {
throw DYNAlgorithmsError(DirectoryDoesNotExist, workingDir);

inputs_.readInputs(workingDirectory_, loadIncrease->getJobsFile());
boost::shared_ptr<job::JobEntry> job = inputs_.cloneJobEntry();
std::shared_ptr<job::JobEntry> job = inputs_.cloneJobEntry();

SimulationParameters params;
// force simulation to dump final values (would be used as input to launch each events)
Expand Down
4 changes: 2 additions & 2 deletions sources/Launcher/DYNComputeSimulationLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ ComputeSimulationLauncher::launch() {
outputFileFullPath = createAbsolutePath("results.xml", workingDir);
}
job::XmlImporter importer;
boost::shared_ptr<job::JobsCollection> jobsCollection = importer.importFromFile(inputFile_);
std::shared_ptr<job::JobsCollection> jobsCollection = importer.importFromFile(inputFile_);
workingDirectory_ = workingDir;
for (job::job_iterator itJobEntry = jobsCollection->begin(); itJobEntry != jobsCollection->end(); ++itJobEntry) {
boost::shared_ptr<job::JobEntry>& job = *itJobEntry;
std::shared_ptr<job::JobEntry>& job = *itJobEntry;
std::cout << DYNLog(LaunchingJob, (*itJobEntry)->getName()) << std::endl;
SimulationResult result;
SimulationParameters params;
Expand Down
6 changes: 3 additions & 3 deletions sources/Launcher/DYNMarginCalculationLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void
MarginCalculationLauncher::readTimes(const std::string& jobFileLoadIncrease, const std::string& jobFileScenario) {
// job
job::XmlImporter importer;
boost::shared_ptr<job::JobsCollection> jobsCollection = importer.importFromFile(createAbsolutePath(jobFileLoadIncrease, workingDirectory_));
std::shared_ptr<job::JobsCollection> jobsCollection = importer.importFromFile(createAbsolutePath(jobFileLoadIncrease, workingDirectory_));
// implicit : only one job per file
job::job_iterator jobIt = jobsCollection->begin();
tLoadIncrease_ = (*jobIt)->getSimulationEntry()->getStopTime();
Expand Down Expand Up @@ -601,7 +601,7 @@ MarginCalculationLauncher::launchScenario(const MultiVariantInputs& inputs, cons
std::stringstream subDir;
subDir << "step-" << variation;
std::string workingDir = createAbsolutePath(scenario->getId(), createAbsolutePath(subDir.str(), workingDirectory_));
boost::shared_ptr<job::JobEntry> job = inputs.cloneJobEntry();
std::shared_ptr<job::JobEntry> job = inputs.cloneJobEntry();

addDydFileToJob(job, scenario->getDydFile());
setCriteriaFileForJob(job, scenario->getCriteriaFile());
Expand Down Expand Up @@ -802,7 +802,7 @@ MarginCalculationLauncher::launchLoadIncrease(const boost::shared_ptr<LoadIncrea
std::stringstream subDir;
subDir << "step-" << variation;
std::string workingDir = createAbsolutePath(loadIncrease->getId(), createAbsolutePath(subDir.str(), workingDirectory_));
boost::shared_ptr<job::JobEntry> job = inputs_.cloneJobEntry();
std::shared_ptr<job::JobEntry> job = inputs_.cloneJobEntry();

SimulationParameters params;
// force simulation to dump final values (would be used as input to launch each event)
Expand Down
8 changes: 4 additions & 4 deletions sources/Launcher/DYNMultiVariantInputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
#include <DYNDataInterfaceFactory.h>
#include <JOBJobsCollection.h>
#include <JOBXmlImporter.h>
#include <boost/make_shared.hpp>


namespace DYNAlgorithms {

void
MultiVariantInputs::readInputs(const std::string& workingDirectory, const std::string& jobFile, const std::string& iidmFile) {
// job
job::XmlImporter importer;
boost::shared_ptr<job::JobsCollection> jobsCollection = importer.importFromFile(createAbsolutePath(jobFile, workingDirectory));
std::shared_ptr<job::JobsCollection> jobsCollection = importer.importFromFile(createAbsolutePath(jobFile, workingDirectory));
// implicit : only one job per file
jobEntry_ = *jobsCollection->begin();

Expand All @@ -56,9 +56,9 @@ MultiVariantInputs::readInputs(const std::string& workingDirectory, const std::s
iidmPath_ = iidmFilePath;
}

boost::shared_ptr<job::JobEntry>
std::shared_ptr<job::JobEntry>
MultiVariantInputs::cloneJobEntry() const {
return jobEntry_ ? boost::make_shared<job::JobEntry>(*jobEntry_) : boost::shared_ptr<job::JobEntry>();
return jobEntry_ ? std::make_shared<job::JobEntry>(*jobEntry_) : std::shared_ptr<job::JobEntry>();
}

} // namespace DYNAlgorithms
11 changes: 6 additions & 5 deletions sources/Launcher/DYNMultiVariantInputs.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

#include <JOBJobEntry.h>
#include <boost/filesystem.hpp>
#include <boost/shared_ptr.hpp>
#include <memory>


namespace DYNAlgorithms {

Expand All @@ -47,7 +48,7 @@ class MultiVariantInputs {
* @brief Retrieve a copy of the job entry
* @returns job entry copy or null pointer if empty
*/
boost::shared_ptr<job::JobEntry> cloneJobEntry() const;
std::shared_ptr<job::JobEntry> cloneJobEntry() const;

/**
* @brief Retrieve the IIDM path to use
Expand Down Expand Up @@ -75,9 +76,9 @@ class MultiVariantInputs {
}

private:
boost::shared_ptr<job::JobEntry> jobEntry_; ///< job entry to use
boost::filesystem::path iidmPath_; ///< IIDM path to use
double tLoadIncreaseVariationMax_; ///< maximum time duration of the variation during the load increase part
std::shared_ptr<job::JobEntry> jobEntry_; ///< job entry to use
boost::filesystem::path iidmPath_; ///< IIDM path to use
double tLoadIncreaseVariationMax_; ///< maximum time duration of the variation during the load increase part
};
} // namespace DYNAlgorithms

Expand Down
34 changes: 16 additions & 18 deletions sources/Launcher/DYNRobustnessAnalysisLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
#include "MacrosMessage.h"
#include "DYNMultiProcessingContext.h"

#include <boost/make_shared.hpp>

using DYN::Trace;
using multipleJobs::MultipleJobs;

Expand Down Expand Up @@ -262,27 +262,25 @@ RobustnessAnalysisLauncher::readInputData(const std::string& fileName) {
}

void
RobustnessAnalysisLauncher::addDydFileToJob(boost::shared_ptr<job::JobEntry>& job,
const std::string& dydFile) {
RobustnessAnalysisLauncher::addDydFileToJob(const std::shared_ptr<job::JobEntry>& job, const std::string& dydFile) {
if (!dydFile.empty()) {
boost::shared_ptr<job::DynModelsEntry> dynModels = job::DynModelsEntryFactory::newInstance();
std::unique_ptr<job::DynModelsEntry> dynModels = job::DynModelsEntryFactory::newInstance();
dynModels->setDydFile(dydFile);
job->getModelerEntry()->addDynModelsEntry(dynModels);
job->getModelerEntry()->addDynModelsEntry(std::move(dynModels));
}
}

void
RobustnessAnalysisLauncher::setCriteriaFileForJob(boost::shared_ptr<job::JobEntry>& job,
const std::string& criteriaFile) {
RobustnessAnalysisLauncher::setCriteriaFileForJob(const std::shared_ptr<job::JobEntry>& job, const std::string& criteriaFile) {
if (!criteriaFile.empty()) {
job->getSimulationEntry()->setCriteriaFile(criteriaFile);
}
}

boost::shared_ptr<DYN::Simulation>
RobustnessAnalysisLauncher::createAndInitSimulation(const std::string& workingDir,
boost::shared_ptr<job::JobEntry>& job, const SimulationParameters& params, SimulationResult& result, const MultiVariantInputs& analysisContext) {
boost::shared_ptr<DYN::SimulationContext> context = boost::shared_ptr<DYN::SimulationContext>(new DYN::SimulationContext());
const std::shared_ptr<job::JobEntry>& job, const SimulationParameters& params, SimulationResult& result, const MultiVariantInputs& analysisContext) {
std::unique_ptr<DYN::SimulationContext> context = std::unique_ptr<DYN::SimulationContext>(new DYN::SimulationContext());
context->setResourcesDirectory(getMandatoryEnvVar("DYNAWO_RESOURCES_DIR"));
context->setLocale(getMandatoryEnvVar("DYNAWO_ALGORITHMS_LOCALE"));
context->setInputDirectory(workingDirectory_);
Expand All @@ -292,7 +290,7 @@ RobustnessAnalysisLauncher::createAndInitSimulation(const std::string& workingDi
? DYN::DataInterfaceFactory::build(DYN::DataInterfaceFactory::DATAINTERFACE_IIDM, analysisContext.iidmPath().generic_string())
: boost::shared_ptr<DYN::DataInterface>();
boost::shared_ptr<DYN::Simulation> simulation =
boost::shared_ptr<DYN::Simulation>(new DYN::Simulation(job, context, dataInterface));
boost::shared_ptr<DYN::Simulation>(new DYN::Simulation(job, std::move(context), dataInterface));

if (!params.InitialStateFile_.empty())
simulation->setInitialStateFile(params.InitialStateFile_);
Expand Down Expand Up @@ -358,8 +356,8 @@ RobustnessAnalysisLauncher::createAndInitSimulation(const std::string& workingDi
result.setLostEquipmentsFileExtensionFromExportMode("XML");

if (job->getOutputsEntry() && job->getOutputsEntry()->getLogsEntry()) {
std::vector<boost::shared_ptr<job::AppenderEntry> > appendersEntry = job->getOutputsEntry()->getLogsEntry()->getAppenderEntries();
for (std::vector<boost::shared_ptr<job::AppenderEntry> >::iterator itApp = appendersEntry.begin(), itAppEnd = appendersEntry.end();
std::vector<std::shared_ptr<job::AppenderEntry> > appendersEntry = job->getOutputsEntry()->getLogsEntry()->getAppenderEntries();
for (std::vector<std::shared_ptr<job::AppenderEntry> >::iterator itApp = appendersEntry.begin(), itAppEnd = appendersEntry.end();
itApp != itAppEnd; ++itApp) {
if ((*itApp)->getTag() == "") {
std::string file = createAbsolutePath(job->getOutputsEntry()->getOutputsDirectory(), workingDir);
Expand Down Expand Up @@ -769,8 +767,8 @@ RobustnessAnalysisLauncher::cleanResult(const std::string& id) const {
}

bool
RobustnessAnalysisLauncher::findExportIIDM(const std::vector<boost::shared_ptr<job::FinalStateEntry> >& finalStates) {
for (std::vector<boost::shared_ptr<job::FinalStateEntry> >::const_iterator it = finalStates.begin(); it != finalStates.end(); ++it) {
RobustnessAnalysisLauncher::findExportIIDM(const std::vector<std::shared_ptr<job::FinalStateEntry> >& finalStates) {
for (std::vector<std::shared_ptr<job::FinalStateEntry> >::const_iterator it = finalStates.begin(); it != finalStates.end(); ++it) {
if (!(*it)->getTimestamp()) {
// one without timestamp : it means that it concerns the final state
return (*it)->getExportIIDMFile();
Expand All @@ -781,8 +779,8 @@ RobustnessAnalysisLauncher::findExportIIDM(const std::vector<boost::shared_ptr<j
}

bool
RobustnessAnalysisLauncher::findExportDump(const std::vector<boost::shared_ptr<job::FinalStateEntry> >& finalStates) {
for (std::vector<boost::shared_ptr<job::FinalStateEntry> >::const_iterator it = finalStates.begin(); it != finalStates.end(); ++it) {
RobustnessAnalysisLauncher::findExportDump(const std::vector<std::shared_ptr<job::FinalStateEntry> >& finalStates) {
for (std::vector<std::shared_ptr<job::FinalStateEntry> >::const_iterator it = finalStates.begin(); it != finalStates.end(); ++it) {
if (!(*it)->getTimestamp()) {
// one without timestamp : it means that it concerns the final state
return (*it)->getExportDumpFile();
Expand All @@ -793,8 +791,8 @@ RobustnessAnalysisLauncher::findExportDump(const std::vector<boost::shared_ptr<j
}

void
RobustnessAnalysisLauncher::initParametersWithJob(boost::shared_ptr<job::JobEntry> job, SimulationParameters& params) {
const std::vector<boost::shared_ptr<job::FinalStateEntry> >& finalStateEntries = job->getOutputsEntry()->getFinalStateEntries();
RobustnessAnalysisLauncher::initParametersWithJob(const std::shared_ptr<job::JobEntry>& job, SimulationParameters& params) {
const std::vector<std::shared_ptr<job::FinalStateEntry> >& finalStateEntries = job->getOutputsEntry()->getFinalStateEntries();
// It is considered that only the first final entry is relevant for parameters for systematic analysis
if (!finalStateEntries.empty()) {
params.activateExportIIDM_ = findExportIIDM(finalStateEntries);
Expand Down
13 changes: 7 additions & 6 deletions sources/Launcher/DYNRobustnessAnalysisLauncher.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <string>
#include <map>
#include <memory>
#include <boost/shared_ptr.hpp>
#include <boost/filesystem.hpp>

Expand Down Expand Up @@ -137,22 +138,22 @@ class RobustnessAnalysisLauncher {
* @return Initialized simulation or a null pointer if initialization failed
*/
boost::shared_ptr<DYN::Simulation> createAndInitSimulation(const std::string& workingDir,
boost::shared_ptr<job::JobEntry>& job, const SimulationParameters& params, SimulationResult& result,
const std::shared_ptr<job::JobEntry>& job, const SimulationParameters& params, SimulationResult& result,
const MultiVariantInputs& analysisContext);

/**
* @brief add a dyd file to the job
* @param job job to simulate
* @param dydFile dyd file to add to the job, empty if none to add
*/
void addDydFileToJob(boost::shared_ptr<job::JobEntry>& job, const std::string& dydFile);
void addDydFileToJob(const std::shared_ptr<job::JobEntry>& job, const std::string& dydFile);

/**
* @brief replace the criteria file for the job
* @param job job to simulate
* @param criteriaFile criteria file to set for the job, empty if none to set
*/
void setCriteriaFileForJob(boost::shared_ptr<job::JobEntry>& job, const std::string& criteriaFile);
void setCriteriaFileForJob(const std::shared_ptr<job::JobEntry>& job, const std::string& criteriaFile);

/**
* @brief launch a simulation and collect results
Expand Down Expand Up @@ -184,7 +185,7 @@ class RobustnessAnalysisLauncher {
* @param job the job to use
* @param params the parameters to update
*/
static void initParametersWithJob(boost::shared_ptr<job::JobEntry> job, SimulationParameters& params);
static void initParametersWithJob(const std::shared_ptr<job::JobEntry>& job, SimulationParameters& params);

/**
* @brief Export a save result file
Expand Down Expand Up @@ -237,7 +238,7 @@ class RobustnessAnalysisLauncher {
* @param finalStates the list of final state entries to check
* @return true if IIDM export is required, false if not
*/
static bool findExportIIDM(const std::vector<boost::shared_ptr<job::FinalStateEntry> >& finalStates);
static bool findExportIIDM(const std::vector<std::shared_ptr<job::FinalStateEntry> >& finalStates);

/**
* @brief Find in the final state entries if the final state dump export is required
Expand All @@ -248,7 +249,7 @@ class RobustnessAnalysisLauncher {
* @param finalStates the list of final state entries to check
* @return true if dump export is required, false if not
*/
static bool findExportDump(const std::vector<boost::shared_ptr<job::FinalStateEntry> >& finalStates);
static bool findExportDump(const std::vector<std::shared_ptr<job::FinalStateEntry> >& finalStates);

/**
* read the input data for launching the systematic analysis
Expand Down
3 changes: 1 addition & 2 deletions sources/Launcher/DYNSystematicAnalysisLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <fstream>

#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
#include "boost/date_time/posix_time/posix_time.hpp"

#include <libzip/ZipFile.h>
Expand Down Expand Up @@ -116,7 +115,7 @@ SystematicAnalysisLauncher::launchScenario(const boost::shared_ptr<Scenario>& sc
<< " criteriaFile =" << scenario->getCriteriaFile() << std::endl;

std::string workingDir = createAbsolutePath(scenario->getId(), workingDirectory_);
boost::shared_ptr<job::JobEntry> job = inputs_.cloneJobEntry();
std::shared_ptr<job::JobEntry> job = inputs_.cloneJobEntry();

addDydFileToJob(job, scenario->getDydFile());
setCriteriaFileForJob(job, scenario->getCriteriaFile());
Expand Down
6 changes: 3 additions & 3 deletions sources/Launcher/test/TestMultiVariantInputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ TEST(MultiVariant, base) {
jobFile = "MyJobsWithIIDM.jobs";
inputs.readInputs(workingDir, jobFile);
ASSERT_EQ(inputs.iidmPath(), expectedIIDM);
boost::shared_ptr<job::JobEntry> job1 = inputs.cloneJobEntry();
boost::shared_ptr<job::JobEntry> job2 = inputs.cloneJobEntry();
std::shared_ptr<job::JobEntry> job1 = inputs.cloneJobEntry();
std::shared_ptr<job::JobEntry> job2 = inputs.cloneJobEntry();
ASSERT_TRUE(job1);
ASSERT_TRUE(job2);
ASSERT_NE(job1, job2);
Expand All @@ -51,7 +51,7 @@ TEST(MultiVariant, base) {
inputs.readInputs(workingDir, jobFile, iidmFile);
ASSERT_EQ(inputs.iidmPath(), expectedIIDM);

boost::shared_ptr<job::JobEntry> job = inputs.cloneJobEntry();
std::shared_ptr<job::JobEntry> job = inputs.cloneJobEntry();
ASSERT_TRUE(job);
ASSERT_EQ(job->getName(), "My Jobs");
}
Expand Down
2 changes: 1 addition & 1 deletion sources/Launcher/test/TestRobustnessAnalysisLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class MyLauncher : public RobustnessAnalysisLauncher {
public:
void launch() {
inputs_.readInputs(workingDirectory_, "MyJobs.jobs");
boost::shared_ptr<job::JobEntry> job = inputs_.cloneJobEntry();
std::shared_ptr<job::JobEntry> job = inputs_.cloneJobEntry();
addDydFileToJob(job, "MyDydFile.dyd");
ASSERT_EQ(job->getModelerEntry()->getDynModelsEntries().size(), 2);
ASSERT_EQ(job->getModelerEntry()->getDynModelsEntries()[0]->getDydFile(), "EmptyDydFile.dyd");
Expand Down

0 comments on commit cd76276

Please sign in to comment.