Skip to content

Commit

Permalink
beter error handling, to be improved
Browse files Browse the repository at this point in the history
  • Loading branch information
Ombrini committed May 24, 2024
1 parent 9c417c8 commit bd3d5d3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
14 changes: 7 additions & 7 deletions Param_estim/instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@ def sim_instructions():
optimization_method = 'DE' # 'DE' or 'GD'

ensable_system = [
[("Conductivity", "sig_carb_c"), ["2e-4", "0.5e-4"]],
# [("Conductivity", "E_sig_carb_c"), ["0.1", "0.4"]],
[("Conductivity", "sig_carb_c"), ["3e-4", "1e-4"]],
[("Conductivity", "E_sig_carb_c"), ["0.1", "0.3"]],
# [("Electrodes", "k0_foil"), ["10","50"]],
]

ensable_cathode = [
# [("Reactions", "k0"), ["5", "30"]],
[("Reactions", "k0"), ["10", "30"]],
]

ensable_anode = []

# Define C-rates and Temperatures

# temps = [298,283,268] # K
temperatures = [298] # K
temperatures = [298, 268] # K
# Possible protocols: 'cc', 'pitt', 'gitt'
protocols = ['cc']
protocols = ['pitt']
# one list for each protocol and temperature
# it is important that the order of temperatures and conditions is the same
c_rates_cc = [[0.5,2]] # C-rates
c_rates_gitt = [[1],
[1]] # C-rates
cont_volts = [[3.377, 3.351, 3.326],
[3.376,3.352,3.271,3.221]] # V
cont_volts = [[3.376,3.326],
[3.271]] # V
# volts at 298 = [3.376, 3.351 ,3.326 ,2.926 ,3.126 ,3.026]
# volts at 268 = [3.376,3.352,3.271,3.221]

Expand Down
8 changes: 7 additions & 1 deletion Param_estim/objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ def run_mpet(scaled_parameters):

elif prot == 'pitt':
time_tolerance = 3*60 # seconds
print('TIME END SIMULATION: ', tim[-1])
if tim[-1] < 1e3-time_tolerance:
print('simulation did not finish')
print('decreasing time tolerance and running again')
Expand Down Expand Up @@ -176,6 +175,13 @@ def obj(parameters):

dict_res = run_mpet(parameters)
if dict_res == 0.25:
with open(os.path.join(save_folder(),"log_book.txt"), 'a') as f:
param_rescaled = copy.deepcopy(parameters)
scaled_enasmble, scaling_factors = scale(ensamble_tot)
params = rescale(param_rescaled, scaling_factors)
for par in params:
f.write(str(par) + "\t")
f.write(str(0.25) + "\n")
return 0.25

weighted_mse = 0
Expand Down

0 comments on commit bd3d5d3

Please sign in to comment.