@@ -92,7 +92,8 @@ def test_outputs(self):
92
92
)
93
93
std_out_test .test_all ()
94
94
95
- def test_sensitivities (self , param_name , param_value ):
95
+ def test_sensitivities (self , param_name , param_value ,
96
+ output_name = 'Terminal voltage [V]' ):
96
97
self .parameter_values .update ({param_name : "[input]" })
97
98
inputs = {param_name : param_value }
98
99
@@ -113,6 +114,7 @@ def test_sensitivities(self, param_name, param_value):
113
114
self .model , t_eval , inputs = inputs ,
114
115
calculate_sensitivities = True
115
116
)
117
+ output_sens = self .solution [output_name ].sensitivities [param_name ]
116
118
117
119
# check via finite differencing
118
120
h = 1e-6 * param_value
@@ -121,14 +123,16 @@ def test_sensitivities(self, param_name, param_value):
121
123
sol_plus = self .solver .solve (
122
124
self .model , t_eval , inputs = inputs_plus ,
123
125
)
126
+ output_plus = sol_plus [output_name ](t = t_eval )
124
127
sol_neg = self .solver .solve (
125
128
self .model , t_eval , inputs = inputs_neg
126
129
)
127
- fd = ((np .array (sol_plus .y ) - np .array (sol_neg .y )) / h )
130
+ output_neg = sol_neg [output_name ](t = t_eval )
131
+ fd = ((np .array (output_plus ) - np .array (output_neg )) / h )
128
132
fd = fd .transpose ().reshape (- 1 , 1 )
129
133
np .testing .assert_allclose (
130
- self . solution . sensitivities [ param_name ] , fd ,
131
- rtol = 1e-1 , atol = 1e-5 ,
134
+ output_sens , fd ,
135
+ rtol = 1e-2 , atol = 1e-6 ,
132
136
)
133
137
134
138
def test_all (
0 commit comments