festim-dev / FESTIM

Coupled hydrogen/tritium transport and heat transfer modelling using FEniCS
https://festim.readthedocs.io/en/stable/
Apache License 2.0
90 stars 23 forks source link

`InitialConditionFromXDMF` class #845

Open RemDelaporteMathurin opened 2 months ago

RemDelaporteMathurin commented 2 months ago

Currently we have the InitialCondition class that can be used for initialising fields with mathematical expressions or XDMF files.

From an mathematical expression:

my_ic = F.InitialCondition(value=F.x**2 + F.y**2, field=0)

From a XDMFfile:

my_ic = F.InitialCondition(
    value="ic_file.xdmf",
    label="mobile",
    time_step=-1,
    field=0
)

We then look check if value is a string and if it ends by .xdmf and initialise fields accordingly: https://github.com/festim-dev/FESTIM/blob/31864c86690750ab854942c82110c3f711187246/festim/concentration/concentration.py#L43-L47

https://github.com/festim-dev/FESTIM/blob/31864c86690750ab854942c82110c3f711187246/festim/temperature/temperature_solver.py#L114-L122

Proposition

We could have a new class InitialConditionFromXDMF and remove the arguments label, time_step from InitialCondition.

This would make things less confusing and would make the implementation more straightforward, we now just have to check for the type of the initial condition object:

if isintance(initial_condition, F.InitialConditon):
    # do something
elif isinstance(initial_condition, F.InitialConditionFromXDMF):
    # do something else