def test_mass_matrix_inverse(self): # get mesh mesh = get_2p1d_mesh_for_testing(ypts=5, zpts=5) spatial_methods = { "macroscale": pybamm.FiniteVolume(), "current collector": pybamm.ScikitFiniteElement(), } # create model a = pybamm.Variable("a", domain="negative electrode") b = pybamm.Variable("b", domain="current collector") model = pybamm.BaseModel() model.rhs = {a: pybamm.Laplacian(a), b: 4 * pybamm.Laplacian(b)} model.initial_conditions = {a: pybamm.Scalar(3), b: pybamm.Scalar(10)} model.boundary_conditions = { a: {"left": (0, "Neumann"), "right": (0, "Neumann")}, b: {"negative tab": (0, "Neumann"), "positive tab": (0, "Neumann")}, } model.variables = {"a": a, "b": b} # create discretisation disc = pybamm.Discretisation(mesh, spatial_methods) disc.process_model(model) # test that computing mass matrix block-by-block (as is done during # discretisation) gives the correct result # Note: inverse is more efficient in csc format mass_inv = inv(csc_matrix(model.mass_matrix.entries)) np.testing.assert_equal( model.mass_matrix_inv.entries.toarray(), mass_inv.toarray() )
def test_evaluates_on_edges(self): a = pybamm.StateVector(slice(0, 10), domain="test") self.assertFalse(pybamm.Index(a, slice(1)).evaluates_on_edges("primary")) self.assertFalse(pybamm.Laplacian(a).evaluates_on_edges("primary")) self.assertFalse(pybamm.GradientSquared(a).evaluates_on_edges("primary")) self.assertFalse(pybamm.BoundaryIntegral(a).evaluates_on_edges("primary")) self.assertTrue(pybamm.Upwind(a).evaluates_on_edges("primary")) self.assertTrue(pybamm.Downwind(a).evaluates_on_edges("primary"))
def test_evaluates_on_edges(self): a = pybamm.StateVector(slice(0, 10)) self.assertFalse(a[1].evaluates_on_edges()) self.assertFalse(pybamm.Laplacian(a).evaluates_on_edges())