From 16307e6042ce6773fdc55a0f82cdafe11b3f07d9 Mon Sep 17 00:00:00 2001 From: "Peles, Slaven" Date: Tue, 6 Apr 2021 01:31:08 +0000 Subject: [PATCH] Refactor CMake configuration --- {config => CMake}/Config.cmake.in | 0 {config => CMake}/FindIpopt.cmake | 0 {config => CMake}/FindSuiteSparse.cmake | 0 {config => CMake}/GridkitAddLibrary.cmake | 7 ++ CMakeLists.txt | 44 +++---- Examples/AdjointSensitivity/CMakeLists.txt | 3 + Examples/CMakeLists.txt | 19 +-- Examples/DynamicConstrainedOpt/CMakeLists.txt | 1 + Examples/GenConstLoad/CMakeLists.txt | 2 + Examples/GenInfiniteBus/CMakeLists.txt | 1 + Examples/Grid3Bus/CMakeLists.txt | 2 + Examples/Grid3Bus/Grid3Bus.cpp | 119 ------------------ Examples/ParameterEstimation/CMakeLists.txt | 2 + Solver/CMakeLists.txt | 14 ++- Solver/Dynamic/CMakeLists.txt | 2 - Solver/Optimization/CMakeLists.txt | 2 - 16 files changed, 59 insertions(+), 159 deletions(-) rename {config => CMake}/Config.cmake.in (100%) rename {config => CMake}/FindIpopt.cmake (100%) rename {config => CMake}/FindSuiteSparse.cmake (100%) rename {config => CMake}/GridkitAddLibrary.cmake (93%) delete mode 100644 Examples/Grid3Bus/Grid3Bus.cpp diff --git a/config/Config.cmake.in b/CMake/Config.cmake.in similarity index 100% rename from config/Config.cmake.in rename to CMake/Config.cmake.in diff --git a/config/FindIpopt.cmake b/CMake/FindIpopt.cmake similarity index 100% rename from config/FindIpopt.cmake rename to CMake/FindIpopt.cmake diff --git a/config/FindSuiteSparse.cmake b/CMake/FindSuiteSparse.cmake similarity index 100% rename from config/FindSuiteSparse.cmake rename to CMake/FindSuiteSparse.cmake diff --git a/config/GridkitAddLibrary.cmake b/CMake/GridkitAddLibrary.cmake similarity index 93% rename from config/GridkitAddLibrary.cmake rename to CMake/GridkitAddLibrary.cmake index e0feb5b..451dab3 100644 --- a/config/GridkitAddLibrary.cmake +++ b/CMake/GridkitAddLibrary.cmake @@ -67,6 +67,7 @@ macro(gridkit_add_library target) add_library(GRIDKIT::${target} ALIAS ${_actual_target_name}) + # Set output name if(gridkit_add_library_OUTPUT_NAME) set_target_properties(${_actual_target_name} PROPERTIES OUTPUT_NAME ${gridkit_add_library_OUTPUT_NAME} @@ -76,6 +77,12 @@ macro(gridkit_add_library target) OUTPUT_NAME ${target} CLEAN_DIRECT_OUTPUT 1) endif() + + # Set the library version + set_target_properties(${_actual_target_name} PROPERTIES + VERSION ${PACKAGE_VERSION} + SOVERSION ${PACKAGE_VERSION_MAJOR}) + install(TARGETS ${_actual_target_name} DESTINATION lib EXPORT gridkit-targets) endforeach() endmacro() diff --git a/CMakeLists.txt b/CMakeLists.txt index 82732f2..cb926e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,10 +68,11 @@ set(PACKAGE_NAME "GRIDKIT") set(PACKAGE_STRING "GRIDKIT 0.0.6") set(PACKAGE_TARNAME "gridkit") -set(PACKAGE_VERSION_MAJOR "1") +set(PACKAGE_VERSION_MAJOR "0") set(PACKAGE_VERSION_MINOR "0") +set(PACKAGE_VERSION_PATCH "6") -set(PACKAGE_VERSION "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}") +set(PACKAGE_VERSION "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}.${PACKAGE_VERSION_PATCH}") # Ipopt support is disabled by default option(GRIDKIT_ENABLE_IPOPT "Enable Ipopt support" ON) @@ -84,7 +85,7 @@ option(GRIDKIT_ENABLE_SUNDIALS_SPARSE "Enable SUNDIALS sparse linear solvers" ON set(CMAKE_MACOSX_RPATH 1) -list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/config) +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMake) # https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling#always-full-rpath # use, i.e. don't skip the full RPATH for the build tree @@ -129,25 +130,29 @@ endif() if(GRIDKIT_ENABLE_SUNDIALS_SPARSE) include(FindSuiteSparse) endif() -# Set up configuration header file -# configure_file(gridkit_config.h.in gridkit_config.h) # Macro that adds libraries include(GridkitAddLibrary) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + +# Create component models add_subdirectory(ComponentLib) -add_subdirectory(Solver) -add_subdirectory(Examples) -set(CMAKE_POSITION_INDEPENDENT_CODE ON) +# Create solvers +add_subdirectory(Solver) -export(EXPORT gridkit-targets FILE "${CMAKE_CURRENT_BINARY_DIR}/GridKitTargets.cmake") +# Create examples and tests +enable_testing() +add_subdirectory(Examples) + +export(EXPORT gridkit-targets FILE ${CMAKE_CURRENT_BINARY_DIR}/GridKitTargets.cmake) # Configuring exporting cmake config install(EXPORT gridkit-targets FILE GridKitTargets.cmake NAMESPACE GRIDKIT:: - DESTINATION lib/cmake/gridkit) + DESTINATION share/cmake/gridkit) include(CMakePackageConfigHelpers) @@ -158,9 +163,9 @@ write_basic_package_version_file( COMPATIBILITY SameMajorVersion) # Generate config file that includes exports -configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/config/Config.cmake.in - "${CMAKE_CURRENT_BINARY_DIR}/GridKitConfig.cmake" - INSTALL_DESTINATION "lib/cmake/gridkit" +configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/CMake/Config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/GridKitConfig.cmake + INSTALL_DESTINATION share/cmake/gridkit NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO) @@ -168,15 +173,4 @@ configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/config/Config.cmake.in install(FILES ${CMAKE_CURRENT_BINARY_DIR}/GridKitConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/GridKitConfigVersion.cmake - DESTINATION lib/cmake/gridkit) - -# TESTING -enable_testing() -add_test(NAME AdjointSens COMMAND $ ) -add_test(NAME Grid3Bus COMMAND $) -if(GRIDKIT_ENABLE_IPOPT) - add_test(NAME DynamicConOpt COMMAND $ ) - add_test(NAME GenConstLoad COMMAND $) - add_test(NAME GenInfiniteBus COMMAND $ ) - add_test(NAME ParameterEst COMMAND $ ${CMAKE_SOURCE_DIR}/Examples/ParameterEstimation/lookup_table.dat) -endif() + DESTINATION share/cmake/gridkit) diff --git a/Examples/AdjointSensitivity/CMakeLists.txt b/Examples/AdjointSensitivity/CMakeLists.txt index 7663c1c..1812188 100644 --- a/Examples/AdjointSensitivity/CMakeLists.txt +++ b/Examples/AdjointSensitivity/CMakeLists.txt @@ -64,3 +64,6 @@ add_executable(adjoint AdjointSensitivity.cpp) target_link_libraries(adjoint GRIDKIT::bus GRIDKIT::generator4 GRIDKIT::solvers_dyn) install(TARGETS adjoint DESTINATION bin) +add_test(NAME AdjointSens COMMAND $ ) + + diff --git a/Examples/CMakeLists.txt b/Examples/CMakeLists.txt index 4487fb8..55f9530 100644 --- a/Examples/CMakeLists.txt +++ b/Examples/CMakeLists.txt @@ -55,11 +55,16 @@ # endorsement purposes. # -add_subdirectory(AdjointSensitivity) -add_subdirectory(Grid3Bus) -if(GRIDKIT_ENABLE_IPOPT) - add_subdirectory(DynamicConstrainedOpt) - add_subdirectory(GenConstLoad) - add_subdirectory(GenInfiniteBus) - add_subdirectory(ParameterEstimation) +if(TARGET SUNDIALS::kinsol) + add_subdirectory(Grid3Bus) +endif() + +if(TARGET SUNDIALS::idas) + add_subdirectory(AdjointSensitivity) + if(GRIDKIT_ENABLE_IPOPT) + add_subdirectory(DynamicConstrainedOpt) + add_subdirectory(GenConstLoad) + add_subdirectory(GenInfiniteBus) + add_subdirectory(ParameterEstimation) + endif() endif() diff --git a/Examples/DynamicConstrainedOpt/CMakeLists.txt b/Examples/DynamicConstrainedOpt/CMakeLists.txt index 18b2894..a89ac09 100644 --- a/Examples/DynamicConstrainedOpt/CMakeLists.txt +++ b/Examples/DynamicConstrainedOpt/CMakeLists.txt @@ -64,3 +64,4 @@ add_executable(dynconopt DynamicConstrainedOpt.cpp) target_link_libraries(dynconopt GRIDKIT::generator4 GRIDKIT::generator2 GRIDKIT::bus GRIDKIT::solvers_dyn GRIDKIT::solvers_opt) install(TARGETS dynconopt DESTINATION bin) +add_test(NAME DynamicConOpt COMMAND $) diff --git a/Examples/GenConstLoad/CMakeLists.txt b/Examples/GenConstLoad/CMakeLists.txt index 6d4aa8f..8fb9adf 100644 --- a/Examples/GenConstLoad/CMakeLists.txt +++ b/Examples/GenConstLoad/CMakeLists.txt @@ -63,3 +63,5 @@ add_executable(genconstload GenConstLoad.cpp) target_link_libraries(genconstload GRIDKIT::generator4governor GRIDKIT::bus GRIDKIT::load GRIDKIT::solvers_dyn GRIDKIT::solvers_opt) install(TARGETS genconstload DESTINATION bin) + +add_test(NAME GenConstLoad COMMAND $) diff --git a/Examples/GenInfiniteBus/CMakeLists.txt b/Examples/GenInfiniteBus/CMakeLists.txt index d825810..c6e90c2 100644 --- a/Examples/GenInfiniteBus/CMakeLists.txt +++ b/Examples/GenInfiniteBus/CMakeLists.txt @@ -64,3 +64,4 @@ add_executable(geninfbus GenInfiniteBus.cpp) target_link_libraries(geninfbus GRIDKIT::bus GRIDKIT::generator4 GRIDKIT::solvers_opt GRIDKIT::solvers_dyn) install(TARGETS geninfbus DESTINATION bin) +add_test(NAME GenInfiniteBus COMMAND $) diff --git a/Examples/Grid3Bus/CMakeLists.txt b/Examples/Grid3Bus/CMakeLists.txt index 3b2d6ff..253371f 100644 --- a/Examples/Grid3Bus/CMakeLists.txt +++ b/Examples/Grid3Bus/CMakeLists.txt @@ -67,3 +67,5 @@ add_executable(grid3bus Grid3BusSys.cpp) target_link_libraries(grid3bus GRIDKIT::minigrid GRIDKIT::bus GRIDKIT::branch GRIDKIT::load GRIDKIT::solvers_steady) install(TARGETS grid3bus RUNTIME DESTINATION bin) + +add_test(NAME Grid3Bus COMMAND $) diff --git a/Examples/Grid3Bus/Grid3Bus.cpp b/Examples/Grid3Bus/Grid3Bus.cpp deleted file mode 100644 index aae37d2..0000000 --- a/Examples/Grid3Bus/Grid3Bus.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* - * - * Copyright (c) 2017, Lawrence Livermore National Security, LLC. - * Produced at the Lawrence Livermore National Laboratory. - * Written by Slaven Peles . - * LLNL-CODE-718378. - * All rights reserved. - * - * This file is part of GridKitâ„¢. For details, see github.com/LLNL/GridKit - * Please also read the LICENSE file. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the disclaimer below. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the disclaimer (as noted below) in the - * documentation and/or other materials provided with the distribution. - * - Neither the name of the LLNS/LLNL 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 LAWRENCE LIVERMORE NATIONAL - * SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY 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) ARISINGIN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - * - * Lawrence Livermore National Laboratory is operated by Lawrence Livermore - * National Security, LLC, for the U.S. Department of Energy, National - * Nuclear Security Administration under Contract DE-AC52-07NA27344. - * - * This document was prepared as an account of work sponsored by an agency - * of the United States government. Neither the United States government nor - * Lawrence Livermore National Security, LLC, nor any of their employees - * makes any warranty, expressed or implied, or assumes any legal liability - * or responsibility for the accuracy, completeness, or usefulness of any - * information, apparatus, product, or process disclosed, or represents that - * its use would not infringe privately owned rights. Reference herein to - * any specific commercial product, process, or service by trade name, - * trademark, manufacturer, or otherwise does not necessarily constitute or - * imply its endorsement, recommendation, or favoring by the United States - * government or Lawrence Livermore National Security, LLC. The views and - * opinions of authors expressed herein do not necessarily state or reflect - * those of the United States government or Lawrence Livermore National - * Security, LLC, and shall not be used for advertising or product - * endorsement purposes. - * - */ - - -#include -#include -#include - -#include -#include - -#include - - -int main() -{ - using namespace ModelLib; - using namespace AnalysisManager::Sundials; - using namespace AnalysisManager; - using namespace GridKit::Testing; - - // Create a system model - // (usually from netfile or GUI input, this one is hard-wired) - MiniGrid* model = new MiniGrid(); - - // allocate model - model->allocate(); - - // Create numerical solver and attach the model to it. - // Here we use Kinsol solver from SUNDIALS library - Kinsol* kinsol = new Kinsol(model); - - // setup simulation - kinsol->configureSimulation(); - // initialize simulation with default initial guess - kinsol->getDefaultInitialCondition(); - // kinsol->initializeSimulation(); - - // Compute solution - kinsol->runSimulation(); - - // Print solution - double const th2 = model->th2() * 180.0/M_PI; - double const V2 = model->V2(); - double const th3 = model->th3() * 180.0/M_PI; - std::cout << "Solution:\n"; - std::cout << " theta2 = " << th2 << " deg, expected = " << " -4.87979 deg\n"; - std::cout << " V2 = " << V2 << " p.u., expected = " << " 1.08281 p.u.\n"; - std::cout << " theta3 = " << th3 << " deg, expected = " << " 1.46241 deg\n\n"; - - // Print solver performance statistics - kinsol->printFinalStats(); - - int retval = 0; - retval += isEqual(th2, -4.878, 1e-4); - retval += isEqual(V2, 1.096, 1e-4); - retval += isEqual(th3, 1.491, 1e-4); - - // Delete solver and model - delete kinsol; - delete model; - return retval; -} diff --git a/Examples/ParameterEstimation/CMakeLists.txt b/Examples/ParameterEstimation/CMakeLists.txt index 44ae520..5f17c27 100644 --- a/Examples/ParameterEstimation/CMakeLists.txt +++ b/Examples/ParameterEstimation/CMakeLists.txt @@ -64,3 +64,5 @@ add_executable(paramest ParameterEstimation.cpp) target_link_libraries(paramest GRIDKIT::bus GRIDKIT::generator4param GRIDKIT::solvers_opt GRIDKIT::solvers_dyn) install(TARGETS paramest RUNTIME DESTINATION bin) install(FILES lookup_table.dat DESTINATION bin) + +add_test(NAME ParameterEst COMMAND $ ${CMAKE_SOURCE_DIR}/Examples/ParameterEstimation/lookup_table.dat) diff --git a/Solver/CMakeLists.txt b/Solver/CMakeLists.txt index eb602ce..8be94fd 100644 --- a/Solver/CMakeLists.txt +++ b/Solver/CMakeLists.txt @@ -58,10 +58,16 @@ # [[ # Author(s): # - Cameron Rutherford +# - Slaven Peles #]] -add_subdirectory(Dynamic) -add_subdirectory(SteadyState) -if(GRIDKIT_ENABLE_IPOPT) - add_subdirectory(Optimization) +if(TARGET SUNDIALS::kinsol) + add_subdirectory(SteadyState) +endif() + +if(TARGET SUNDIALS::idas) + add_subdirectory(Dynamic) + if(GRIDKIT_ENABLE_IPOPT) + add_subdirectory(Optimization) + endif() endif() diff --git a/Solver/Dynamic/CMakeLists.txt b/Solver/Dynamic/CMakeLists.txt index 9e45c2e..7598299 100644 --- a/Solver/Dynamic/CMakeLists.txt +++ b/Solver/Dynamic/CMakeLists.txt @@ -66,8 +66,6 @@ gridkit_add_library(solvers_dyn LINK_LIBRARIES PUBLIC SUNDIALS::nvecserial PUBLIC SUNDIALS::idas - PUBLIC SUNDIALS::kinsol - PUBLIC IPOPT OUTPUT_NAME gridkit_solvers_dyn) diff --git a/Solver/Optimization/CMakeLists.txt b/Solver/Optimization/CMakeLists.txt index 7be4514..756dfa5 100644 --- a/Solver/Optimization/CMakeLists.txt +++ b/Solver/Optimization/CMakeLists.txt @@ -65,8 +65,6 @@ gridkit_add_library(solvers_opt DynamicObjective.cpp DynamicConstraint.cpp LINK_LIBRARIES - PUBLIC SUNDIALS::nvecserial - PUBLIC SUNDIALS::idas PUBLIC IPOPT PUBLIC GRIDKIT::solvers_dyn OUTPUT_NAME