Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IC improvements for Heat Transfer #774

Merged
merged 7 commits into from
Jun 4, 2024
Merged

Conversation

RemDelaporteMathurin
Copy link
Collaborator

Proposed changes

Currently when running a transient Heat Transfer problem, an initial condition is required.
The process is a bit cumbersome as if users just want to initialise the temperature to say 300 K then they have to

  • create a InitialCondition object
  • give it the field "T" (which is redundant!)
  • pass it to HeatTransferProblem

This PR simplifies the process.
Now users can simply give a float, int or sympy Expression as the initial_condition argument.
If users want to give a initial condition from XDMF then the process is unchanged.

Moreover, this adds an error when transient heat transfer sims are run without giving an IC.

Documentation was also updated as the confusion was first reported here.

Types of changes

What types of changes does your code introduce to FESTIM?

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Code refactoring
  • Documentation Update (if none of the other choices apply)
  • New tests

Checklist

  • Black formatted
  • Unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

@RemDelaporteMathurin RemDelaporteMathurin added the enhancement New feature or request label Jun 4, 2024
@RemDelaporteMathurin RemDelaporteMathurin added this to the v1.3 milestone Jun 4, 2024
Copy link

codecov bot commented Jun 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.51%. Comparing base (217dc15) to head (82509da).
Report is 204 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #774   +/-   ##
=======================================
  Coverage   99.51%   99.51%           
=======================================
  Files          58       58           
  Lines        2478     2488   +10     
=======================================
+ Hits         2466     2476   +10     
  Misses         12       12           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@KulaginVladimir
Copy link
Collaborator

@RemDelaporteMathurin
Looks good to me. I also got a bit tired of using InitialCondition with a constant initial temperature.

Just two unnecessary moments

@@ -8,7 +8,7 @@ class HeatTransferProblem(festim.Temperature):
Args:
transient (bool, optional): If True, a transient simulation will
be run. Defaults to True.
initial_condition (festim.InitialCondition, optional): The initial condition.
initial_condition (int, float, sp.Expr, festim.InitialCondition, optional): The initial condition.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't it be useful to add a small test to check create_functions with sp.Expr?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Let me know what you think

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect

Comment on lines +65 to +68
if isinstance(value, (int, float, sp.Expr)):
self._initial_condition = festim.InitialCondition(field="T", value=value)
else:
self._initial_condition = value
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm correct, users can provide F.InitialCondition with any field if they set directly initial_condition=F.InitialCondition(...). Is there any point in restricting the allowable field for the initial condition in the heat transfer problem?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is correct. What do you mean by "restricting the allowable field"?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, we can add a check for the field value. If it's not T than raise an error. Though, such restriction doesn't make a lot of sense

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since in this specific case field isn't even required (users could put anything in there) I don't think that's a good idea.
What we could do is make different classes InitialTemperature and InitialConcentration (a bit like the approach we hvae in fenicsx). For InitialTemperature we wouldn't need to specify field.

Maybe worth doing it in another PR? Maybe it's not even needed at all

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InitialTemperature and InitialConcentration sound interesting. However, I assume that the current users should be familiar with InitialCondition as it is, if they use it. Possibly, these new classes can be considered later, yes

@RemDelaporteMathurin RemDelaporteMathurin merged commit fb2c99f into main Jun 4, 2024
6 checks passed
@RemDelaporteMathurin RemDelaporteMathurin deleted the IC-heat-transfer branch July 11, 2024 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants