-
Notifications
You must be signed in to change notification settings - Fork 25
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
Coupled transient heat transfer and hydrogen transport models #948
Open
jhdark
wants to merge
26
commits into
festim-dev:fenicsx
Choose a base branch
from
jhdark:coupled_heat_hydrogen
base: fenicsx
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+637
−34
Open
Changes from all commits
Commits
Show all changes
26 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 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 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 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,183 @@ | ||
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 CoupledtTransientHeatTransferHydrogenTransport: | ||
""" | ||
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 hydorgen_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") | ||
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 - hydorgen 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() | ||
|
||
self.heat_problem.show_progress_bar = False | ||
|
||
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 = as_fenics_constant( | ||
value=next_dt_value, mesh=self.heat_problem.mesh.mesh | ||
) | ||
self.hydrogen_problem.dt = as_fenics_constant( | ||
value=next_dt_value, mesh=self.hydrogen_problem.mesh.mesh | ||
) | ||
|
||
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 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 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 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.