From 84d9f68dbaee32fd9567ad72b6438ab9e80a2fb3 Mon Sep 17 00:00:00 2001 From: Adrien DELSALLE Date: Thu, 30 Jun 2022 20:48:12 +0200 Subject: [PATCH 1/2] package the library create libyams split the header-only library from the binary targets add a python package structure to install pyams make the CLI, C++ tests and python bindings rely on libyams update the conda recipe add cmake config files for downstream packages add README for build instructions add missing deps in env-dev yaml file use pre-installed libyams if lib is not built --- .gitignore | 51 +++++++- CMakeLists.txt | 112 +++------------- README | 116 +++++++++++++++++ environment-dev.yml | 3 + libyams/CMakeLists.txt | 122 ++++++++++++++++++ .../include/yams/correlationscax.h | 2 + .../include/yams/curvaturesolver.h | 10 +- .../include/yams/datastorage.h | 5 +- diffop.h => libyams/include/yams/diffop.h | 7 +- .../include/yams/eqcurvaturesolver.h | 8 +- .../include/yams/gridmetrics.h | 13 +- .../include/yams/gridreader.h | 11 +- .../include/yams/gridrender.h | 7 +- .../include/yams/meridionalsolvercase.h | 9 +- .../include/yams/meshtools.h | 7 +- plots.h => libyams/include/yams/plots.h | 4 +- .../include/yams/solvercasetools.h | 2 +- libyams/libyamsConfig.cmake.in | 14 ++ python/CMakeLists.txt | 42 ++---- python/MANIFEST | 2 + python/pyams/__init__.py | 1 + python/pyams/_version.py | 2 + python/{ => pyams}/post.py | 0 python/setup.cfg | 16 +++ python/setup.py | 3 + python/{ => src}/vtk_bind.h | 0 python/{ => src}/yamsbind.cpp | 26 ++-- recipe/bld.bat | 8 +- recipe/build.sh | 8 +- recipe/meta.yaml | 23 +--- tests/CMakeLists.txt | 47 +++---- tests/gridsbuilders.h | 6 +- tests/tests_burgereq.cpp | 2 +- tests/tests_curvaturesolver.cpp | 16 ++- tests/tests_datastorage.cpp | 11 +- tests/tests_diff.cpp | 16 ++- tests/tests_equations.cpp | 20 +-- tests/tests_euler1D.cpp | 4 +- tests/tests_grid2D.cpp | 15 ++- tests/tests_mesh.cpp | 5 +- tests/tests_visu.cpp | 12 +- yams-cli/CMakeLists.txt | 19 +++ yams.cpp => yams-cli/src/yams.cpp | 12 +- 43 files changed, 564 insertions(+), 255 deletions(-) create mode 100644 README create mode 100644 libyams/CMakeLists.txt rename correlationscax.h => libyams/include/yams/correlationscax.h (99%) rename curvaturesolver.h => libyams/include/yams/curvaturesolver.h (99%) rename datastorage.h => libyams/include/yams/datastorage.h (99%) rename diffop.h => libyams/include/yams/diffop.h (99%) rename eqcurvaturesolver.h => libyams/include/yams/eqcurvaturesolver.h (99%) rename gridmetrics.h => libyams/include/yams/gridmetrics.h (98%) rename gridreader.h => libyams/include/yams/gridreader.h (99%) rename gridrender.h => libyams/include/yams/gridrender.h (99%) rename meridionalsolvercase.h => libyams/include/yams/meridionalsolvercase.h (99%) rename meshtools.h => libyams/include/yams/meshtools.h (99%) rename plots.h => libyams/include/yams/plots.h (98%) rename solvercasetools.h => libyams/include/yams/solvercasetools.h (96%) create mode 100644 libyams/libyamsConfig.cmake.in create mode 100644 python/MANIFEST create mode 100644 python/pyams/__init__.py create mode 100644 python/pyams/_version.py rename python/{ => pyams}/post.py (100%) create mode 100644 python/setup.cfg create mode 100644 python/setup.py rename python/{ => src}/vtk_bind.h (100%) rename python/{ => src}/yamsbind.cpp (97%) create mode 100644 yams-cli/CMakeLists.txt rename yams.cpp => yams-cli/src/yams.cpp (95%) diff --git a/.gitignore b/.gitignore index 5cbb1e1..ab7335b 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,53 @@ build/ __pycache__ *_svs.* -*_dummy.* \ No newline at end of file +*_dummy.* + +pyams.egg-info/ +*.orig + +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll +*.pyd + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app diff --git a/CMakeLists.txt b/CMakeLists.txt index ff61f08..869b185 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,123 +1,45 @@ cmake_minimum_required(VERSION 3.17.0) -set(CMAKE_INCLUDE_CURRENT_DIR ON) +project(yams) -project(gbs LANGUAGES CXX) - -# -# c++ conf -# -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS ON) -set(CMAKE_INCLUDE_CURRENT_DIR ON) -# # +# Build options +option(BUILD_LIB "Enable the build of header-only library" ON) +option(BUILD_CLI "Enable the build of the CLI" OFF) +option(BUILD_TESTS "Enable the build of the C++ tests" OFF) +option(BUILD_PYTHON_BINDINGS "Enable the build of Python bindings" OFF) +# Set installation directories include(GNUInstallDirs) message("-- CMake install prefix: " ${CMAKE_INSTALL_PREFIX}) message(" -> binaries: " ${CMAKE_INSTALL_BINDIR}) message(" -> libs: " ${CMAKE_INSTALL_LIBDIR}) message(" -> includes: " ${CMAKE_INSTALL_INCLUDEDIR}) -# -# set output dirs (vs is a pain) -# -function(SET_OUT_DIR REQUIRED_ARG) - list(GET ARGV 0 TARGET_NAME) - list(GET ARGV 1 OUT_DIR) - message(${TARGET_NAME}) - message(${OUT_DIR}) - foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} ) - string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG ) - set_property(TARGET ${TARGET_NAME} PROPERTY RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${OUT_DIR} ) - set_property(TARGET ${TARGET_NAME} PROPERTY LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${OUT_DIR} ) - set_property(TARGET ${TARGET_NAME} PROPERTY ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${OUT_DIR} ) - endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES ) -endfunction() + +set(CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE + STRING "install path for libyamsConfig.cmake") # Paths +# TODO: remove this after GBS refactoring file(TO_CMAKE_PATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} lib_dir) file(TO_CMAKE_PATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR} bin_dir) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}) include_directories(${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/gbs) link_directories(${lib_dir}) link_directories(${bin_dir}) - -# Eigen -find_package (Eigen3 3.3 REQUIRED NO_MODULE) -include_directories(${EIGEN3_INCLUDE_DIR}) -# libIGES -include_directories(${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/iges/) -# -# xtensors -# -set(XTENSOR_USE_XSIMD BOOL:ON) -find_package(xtl REQUIRED) -find_package(xtensor REQUIRED) -find_package(xsimd REQUIRED) -add_definitions(-DXTENSOR_USE_XSIMD) -# -# VTK -# -find_package( - VTK REQUIRED - COMPONENTS - CommonCore - CommonColor - CommonDataModel - FiltersSources - InteractionStyle - RenderingCore - RenderingAnnotation - RenderingFreeType - IOXML - ChartsCore - InteractionStyle - RenderingContext2D - RenderingContextOpenGL2 - RenderingCore - RenderingFreeType - ViewsContext2D - RenderingOpenGL2 - Python - WrappingPythonCore -) -# NLopt -find_package(NLopt REQUIRED) - -if(LINUX) - # add_definitions(-D__TBB_show_deprecation_message_task_H)) - find_package(TBB REQUIRED) +if (${BUILD_LIB}) + add_subdirectory(libyams) endif() if(${BUILD_TESTS}) add_subdirectory(tests) endif() -if(${BUILD_PYTHON_BINDING}) +if(${BUILD_PYTHON_BINDINGS}) add_subdirectory(python) endif() -add_executable( - yams MACOSX_BUNDLE - yams.cpp -) -target_link_libraries( - yams - NLopt::nlopt - ${VTK_LIBRARIES} - xtensor - xtensor::optimize - xtensor::use_xsimd - gbs-render - iges - TBB::tbb -) - -vtk_module_autoinit( - TARGETS yams - MODULES ${VTK_LIBRARIES} -) -install(TARGETS yams) \ No newline at end of file +if(${BUILD_CLI}) + add_subdirectory(yams-cli) +endif() diff --git a/README b/README new file mode 100644 index 0000000..b5c57be --- /dev/null +++ b/README @@ -0,0 +1,116 @@ +# YAMS + +## Build instructions + +### Clone the repo + +Start by cloning the repo: + +```bash +$ git clone https://github.com/ssg-aero/yams.git +``` + +Then move to the newly created directory: + +```bash +$ cd yams +``` + +### Install dev requirements + +Make sure you have `yams`'s development requirements installed in your environment. +To do so, you can create a new ``conda`` env using ``mamba`` or ``micromamba``: + +```bash +$ micromamba create -f environment-dev.yml +``` + +### Build the projects + +Note: +All ``cmake`` commands listed below use ``bash`` multi-line syntax. + On Windows, replace ``\`` trailing character with ``^``. + +Note: +Feel free to use your favorite generator: ``make``, ``ninja``, etc. + +Note: +Installation prefix on Unix (linux and MacOS) is set to your `conda` env using +the `CMAKE_INSTALL_PREFIX` CMake option to the `CONDA_PREFIX` env variable. On Windows, +it has to be set to `CONDA_PREFIX/Library`. + + +#### ``libyams`` library + +`libyams` is a header-only library, so it has no translation unit to compile and the +library CMake definition is used: +- to install headers in the correct directory +- to forward include directories and link libraries to downstream projects + +```bash +$ mkdir -p build +$ cd build +$ cmake .. \ +$ -DBUILD_LIB=ON \ +$ -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX +$ ninja +``` + +Note: +This target is built by default + +#### C++ Tests + +Build C++ tests by activating the `BUILD_TESTS` CMake option: + +```bash +$ mkdir -p build +$ cd build +$ cmake .. \ +$ -G"Ninja" \ +$ -DBUILD_TESTS=ON \ +$ -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX +$ ninja +``` + +#### Python bindings + +To build the Python bindings and make it possible to use `yams` from Python code, just +active the `BUILD_PYTHON_BINDINGS` CMake option: + +```bash +$ mkdir -p build +$ cd build +$ cmake .. \ +$ -G"Ninja" \ +$ -DBUILD_PYTHON_BINDINGS=ON \ +$ -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX +$ ninja install +``` +CMake will install the shared library in the Python package source directory. +It can be then installed using `pip`: + +```bash +$ pip install ./python +``` + +or in editable mode: + +```bash +$ pip install -e ./python +``` + +#### CLI interface + +`yams` as a simple CLI interface one can use to run a simulation. +To build it, just active the `BUILD_CLI` CMake option in the `cmake` command. + +```bash +$ mkdir -p build +$ cd build +$ cmake .. \ +$ -G"Ninja" \ +$ -BUILD_CLI=ON \ +$ -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX +$ ninja install +``` \ No newline at end of file diff --git a/environment-dev.yml b/environment-dev.yml index c2a5fc8..0b1f2da 100644 --- a/environment-dev.yml +++ b/environment-dev.yml @@ -15,4 +15,7 @@ dependencies: - python=3.9 - pybind11 - pytest + - gtest + - gmock + - nlopt - sel(win): vs2019_win-64 \ No newline at end of file diff --git a/libyams/CMakeLists.txt b/libyams/CMakeLists.txt new file mode 100644 index 0000000..3aae11d --- /dev/null +++ b/libyams/CMakeLists.txt @@ -0,0 +1,122 @@ +project(libyams) + +# C++ conf +set(CMAKE_CXX_STANDARD 20) + +# dependencies +## Eigen +find_package (Eigen3 3.3 REQUIRED NO_MODULE) +#include_directories(${EIGEN3_INCLUDE_DIR}) + +## libIGES +include_directories(${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/iges/) + +## xtensor/xsimd +find_package(xtl REQUIRED) +find_package(xtensor REQUIRED) +find_package(xsimd REQUIRED) +add_definitions(-DXTENSOR_USE_XSIMD) + +## VTK +find_package( + VTK REQUIRED + COMPONENTS + CommonCore + CommonColor + CommonDataModel + FiltersSources + InteractionStyle + RenderingCore + RenderingAnnotation + RenderingFreeType + IOXML + ChartsCore + InteractionStyle + RenderingContext2D + RenderingContextOpenGL2 + RenderingCore + RenderingFreeType + ViewsContext2D + RenderingOpenGL2 + Python + WrappingPythonCore +) + +## NLopt +find_package(NLopt REQUIRED) + +# TBB +if(LINUX) + # add_definitions(-D__TBB_show_deprecation_message_task_H)) + find_package(TBB REQUIRED) +endif() + +set(YAMS_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) + +set(yams_headers + ${YAMS_INCLUDE_DIR}/yams/correlationscax.h + ${YAMS_INCLUDE_DIR}/yams/curvaturesolver.h + ${YAMS_INCLUDE_DIR}/yams/datastorage.h + ${YAMS_INCLUDE_DIR}/yams/diffop.h + ${YAMS_INCLUDE_DIR}/yams/eqcurvaturesolver.h + ${YAMS_INCLUDE_DIR}/yams/gridmetrics.h + ${YAMS_INCLUDE_DIR}/yams/gridreader.h + ${YAMS_INCLUDE_DIR}/yams/gridrender.h + ${YAMS_INCLUDE_DIR}/yams/meridionalsolvercase.h + ${YAMS_INCLUDE_DIR}/yams/meshtools.h + ${YAMS_INCLUDE_DIR}/yams/plots.h + ${YAMS_INCLUDE_DIR}/yams/solvercasetools.h +) + +add_library(libyams INTERFACE ${yams_headers}) +target_compile_features(libyams INTERFACE cxx_std_20) + +target_include_directories( + libyams + INTERFACE + $ + $ +) + +target_link_libraries( + libyams INTERFACE + NLopt::nlopt + ${VTK_LIBRARIES} + xtensor + xtensor::optimize + xtensor::use_xsimd + Eigen3::Eigen + gbs-render + iges + TBB::tbb +) + +vtk_module_autoinit( + TARGETS libyams + MODULES ${VTK_LIBRARIES} +) + +install(TARGETS libyams EXPORT ${PROJECT_NAME}-targets) +install(FILES ${yams_headers} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yams) + +# CMake config +# Add helpers for cmake configuration +include(CMakePackageConfigHelpers) + +# Definition +set(ConfigFileInstallDir ${CMAKECONFIG_INSTALL_DIR}) +configure_package_config_file(${PROJECT_NAME}Config.cmake.in + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + INSTALL_DESTINATION ${ConfigFileInstallDir}) + +# Makes the project importable from the build directory +export(EXPORT ${PROJECT_NAME}-targets +FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake") + +# Installation +install(EXPORT ${PROJECT_NAME}-targets + FILE ${PROJECT_NAME}Targets.cmake + DESTINATION ${ConfigFileInstallDir}) + +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake + DESTINATION ${ConfigFileInstallDir}) diff --git a/correlationscax.h b/libyams/include/yams/correlationscax.h similarity index 99% rename from correlationscax.h rename to libyams/include/yams/correlationscax.h index 8a914b7..ec7b21b 100644 --- a/correlationscax.h +++ b/libyams/include/yams/correlationscax.h @@ -1,6 +1,8 @@ #pragma once + #include #include + namespace yams { auto Kti(auto tb, auto c) diff --git a/curvaturesolver.h b/libyams/include/yams/curvaturesolver.h similarity index 99% rename from curvaturesolver.h rename to libyams/include/yams/curvaturesolver.h index 48533ac..9ef873c 100644 --- a/curvaturesolver.h +++ b/libyams/include/yams/curvaturesolver.h @@ -1,10 +1,12 @@ #pragma once -#include -#include -#include + +#include "eqcurvaturesolver.h" +#include "meridionalsolvercase.h" +#include "gridmetrics.h" +#include "meshtools.h" + #include #include -#include // const bool use_meridional_grad = false; // const bool use_meridional_grad = true; diff --git a/datastorage.h b/libyams/include/yams/datastorage.h similarity index 99% rename from datastorage.h rename to libyams/include/yams/datastorage.h index e819bbc..33ae7de 100644 --- a/datastorage.h +++ b/libyams/include/yams/datastorage.h @@ -1,7 +1,10 @@ #pragma once -#include + #include + #include +#include + namespace yams { template diff --git a/diffop.h b/libyams/include/yams/diffop.h similarity index 99% rename from diffop.h rename to libyams/include/yams/diffop.h index ddf0028..4a61826 100644 --- a/diffop.h +++ b/libyams/include/yams/diffop.h @@ -1,5 +1,8 @@ -#pragma once -#include +#pragma once + +#include "datastorage.h" + + namespace yams { template diff --git a/eqcurvaturesolver.h b/libyams/include/yams/eqcurvaturesolver.h similarity index 99% rename from eqcurvaturesolver.h rename to libyams/include/yams/eqcurvaturesolver.h index d2d4c85..6e0d9e5 100644 --- a/eqcurvaturesolver.h +++ b/libyams/include/yams/eqcurvaturesolver.h @@ -1,7 +1,11 @@ #pragma once -#include -#include + +#include "diffop.h" + #include + +#include + // Using Novak and Hearsey 1977 namespace yams { diff --git a/gridmetrics.h b/libyams/include/yams/gridmetrics.h similarity index 98% rename from gridmetrics.h rename to libyams/include/yams/gridmetrics.h index 0d92d69..90df8c9 100644 --- a/gridmetrics.h +++ b/libyams/include/yams/gridmetrics.h @@ -1,11 +1,14 @@ #pragma once -#include -#include + +#include "datastorage.h" +#include "meridionalsolvercase.h" +#include "gridreader.h" +#include "diffop.h" +#include "correlationscax.h" + #include #include -#include -#include -#include + namespace yams { template diff --git a/gridreader.h b/libyams/include/yams/gridreader.h similarity index 99% rename from gridreader.h rename to libyams/include/yams/gridreader.h index 6400a9f..c632019 100644 --- a/gridreader.h +++ b/libyams/include/yams/gridreader.h @@ -1,16 +1,21 @@ #pragma once + +#include "datastorage.h" +#include "meridionalsolvercase.h" + #include #include #include #include #include #include -#include -#include + #include + #include #include -#include + +#include namespace yams { diff --git a/gridrender.h b/libyams/include/yams/gridrender.h similarity index 99% rename from gridrender.h rename to libyams/include/yams/gridrender.h index 2406afb..e07d412 100644 --- a/gridrender.h +++ b/libyams/include/yams/gridrender.h @@ -1,5 +1,9 @@ #pragma once + +#include "meridionalsolvercase.h" + #include + #include #include #include @@ -17,8 +21,9 @@ #include #include #include + #include -#include + namespace yams { template diff --git a/meridionalsolvercase.h b/libyams/include/yams/meridionalsolvercase.h similarity index 99% rename from meridionalsolvercase.h rename to libyams/include/yams/meridionalsolvercase.h index 9c3f7b9..ee93c72 100644 --- a/meridionalsolvercase.h +++ b/libyams/include/yams/meridionalsolvercase.h @@ -1,8 +1,13 @@ #pragma once -#include + +#include "datastorage.h" + +#include + #include #include -#include + + namespace yams { template diff --git a/meshtools.h b/libyams/include/yams/meshtools.h similarity index 99% rename from meshtools.h rename to libyams/include/yams/meshtools.h index 209613c..1034473 100644 --- a/meshtools.h +++ b/libyams/include/yams/meshtools.h @@ -1,10 +1,13 @@ #pragma once -#include -#include + #include #include #include #include + +#include +#include + namespace yams { template diff --git a/plots.h b/libyams/include/yams/plots.h similarity index 98% rename from plots.h rename to libyams/include/yams/plots.h index 9203723..14c0809 100644 --- a/plots.h +++ b/libyams/include/yams/plots.h @@ -1,6 +1,7 @@ #pragma once -#include +#include "curvaturesolver.h" + #include #include #include @@ -15,6 +16,7 @@ #include #include #include + namespace yams { template diff --git a/solvercasetools.h b/libyams/include/yams/solvercasetools.h similarity index 96% rename from solvercasetools.h rename to libyams/include/yams/solvercasetools.h index ea09d4a..8e20deb 100644 --- a/solvercasetools.h +++ b/libyams/include/yams/solvercasetools.h @@ -1,4 +1,4 @@ -#include +#include "meridionalsolvercase.h" namespace yams { diff --git a/libyams/libyamsConfig.cmake.in b/libyams/libyamsConfig.cmake.in new file mode 100644 index 0000000..c352689 --- /dev/null +++ b/libyams/libyamsConfig.cmake.in @@ -0,0 +1,14 @@ +# libyams cmake module +# This module sets the following variables in your project: +# +# libyams_FOUND - true if libyams found on the system +# libyams_INCLUDE_DIRS - the directory containing libyams headers +# libyams_LIBRARY - empty + + +@PACKAGE_INIT@ + +if(NOT TARGET @PROJECT_NAME@) + include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") + get_target_property(@PROJECT_NAME@_INCLUDE_DIRS @PROJECT_NAME@ INTERFACE_INCLUDE_DIRECTORIES) +endif() \ No newline at end of file diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 9dfbafe..752a6c1 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -1,8 +1,12 @@ cmake_minimum_required(VERSION 3.17.0) -project(pyams LANGUAGES CXX) +project(yams_bindings) -# set(CMAKE_INCLUDE_CURRENT_DIR ON) +if(NOT TARGET libyams) + find_package(libyams REQUIRED) +endif () + +find_package(pybind11 REQUIRED) find_package(Python3 COMPONENTS @@ -10,40 +14,20 @@ find_package(Python3 Developement ) message("Python3_SITELIB:" ${Python3_SITELIB}) -find_package(pybind11 REQUIRED) -file(GLOB SRC_LIST "*.cpp") - -pybind11_add_module( - ${PROJECT_NAME} - ${SRC_LIST} +pybind11_add_module(yams_bindings + src/yamsbind.cpp ) target_link_libraries( - ${PROJECT_NAME} PRIVATE - ${VTK_LIBRARIES} - TBB::tbb - NLopt::nlopt - gbs-render -) - -vtk_module_autoinit( - TARGETS ${PROJECT_NAME} - MODULES ${VTK_LIBRARIES} + ${PROJECT_NAME} PRIVATE + libyams ) set_target_properties( ${PROJECT_NAME} PROPERTIES - OUTPUT_NAME "yams" -) - -install( - TARGETS ${PROJECT_NAME} - DESTINATION ${Python3_SITELIB}/${PROJECT_NAME} + OUTPUT_NAME "yams_bindings" ) -file(GLOB PY_SRC_LIST "*.py") - -install(FILES ${PY_SRC_LIST} - DESTINATION ${Python3_SITELIB}/${PROJECT_NAME} -) \ No newline at end of file +install(TARGETS ${PROJECT_NAME} + LIBRARY DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/pyams/) \ No newline at end of file diff --git a/python/MANIFEST b/python/MANIFEST new file mode 100644 index 0000000..0745145 --- /dev/null +++ b/python/MANIFEST @@ -0,0 +1,2 @@ +include pyams/yams_bindings* +exclude src/ \ No newline at end of file diff --git a/python/pyams/__init__.py b/python/pyams/__init__.py new file mode 100644 index 0000000..02e5e8e --- /dev/null +++ b/python/pyams/__init__.py @@ -0,0 +1 @@ +from pyams.yams_bindings import * # noqa: F401,F403 \ No newline at end of file diff --git a/python/pyams/_version.py b/python/pyams/_version.py new file mode 100644 index 0000000..2c78aca --- /dev/null +++ b/python/pyams/_version.py @@ -0,0 +1,2 @@ +version_info = (0, 7, 0) +__version__ = ".".join(map(str, version_info)) diff --git a/python/post.py b/python/pyams/post.py similarity index 100% rename from python/post.py rename to python/pyams/post.py diff --git a/python/setup.cfg b/python/setup.cfg new file mode 100644 index 0000000..acd48cc --- /dev/null +++ b/python/setup.cfg @@ -0,0 +1,16 @@ +[metadata] +name = pyams +version = attr: pyams._version.__version__ +description = YAMS aerodynamic solver +long_description = Python bindings of YAMS aerodynamic solver +long_description_content_type = text/markdown +license_file = LICENSE +author = SSG-Aero +url = https://github.com/ssg-aero/yams +platforms = Windows, Linux, Mac OS X +keywords = yams, gbs + +[options] +include_package_data = True +packages = find: +python_requires = >=3.7 \ No newline at end of file diff --git a/python/setup.py b/python/setup.py new file mode 100644 index 0000000..c1057cf --- /dev/null +++ b/python/setup.py @@ -0,0 +1,3 @@ +import setuptools + +setuptools.setup() \ No newline at end of file diff --git a/python/vtk_bind.h b/python/src/vtk_bind.h similarity index 100% rename from python/vtk_bind.h rename to python/src/vtk_bind.h diff --git a/python/yamsbind.cpp b/python/src/yamsbind.cpp similarity index 97% rename from python/yamsbind.cpp rename to python/src/yamsbind.cpp index 7fa9709..1d182f8 100644 --- a/python/yamsbind.cpp +++ b/python/src/yamsbind.cpp @@ -1,20 +1,24 @@ +#include "vtk_bind.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include + #include + namespace py = pybind11; -PYBIND11_MODULE(yams, m) +PYBIND11_MODULE(yams_bindings, m) { using namespace yams; using T = double; diff --git a/recipe/bld.bat b/recipe/bld.bat index 21f4ada..c3c7a80 100644 --- a/recipe/bld.bat +++ b/recipe/bld.bat @@ -4,12 +4,16 @@ cd build-conda cmake .. ^ -D CMAKE_BUILD_TYPE:STRING="Release" ^ --D BUILD_TESTS:BOOL=FALSE ^ --D BUILD_PYTHON_BINDING=TRUE ^ +-D BUILD_TESTS=OFF ^ +-D BUILD_CLI=ON ^ +-D BUILD_PYTHON_BINDINGS=ON ^ -D CMAKE_INSTALL_PREFIX=%LIBRARY_PREFIX% ^ -G "Ninja" ^ -Wno-dev ninja install +cd ../python +%PYTHON% -m pip install ../python --no-deps -vv + cd .. diff --git a/recipe/build.sh b/recipe/build.sh index beb4945..96548fe 100644 --- a/recipe/build.sh +++ b/recipe/build.sh @@ -3,12 +3,16 @@ cd build-conda cmake .. \ -D CMAKE_BUILD_TYPE:STRING="Release" \ --D BUILD_TESTS:BOOL=FALSE \ --D BUILD_PYTHON_BINDING=TRUE \ +-D BUILD_TESTS=OFF \ +-D BUILD_CLI=ON \ +-D BUILD_PYTHON_BINDINGS=ON \ -D CMAKE_INSTALL_PREFIX=$PREFIX \ -G "Ninja" \ -Wno-dev ninja install +cd ../python +$PYTHON -m pip install . --no-deps -vv + cd .. \ No newline at end of file diff --git a/recipe/meta.yaml b/recipe/meta.yaml index 7df97d7..8497ad6 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -10,34 +10,23 @@ build: requirements: build: - {{ compiler('cxx') }} - # - {{ cdt('libx11-devel') }} # [linux] - # - {{ cdt('xorg-x11-proto-devel') }} # [linux] - # - {{ cdt('mesa-libgl-devel') }} # [linux] - # - {{ cdt('libxi-devel') }} # [linux] - vs2019_win-64 [win] - ninja - - cmake - # - python {{ python }} + - cmake + - python host: - # - {{ cdt('libx11-devel') }} # [linux] - # - {{ cdt('xorg-x11-proto-devel') }} # [linux] - # - {{ cdt('mesa-libgl-devel') }} # [linux] - # - {{ cdt('libxi-devel') }} # [linux] - # - python {{ python }} - - python=3.9 + - python - python-devtools - pybind11 - xtl - xtensor - xsimd - gbs >=0.1.9 - - tbb <2021.0 [linux] # upgrade asap when other packages will be ready + - tbb <2021.0 # [linux] run: - # - python {{ python }} - # - pytest - - python=3.9 + - python - gbs - - tbb <2021.0 [linux] # upgrade asap when other packages will be ready + - tbb <2021.0 # [linux] about: home: http://www.ssg-aero.com license: LGPL3 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4e64fec..7124454 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,40 +1,29 @@ cmake_minimum_required(VERSION 3.17.0) -find_package(GTest REQUIRED) +project(yams_tests) -project(quiss_tests LANGUAGES CXX) if(MSVC) add_compile_options(/bigobj) endif() -message(${CMAKE_CURRENT_SOURCE_DIR}/../) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../) +find_package(GTest REQUIRED) + +if(NOT TARGET libyams) + find_package(libyams REQUIRED) +endif () file(GLOB SRC_LIST "tests_*") + foreach(file_name ${SRC_LIST}) - get_filename_component(exe_name ${file_name} NAME_WE ) - add_executable(${exe_name} ${file_name}) - - target_link_libraries(${exe_name} - GTest::gtest - GTest::gtest_main - xtensor - xtensor::optimize - xtensor::use_xsimd - ${VTK_LIBRARIES} - NLopt::nlopt - gbs-render - iges - TBB::tbb - ) - - install(TARGETS ${exe_name}) - if ( MSVC ) - SET_OUT_DIR(${exe_name} ${CMAKE_BINARY_DIR}) - endif ( MSVC ) - vtk_module_autoinit( - TARGETS ${exe_name} - MODULES ${VTK_LIBRARIES} - ) - + get_filename_component(exe_name ${file_name} NAME_WE) + add_executable(${exe_name} ${file_name}) + + target_link_libraries( + ${exe_name} + GTest::gtest + GTest::gtest_main + libyams + ) + + install(TARGETS ${exe_name}) endforeach() \ No newline at end of file diff --git a/tests/gridsbuilders.h b/tests/gridsbuilders.h index c6d33d4..b8e85c2 100644 --- a/tests/gridsbuilders.h +++ b/tests/gridsbuilders.h @@ -1,5 +1,9 @@ -# pragma once +#pragma once + #include +#include +#include + template auto make_uniform_grid(double l,double h, T &g,double a=0, double b=0,double ri=0.) -> void { diff --git a/tests/tests_burgereq.cpp b/tests/tests_burgereq.cpp index 60a9ecf..9c59e38 100644 --- a/tests/tests_burgereq.cpp +++ b/tests/tests_burgereq.cpp @@ -2,7 +2,6 @@ // #include #include - #include #include #include @@ -16,6 +15,7 @@ #include #include #include + template void plotXY(const std::vector &X, const std::vector> &Y) { diff --git a/tests/tests_curvaturesolver.cpp b/tests/tests_curvaturesolver.cpp index 960e0ef..3e3acfe 100644 --- a/tests/tests_curvaturesolver.cpp +++ b/tests/tests_curvaturesolver.cpp @@ -1,11 +1,15 @@ +#include "gridsbuilders.h" + +#include +#include +#include +#include +#include + #include -#include -#include -#include -#include -#include -#include + #include + #include #include // #include diff --git a/tests/tests_datastorage.cpp b/tests/tests_datastorage.cpp index 221f22f..7d23ce2 100644 --- a/tests/tests_datastorage.cpp +++ b/tests/tests_datastorage.cpp @@ -1,8 +1,11 @@ +#include "gridsbuilders.h" + +#include +#include +#include + #include -#include -#include -#include -#include + #include #include #include diff --git a/tests/tests_diff.cpp b/tests/tests_diff.cpp index e910c6b..cdb1692 100644 --- a/tests/tests_diff.cpp +++ b/tests/tests_diff.cpp @@ -1,11 +1,15 @@ +#include "gridsbuilders.h" + +#include +#include +#include +#include +#include + #include -#include -#include -#include -#include -#include -#include + #include + using namespace yams; const double PI = acos(-1.); diff --git a/tests/tests_equations.cpp b/tests/tests_equations.cpp index 8f4d4ee..fbb4440 100644 --- a/tests/tests_equations.cpp +++ b/tests/tests_equations.cpp @@ -1,16 +1,20 @@ +#include "gridsbuilders.h" + +#include +#include +#include +#include + #include -#include -#include -#include -#include -#include + #include #include #include +#include + #include -#include const double PI = acos(-1.); const bool TESTS_USE_PLOT = true; @@ -21,8 +25,6 @@ using gbs::operator*; using gbs::operator+; using gbs::operator-; - - auto f_sqVmq2 = [](const auto &gp) { return 0.5 * gp.Vm * gp.Vm; }; auto f_mf = [](const auto &gp) { @@ -967,8 +969,6 @@ TEST(tests_eq, solve_straight_cmp) } } -#include -#include TEST(tests_gridreader, vtk_no_blades) { using T = double; diff --git a/tests/tests_euler1D.cpp b/tests/tests_euler1D.cpp index ab57258..1529af4 100644 --- a/tests/tests_euler1D.cpp +++ b/tests/tests_euler1D.cpp @@ -1,6 +1,6 @@ #include -#include +#include #include #include @@ -15,6 +15,8 @@ #include #include #include + + template void plotXY(const std::vector &X, const std::vector &Y) { diff --git a/tests/tests_grid2D.cpp b/tests/tests_grid2D.cpp index b216def..6e48207 100644 --- a/tests/tests_grid2D.cpp +++ b/tests/tests_grid2D.cpp @@ -1,13 +1,18 @@ +#include "gridsbuilders.h" + +#include +#include +#include +#include + #include + #include #include #include -#include -#include -#include -#include -#include + #include + using T = double; using namespace yams; const bool PLOT_ON = false; diff --git a/tests/tests_mesh.cpp b/tests/tests_mesh.cpp index ca8e66a..947b5c6 100644 --- a/tests/tests_mesh.cpp +++ b/tests/tests_mesh.cpp @@ -1,7 +1,10 @@ +#include + #include -#include + #include #include + using T = double; const T tol{static_cast(1e-6)}; const bool PLOT_ON = true; diff --git a/tests/tests_visu.cpp b/tests/tests_visu.cpp index 14732b7..32747e2 100644 --- a/tests/tests_visu.cpp +++ b/tests/tests_visu.cpp @@ -1,9 +1,11 @@ +#include "gridsbuilders.h" + +#include +#include +#include +#include + #include -#include -#include -#include -#include -#include const double PI = acos(-1.); diff --git a/yams-cli/CMakeLists.txt b/yams-cli/CMakeLists.txt new file mode 100644 index 0000000..414314a --- /dev/null +++ b/yams-cli/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.17.0) + +project(yams-cli) + +if(NOT TARGET libyams) + find_package(libyams REQUIRED) +endif () + +add_executable( + yams MACOSX_BUNDLE + ${CMAKE_CURRENT_SOURCE_DIR}/src/yams.cpp +) + +target_link_libraries( + yams PRIVATE + libyams +) + +install(TARGETS yams) \ No newline at end of file diff --git a/yams.cpp b/yams-cli/src/yams.cpp similarity index 95% rename from yams.cpp rename to yams-cli/src/yams.cpp index c161761..f7809ff 100644 --- a/yams.cpp +++ b/yams-cli/src/yams.cpp @@ -1,9 +1,11 @@ +#include +#include +#include +#include +#include + #include -#include -#include -#include -#include -#include + int main(int argc, char *argv[]) { From 4220b85801210ed889d2df0bb4bdfb968f92341c Mon Sep 17 00:00:00 2001 From: Adrien DELSALLE Date: Wed, 6 Jul 2022 12:28:44 +0200 Subject: [PATCH 2/2] use dependency on gbs replace incl dirs and links libs with deps on gbs targets --- CMakeLists.txt | 8 ---- libyams/CMakeLists.txt | 65 +++++++------------------------ libyams/include/yams/gridreader.h | 2 +- libyams/include/yams/gridrender.h | 2 +- libyams/include/yams/meshtools.h | 4 +- python/src/yamsbind.cpp | 2 +- tests/tests_diff.cpp | 2 +- tests/tests_grid2D.cpp | 4 +- tests/tests_mesh.cpp | 4 +- 9 files changed, 23 insertions(+), 70 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 869b185..12d617e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,14 +19,6 @@ message(" -> includes: " ${CMAKE_INSTALL_INCLUDEDIR}) set(CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE STRING "install path for libyamsConfig.cmake") -# Paths -# TODO: remove this after GBS refactoring -file(TO_CMAKE_PATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} lib_dir) -file(TO_CMAKE_PATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR} bin_dir) -include_directories(${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}) -include_directories(${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/gbs) -link_directories(${lib_dir}) -link_directories(${bin_dir}) if (${BUILD_LIB}) add_subdirectory(libyams) diff --git a/libyams/CMakeLists.txt b/libyams/CMakeLists.txt index 3aae11d..98a2a93 100644 --- a/libyams/CMakeLists.txt +++ b/libyams/CMakeLists.txt @@ -3,11 +3,6 @@ project(libyams) # C++ conf set(CMAKE_CXX_STANDARD 20) -# dependencies -## Eigen -find_package (Eigen3 3.3 REQUIRED NO_MODULE) -#include_directories(${EIGEN3_INCLUDE_DIR}) - ## libIGES include_directories(${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/iges/) @@ -17,39 +12,10 @@ find_package(xtensor REQUIRED) find_package(xsimd REQUIRED) add_definitions(-DXTENSOR_USE_XSIMD) -## VTK -find_package( - VTK REQUIRED - COMPONENTS - CommonCore - CommonColor - CommonDataModel - FiltersSources - InteractionStyle - RenderingCore - RenderingAnnotation - RenderingFreeType - IOXML - ChartsCore - InteractionStyle - RenderingContext2D - RenderingContextOpenGL2 - RenderingCore - RenderingFreeType - ViewsContext2D - RenderingOpenGL2 - Python - WrappingPythonCore -) - -## NLopt -find_package(NLopt REQUIRED) - -# TBB -if(LINUX) - # add_definitions(-D__TBB_show_deprecation_message_task_H)) - find_package(TBB REQUIRED) -endif() +find_package(gbs REQUIRED) +find_package(gbs-io REQUIRED) +find_package(gbs-render REQUIRED) +find_package(gbs-mesh REQUIRED) set(YAMS_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) @@ -79,22 +45,17 @@ target_include_directories( ) target_link_libraries( - libyams INTERFACE - NLopt::nlopt - ${VTK_LIBRARIES} - xtensor - xtensor::optimize - xtensor::use_xsimd - Eigen3::Eigen - gbs-render - iges - TBB::tbb + libyams + INTERFACE + xtensor + xtensor::optimize + xtensor::use_xsimd + gbs::core + gbs::render + gbs::io + gbs::mesh ) -vtk_module_autoinit( - TARGETS libyams - MODULES ${VTK_LIBRARIES} -) install(TARGETS libyams EXPORT ${PROJECT_NAME}-targets) install(FILES ${yams_headers} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yams) diff --git a/libyams/include/yams/gridreader.h b/libyams/include/yams/gridreader.h index c632019..172eb6e 100644 --- a/libyams/include/yams/gridreader.h +++ b/libyams/include/yams/gridreader.h @@ -13,7 +13,7 @@ #include #include -#include +#include #include diff --git a/libyams/include/yams/gridrender.h b/libyams/include/yams/gridrender.h index e07d412..965401b 100644 --- a/libyams/include/yams/gridrender.h +++ b/libyams/include/yams/gridrender.h @@ -2,7 +2,7 @@ #include "meridionalsolvercase.h" -#include +#include #include #include diff --git a/libyams/include/yams/meshtools.h b/libyams/include/yams/meshtools.h index 1034473..575678a 100644 --- a/libyams/include/yams/meshtools.h +++ b/libyams/include/yams/meshtools.h @@ -2,8 +2,8 @@ #include #include -#include -#include +#include +#include #include #include diff --git a/python/src/yamsbind.cpp b/python/src/yamsbind.cpp index 1d182f8..8145905 100644 --- a/python/src/yamsbind.cpp +++ b/python/src/yamsbind.cpp @@ -14,7 +14,7 @@ #include #include -#include +#include namespace py = pybind11; diff --git a/tests/tests_diff.cpp b/tests/tests_diff.cpp index cdb1692..6962a99 100644 --- a/tests/tests_diff.cpp +++ b/tests/tests_diff.cpp @@ -8,7 +8,7 @@ #include -#include +#include using namespace yams; diff --git a/tests/tests_grid2D.cpp b/tests/tests_grid2D.cpp index 6e48207..814be41 100644 --- a/tests/tests_grid2D.cpp +++ b/tests/tests_grid2D.cpp @@ -8,8 +8,8 @@ #include #include -#include -#include +#include +#include #include diff --git a/tests/tests_mesh.cpp b/tests/tests_mesh.cpp index 947b5c6..e96e5fe 100644 --- a/tests/tests_mesh.cpp +++ b/tests/tests_mesh.cpp @@ -2,8 +2,8 @@ #include -#include -#include +#include +#include using T = double; const T tol{static_cast(1e-6)};