Skip to content

Commit 66dba05

Browse files
834 merge #933
2 parents 2cdc949 + a338812 commit 66dba05

File tree

260 files changed

+5076
-3220
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

260 files changed

+5076
-3220
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,6 @@ cmake_install.cmake
9696

9797

9898
third-party/pybind11
99+
100+
# Build dependencies/
101+
KLU_module_deps

.travis.yml

+8-19
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ addons:
1414
- libopenblas-dev
1515
- liblapack-dev
1616
- graphviz
17-
- libsuitesparse-dev
1817

1918
matrix:
2019
include:
@@ -31,7 +30,6 @@ matrix:
3130
- liblapack-dev
3231
- graphviz
3332
- python3.6-dev
34-
- libsuitesparse-dev
3533
env:
3634
- PYBAMM_UNIT=true
3735
- PYBAMM_EXAMPLES=true
@@ -49,7 +47,6 @@ matrix:
4947
- liblapack-dev
5048
- graphviz
5149
- python3.7-dev
52-
- libsuitesparse-dev
5350
env:
5451
- PYBAMM_UNIT=true
5552
- PYBAMM_EXAMPLES=true
@@ -76,7 +73,6 @@ matrix:
7673
- liblapack-dev
7774
- graphviz
7875
- python3.7-dev
79-
- libsuitesparse-dev
8076
env:
8177
- PYBAMM_UNIT=true
8278
- PYBAMM_SCIKITS_ODES=true
@@ -94,7 +90,6 @@ matrix:
9490
- liblapack-dev
9591
- graphviz
9692
- python3.7-dev
97-
- libsuitesparse-dev
9893
env:
9994
- PYBAMM_UNIT=true
10095
- PYBAMM_EXAMPLES=true
@@ -112,7 +107,6 @@ matrix:
112107
- liblapack-dev
113108
- graphviz
114109
- python3.7-dev
115-
- libsuitesparse-dev
116110
env:
117111
- PYBAMM_COVER=true
118112
- PYBAMM_SCIKITS_ODES=true
@@ -130,7 +124,6 @@ matrix:
130124
- liblapack-dev
131125
- graphviz
132126
- python3.7-dev
133-
- libsuitesparse-dev
134127
env:
135128
- PYBAMM_DOCS=true
136129
if: type != cron
@@ -146,7 +139,6 @@ matrix:
146139
- liblapack-dev
147140
- graphviz
148141
- python3.7-dev
149-
- libsuitesparse-dev
150142
env:
151143
- PYBAMM_STYLE=true
152144
if: type != cron
@@ -163,7 +155,6 @@ matrix:
163155
- liblapack-dev
164156
- graphviz
165157
- python3.7-dev
166-
- libsuitesparse-dev
167158
env:
168159
- PYBAMM_UNIT=true
169160
- PYBAMM_EXAMPLES=true
@@ -195,6 +186,7 @@ before_install: |
195186
source venv/bin/activate;
196187
# A manual check that the correct version of Python is running.
197188
python --version;
189+
pip install wheel;
198190
fi
199191
200192
# Install dependencies
@@ -203,27 +195,24 @@ before_install: |
203195
# without the packages from -dev and -doc!
204196
install:
205197
- pip install --upgrade pip
206-
# In order to download SUNDIALS and SuiteSparse
207-
- pip install wget
208198
- pip install -e .
209199
- if [[ $PYBAMM_DOCS == true ]]; then pip install -e .[docs]; fi;
210200
- if [[ $PYBAMM_STYLE == true || $PYBAMM_EXAMPLES ]]; then pip install -e .[dev]; fi;
211201
- if [[ $PYBAMM_COVER == true ]]; then pip install coverage codecov; fi;
212202
- |
213203
if [[ $PYBAMM_SCIKITS_ODES == true ]]; then
214-
python setup.py install_odes -f;
215-
export LD_LIBRARY_PATH=sundials/lib:$LD_LIBRARY_PATH
204+
pip install wget;
205+
pybamm_install_odes --install-sundials;
206+
export LD_LIBRARY_PATH=scikits.odes/sundials5/lib:$LD_LIBRARY_PATH;
216207
fi;
217208
- |
218209
if [[ $PYBAMM_KLU == true ]]; then
219-
mkdir -p third-party;
220-
cd third-party;
210+
pip install wget
211+
python scripts/setup_KLU_module_build.py
212+
export LD_LIBRARY_PATH=$(HOME)/.local/lib:$LD_LIBRARY_PATH
221213
rm -rf pybind11;
222214
git clone https://github.com/pybind/pybind11.git;
223-
cd ../;
224-
python setup.py install_klu -f;
225-
export LD_LIBRARY_PATH=sundials/lib:$LD_LIBRARY_PATH
226-
export LD_LIBRARY_PATH=SuiteSparse-5.6.0/lib:$LD_LIBRARY_PATH
215+
pip install -e .
227216
fi;
228217
229218
before_script:

