# How to set initial temperature distribution from XDMF?

**URL:** <https://festim.discourse.group/t/how-to-set-initial-temperature-distribution-from-xdmf/17>\
**Category:** User Support\
**Created:** [December 3, 2023, 2:46pm UTC](https://festim.discourse.group/t/how-to-set-initial-temperature-distribution-from-xdmf/17 "2023-12-03T14:46:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![VVKulagin](https://yyz2.discourse-cdn.com/free1/user_avatar/festim.discourse.group/vvkulagin/32/51_2.png) [@VVKulagin](https://festim.discourse.group/u/VVKulagin)\
**Post date:** [December 3, 2023, 2:46pm UTC](https://festim.discourse.group/t/how-to-set-initial-temperature-distribution-from-xdmf/17/1 "2023-12-03T14:46:08Z")

</div>

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:

```auto
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:

```auto
my_model.initial_conditions = [
    F.InitialCondition(field="T", value = './results1/T.xdmf', label = 'temperature', time_step=0)
]

```

Throws an error.

---

<div class="post-metadata">

**Author:** ![remidm](https://yyz2.discourse-cdn.com/free1/user_avatar/festim.discourse.group/remidm/32/4_2.png) [@remidm](https://festim.discourse.group/u/remidm)\
**Post date:** [December 3, 2023, 3:12pm UTC](https://festim.discourse.group/t/how-to-set-initial-temperature-distribution-from-xdmf/17/2 "2023-12-03T15:12:11Z")

</div>

Hi @VVKulagin

This looks correct to me.

Could you provide the full error message?

---

<div class="post-metadata">

**Author:** ![VVKulagin](https://yyz2.discourse-cdn.com/free1/user_avatar/festim.discourse.group/vvkulagin/32/51_2.png) [@VVKulagin](https://festim.discourse.group/u/VVKulagin)\
**Post date:** [December 3, 2023, 3:29pm UTC](https://festim.discourse.group/t/how-to-set-initial-temperature-distribution-from-xdmf/17/3 "2023-12-03T15:29:22Z")

</div>

Hi @remidm. The output message is:

```auto
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'

```

---

<div class="post-metadata">

**Author:** ![remidm](https://yyz2.discourse-cdn.com/free1/user_avatar/festim.discourse.group/remidm/32/4_2.png) [@remidm](https://festim.discourse.group/u/remidm)\
**Post date:** [December 3, 2023, 3:37pm UTC](https://festim.discourse.group/t/how-to-set-initial-temperature-distribution-from-xdmf/17/4 "2023-12-03T15:37:00Z")

</div>

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:

> <https://github.com/festim-dev/FESTIM/blob/6364d4607aaae5e0e15fe9dd3daadd6c576b477d/festim/temperature/temperature_solver.py#L77-L80>

It doesn’t account for XDMF files (yet!).

Looking at `TemperatureFromXDMF` I think it shouldn’t be too hard to adapt:

> <https://github.com/festim-dev/FESTIM/blob/6364d4607aaae5e0e15fe9dd3daadd6c576b477d/festim/temperature/temperature_from_xdmf.py#L31-L42>

Feel free to open an issue on the Github repo!

Thanks for reporting

---

<div class="post-metadata">

**Author:** ![VVKulagin](https://yyz2.discourse-cdn.com/free1/user_avatar/festim.discourse.group/vvkulagin/32/51_2.png) [@VVKulagin](https://festim.discourse.group/u/VVKulagin)\
**Post date:** [December 7, 2023, 7:50pm UTC](https://festim.discourse.group/t/how-to-set-initial-temperature-distribution-from-xdmf/17/5 "2023-12-07T19:50:58Z")

</div>

This issue has been [solved](https://github.com/festim-dev/FESTIM/pull/662). New modification allows to set the initial condition for the Heat Transfer Problem from XDMF:

```auto
my_temp = F.HeatTransferProblem(
    ...,
    initial_value=F.InitialCondition("T", "filename.xdmf", "label", timestep=-1)
)

```
