diff --git a/.gitignore b/.gitignore index 5c699a12102b0bdd42249a7bad009c33ccd3f061..a8fd9957d1b1366a9ec3fb1ee7777eb655e0e161 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,5 @@ _local_tmp doc/bibtex.json RELEASE-VERSION /db +/lbmpy/phasefield/simplex_projection.*.so +/lbmpy/phasefield/simplex_projection.c \ No newline at end of file diff --git a/lbmpy/phasefield/nphase_nestler.py b/lbmpy/phasefield/nphase_nestler.py index 7ca7e8983465e07f4405395fa3e88440251bda10..1437148d2a1fe1911b4c101b0db1d13024b356e5 100644 --- a/lbmpy/phasefield/nphase_nestler.py +++ b/lbmpy/phasefield/nphase_nestler.py @@ -1,18 +1,25 @@ -import pyximport +try: + import pyximport + + pyximport.install(language_level=3) + from lbmpy.phasefield.simplex_projection import simplex_projection_2d # NOQA +except ImportError: + try: + from lbmpy.phasefield.simplex_projection import simplex_projection_2d # NOQA + except ImportError: + raise ImportError("neither pyximport nor binary module simplex_projection_2d available.") + import sympy as sp from lbmpy.creationfunctions import create_lb_update_rule from lbmpy.macroscopic_value_kernels import pdf_initialization_assignments from lbmpy.phasefield.analytical import chemical_potentials_from_free_energy, force_from_phi_and_mu from lbmpy.phasefield.cahn_hilliard_lbm import cahn_hilliard_lb_method -from lbmpy.phasefield.simplex_projection import simplex_projection_2d # NOQA from lbmpy.stencils import get_stencil from pystencils import Assignment, create_data_handling, create_kernel from pystencils.fd import Diff, discretize_spatial, expand_diff_full from pystencils.fd.derivation import FiniteDifferenceStencilDerivation -pyximport.install(language_level=3) - def forth_order_isotropic_discretize(field): second_neighbor_stencil = [(i, j) diff --git a/setup.py b/setup.py index 40177808ef3c35c9b9ebf566629780bd914d2390..e78ac28fa1dbb30cfce4984575202c28533f47fa 100644 --- a/setup.py +++ b/setup.py @@ -8,12 +8,17 @@ from importlib import import_module sys.path.insert(0, os.path.abspath('doc')) +try: + import cython # noqa + USE_CYTHON = True +except ImportError: + USE_CYTHON = False + quick_tests = [ - # 'test_serial_scenarios.test_ldc_mrt', + 'test_serial_scenarios.test_ldc_mrt', 'test_serial_scenarios.test_channel_srt', ] - class SimpleTestRunner(distutils.cmd.Command): """A custom command to run selected tests""" @@ -43,7 +48,6 @@ class SimpleTestRunner(distutils.cmd.Command): for test in quick_tests: self._run_tests_in_module(test) - try: sys.path.insert(0, os.path.abspath('doc')) from version_from_git import version_number_from_git @@ -54,6 +58,14 @@ try: except ImportError: version = open('RELEASE-VERSION', 'r').read() +def cython_extensions(*extensions): + from distutils.extension import Extension + ext = '.pyx' if USE_CYTHON else '.c' + result = [Extension(e, [e.replace('.', '/') + ext]) for e in extensions] + if USE_CYTHON: + from Cython.Build import cythonize + result = cythonize(result, language_level=3) + return result def readme(): with open('README.md') as f: @@ -71,6 +83,9 @@ setup(name='lbmpy', url='https://i10git.cs.fau.de/pycodegen/lbmpy/', packages=['lbmpy'] + ['lbmpy.' + s for s in find_packages('lbmpy')], install_requires=['pystencils', 'sympy>=1.2', 'numpy>=1.11.0'], + package_data={'lbmpy': ['phasefield/simplex_projection.pyx', + 'phasefield/simplex_projection.c']}, + ext_modules=cython_extensions("lbmpy.phasefield.simplex_projection"), classifiers=[ 'Development Status :: 4 - Beta', 'Framework :: Jupyter', @@ -89,6 +104,7 @@ setup(name='lbmpy', 'ipy_table', 'imageio', 'jupyter', 'pyevtk'], 'doc': ['sphinx', 'sphinx_rtd_theme', 'nbsphinx', 'sphinxcontrib-bibtex', 'sphinx_autodoc_typehints', 'pandoc'], + 'phasefield': ['Cython'] }, cmdclass={ 'quicktest': SimpleTestRunner