Skip to content

Commit

Permalink
Fix coverage (pybamm-team#3954)
Browse files Browse the repository at this point in the history
  • Loading branch information
kratman authored Apr 1, 2024
1 parent 93448c0 commit 78b7d25
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 46 deletions.
7 changes: 0 additions & 7 deletions pybamm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
#
# Root of the pybamm module.
# Provides access to all shared functionality (models, solvers, etc.).
#
# The code in this file is adapted from Pints
# (see https://github.com/pints-team/pints)
#
import sys
import os

Expand Down
8 changes: 3 additions & 5 deletions pybamm/meshes/one_dimensional_submeshes.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ class Exponential1DSubMesh(SubMesh1D):
.. math::
x_{k} = (b-a) +
\\frac{\mathrm{e}^{\\alpha k / N} - 1}{\mathrm{e}^{\\alpha} - 1} + a,
\\frac{\\mathrm{e}^{\\alpha k / N} - 1}{\\mathrm{e}^{\\alpha} - 1} + a,
for k = 1, ..., N, where N is the number of nodes.
Is side is "right", the gridpoints are given by
.. math::
x_{k} = (b-a) +
\\frac{\mathrm{e}^{-\\alpha k / N} - 1}{\mathrm{e}^{-\\alpha} - 1} + a,
\\frac{\\mathrm{e}^{-\\alpha k / N} - 1}{\\mathrm{e}^{-\\alpha} - 1} + a,
for k = 1, ..., N.
Expand All @@ -149,7 +149,7 @@ class Exponential1DSubMesh(SubMesh1D):
.. math::
x_{k} = (b/2-a) +
\\frac{\mathrm{e}^{\\alpha k / N} - 1}{\mathrm{e}^{\\alpha} - 1} + a,
\\frac{\\mathrm{e}^{\\alpha k / N} - 1}{\\mathrm{e}^{\\alpha} - 1} + a,
for k = 1, ..., N. The grid spacing is then reflected to contruct the grid
on the full interval [a,b].
Expand Down Expand Up @@ -289,14 +289,12 @@ class UserSupplied1DSubMesh(SubMesh1D):
"""

def __init__(self, lims, npts, edges=None):
# raise error if no edges passed
if edges is None:
raise pybamm.GeometryError("User mesh requires parameter 'edges'")

spatial_var, spatial_lims, tabs = self.read_lims(lims)
npts = npts[spatial_var.name]

# check that npts + 1 equals number of user-supplied edges
if (npts + 1) != len(edges):
raise pybamm.GeometryError(
f"""User-suppled edges has should have length (npts + 1) but has length
Expand Down
33 changes: 18 additions & 15 deletions pybamm/solvers/base_solver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#
# Base solver class
#
import copy
import itertools
from scipy.sparse import block_diag
Expand Down Expand Up @@ -357,7 +354,8 @@ def _check_and_prepare_model_inplace(self, model, inputs, ics_only):
)
model.convert_to_format = "casadi"

