@@ -13,11 +13,30 @@ class BatchStudy:
13
13
----------
14
14
models : dict
15
15
A dictionary of models to be simulated
16
- solvers : dict (optional)
17
- A dictionary of solvers to use to solve the model. Default is None
18
16
experiments : dict (optional)
19
17
A dictionary of experimental conditions under which to solve the model.
20
18
Default is None
19
+ geometries : dict (optional)
20
+ A dictionary of geometries upon which to solve the model
21
+ parameter_values : dict (optional)
22
+ A dictionary of parameters and their corresponding numerical values.
23
+ Default is None
24
+ submesh_types : dict (optional)
25
+ A dictionary of the types of submesh to use on each subdomain.
26
+ Default is None
27
+ var_pts : dict (optional)
28
+ A dictionary of the number of points used by each spatial variable.
29
+ Default is None
30
+ spatial_methods : dict (optional)
31
+ A dictionary of the types of spatial method to use on each domain.
32
+ Default is None
33
+ solvers : dict (optional)
34
+ A dictionary of solvers to use to solve the model. Default is None
35
+ output_variables : dict (optional)
36
+ A dictionary of variables to plot automatically. Default is None
37
+ C_rates : dict (optional)
38
+ A dictionary of C-rates at which you would like to run a constant current
39
+ (dis)charge. Default is None
21
40
repeats : int (optional)
22
41
The number of times `solve` should be called. Default is 1
23
42
permutations : bool (optional)
@@ -27,64 +46,131 @@ class BatchStudy:
27
46
Default is False
28
47
"""
29
48
49
+ INPUT_LIST = [
50
+ "experiments" ,
51
+ "geometries" ,
52
+ "parameter_values" ,
53
+ "submesh_types" ,
54
+ "var_pts" ,
55
+ "spatial_methods" ,
56
+ "solvers" ,
57
+ "output_variables" ,
58
+ "C_rates" ,
59
+ ]
60
+
30
61
def __init__ (
31
- self , models , solvers = None , experiments = None , repeats = 1 , permutations = False
62
+ self ,
63
+ models ,
64
+ experiments = None ,
65
+ geometries = None ,
66
+ parameter_values = None ,
67
+ submesh_types = None ,
68
+ var_pts = None ,
69
+ spatial_methods = None ,
70
+ solvers = None ,
71
+ output_variables = None ,
72
+ C_rates = None ,
73
+ repeats = 1 ,
74
+ permutations = False ,
32
75
):
33
76
self .models = models
34
- self .solvers = solvers
35
77
self .experiments = experiments
78
+ self .geometries = geometries
79
+ self .parameter_values = parameter_values
80
+ self .submesh_types = submesh_types
81
+ self .var_pts = var_pts
82
+ self .spatial_methods = spatial_methods
83
+ self .solvers = solvers
84
+ self .output_variables = output_variables
85
+ self .C_rates = C_rates
36
86
self .repeats = repeats
37
87
self .permutations = permutations
38
88
39
89
if not self .permutations :
40
- if self .solvers and (len (self .models ) != len (self .solvers )):
41
- raise ValueError (
42
- f"Either provide no solvers or an equal number of solvers as the"
43
- f" models ({ len (self .models )} models given) if permutations=False"
44
- )
45
- elif self .experiments and (len (self .models ) != len (self .experiments )):
46
- raise ValueError (
47
- f"Either provide no experiments or an equal number of experiments"
48
- f" as the models ({ len (self .models )} models given)"
49
- f" if permutations=False"
50
- )
90
+ for name in self .INPUT_LIST :
91
+ if getattr (self , name ) and (
92
+ len (self .models ) != len (getattr (self , name ))
93
+ ):
94
+ raise ValueError (
95
+ f"Either provide no { name } or an equal number of { name } "
96
+ f" as the models ({ len (self .models )} models given)"
97
+ f" if permutations=False"
98
+ )
51
99
52
- def solve (self , t_eval = None ):
100
+ def solve (
101
+ self ,
102
+ t_eval = None ,
103
+ solver = None ,
104
+ check_model = True ,
105
+ save_at_cycles = None ,
106
+ starting_solution = None ,
107
+ ** kwargs ,
108
+ ):
109
+ """
110
+ For more information on the parameters used in the solve,
111
+ See :meth:`pybamm.Simulation.solve`
112
+ """
53
113
self .sims = []
54
114
iter_func = product if self .permutations else zip
55
115
56
- # Instantiate values for solvers based on the value of self.permutations
57
- if self .solvers :
58
- solver_values = self .solvers .values ()
59
- elif self .permutations :
60
- solver_values = [None ]
61
- else :
62
- solver_values = [None ] * len (self .models )
116
+ # Instantiate items in INPUT_LIST based on the value of self.permutations
117
+ inp_values = []
118
+ for name in self .INPUT_LIST :
119
+ if getattr (self , name ):
120
+ inp_value = getattr (self , name ).values ()
121
+ elif self .permutations :
122
+ inp_value = [None ]
123
+ else :
124
+ inp_value = [None ] * len (self .models )
125
+ inp_values .append (inp_value )
63
126
64
- # Instantiate values for experminents based on the value of self.permutations
65
- if self .experiments :
66
- experiment_values = self .experiments .values ()
67
- elif self .permutations :
68
- experiment_values = [None ]
69
- else :
70
- experiment_values = [None ] * len (self .models )
71
-
72
- for model , solver , experiment in iter_func (
73
- self .models .values (), solver_values , experiment_values
74
- ):
75
- sim = pybamm .Simulation (model , solver = solver , experiment = experiment )
76
- # repeat to get average solve time and integration time
127
+ for (
128
+ model ,
129
+ experiment ,
130
+ geometry ,
131
+ parameter_value ,
132
+ submesh_type ,
133
+ var_pt ,
134
+ spatial_method ,
135
+ solver ,
136
+ output_variable ,
137
+ C_rate ,
138
+ ) in iter_func (self .models .values (), * inp_values ):
139
+ sim = pybamm .Simulation (
140
+ model ,
141
+ experiment = experiment ,
142
+ geometry = geometry ,
143
+ parameter_values = parameter_value ,
144
+ submesh_types = submesh_type ,
145
+ var_pts = var_pt ,
146
+ spatial_methods = spatial_method ,
147
+ solver = solver ,
148
+ output_variables = output_variable ,
149
+ C_rate = C_rate ,
150
+ )
151
+ # Repeat to get average solve time and integration time
77
152
solve_time = 0
78
153
integration_time = 0
79
154
for _ in range (self .repeats ):
80
- sol = sim .solve (t_eval )
155
+ sol = sim .solve (
156
+ t_eval ,
157
+ solver ,
158
+ check_model ,
159
+ save_at_cycles ,
160
+ starting_solution ,
161
+ ** kwargs ,
162
+ )
81
163
solve_time += sol .solve_time
82
164
integration_time += sol .integration_time
83
165
sim .solution .solve_time = solve_time / self .repeats
84
166
sim .solution .integration_time = integration_time / self .repeats
85
167
self .sims .append (sim )
86
168
87
169
def plot (self , output_variables = None , ** kwargs ):
170
+ """
171
+ For more information on the parameters used in the plot,
172
+ See :meth:`pybamm.Simulation.plot`
173
+ """
88
174
self .quick_plot = pybamm .dynamic_plot (
89
175
self .sims , output_variables = output_variables , ** kwargs
90
176
)
0 commit comments