Skip to content

Commit

Permalink
#2599 add idaklu solver to benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjrobins committed Jan 10, 2023
1 parent fb36a84 commit f9a9fcc
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 96 deletions.
58 changes: 32 additions & 26 deletions benchmarks/different_model_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def build_model(parameter, model_, option, value):


class SolveModel:
def solve_setup(self, parameter, model_, option, value):
self.solver = pybamm.CasadiSolver()
def solve_setup(self, parameter, model_, option, value, solver_class):
self.solver = solver_class()
self.model = model_({option: value})
c_rate = 1
tmax = 4000 / c_rate
Expand Down Expand Up @@ -77,16 +77,17 @@ def time_setup_model(self, model, params):


class TimeSolveLossActiveMaterial:
param_names = ["model", "model option"]
param_names = ["model", "model option", "solver class"]
params = (
[pybamm.lithium_ion.SPM, pybamm.lithium_ion.DFN],
["none", "stress-driven", "reaction-driven", "stress and reaction-driven"],
[pybamm.CasadiSolver, pybamm.IDAKLUSolver],
)

def setup(self, model, params):
SolveModel.solve_setup(self, "Ai2020", model, "loss of active material", params)
def setup(self, model, params, solver_class):
SolveModel.solve_setup(self, "Ai2020", model, "loss of active material", params, solver_class)

def time_solve_model(self, model, params):
def time_solve_model(self, model, params, solver_class):
self.solver.solve(self.model, t_eval=self.t_eval)


Expand All @@ -102,16 +103,17 @@ def time_setup_model(self, model, params):


class TimeSolveLithiumPlating:
param_names = ["model", "model option"]
param_names = ["model", "model option", "solver class"]
params = (
[pybamm.lithium_ion.SPM, pybamm.lithium_ion.DFN],
["none", "irreversible", "reversible", "partially reversible"],
[pybamm.CasadiSolver, pybamm.IDAKLUSolver],
)

def setup(self, model, params):
SolveModel.solve_setup(self, "OKane2020", model, "lithium plating", params)
def setup(self, model, params, solver_class):
SolveModel.solve_setup(self, "OKane2020", model, "lithium plating", params, solver_class)

def time_solve_model(self, model, params):
def time_solve_model(self, model, params, solver_class):
self.solver.solve(self.model, t_eval=self.t_eval)


Expand All @@ -137,7 +139,7 @@ def time_setup_model(self, model, params):


class TimeSolveSEI:
param_names = ["model", "model option"]
param_names = ["model", "model option", "solver class"]
params = (
[pybamm.lithium_ion.SPM, pybamm.lithium_ion.DFN],
[
Expand All @@ -151,12 +153,13 @@ class TimeSolveSEI:
"ec reaction limited",
"ec reaction limited (asymmetric)",
],
[pybamm.CasadiSolver, pybamm.IDAKLUSolver],
)

def setup(self, model, params):
SolveModel.solve_setup(self, "Marquis2019", model, "SEI", params)
def setup(self, model, params, solver_class):
SolveModel.solve_setup(self, "Marquis2019", model, "SEI", params, solver_class)

def time_solve_model(self, model, params):
def time_solve_model(self, model, params, solver_class):
self.solver.solve(self.model, t_eval=self.t_eval)


Expand All @@ -177,7 +180,7 @@ def time_setup_model(self, model, params):


class TimeSolveParticle:
param_names = ["model", "model option"]
param_names = ["model", "model option", "solver class"]
params = (
[pybamm.lithium_ion.SPM, pybamm.lithium_ion.DFN],
[
Expand All @@ -186,12 +189,13 @@ class TimeSolveParticle:
"quadratic profile",
"quartic profile",
],
[pybamm.CasadiSolver, pybamm.IDAKLUSolver],
)

def setup(self, model, params):
SolveModel.solve_setup(self, "Marquis2019", model, "particle", params)
def setup(self, model, params, solver_class):
SolveModel.solve_setup(self, "Marquis2019", model, "particle", params, solver_class)

def time_solve_model(self, model, params):
def time_solve_model(self, model, params, solver_class):
self.solver.solve(self.model, t_eval=self.t_eval)


