Skip to content

Commit

Permalink
Merge branch 'cmf2' of https://github.com/philippkraft/cmf into cmf2
Browse files Browse the repository at this point in the history
� Conflicts:
�	tools/docker-build.sh
�	tools/install_solvers.sh
  • Loading branch information
philippkraft committed Apr 9, 2022
2 parents b796612 + 5c7380d commit bac6584
Show file tree
Hide file tree
Showing 10 changed files with 210 additions and 173 deletions.
3 changes: 1 addition & 2 deletions cmf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
from .timetools import StopWatch, datetime_to_cmf, timerange


__version__ = '2.0.0b5.cmf2'
__compiletime__ = 'Fri Jan 15 16:05:41 2021'
__version__ = '2.0.0b6'

from .cmf_core import connect_cells_with_flux as __ccwf

Expand Down
2 changes: 1 addition & 1 deletion cmf/cmf_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ def __format__(self, fmt):

# Register Time in _cmf_core:
_cmf_core.Time_swigregister(Time)
__compiledate__ = cvar.__compiledate__
Pi = cvar.Pi

class Date(object):
Expand Down Expand Up @@ -2012,6 +2011,7 @@ def __init__(self, *args):
global_water_balance = _swig_new_instance_method(_cmf_core.node_list_global_water_balance)
water_balance = _swig_new_instance_method(_cmf_core.node_list_water_balance)
conc = _swig_new_instance_method(_cmf_core.node_list_conc)
set_solute_source = _swig_new_instance_method(_cmf_core.node_list_set_solute_source)
get_fluxes_to = _swig_new_instance_method(_cmf_core.node_list_get_fluxes_to)
get_fluxes3d_to = _swig_new_instance_method(_cmf_core.node_list_get_fluxes3d_to)
get_fluxes3d = _swig_new_instance_method(_cmf_core.node_list_get_fluxes3d)
Expand Down
262 changes: 161 additions & 101 deletions cmf/cmf_core_src/cmf_wrap.cpp

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion cmf/cmf_core_src/math/real.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ typedef double real;
const real REAL_MAX = std::numeric_limits<real>::max();
#endif

const std::string __compiledate__ = std::string("cmf compiled ") + std::string(__DATE__) + " - " + std::string(__TIME__);

// Some helper functions
/// Returns the minimum of two values
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
numpy>=1.14
wheel
scipy>=1.0
cmake>=3.13.0
# shapely>=1.5.0
86 changes: 36 additions & 50 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,8 @@
from setuptools.command.build_ext import build_ext
from distutils.sysconfig import customize_compiler
from distutils.command.build_py import build_py

version = '2.0.0b5'

branchversion = version
try:
from pygit2 import Repository
head = Repository('.').head.shorthand
if head != 'master':
branchversion = version + '.' + head
except:
Repository = None

print('cmf', branchversion)


import logging
logging.basicConfig(level=logging.DEBUG)

