Dolfinx_materials installation: demos not working

I would like to use dolfinx_materials, but am unable to run the demos provided.
When running the demos/hyperelasticity/heterogeneous_hyperelasticity.py, I get the following error:

WARNING:py.warnings:/home/joep/code/projects/phase-field-framework/dolfinx_materials/demos/hyperelasticity/heterogeneous_hyperelasticity.py:23: DeprecationWarning: This method is deprecated. Use FunctionSpace with an element shape argument instead
  V = fem.VectorFunctionSpace(domain, ("CG", order))

Traceback (most recent call last):
  File "/home/joep/.local/lib/python3.10/site-packages/dolfinx_materials/material/mfront.py", line 81, in __init__
    self.load_behaviour()
  File "/home/joep/.local/lib/python3.10/site-packages/dolfinx_materials/material/mfront.py", line 105, in load_behaviour
    self.is_finite_strain = mgis_bv.isStandardFiniteStrainBehaviour(
RuntimeError: LibrariesManager::loadLibrary: library 'dolfinx_materials/mfront_materials/src/libBehaviour.so' could not be loaded, (dolfinx_materials/mfront_materials/src/libBehaviour.so: cannot open shared object file: No such file or directory)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/joep/code/projects/phase-field-framework/dolfinx_materials/demos/hyperelasticity/heterogeneous_hyperelasticity.py", line 30, in <module>
    material = MFrontMaterial(
  File "/home/joep/.local/lib/python3.10/site-packages/dolfinx_materials/material/mfront.py", line 85, in __init__
    os.chdir(install_path)
FileNotFoundError: [Errno 2] No such file or directory: 'dolfinx_materials/mfront_materials/'

And when running the plane_elastoplasticity.py demo:

WARNING:py.warnings:/home/joep/code/projects/phase-field-framework/dolfinx_materials/demos/elastoplasticity/plane_elastoplasticity.py:66: DeprecationWarning: This method is deprecated. Use FunctionSpace with an element shape argument instead
  V = fem.VectorFunctionSpace(domain, ("CG", order))

Traceback (most recent call last):
  File "/home/joep/code/projects/phase-field-framework/dolfinx_materials/demos/elastoplasticity/plane_elastoplasticity.py", line 125, in <module>
    qmap = QuadratureMap(domain, deg_quad, material)
  File "/home/joep/.local/lib/python3.10/site-packages/dolfinx_materials/quadrature_map.py", line 98, in __init__
    self.update_material_properties()
  File "/home/joep/.local/lib/python3.10/site-packages/dolfinx_materials/quadrature_map.py", line 134, in update_material_properties
    fs_type = get_function_space_type(mat_prop)
  File "/home/joep/.local/lib/python3.10/site-packages/dolfinx_materials/utils.py", line 69, in get_function_space_type
    shape = x.ufl_shape
AttributeError: 'LinearElasticIsotropic' object has no attribute 'ufl_shape'

I’ve had trouble installing mgis before (and still haven’t managed to get it working in a conda environment), but thought that it is done correctly for my system python. I’m using dolfinx version 0.7.3.
Here are my dolfinx site-packages, where it is clear that the scripts seen from the error above are not present:

Is this still an error with my installation? Any help would be much appreciated!

cc @bleyerj who maintains the package.

1 Like

The project has moved to:

You should be able to run the first demo if MFront and mgis are properly installed
The second demo based on Python implementation is currently broken. A fix will be pushed soon when adding the integration with JAX.

Thank you for the reply.
I believe my MFront and mgis are correctly installed, but I’m probably doing something wrong. I was wondering if it can be related to the versions of the packages?

I’ve reinstalled them now with the following (commands from inside the folder):
Downloaded TFEL-4.2.0cmake .sudo makesudo make install
Downloaded MFrontGIS-2.2cmake . -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local/ -Denable-c-bindings=ON -Denable-fortran-bindings=OFF -Denable-python-bindings=ON -Denable-website=ON -DPython_ADDITIONAL_VERSIONS=3.10 -DPYTHON_EXECUTABLE=/usr/bin/python -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.10.so -DPYTHON_INCLUDE_DIR=/usr/include/python3.10sudo makesudo make install
Downloaded dolfinx_materials, (main branch, giving version -0.2.1) → pip install .
Added to .bashrc: export PYTHONPATH=/usr/local/lib/python3.10/site-packages/

These happen without any sign that something went wrong.

But the demo still gives an error that points towards an incompatibility with my mgis installation:

dolfinx_materials/demos/hyperelasticity$ python heterogeneous_hyperelasticity.py 
Traceback (most recent call last):
  File "/home/joep/code/projects/phase-field-framework/dolfinx_materials/demos/hyperelasticity/heterogeneous_hyperelasticity.py", line 9, in <module>
    from dolfinx_materials.quadrature_map import QuadratureMap
  File "/home/joep/.local/lib/python3.10/site-packages/dolfinx_materials/quadrature_map.py", line 16, in <module>
    from .material import Material
  File "/home/joep/.local/lib/python3.10/site-packages/dolfinx_materials/material/__init__.py", line 10, in <module>
    from .mfront import MFrontMaterial
  File "/home/joep/.local/lib/python3.10/site-packages/dolfinx_materials/material/mfront.py", line 10, in <module>
    import mgis.behaviour as mgis_bv
ImportError: /usr/local/lib/python3.10/site-packages/mgis/behaviour.so: undefined symbol: _ZN4mgis9behaviour25executeInitializeFunctionERNS_10ThreadPoolERNS0_19MaterialDataManagerESt17basic_string_viewIcSt11char_traitsIcEESt4spanIKdLm18446744073709551615EE

EDIT: since this is not related to dolfinx_materials but to mgis, I’ve asked my question to mgis instead.

I’m fairly sure I’ve installed mgis & mfront correctly now, but am still getting the same error as I was initially.
I’ve created a docker environment as follows:

Bootstrap: docker
From: ubuntu:22.04

%environment

%files
  ./dolfinx_zips/tfel_4.2.0.zip /home/user/
  ./dolfinx_zips/mgis_2.2.zip /home/user/
  ./dolfinx_zips/dolfinx_materials-main.zip /home/user/


%post
 
  apt-get update -y
  apt-get install -y software-properties-common
  apt install -y unzip zlib1g-dev libreadline-dev freeglut3-dev build-essential g++ libboost-all-dev
  apt-get update && apt-get -y install cmake protobuf-compiler
  
  DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
      python3 \
      python3-tk \
      python3-pip \
      python3-dev

  rm -rf /var/lib/apt/lists/*
  
  pip3 install numpy
  
  
  cd /home/user/
  unzip tfel_4.2.0.zip
  (cd thelfer-tfel-cd70cc7 && cmake . && make && make install)
  
  cd /home/user/
  unzip mgis_2.2.zip
  (cd MFrontGenericInterfaceSupport-rliv-2.2/ && cmake . -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local/ -Denable-c-bindings=ON -Denable-fortran-bindings=OFF -Denable-python-bindings=ON -Denable-website=ON && make && make install)
  
  add-apt-repository ppa:fenics-packages/fenics
  apt update
  apt install -y fenicsx
  
  cd /home/user/
  unzip dolfinx_materials-main.zip
  cd ./dolfinx_materials-main
  pip3 install .  

(I hope the downloaded zip folders are clear).
Running the environment, calling python and loading mgis modules works fine.
However, when (in the environment) I go to /home/user/dolfinx_materials-main/demos/hyperelasticity/ and call python3 heterogeneous_hyperelasticity.py I get the same error as in my original question:

RuntimeError: LibrariesManager::loadLibrary: library 'dolfinx_materials/mfront_materials/src/libBehaviour.so' could not be loaded, (dolfinx_materials/mfront_materials/src/libBehaviour.so: cannot open shared object file: No such file or directory)

@bleyerj is calling pip install . inside the dolfinx_materials folder the correct way to install it? Are there additional paths that need to be set for it to find the other libraries? Can existing system installations of mgis or dolfinx_materials or system variables prevent it from being correct?

I appreciate the support

material = MFrontMaterial(
    "dolfinx_materials/mfront_materials/src/libBehaviour.so",
    "Ogden",
)

supposes that you have compiled the mfront behavior Ogden.mfront in ./dolfinx_materials/mfront_materials.
Have you managed to compile it with

mfront --obuild --interface=generic Ogden.mfront

Besides, you may need to change the path in MFrontMaterial depending on where you are executing your script.

1 Like

Ahh I see! That makes it work, thank you.
You mentioned that the other demo is broken - are the ‘python_materials’ broken in general, or is it something specific about the demo?

Yes it is general, as the Python loop is really inefficient, I plan to rely on JAX to use auto-vectorization and JIT. But it is almost ready.

That is good to know. Can I ask if almost means you think it will be in the order of weeks or more like months? Sorry if I come across as pushy, I’m just curious.

More likely 1 or 2 weeks

1 Like