Repository: tinosulzer/PyBaMM

Issue:
Add a process_variables in discretisation
**Summary**
Currently we process model.variables using process_dict. But if this evaluates to a number then we eqn_key.domain is used. This is fine for rhs, etc but for variables  the keys are strings and so have no attribute of this type. 
For model.variables it is probably fine to just output the number instead of broadcasting to a domain so we could just skip this step



Discussion:

Patch:
diff --git a/pybamm/discretisations/discretisation.py b/pybamm/discretisations/discretisation.py
index 78bed05e..14d7e507 100644
--- a/pybamm/discretisations/discretisation.py
+++ b/pybamm/discretisations/discretisation.py
@@ -166,7 +166,9 @@ class Discretisation(object):
         for eqn_key, eqn in var_eqn_dict.items():
 
             if eqn.evaluates_to_number():
-                if eqn_key.domain == []:
+                if isinstance(eqn_key, str):
+                    eqn = pybamm.NumpyBroadcast(eqn, [], {})
+                elif eqn_key.domain == []:
                     eqn = pybamm.NumpyBroadcast(eqn, eqn_key.domain, {})
                 else:
                     eqn = self._spatial_methods[eqn_key.domain[0]].broadcast(


Test patch:
diff --git a/tests/test_discretisations/test_base_discretisations.py b/tests/test_discretisations/test_discretisation.py
similarity index 98%
rename from tests/test_discretisations/test_base_discretisations.py
rename to tests/test_discretisations/test_discretisation.py
index c3006a23..938b6174 100644
--- a/tests/test_discretisations/test_base_discretisations.py
+++ b/tests/test_discretisations/test_discretisation.py
@@ -286,6 +286,15 @@ class TestDiscretise(unittest.TestCase):
             y0[T].evaluate(0, None), 5 * np.ones_like(mesh["negative electrode"].nodes)
         )
 
+    def test_process_variables_dict(self):
+        # want to check the case where the keys are strings and
+        # and the equation evals to a number
+
+        variables = {"c": pybamm.Scalar(0)}
+
+        disc = get_discretisation_for_testing()
+        disc.process_dict(variables)
+
     def test_process_model_ode(self):
         # one equation
         whole_cell = ["negative electrode", "separator", "positive electrode"]