Skip to content

Commit

Permalink
Merge pull request #500 from RemDelaporteMathurin/tempfromxdmf-transient
Browse files Browse the repository at this point in the history
TemperatureFromXDMF with transient h transport cases
  • Loading branch information
jhdark authored Jul 15, 2022
2 parents 3fb6cd8 + 11edf64 commit 13232e5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
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()

0 comments on commit 13232e5

Please sign in to comment.