diff --git a/CMakeLists.txt b/CMakeLists.txt index 859f166..d39e25c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,197 +1,205 @@ #################################################### # # # SpecMiCP : CMakeLists.txt # # # #################################################### project(specmicp) cmake_minimum_required(VERSION 2.8.8) # Configuration options # ====================== # For an explanation of the options see the INSTALL file option( SPECMICP_USE_OPENMP "Thread parallelisation of specmicp instances if available" ON ) option( SPECMICP_NO_DEBUG "Disable SpecMiCP assert" OFF ) option( SPECMICP_BUILD_STATIC "Build static libraries" OFF ) option( SPECMICP_BUILD_EXAMPLE "Build the examples" ON ) option( SPECMICP_DEBUG_EQUATION_FD_JACOBIAN "Use a finite difference jacobian is specmicp" OFF ) # PGO sequence option( SPECMICP_PROFILE_GENERATE "Generate the profile for PGO optimization" OFF ) option( SPECMICP_PROFILE_USE "Use the generated profile for PGO optimization" OFF ) # LTO optimization option( SPECMICP_LTO "Use link time optimization" OFF ) option( SPECMICP_LD_GOLD "Use GNU gold linker" ON ) # global variables # ================ set(SPECMICP_VERSION 0.0.3) # External Package # ================ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake) # OpenMP #------- # not required but recommended if(SPECMICP_USE_OPENMP) find_package(OpenMP) endif() # Boost # ----- find_package(Boost REQUIRED) include_directories(${Boost_INCLUDE_DIR}) # Eigen # ----- find_package(Eigen3 REQUIRED) # This module comes from the Eigen3 Package include_directories(${EIGEN3_INCLUDE_DIR}) # Eigen unsuported # GMRES.h is really the file we are using/looking for # If it doesn't exist then the solver will not be included in the list of the parse solvers if(EXISTS "${EIGEN3_INCLUDE_DIR}/unsupported/Eigen/src/IterativeSolvers/GMRES.h") add_definitions(-DEIGEN_UNSUPPORTED_FOUND) include_directories("${EIGEN3_INCLUDE_DIR}/unsupported/") endif() +# Yaml-cpp +# -------- + +include(FindPkgConfig) +pkg_check_modules(YAML REQUIRED yaml-cpp>=0.5) +include_directories(${YAML_INCLUDE_DIRS}) + + # sanitizer include(SanitizerBuild) # compilation flags # ================= # check the availability of : # c++11 include(cxx11) # -fuse-ld=gold include(gold_linker) # pgo optimization include(pg_optimization) # -fvisibility-hidden include(visibility_flag) # just a friendly warning if(NOT UNIX) message(WARNING "not tested !") endif() include(lto) # set the flag SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX11_FLAG}") if (OPENMP_FOUND) SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") endif() SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -pedantic") ##SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG") message(STATUS "c++ flags : ${CMAKE_CXX_FLAGS}") # Directories ######################################################################### # 3rd party # ========= # JsonCPP # ------- set(JSONCPP_DIR ${PROJECT_SOURCE_DIR}/3rdparty/jsoncpp/) add_custom_target(3rdparty_header SOURCES ${JSONCPP_DIR}/json/json.h ${JSONCPP_DIR}/json/json-forwards.h ) include_directories(${JSONCPP_DIR}) # installation dir # ---------------- # http://www.cmake.org/pipermail/cmake/2010-February/035466.html # compute default library install dir # library # ------ set (_DEFAULT_LIBRARY_INSTALL_DIR lib) if (EXISTS "${CMAKE_INSTALL_PREFIX}/lib32/" AND CMAKE_SIZEOF_VOID_P EQUAL 4) set (_DEFAULT_LIBRARY_INSTALL_DIR lib32) elif (EXISTS "${CMAKE_INSTALL_PREFIX}/lib64/" AND CMAKE_SIZEOF_VOID_P EQUAL 8) set (_DEFAULT_LIBRARY_INSTALL_DIR lib64) endif () # the library install dir set(LIBRARY_INSTALL_DIR "${_DEFAULT_LIBRARY_INSTALL_DIR}" CACHE PATH "Installation directory for libraries") set(STATIC_LIBRARY_INSTALL_DIR "${_DEFAULT_LIBRARY_INSTALL_DIR}/static" CACHE PATH "Installation directory for static libraries") # make the library install dir an absolute path (can be important e.g. when using CONFIGURE_FILE to embed # the library installation directory into a file) if(NOT IS_ABSOLUTE "${LIBRARY_INSTALL_DIR}") set(LIBRARY_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${LIBRARY_INSTALL_DIR}") endif() if(NOT IS_ABSOLUTE "${STATIC_LIBRARY_INSTALL_DIR}") set(STATIC_LIBRARY_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${STATIC_LIBRARY_INSTALL_DIR}") endif() # include #-------- set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include/specmicp" CACHE PATH "Installation directories for the headers") # share #------ set(SHARE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/specmicp" CACHE PATH "Installation directories for the miscalleneous files...") enable_testing(true) # CPP API : SpecMiCP / ReactMiCP ######################################################################### # the main source directory - the c++ api set(SPECMICP_CPP_API ${CMAKE_CURRENT_SOURCE_DIR}/src) include_directories(${SPECMICP_CPP_API}) add_subdirectory( ${SPECMICP_CPP_API} ) -set(SPECMICP_LIBS specmicp specmicp_database specmicp_common) -set(REACTMICP_LIBS reactmicp dfpm ${SPECMICP_LIBS}) -set(SPECMICP_STATIC_LIBS specmicp_static specmicp_database_static specmicp_common_static) +set(SPECMICP_LIBS specmicp specmicp_database specmicp_common ${YAML_LIBRARIES}) +set(REACTMICP_LIBS reactmicp dfpm ${SPECMICP_LIBS} ) +set(SPECMICP_STATIC_LIBS specmicp_static specmicp_database_static specmicp_common_static ${YAML_LIBRARIES}) set(REACTMICP_STATIC_LIBS reactmicp_static dfpm_static ${SPECMICP_STATIC_LIBS}) # Database ######################################################################### add_subdirectory( data ) # Documentation ######################################################################### # "common" documentation # ----------------------- set( DOCS_LIST ${CMAKE_CURRENT_SOURCE_DIR}/README.md ${CMAKE_CURRENT_SOURCE_DIR}/INSTALL ${CMAKE_CURRENT_SOURCE_DIR}/COPYING ) add_custom_target(docs SOURCES ${DOCS_LIST}) install(FILES ${DOCS_LIST} DESTINATION ${SHARE_INSTALL_DIR} ) # scripts # -------- add_subdirectory( scripts ) # Doxygen documentation # --------------------- add_subdirectory( doc ) # Tests ######################################################################### add_subdirectory( tests ) # Examples ######################################################################### add_subdirectory( examples ) diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt index f4f9d07..984ecb0 100644 --- a/src/utils/CMakeLists.txt +++ b/src/utils/CMakeLists.txt @@ -1,93 +1,94 @@ add_custom_target(utils_inc SOURCES log.hpp # sparse solvers # -------------- sparse_solvers/sparse_solver_base.hpp sparse_solvers/sparse_solver.hpp sparse_solvers/sparse_solver_structs.hpp sparse_solvers/sparse_qr.hpp sparse_solvers/sparse_lu.hpp sparse_solvers/sparse_bicgstab.hpp sparse_solvers/sparse_gmres.hpp options_handler.hpp perfs_handler.hpp ) set(SPECMICP_COMMON_LIBRARY_FILES dateandtime.cpp timer.cpp moving_average.cpp json.cpp ../physics/laws.cpp ../physics/units.cpp ../physics/io/units.cpp io/csv_formatter.cpp + io/yaml.cpp ${JSONCPP_DIR}/jsoncpp.cpp ) set_pgo_flag(${SPECMICP_COMMON_LIBRARY_FILES}) add_library(objspecmicp_common OBJECT ${SPECMICP_COMMON_LIBRARY_FILES}) set_property(TARGET objspecmicp_common PROPERTY POSITION_INDEPENDENT_CODE 1) add_library(specmicp_common SHARED $) install(TARGETS specmicp_common LIBRARY DESTINATION ${LIBRARY_INSTALL_DIR} ) set(UTILS_INCLUDE_LIST log.hpp options_handler.hpp perfs_handler.hpp moving_average.hpp timer.hpp dateandtime.hpp json.hpp ) set(UTILS_SPARSE_INCLUDE_LIST # sparse solvers # -------------- sparse_solvers/sparse_solver.hpp sparse_solvers/sparse_solver_base.hpp sparse_solvers/sparse_solver_structs.hpp sparse_solvers/sparse_qr.hpp sparse_solvers/sparse_lu.hpp sparse_solvers/sparse_bicgstab.hpp sparse_solvers/sparse_gmres.hpp ) install(FILES ${UTILS_INCLUDE_LIST} DESTINATION ${INCLUDE_INSTALL_DIR}/utils ) install(FILES ${UTILS_SPARSE_INCLUDE_LIST} DESTINATION ${INCLUDE_INSTALL_DIR}/utils/sparse_solvers ) -install(FILES io/csv_formatter.hpp +install(FILES io/csv_formatter.hpp io/yaml.hpp DESTINATION ${INCLUDE_INSTALL_DIR}/utils/io ) # static libraries # ---------------- if(SPECMICP_BUILD_STATIC) add_library(specmicp_common_static STATIC $) install(TARGETS specmicp_common_static ARCHIVE DESTINATION ${STATIC_LIBRARY_INSTALL_DIR} ) else() add_library(specmicp_common_static EXCLUDE_FROM_ALL STATIC $) endif() set_target_properties(specmicp_common_static PROPERTIES OUTPUT_NAME specmicp_common) diff --git a/src/utils/io/yaml.cpp b/src/utils/io/yaml.cpp new file mode 100644 index 0000000..a98cd86 --- /dev/null +++ b/src/utils/io/yaml.cpp @@ -0,0 +1,59 @@ +/*------------------------------------------------------------------------------- + +Copyright (c) 2015 F. Georget , Princeton University +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors +may be used to endorse or promote products derived from this software without +specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +-----------------------------------------------------------------------------*/ + +#include "yaml.hpp" +#include + +namespace specmicp { +namespace io { + +YAML::Node parse_config_file(const std::string &filename) +{ + return YAML::LoadFile(filename); +} + + +YAML::Node parse_string(const std::string& config_string) +{ + return YAML::Load(config_string); +} + + +void check_mandatory_yaml_node(const YAML::Node& node, const std::string& child, const std::string& section) +{ + if (not node[child]) + throw std::invalid_argument("Node '"+child+"' is required in section '"+section+"'."); +} + + +} //end namespace io +} //end namespace spe diff --git a/src/utils/io/yaml.hpp b/src/utils/io/yaml.hpp new file mode 100644 index 0000000..8555252 --- /dev/null +++ b/src/utils/io/yaml.hpp @@ -0,0 +1,72 @@ +/*------------------------------------------------------------------------------- + +Copyright (c) 2015 F. Georget , Princeton University +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors +may be used to endorse or promote products derived from this software without +specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +-----------------------------------------------------------------------------*/ + +#ifndef SPECMICP_IO_YAML_HPP +#define SPECMICP_IO_YAML_HPP + +#include "macros.hpp" +#include +#include + +#include + + +namespace specmicp { +namespace io { + +YAML::Node parse_config_file(const std::string& filename); +YAML::Node parse_string(const std::string& config_string); + + +template +T get_yaml_optional(const YAML::Node& node, const std::string& attribute, T value) +{ + if (node[attribute]) + return node[attribute].as(); + else + return value; +} + +template +T get_yaml_mandatory(const YAML::Node& node, const std::string& attribute, const std::string& section) +{ + if (not node[attribute]) + throw std::invalid_argument("Attribute '"+attribute+"' is required in section '"+section+"'."); + return node[attribute].as(); +} + +void check_mandatory_yaml_node(const YAML::Node& node, const std::string& child, const std::string& section); + +} //end namespace io +} //end namespace specmicp + +#endif // SPECMICP_IO_YAML_HPP