Expand All @@ -207,16 +211,17 @@ def time_setup_model(self, model, params):


class TimeSolveThermal:
param_names = ["model", "model option"]
param_names = ["model", "model option", "solver class"]
params = (
[pybamm.lithium_ion.SPM, pybamm.lithium_ion.DFN],
["isothermal", "lumped", "x-lumped", "x-full"],
[pybamm.CasadiSolver, pybamm.IDAKLUSolver],
)

def setup(self, model, params):
SolveModel.solve_setup(self, "Marquis2019", model, "thermal", params)
def setup(self, model, params, solver_class):
SolveModel.solve_setup(self, "Marquis2019", model, "thermal", params, solver_class)

def time_solve_model(self, model, params):
def time_solve_model(self, model, params, solver_class):
self.solver.solve(self.model, t_eval=self.t_eval)


Expand All @@ -232,14 +237,15 @@ def time_setup_model(self, model, params):


class TimeSolveSurfaceForm:
param_names = ["model", "model option"]
param_names = ["model", "model option", "solver class"]
params = (
[pybamm.lithium_ion.SPM, pybamm.lithium_ion.DFN],
["false", "differential", "algebraic"],
[pybamm.CasadiSolver, pybamm.IDAKLUSolver],
)

def setup(self, model, params):
SolveModel.solve_setup(self, "Marquis2019", model, "surface form", params)
def setup(self, model, params, solver_class):
SolveModel.solve_setup(self, "Marquis2019", model, "surface form", params, solver_class)

def time_solve_model(self, model, params):
def time_solve_model(self, model, params, solver_class):
self.solver.solve(self.model, t_eval=self.t_eval)
91 changes: 33 additions & 58 deletions benchmarks/time_sims_experiments.py
Original file line number Diff line number Diff line change
@@ -1,67 +1,42 @@
import pybamm

parameters = ["Marquis2019", "Chen2020"]


class TimeSPMSimulationCCCV:
param_names = ["parameter"]
params = parameters

def time_setup_SPM_simulation(self, parameters):
class TimeSimulation:
param_names = ["experiment", "parameter", "model_class", "solver_class"]
params = [
["CCCV", "GITT"],
["Marquis2019", "Chen2020"],
[pybamm.lithium_ion.SPM, pybamm.lithium_ion.DFN],
[pybamm.CasadiSolver, pybamm.IDAKLUSolver],
]
experiment_descriptions = {
"CCCV": [
"Discharge at C/5 for 10 hours or until 3.3 V",
"Rest for 1 hour",
"Charge at 1 A until 4.1 V",
"Hold at 4.1 V until 10 mA",
"Rest for 1 hour",
],
"GITT": [("Discharge at C/20 for 1 hour", "Rest for 1 hour")] * 20
}

def setup(self, experiment, parameters, model_class, solver_class):
self.param = pybamm.ParameterValues(parameters)
self.model = pybamm.lithium_ion.SPM()
exp = pybamm.Experiment(
[
"Discharge at C/5 for 10 hours or until 3.3 V",
"Rest for 1 hour",
"Charge at 1 A until 4.1 V",
"Hold at 4.1 V until 10 mA",
"Rest for 1 hour",
]
self.model = model_class()
self.solver = solver_class()
self.exp = pybamm.Experiment(self.experiment_descriptions[experiment])
self.sim = pybamm.Simulation(
self.model, parameter_values=self.param, experiment=self.exp, solver=self.solver
)
pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp)

def time_setup(self, experiment, parameters, model_class, solver_class):
param = pybamm.ParameterValues(parameters)
model = model_class()
solver = solver_class()
exp = pybamm.Experiment(self.experiment_descriptions[experiment])
pybamm.Simulation(model, parameter_values=param, experiment=exp, solver=solver)

class TimeDFNSimulationCCCV:
param_names = ["parameter"]
params = parameters
def time_solve(self, experiment, parameters, model_class, solver_class):
self.sim.solve()

def time_setup_SPM_simulation(self, parameters):
self.param = pybamm.ParameterValues(parameters)
self.model = pybamm.lithium_ion.DFN()
exp = pybamm.Experiment(
[
"Discharge at C/5 for 10 hours or until 3.3 V",
"Rest for 1 hour",
"Charge at 1 A until 4.1 V",
"Hold at 4.1 V until 10 mA",
"Rest for 1 hour",
]
)
pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp)


