diff --git a/src/libs/antares/study/area/area.cpp b/src/libs/antares/study/area/area.cpp index 130c56a0d6..3bd4b91222 100644 --- a/src/libs/antares/study/area/area.cpp +++ b/src/libs/antares/study/area/area.cpp @@ -185,7 +185,7 @@ uint64_t Area::memoryUsage() const ret += wind.memoryUsage(); // Hydro - ret += PreproHydroMemoryUsage(hydro.prepro); + ret += PreproHydroMemoryUsage(hydro.prepro.get()); if (hydro.series) { ret += hydro.series->memoryUsage(); @@ -223,7 +223,7 @@ void Area::createMissingTimeSeries() { if (!hydro.series) { - hydro.series = new DataSeriesHydro(); + hydro.series = std::make_unique(); } } @@ -231,19 +231,19 @@ void Area::createMissingPrepros() { if (!load.prepro) { - load.prepro = new Data::Load::Prepro(); + load.prepro = std::make_unique(); } if (!solar.prepro) { - solar.prepro = new Data::Solar::Prepro(); + solar.prepro = std::make_unique(); } if (!wind.prepro) { - wind.prepro = new Data::Wind::Prepro(); + wind.prepro = std::make_unique(); } if (!hydro.prepro) { - hydro.prepro = new PreproHydro(); + hydro.prepro = std::make_unique(); } thermal.list.ensureDataPrepro(); } diff --git a/src/libs/antares/study/area/list.cpp b/src/libs/antares/study/area/list.cpp index 46a2e98c6f..cee20dc5d5 100644 --- a/src/libs/antares/study/area/list.cpp +++ b/src/libs/antares/study/area/list.cpp @@ -934,11 +934,10 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, ret = area.hydro.prepro->validate(area.id) && ret; } - auto* hydroSeries = area.hydro.series; if (!options.loadOnlyNeeded || !area.hydro.prepro) // Series { buffer.clear() << study.folderInput << SEP << "hydro" << SEP << "series"; - ret = hydroSeries->loadGenerationTS(area.id, buffer, studyVersion) && ret; + ret = area.hydro.series->loadGenerationTS(area.id, buffer, studyVersion) && ret; } if (studyVersion < StudyVersion(9, 1)) @@ -953,12 +952,12 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, else { buffer.clear() << study.folderInput << SEP << "hydro" << SEP << "series"; - ret = hydroSeries->LoadMaxPower(area.id, buffer) && ret; + ret = area.hydro.series->LoadMaxPower(area.id, buffer) && ret; } - hydroSeries->resizeTSinDeratedMode(study.parameters.derated, - studyVersion, - study.usedByTheSolver); + area.hydro.series->resizeTSinDeratedMode(study.parameters.derated, + studyVersion, + study.usedByTheSolver); } // Wind @@ -1320,7 +1319,7 @@ void AreaListEnsureDataLoadPrepro(AreaList* l) { if (!area.load.prepro) { - area.load.prepro = new Antares::Data::Load::Prepro(); + area.load.prepro = std::make_unique(); } }); } @@ -1335,7 +1334,7 @@ void AreaListEnsureDataSolarPrepro(AreaList* l) { if (!area.solar.prepro) { - area.solar.prepro = new Antares::Data::Solar::Prepro(); + area.solar.prepro = std::make_unique(); } }); } @@ -1350,7 +1349,7 @@ void AreaListEnsureDataWindPrepro(AreaList* l) { if (!area.wind.prepro) { - area.wind.prepro = new Antares::Data::Wind::Prepro(); + area.wind.prepro = std::make_unique(); } }); } @@ -1365,7 +1364,7 @@ void AreaListEnsureDataHydroTimeSeries(AreaList* l) { if (!area.hydro.series) { - area.hydro.series = new DataSeriesHydro(); + area.hydro.series = std::make_unique(); } }); } @@ -1380,7 +1379,7 @@ void AreaListEnsureDataHydroPrepro(AreaList* l) { if (!area.hydro.prepro) { - area.hydro.prepro = new PreproHydro(); + area.hydro.prepro = std::make_unique(); } }); } diff --git a/src/libs/antares/study/include/antares/study/parts/hydro/container.h b/src/libs/antares/study/include/antares/study/parts/hydro/container.h index 01c219b46b..1da5ab6023 100644 --- a/src/libs/antares/study/include/antares/study/parts/hydro/container.h +++ b/src/libs/antares/study/include/antares/study/parts/hydro/container.h @@ -138,7 +138,7 @@ class PartHydro */ PartHydro(); //! Destructor - ~PartHydro(); + ~PartHydro() = default; /*! ** \brief Reset internal data @@ -211,10 +211,10 @@ class PartHydro HydroAllocation allocation; //! Data for the pre-processor - PreproHydro* prepro; + std::unique_ptr prepro; //! Data for time-series - DataSeriesHydro* series; + std::unique_ptr series; // TODO : following time series could be hosted by the series data member above (of type // DataSeriesHydro), // which contains other time. diff --git a/src/libs/antares/study/include/antares/study/parts/load/container.h b/src/libs/antares/study/include/antares/study/parts/load/container.h index 083dc6df7d..ec7402034a 100644 --- a/src/libs/antares/study/include/antares/study/parts/load/container.h +++ b/src/libs/antares/study/include/antares/study/parts/load/container.h @@ -44,7 +44,7 @@ class Container final: private Yuni::NonCopyable */ Container(); //! Destructor - ~Container(); + ~Container() = default; //@} /*! @@ -67,9 +67,8 @@ class Container final: private Yuni::NonCopyable */ uint64_t memoryUsage() const; -public: //! Data for the pre-processor - Data::Load::Prepro* prepro; + std::unique_ptr prepro; TimeSeriesNumbers tsNumbers; diff --git a/src/libs/antares/study/include/antares/study/parts/solar/container.h b/src/libs/antares/study/include/antares/study/parts/solar/container.h index a4ea96d55b..390b72cd90 100644 --- a/src/libs/antares/study/include/antares/study/parts/solar/container.h +++ b/src/libs/antares/study/include/antares/study/parts/solar/container.h @@ -41,7 +41,7 @@ class Container */ Container(); //! Destructor - ~Container(); + ~Container() = default; //@} /*! @@ -64,9 +64,8 @@ class Container */ uint64_t memoryUsage() const; -public: //! Data for the pre-processor - Data::Solar::Prepro* prepro; + std::unique_ptr prepro; TimeSeriesNumbers tsNumbers; diff --git a/src/libs/antares/study/include/antares/study/parts/wind/container.h b/src/libs/antares/study/include/antares/study/parts/wind/container.h index 7e36522597..ba149068f5 100644 --- a/src/libs/antares/study/include/antares/study/parts/wind/container.h +++ b/src/libs/antares/study/include/antares/study/parts/wind/container.h @@ -41,7 +41,7 @@ class Container */ Container(); //! Destructor - ~Container(); + ~Container() = default; //@} /*! @@ -64,9 +64,8 @@ class Container */ uint64_t memoryUsage() const; -public: //! Data for the pre-processor - Data::Wind::Prepro* prepro; + std::unique_ptr prepro; TimeSeriesNumbers tsNumbers; diff --git a/src/libs/antares/study/include/antares/study/progression/progression.h b/src/libs/antares/study/include/antares/study/progression/progression.h index 5e013df957..19c2be8c00 100644 --- a/src/libs/antares/study/include/antares/study/progression/progression.h +++ b/src/libs/antares/study/include/antares/study/progression/progression.h @@ -169,15 +169,7 @@ class Progression final public: Meter(); - virtual ~Meter() - { - if (logsContainer) - { - delete[] logsContainer; - } - } - - void allocateLogsContainer(uint nb); + virtual ~Meter() = default; /*! ** \brief Prepare enough space to allow @n simultaneous tasks @@ -188,16 +180,12 @@ class Progression final virtual bool onInterval(uint) override; public: - // Progression::Part::Map parts; Part::ListRef inUse; std::mutex mutex; uint nbParallelYears; - // Because writing something to the logs might be expensive, we have to - // reduce the time spent in locking the mutex. - // We will use a temp vector of string to delay the writing into the logs - Yuni::CString<256, false>* logsContainer; + std::vector> logsContainer; }; // class Meter diff --git a/src/libs/antares/study/include/antares/study/progression/progression.hxx b/src/libs/antares/study/include/antares/study/progression/progression.hxx index 91430681dc..ad262b4ad5 100644 --- a/src/libs/antares/study/include/antares/study/progression/progression.hxx +++ b/src/libs/antares/study/include/antares/study/progression/progression.hxx @@ -26,16 +26,10 @@ namespace Antares namespace Solver { inline Progression::Meter::Meter(): - nbParallelYears(0), - logsContainer(nullptr) + nbParallelYears(0) { } -inline void Progression::Meter::allocateLogsContainer(uint nb) -{ - logsContainer = new Yuni::CString<256, false>[nb]; -} - inline void Progression::Meter::taskCount(uint n) { (void)n; @@ -49,7 +43,7 @@ inline void Progression::add(Section section, int nbTicks) inline void Progression::setNumberOfParallelYears(uint nb) { pProgressMeter.nbParallelYears = nb; - pProgressMeter.allocateLogsContainer(nb); + pProgressMeter.logsContainer.resize(nb); } inline Progression::Part& Progression::begin(uint year, Progression::Section section) diff --git a/src/libs/antares/study/parts/hydro/container.cpp b/src/libs/antares/study/parts/hydro/container.cpp index 92d13a586e..336595b95b 100644 --- a/src/libs/antares/study/parts/hydro/container.cpp +++ b/src/libs/antares/study/parts/hydro/container.cpp @@ -48,17 +48,10 @@ PartHydro::PartHydro(): leewayLowerBound(1.), leewayUpperBound(1.), pumpingEfficiency(1.), - prepro(nullptr), series(nullptr) { } -PartHydro::~PartHydro() -{ - delete prepro; - delete series; -} - void PartHydro::reset() { intraDailyModulation = 24; diff --git a/src/libs/antares/study/parts/load/container.cpp b/src/libs/antares/study/parts/load/container.cpp index b377eb0bf3..364b761985 100644 --- a/src/libs/antares/study/parts/load/container.cpp +++ b/src/libs/antares/study/parts/load/container.cpp @@ -31,17 +31,10 @@ using namespace Yuni; namespace Antares::Data::Load { Container::Container(): - prepro(nullptr), series(tsNumbers) { } -Container::~Container() -{ - delete prepro; - prepro = nullptr; -} - bool Container::forceReload(bool reload) const { bool ret = true; diff --git a/src/libs/antares/study/parts/solar/container.cpp b/src/libs/antares/study/parts/solar/container.cpp index 27e96d823c..08c85a0cc0 100644 --- a/src/libs/antares/study/parts/solar/container.cpp +++ b/src/libs/antares/study/parts/solar/container.cpp @@ -31,16 +31,10 @@ using namespace Yuni; namespace Antares::Data::Solar { Container::Container(): - prepro(nullptr), series(tsNumbers) { } -Container::~Container() -{ - delete prepro; -} - bool Container::forceReload(bool reload) const { bool ret = true; diff --git a/src/libs/antares/study/parts/wind/container.cpp b/src/libs/antares/study/parts/wind/container.cpp index eff23dff6f..64575b73ab 100644 --- a/src/libs/antares/study/parts/wind/container.cpp +++ b/src/libs/antares/study/parts/wind/container.cpp @@ -30,16 +30,10 @@ using namespace Yuni; namespace Antares::Data::Wind { Container::Container(): - prepro(nullptr), series(tsNumbers) { } -Container::~Container() -{ - delete prepro; -} - bool Container::forceReload(bool reload) const { bool ret = true; diff --git a/src/libs/antares/study/study.cpp b/src/libs/antares/study/study.cpp index 67206dad70..29f22e9bf5 100644 --- a/src/libs/antares/study/study.cpp +++ b/src/libs/antares/study/study.cpp @@ -979,22 +979,22 @@ bool Study::clusterRename(Cluster* cluster, ClusterName newName) void Study::destroyAllLoadTSGeneratorData() { - areas.each([](Data::Area& area) { FreeAndNil(area.load.prepro); }); + areas.each([](Data::Area& area) { area.load.prepro.reset(); }); } void Study::destroyAllSolarTSGeneratorData() { - areas.each([](Data::Area& area) { FreeAndNil(area.solar.prepro); }); + areas.each([](Data::Area& area) { area.solar.prepro.reset(); }); } void Study::destroyAllHydroTSGeneratorData() { - areas.each([](Data::Area& area) { FreeAndNil(area.hydro.prepro); }); + areas.each([](Data::Area& area) { area.hydro.prepro.reset(); }); } void Study::destroyAllWindTSGeneratorData() { - areas.each([](Data::Area& area) { FreeAndNil(area.wind.prepro); }); + areas.each([](Data::Area& area) { area.wind.prepro.reset(); }); } void Study::ensureDataAreLoadedForAllBindingConstraints() diff --git a/src/solver/ts-generator/generator.cpp b/src/solver/ts-generator/generator.cpp index 3423a9a8ad..c682e412ab 100644 --- a/src/solver/ts-generator/generator.cpp +++ b/src/solver/ts-generator/generator.cpp @@ -50,9 +50,7 @@ void ResizeGeneratedTimeSeries(Data::AreaList& areas, Data::Parameters& params) // Hydro if (params.timeSeriesToGenerate & Data::timeSeriesHydro) { - Data::DataSeriesHydro* const series = area.hydro.series; - const uint nbSeries = params.nbTimeSeriesHydro; - series->resizeTS(nbSeries); + area.hydro.series->resizeTS(params.nbTimeSeriesHydro); } // Thermal diff --git a/src/solver/ts-generator/hydro.cpp b/src/solver/ts-generator/hydro.cpp index c5c2601bed..ccf61f9466 100644 --- a/src/solver/ts-generator/hydro.cpp +++ b/src/solver/ts-generator/hydro.cpp @@ -96,7 +96,7 @@ bool GenerateHydroTimeSeries(Data::Study& study, uint currentYear, Solver::IResu for (uint i = 0; i < DIM; i++) { uint areaIndexI = i / MONTHS_PER_YEAR; - auto* prepro = study.areas.byIndex[areaIndexI]->hydro.prepro; + auto* prepro = study.areas.byIndex[areaIndexI]->hydro.prepro.get(); auto& corre = CORRE[i]; @@ -105,7 +105,7 @@ bool GenerateHydroTimeSeries(Data::Study& study, uint currentYear, Solver::IResu for (uint j = 0; j < DIM; j++) { uint areaIndexJ = j / MONTHS_PER_YEAR; - auto* preproJ = study.areas.byIndex[areaIndexJ]->hydro.prepro; + auto* preproJ = study.areas.byIndex[areaIndexJ]->hydro.prepro.get(); x = std::abs(((int)(i % MONTHS_PER_YEAR) - (int)(j % MONTHS_PER_YEAR)) / 2.); diff --git a/src/solver/ts-generator/include/antares/solver/ts-generator/xcast/studydata.h b/src/solver/ts-generator/include/antares/solver/ts-generator/xcast/studydata.h index 81c42be09a..1ff51a068d 100644 --- a/src/solver/ts-generator/include/antares/solver/ts-generator/xcast/studydata.h +++ b/src/solver/ts-generator/include/antares/solver/ts-generator/xcast/studydata.h @@ -40,7 +40,7 @@ class StudyData final /*! ** \brief Destructor */ - ~StudyData(); + ~StudyData() = default; //@} /*! @@ -77,7 +77,7 @@ class StudyData final //! List of all areas (sub-set of the complete list) Data::Area::Vector localareas; //! Correlation coefficients for each month - const Matrix* correlation[12]; + std::array, 12> correlation; /*! ** \brief Correlation mode (monthly / annual) ** diff --git a/src/solver/ts-generator/xcast/studydata.cpp b/src/solver/ts-generator/xcast/studydata.cpp index c6bbd15b4e..9cf7e641ba 100644 --- a/src/solver/ts-generator/xcast/studydata.cpp +++ b/src/solver/ts-generator/xcast/studydata.cpp @@ -32,32 +32,6 @@ namespace Antares::TSGenerator::XCast StudyData::StudyData(): mode(Data::Correlation::modeNone) { - for (uint realmonth = 0; realmonth != 12; ++realmonth) - { - correlation[realmonth] = nullptr; - } -} - -StudyData::~StudyData() -{ - switch (mode) - { - case Data::Correlation::modeMonthly: - { - for (uint realmonth = 0; realmonth != 12; ++realmonth) - { - delete correlation[realmonth]; - } - break; - } - case Data::Correlation::modeAnnual: - { - delete correlation[0]; - break; - } - case Data::Correlation::modeNone: - break; - } } void StudyData::prepareMatrix(Matrix& m, const Matrix& source) const @@ -92,12 +66,9 @@ void StudyData::reloadDataFromAreaList(const Data::Correlation& originalCorrelat { case Data::Correlation::modeAnnual: { - auto* m = new Matrix(); - prepareMatrix(*m, originalCorrelation.annual); - for (uint realmonth = 0; realmonth != 12; ++realmonth) { - correlation[realmonth] = m; + prepareMatrix(correlation[realmonth], originalCorrelation.annual); } break; } @@ -105,9 +76,7 @@ void StudyData::reloadDataFromAreaList(const Data::Correlation& originalCorrelat { for (uint realmonth = 0; realmonth != 12; ++realmonth) { - auto* m = new Matrix(); - correlation[realmonth] = m; - prepareMatrix(*m, originalCorrelation.monthly[realmonth]); + prepareMatrix(correlation[realmonth], originalCorrelation.monthly[realmonth]); } break; } @@ -115,13 +84,6 @@ void StudyData::reloadDataFromAreaList(const Data::Correlation& originalCorrelat break; } } - else - { - for (uint realmonth = 0; realmonth != 12; ++realmonth) - { - correlation[realmonth] = nullptr; - } - } } } // namespace Antares::TSGenerator::XCast diff --git a/src/solver/ts-generator/xcast/xcast.cpp b/src/solver/ts-generator/xcast/xcast.cpp index b431e8d8ff..2c8a391a22 100644 --- a/src/solver/ts-generator/xcast/xcast.cpp +++ b/src/solver/ts-generator/xcast/xcast.cpp @@ -325,7 +325,7 @@ bool XCast::runWithPredicate(PredicateT& predicate, Progression::Task& progressi pNewMonth = true; - pCorrMonth = pData.correlation[realmonth]; + pCorrMonth = &pData.correlation[realmonth]; for (uint s = 0; s != processCount; ++s) { diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/area/hydroprepro.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/area/hydroprepro.cpp index f2d0ebbabf..115bc0b0d4 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/area/hydroprepro.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/area/hydroprepro.cpp @@ -141,7 +141,7 @@ void HydroPrepro::internalAreaChanged(Antares::Data::Area* area) if (area && !study) study = GetCurrentStudy(); - auto* pPreproHydro = (area) ? area->hydro.prepro : nullptr; + auto* pPreproHydro = (area) ? area->hydro.prepro.get() : nullptr; Renderer::ARendererArea::internalAreaChanged(area); if (pPreproHydro) {