diff --git a/python/MANIFEST.in b/python/MANIFEST.in index 3adb996..e61422f 100644 --- a/python/MANIFEST.in +++ b/python/MANIFEST.in @@ -1,2 +1 @@ include tamaas/_tamaas*.so -include tamaas/libTamaas.so* diff --git a/python/SConscript b/python/SConscript index 254c6c9..601235a 100644 --- a/python/SConscript +++ b/python/SConscript @@ -1,159 +1,162 @@ # -*- mode:python; coding: utf-8 -*- # vim: set ft=python: # @file # @section LICENSE # # Copyright (©) 2016-2020 EPFL (École Polytechnique Fédérale de Lausanne), # Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published # by the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program 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 # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . from __future__ import print_function from os.path import abspath, join from SCons.Script import Import, Split, Copy, Dir Import('main_env') # Pybind11 wrapper env_pybind = main_env.Clone(SHLIBPREFIX='') # Remove pedantic warnings cxx_flags = env_pybind['CXXFLAGS'] try: del cxx_flags[cxx_flags.index('-pedantic')] except ValueError: pass env_pybind.Tool(pybind11) pybind_sources = Split(""" tamaas_module.cpp wrap/core.cpp wrap/percolation.cpp wrap/surface.cpp wrap/model.cpp wrap/solvers.cpp wrap/compute.cpp wrap/test_features.cpp """) # Adding legacy wrap code if env_pybind['legacy_bem']: env_pybind.AppendUnique(CPPDEFINES=['LEGACY_BEM']) pybind_sources += ["wrap/bem.cpp"] # Setting paths to find libTamaas env_pybind.AppendUnique(LIBPATH=[Dir(join('#${build_dir}', 'src'))]) +# Link against a static libTamaas if env_pybind['packaging_setup']: - env_pybind.AppendUnique(RPATH=[ - "'$$$$ORIGIN'", #< path to lib in python module (install from pypi) - ]) + env_pybind.AppendUnique(LIBS=['Tamaas']) # keep other libs for link + env_pybind['RPATH'] = "" # no need for rpath w/ static lib + +# Link against a dynamic libTamaas else: env_pybind.AppendUnique(RPATH=[ "'$$$$ORIGIN/../../src'", #< path to lib in build_dir "'$$$$ORIGIN/../../..'", #< path to lib in install prefix ]) + env_pybind['LIBS'] = ['Tamaas'] # discard other libs for link + # Building the pybind library tamaas_wrap = env_pybind.Pybind11Module( target='tamaas/_tamaas', source=pybind_sources, - LIBS=['Tamaas'], ) # For some reason link happens too early Import('libTamaas') env_pybind.Depends(tamaas_wrap, libTamaas) # Copying the __init__.py file with extra python classes copy_env = env_pybind.Clone() # Copying additional python files python_files = """ compute.py dumpers/__init__.py dumpers/_helper.py nonlinear_solvers/__init__.py """.split() targets = [tamaas_wrap] targets += [ copy_env.Command(join('tamaas', f), join(abspath(str(Dir('#python/tamaas'))), f), Copy("$TARGET", "$SOURCE")) for f in python_files ] targets.append(copy_env.Command('MANIFEST.in', '#python/MANIFEST.in', Copy("$TARGET", "$SOURCE"))) subst_env = env_pybind.Clone( SUBST_DICT={ '@version@': '$version', '@authors@': str(copy_env['authors']), '@email@': '$email', '@packaging_setup@': '${packaging_setup}', # TODO change when issue with unicode fixed # '@copyright@': '$copyright', # '@maintainer@': '$maintainer', } ) subst_env.Tool('textfile') targets.append(subst_env.Substfile('setup.py.in')) targets.append(subst_env.Substfile('tamaas/__init__.py.in')) # Defining alias for python builds main_env.Alias('build-python', targets) # Checking if we can use pip to install (more convenient for end-user) conf = Configure(main_env, custom_tests={'CheckPythonModule': CheckPythonModule}) has_pip = conf.CheckPythonModule('pip') install_env = conf.Finish() # Current build directory install_env['PYDIR'] = Dir('.') # Setting command line for installation if has_pip: install_env['PYINSTALLCOM'] = '${py_exec} -m pip install -U $PYOPTIONS .' install_env['PYDEVELOPCOM'] = \ '${py_exec} -m pip install $PYOPTIONS -e .[solvers,dumpers]' else: install_env['PYINSTALLCOM'] = '${py_exec} setup.py install $PYOPTIONS' install_env['PYDEVELOPCOM'] = '${py_exec} setup.py develop $PYOPTIONS' install_env['py_version'] = get_python_version(install_env) install_env.PrependENVPath( 'PYTHONPATH', install_env.subst('${prefix}/lib/python${py_version}/site-packages')) # Specify install target python_install = install_env.Command( join('$prefix', 'dummy_target'), targets, install_env['PYINSTALLCOM'], PYOPTIONS='--prefix ${prefix}', chdir=install_env['PYDIR']) python_install_dev = install_env.Command( join('$prefix', 'dummy_target_local'), targets, install_env['PYDEVELOPCOM'], PYOPTIONS='--user', chdir=install_env['PYDIR']) main_env.Alias('install-python', python_install) main_env.Alias('dev', python_install_dev) diff --git a/python/setup.py.in b/python/setup.py.in index 814bc89..8842ebb 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -1,93 +1,88 @@ import setuptools import shutil import sysconfig import os long_description = """ # Tamaas - A high-performance library for periodic rough surface contact [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3479236.svg)](https://doi.org/10.5281/zenodo.3479236) [![status](https://joss.theoj.org/papers/86903c51f3c66964eef7776d8aeaf17d/status.svg)](https://joss.theoj.org/papers/86903c51f3c66964eef7776d8aeaf17d) Tamaas (from تماس meaning “contact” in Arabic and Farsi) is a high-performance rough-surface periodic contact code based on boundary and volume integral equations. The clever mathematical formulation of the underlying numerical methods allows the use of the fast-Fourier Transform, a great help in achieving peak performance: Tamaas is consistently two orders of magnitude faster (and lighter) than traditional FEM! Tamaas is aimed at researchers and practitioners wishing to compute realistic contact solutions for the study of interface phenomena. ## Disclaimer This package is intended for ease of installation for Linux platforms, but comes with NO WARRANTY of compatibility. If you experience any issue, please install Tamaas from [source](https://c4science.ch/source/tamaas/). We provide a Docker image for non-Linux systems. This package contains unsigned binary blobs: if you are concerned about security, please build Tamaas from source (the commits are signed). Tamaas is the result of a science research project. To give proper credit to Tamaas and the researchers who have developed the numerical methods that it implements, please cite the [JOSS paper](https://joss.theoj.org/papers/86903c51f3c66964eef7776d8aeaf17d) and the appropriate references therein. ## Dependencies Essentials: - FFTW with OpenMP support (needs to be installed separately, e.g. with your system's package manager) - Numpy Optional: - Scipy (for non-linear solvers) - UVW (for dumpers) - h5py (for dumpers) - netCDF4 (for dumpers) To install with all dependencies (except FFTW), run ``pip install tamaas[solvers,dumpers]``. ## Documentation Documentation can be found on [tamaas.readthedocs.io](https://tamaas.readthedocs.io/en/latest/). """ -version = "@version@" -major = version.split('.')[0] - if @packaging_setup@: shutil.copyfile('../../README.md', 'README.md') - shutil.copyfile('../src/libTamaas.so.{}'.format(version), - 'tamaas/libTamaas.so.{}'.format(major)) setuptools.setup( name="tamaas", version="@version@", packages=setuptools.find_packages(), include_package_data=True, author=', '.join(@authors@), author_email="@email@", description='A high-performance library for periodic rough surface contact', long_description=long_description, long_description_content_type="text/markdown", url="https://c4science.ch/project/view/2036/", install_requires=['numpy'], extras_require={ "dumpers": ['uvw', 'h5py', 'netCDF4'], "solvers": ['scipy'], }, classifiers=[ "Intended Audience :: Science/Research", "License :: OSI Approved :: GNU Affero General Public License v3", "Programming Language :: C++", "Programming Language :: Python :: 3", "Topic :: Scientific/Engineering", "Intended Audience :: Science/Research", "Operating System :: POSIX :: Linux", ] ) diff --git a/src/SConscript b/src/SConscript index b71272e..b4b1fd6 100644 --- a/src/SConscript +++ b/src/SConscript @@ -1,171 +1,174 @@ # -*- mode:python; coding: utf-8 -*- # vim: set ft=python: # @file # @section LICENSE # # Copyright (©) 2016-2020 EPFL (École Polytechnique Fédérale de Lausanne), # Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published # by the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program 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 # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . import os Import('main_env') def prepend(path, list): return [os.path.join(path, x) for x in list] env = main_env.Clone() # Core core_list = """ fft_engine.cpp grid.cpp grid_hermitian.cpp statistics.cpp surface.cpp tamaas.cpp legacy_types.cpp loop.cpp computes.cpp logger.cpp """.split() if env['legacy_bem']: core_list.append('surface_statistics.cpp') core_list = prepend('core', core_list) info_file = main_env.Substfile('tamaas_info.cpp', 'tamaas_info.cpp.in') core_list.append(info_file) # Lib roughcontact generator_list = """ surface_generator.cpp surface_generator_filter.cpp surface_generator_filter_fft.cpp surface_generator_random_phase.cpp isopowerlaw.cpp regularized_powerlaw.cpp """.split() generator_list = prepend('surface', generator_list) # Lib PERCOLATION percolation_list = """ flood_fill.cpp """.split() percolation_list = prepend('percolation', percolation_list) # BEM PERCOLATION bem_list = """ bem_kato.cpp bem_polonski.cpp bem_gigi.cpp bem_gigipol.cpp bem_penalty.cpp bem_uzawa.cpp bem_fft_base.cpp bem_functional.cpp bem_meta_functional.cpp elastic_energy_functional.cpp exponential_adhesion_functional.cpp squared_exponential_adhesion_functional.cpp maugis_adhesion_functional.cpp complimentary_term_functional.cpp bem_grid.cpp bem_grid_polonski.cpp bem_grid_kato.cpp bem_grid_teboulle.cpp bem_grid_condat.cpp """.split() bem_list = prepend('bem', bem_list) # Model model_list = """ model.cpp model_factory.cpp model_type.cpp model_template.cpp integral_operator.cpp be_engine.cpp westergaard.cpp elastic_functional.cpp meta_functional.cpp adhesion_functional.cpp volume_potential.cpp kelvin.cpp mindlin.cpp boussinesq.cpp elasto_plastic/isotropic_hardening.cpp elasto_plastic/residual.cpp integration/element.cpp """.split() model_list = prepend('model', model_list) # Solvers solvers_list = """ contact_solver.cpp polonsky_keer_rey.cpp kato_saturated.cpp kato.cpp beck_teboulle.cpp condat.cpp polonsky_keer_tan.cpp ep_solver.cpp epic.cpp """.split() solvers_list = prepend('solvers', solvers_list) # GPU API gpu_list = """ fftransform_cufft.cpp """.split() gpu_list = prepend('gpu', gpu_list) # Assembling total list rough_contact_list = \ core_list + generator_list + percolation_list + model_list + solvers_list # Adding legacy code if env['legacy_bem']: rough_contact_list += bem_list # Adding GPU if needed if env['backend'] == 'cuda': rough_contact_list += gpu_list # Adding extra warnings for Tamaas base lib env.AppendUnique(CXXFLAGS=['-Wextra']) # Allowing libTamaas.so to find libs in the same directory env.AppendUnique(RPATH=["'$$$$ORIGIN'"]) -# Build library -libTamaas = env.SharedLibrary('Tamaas', - rough_contact_list, - SHLIBVERSION=env['version']) +# Build static library for packaging +if env['packaging_setup']: + libTamaas = env.StaticLibrary('Tamaas', rough_contact_list) +# Build shared library (default) +else: + libTamaas = env.SharedLibrary('Tamaas', rough_contact_list, + SHLIBVERSION=env['version']) # Defining alias for cpp builds main_env.Alias('build-cpp', libTamaas) # Specify install target to install lib lib_prefix = os.path.join(env['prefix'], 'lib') lib_install = env.InstallVersionedLib(target=lib_prefix, source=libTamaas) main_env.Alias('install-lib', lib_install) # Export target for use in python builds Export('libTamaas')