# Changing temperature settings at a certain time in the simulation

**URL:** <https://festim.discourse.group/t/changing-temperature-settings-at-a-certain-time-in-the-simulation/73>\
**Category:** User Support\
**Created:** [September 10, 2024, 1:11pm UTC](https://festim.discourse.group/t/changing-temperature-settings-at-a-certain-time-in-the-simulation/73 "2024-09-10T13:11:46Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamryo](https://yyz2.discourse-cdn.com/free1/user_avatar/festim.discourse.group/iamryo/32/60_2.png) [@iamryo](https://festim.discourse.group/u/iamryo)\
**Post date:** [September 10, 2024, 1:11pm UTC](https://festim.discourse.group/t/changing-temperature-settings-at-a-certain-time-in-the-simulation/73/1 "2024-09-10T13:11:46Z")

</div>

Hi! 🙂

I am trying to reproduct a series of simulations from plasma irradiation to TDS.  
But, I faced one problem.

During plasma irradiation, sample temperature is transient settings.

```auto
model.T = F.HeatTransferProblem(
    transient=True, 
    initial_condition= F.InitialCondition(field="T", value=300)
)

```

On the other hand, in the TDS process after plasma irradiation, I’d like to raise the temperature of the sample uniformly throughout like  
`model.T = F.Temperature(value = 300 + t)` .  
Therefore, the sample temperature does not need to be transient in the TDS process.

Is there any way to use a transient temperature during plasma irradiation and a non-transient temperature during TDS?

---

<div class="post-metadata">

**Author:** ![jhdark](https://yyz2.discourse-cdn.com/free1/user_avatar/festim.discourse.group/jhdark/32/13_2.png) [@jhdark](https://festim.discourse.group/u/jhdark)\
**Post date:** [September 10, 2024, 1:59pm UTC](https://festim.discourse.group/t/changing-temperature-settings-at-a-certain-time-in-the-simulation/73/2 "2024-09-10T13:59:51Z")

</div>

Yes this is absolutely possible, you can access the simulation time in FESTIM using `F.t`.

Say you have an implantation temperature of 300K, exposure for 100s, then start a TDS with a temperature ramp of 1 K/min, it would look like this:

```auto
implantation_temperature = 300 # K
start_tds = 100 # s
temperature_ramp = 1/60 # K/s

model.T = F.Temperature(
    value=sp.Piecewise(
        (implantation_temperature, F.t < start_tds),
        (implantation_temperature+ temperature_ramp * (F.t - start_tds), True),
    )
)

```

You can check out an example of modelling TDS in the new : [V&V report](https://festim-vv-report.readthedocs.io/en/latest/validation/thermodesorption_spectra/ogorodnikova/ogorodnikova-tds.html).

And we have an example in the workshop [task 10](https://github.com/festim-dev/FESTIM-workshop/blob/main/tasks/task10.ipynb)

---

<div class="post-metadata">

**Author:** ![iamryo](https://yyz2.discourse-cdn.com/free1/user_avatar/festim.discourse.group/iamryo/32/60_2.png) [@iamryo](https://festim.discourse.group/u/iamryo)\
**Post date:** [September 11, 2024, 2:42am UTC](https://festim.discourse.group/t/changing-temperature-settings-at-a-certain-time-in-the-simulation/73/3 "2024-09-11T02:42:56Z")

</div>

Hi! Thank you for your replying 🙂

It’s certainly a powerful method. However, what I’d like to do is a little different.

What I want to do is like this: (Note that this code doesn’t actually work)

```auto
implantation_temperature = 300 # K
start_tds = 100 # s
temperature_ramp = 1/60 # K/s

if F.t < start_tds:
    condition = F.HeatTransferProblem(transient=True, initial_condition=F.InitialCondition(field="T", value=300))
elif F.t >= start_tds:
    condition = F.Temperature(value=implantation_temperature+ temperature_ramp * (F.t - start_tds))

model.T = condition

```

For example, such a condition is required in the following cases: During plasma irradiation, it is necessary to resolve transient temperature changes, and the subsequent TDS step requires a constant temperature increase condition.

Is there any way to make such conditions possible?

---

<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:** [September 11, 2024, 10:27am UTC](https://festim.discourse.group/t/changing-temperature-settings-at-a-certain-time-in-the-simulation/73/4 "2024-09-11T10:27:18Z")

</div>

Hi @iamryo!

What are the boundary conditions for the `HeatTransferProblem`?

Meanwhile, one possible solution is to split your problem into two (i.e. two different FESTIM models):

1. Implantation phase with `F.HeatTransferProblem`: At the end, you could write your final profiles of solute/trapped species to XDMF
2. TDS phase with `F.Temperature`: the profiles then could be read from XDMF and used as initial condition for the corresponding fields

---

<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:** [September 11, 2024, 11:58am UTC](https://festim.discourse.group/t/changing-temperature-settings-at-a-certain-time-in-the-simulation/73/5 "2024-09-11T11:58:17Z")

</div>

Hi @iamryo , if I understand correctly, would want to start with a `HeatTransferProblem` and then switch to a `F.Temperature`.

I can see a hacky way of doing this by manually changing the `model.T` attribute in the middle of the simulation, but before doing this I guess it’s important to see if the heat transfer problem can be replaced by a `Temperature` object.

What is the size of your sample? What material? is it a 1D sim? what BCs? etc.

---

<div class="post-metadata">

**Author:** ![iamryo](https://yyz2.discourse-cdn.com/free1/user_avatar/festim.discourse.group/iamryo/32/60_2.png) [@iamryo](https://festim.discourse.group/u/iamryo)\
**Post date:** [September 13, 2024, 3:42pm UTC](https://festim.discourse.group/t/changing-temperature-settings-at-a-certain-time-in-the-simulation/73/6 "2024-09-13T15:42:04Z")

</div>

Hi @VVKulagin! Thank you for your replying 🙂

> [@VVKulagin](#):
>
> What are the boundary conditions for the `HeatTransferProblem`?

With 1D FESTIM simulation, I am trying to reproduce an experimental sample in which plasma and pulsed heating were performed simultaneously.  
Therefore, on the front side, we use `F.CustomFlux()`, which combines heat flux from plasma and heating from pulses.  
On the reverse side, `F.ConvectiveFlux()` is used to simulate water cooling

The boundary conditions are as follows (Detailed parameters are not written):

```auto
def bc_1(T, solute, q_pulse):
    q_plasma = # W/m2
    T_chamber = 300 
    emi_W = 0.4
    sigma = 5.67e-8 # W/m2/K4
    q_radiation = emi_W*sigma*(T **4-T_chamber** 4)
    return q_pulse + q_plasma - q_radiation

def pulse(t):
    a = 
    b = 
    c = 
    d = 
    amp = 
    t = 
    S = 
    r = 
    y = (1-r) * amp * a * (1 + sp.exp(-(t-b)/c))**(-1) * sp.exp(-(t-b)/d) * S**(-1)
    return y

model_1d.boundary_conditions = [
    F.CustomFlux(surfaces=1, function=bc_1, field="T", q_pulse=pulse(F.t)),
    F.ConvectiveFlux(h_coeff= , T_ext=300, surfaces=2)
]

```

> [@VVKulagin](#):
>
> Meanwhile, one possible solution is to split your problem into two (i.e. two different FESTIM models):

This is a great idea!

> [@VVKulagin](#):
>
> 1. Implantation phase with `F.HeatTransferProblem`: At the end, you could write your final profiles of solute/trapped species to XDMF
> 2. TDS phase with `F.Temperature`: the profiles then could be read from XDMF and used as initial condition for the corresponding fields

If a profile exported to XDMF in the implantation phase is used in the TDS phase, Is a trapped concentration input as an initial condition, treated as “trapped in a defect”? Or is it treated as a mobile condition?

---

<div class="post-metadata">

**Author:** ![iamryo](https://yyz2.discourse-cdn.com/free1/user_avatar/festim.discourse.group/iamryo/32/60_2.png) [@iamryo](https://festim.discourse.group/u/iamryo)\
**Post date:** [September 13, 2024, 3:54pm UTC](https://festim.discourse.group/t/changing-temperature-settings-at-a-certain-time-in-the-simulation/73/7 "2024-09-13T15:54:24Z")

</div>

Hi @remidm! Thank you as always 🙂

> [@remidm](#):
>
> would want to start with a `HeatTransferProblem` and then switch to a `F.Temperature`.

Yes, that is correct. Glad you got my thoughts.

It may be difficult to replace the heat transfer problem with a Temperature object because of the boundary conditions as mentioned in the previous reply to @VVKulagin.

---

<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:** [September 13, 2024, 4:03pm UTC](https://festim.discourse.group/t/changing-temperature-settings-at-a-certain-time-in-the-simulation/73/8 "2024-09-13T16:03:17Z")

</div>

You can export each species to individual XDMF-files. Then, set [initial conditions](https://festim.readthedocs.io/en/latest/api/initial_condition.html) for each species. Consider:

```auto
model.initial_conditions = [
    F.InitialCondition(field='solute', 
                        value='filename_solute.xdmf', 
                        label = 'label_solute', 
                        time_step=-1),
    F.InitialCondition(field='1', 
                        value='filename_trap1.xdmf', 
                        label = 'label_trap1', 
                        time_step=-1),
    F.InitialCondition(field='2', 
                        value='filename_trap2.xdmf', 
                        label = 'label_trap2', 
                        time_step=-1),
    ...
]

```

Therefore, the profile of solute species will be set for solute species and trapped profiles for trapped in defects species. Does it help?

---

<div class="post-metadata">

**Author:** ![iamryo](https://yyz2.discourse-cdn.com/free1/user_avatar/festim.discourse.group/iamryo/32/60_2.png) [@iamryo](https://festim.discourse.group/u/iamryo)\
**Post date:** [September 15, 2024, 6:50am UTC](https://festim.discourse.group/t/changing-temperature-settings-at-a-certain-time-in-the-simulation/73/9 "2024-09-15T06:50:31Z")

</div>

Thank you, this is very informative!  
I am surprised to see such a useful feature.

I will try the following things you suggested

> [@VVKulagin](#):
>
> split your problem into two (i.e. two different FESTIM models):
> 
> 1. Implantation phase with `F.HeatTransferProblem`: At the end, you could write your final profiles of solute/trapped species to XDMF
> 2. TDS phase with `F.Temperature`: the profiles then could be read from XDMF and used as initial condition for the corresponding fields

> [@VVKulagin](#):
>
> You can export each species to individual XDMF-files. Then, set [initial conditions](https://festim.readthedocs.io/en/latest/api/initial_condition.html) for each species.

Thank you very much!

---

<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:** [September 16, 2024, 4:14pm UTC](https://festim.discourse.group/t/changing-temperature-settings-at-a-certain-time-in-the-simulation/73/10 "2024-09-16T16:14:41Z")

</div>

@iamryo just for your information, you can set multiple flux bcs on a single surface instead of bundling everything in one object like you do.

For instance:

```python
def radiation_flux_value(T, solute):
    T_chamber = 300 
    emi_W = 0.4
    sigma = 5.67e-8 # W/m2/K4
    return -emi_W*sigma*(T **4-T_chamber** 4)

radiation_flux = F.CustomFlux(surfaces=1, function=radiation_flux_value, field="T")
heat_flux_from_plasma = F.HeatFlux(value=q_plasma, surfaces=1)
pulsed_heat_flux = F.HeatFlux(
    value=(1-r) * amp * a * (1 + sp.exp(-(F.t-b)/c))**(-1) * sp.exp(-(F.t-b)/d) * S**(-1),
    surfaces=1
)

model_1d.boundary_conditions = [
    radiation_flux,
    heat_flux_from_plasma,
    pulsed_heat_flux,
    F.ConvectiveFlux(h_coeff= , T_ext=300, surfaces=2)
]

```

This will help simplify your code a bit.

---

<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:** [November 8, 2024, 2:11pm UTC](https://festim.discourse.group/t/changing-temperature-settings-at-a-certain-time-in-the-simulation/73/11 "2024-11-08T14:11:09Z")

</div>

@iamryo have you been able to fix your issue?

---

<div class="post-metadata">

**Author:** ![iamryo](https://yyz2.discourse-cdn.com/free1/user_avatar/festim.discourse.group/iamryo/32/60_2.png) [@iamryo](https://festim.discourse.group/u/iamryo)\
**Post date:** [December 21, 2024, 6:53am UTC](https://festim.discourse.group/t/changing-temperature-settings-at-a-certain-time-in-the-simulation/73/12 "2024-12-21T06:53:56Z")

</div>

Hi @remidm @VVKulagin .  
Sorry for my late reply.  
The FESTIM model split in two worked fine!  
Thank you for the helpful advice 🙂