CHANGELOG.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Features
44

5+
- Added functionality to solver to automatically discretise a 0D model ([#947](https://github.com/pybamm-team/PyBaMM/pull/947))
6+
- Added sensitivity to `CasadiAlgebraicSolver` ([#940](https://github.com/pybamm-team/PyBaMM/pull/940))
7+
- Added `ProcessedSymbolicVariable` class, which can handle symbolic variables (i.e. variables for which the inputs are symbolic) ([#940](https://github.com/pybamm-team/PyBaMM/pull/940))
58
- Made `QuickPlot` compatible with Google Colab ([#935](https://github.com/pybamm-team/PyBaMM/pull/935))
69
- Added `BasicFull` model for lead-acid ([#932](https://github.com/pybamm-team/PyBaMM/pull/932))
710

@@ -12,11 +15,19 @@
1215

1316
## Bug fixes
1417

18+
- Fixed `Interpolant` ids to allow processing ([#962](https://github.com/pybamm-team/PyBaMM/pull/962)
19+
- Changed simulation attributes to assign copies rather than the objects themselves ([#952](https://github.com/pybamm-team/PyBaMM/pull/952)
20+
- Added default values to base model so that it works with the `Simulation` class ([#952](https://github.com/pybamm-team/PyBaMM/pull/952)
21+
- Fixed solver to recompute initial conditions when inputs are changed ([#951](https://github.com/pybamm-team/PyBaMM/pull/951)
22+
- Reformatted thermal submodels ([#938](https://github.com/pybamm-team/PyBaMM/pull/938)
1523
- Reformatted electrolyte submodels ([#927](https://github.com/pybamm-team/PyBaMM/pull/927))
24+
- Reformatted convection submodels ([#635](https://github.com/pybamm-team/PyBaMM/pull/635))
1625

1726
## Breaking changes
1827

1928
- Removed some inputs like `T_inf`, `R_g` and activation energies to some of the standard function parameters. This is because each of those inputs is specific to a particular function (e.g. the reference temperature at which the function was measured). To change a property such as the activation energy, users should create a new function, specifying the relevant property as a `Parameter` or `InputParameter` ([#942](https://github.com/pybamm-team/PyBaMM/pull/942))
29+
- The thermal option 'xyz-lumped' has been removed. The option 'thermal current collector' has also been removed ([#938](https://github.com/pybamm-team/PyBaMM/pull/938)
30+
- The 'C-rate' parameter has been deprecated. Use 'Current function [A]' instead. The cell capacity can be accessed as 'Cell capacity [A.h]', and used to calculate current from C-rate ([#952](https://github.com/pybamm-team/PyBaMM/pull/952)
2031

2132
# [v0.2.1](https://github.com/pybamm-team/PyBaMM/tree/v0.2.1) - 2020-03-31
2233

@@ -45,7 +56,7 @@ New expression tree node types, models, parameter sets and solvers, as well as g
4556

4657
## Bug fixes
4758

48-
- Filter out discontinuities that occur after solve times
59+
- Filter out discontinuities that occur after solve times
4960
([#941](https://github.com/pybamm-team/PyBaMM/pull/945))
5061
- Fixed tight layout for QuickPlot in jupyter notebooks ([#930](https://github.com/pybamm-team/PyBaMM/pull/930))
5162
- Fixed bug raised if function returns a scalar ([#919](https://github.com/pybamm-team/PyBaMM/pull/919))

CMakeBuild.py

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import os
2+
import sys
3+
import subprocess
4+
from pathlib import Path
5+
from platform import system
6+
7+
try:
8+
from setuptools.command.build_ext import build_ext
9+
except ImportError:
10+
from distutils.command.build_ext import build_ext
11+
12+
default_lib_dir = (
13+
"" if system() == "Windows" else os.path.join(os.getenv("HOME"), ".local")
14+
)
15+
16+
17+
class CMakeBuild(build_ext):
18+
user_options = build_ext.user_options + [
19+
("suitesparse-root=", None, "suitesparse source location"),
20+
("sundials-root=", None, "sundials source location"),
21+
]
22+
23+
def initialize_options(self):
24+
build_ext.initialize_options(self)
25+
self.suitesparse_root = None
26+
self.sundials_root = None
27+
28+
def finalize_options(self):
29+
build_ext.finalize_options(self)
30+
# Determine the calling command to get the
31+
# undefined options from.
32+
# If build_ext was called directly then this
33+
# doesn't matter.
34+
try:
35+
self.get_finalized_command("install", create=0)
36+
calling_cmd = "install"
37+
except AttributeError:
38+
calling_cmd = "bdist_wheel"
39+
self.set_undefined_options(
40+
calling_cmd,
41+
("suitesparse_root", "suitesparse_root"),
42+
("sundials_root", "sundials_root"),
43+
)
44+
if not self.suitesparse_root:
45+
self.suitesparse_root = os.path.join(default_lib_dir)
46+
if not self.sundials_root:
47+
self.sundials_root = os.path.join(default_lib_dir)
48+
49+
def run(self):
50+
if not self.extensions:
51+
return
52+
53+
cmake_args = ["-DPYTHON_EXECUTABLE={}".format(sys.executable)]
54+
if self.suitesparse_root:
55+
cmake_args.append(
56+
"-DSuiteSparse_ROOT={}".format(os.path.abspath(self.suitesparse_root))
57+
)
58+
if self.sundials_root:
59+
cmake_args.append(
60+
"-DSUNDIALS_ROOT={}".format(os.path.abspath(self.sundials_root))
61+
)
62+
63+
if not os.path.exists(self.build_temp):
64+
os.makedirs(self.build_temp)
65+
66+
# The CMakeError.log file is generated by cmake is the configure step
67+
# encounters error. In the following the existence of this file is used
68+
# to determine whether or not the cmake configure step went smoothly.
69+
# So must make sure this file does not remain from a previous failed build.
70+
if os.path.isfile(os.path.join(self.build_temp, "CMakeError.log")):
71+
os.remove(os.path.join(self.build_temp, "CMakeError.log"))
72+
73+
cmake_list_dir = os.path.abspath(os.path.dirname(__file__))
74+
print("-" * 10, "Running CMake for idaklu solver", "-" * 40)
75+
subprocess.run(["cmake", cmake_list_dir] + cmake_args, cwd=self.build_temp)
76+
77+
if os.path.isfile(os.path.join(self.build_temp, "CMakeError.log")):
78+
msg = (
79+
"cmake configuration steps encountered errors, and the idaklu module"
80+
" could not be built. Make sure dependencies are correctly "
81+
"installed. See "
82+
"https://github.com/pybamm-team/PyBaMM/blob/develop/"
83+
"INSTALL-LINUX-MAC.md"
84+
)
85+
raise RuntimeError(msg)
86+
else:
87+
print("-" * 10, "Building idaklu module", "-" * 40)
88+
subprocess.run(["cmake", "--build", "."], cwd=self.build_temp)
89+
90+
# Move from build temp to final position
91+
for ext in self.extensions:
92+
self.move_output(ext)
93+
94+
def move_output(self, ext):
95+
# Copy built module to dist/ directory
96+
build_temp = Path(self.build_temp).resolve()
97+
source_path = build_temp / self.get_ext_filename(ext.name)
98+
# Get destination location
99+
# self.get_ext_fullpath(ext.name) -->
100+
# build/lib.linux-x86_64-3.5/idaklu.cpython-37m-x86_64-linux-gnu.so
101+
# using resolve() with python < 3.6 will result in a FileNotFoundError
102+
# since the location does not yet exists.
103+
dest_path = Path(self.get_ext_fullpath(ext.name)).resolve()
104+
source_path = build_temp / self.get_ext_filename(ext.name)
105+
dest_directory = dest_path.parents[0]
106+
dest_directory.mkdir(parents=True, exist_ok=True)
107+
self.copy_file(source_path, dest_path)

CMakeLists.txt

+9-11
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,20 @@ project(idaklu)
44
set (CMAKE_CXX_STANDARD 11)
55
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
66

7-
add_subdirectory(third-party/pybind11)
7+
if(NOT PYBIND11_DIR)
8+
set(PYBIND11_DIR pybind11)
9+
endif()
10+
11+
add_subdirectory(${PYBIND11_DIR})
812
pybind11_add_module(idaklu pybamm/solvers/c_solvers/idaklu.cpp)
913

14+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR})
1015
# Sundials
11-
set(SUNDIALS_INCLUDE "sundials/include")
12-
TARGET_INCLUDE_DIRECTORIES(idaklu PRIVATE ${SUNDIALS_INCLUDE})
13-
14-
find_library(SUNMATSPARSE sundials_sunmatrixsparse PATHS "sundials/lib" NO_DEFAULT_PATH)
15-
find_library(IDA sundials_ida PATHS "sundials/lib" NO_DEFAULT_PATH)
16-
find_library(NVECTOR sundials_nvecserial PATHS "sundials/lib" NO_DEFAULT_PATH)
17-
find_library(SUNKLU sundials_sunlinsolklu PATHS "sundials/lib" NO_DEFAULT_PATH)
18-
TARGET_LINK_LIBRARIES(idaklu PRIVATE ${SUNMATSPARSE} ${IDA} ${NVECTOR} ${SUNKLU})
16+
find_package(SUNDIALS)
17+
target_include_directories(idaklu PRIVATE ${SUNDIALS_INCLUDE_DIR})
18+
target_link_libraries(idaklu PRIVATE ${SUNDIALS_LIBRARIES})
1919

2020
# link suitesparse
21-
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR})
22-
set(SuiteSparse_ROOT SuiteSparse-5.6.0)
2321
find_package(SuiteSparse OPTIONAL_COMPONENTS KLU AMD COLAMD BTF)
2422
include_directories(${SuiteSparse_INCLUDE_DIRS})
2523
target_link_libraries(idaklu PRIVATE ${SuiteSparse_LIBRARIES})

FindSUNDIALS.cmake

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# This module is adapted from that in CADET (`<https://github.com/modsim/CADET)>`_):
2+
3+
# .. cmake_module::
4+
5+
# Find SUNDIALS, the SUite of Nonlinear and DIfferential/ALgebraic equation Solvers.
6+
#
7+
# The module looks for the following sundials components
8+
#
9+
# * sundials_ida
10+
# * sundials_sunlinsolklu
11+
# * sundials_sunmatrix_sparse
12+
# * sundials_nvecserial
13+
#
14+
# To provide the module with a hint about where to find your SUNDIALS installation,
15+
# you can set the environment variable :code:`SUNDIALS_ROOT`. The FindSUNDIALS module will
16+
# then look in this path when searching for SUNDIALS paths and libraries.
17+
# This behavior is defined in CMake >= 3.12, see policy CMP0074.
18+
# It is replicated for older versions by adding the :code:`SUNDIALS_ROOT` variable to the
19+
# :code:`PATHS` entry.
20+
#
21+
# This module will define the following variables:
22+
# :code:`SUNDIALS_INCLUDE_DIRS` - Location of the SUNDIALS includes
23+
# :code:`SUNDIALS_LIBRARIES` - Required libraries for all requested components
24+
25+
# List of the valid SUNDIALS components
26+
27+
# find the SUNDIALS include directories
28+
find_path(SUNDIALS_INCLUDE_DIR
29+
NAMES
30+
ida/ida.h
31+
sundials/sundials_math.h
32+
sundials/sundials_types.h
33+
sunlinsol/sunlinsol_klu.h
34+
sunmatrix/sunmatrix_sparse.h
35+
PATH_SUFFIXES
36+
include
37+
PATHS
38+
${SUNDIALS_ROOT}
39+
)
40+
41+
set(SUNDIALS_WANT_COMPONENTS
42+
sundials_ida
43+
sundials_sunlinsolklu
44+
sundials_sunmatrixsparse
45+
sundials_nvecserial
46+
)
47+
48+
# find the SUNDIALS libraries
49+
foreach(LIB ${SUNDIALS_WANT_COMPONENTS})
50+
if (UNIX AND SUNDIALS_PREFER_STATIC_LIBRARIES)
51+
# According to bug 1643 on the CMake bug tracker, this is the
52+
# preferred method for searching for a static library.
53+
# See http://www.cmake.org/Bug/view.php?id=1643. We search
54+
# first for the full static library name, but fall back to a
55+
# generic search on the name if the static search fails.
56+
set(THIS_LIBRARY_SEARCH lib${LIB}.a ${LIB})
57+
else()
58+
set(THIS_LIBRARY_SEARCH ${LIB})
59+
endif()
60+
61+
find_library(SUNDIALS_${LIB}_LIBRARY
62+
NAMES ${THIS_LIBRARY_SEARCH}
63+
PATH_SUFFIXES
64+
lib
65+
Lib
66+
PATHS
67+
${SUNDIALS_ROOT}
68+
)
69+
70+
set(SUNDIALS_${LIB}_FOUND FALSE)
71+
if (SUNDIALS_${LIB}_LIBRARY)
72+
list(APPEND SUNDIALS_LIBRARIES ${SUNDIALS_${LIB}_LIBRARY})
73+
set(SUNDIALS_${LIB}_FOUND TRUE)
74+
endif()
75+
mark_as_advanced(SUNDIALS_${LIB}_LIBRARY)
76+
endforeach()
77+
78+
mark_as_advanced(
79+
SUNDIALS_LIBRARIES
80+
SUNDIALS_INCLUDE_DIR
81+
)

0 commit comments

Comments
 (0)