Skip to content

Commit

Permalink
#617 flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
rtimms committed Sep 30, 2019
1 parent 8df1cb4 commit 16fd8c0
Show file tree
Hide file tree
Showing 17 changed files with 41 additions and 102 deletions.
13 changes: 5 additions & 8 deletions pybamm/geometry/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ def add_domain(self, name, geometry):
for k, v in geometry.items():
if k not in ["primary", "secondary", "tabs"]:
raise ValueError(
"keys of geometry must be either \"primary\", \"secondary\" or "
"\"tabs\""
'keys of geometry must be either "primary", "secondary" or '
'"tabs"'
)
if k != "tabs":
for variable, rnge in v.items():
Expand All @@ -135,15 +135,12 @@ def add_domain(self, name, geometry):
else:
for region, params in v.items():
if region not in ["negative", "positive"]:
raise ValueError(
"tabs region must be \"negative\" or \"positive\""

)
raise ValueError('tabs region must be "negative" or "positive"')
for pname in params.keys():
if pname not in ["y_centre", "z_centre", "width"]:
raise ValueError(
"tabs region params must be \"y_centre\", "
"\"z_centre\" or \"width\""
'tabs region params must be "y_centre", '
'"z_centre" or "width"'
)

self.update({name: geometry})
Expand Down
18 changes: 4 additions & 14 deletions pybamm/meshes/meshes.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ def combine_submeshes(self, *submeshnames):
+ [self[submeshname][i].edges[1:] for submeshname in submeshnames[1:]]
)
coord_sys = self[submeshnames[0]][i].coord_sys
submeshes[i] = pybamm.SubMesh1D(
combined_submesh_edges, coord_sys
)
submeshes[i] = pybamm.SubMesh1D(combined_submesh_edges, coord_sys)
return submeshes

def add_ghost_meshes(self):
Expand All @@ -176,11 +174,7 @@ def add_ghost_meshes(self):
(domain, submesh_list)
for domain, submesh_list in self.items()
if not isinstance(
submesh_list[0],
(
pybamm.SubMesh0D,
pybamm.ScikitSubMesh2D,
),
submesh_list[0], (pybamm.SubMesh0D, pybamm.ScikitSubMesh2D)
)
]
for domain, submesh_list in submeshes:
Expand All @@ -192,17 +186,13 @@ def add_ghost_meshes(self):

