TemperatureFromXDMF work in a conda environment

Hi all,

It seems that when trying to use the TemperatureFromXDMF class in combination with using chemical potential such as in the following script, seems to fail using festim 1.0.0 in a conda environment of fenics, but passes within a docker environment. I can make an accompanying issue on the repo too.

import fenics as f
import festim as F

mesh = f.UnitSquareMesh(10, 10)
V = f.FunctionSpace(mesh, "CG", 1)
expr = f.Expression("1 + x[0] + 2*x[1]", degree=2)
T = f.interpolate(expr, V)
# write function to temporary file
T_file = "T.xdmf"
f.XDMFFile(T_file).write_checkpoint(
    T, "T", 0, f.XDMFFile.Encoding.HDF5, append=False
)


my_mesh = F.Mesh()
my_mesh.mesh = mesh

my_model = F.Simulation()

my_model.mesh = my_mesh

my_model.materials = F.Materials(
    [
        F.Material(
            id=1,
            D_0=1.0,
            E_D=0.1,
            S_0=1.0,
            E_S=0.1,
)])

my_model.T = F.TemperatureFromXDMF(filename=T_file, label="T")

my_model.settings = F.Settings(
    transient=False,
    chemical_pot=True,
    absolute_tolerance=1e01,
    relative_tolerance=1e-06,
)

my_model.initialise()

Can you provide more information?( Error message, and how you created the conda environment.)

What is the festim version in each environment (conda, docker) with:

pip show festim

This PR should fix the bug. Once merged, we’ll release a patch version.

Yes of course,

The error message being raised:

Traceback (most recent call last):
  File "/home/jdark/repos/FESTIM-review/gallery/breeding_blanket/mwe.py", line 41, in <module>
    my_model.initialise()
  File "/home/jdark/anaconda3/envs/festim-env/lib/python3.11/site-packages/festim/generic_simulation.py", line 255, in initialise
    if self.T.is_steady_state():
       ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jdark/anaconda3/envs/festim-env/lib/python3.11/site-packages/festim/temperature/temperature.py", line 54, in is_steady_state
    return "t" not in sp.printing.ccode(self.value)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jdark/anaconda3/envs/festim-env/lib/python3.11/site-packages/sympy/printing/codeprinter.py", line 741, in ccode
    return c_code_printers[standard.lower()](settings).doprint(expr, assign_to)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jdark/anaconda3/envs/festim-env/lib/python3.11/site-packages/sympy/printing/codeprinter.py", line 155, in doprint
    expr = self._handle_UnevaluatedExpr(expr)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jdark/anaconda3/envs/festim-env/lib/python3.11/site-packages/sympy/printing/codeprinter.py", line 115, in _handle_UnevaluatedExpr
    return expr.replace(re, lambda arg: arg if isinstance(
           ^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'replace'

The version of festim in both cases was 1.0.0.

It seems from investigation this error is a result of the version of sympy within the docker container (1.1.1) vs that which is in the conda env (1.11.0). Specifically, changes to how the function sp.printing.ccode() operates.

FESTIM 1.1.1 was just released, can you try updating with

pip install festim==1.1.1

And confirm that the bug is fixed?

Can confirm it now works, cheers!