class TimeSPMSimulationGITT:
param_names = ["parameter"]
params = parameters

def time_setup_SPM_simulation(self, parameters):
self.param = pybamm.ParameterValues(parameters)
self.model = pybamm.lithium_ion.SPM()
exp = pybamm.Experiment(
[("Discharge at C/20 for 1 hour", "Rest for 1 hour")] * 20
)
pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp)


class TimeDFNSimulationGITT:
param_names = ["parameter"]
params = parameters

def time_setup_SPM_simulation(self, parameters):
self.param = pybamm.ParameterValues(parameters)
self.model = pybamm.lithium_ion.DFN()
exp = pybamm.Experiment(
[("Discharge at C/20 for 1 hour", "Rest for 1 hour")] * 20
)
pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp)
37 changes: 25 additions & 12 deletions benchmarks/time_solve_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def solve_model_once(model, solver, t_eval):


class TimeSolveSPM:
param_names = ["solve first", "parameter"]
param_names = ["solve first", "parameter", "solver_class"]
params = (
[False, True],
[
Expand All @@ -24,10 +24,15 @@ class TimeSolveSPM:
"Chen2020",
"Ecker2015",
],
[
pybamm.CasadiSolver,
pybamm.IDAKLUSolver,
],

)

def setup(self, solve_first, parameters):
self.solver = pybamm.CasadiSolver()
def setup(self, solve_first, parameters, solver_class):
self.solver = solver_class()
self.model = pybamm.lithium_ion.SPM()
c_rate = 1
tmax = 4000 / c_rate
Expand Down Expand Up @@ -58,12 +63,12 @@ def setup(self, solve_first, parameters):
if solve_first:
solve_model_once(self.model, self.solver, self.t_eval)

def time_solve_model(self, solve_first, parameters):
def time_solve_model(self, solve_first, parameters, solver_class):
self.solver.solve(self.model, t_eval=self.t_eval)


class TimeSolveSPMe:
param_names = ["solve first", "parameter"]
param_names = ["solve first", "parameter", "solver_class"]
params = (
[False, True],
[
Expand All @@ -77,10 +82,14 @@ class TimeSolveSPMe:
"Chen2020",
"Ecker2015",
],
[
pybamm.CasadiSolver,
pybamm.IDAKLUSolver,
],
)

def setup(self, solve_first, parameters):
self.solver = pybamm.CasadiSolver()
def setup(self, solve_first, parameters, solver_class):
self.solver = solver_class()
self.model = pybamm.lithium_ion.SPMe()
c_rate = 1
tmax = 4000 / c_rate
Expand Down Expand Up @@ -111,12 +120,12 @@ def setup(self, solve_first, parameters):
if solve_first:
solve_model_once(self.model, self.solver, self.t_eval)

def time_solve_model(self, solve_first, parameters):
def time_solve_model(self, solve_first, parameters, solver_class):
self.solver.solve(self.model, t_eval=self.t_eval)


class TimeSolveDFN:
param_names = ["solve first", "parameter"]
param_names = ["solve first", "parameter", "solver_class"]
params = (
[False, True],
[
Expand All @@ -130,10 +139,14 @@ class TimeSolveDFN:
"Chen2020",
"Ecker2015",
],
[
pybamm.CasadiSolver,
pybamm.IDAKLUSolver,
],
)

def setup(self, solve_first, parameters):
self.solver = pybamm.CasadiSolver()
def setup(self, solve_first, parameters, solver_class):
self.solver = solver_class()
self.model = pybamm.lithium_ion.DFN()
c_rate = 1
tmax = 4000 / c_rate
Expand Down Expand Up @@ -164,5 +177,5 @@ def setup(self, solve_first, parameters):
if solve_first:
solve_model_once(self.model, self.solver, self.t_eval)

def time_solve_model(self, solve_first, parameters):
def time_solve_model(self, solve_first, parameters, solver_class):
self.solver.solve(self.model, t_eval=self.t_eval)

0 comments on commit f9a9fcc

Please sign in to comment.