Initial conditions#

The initial conditions are essential to transient FESTIM simulations. They describe the mathematical problem at the beginning of the simulation. By default, the initial conditions are set to zero.

All initial conditions in FESTIM require a volume subdomain, defined with the festim.VolumeSubdomain class (see Volume Subdomains). They are passed to the problem as a list in its initial_conditions attribute.

my_model = F.HydrogenTransportProblem()

my_model.initial_conditions = [
    F.InitialConcentration(value=1e20, species=H, volume=my_vol),
]

Initial concentration#

The initial concentration of a species is set with the festim.InitialConcentration class.

from festim import InitialConcentration

my_ic = InitialConcentration(value=1e20, species=H, volume=my_vol)

The value can also be a function of space and temperature:

from festim import InitialConcentration

my_custom_value = lambda x, T: 1e20 * x[0] ** 2 + 1e15 * T

my_ic = InitialConcentration(value=my_custom_value, species=H, volume=my_vol)

Note

When defining custom functions for values, only the arguments x and T can be defined. Spatial coordinates can be referred to by their indices, such as x[0], x[1], and x[2], regardless of the coordinate system used. An initial condition cannot be a function of time: passing a function of t raises an error.

In a multi-material problem, one festim.InitialConcentration is needed per volume subdomain where the initial concentration is not zero.

Initial temperature#

For transient festim.HeatTransferProblem simulations, the initial temperature is set with the festim.InitialTemperature class and passed to the initial_condition attribute of the heat transfer problem (see Temperature).

from festim import InitialTemperature

my_heat_model = F.HeatTransferProblem()

my_heat_model.initial_condition = InitialTemperature(value=300, volume=my_vol)

The value can be a function of space:

from festim import InitialTemperature

my_ic = InitialTemperature(value=lambda x: 300 + 100 * x[0], volume=my_vol)

Restarting from a checkpoint#

Initial conditions can also be read from a previously written checkpoint file. This is useful when restarting a simulation. The field is read with festim.read_function_from_file() and passed as the value of the initial condition:

import festim as F

my_model = F.HydrogenTransportProblem()
my_model.mesh = F.Mesh1D(vertices=np.linspace(0, 1e-3, 100))

my_ic = F.InitialConcentration(
    value=F.read_function_from_file(
        filename="state.bp", name="H", timestamp=10.0, mesh=my_model.mesh.mesh
    ),
    species=H,
    volume=my_vol,
)

In the snippet above, the initial condition is read from the file state.bp. The name H is the name under which the field was written (the name of the species) and the timestamp 10.0 is the time at which it was written. The mesh argument is the mesh of the new simulation: the field is interpolated onto it, which also allows restarting on a different mesh than the one the checkpoint was written on.

Note

Only files written with an export in "checkpoint" format can be read back this way (see Checkpoints). The visualisation formats ("vtx", "vtkhdf", "xdmf") store values interpolated onto the mesh nodes and cannot be used to restart a simulation.

If the checkpoint was written with backend="h5py", the same backend must be passed to festim.read_function_from_file().