-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TEST] Refactoring study's loader #893
Changes from all commits
c166bb2
39d818c
ac9cb47
0897afd
28bfd0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
/* | ||
** Copyright 2007-2018 RTE | ||
** Authors: Antares_Simulator Team | ||
** | ||
** This file is part of Antares_Simulator. | ||
** | ||
** Antares_Simulator is free software: you can redistribute it and/or modify | ||
** it under the terms of the GNU General Public License as published by | ||
** the Free Software Foundation, either version 3 of the License, or | ||
** (at your option) any later version. | ||
** | ||
** There are special exceptions to the terms and conditions of the | ||
** license as they are applied to this software. View the full text of | ||
** the exceptions in file COPYING.txt in the directory of this software | ||
** distribution | ||
** | ||
** 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 | ||
** GNU General Public License for more details. | ||
** | ||
** You should have received a copy of the GNU General Public License | ||
** along with Antares_Simulator. If not, see <http://www.gnu.org/licenses/>. | ||
** | ||
** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions | ||
*/ | ||
|
||
#include "study.h" | ||
|
||
using namespace Yuni; | ||
|
||
|
||
namespace Antares | ||
{ | ||
namespace Data | ||
{ | ||
|
||
bool Study::initializeInternalData(const StudyLoadOptions& options) | ||
{ | ||
|
||
if (usedByTheSolver and not options.prepareOutput) | ||
{ | ||
parameters.noOutput = true; | ||
parameters.yearByYear = false; | ||
parameters.timeSeriesToArchive = 0; | ||
parameters.storeTimeseriesNumbers = false; | ||
parameters.synthesis = false; | ||
} | ||
|
||
if (options.loadOnlyNeeded and !parameters.timeSeriesToGenerate) | ||
// Nothing to refresh | ||
parameters.timeSeriesToRefresh = 0; | ||
|
||
|
||
// We can not run the simulation if the study folder is not in the latest | ||
// version and that we would like to re-importe the generated timeseries | ||
if (usedByTheSolver) | ||
{ | ||
// We have time-series to import | ||
if (parameters.timeSeriesToImport and (uint) header.version != (uint)versionLatest) | ||
{ | ||
logs.error() << "Stochastic TS stored in input : study must be upgraded to " | ||
<< Data::VersionToCStr((Data::Version)Data::versionLatest); | ||
gotFatalError = true; | ||
// it is useless to continue at this point | ||
return false; | ||
} | ||
} | ||
|
||
// calendar update | ||
if (usedByTheSolver) | ||
calendar.reset(parameters, /*force leapyear:*/ false); | ||
else | ||
calendar.reset(parameters); | ||
|
||
calendarOutput.reset(parameters); | ||
|
||
// In case hydro hot start is enabled, check all conditions are met. | ||
// (has to be called after areas load and calendar building) | ||
if (usedByTheSolver && !checkHydroHotStart()) | ||
return false; | ||
|
||
// Reducing memory footprint | ||
reduceMemoryUsage(); | ||
return true; | ||
|
||
} | ||
|
||
class SetHandlerAreas | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Each method of class SetHandlerAreas is given a |
||
{ | ||
public: | ||
SetHandlerAreas(AreaList& _areas) : areas(_areas) | ||
{ | ||
} | ||
|
||
void clear(Study::SingleSetOfAreas& set) | ||
{ | ||
set.clear(); | ||
} | ||
|
||
uint size(Study::SingleSetOfAreas& set) const | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
return (uint)set.size(); | ||
} | ||
|
||
bool add(Study::SingleSetOfAreas& set, const String& value) | ||
{ | ||
Area* area = AreaListLFind(&areas, value.c_str()); | ||
if (area) | ||
{ | ||
set.insert(area); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
bool add(Study::SingleSetOfAreas& set, const Study::SingleSetOfAreas& otherSet) | ||
{ | ||
if (!otherSet.empty()) | ||
{ | ||
auto end = otherSet.end(); | ||
for (auto i = otherSet.begin(); i != end; ++i) | ||
set.insert(*i); | ||
} | ||
return true; | ||
} | ||
|
||
bool remove(Study::SingleSetOfAreas& set, const String& value) | ||
{ | ||
Area* area = AreaListLFind(&areas, value.c_str()); | ||
if (area) | ||
{ | ||
set.erase(area); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
bool remove(Study::SingleSetOfAreas& set, const Study::SingleSetOfAreas& otherSet) | ||
{ | ||
if (!otherSet.empty()) | ||
{ | ||
auto end = otherSet.end(); | ||
for (auto i = otherSet.begin(); i != end; ++i) | ||
{ | ||
set.erase(*i); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
bool applyFilter(Study::SingleSetOfAreas& set, const String& value) | ||
{ | ||
if (value == "add-all") | ||
{ | ||
auto end = areas.end(); | ||
for (auto i = areas.begin(); i != end; ++i) | ||
set.insert(i->second); | ||
return true; | ||
} | ||
|
||
if (value == "remove-all") | ||
{ | ||
set.clear(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
private: | ||
AreaList& areas; | ||
|
||
}; // class SetHandlerAreas | ||
|
||
void Study::initializeSetsData() | ||
{ | ||
// Apply the rules | ||
SetHandlerAreas handler(this->areas); | ||
setsOfAreas.rebuildAllFromRules(handler); | ||
// Write the results into the logs | ||
setsOfAreas.dumpToLogs(logs); | ||
} | ||
|
||
} // namespace Data | ||
} // namespace Antares |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently, method initializeInternalData does 3 (at least) things :
Each bullet should be separated from the others in a function / method
This split would have few consequences test-study-load-internal.cpp.