def _get_vars_for_processing(self, model, inputs, calculate_sensitivities_explicit):
@staticmethod
def _get_vars_for_processing(model, inputs, calculate_sensitivities_explicit):
vars_for_processing = {
"model": model,
"calculate_sensitivities_explicit": calculate_sensitivities_explicit,
Expand Down Expand Up @@ -412,8 +410,9 @@ def _get_vars_for_processing(self, model, inputs, calculate_sensitivities_explic

return vars_for_processing

@staticmethod
def _set_up_model_sensitivities_inplace(
self, model, inputs, calculate_sensitivities_explicit
model, inputs, calculate_sensitivities_explicit
):
"""
Set up model attributes related to sensitivities.
Expand Down Expand Up @@ -998,8 +997,9 @@ def solve(
else:
return solutions

def _get_discontinuity_start_end_indices(self, model, inputs, t_eval):
if model.discontinuity_events_eval == []:
@staticmethod
def _get_discontinuity_start_end_indices(model, inputs, t_eval):
if not model.discontinuity_events_eval:
pybamm.logger.verbose("No discontinuity events found")
return [0], [len(t_eval)], t_eval

Expand Down Expand Up @@ -1038,7 +1038,7 @@ def _get_discontinuity_start_end_indices(self, model, inputs, t_eval):
)

# insert time points around discontinuities in t_eval
# keep track of sub sections to integrate by storing start and end indices
# keep track of subsections to integrate by storing start and end indices
start_indices = [0]
end_indices = []
eps = sys.float_info.epsilon
Expand All @@ -1057,7 +1057,8 @@ def _get_discontinuity_start_end_indices(self, model, inputs, t_eval):

return start_indices, end_indices, t_eval

def _check_events_with_initial_conditions(self, t_eval, model, inputs_dict):
@staticmethod
def _check_events_with_initial_conditions(t_eval, model, inputs_dict):
num_terminate_events = len(model.terminate_events_eval)
if num_terminate_events == 0:
return
Expand Down Expand Up @@ -1267,7 +1268,8 @@ def step(
else:
return old_solution + solution

def get_termination_reason(self, solution, events):
@staticmethod
def get_termination_reason(solution, events):
"""
Identify the cause for termination. In particular, if the solver terminated
due to an event, (try to) pinpoint which event was responsible. If an event
Expand Down Expand Up @@ -1379,7 +1381,7 @@ def check_extrapolation(self, solution, events):
pybamm.SolverWarning,
stacklevel=2,
)
# Add the event dictionaryto the solution object
# Add the event dictionary to the solution object
solution.extrap_events = extrap_events
elif self._on_extrapolation == "error":
raise pybamm.SolverError(
Expand All @@ -1389,7 +1391,8 @@ def check_extrapolation(self, solution, events):
"outside these bounds."
)

def _set_up_model_inputs(self, model, inputs):
@staticmethod
def _set_up_model_inputs(model, inputs):
"""Set up input parameters"""
inputs = inputs or {}

Expand Down Expand Up @@ -1437,21 +1440,21 @@ def process(
jac: :class:`pybamm.EvaluatorPython` or
:class:`pybamm.EvaluatorJaxJacobian` or
:class:`casadi.Function`
evaluator for the Jacobian $\frac{\partial f}{\partial y}$
evaluator for the Jacobian $\\frac{\\partial f}{\\partial y}$
of the function given by `symbol`
jacp: :class:`pybamm.EvaluatorPython` or
:class:`pybamm.EvaluatorJaxSensitivities` or
:class:`casadi.Function`
evaluator for the parameter sensitivities
$\frac{\partial f}{\partial p}$
$\frac{\\partial f}{\\partial p}$
of the function given by `symbol`
jac_action: :class:`pybamm.EvaluatorPython` or
:class:`pybamm.EvaluatorJax` or
:class:`casadi.Function`
evaluator for product of the Jacobian with a vector $v$,
i.e. $\frac{\partial f}{\partial y} * v$
i.e. $\\frac{\\partial f}{\\partial y} * v$
"""

def report(string):
Expand Down
17 changes: 6 additions & 11 deletions pybamm/spatial_methods/scikit_finite_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ class ScikitFiniteElement(pybamm.SpatialMethod):
solving the Poisson problem -grad^2 u = f in the y-z plane (i.e. not the
through-cell direction).
For broadcast we follow the default behaviour from SpatialMethod.
Parameters
----------
mesh : :class:`pybamm.Mesh`
Contains all the submeshes for discretisation
For broadcast, we follow the default behaviour from SpatialMethod.
"""

def __init__(self, options=None):
Expand Down Expand Up @@ -305,9 +300,9 @@ def definite_integral_matrix(self, child, vector_type="row"):
the entire domain
.. math::
I = \\int_{\Omega}\\!f(s)\\,dx
I = \\int_{\\Omega}\\!f(s)\\,dx
for where :math:`\Omega` is the domain.
for where :math:`\\Omega` is the domain.
Parameters
----------
Expand Down Expand Up @@ -533,14 +528,14 @@ def mass_form(u, v, w):

def bc_apply(self, M, boundary, zero=False):
"""
Adjusts the assemled finite element matrices to account for boundary conditons.
Adjusts the assembled finite element matrices to account for boundary conditions.
Parameters
----------
M: :class:`scipy.sparse.coo_matrix`
The assemled finite element matrix to adjust.
The assembled finite element matrix to adjust.
boundary: :class:`numpy.array`
Array of the indicies which correspond to the boundary.
Array of the indices which correspond to the boundary.
zero: bool, optional
If True, the rows of M given by the indicies in boundary are set to zero.
If False, the diagonal element is set to one. default is False.
Expand Down
8 changes: 0 additions & 8 deletions pybamm/spatial_methods/spatial_method.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#
# A general spatial method class
#
import pybamm
import numpy as np
from scipy.sparse import eye, kron, coo_matrix, csr_matrix, vstack
Expand All @@ -13,11 +10,6 @@ class SpatialMethod:
All spatial methods will follow the general form of SpatialMethod in
that they contain a method for broadcasting variables onto a mesh,
a gradient operator, and a divergence operator.
Parameters
----------
mesh : :class: `pybamm.Mesh`
Contains all the submeshes for discretisation
"""

def __init__(self, options=None):
Expand Down

0 comments on commit 78b7d25

Please sign in to comment.