def test_discretise_spatial_variable(self): # create discretisation mesh = get_mesh_for_testing() spatial_method = pybamm.SpatialMethod() spatial_method.build(mesh) # centre x1 = pybamm.SpatialVariable("x", ["negative electrode"]) x2 = pybamm.SpatialVariable("x", ["negative electrode", "separator"]) r = pybamm.SpatialVariable("r", ["negative particle"]) for var in [x1, x2, r]: var_disc = spatial_method.spatial_variable(var) self.assertIsInstance(var_disc, pybamm.Vector) np.testing.assert_array_equal( var_disc.evaluate()[:, 0], mesh.combine_submeshes(*var.domain)[0].nodes ) # edges x1_edge = pybamm.SpatialVariableEdge("x", ["negative electrode"]) x2_edge = pybamm.SpatialVariableEdge("x", ["negative electrode", "separator"]) r_edge = pybamm.SpatialVariableEdge("r", ["negative particle"]) for var in [x1_edge, x2_edge, r_edge]: var_disc = spatial_method.spatial_variable(var) self.assertIsInstance(var_disc, pybamm.Vector) np.testing.assert_array_equal( var_disc.evaluate()[:, 0], mesh.combine_submeshes(*var.domain)[0].edges )
def get_error(n): # create mesh and discretisation (single particle) mesh = get_mesh_for_testing(rpts=n) disc = pybamm.Discretisation(mesh, spatial_methods) submesh = mesh["negative particle"] r = submesh.nodes r_edge = pybamm.SpatialVariableEdge("r_n", domain=["negative particle"]) # Define flux and bcs N = r_edge * pybamm.sin(r_edge) div_eqn = pybamm.div(N) # Define exact solutions # N = r*sin(r) --> div(N) = 3*sin(r) + r*cos(r) div_exact = 3 * np.sin(r) + r * np.cos(r) # Discretise and evaluate div_eqn_disc = disc.process_symbol(div_eqn) div_approx = div_eqn_disc.evaluate() # Return difference between approx and exact return div_approx[:, 0] - div_exact
coord_sys="spherical polar", ) r_p = pybamm.SpatialVariable( "r_p", domain=["positive particle"], auxiliary_domains={ "secondary": "positive electrode", "tertiary": "current collector", }, coord_sys="spherical polar", ) # Domains at cell edges x_n_edge = pybamm.SpatialVariableEdge( "x_n", domain=["negative electrode"], auxiliary_domains={"secondary": "current collector"}, coord_sys="cartesian", ) x_s_edge = pybamm.SpatialVariableEdge( "x_s", domain=["separator"], auxiliary_domains={"secondary": "current collector"}, coord_sys="cartesian", ) x_p_edge = pybamm.SpatialVariableEdge( "x_p", domain=["positive electrode"], auxiliary_domains={"secondary": "current collector"}, coord_sys="cartesian", ) x_edge = pybamm.SpatialVariableEdge(
coord_sys="cartesian") r_w = pybamm.SpatialVariable( "r_w", domain=["working particle"], auxiliary_domains={ "secondary": "working electrode", "tertiary": "current collector", }, coord_sys="spherical polar", ) # Domains at cell edges x_Li_edge = pybamm.SpatialVariableEdge( "x_Li", domain=["lithium counter electrode"], auxiliary_domains={"secondary": "current collector"}, coord_sys="cartesian", ) x_s_edge = pybamm.SpatialVariableEdge( "x_s", domain=["separator"], auxiliary_domains={"secondary": "current collector"}, coord_sys="cartesian", ) x_w_edge = pybamm.SpatialVariableEdge( "x_w", domain=["working electrode"], auxiliary_domains={"secondary": "current collector"}, coord_sys="cartesian", ) x_edge = pybamm.SpatialVariableEdge(
def test_spatial_variable_edge(self): x = pybamm.SpatialVariableEdge("x", "negative electrode") self.assertEqual(x.name, "x") self.assertTrue(x.evaluates_on_edges("primary"))