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

TemperatureFromXDMF with transient h transport cases #500

Merged
merged 7 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions FESTIM/temperature/temperature_from_xdmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ def create_functions(self, mesh):

self.T_n = f.Function(V, name="T_n")
self.T_n.assign(self.T)

def update(self, t):
"""Allows for the use of this class in transient h transport cases,
refer to issue #499
"""
pass
30 changes: 30 additions & 0 deletions Tests/unit/test_temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from ufl.core.multiindex import Index
from pathlib import Path
import pytest
import numpy as np


def test_formulation_heat_transfer_2_ids_per_mat():
Expand Down Expand Up @@ -136,3 +137,32 @@ def test_temperature_from_xdmf_label_checker(tmpdir):
# read file with wrong label specified
with pytest.raises(ValueError):
FESTIM.TemperatureFromXDMF(filename=str(Path(T_file)), label="coucou")


def test_temperature_from_xdmf_transient_case(tmpdir):
"""Test that the TemperatureFromXdmf class works in a transient
h transport case"""
# create temperature field xdmf
my_model = FESTIM.Simulation(log_level=20)
my_model.mesh = FESTIM.MeshFromVertices(vertices=np.linspace(0, 1, num=100))
my_model.materials = FESTIM.Materials([FESTIM.Material(1, 1, 1)])
my_model.T = FESTIM.Temperature(value=300)
my_model.settings = FESTIM.Settings(
transient=False,
absolute_tolerance=1e12,
relative_tolerance=1e-08,
)
my_model.initialise()
T = my_model.T.T
T_file = tmpdir.join("T.xdmf")
fenics.XDMFFile(str(Path(T_file))).write_checkpoint(
T, "T", 0, fenics.XDMFFile.Encoding.HDF5, append=False
)

# run transient simulation with TemperatureFromXDMF class
my_model.T = FESTIM.TemperatureFromXDMF(filename=str(Path(T_file)), label="T")
my_model.dt = FESTIM.Stepsize(initial_value=1)
my_model.settings.transient = True
my_model.settings.final_time = 10
my_model.initialise()
my_model.run()