def discharge_times_and_errors(compute): savefile = "capacitance_times_and_errors.pickle" if compute: try: with open(savefile, "rb") as f: models_times_and_voltages = pickle.load(f) except FileNotFoundError: models_times_and_voltages = pybamm.get_infinite_nested_dict() models = [ pybamm.lead_acid.Full(name="direct form"), pybamm.lead_acid.Full( {"surface form": "differential"}, name="capacitance form\n(differential)", ), pybamm.lead_acid.Full({"surface form": "algebraic"}, name="capacitance form\n(algebraic)"), ] Crates = [1] all_npts = np.linspace(10, 100, 2) t_eval = np.linspace(0, 1, 100) new_models_times_and_voltages = convergence_study( models, Crates, all_npts, t_eval) models_times_and_voltages.update(new_models_times_and_voltages) with open(savefile, "wb") as f: pickle.dump(models_times_and_voltages, f, pickle.HIGHEST_PROTOCOL) else: try: with open(savefile, "rb") as f: models_times_and_voltages = pickle.load(f) except FileNotFoundError: raise FileNotFoundError( "Run script with '--compute' first to generate results") plot_errors(models_times_and_voltages)
def discharge_times_and_errors(compute): savefile = "discharge_asymptotics_times_and_errors.pickle" if compute: try: with open(savefile, "rb") as f: models_times_and_voltages = pickle.load(f) except FileNotFoundError: models_times_and_voltages = pybamm.get_infinite_nested_dict() models = [ pybamm.lead_acid.Full({"surface form": "algebraic"}, name="Full"), pybamm.lead_acid.LOQS(name="LOQS"), # pybamm.lead_acid.FOQS(name="FOQS"), # pybamm.lead_acid.Composite(name="Composite"), ] Crates = np.linspace(0.01, 5, 2) all_npts = [20] t_eval = np.linspace(0, 1, 100) new_models_times_and_voltages = convergence_study( models, Crates, all_npts, t_eval) models_times_and_voltages.update(new_models_times_and_voltages) with open(savefile, "wb") as f: pickle.dump(models_times_and_voltages, f, pickle.HIGHEST_PROTOCOL) else: try: with open(savefile, "rb") as f: models_times_and_voltages = pickle.load(f) except FileNotFoundError: raise FileNotFoundError( "Run script with '--compute' first to generate results") plot_errors(models_times_and_voltages) plot_times(models_times_and_voltages)
def test_infinite_nested_dict(self): d = pybamm.get_infinite_nested_dict() d[1][2][3] = "x" self.assertEqual(d[1][2][3], "x") d[4][5] = "y" self.assertEqual(d[4][5], "y")