Skip to content

Commit

Permalink
Link TS generation : splitting into multiple files (#2171)
Browse files Browse the repository at this point in the history
This PR aims at moving some code about link TS generation, from **main**
program to new source files.
It follows PR #2155 

To be done : 

- [x] move headers (*.h) to the right place
- [x] update this branch with its base branch (@flomnes made a change on
base branch)

We may also take advantage of this PR to : 
- [ ] Thermal TS generation :
- [ ] avoid loading the **whole study** when **no** thermal TS
generation is required (this is currently the case)
- [ ] move implementation details about thermal TS generation from
**main** program to new source files
- [ ] Separate loading / extracting data from study and generate the TS

---------

Co-authored-by: Florian OMNES <[email protected]>
Co-authored-by: Florian OMNES <[email protected]>
  • Loading branch information
3 people authored Jul 10, 2024
1 parent 7f850a0 commit c80109f
Show file tree
Hide file tree
Showing 12 changed files with 634 additions and 588 deletions.
6 changes: 2 additions & 4 deletions src/libs/antares/utils/include/antares/utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ namespace Antares
*/
template<class StringT>
void TransformNameIntoID(const AnyString& name, StringT& out);

std::string transformNameIntoID(const std::string& name);

std::string FormattedTime(const std::string& format);

/*!
** \brief Beautify a name, for renaming an area for example
*/
Expand All @@ -51,11 +52,8 @@ std::vector<std::pair<std::string, std::string>> splitStringIntoPairs(const std:

namespace Utils
{

bool isZero(double d);

double round(double d, unsigned precision);

} // namespace Utils
} // namespace Antares

Expand Down
12 changes: 12 additions & 0 deletions src/libs/antares/utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ void BeautifyName(std::string& out, const std::string& oldname)
out = yuniOut.c_str();
}

std::string FormattedTime(const std::string& format)
{
using namespace std::chrono;
auto time = system_clock::to_time_t(system_clock::now());
std::tm local_time = *std::localtime(&time);

char time_buffer[256];
std::strftime(time_buffer, sizeof(time_buffer), format.c_str(), &local_time);

return std::string(time_buffer);
}

std::vector<std::pair<std::string, std::string>> splitStringIntoPairs(const std::string& s,
char delimiter1,
char delimiter2)
Expand Down
19 changes: 3 additions & 16 deletions src/solver/application/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,20 +435,6 @@ void Application::runSimulationInAdequacyMode()
observer);
}

static std::string timeToString()
{
using namespace std::chrono;
auto time = system_clock::to_time_t(system_clock::now());
std::tm local_time = *std::localtime(&time);

char time_buffer[256];
std::strftime(time_buffer, sizeof(time_buffer), "%Y%m%d-%H%M%S", &local_time);

std::string currentTime = time_buffer;

return currentTime;
}

void Application::resetLogFilename() const
{
fs::path logfile = fs::path(pSettings.studyFolder.c_str()) / "logs";
Expand All @@ -459,8 +445,9 @@ void Application::resetLogFilename() const
+ ". Aborting now.");
}

logfile /= "solver-"; // append the filename
logfile += timeToString() + ".log"; // complete filename with timestamp and extension
logfile /= "solver-"; // append the filename
logfile += FormattedTime("%Y%m%d-%H%M%S")
+ ".log"; // complete filename with timestamp and extension

// Assigning the log filename
logs.logfile(logfile.string());
Expand Down
19 changes: 14 additions & 5 deletions src/solver/simulation/include/antares/solver/simulation/solver.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -454,15 +454,24 @@ void ISimulation<ImplementationType>::regenerateTimeSeries(uint year)
if (refreshTSonCurrentYear)
{
auto clusters = getAllClustersToGen(study.areas, pData.haveToRefreshTSThermal);
#define SEP Yuni::IO::Separator
const std::string savePath = std::string("ts-generator") + SEP + "thermal" + SEP + "mc-"
+ std::to_string(year);
#undef SEP
generateThermalTimeSeries(study, clusters, pResultWriter, savePath);
generateThermalTimeSeries(study,
clusters,
study.runtime->random[Data::seedTsGenThermal]);

bool archive = study.parameters.timeSeriesToArchive & Data::timeSeriesThermal;
bool doWeWrite = archive && !study.parameters.noOutput;
if (doWeWrite)
{
fs::path savePath = fs::path(study.folderOutput.to<std::string>()) / "ts-generator"
/ "thermal" / "mc-" / std::to_string(year);
writeThermalTimeSeries(clusters, savePath);
}

// apply the spinning if we generated some in memory clusters
for (auto* cluster: clusters)
{
cluster->calculationOfSpinning();
}
}
};
}
Expand Down
Loading

0 comments on commit c80109f

Please sign in to comment.