swig = False
openmp = False
Expand All @@ -61,8 +48,8 @@ def __init__(self, includepath, libpath, *libs, build_script=None, build_always=
self.build_script_name = build_script
self.build_always = build_always

def __str__(self):
return self.libs[0] + ' - library'
def __repr__(self):
return self.libs[0] + '-library'

def as_win32(self):
checked_libs = []
Expand All @@ -76,19 +63,27 @@ def as_win32(self):
return [self.libpath], reversed(checked_libs), []

def as_posix(self):
# Move static libraries to extra_objects (with path) to ensure static linking in posix systems
if os.path.exists(self.libpath):
libpath = self.libpath
elif os.path.exists(self.libpath + '64'):
libpath = self.libpath + '64'
else:
raise FileNotFoundError("Can't find static library directory" + self.libpath)
def get_posix_path_to_lib(libname):
def lib_to_path(libpath, libname):
p = libpath + '/' + f'lib{libname}.a'
if os.path.exists(p):
return p
else:
return None

def raise_if_none(path_to_lib):
if path_to_lib:
return path_to_lib
else:
raise FileNotFoundError(f"Can't find static library {libname} in {self.libpath}[64]")

return raise_if_none(
lib_to_path(self.libpath, libname) or
lib_to_path(self.libpath + '64', libname)
)

libfiles = ['{}/lib{}.a'.format(libpath, l) for l in self.libs]
for lf in libfiles:
if not os.path.exists(lf):
raise FileNotFoundError("Can't find static library " + lf)
return [], [], libfiles
# Move static libraries to extra_objects (with path) to ensure static linking in posix systems
return [], [], [get_posix_path_to_lib(l) for l in self.libs]

def exists(self):
try:
Expand All @@ -113,6 +108,7 @@ def extend(self, include_dirs, library_dirs, libraries, extra_objects):

def build(self):
import subprocess as sp
logging.debug(f'StaticLibrary.build({self})')
cwd = os.path.dirname(__file__)
if os.name == 'nt':
script_ext = '.bat'
Expand Down Expand Up @@ -194,6 +190,7 @@ def add_numpy_include(self):
ext.include_dirs += [get_numpy_include()]

def build_libraries(self):
logging.debug('build_libraries()' + str(static_libraries))
for sl in static_libraries:
if not sl.exists():
print(sl, 'get downloaded and installed')
Expand All @@ -215,6 +212,7 @@ def build_libraries(self):


def build_extensions(self):
logging.debug('build_extensions()')
customize_compiler(self.compiler)

try:
Expand Down Expand Up @@ -250,19 +248,10 @@ def updateversion():
cmf/__init__.py: set __version__ constant
Doxyfile: set PROJECT_NUMBER
"""
try:
module_code = open('cmf/__init__.py').readlines()
except IOError:
pass
else:
fout = open('cmf/__init__.py', 'w')
for line in module_code:
if line.startswith('__version__'):
fout.write("__version__ = '{}'\n".format(branchversion))
elif line.startswith('__compiletime__'):
fout.write("__compiletime__ = '{}'\n".format(time.ctime()))
else:
fout.write(line)
logging.debug('updateversion()')
with open('cmf/__init__.py') as initfile:
t = initfile.read()
version = re.search('__version__ ?= ?\'(.*?)\'', t).group(1)
try:
doxycode = open('tools/Doxyfile').readlines()
except IOError:
Expand All @@ -274,7 +263,7 @@ def updateversion():
fout.write("PROJECT_NUMBER = {}\n".format(version))
else:
fout.write(line)

return version

def pop_arg(arg):
"""
Expand Down Expand Up @@ -338,7 +327,7 @@ def make_cmf_core():
- include dirs
- extra compiler flags
"""

logging.debug('make_cmf_core()')
# Include numpy
include_dirs = []
library_dirs = []
Expand Down Expand Up @@ -388,14 +377,11 @@ def make_cmf_core():

# Get the source files
cmf_files = [] # get_source_files()
if not any('cmf_core' in sl.libs for sl in static_libraries):
print('search source files')
cmf_files += get_source_files()

if swig:
# Adding cmf.i when build_ext should perform the swig call
cmf_files.append("cmf/cmf_core_src/cmf.i")
swig_opts = ['-c++', '-w512', '-w511', '-O', '-keyword', '-castmode', '-modern']
swig_opts = ['-c++', '-w512', '-w511', '-O', '-keyword', '-castmode']

else:
# Else use what we have there
Expand All @@ -416,7 +402,7 @@ def make_cmf_core():


if __name__ == '__main__':
updateversion()
version = updateversion()
openmp = not pop_arg('noopenmp')
swig = pop_arg('swig')
debug = not pop_arg('nodebug')
Expand All @@ -442,7 +428,7 @@ def make_cmf_core():
ext_modules=ext,
packages=['cmf', 'cmf.draw', 'cmf.geometry'],
python_requires='>=3.7',
install_requires='numpy>=1.11.1',
install_requires=['numpy>=1.11.1', 'cmake>3.1.0'],
keywords='hydrology catchment simulation toolbox',
author='Philipp Kraft',
author_email="philipp.kraft@umwelt.uni-giessen.de",
Expand Down
2 changes: 1 addition & 1 deletion tools/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = cmf
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 2.0.0b5
PROJECT_NUMBER = 2.0.0b6

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
4 changes: 3 additions & 1 deletion tools/docker-build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

# This file should be used in a manylinux container to build several binaries
# Explain usage if no /io directory exists (which mounts on proper docker usage the current directory)
[[ -d "/io" ]] || echo "Run in manylinux container:\ndocker run -ti -v $(pwd):/io quay.io/pypa/manylinux2014_x86_64 /bin/bash /io/cmf2/tools/docker-build.sh"

Expand All @@ -17,6 +18,7 @@ function repair_wheel {

export CFLAGS="-fPIC"
export CXXFLAGS="-fPIC"
CMFDIR=/io/cmf
export MAKEFLAGS="-j$(nproc)"

CMFDIR=/io/cmf2
Expand All @@ -25,7 +27,7 @@ TOOLDIR=$CMFDIR/tools

# Install solvers
SOLVERBUILDDIR=$CMFDIR/build/extern
# rm -rf $SOLVERBUILDDIR
rm -rf $SOLVERBUILDDIR
cmake -S ${TOOLDIR} -B ${SOLVERBUILDDIR} -DCMAKE_BUILD_TYPE=Release
make -C ${SOLVERBUILDDIR}

Expand Down
14 changes: 4 additions & 10 deletions tools/install_cmf_core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,13 @@ export CXXFLAGS="-fPIC"

CWD=$PWD
TOOLDIR=$(dirname $0)
TOOLDIR=$(python3 $TOOLDIR/abspath.py $TOOLDIR)
echo "tools: "$TOOLDIR
CMFDIR=$(python3 $TOOLDIR/abspath.py $TOOLDIR/..)
echo "home: "$CMFDIR

CMFDIR=$TOOLDIR/..

BUILDDIR=$CMFDIR/build/cmf_core
echo "CMF build directory: "$BUILDDIR
CMF_CORE_SRC=$CMFDIR/cmf/cmf_core_src
echo "CMF core source directory: "$CMF_CORE_SRC
mkdir -p $BUILDDIR
cd $BUILDDIR
cmake $CMF_CORE_SRC -DCMAKE_BUILD_TYPE=Release
make $MAKE_OPTIONS
make install
cmake -S $CMF_CORE_SRC -B $BUILDDIR -DCMAKE_BUILD_TYPE=Release
make -C $BUILDDIR
make install -C $BUILDDIR
cd $CWD
8 changes: 2 additions & 6 deletions tools/install_solvers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,5 @@ export CXXFLAGS="-fPIC"
BUILDDIR=$CMFDIR/build/extern-linux
echo "BUILDDIR="$BUILDDIR

mkdir -p $BUILDDIR
cd $BUILDDIR
cmake ${TOOLDIR} -DCMAKE_BUILD_TYPE=Release
make $MAKE_OPTIONS

cd $CWD
cmake -S ${TOOLDIR} -B ${BUILDDIR} -DCMAKE_BUILD_TYPE=Release
make -C ${BUILDDIR}

0 comments on commit bac6584

Please sign in to comment.