-
Notifications
You must be signed in to change notification settings - Fork 32
Coupled transient heat transfer and hydrogen transport models #948
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
Merged
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
f508ad0
new coupled problem
jhdark ba841ef
update temperature dependent values
jhdark 44284a3
use same initial dt and max time
jhdark 01ea1b0
update temperature depedent values
jhdark 7718eac
alter order of arguments
jhdark a1c8ad4
add unit tests for class
jhdark bf15639
system tests
jhdark 9566154
add docs
jhdark 9e0d0f0
support for mismatching meshes
jhdark 9d8e86a
additional tests
jhdark e75edc8
remove unnecessary test
jhdark 7bd986b
add suggestions from code reveiw, addional setter conditions
jhdark 90488b1
prevent circular imports
jhdark cb6250b
remove line
jhdark 9364e51
new tests
jhdark 61d7313
Merge branch 'fenicsx' into coupled_heat_hydrogen
jhdark ec218bf
rename class to confirm only for transient
jhdark 60fcb8a
new name, test if both args are transient
jhdark f2574db
rename class
jhdark 85b10e7
remove steady tests, new mms test
jhdark e92c9bf
additional test for transient arg
jhdark 816f176
move interpolation function to helpers
jhdark 366be72
no need for steady state capability
jhdark c8bacca
remove exports from test
jhdark e3d4343
clean up mms test, replace docs
jhdark a9c100f
use predefined trap properties, add inline comments
jhdark e3ab6d2
Apply suggestions from code review
jhdark 6dbf9a1
fix typo in class name
jhdark f629ddf
mms test for mismatching mesh
jhdark 0217ca1
update dt value rather than create new object
jhdark 71f470d
new dt property
jhdark c27b287
fix typo
jhdark 899ea52
move progress bar alteration to setter
jhdark b6da93a
fix typo in regex
jhdark 3eae394
use previously defined function
jhdark 81f4e98
fix typo in docs
jhdark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| import tqdm.autonotebook | ||
| from dolfinx import fem | ||
|
|
||
| from festim.heat_transfer_problem import HeatTransferProblem | ||
| from festim.helpers import as_fenics_constant, nmm_interpolate | ||
| from festim.hydrogen_transport_problem import ( | ||
| HTransportProblemDiscontinuous, | ||
| HTransportProblemPenalty, | ||
| HydrogenTransportProblem, | ||
| ) | ||
| from festim.problem_change_of_var import HydrogenTransportProblemDiscontinuousChangeVar | ||
|
|
||
|
|
||
| class CoupledTransientHeatTransferHydrogenTransport: | ||
| """ | ||
| Coupled heat transfer and hydrogen transport transient problem | ||
|
|
||
| Args: | ||
| heat_problem: the heat transfer problem | ||
| hydrogen_problem: the hydrogen transport problem | ||
|
|
||
| Attributes: | ||
| heat_problem: the heat transfer problem | ||
| hydrogen_problem: the hydrogen transport problem | ||
| non_matching_meshes: True if the meshes in the heat_problem and hydrogen_problem | ||
| are not matching | ||
|
|
||
| Examples: | ||
| .. highlight:: python | ||
| .. code-block:: python | ||
|
|
||
| import festim as F | ||
|
|
||
| my_heat_transfer_model = F.HeatTransferProblem( | ||
| mesh=F.Mesh(...), | ||
| subdomains=[F.Subdomain(...)], | ||
| ... | ||
| ) | ||
|
|
||
| my_h_transport_model = F.HydrogenTransportProblem( | ||
| mesh=F.Mesh(...), | ||
| subdomains=[F.Subdomain(...)], | ||
| species=[F.Species(name="H"), F.Species(name="Trap")], | ||
| ... | ||
| ) | ||
|
|
||
| coupled_problem = F.CoupledHeatTransferHydrogenTransport( | ||
| heat_problem=my_heat_transfer_model, | ||
| hydrogen_problem=my_h_transport_model, | ||
| ) | ||
|
|
||
| """ | ||
|
|
||
| heat_problem: HeatTransferProblem | ||
| hydrogen_problem: HydrogenTransportProblem | ||
|
|
||
| non_matching_meshes: bool | ||
|
|
||
| def __init__( | ||
| self, | ||
| heat_problem: HeatTransferProblem, | ||
| hydrogen_problem: HydrogenTransportProblem, | ||
| ) -> None: | ||
| self.heat_problem = heat_problem | ||
| self.hydrogen_problem = hydrogen_problem | ||
|
|
||
| if ( | ||
| not self.heat_problem.settings.transient | ||
| or not self.hydrogen_problem.settings.transient | ||
| ): | ||
| raise TypeError( | ||
| "Both the heat and hydrogen problems must be set to transient" | ||
| ) | ||
|
|
||
| @property | ||
| def heat_problem(self): | ||
| return self._heat_problem | ||
|
|
||
| @heat_problem.setter | ||
| def heat_problem(self, value): | ||
| if not isinstance(value, HeatTransferProblem): | ||
| raise TypeError("heat_problem must be a festim.HeatTransferProblem object") | ||
| value.show_progress_bar = False | ||
| self._heat_problem = value | ||
|
|
||
| @property | ||
| def hydrogen_problem(self): | ||
| return self._hydrogen_problem | ||
|
|
||
| @hydrogen_problem.setter | ||
| def hydrogen_problem(self, value): | ||
| if isinstance( | ||
| value, | ||
| HTransportProblemDiscontinuous | ||
| | HTransportProblemPenalty | ||
| | HydrogenTransportProblemDiscontinuousChangeVar, | ||
| ): | ||
| raise NotImplementedError( | ||
| "Coupled heat transfer - hydrogen transport simulations with " | ||
| "HydrogenTransportProblemDiscontinuousChangeVar, " | ||
| "HTransportProblemPenalty or" | ||
| "HydrogenTransportProblemDiscontinuousChangeVar, " | ||
| "not currently supported" | ||
| ) | ||
| elif not isinstance(value, HydrogenTransportProblem): | ||
| raise TypeError( | ||
| "hydrogen_problem must be a festim.HydrogenTransportProblem object" | ||
| ) | ||
| self._hydrogen_problem = value | ||
|
|
||
| @property | ||
| def non_matching_meshes(self): | ||
| return self.heat_problem.mesh.mesh != self.hydrogen_problem.mesh.mesh | ||
|
|
||
| def initialise(self): | ||
| # make sure both problems have the same initial time step and final time, | ||
| # use minimal initial value of the two and maximal final time of the two | ||
| min_initial_dt = min( | ||
| self.heat_problem.settings.stepsize.initial_value, | ||
| self.hydrogen_problem.settings.stepsize.initial_value, | ||
| ) | ||
| self.heat_problem.settings.stepsize.initial_value = min_initial_dt | ||
| self.hydrogen_problem.settings.stepsize.initial_value = min_initial_dt | ||
|
|
||
| if ( | ||
| self.heat_problem.settings.final_time | ||
| != self.hydrogen_problem.settings.final_time | ||
| ): | ||
| raise ValueError( | ||
| "Final time values in the heat transfer and hydrogen transport " | ||
| "model must be the same" | ||
| ) | ||
|
|
||
| self.heat_problem.initialise() | ||
|
|
||
| if self.non_matching_meshes: | ||
| V = fem.functionspace(self.hydrogen_problem.mesh.mesh, ("P", 1)) | ||
| T_func = fem.Function(V) | ||
|
|
||
| nmm_interpolate(T_func, self.heat_problem.u) | ||
|
|
||
| self.hydrogen_problem.temperature = T_func | ||
| else: | ||
| self.hydrogen_problem.temperature = self.heat_problem.u | ||
|
|
||
| self.hydrogen_problem.initialise() | ||
|
|
||
| def iterate(self): | ||
| self.heat_problem.iterate() | ||
|
|
||
| if self.non_matching_meshes: | ||
| nmm_interpolate( | ||
| self.hydrogen_problem.temperature_fenics, self.heat_problem.u | ||
| ) | ||
|
|
||
| self.hydrogen_problem.iterate() | ||
|
|
||
| # use the same time step for both problems, use minimum of the two | ||
| next_dt_value = min( | ||
| float(self.hydrogen_problem.dt), float(self.heat_problem.dt) | ||
| ) | ||
| self.heat_problem.dt.value = next_dt_value | ||
| self.hydrogen_problem.dt.value = next_dt_value | ||
|
|
||
| def run(self): | ||
| if self.hydrogen_problem.show_progress_bar: | ||
| self.hydrogen_problem.progress_bar = tqdm.autonotebook.tqdm( | ||
| desc=f"Solving {self.__class__.__name__}", | ||
| total=self.hydrogen_problem.settings.final_time, | ||
| unit_scale=True, | ||
| ) | ||
|
|
||
| while self.hydrogen_problem.t.value < self.hydrogen_problem.settings.final_time: | ||
| self.iterate() | ||
|
|
||
| if self.hydrogen_problem.show_progress_bar: | ||
| self.hydrogen_problem.progress_bar.refresh() | ||
| self.hydrogen_problem.progress_bar.close() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.