Skip to content

Commit

Permalink
Merge pull request pybamm-team#2086 from Vaibhav-Chopra-GT/benchmarks…
Browse files Browse the repository at this point in the history
…_parameters

Benchmarks for model X parameter set combinations
  • Loading branch information
brosaplanella authored Jun 7, 2022
2 parents e1f52ff + deefe3d commit 79b9368
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 56 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,7 @@ Manifest.toml

# vcpkg
vcpkg_installed/

# benchmarks
html/
results/
64 changes: 37 additions & 27 deletions benchmarks/time_setup_models_and_sims.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
import pybamm

parameters = [
"Marquis2019",
"ORegan2021",
"NCA_Kim2011",
"Prada2013",
"Ai2020",
"Ramadass2004",
"Mohtat2020",
"Chen2020",
"Chen2020_plating",
"Ecker2015",
]


def compute_discretisation(model, param):
var_pts = {
Expand All @@ -18,43 +31,44 @@ def compute_discretisation(model, param):


class TimeBuildSPM:
def __init__(self):
self.param = pybamm.ParameterValues("Marquis2019")
param_names = ["parameter"]
params = parameters

def time_setup_SPM(self):
def time_setup_SPM(self, parameters):
self.param = pybamm.ParameterValues(parameters)
self.model = pybamm.lithium_ion.SPM()
self.param.process_model(self.model)
compute_discretisation(self.model, self.param).process_model(self.model)


class TimeBuildSPMe:
def __init__(self):
self.param = pybamm.ParameterValues("Marquis2019")
param_names = ["parameter"]
params = parameters

def time_setup_SPMe(self):
def time_setup_SPMe(self, parameters):
self.param = pybamm.ParameterValues(parameters)
self.model = pybamm.lithium_ion.SPMe()
self.param.process_model(self.model)
compute_discretisation(self.model, self.param).process_model(self.model)


class TimeBuildDFN:
def __init__(self):
self.param = pybamm.ParameterValues("Marquis2019")
param_names = ["parameter"]
params = parameters

def time_setup_DFN(self):
def time_setup_DFN(self, parameters):
self.param = pybamm.ParameterValues(parameters)
self.model = pybamm.lithium_ion.DFN()
self.param.process_model(self.model)
compute_discretisation(self.model, self.param).process_model(self.model)


class TimeBuildSPMSimulation:
# with_experiment
params = [False, True]

def __init__(self):
self.param = pybamm.ParameterValues("Marquis2019")
param_names = ["with experiment", "parameter"]
params = ([False, True], parameters)

def time_setup_SPM_simulation(self, with_experiment):
def time_setup_SPM_simulation(self, with_experiment, parameters):
self.param = pybamm.ParameterValues(parameters)
self.model = pybamm.lithium_ion.SPM()
if with_experiment:
exp = pybamm.Experiment(
Expand All @@ -68,13 +82,11 @@ def time_setup_SPM_simulation(self, with_experiment):


class TimeBuildSPMeSimulation:
# with_experiment
params = [False, True]
param_names = ["with experiment", "parameter"]
params = ([False, True], parameters)

def __init__(self):
self.param = pybamm.ParameterValues("Marquis2019")

def time_setup_SPMe_simulation(self, with_experiment):
def time_setup_SPMe_simulation(self, with_experiment, parameters):
self.param = pybamm.ParameterValues(parameters)
self.model = pybamm.lithium_ion.SPMe()
if with_experiment:
exp = pybamm.Experiment(
Expand All @@ -88,13 +100,11 @@ def time_setup_SPMe_simulation(self, with_experiment):


class TimeBuildDFNSimulation:
# with_experiment
params = [False, True]

def __init__(self):
self.param = pybamm.ParameterValues("Marquis2019")
param_names = ["with experiment", "parameter"]
params = ([False, True], parameters)

def time_setup_DFN_simulation(self, with_experiment):
def time_setup_DFN_simulation(self, with_experiment, parameters):
self.param = pybamm.ParameterValues(parameters)
self.model = pybamm.lithium_ion.DFN()
if with_experiment:
exp = pybamm.Experiment(
Expand Down
149 changes: 120 additions & 29 deletions benchmarks/time_solve_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,76 +5,167 @@
import numpy as np


def prepare_model(model):
geometry = model.default_geometry

# load parameter values and process model and geometry
param = pybamm.ParameterValues("Marquis2019")
param.process_model(model)
param.process_geometry(geometry)

# set mesh
var_pts = {"x_n": 20, "x_s": 20, "x_p": 20, "r_n": 30, "r_p": 30, "y": 10, "z": 10}
mesh = pybamm.Mesh(geometry, model.default_submesh_types, var_pts)

# discretise model
disc = pybamm.Discretisation(mesh, model.default_spatial_methods)
disc.process_model(model)


def solve_model_once(model, solver, t_eval):
solver.solve(model, t_eval=t_eval)


class TimeSolveSPM:
params = [True, False]
param_names = ['solve first', 'parameter']
params = (
[False, True],
[
"Marquis2019",
"ORegan2021",
"NCA_Kim2011",
"Prada2013",
# "Ai2020",
"Ramadass2004",
"Mohtat2020",
"Chen2020",
"Chen2020_plating",
"Ecker2015",
],
)
solver = pybamm.CasadiSolver()

def setup(self, solve_first):
def setup(self, solve_first, parameters):
self.model = pybamm.lithium_ion.SPM()
c_rate = 1
tmax = 4000 / c_rate
nb_points = 500
self.t_eval = np.linspace(0, tmax, nb_points)
prepare_model(self.model)
geometry = self.model.default_geometry

# load parameter values and process model and geometry
param = pybamm.ParameterValues(parameters)
param.process_model(self.model)
param.process_geometry(geometry)

# set mesh
var_pts = {
"x_n": 20,
"x_s": 20,
"x_p": 20,
"r_n": 30,
"r_p": 30,
"y": 10,
"z": 10,
}
mesh = pybamm.Mesh(geometry, self.model.default_submesh_types, var_pts)

# discretise model
disc = pybamm.Discretisation(mesh, self.model.default_spatial_methods)
disc.process_model(self.model)
if solve_first:
solve_model_once(self.model, TimeSolveSPM.solver, self.t_eval)

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


class TimeSolveSPMe:
params = [True, False]
param_names = ['solve first', 'parameter']
params = (
[False, True],
[
"Marquis2019",
"ORegan2021",
"NCA_Kim2011",
"Prada2013",
# "Ai2020",
"Ramadass2004",
"Mohtat2020",
"Chen2020",
"Chen2020_plating",
"Ecker2015",
],
)
solver = pybamm.CasadiSolver()

def setup(self, solve_first):
def setup(self, solve_first, parameters):
self.model = pybamm.lithium_ion.SPMe()
c_rate = 1
tmax = 4000 / c_rate
nb_points = 500
self.t_eval = np.linspace(0, tmax, nb_points)
prepare_model(self.model)
geometry = self.model.default_geometry

# load parameter values and process model and geometry
param = pybamm.ParameterValues(parameters)
param.process_model(self.model)
param.process_geometry(geometry)

# set mesh
var_pts = {
"x_n": 20,
"x_s": 20,
"x_p": 20,
"r_n": 30,
"r_p": 30,
"y": 10,
"z": 10,
}
mesh = pybamm.Mesh(geometry, self.model.default_submesh_types, var_pts)

# discretise model
disc = pybamm.Discretisation(mesh, self.model.default_spatial_methods)
disc.process_model(self.model)
if solve_first:
solve_model_once(self.model, TimeSolveSPMe.solver, self.t_eval)

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


class TimeSolveDFN:
params = [True, False]
param_names = ['solve first', 'parameter']
params = (
[False, True],
[
"Marquis2019",
"ORegan2021",
# "NCA_Kim2011",
"Prada2013",
"Ai2020",
"Ramadass2004",
# "Mohtat2020",
"Chen2020",
"Chen2020_plating",
"Ecker2015",
],
)
solver = pybamm.CasadiSolver()

def setup(self, solve_first):
def setup(self, solve_first, parameters):
self.model = pybamm.lithium_ion.DFN()
c_rate = 1
tmax = 4000 / c_rate
nb_points = 500
self.t_eval = np.linspace(0, tmax, nb_points)
prepare_model(self.model)
geometry = self.model.default_geometry

# load parameter values and process model and geometry
param = pybamm.ParameterValues(parameters)
param.process_model(self.model)
param.process_geometry(geometry)

# set mesh
var_pts = {
"x_n": 20,
"x_s": 20,
"x_p": 20,
"r_n": 30,
"r_p": 30,
"y": 10,
"z": 10,
}
mesh = pybamm.Mesh(geometry, self.model.default_submesh_types, var_pts)

# discretise model
disc = pybamm.Discretisation(mesh, self.model.default_spatial_methods)
disc.process_model(self.model)
if solve_first:
solve_model_once(self.model, TimeSolveDFN.solver, self.t_eval)

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

0 comments on commit 79b9368

Please sign in to comment.