festim-dev / FESTIM

Coupled hydrogen/tritium transport and heat transfer modelling using FEniCS
https://festim.readthedocs.io/en/stable/
Apache License 2.0
78 stars 16 forks source link

Error message when temperature is not defined #768

Closed RemDelaporteMathurin closed 1 month ago

RemDelaporteMathurin commented 1 month ago

Proposed changes

I've noticed that it's easy to miss the temperature field when setting up a model. And the error message that's produced isn't straightforward:

Traceback (most recent call last):
  File "/home/remidm/FESTIM/mwe_2.py", line 19, in <module>
    my_model.initialise()
  File "/home/remidm/FESTIM/festim/generic_simulation.py", line 264, in initialise
    self.attribute_source_terms()
  File "/home/remidm/FESTIM/festim/generic_simulation.py", line 173, in attribute_source_terms
    self.T.sources = []
    ^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'sources'

Instead, this PR adds a clearer error message upon calling initialise()

Traceback (most recent call last):
  File "/home/remidm/FESTIM/mwe_2.py", line 18, in <module>
    my_model.initialise()
  File "/home/remidm/FESTIM/festim/generic_simulation.py", line 257, in initialise
    raise AttributeError("Temperature is not defined")
AttributeError: Temperature is not defined

Types of changes

What types of changes does your code introduce to FESTIM?

Checklist

codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 99.52%. Comparing base (24420e6) to head (d4a8d6e). Report is 6 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #768 +/- ## ========================================== + Coverage 99.51% 99.52% +0.01% ========================================== Files 58 58 Lines 2468 2523 +55 ========================================== + Hits 2456 2511 +55 Misses 12 12 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.