DanielDosSantosAvila / bainite-model

Code accompanying the paper "Modeling the effect of prior austenite grain size on bainite formation kinetics."
MIT License
0 stars 0 forks source link

python #2

Closed JDFIJ closed 2 months ago

JDFIJ commented 2 months ago

Hello, thank you very much for providing this program. However, during the execution process, I encountered some issues. May I ask which version of Python you are using?

DanielDosSantosAvila commented 2 months ago

I was using Python 3.7. Can you let me know exactly which issues you're encountering?

DanielDosSantosAvila commented 2 months ago

I tried to run the code and I also got an error because of some mutable arguments in the dataclass TransformationKinetics. I made a small change to bainitemodel.py and now it's working for me. Could you please download the updated file, try again, and let me know if it's working? Thanks!

JDFIJ commented 2 months ago

Thank you very much! I'll try running it and see how it goes. I'm currently using Python 3.12, which might not be fully compatible, so I'll give it a shot with Python 3.7 instead. Thanks again for your help!

JDFIJ commented 2 months ago

(myenv37) E:\B\bainite-model-main (1)\bainite-model-main>python example2.py Traceback (most recent call last): File "example2.py", line 5, in from bainitemodel import Composition, Bainite, TransformationKinetics, fit_single_curve File "E:\B\bainite-model-main (1)\bainite-model-main\bainitemodel.py", line 728, in solver_options: dict = None, minimizer_options: dict = None): TypeError: 'type' object is not subscriptable

(myenv37) E:\B\bainite-model-main (1)\bainite-model-main>python example1.py Traceback (most recent call last): File "example1.py", line 3, in from bainitemodel import Composition, Bainite, bainite_model File "E:\B\bainite-model-main (1)\bainite-model-main\bainitemodel.py", line 728, in solver_options: dict = None, minimizer_options: dict = None): TypeError: 'type' object is not subscriptable I re-ran it using Python 3.7, and the following issue occurred.

JDFIJ commented 2 months ago

= RESTART: E:\B\bainite-model-main (1)\bainite-model-main\Example2.py Traceback (most recent call last): File "E:\B\bainite-model-main (1)\bainite-model-main\Example2.py", line 23, in fit = fit_single_curve(bainite_params=bainite_params, minimizer_options={'method': 'differential_evolution'}) File "E:\B\bainite-model-main (1)\bainite-model-main\bainitemodel.py", line 638, in fit_single_curve if (bainite_params.kinetics.experiment_time_datapoints == np.array([]) or ValueError: operands could not be broadcast together with shapes (2401,) (0,) I used version 3.12, and example one runs successfully, but example two encountered the following error

DanielDosSantosAvila commented 2 months ago

Okay, I see! I made a few changes and tried again using Python 3.11. Now all three examples worked for me, and I guess they should also work for Python 3.12. Could you please try again and let me know if it works?

JDFIJ commented 2 months ago

Hello, thank you very much for providing the revised version. I tried rerunning it, but the following issues still occurred:

  1. First Example: The first example runs normally.
  2. Second Example:

The second example throws the following error:

File "E:\B\bainite-model-main new\bainite-model-main\bainitemodel.py", line 663, in residuals return experiment - model


ValueError: operands could not be broadcast together with shapes (2401,) (4,)

3. Third Example:

The third example runs, but the following warnings still appear during execution:

E:\B\bainite-model-main new\bainite-model-main\bainitemodel.py:477: RuntimeWarning: overflow encountered in scalar multiply
  n_t_a = n_s_a * (f_sum / sub_unit_length) * (1 - f_a / f_a_max) * enrichment_factor if f_a_max > 0 else 0
E:\B\bainite-model-main new\bainite-model-main\bainitemodel.py:480: RuntimeWarning: overflow encountered in exp
  dn_gb_dt = vibration_factor * n_t_gb * np.exp(- q_gb_t / (r * temp_kelvin))
E:\B\bainite-model-main new\bainite-model-main\bainitemodel.py:481: RuntimeWarning: overflow encountered in exp
  dn_a_dt = vibration_factor * n_t_a * np.exp(- q_a_t / (r * temp_kelvin))
E:\B\bainite-model-main new\bainite-model-main\bainitemodel.py:462: RuntimeWarning: invalid value encountered in scalar add
  f_sum = f_gb + f_a

This issue also appeared in the second error.

This is the result after the error occurred. There doesn’t seem to be a numerical difference between the two.
![image](https://github.com/user-attachments/assets/a4f40a4d-7378-4890-81e0-4ec870d53a74)
DanielDosSantosAvila commented 2 months ago

Good. I changed the second example, and it should be running now. There was an issue with Scipy, it wasn't solving correctly the ODEs. The warnings you got running Example 3 are normal, and they don't interfere with the result. Example 3 considers the same activation energy for the two prior austenite grain sizes, so the activation energy you find should indeed be the same. The example is running correctly.

This code here on GitHub sometimes cannot find a good fit. I'm using a different optimization approach right now that I plan on publishing here in October/November. If you get poor fitting or some weird results, email me at D.dosSantosAvila@tudelft.nl and I can share the new code I'm using with you.