Skip to content

Commit

Permalink
[TEST] Refactoring study's loader
Browse files Browse the repository at this point in the history
  • Loading branch information
kathvargasr committed Oct 10, 2022
1 parent a8b063e commit f2e79db
Show file tree
Hide file tree
Showing 6 changed files with 327 additions and 214 deletions.
1 change: 1 addition & 0 deletions src/libs/antares/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ set(SRC
study/memory-usage.cpp
study/importlogs.cpp
study/load.cpp
study/load-data.cpp
study/save.cpp
study/study.extra.cpp
study/version.h
Expand Down
2 changes: 1 addition & 1 deletion src/libs/antares/study/area/area.h
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ class AreaList final : public Yuni::NonCopyable<AreaList>

private:
//! The parent study
Study& pStudy;
Study& pStudy; //KVR: why is this needed? -> see notes in joplin @06/10

}; // class AreaList

Expand Down
211 changes: 211 additions & 0 deletions src/libs/antares/study/load-data.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
/*
** 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;
}
}

// -------------------------
// Logical cores
// -------------------------
// Getting the number of logical cores to use before loading and creating the areas :
// Areas need this number to be up-to-date at construction.
getNumberOfCores(options.forceParallel, options.maxNbYearsInParallel);


#ifdef ANTARES_SWAP_SUPPORT //KVR ToDo: remove swap
// In case of swap support, MC years parallel computing is forbidden.
// Numbers of parallel years is set to 1.
maxNbYearsInParallel = 1;
#endif

//KVR this could be in setRawNbParallelYear but there's a dependency on options
// (why? maxNbYearsInParallel is a class member tho)
// In case the study is run in the draft mode, only 1 core is allowed
if (parameters.mode == Data::stdmAdequacyDraft)
maxNbYearsInParallel = 1;

// In case parallel mode was not chosen, only 1 core is allowed
if (!options.enableParallel && !options.forceParallel)
maxNbYearsInParallel = 1;

// End logical core --------

// 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
{
public:
SetHandlerAreas(Study& study) : pStudy(study)
{
}

void clear(Study::SingleSetOfAreas& set)
{
set.clear();
}

uint size(Study::SingleSetOfAreas& set)
{
return (uint)set.size();
}

bool add(Study::SingleSetOfAreas& set, const String& value)
{
Area* area = AreaListLFind(&pStudy.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(&pStudy.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 = pStudy.areas.end();
for (auto i = pStudy.areas.begin(); i != end; ++i)
set.insert(i->second);
return true;
}

if (value == "remove-all")
{
set.clear();
return true;
}
return false;
}

private:
Study& pStudy;

}; // class SetHandlerAreas

void Study::initializeSetsData()
{
// Apply the rules
SetHandlerAreas handler(*this);
setsOfAreas.rebuildAllFromRules(handler);
// Write the results into the logs
setsOfAreas.dumpToLogs(logs);
}

} // namespace Data
} // namespace Antares
Loading

0 comments on commit f2e79db

Please sign in to comment.