From 16fd8c008c1b33035b130e2ccd225a71e258ab1b Mon Sep 17 00:00:00 2001 From: Robert Timms Date: Mon, 30 Sep 2019 12:01:30 +0100 Subject: [PATCH] #617 flake8 --- pybamm/geometry/geometry.py | 13 ++++----- pybamm/meshes/meshes.py | 18 +++--------- .../full_battery_models/base_battery_model.py | 12 ++------ pybamm/models/standard_variables.py | 6 ++-- .../effective_resistance_current_collector.py | 4 +-- .../base_electrolyte_conductivity.py | 3 +- .../standard_parameters_lithium_ion.py | 4 +-- pybamm/processed_variable.py | 6 ++-- pybamm/solvers/base_solver.py | 6 ++-- pybamm/solvers/scikits_dae_solver.py | 2 +- pybamm/solvers/scikits_ode_solver.py | 2 +- pybamm/solvers/scipy_solver.py | 8 +----- tests/shared.py | 9 ++---- tests/unit/test_meshes/test_meshes.py | 28 +++++-------------- .../test_meshes/test_scikit_fem_submesh.py | 16 +++-------- .../test_base_battery_model.py | 3 +- .../test_lead_acid/test_loqs.py | 3 +- 17 files changed, 41 insertions(+), 102 deletions(-) diff --git a/pybamm/geometry/geometry.py b/pybamm/geometry/geometry.py index bb7389b8c3..4d38bd3bb9 100644 --- a/pybamm/geometry/geometry.py +++ b/pybamm/geometry/geometry.py @@ -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(): @@ -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}) diff --git a/pybamm/meshes/meshes.py b/pybamm/meshes/meshes.py index 7e500a50d0..3eb7a7317b 100644 --- a/pybamm/meshes/meshes.py +++ b/pybamm/meshes/meshes.py @@ -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): @@ -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: @@ -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 ) diff --git a/pybamm/models/full_battery_models/base_battery_model.py b/pybamm/models/full_battery_models/base_battery_model.py index db51d42db9..b7b0792e92 100644 --- a/pybamm/models/full_battery_models/base_battery_model.py +++ b/pybamm/models/full_battery_models/base_battery_model.py @@ -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 diff --git a/pybamm/models/standard_variables.py b/pybamm/models/standard_variables.py index 277aeebe73..64636416c5 100644 --- a/pybamm/models/standard_variables.py +++ b/pybamm/models/standard_variables.py @@ -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" ) diff --git a/pybamm/models/submodels/current_collector/effective_resistance_current_collector.py b/pybamm/models/submodels/current_collector/effective_resistance_current_collector.py index ab12982a5d..80ad85dbd8 100644 --- a/pybamm/models/submodels/current_collector/effective_resistance_current_collector.py +++ b/pybamm/models/submodels/current_collector/effective_resistance_current_collector.py @@ -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): diff --git a/pybamm/models/submodels/electrolyte/base_electrolyte_conductivity.py b/pybamm/models/submodels/electrolyte/base_electrolyte_conductivity.py index 47c6f69890..7d685dc7fe 100644 --- a/pybamm/models/submodels/electrolyte/base_electrolyte_conductivity.py +++ b/pybamm/models/submodels/electrolyte/base_electrolyte_conductivity.py @@ -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, diff --git a/pybamm/parameters/standard_parameters_lithium_ion.py b/pybamm/parameters/standard_parameters_lithium_ion.py index c39939b370..1f9f9894c5 100644 --- a/pybamm/parameters/standard_parameters_lithium_ion.py +++ b/pybamm/parameters/standard_parameters_lithium_ion.py @@ -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 diff --git a/pybamm/processed_variable.py b/pybamm/processed_variable.py index 0e36774780..2e6507459f 100644 --- a/pybamm/processed_variable.py +++ b/pybamm/processed_variable.py @@ -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) diff --git a/pybamm/solvers/base_solver.py b/pybamm/solvers/base_solver.py index eb4a93e224..ae15aacdba 100644 --- a/pybamm/solvers/base_solver.py +++ b/pybamm/solvers/base_solver.py @@ -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 @@ -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 diff --git a/pybamm/solvers/scikits_dae_solver.py b/pybamm/solvers/scikits_dae_solver.py index 0ed22a1030..bf82af9979 100644 --- a/pybamm/solvers/scikits_dae_solver.py +++ b/pybamm/solvers/scikits_dae_solver.py @@ -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) diff --git a/pybamm/solvers/scikits_ode_solver.py b/pybamm/solvers/scikits_ode_solver.py index 17cfff62a0..bbeed30ccd 100644 --- a/pybamm/solvers/scikits_ode_solver.py +++ b/pybamm/solvers/scikits_ode_solver.py @@ -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) diff --git a/pybamm/solvers/scipy_solver.py b/pybamm/solvers/scipy_solver.py index 60e3db9ac5..07f133a2b8 100644 --- a/pybamm/solvers/scipy_solver.py +++ b/pybamm/solvers/scipy_solver.py @@ -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) diff --git a/tests/shared.py b/tests/shared.py index 5cd52df946..23e77c9dfa 100644 --- a/tests/shared.py +++ b/tests/shared.py @@ -95,9 +95,7 @@ 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 @@ -105,10 +103,7 @@ def get_1p1d_mesh_for_testing( 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( diff --git a/tests/unit/test_meshes/test_meshes.py b/tests/unit/test_meshes/test_meshes.py index 8841b4019d..7012c1813c 100644 --- a/tests/unit/test_meshes/test_meshes.py +++ b/tests/unit/test_meshes/test_meshes.py @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/tests/unit/test_meshes/test_scikit_fem_submesh.py b/tests/unit/test_meshes/test_scikit_fem_submesh.py index ba75f6c70b..c74d5a1083 100644 --- a/tests/unit/test_meshes/test_scikit_fem_submesh.py +++ b/tests/unit/test_meshes/test_scikit_fem_submesh.py @@ -320,9 +320,7 @@ 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 = { @@ -330,9 +328,7 @@ def test_init_failure(self): 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 = { @@ -340,9 +336,7 @@ def test_init_failure(self): 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): @@ -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 diff --git a/tests/unit/test_models/test_full_battery_models/test_base_battery_model.py b/tests/unit/test_models/test_full_battery_models/test_base_battery_model.py index 60cdb8ba23..f85513f1d1 100644 --- a/tests/unit/test_models/test_full_battery_models/test_base_battery_model.py +++ b/tests/unit/test_models/test_full_battery_models/test_base_battery_model.py @@ -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}) diff --git a/tests/unit/test_models/test_full_battery_models/test_lead_acid/test_loqs.py b/tests/unit/test_models/test_full_battery_models/test_lead_acid/test_loqs.py index 5628cc72f2..01ae5c0ca3 100644 --- a/tests/unit/test_models/test_full_battery_models/test_lead_acid/test_loqs.py +++ b/tests/unit/test_models/test_full_battery_models/test_lead_acid/test_loqs.py @@ -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(