From cb270ed87fbd783beb76c539267ace6057a104b9 Mon Sep 17 00:00:00 2001 From: payetvin <113102157+payetvin@users.noreply.github.com> Date: Wed, 24 Jul 2024 09:39:33 +0200 Subject: [PATCH] Remove dynamic manually allocated memory (#2273) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jason Marechal Co-authored-by: Jason Maréchal <45510813+JasonMarechal25@users.noreply.github.com> --- src/analyzer/atsp/correlations.cpp | 14 +- src/libs/antares/correlation/correlation.cpp | 180 ++++++------------ .../include/antares/correlation/correlation.h | 49 +++-- .../antares/study/parts/thermal/cluster.h | 42 ++-- .../study/include/antares/study/sets.h | 8 +- .../study/include/antares/study/sets.hxx | 36 +--- .../study/include/antares/study/study.h | 46 ++--- .../study/include/antares/study/study.hxx | 3 - .../antares/study/parts/thermal/cluster.cpp | 47 ++--- .../study/parts/thermal/cluster_list.cpp | 40 ++-- src/libs/antares/study/study.cpp | 14 +- src/libs/antares/study/study.extra.cpp | 62 +++--- src/solver/constraints-builder/cbuilder.cpp | 55 +++--- .../solver/constraints-builder/cbuilder.h | 52 ++--- src/solver/constraints-builder/load.cpp | 48 ++--- src/solver/ts-generator/availability.cpp | 2 +- src/solver/ts-generator/hydro.cpp | 42 ++-- src/solver/ts-generator/xcast/studydata.cpp | 40 ++-- src/tests/inmemory-study/in-memory-study.cpp | 2 +- .../test-sc-builder-file-save.cpp | 2 +- src/ui/simulator/application/main/main.cpp | 2 +- .../datagrid/renderer/area/thermalprepro.cpp | 2 +- .../windows/correlation/correlation.cpp | 93 +++++---- 23 files changed, 376 insertions(+), 505 deletions(-) diff --git a/src/analyzer/atsp/correlations.cpp b/src/analyzer/atsp/correlations.cpp index af3c800d5c..120d9d8465 100644 --- a/src/analyzer/atsp/correlations.cpp +++ b/src/analyzer/atsp/correlations.cpp @@ -71,7 +71,7 @@ bool ATSP::computeMonthlyCorrelations() Matrix<> tmpNDP; tmpNDP.reset(realAreaCount, realAreaCount); - double* tmpArray = new double[realAreaCount + 1]; + std::vector tmpArray(realAreaCount + 1); // Initialize mapping, to skip areas which has been disabled // the real number of items is `realAreaCount` @@ -342,7 +342,7 @@ bool ATSP::computeMonthlyCorrelations() resultNDP.entry, ID.entry, ID.width, - tmpArray); + tmpArray.data()); if (shrink < 1.) { if (shrink <= -1.) @@ -381,7 +381,7 @@ bool ATSP::computeMonthlyCorrelations() resultNDP.entry, CORR_MNPZ.entry, CORR_MNPZ.width, - tmpArray); + tmpArray.data()); if (shrink < 1.) { if (shrink <= -1.) // CORR_MNPZ is too close to sdp boundary, shrink CORR_MNP instead @@ -393,7 +393,7 @@ bool ATSP::computeMonthlyCorrelations() resultNDP.entry, ID.entry, ID.width, - tmpArray); + tmpArray.data()); if (shrink <= -1.) { logs.error() << "invalid data, can not be processed"; @@ -505,7 +505,7 @@ bool ATSP::computeMonthlyCorrelations() resultNDP.entry, ID.entry, ID.width, - tmpArray); + tmpArray.data()); if (shrink < 1.) { if (shrink <= -1.) @@ -542,7 +542,7 @@ bool ATSP::computeMonthlyCorrelations() resultNDP.entry, CORR_YNPZ.entry, CORR_YNPZ.width, - tmpArray); + tmpArray.data()); if (shrink < 1.) { if (shrink <= -1.) // CORR_YNP is too close to sdp boundary, shrink CORR_YNP instead @@ -554,7 +554,7 @@ bool ATSP::computeMonthlyCorrelations() resultNDP.entry, ID.entry, ID.width, - tmpArray); + tmpArray.data()); if (shrink <= -1.) { logs.error() << "invalid data, can not be processed"; diff --git a/src/libs/antares/correlation/correlation.cpp b/src/libs/antares/correlation/correlation.cpp index 50b4084bf1..efdf3b3769 100644 --- a/src/libs/antares/correlation/correlation.cpp +++ b/src/libs/antares/correlation/correlation.cpp @@ -1,23 +1,23 @@ /* -** Copyright 2007-2024, RTE (https://www.rte-france.com) -** See AUTHORS.txt -** SPDX-License-Identifier: MPL-2.0 -** This file is part of Antares-Simulator, -** Adequacy and Performance assessment for interconnected energy networks. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the Mozilla Public Licence 2.0 as published by -** the Mozilla Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** Mozilla Public Licence 2.0 for more details. -** -** You should have received a copy of the Mozilla Public Licence 2.0 -** along with Antares_Simulator. If not, see . -*/ + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ #include "antares/correlation/correlation.h" @@ -327,18 +327,10 @@ int InterAreaCorrelationSaveToFile(const Matrix<>* m, const AreaList* l, const c } Correlation::Correlation(): - annual(nullptr), - monthly(nullptr), pMode(modeNone) { } -Correlation::~Correlation() -{ - delete annual; - delete[] monthly; -} - bool Correlation::loadFromFile(Study& study, const AnyString& filename, bool warnings) { #ifndef NDEBUG @@ -397,16 +389,16 @@ void Correlation::internalSaveToINI(Study& study, IO::File::Stream& file) const // mode file << "[general]\nmode = " << ModeToCString(pMode) << "\n\n"; - if (annual) + if (!annual.empty()) { - ExportCorrelationCoefficients(study, *annual, file, "annual"); + ExportCorrelationCoefficients(study, annual, file, "annual"); } else { logs.error() << correlationName << ": the annual correlation coefficients are missing"; } - if (monthly) + if (!monthly.empty()) { for (int month = 0; month < 12; month++) { @@ -428,20 +420,20 @@ bool Correlation::internalLoadFromINITry(Study& study, const IniFile& ini, bool if (JIT::usedFromGUI or pMode == modeAnnual) { - annual = new Matrix<>(); - annual->resize(study.areas.size(), study.areas.size()); - annual->fillUnit(); + annual.clear(); + annual.resize(study.areas.size(), study.areas.size()); + annual.fillUnit(); auto* section = ini.find("annual"); if (section) // the section might be missing { - ReadCorrelationCoefficients(*this, study, *annual, ini, *section, warnings); + ReadCorrelationCoefficients(*this, study, annual, ini, *section, warnings); } } if (JIT::usedFromGUI or pMode == modeMonthly) { - monthly = new Matrix<>[12]; + monthly.resize(12); for (uint i = 0; i < 12; ++i) { monthly[i].resize(study.areas.size(), study.areas.size()); @@ -475,28 +467,18 @@ bool Correlation::internalLoadFromINITry(Study& study, const IniFile& ini, bool void Correlation::reset(Study& study) { - // Clean - if (annual) - { - delete annual; - annual = nullptr; - } - if (monthly) - { - delete[] monthly; - monthly = nullptr; - } + clear(); pMode = modeAnnual; if (JIT::usedFromGUI) { // Reset - annual = new Matrix<>(); - annual->resize(study.areas.size(), study.areas.size()); - annual->fillUnit(); + annual.clear(); + annual.resize(study.areas.size(), study.areas.size()); + annual.fillUnit(); // Preparing the monthly correlation matrices - monthly = new Matrix<>[12]; + monthly.resize(12); for (int i = 0; i < 12; ++i) { monthly[i].resize(study.areas.size(), study.areas.size()); @@ -505,40 +487,21 @@ void Correlation::reset(Study& study) } else { - annual = new Matrix<>(); - annual->resize(study.areas.size(), study.areas.size()); - annual->fillUnit(); + annual.clear(); + annual.resize(study.areas.size(), study.areas.size()); + annual.fillUnit(); } } void Correlation::clear() { - // Clean - if (annual) - { - delete annual; - annual = nullptr; - } - if (monthly) - { - delete[] monthly; - monthly = nullptr; - } + annual.reset(); + monthly.clear(); } bool Correlation::internalLoadFromINI(Study& study, const IniFile& ini, bool warnings) { - // Clean - if (annual) - { - delete annual; - annual = nullptr; - } - if (monthly) - { - delete[] monthly; - monthly = nullptr; - } + clear(); if (!internalLoadFromINITry(study, ini, warnings)) { @@ -546,28 +509,22 @@ bool Correlation::internalLoadFromINI(Study& study, const IniFile& ini, bool war pMode = modeAnnual; if (JIT::usedFromGUI) { - // Reset - annual = new Matrix<>(); - annual->resize(study.areas.size(), study.areas.size()); - annual->fillUnit(); - // Preparing the monthly correlation matrices - monthly = new Matrix<>[12]; + monthly.resize(12); for (int i = 0; i < 12; ++i) { monthly[i].resize(study.areas.size(), study.areas.size()); monthly[i].fillUnit(); } } - else - { - annual = new Matrix<>(); - annual->resize(study.areas.size(), study.areas.size()); - annual->fillUnit(); - } + + annual.clear(); + annual.resize(study.areas.size(), study.areas.size()); + annual.fillUnit(); return false; } + return true; } @@ -600,45 +557,14 @@ void Correlation::set(Matrix<>& m, const Area& from, const Area& to, double v) m[to.index][from.index] = v; } -void Correlation::retrieveMontlyMatrixArray(const Matrix<>* array[12]) const -{ - switch (pMode) - { - case modeAnnual: - { - for (uint i = 0; i != 12; ++i) - { - array[i] = annual; - } - break; - } - case modeMonthly: - { - for (uint i = 0; i != 12; ++i) - { - array[i] = &(monthly[i]); - } - break; - } - default: - { - for (uint i = 0; i != 12; ++i) - { - array[i] = nullptr; - } - return; - } - } -} - uint64_t Correlation::memoryUsage() const { uint64_t r = sizeof(Correlation); - if (annual) + if (!annual.empty()) { - r += annual->memoryUsage(); + r += annual.memoryUsage(); } - if (monthly) + if (!monthly.empty()) { for (uint i = 0; i != 12; ++i) { @@ -651,9 +577,9 @@ uint64_t Correlation::memoryUsage() const bool Correlation::forceReload(bool reload) const { bool ret = true; - if (annual) + if (!annual.empty()) { - ret = annual->forceReload(reload) and ret; + ret = annual.forceReload(reload) and ret; } for (uint i = 0; i != 12; ++i) { @@ -665,9 +591,9 @@ bool Correlation::forceReload(bool reload) const void Correlation::markAsModified() const { - if (annual) + if (!annual.empty()) { - annual->markAsModified(); + annual.markAsModified(); } for (uint i = 0; i != 12; ++i) { @@ -762,8 +688,8 @@ void Correlation::copyFrom(const Correlation& source, // copying the annual correlation matrix std::cout << "ANNUAL\n"; - CopyFromSingleMatrix(*source.annual, - *annual, + CopyFromSingleMatrix(source.annual, + annual, studySource, areaSourceIndex, areaTargetIndex, diff --git a/src/libs/antares/correlation/include/antares/correlation/correlation.h b/src/libs/antares/correlation/include/antares/correlation/correlation.h index 9dc48c5a76..c0ffebe4a0 100644 --- a/src/libs/antares/correlation/include/antares/correlation/correlation.h +++ b/src/libs/antares/correlation/include/antares/correlation/correlation.h @@ -1,23 +1,23 @@ /* -** Copyright 2007-2024, RTE (https://www.rte-france.com) -** See AUTHORS.txt -** SPDX-License-Identifier: MPL-2.0 -** This file is part of Antares-Simulator, -** Adequacy and Performance assessment for interconnected energy networks. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the Mozilla Public Licence 2.0 as published by -** the Mozilla Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** Mozilla Public Licence 2.0 for more details. -** -** You should have received a copy of the Mozilla Public Licence 2.0 -** along with Antares_Simulator. If not, see . -*/ + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ #ifndef __ANTARES_LIBS_ARRAY_CORRELATION_H__ #define __ANTARES_LIBS_ARRAY_CORRELATION_H__ @@ -62,7 +62,7 @@ class Correlation final /*! ** \brief Destructor */ - ~Correlation(); + ~Correlation() = default; //@} //! \name Mode @@ -123,11 +123,6 @@ class Correlation final const AreaNameMapping& mapping, const Study& study); - /*! - ** \brief - */ - void retrieveMontlyMatrixArray(const Matrix<>* array[12]) const; - /*! ** \brief Get the amount of memory used the correlation matrices */ @@ -145,9 +140,9 @@ class Correlation final public: //! The correlation matrix for the whole year - Matrix<>* annual; + Matrix<> annual; //! All correlation matrices per month (12) - Matrix<>* monthly; // [12] + std::vector> monthly; // [12] //! The name to displays in logs Yuni::CString<30, false> correlationName; diff --git a/src/libs/antares/study/include/antares/study/parts/thermal/cluster.h b/src/libs/antares/study/include/antares/study/parts/thermal/cluster.h index 7d1ce30bac..9216ac88aa 100644 --- a/src/libs/antares/study/include/antares/study/parts/thermal/cluster.h +++ b/src/libs/antares/study/include/antares/study/parts/thermal/cluster.h @@ -1,23 +1,23 @@ /* -** Copyright 2007-2024, RTE (https://www.rte-france.com) -** See AUTHORS.txt -** SPDX-License-Identifier: MPL-2.0 -** This file is part of Antares-Simulator, -** Adequacy and Performance assessment for interconnected energy networks. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the Mozilla Public Licence 2.0 as published by -** the Mozilla Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** Mozilla Public Licence 2.0 for more details. -** -** You should have received a copy of the Mozilla Public Licence 2.0 -** along with Antares_Simulator. If not, see . -*/ + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ #ifndef __ANTARES_LIBS_STUDY_PARTS_THERMAL_CLUSTER_H__ #define __ANTARES_LIBS_STUDY_PARTS_THERMAL_CLUSTER_H__ @@ -115,7 +115,7 @@ class ThermalCluster final: public Cluster, public std::enable_shared_from_this< explicit ThermalCluster(Data::Area* parent); ThermalCluster() = delete; - ~ThermalCluster(); + ~ThermalCluster() = default; /*! ** \brief Invalidate all data associated to the thermal cluster @@ -353,7 +353,7 @@ class ThermalCluster final: public Cluster, public std::enable_shared_from_this< std::vector PthetaInf; //! Data for the preprocessor - PreproAvailability* prepro = nullptr; + std::unique_ptr prepro; /*! ** \brief Production Cost, Market Bid Cost and Marginal Cost Matrixes - Per Hour and per Time diff --git a/src/libs/antares/study/include/antares/study/sets.h b/src/libs/antares/study/include/antares/study/sets.h index 0309916749..414847af2f 100644 --- a/src/libs/antares/study/include/antares/study/sets.h +++ b/src/libs/antares/study/include/antares/study/sets.h @@ -134,7 +134,7 @@ class Sets final */ Sets(const Sets& rhs); //! Destructor - ~Sets(); + ~Sets() = default; //@} //! \name Iterators @@ -155,7 +155,7 @@ class Sets final */ TypePtr add(const IDType& name) { - TypePtr p = new T(); + TypePtr p = std::make_shared(); pMap[name] = p; pOptions[name].reset(name); return p; @@ -269,8 +269,8 @@ class Sets final MapType pMap; MapOptions pOptions; //! - TypePtr* pByIndex; - IDType* pNameByIndex; + std::vector pByIndex; + std::vector pNameByIndex; mutable bool pModified; }; // class Sets diff --git a/src/libs/antares/study/include/antares/study/sets.hxx b/src/libs/antares/study/include/antares/study/sets.hxx index 931e044ba0..2a1b777995 100644 --- a/src/libs/antares/study/include/antares/study/sets.hxx +++ b/src/libs/antares/study/include/antares/study/sets.hxx @@ -27,8 +27,6 @@ namespace Data { template inline Sets::Sets(): - pByIndex(NULL), - pNameByIndex(NULL), pModified(false) { } @@ -37,8 +35,6 @@ template inline Sets::Sets(const Sets& rhs): pMap(rhs.pMap), pOptions(rhs.pOptions), - pByIndex(NULL), - pNameByIndex(NULL), pModified(false) { if (rhs.pByIndex) @@ -47,12 +43,6 @@ inline Sets::Sets(const Sets& rhs): } } -template -inline Sets::~Sets() -{ - delete[] pByIndex; -} - template typename Sets::iterator Sets::begin() { @@ -80,17 +70,8 @@ typename Sets::const_iterator Sets::end() const template void Sets::clear() { - if (pByIndex) - { - delete[] pByIndex; - pByIndex = NULL; - } - if (pNameByIndex) - { - delete[] pNameByIndex; - pNameByIndex = NULL; - } - + pByIndex.clear(); + pNameByIndex.clear(); pMap.clear(); pOptions.clear(); } @@ -401,13 +382,13 @@ void Sets::rebuildFromRules(const IDType& id, HandlerT& handler) template void Sets::rebuildIndexes() { - delete[] pByIndex; - delete[] pNameByIndex; + pNameByIndex.clear(); + pByIndex.clear(); if (!pMap.empty()) { - pByIndex = new TypePtr[pMap.size()]; - pNameByIndex = new IDType[pMap.size()]; + pByIndex.resize(pMap.size()); + pNameByIndex.resize(pMap.size()); const typename MapType::iterator end = pMap.end(); uint index = 0; for (typename MapType::iterator i = pMap.begin(); i != end; ++i) @@ -417,11 +398,6 @@ void Sets::rebuildIndexes() ++index; } } - else - { - pByIndex = NULL; - pNameByIndex = NULL; - } } template diff --git a/src/libs/antares/study/include/antares/study/study.h b/src/libs/antares/study/include/antares/study/study.h index 65f8f531fd..d8a187f9f9 100644 --- a/src/libs/antares/study/include/antares/study/study.h +++ b/src/libs/antares/study/include/antares/study/study.h @@ -1,23 +1,23 @@ /* -** Copyright 2007-2024, RTE (https://www.rte-france.com) -** See AUTHORS.txt -** SPDX-License-Identifier: MPL-2.0 -** This file is part of Antares-Simulator, -** Adequacy and Performance assessment for interconnected energy networks. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the Mozilla Public Licence 2.0 as published by -** the Mozilla Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** Mozilla Public Licence 2.0 for more details. -** -** You should have received a copy of the Mozilla Public Licence 2.0 -** along with Antares_Simulator. If not, see . -*/ + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ #ifndef __ANTARES_LIBS_STUDY_STUDY_H__ #define __ANTARES_LIBS_STUDY_STUDY_H__ @@ -363,8 +363,6 @@ class Study: public Yuni::NonCopyable, public LayerData void destroyAllWindTSGeneratorData(); //! Destroy all data of the hydro TS generator void destroyAllHydroTSGeneratorData(); - //! Destroy all data of the thermal TS generator - void destroyAllThermalTSGeneratorData(); /*! ** \brief Import all time-series into the input folder @@ -391,10 +389,6 @@ class Study: public Yuni::NonCopyable, public LayerData ** \brief Re-Initialize/Re-Load the scenario builder data */ void scenarioRulesCreate(); - /*! - ** \brief Re-Initialize/Re-Load the scenario builder data but consider a single ruleset only - */ - void scenarioRulesCreate(const RulesScenarioName& thisoneonly); /*! ** \brief Release the scenario builder @@ -586,7 +580,7 @@ class Study: public Yuni::NonCopyable, public LayerData //! \name Scenario Builder //@{ //! Rules for building scenarios (can be null) - ScenarioBuilder::Sets* scenarioRules = nullptr; + std::unique_ptr scenarioRules; //@} TimeSeries::TS scenarioInitialHydroLevels; diff --git a/src/libs/antares/study/include/antares/study/study.hxx b/src/libs/antares/study/include/antares/study/study.hxx index 9f0053d0a4..5c1ad58282 100644 --- a/src/libs/antares/study/include/antares/study/study.hxx +++ b/src/libs/antares/study/include/antares/study/study.hxx @@ -53,9 +53,6 @@ inline void Study::destroyTSGeneratorData() case TimeSeriesType::timeSeriesHydro: destroyAllHydroTSGeneratorData(); break; - case TimeSeriesType::timeSeriesThermal: - destroyAllThermalTSGeneratorData(); - break; default: break; } diff --git a/src/libs/antares/study/parts/thermal/cluster.cpp b/src/libs/antares/study/parts/thermal/cluster.cpp index da502ac29e..9198bc1ec6 100644 --- a/src/libs/antares/study/parts/thermal/cluster.cpp +++ b/src/libs/antares/study/parts/thermal/cluster.cpp @@ -1,23 +1,23 @@ /* -** Copyright 2007-2024, RTE (https://www.rte-france.com) -** See AUTHORS.txt -** SPDX-License-Identifier: MPL-2.0 -** This file is part of Antares-Simulator, -** Adequacy and Performance assessment for interconnected energy networks. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the Mozilla Public Licence 2.0 as published by -** the Mozilla Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** Mozilla Public Licence 2.0 for more details. -** -** You should have received a copy of the Mozilla Public Licence 2.0 -** along with Antares_Simulator. If not, see . -*/ + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ #include "antares/study/parts/thermal/cluster.h" @@ -129,11 +129,6 @@ Data::ThermalCluster::ThermalCluster(Area* parent): assert(parent && "A parent for a thermal dispatchable cluster can not be null"); } -Data::ThermalCluster::~ThermalCluster() -{ - delete prepro; -} - uint ThermalCluster::groupId() const { return groupID; @@ -202,7 +197,7 @@ void Data::ThermalCluster::copyFrom(const ThermalCluster& cluster) // prepro if (!prepro) { - prepro = new PreproAvailability(id(), unitCount); + prepro = std::make_unique(id(), unitCount); } prepro->copyFrom(*cluster.prepro); @@ -477,7 +472,7 @@ void Data::ThermalCluster::reset() // we must simply reset their content. if (!prepro) { - prepro = new PreproAvailability(id(), unitCount); + prepro = std::make_unique(id(), unitCount); } prepro->reset(); diff --git a/src/libs/antares/study/parts/thermal/cluster_list.cpp b/src/libs/antares/study/parts/thermal/cluster_list.cpp index 8435870d0a..1b46282504 100644 --- a/src/libs/antares/study/parts/thermal/cluster_list.cpp +++ b/src/libs/antares/study/parts/thermal/cluster_list.cpp @@ -1,23 +1,23 @@ /* -** Copyright 2007-2024, RTE (https://www.rte-france.com) -** See AUTHORS.txt -** SPDX-License-Identifier: MPL-2.0 -** This file is part of Antares-Simulator, -** Adequacy and Performance assessment for interconnected energy networks. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the Mozilla Public Licence 2.0 as published by -** the Mozilla Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** Mozilla Public Licence 2.0 for more details. -** -** You should have received a copy of the Mozilla Public Licence 2.0 -** along with Antares_Simulator. If not, see . -*/ + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ #include "antares/study/parts/thermal/cluster_list.h" @@ -388,7 +388,7 @@ void ThermalClusterList::ensureDataPrepro() { if (!c->prepro) { - c->prepro = new PreproAvailability(c->id(), c->unitCount); + c->prepro = std::make_unique(c->id(), c->unitCount); } } } diff --git a/src/libs/antares/study/study.cpp b/src/libs/antares/study/study.cpp index 01d91b3abb..2ef5ccc5dd 100644 --- a/src/libs/antares/study/study.cpp +++ b/src/libs/antares/study/study.cpp @@ -104,7 +104,7 @@ Study::~Study() void Study::clear() { - FreeAndNil(scenarioRules); + scenarioRules.reset(); FreeAndNil(uiinfo); // areas @@ -1104,18 +1104,6 @@ void Study::destroyAllWindTSGeneratorData() areas.each([](Data::Area& area) { FreeAndNil(area.wind.prepro); }); } -void Study::destroyAllThermalTSGeneratorData() -{ - areas.each( - [](const Data::Area& area) - { - for (const auto& cluster: area.thermal.list.each_enabled_and_not_mustrun()) - { - FreeAndNil(cluster->prepro); - } - }); -} - void Study::ensureDataAreLoadedForAllBindingConstraints() { for (const auto& constraint: bindingConstraints) diff --git a/src/libs/antares/study/study.extra.cpp b/src/libs/antares/study/study.extra.cpp index 1ec628c321..fdfb6eb2d3 100644 --- a/src/libs/antares/study/study.extra.cpp +++ b/src/libs/antares/study/study.extra.cpp @@ -1,23 +1,23 @@ /* -** Copyright 2007-2024, RTE (https://www.rte-france.com) -** See AUTHORS.txt -** SPDX-License-Identifier: MPL-2.0 -** This file is part of Antares-Simulator, -** Adequacy and Performance assessment for interconnected energy networks. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the Mozilla Public Licence 2.0 as published by -** the Mozilla Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** Mozilla Public Licence 2.0 for more details. -** -** You should have received a copy of the Mozilla Public Licence 2.0 -** along with Antares_Simulator. If not, see . -*/ + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ #include "antares/study/study.h" @@ -35,32 +35,16 @@ String StudyIconFile; void Study::scenarioRulesCreate() { // releasing the previous instance of the scenario builder - delete scenarioRules; + scenarioRules.reset(); // When ran from the solver, the scenario builder must be present - scenarioRules = new ScenarioBuilder::Sets(); - scenarioRules->loadFromStudy(*this); -} - -void Study::scenarioRulesCreate(const RulesScenarioName& /*thisoneonly*/) -{ - // releasing the previous instance of the scenario builder - delete scenarioRules; - // When ran from the solver, the scenario builder must be present - scenarioRules = new ScenarioBuilder::Sets(); + scenarioRules = std::make_unique(); scenarioRules->loadFromStudy(*this); } void Study::scenarioRulesDestroy() { - if (scenarioRules) - { - // releasing the previous instance of the scenario builder - // safety dereferencing for the interface if running - ScenarioBuilder::Sets* sb = scenarioRules; - scenarioRules = nullptr; - delete sb; - } + scenarioRules.reset(); } void Study::scenarioRulesLoadIfNotAvailable() @@ -68,7 +52,7 @@ void Study::scenarioRulesLoadIfNotAvailable() if (!scenarioRules) { // When ran from the solver, the scenario builder must be present - scenarioRules = new ScenarioBuilder::Sets(); + scenarioRules = std::make_unique(); scenarioRules->loadFromStudy(*this); } } diff --git a/src/solver/constraints-builder/cbuilder.cpp b/src/solver/constraints-builder/cbuilder.cpp index 2a1e1b8dce..5c02947a6f 100644 --- a/src/solver/constraints-builder/cbuilder.cpp +++ b/src/solver/constraints-builder/cbuilder.cpp @@ -1,23 +1,23 @@ /* -** Copyright 2007-2024, RTE (https://www.rte-france.com) -** See AUTHORS.txt -** SPDX-License-Identifier: MPL-2.0 -** This file is part of Antares-Simulator, -** Adequacy and Performance assessment for interconnected energy networks. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the Mozilla Public Licence 2.0 as published by -** the Mozilla Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** Mozilla Public Licence 2.0 for more details. -** -** You should have received a copy of the Mozilla Public Licence 2.0 -** along with Antares_Simulator. If not, see . -*/ + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ #include "antares/solver/constraints-builder/cbuilder.h" @@ -54,15 +54,6 @@ CBuilder::CBuilder(Antares::Data::Study& study): { } -CBuilder::~CBuilder() -{ - // delete all the elements of pLink - for (auto i = pLink.begin(); i != pLink.end(); i++) - { - delete *i; - } -} - bool Antares::CBuilder::isCycleDriver(linkInfo* lnkI) { std::string s1(lnkI->ptr->from->name.to()); @@ -180,7 +171,7 @@ bool CBuilder::updateLinks() } // check validity of loopflow against NTC - if (includeLoopFlow && !checkValidityOfNodalLoopFlow(linkInfo, hour)) + if (includeLoopFlow && !checkValidityOfNodalLoopFlow(linkInfo.get(), hour)) { return false; } @@ -190,8 +181,8 @@ bool CBuilder::updateLinks() continue; } - updateLinkPhaseShift(linkInfo, hour); - if (!checkLinkPhaseShift(linkInfo, hour)) + updateLinkPhaseShift(linkInfo.get(), hour); + if (!checkLinkPhaseShift(linkInfo.get(), hour)) { return false; } @@ -239,7 +230,7 @@ bool CBuilder::update() && ((*linkInfoIt)->type == Antares::Data::atAC /*|| (*linkInfoIt)->type == linkInfo::tyACPST*/)) { - enabledACLines.push_back(*linkInfoIt); + enabledACLines.push_back((*linkInfoIt).get()); } } diff --git a/src/solver/constraints-builder/include/antares/solver/constraints-builder/cbuilder.h b/src/solver/constraints-builder/include/antares/solver/constraints-builder/cbuilder.h index 833f9e82e6..29ddd2b4c5 100644 --- a/src/solver/constraints-builder/include/antares/solver/constraints-builder/cbuilder.h +++ b/src/solver/constraints-builder/include/antares/solver/constraints-builder/cbuilder.h @@ -1,23 +1,23 @@ /* -** Copyright 2007-2024, RTE (https://www.rte-france.com) -** See AUTHORS.txt -** SPDX-License-Identifier: MPL-2.0 -** This file is part of Antares-Simulator, -** Adequacy and Performance assessment for interconnected energy networks. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the Mozilla Public Licence 2.0 as published by -** the Mozilla Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** Mozilla Public Licence 2.0 for more details. -** -** You should have received a copy of the Mozilla Public Licence 2.0 -** along with Antares_Simulator. If not, see . -*/ + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ #ifndef __ANTARES_CONSTRAINTSBUILDER_BUILDER_CBUILDER_H__ #define __ANTARES_CONSTRAINTSBUILDER_BUILDER_CBUILDER_H__ @@ -231,7 +231,7 @@ class CBuilder final */ CBuilder(Antares::Data::Study&); //! Destructor - ~CBuilder(); + ~CBuilder() = default; //@} /*! @@ -262,7 +262,7 @@ class CBuilder final { auto linkIT = std::find_if(pLink.begin(), pLink.end(), - [&u, &v](const linkInfo* edgeP) -> bool + [&u, &v](std::shared_ptr edgeP) -> bool { if (edgeP->ptr->from->id == u && edgeP->ptr->with->id == v) { @@ -279,7 +279,7 @@ class CBuilder final }); if (linkIT != pLink.end()) { - return *linkIT; + return linkIT->get(); } return nullptr; @@ -294,11 +294,11 @@ class CBuilder final auto a = area.second; std::for_each(pLink.begin(), pLink.end(), - [&a, this](linkInfo* edgeP) + [&a, this](std::shared_ptr edgeP) { if (edgeP->ptr->from == a || edgeP->ptr->with == a) { - this->areaToLinks[a].insert(edgeP); + this->areaToLinks[a].insert(edgeP.get()); } }); } @@ -308,7 +308,7 @@ class CBuilder final { if (i < pLink.size()) { - return pLink[i]; + return pLink[i].get(); } return nullptr; } @@ -418,7 +418,7 @@ class CBuilder final const double& secondMember); public: - Vector pLink; + std::vector> pLink; private: std::string pPrefix; diff --git a/src/solver/constraints-builder/load.cpp b/src/solver/constraints-builder/load.cpp index 22d8632cda..73beec49c1 100644 --- a/src/solver/constraints-builder/load.cpp +++ b/src/solver/constraints-builder/load.cpp @@ -1,23 +1,23 @@ /* -** Copyright 2007-2024, RTE (https://www.rte-france.com) -** See AUTHORS.txt -** SPDX-License-Identifier: MPL-2.0 -** This file is part of Antares-Simulator, -** Adequacy and Performance assessment for interconnected energy networks. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the Mozilla Public Licence 2.0 as published by -** the Mozilla Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** Mozilla Public Licence 2.0 for more details. -** -** You should have received a copy of the Mozilla Public Licence 2.0 -** along with Antares_Simulator. If not, see . -*/ + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ #include #include @@ -43,18 +43,18 @@ bool CBuilder::completeFromStudy() { // for all links of the study // check if it has been enabled in the INI File - linkInfo* k = findLinkInfoFromNodeNames(j->second->from->id, j->second->with->id); + auto k = findLinkInfoFromNodeNames(j->second->from->id, j->second->with->id); if (!k) { - k = new linkInfo(); + auto infos = std::make_shared(); logs.info() << "Read data (link " << nCount++ << ")"; // if Yes, complete the linkInfo // load the pointer - k->ptr = j->second; - k->type = k->ptr->assetType; + infos->ptr = j->second; + infos->type = infos->ptr->assetType; - pLink.push_back(k); + pLink.push_back(infos); } } } diff --git a/src/solver/ts-generator/availability.cpp b/src/solver/ts-generator/availability.cpp index a94fd99e46..1ac5e7675b 100644 --- a/src/solver/ts-generator/availability.cpp +++ b/src/solver/ts-generator/availability.cpp @@ -38,7 +38,7 @@ AvailabilityTSGeneratorData::AvailabilityTSGeneratorData(Data::ThermalCluster* c plannedVolatility(cluster->plannedVolatility), forcedLaw(cluster->forcedLaw), plannedLaw(cluster->plannedLaw), - prepro(cluster->prepro), + prepro(cluster->prepro.get()), modulationCapacity(cluster->modulation[Data::thermalModulationCapacity]), name(cluster->name()) { diff --git a/src/solver/ts-generator/hydro.cpp b/src/solver/ts-generator/hydro.cpp index 168b290dfb..c5c2601bed 100644 --- a/src/solver/ts-generator/hydro.cpp +++ b/src/solver/ts-generator/hydro.cpp @@ -1,23 +1,23 @@ /* -** Copyright 2007-2024, RTE (https://www.rte-france.com) -** See AUTHORS.txt -** SPDX-License-Identifier: MPL-2.0 -** This file is part of Antares-Simulator, -** Adequacy and Performance assessment for interconnected energy networks. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the Mozilla Public Licence 2.0 as published by -** the Mozilla Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** Mozilla Public Licence 2.0 for more details. -** -** You should have received a copy of the Mozilla Public Licence 2.0 -** along with Antares_Simulator. If not, see . -*/ + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ #include @@ -80,7 +80,7 @@ bool GenerateHydroTimeSeries(Data::Study& study, uint currentYear, Solver::IResu double** nullmatrx = nullptr; if (1. > Solver::MatrixDPMake(CHSKY.entry, - study.preproHydroCorrelation.annual->entry, + study.preproHydroCorrelation.annual.entry, B.entry, nullmatrx, study.areas.size(), @@ -100,7 +100,7 @@ bool GenerateHydroTimeSeries(Data::Study& study, uint currentYear, Solver::IResu auto& corre = CORRE[i]; - auto& annualCorrAreaI = (*study.preproHydroCorrelation.annual)[areaIndexI]; + auto& annualCorrAreaI = study.preproHydroCorrelation.annual[areaIndexI]; for (uint j = 0; j < DIM; j++) { diff --git a/src/solver/ts-generator/xcast/studydata.cpp b/src/solver/ts-generator/xcast/studydata.cpp index 217f61fe14..c6bbd15b4e 100644 --- a/src/solver/ts-generator/xcast/studydata.cpp +++ b/src/solver/ts-generator/xcast/studydata.cpp @@ -1,23 +1,23 @@ /* -** Copyright 2007-2024, RTE (https://www.rte-france.com) -** See AUTHORS.txt -** SPDX-License-Identifier: MPL-2.0 -** This file is part of Antares-Simulator, -** Adequacy and Performance assessment for interconnected energy networks. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the Mozilla Public Licence 2.0 as published by -** the Mozilla Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** Mozilla Public Licence 2.0 for more details. -** -** You should have received a copy of the Mozilla Public Licence 2.0 -** along with Antares_Simulator. If not, see . -*/ + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ #include "antares/solver/ts-generator/xcast/studydata.h" @@ -93,7 +93,7 @@ void StudyData::reloadDataFromAreaList(const Data::Correlation& originalCorrelat case Data::Correlation::modeAnnual: { auto* m = new Matrix(); - prepareMatrix(*m, *(originalCorrelation.annual)); + prepareMatrix(*m, originalCorrelation.annual); for (uint realmonth = 0; realmonth != 12; ++realmonth) { diff --git a/src/tests/inmemory-study/in-memory-study.cpp b/src/tests/inmemory-study/in-memory-study.cpp index 1f3f78c194..cfe1c1d130 100644 --- a/src/tests/inmemory-study/in-memory-study.cpp +++ b/src/tests/inmemory-study/in-memory-study.cpp @@ -172,7 +172,7 @@ averageResults OutputRetriever::thermalNbUnitsON(ThermalCluster* cluster) ScenarioBuilderRule::ScenarioBuilderRule(Study& study) { study.scenarioRulesCreate(); - ScenarioBuilder::Sets* sets = study.scenarioRules; + auto sets = study.scenarioRules.get(); if (sets && !sets->empty()) { rules_ = sets->createNew("Custom"); diff --git a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp index 64813637fc..e9a410b983 100644 --- a/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp +++ b/src/tests/src/libs/antares/study/scenario-builder/test-sc-builder-file-save.cpp @@ -188,7 +188,7 @@ struct commonFixture study->bindingConstraintsGroups.add("group3"); // Scenario builder initialization - study->scenarioRules = new ScenarioBuilder::Sets(); + study->scenarioRules = std::make_unique(); study->scenarioRules->setStudy(*study); my_rule = study->scenarioRules->createNew("my rule name"); BOOST_CHECK(my_rule->reset()); diff --git a/src/ui/simulator/application/main/main.cpp b/src/ui/simulator/application/main/main.cpp index 3b321e6c12..31865edc53 100644 --- a/src/ui/simulator/application/main/main.cpp +++ b/src/ui/simulator/application/main/main.cpp @@ -702,7 +702,7 @@ void ApplWnd::onSectionNotebookPageChanging(Component::Notebook::Page& page) auto* job = new JobLoadScenarioBuilder(*study); wxTheApp->Yield(); job->run(); - study->scenarioRules = job->scenarioBuilder(); + study->scenarioRules.reset(job->scenarioBuilder()); job->Destroy(); } diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/area/thermalprepro.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/area/thermalprepro.cpp index 4c39002613..d169a59f91 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/area/thermalprepro.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/area/thermalprepro.cpp @@ -183,7 +183,7 @@ bool ThermalClusterPrepro::cellValue(int x, int y, const String& value) void ThermalClusterPrepro::internalThermalClusterChanged(Antares::Data::ThermalCluster* cluster) { pCluster = cluster; - pPreproAvailability = (cluster) ? cluster->prepro : nullptr; + pPreproAvailability = (cluster) ? cluster->prepro.get() : nullptr; MatrixAncestorType::matrix((pPreproAvailability) ? &pPreproAvailability->data : nullptr); onRefresh(); } diff --git a/src/ui/simulator/windows/correlation/correlation.cpp b/src/ui/simulator/windows/correlation/correlation.cpp index 762479f64e..110182bbde 100644 --- a/src/ui/simulator/windows/correlation/correlation.cpp +++ b/src/ui/simulator/windows/correlation/correlation.cpp @@ -1,36 +1,37 @@ /* -** Copyright 2007-2024, RTE (https://www.rte-france.com) -** See AUTHORS.txt -** SPDX-License-Identifier: MPL-2.0 -** This file is part of Antares-Simulator, -** Adequacy and Performance assessment for interconnected energy networks. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the Mozilla Public Licence 2.0 as published by -** the Mozilla Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** Mozilla Public Licence 2.0 for more details. -** -** You should have received a copy of the Mozilla Public Licence 2.0 -** along with Antares_Simulator. If not, see . -*/ + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ #include "correlation.h" + +#include +#include + +#include + #include "../../application/study.h" -#include "../../toolbox/components/notebook/notebook.h" #include "../../toolbox/components/datagrid/component.h" #include "../../toolbox/components/datagrid/renderer/correlation.h" +#include "../../toolbox/components/notebook/notebook.h" #include "../../toolbox/components/refresh.h" -#include #include "../../toolbox/resources.h" - -#include -#include - #include "datasources.hxx" using namespace Yuni; @@ -45,12 +46,17 @@ class CorrelationPanelData final using CorrelationMatrixType = Component::Datagrid::Renderer::CorrelationMatrix; public: - CorrelationPanelData() : pCorrelation(nullptr) + CorrelationPanelData(): + pCorrelation(nullptr) { for (uint i = 0; i != 12; ++i) + { pGridMonthly[i] = nullptr; + } for (uint i = 0; i != 12 + 1; ++i) + { renderer[i] = nullptr; + } } public: @@ -62,7 +68,8 @@ class CorrelationPanelData final CorrelationMatrixType::IDatasource::Ptr datasource; }; -CorrelationPanel::CorrelationPanel(wxWindow* parent, int timeseries) : wxPanel(parent, wxID_ANY) +CorrelationPanel::CorrelationPanel(wxWindow* parent, int timeseries): + wxPanel(parent, wxID_ANY) { // Init pData = new CorrelationPanelData(); @@ -113,8 +120,9 @@ CorrelationPanel::CorrelationPanel(wxWindow* parent, int timeseries) : wxPanel(p }; #endif - btn - = Resources::BitmapButtonLoadFromFile(panel, wxID_ANY, "images/16x16/sort_alphabet.png"); + btn = Resources::BitmapButtonLoadFromFile(panel, + wxID_ANY, + "images/16x16/sort_alphabet.png"); btn->Connect(btn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(CorrelationPanel::onSortAlpha), @@ -123,8 +131,9 @@ CorrelationPanel::CorrelationPanel(wxWindow* parent, int timeseries) : wxPanel(p panel->GetSizer()->Add(btn, 0, wxALL | wxEXPAND, margin); // Sort - reverse - btn = Resources::BitmapButtonLoadFromFile( - panel, wxID_ANY, "images/16x16/sort_alphabet_descending.png"); + btn = Resources::BitmapButtonLoadFromFile(panel, + wxID_ANY, + "images/16x16/sort_alphabet_descending.png"); btn->Connect(btn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(CorrelationPanel::onSortAlphaReverse), @@ -145,8 +154,8 @@ CorrelationPanel::CorrelationPanel(wxWindow* parent, int timeseries) : wxPanel(p { for (uint i = 0; i != 12; ++i) { - pData->pGridMonthly[i] - = new Component::Datagrid::Component(notebook, pData->renderer[i]); + pData->pGridMonthly[i] = new Component::Datagrid::Component(notebook, + pData->renderer[i]); pData->renderer[i]->control(pData->pGridMonthly[i]); notebook->add(pData->pGridMonthly[i], months[i]); } @@ -192,7 +201,9 @@ CorrelationPanel::~CorrelationPanel() // we should destroy all children as soon as possible. wxSizer* sizer = GetSizer(); if (sizer) + { sizer->Clear(true); + } } void CorrelationPanel::onStudyLoaded() @@ -226,7 +237,9 @@ void CorrelationPanel::reload() { assignMatrices(nullptr); if (not pData) + { return; + } pData->datasource->reload(); @@ -256,12 +269,16 @@ void CorrelationPanel::reload() // It is useless to reassign matrices since they are already // assigned to null if (pData->pCorrelation) + { assignMatrices(pData->pCorrelation); + } // Force refresh RefreshAllControls(pData->pGridAnnual); for (uint i = 0; i != 12; ++i) + { RefreshAllControls(pData->pGridMonthly[i]); + } } void CorrelationPanel::updateAllDatasources() @@ -270,13 +287,17 @@ void CorrelationPanel::updateAllDatasources() for (uint i = 0; i != 12 + 1; ++i) { if (pData->renderer[i]) + { pData->renderer[i]->datasource(pData->datasource); + } } for (uint i = 0; i != 12; ++i) { if (pData->pGridMonthly[i]) + { pData->pGridMonthly[i]->forceRefresh(); + } } pData->pGridAnnual->forceRefresh(); } @@ -308,7 +329,9 @@ void CorrelationPanel::assignMatrices(Data::Correlation* corr) for (uint i = 0; i < 12 + 1; ++i) { if (pData->renderer) + { pData->renderer[i]->matrix(nullptr); + } } } else @@ -316,9 +339,11 @@ void CorrelationPanel::assignMatrices(Data::Correlation* corr) for (uint i = 0; i < 12; ++i) { if (pData->renderer[i]) + { pData->renderer[i]->matrix(&(corr->monthly[i])); + } } - pData->renderer[12]->matrix(corr->annual); + pData->renderer[12]->matrix(&corr->annual); } } }