Hello, everyone! Assume, I have a FESTIM model that solves a time-dependent problem (heat transfer + diffusion). I export profiles of temperature, solute concentration, trapped concentration on the last timestep with:
XDMF = [F.XDMFExport(
field="solute",
filename=results_folder + "/mobile.xdmf",
checkpoint=True,
mode="last",
),
F.XDMFExport(
field="1",
filename=results_folder + "/trapped.xdmf",
checkpoint=True,
mode="last",
),
F.XDMFExport(
field="T",
filename=results_folder + "/T.xdmf",
checkpoint=True,
mode="last",
)]
I can successfully set initial conditions for trapped and solute concentrations, but not really understand how to do it for the heat transfer problem. The use of:
my_model.initial_conditions = [
F.InitialCondition(field="T", value = './results1/T.xdmf', label = 'temperature', time_step=0)
]
Throws an error.
remidm
December 3, 2023, 3:12pm
2
Hi @VVKulagin
This looks correct to me.
Could you provide the full error message?
Hi @remidm . The output message is:
Defining variational problem heat transfers
Defining initial values
Traceback (most recent call last):
File "/home/vvkulagin/FESTIM/TEST/test.py", line 278, in <module>
my_model.initialise()
File "/home/vvkulagin/anaconda3/envs/festim-env/lib/python3.12/site-packages/festim/generic_simulation.py", line 270, in initialise
self.h_transport_problem.initialise(self.mesh, self.materials, self.dt)
File "/home/vvkulagin/anaconda3/envs/festim-env/lib/python3.12/site-packages/festim/h_transport_problem.py", line 64, in initialise
self.initialise_concentrations()
File "/home/vvkulagin/anaconda3/envs/festim-env/lib/python3.12/site-packages/festim/h_transport_problem.py", line 141, in initialise_concentrations
component = field_to_component[ini.field]
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
KeyError: 'T'
remidm
December 3, 2023, 3:37pm
4
Having a look at the code, it seems that this (initial conditions for temperature from XDMF) is not possible at the moment.
This is the code for the initialisation of temperature:
if self.transient:
ccode_T_ini = sp.printing.ccode(self.initial_value)
self.initial_value = f.Expression(ccode_T_ini, degree=2, t=0)
self.T_n.assign(f.interpolate(self.initial_value, V))
It doesn’t account for XDMF files (yet!).
Looking at TemperatureFromXDMF
I think it shouldn’t be too hard to adapt:
def create_functions(self, mesh):
"""Creates functions self.T, self.T_n
Args:
mesh (festim.Mesh): the mesh
"""
V = f.FunctionSpace(mesh.mesh, "CG", 1)
self.T = f.Function(V, name="T")
f.XDMFFile(self.filename).read_checkpoint(self.T, self.label, -1)
self.T_n = f.Function(V, name="T_n")
self.T_n.assign(self.T)
Feel free to open an issue on the Github repo!
Thanks for reporting
This issue has been solved . New modification allows to set the initial condition for the Heat Transfer Problem from XDMF:
my_temp = F.HeatTransferProblem(
...,
initial_value=F.InitialCondition("T", "filename.xdmf", "label", timestep=-1)
)
1 Like