diff --git a/pybamm/plotting/quick_plot.py b/pybamm/plotting/quick_plot.py index 5f22365adc..0643f3a1a6 100644 --- a/pybamm/plotting/quick_plot.py +++ b/pybamm/plotting/quick_plot.py @@ -314,11 +314,9 @@ def set_output_variables(self, output_variables, solutions): ) = self.get_spatial_var(variable_tuple, first_variable, "first") self.spatial_variable_dict[variable_tuple] = { spatial_var_name: spatial_var_value - * spatial_scale - / self.spatial_factor } self.first_scaled_spatial_variable[variable_tuple] = ( - spatial_var_value * spatial_scale + spatial_var_value * self.spatial_factor ) self.first_spatial_scale[variable_tuple] = spatial_scale @@ -343,18 +341,14 @@ def set_output_variables(self, output_variables, solutions): second_spatial_scale, ) = self.get_spatial_var(variable_tuple, first_variable, "second") self.spatial_variable_dict[variable_tuple] = { - first_spatial_var_name: first_spatial_var_value - * first_spatial_scale - / self.spatial_factor, - second_spatial_var_name: second_spatial_var_value - * second_spatial_scale - / self.spatial_factor, + first_spatial_var_name: first_spatial_var_value, + second_spatial_var_name: second_spatial_var_value, } self.first_scaled_spatial_variable[variable_tuple] = ( - first_spatial_var_value * first_spatial_scale + first_spatial_var_value * self.spatial_factor ) self.second_scaled_spatial_variable[variable_tuple] = ( - second_spatial_var_value * second_spatial_scale + second_spatial_var_value * self.spatial_factor ) if first_spatial_var_name == "r" and second_spatial_var_name == "x": self.is_x_r[variable_tuple] = True @@ -383,15 +377,11 @@ def get_spatial_var(self, key, variable, dimension): else: domain = variable.auxiliary_domains["secondary"][0] - # Remove subscript "n" or "p" so spatial_var_name can be used in the - # call to a `ProcessedVariable` - if spatial_var_name in ["r_n", "r_p"]: - spatial_var_name = "r" - if domain == "current collector": domain += " {}".format(spatial_var_name) - # Get scale + # Get scale to go from dimensionless to dimensional in the units + # specified by spatial_unit try: spatial_scale = self.spatial_scales[domain] except KeyError: diff --git a/pybamm/solvers/processed_variable.py b/pybamm/solvers/processed_variable.py index 33f288abba..5954923caa 100644 --- a/pybamm/solvers/processed_variable.py +++ b/pybamm/solvers/processed_variable.py @@ -146,7 +146,7 @@ def initialise_0D(self): else: entries[idx] = self.base_variable.evaluate(t, u, inputs=inputs) - # No discretisation provided, or variable has no domain (function of t only) + # set up interpolation if len(self.t_sol) == 1: # Variable is just a scalar value, but we need to create a callable # function to be consitent with other processed variables @@ -205,11 +205,8 @@ def initialise_1D(self, fixed_t=False): # assign attributes for reference (either x_sol or r_sol) self.entries = entries self.dimensions = 1 - if self.domain[0] == "negative particle": - self.first_dimension = "r_n" - self.r_sol = space - elif self.domain[0] == "positive particle": - self.first_dimension = "r_p" + if self.domain[0] in ["negative particle", "positive particle"]: + self.first_dimension = "r" self.r_sol = space elif self.domain[0] in [ "negative electrode", @@ -225,7 +222,10 @@ def initialise_1D(self, fixed_t=False): self.first_dimension = "x" self.x_sol = space - self.first_dim_pts = space * self.get_spatial_scale(self.first_dimension) + # assign attributes for reference + self.first_dim_pts = space * self.get_spatial_scale( + self.first_dimension, self.domain[0] + ) self.internal_boundaries = self.mesh[0].internal_boundaries # set up interpolation @@ -278,10 +278,7 @@ def initialise_2D(self): "negative electrode", "positive electrode", ]: - if self.domain[0] == "negative particle": - self.first_dimension = "r_n" - elif self.domain[0] == "positive particle": - self.first_dimension = "r_p" + self.first_dimension = "r" self.second_dimension = "x" self.r_sol = first_dim_pts self.x_sol = second_dim_pts @@ -330,7 +327,7 @@ def initialise_2D(self): self.entries = entries self.dimensions = 2 self.first_dim_pts = first_dim_pts * self.get_spatial_scale( - self.first_dimension + self.first_dimension, self.domain[0] ) self.second_dim_pts = second_dim_pts * self.get_spatial_scale( self.second_dimension @@ -481,8 +478,15 @@ def call_2D(self, t, x, r, y, z): second_dim = second_dim[:, np.newaxis] return self._interpolation_function((first_dim, second_dim, t)) - def get_spatial_scale(self, name): + def get_spatial_scale(self, name, domain=None): "Returns the spatial scale for a named spatial variable" + # Different scale in negative and positive particles + if domain == "negative particle": + name = "r_n" + elif domain == "positive particle": + name = "r_p" + + # Try to get length scale if name + " [m]" in self.spatial_vars and name in self.spatial_vars: scale = ( self.spatial_vars[name + " [m]"] / self.spatial_vars[name] @@ -505,8 +509,7 @@ def data(self): def eval_dimension_name(name, x, r, y, z): if name == "x": out = x - elif name in ["r_n", "r_p"]: - name = "r" # remove subscript to match input name in case of error + elif name == "r": out = r elif name == "y": out = y diff --git a/tests/integration/test_models/standard_output_tests.py b/tests/integration/test_models/standard_output_tests.py index 8290a65055..f985de5150 100644 --- a/tests/integration/test_models/standard_output_tests.py +++ b/tests/integration/test_models/standard_output_tests.py @@ -629,14 +629,16 @@ def __init__(self, model, param, disc, solution, operating_condition): def test_velocity_boundaries(self): """Test the boundary values of the current densities""" + L = self.v_box.first_dim_pts[-1] np.testing.assert_array_almost_equal(self.v_box(self.t, 0), 0, decimal=4) - np.testing.assert_array_almost_equal(self.v_box(self.t, 1), 0, decimal=4) + np.testing.assert_array_almost_equal(self.v_box(self.t, L), 0, decimal=4) def test_vertical_velocity(self): """Test the boundary values of the current densities""" + L = self.v_box.first_dim_pts[-1] np.testing.assert_array_equal(self.dVbox_dz(self.t, 0), 0) - np.testing.assert_array_less(self.dVbox_dz(self.t, 0.5), 0) - np.testing.assert_array_equal(self.dVbox_dz(self.t, 1), 0) + np.testing.assert_array_less(self.dVbox_dz(self.t, 0.5 * L), 0) + np.testing.assert_array_equal(self.dVbox_dz(self.t, L), 0) def test_velocity_vs_current(self): """Test the boundary values of the current densities"""