# left ghost cell: two edges, one node, to the left of existing submesh
lgs_edges = np.array([2 * edges[0] - edges[1], edges[0]])
self[domain + "_left ghost cell"][
i
] = pybamm.SubMesh1D(
self[domain + "_left ghost cell"][i] = pybamm.SubMesh1D(
lgs_edges, submesh.coord_sys
)

# right ghost cell: two edges, one node, to the right of
# existing submesh
rgs_edges = np.array([edges[-1], 2 * edges[-1] - edges[-2]])
self[domain + "_right ghost cell"][
i
] = pybamm.SubMesh1D(
self[domain + "_right ghost cell"][i] = pybamm.SubMesh1D(
rgs_edges, submesh.coord_sys
)
12 changes: 3 additions & 9 deletions pybamm/models/full_battery_models/base_battery_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,11 @@ def default_submesh_types(self):
"positive particle": pybamm.Uniform1DSubMesh,
}
if self.options["dimensionality"] == 0:
base_submeshes[
"current collector"
] = pybamm.SubMesh0D
base_submeshes["current collector"] = pybamm.SubMesh0D
elif self.options["dimensionality"] == 1:
base_submeshes[
"current collector"
] = pybamm.Uniform1DSubMesh
base_submeshes["current collector"] = pybamm.Uniform1DSubMesh
elif self.options["dimensionality"] == 2:
base_submeshes[
"current collector"
] = pybamm.ScikitUniform2DSubMesh
base_submeshes["current collector"] = pybamm.ScikitUniform2DSubMesh
return base_submeshes

@property
Expand Down
6 changes: 2 additions & 4 deletions pybamm/models/standard_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,10 @@
auxiliary_domains={"secondary": "current collector"},
)
c_s_n_surf_xav = pybamm.Variable(
"X-averaged negative particle surface concentration",
"current collector",
"X-averaged negative particle surface concentration", "current collector"
)
c_s_p_surf_xav = pybamm.Variable(
"X-averaged positive particle surface concentration",
"current collector",
"X-averaged positive particle surface concentration", "current collector"
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,7 @@ def default_var_pts(self):

@property
def default_submesh_types(self):
return {
"current collector": pybamm.ScikitUniform2DSubMesh
}
return {"current collector": pybamm.ScikitUniform2DSubMesh}

@property
def default_spatial_methods(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ def _get_standard_potential_variables(self, phi_e, phi_e_av):
"Positive electrolyte potential": phi_e_p,
"Positive electrolyte potential [V]": -param.U_n_ref + pot_scale * phi_e_p,
"Electrolyte potential": phi_e,
"Electrolyte potential [V]": -param.U_n_ref
+ pot_scale * phi_e,
"Electrolyte potential [V]": -param.U_n_ref + pot_scale * phi_e,
"X-averaged electrolyte potential": phi_e_av,
"X-averaged electrolyte potential [V]": -param.U_n_ref
+ pot_scale * phi_e_av,
Expand Down
4 changes: 1 addition & 3 deletions pybamm/parameters/standard_parameters_lithium_ion.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,7 @@ def U_p_dimensional(sto, T):
sigma_cn_dbl_prime = sigma_cn_prime * delta
sigma_cp_dbl_prime = sigma_cp_prime * delta
# should rename this to avoid confusion with Butler-Volmer
alpha = 1 / (sigma_cn * delta ** 2 * l_cn) + 1 / (
sigma_cp * delta ** 2 * l_cp
)
alpha = 1 / (sigma_cn * delta ** 2 * l_cn) + 1 / (sigma_cp * delta ** 2 * l_cp)
alpha_prime = alpha / delta

# Electrolyte Properties
Expand Down
6 changes: 4 additions & 2 deletions pybamm/processed_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ def __init__(
self.base_eval = base_variable.evaluate(t_sol[0], u_sol[:, 0])

# handle 2D (in space) finite element variables differently
if mesh and "current collector" in self.domain and isinstance(
self.mesh[self.domain[0]][0], pybamm.ScikitSubMesh2D
if (
mesh
and "current collector" in self.domain
and isinstance(self.mesh[self.domain[0]][0], pybamm.ScikitSubMesh2D)
):
if len(self.t_sol) == 1:
# space only (steady solution)
Expand Down
6 changes: 2 additions & 4 deletions pybamm/solvers/base_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def step(self, model, dt, npts=2):
timer = pybamm.Timer()

# Run set up on first step
if not hasattr(self, 'y0'):
if not hasattr(self, "y0"):
start_time = timer.time()
self.set_up(model)
self.t = 0.0
Expand Down Expand Up @@ -130,9 +130,7 @@ def step(self, model, dt, npts=2):
)
else:
pybamm.logger.info(
"Step time: {}".format(
timer.format(solution.solve_time),
)
"Step time: {}".format(timer.format(solution.solve_time))
)
return solution

Expand Down
2 changes: 1 addition & 1 deletion pybamm/solvers/scikits_dae_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def jacfn(t, y, ydot, residuals, cj, J):
np.transpose(sol.values.y),
sol.roots.t,
np.transpose(sol.roots.y),
termination
termination,
)
else:
raise pybamm.SolverError(sol.message)
2 changes: 1 addition & 1 deletion pybamm/solvers/scikits_ode_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def jac_times_setupfn(t, y, fy, userdata):
np.transpose(sol.values.y),
sol.roots.t,
np.transpose(sol.roots.y),
termination
termination,
)
else:
raise pybamm.SolverError(sol.message)
8 changes: 1 addition & 7 deletions pybamm/solvers/scipy_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,6 @@ def integrate(
termination = "final time"
t_event = None
y_event = np.array(None)
return pybamm.Solution(
sol.t,
sol.y,
t_event,
y_event,
termination
)
return pybamm.Solution(sol.t, sol.y, t_event, y_event, termination)
else:
raise pybamm.SolverError(sol.message)
9 changes: 2 additions & 7 deletions tests/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,15 @@ def get_p2d_mesh_for_testing(xpts=None, rpts=10):
return get_mesh_for_testing(xpts=xpts, rpts=rpts, geometry=geometry)


def get_1p1d_mesh_for_testing(
xpts=None, zpts=15, cc_submesh=pybamm.Uniform1DSubMesh
):
def get_1p1d_mesh_for_testing(xpts=None, zpts=15, cc_submesh=pybamm.Uniform1DSubMesh):
geometry = pybamm.Geometry("1+1D macro")
return get_mesh_for_testing(
xpts=xpts, zpts=zpts, geometry=geometry, cc_submesh=cc_submesh
)


def get_2p1d_mesh_for_testing(
xpts=None,
ypts=15,
zpts=15,
cc_submesh=pybamm.ScikitUniform2DSubMesh,
xpts=None, ypts=15, zpts=15, cc_submesh=pybamm.ScikitUniform2DSubMesh
):
geometry = pybamm.Geometry("2+1D macro")
return get_mesh_for_testing(
Expand Down
28 changes: 7 additions & 21 deletions tests/unit/test_meshes/test_meshes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ def test_mesh_creation_no_parameters(self):
}
}

submesh_types = {
"negative particle": pybamm.Uniform1DSubMesh
}
submesh_types = {"negative particle": pybamm.Uniform1DSubMesh}
var_pts = {r: 20}
mesh = pybamm.Mesh(geometry, submesh_types, var_pts)

Expand Down Expand Up @@ -282,14 +280,8 @@ def test_multiple_meshes(self):
self.assertEqual(len(mesh["positive particle"]), 10)

for i in range(10):
self.assertIsInstance(
mesh["negative particle"][i],
pybamm.Uniform1DSubMesh,
)
self.assertIsInstance(
mesh["positive particle"][i],
pybamm.Uniform1DSubMesh,
)
self.assertIsInstance(mesh["negative particle"][i], pybamm.Uniform1DSubMesh)
self.assertIsInstance(mesh["positive particle"][i], pybamm.Uniform1DSubMesh)
self.assertEqual(mesh["negative particle"][i].npts, 5)
self.assertEqual(mesh["positive particle"][i].npts, 6)

Expand Down Expand Up @@ -330,15 +322,11 @@ def test_multiple_meshes_macro(self):

for i in range(5):
self.assertIsInstance(
mesh["negative electrode"][i],
pybamm.Uniform1DSubMesh,
)
self.assertIsInstance(
mesh["separator"][i], pybamm.Uniform1DSubMesh
mesh["negative electrode"][i], pybamm.Uniform1DSubMesh
)
self.assertIsInstance(mesh["separator"][i], pybamm.Uniform1DSubMesh)
self.assertIsInstance(
mesh["positive electrode"][i],
pybamm.Uniform1DSubMesh,
mesh["positive electrode"][i], pybamm.Uniform1DSubMesh
)
self.assertEqual(mesh["negative electrode"][i].npts, 10)
self.assertEqual(mesh["separator"][i].npts, 15)
Expand Down Expand Up @@ -386,9 +374,7 @@ def test_unimplemented_meshes(self):
"primary": {var.x_n: {"min": 0, "max": 1}, var.y: {"min": 0, "max": 1}}
}
}
submesh_types = {
"negative electrode": pybamm.Uniform1DSubMesh
}
submesh_types = {"negative electrode": pybamm.Uniform1DSubMesh}
with self.assertRaises(pybamm.GeometryError):
pybamm.Mesh(geometry, submesh_types, var_pts)

