Skip to content

Commit

Permalink
Add loadParameters.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
payetvin committed Dec 24, 2024
1 parent 557edaf commit 5bda772
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/solver/modeler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ set_target_properties(antares-modeler PROPERTIES OUTPUT_NAME ${exec_name})
target_link_libraries(modeler-lib
INTERFACE
Antares::loadModelerFiles
modeler-parameters
Antares::modelerParameters
)

target_link_libraries(antares-modeler
Expand Down
1 change: 1 addition & 0 deletions src/solver/modeler/loadFiles/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ target_link_libraries(loadModelerFiles
Antares::systemParser
Antares::modelParser
Antares::modelConverter
Antares::modelerParameters
)

install(DIRECTORY include/antares
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@
#include <filesystem>
#include <vector>

#include <antares/solver/modeler/parameters/modelerParameters.h>
#include <antares/study/system-model/library.h>
#include <antares/study/system-model/system.h>

namespace Antares::Solver::LoadFiles
{

Study::SystemModel::System loadSystem(const std::filesystem::path& studyPath,
const std::vector<Study::SystemModel::Library>& libraries);
ModelerParameters loadParameters(const std::filesystem::path& studyPath);

std::vector<Study::SystemModel::Library> loadLibraries(const std::filesystem::path& studyPath);

Study::SystemModel::System loadSystem(const std::filesystem::path& studyPath,
const std::vector<Study::SystemModel::Library>& libraries);

} // namespace Antares::Solver::LoadFiles
61 changes: 61 additions & 0 deletions src/solver/modeler/loadFiles/readParameters.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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 <https://opensource.org/license/mpl-2-0/>.
*/

#include <yaml-cpp/yaml.h>

#include <antares/io/file.h>
#include <antares/logs/logs.h>
#include "antares/solver/modeler/parameters/parseModelerParameters.h"
#include "antares/solver/modeler/loadFiles/loadFiles.h"

namespace fs = std::filesystem;

namespace Antares::Solver::LoadFiles
{

ModelerParameters loadParameters(const fs::path& studyPath)
{
try
{
const std::string paramStr = IO::readFile(studyPath / "parameters.yml");
return parseModelerParameters(paramStr);
}
catch (const YAML::Exception& e)
{
logs.error() << "Error while parsing the yaml parameters file";
if (!e.mark.is_null())
{
logs.error() << "Line " << e.mark.line << " column " << e.mark.column;
}
logs.error() << e.what();

throw std::runtime_error(e.what());
}
catch (const std::runtime_error& e)
{
logs.error() << "Error while parsing the yaml parameters file:";
logs.error() << e.what();

throw std::runtime_error(e.what());
}
}

} // namespace Antares::Solver::LoadFiles
18 changes: 10 additions & 8 deletions src/solver/modeler/parameters/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
add_library(modeler-parameters
include/antares/solver/modeler/parameters/modelerParameters.h
include/antares/solver/modeler/parameters/parseModelerParameters.h
parseModelerParameters.cpp
encoder.hxx)
add_library(modelerParameters
include/antares/solver/modeler/parameters/modelerParameters.h
include/antares/solver/modeler/parameters/parseModelerParameters.h
parseModelerParameters.cpp
encoder.hxx)

target_link_libraries(modeler-parameters
add_library(Antares::modelerParameters ALIAS modelerParameters)

target_link_libraries(modelerParameters
PRIVATE
yaml-cpp
Antares::io)
Antares::io)

target_include_directories(modeler-parameters
target_include_directories(modelerParameters
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
7 changes: 4 additions & 3 deletions src/solver/modeler/parameters/parseModelerParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/

#include <filesystem>
#include <fstream>

#include <antares/io/file.h>
#include <antares/solver/modeler/parameters/parseModelerParameters.h>
Expand All @@ -29,10 +28,12 @@

namespace Antares::Solver::LoadFiles
{
ModelerParameters parseModelerParameters(const std::filesystem::path& studyPath)

ModelerParameters parseModelerParameters(const std::filesystem::path& filePath)
{
const auto contents = Antares::IO::readFile(studyPath / "parameters.yml");
const auto contents = Antares::IO::readFile(filePath);
YAML::Node root = YAML::Load(contents);
return root.as<ModelerParameters>();
}

} // namespace Antares::Solver::LoadFiles
1 change: 1 addition & 0 deletions src/tests/src/solver/modeler/loadFiles/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ target_link_libraries(load-modeler-files
PRIVATE
Boost::unit_test_framework
Antares::loadModelerFiles
Antares::modelerParameters
test_utils_unit
)

Expand Down
2 changes: 1 addition & 1 deletion src/tests/src/solver/modeler/parameters/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ include(${CMAKE_SOURCE_DIR}/tests/macros.cmake)
add_boost_test(parse-parameters
SRC testParametersParsing.cpp
LIBS
modeler-parameters
Antares::modelerParameters
test_utils_unit)

0 comments on commit 5bda772

Please sign in to comment.