Expand Down
16 changes: 4 additions & 12 deletions tests/unit/test_meshes/test_scikit_fem_submesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,29 +320,23 @@ def test_init_failure(self):
# only one lim
lims = {var.x_n: {"min": pybamm.Scalar(0), "max": pybamm.Scalar(1)}}
with self.assertRaises(pybamm.GeometryError):
pybamm.ScikitTopExponential2DSubMesh(
lims, None, None
)
pybamm.ScikitTopExponential2DSubMesh(lims, None, None)

# different coord_sys
lims = {
var.r_n: {"min": pybamm.Scalar(0), "max": pybamm.Scalar(1)},
var.z: {"min": pybamm.Scalar(0), "max": pybamm.Scalar(1)},
}
with self.assertRaises(pybamm.DomainError):
pybamm.ScikitTopExponential2DSubMesh(
lims, None, None
)
pybamm.ScikitTopExponential2DSubMesh(lims, None, None)

# not y and z
lims = {
var.x_n: {"min": pybamm.Scalar(0), "max": pybamm.Scalar(1)},
var.z: {"min": pybamm.Scalar(0), "max": pybamm.Scalar(1)},
}
with self.assertRaises(pybamm.DomainError):
pybamm.ScikitTopExponential2DSubMesh(
lims, None, None
)
pybamm.ScikitTopExponential2DSubMesh(lims, None, None)


class TestScikitUser2DSubMesh(unittest.TestCase):
Expand Down Expand Up @@ -376,9 +370,7 @@ def test_mesh_creation(self):
"negative electrode": pybamm.Uniform1DSubMesh,
"separator": pybamm.Uniform1DSubMesh,
"positive electrode": pybamm.Uniform1DSubMesh,
"current collector": pybamm.GetUserSupplied2DSubMesh(
y_edges, z_edges
),
"current collector": pybamm.GetUserSupplied2DSubMesh(y_edges, z_edges),
}

mesh_type = pybamm.Mesh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ def test_default_submesh_types(self):
model = pybamm.BaseBatteryModel({"dimensionality": 0})
self.assertTrue(
issubclass(
model.default_submesh_types["current collector"],
pybamm.SubMesh0D,
model.default_submesh_types["current collector"], pybamm.SubMesh0D
)
)
model = pybamm.BaseBatteryModel({"dimensionality": 1})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ def test_defaults_dimensions(self):
)
self.assertTrue(
issubclass(
model.default_submesh_types["current collector"],
pybamm.SubMesh0D,
model.default_submesh_types["current collector"], pybamm.SubMesh0D
)
)
model = pybamm.lead_acid.LOQS(
Expand Down

0 comments on commit 16fd8c0

Please sign in to comment.