Plasticity in FEniCSX

Hi everyone,

I’m trying to model plasticity in FEniCSX and I can’t find any simple examples of it anywhere. All I’m trying to achieve is a simple uniaxial tension test by simply changing the DBCs on one side, under linear hardening. The only example of plasticity in FEniCSX I can find here and run is @tianjuxue 's immense program for thermo-elasto-plasticity, which is hard to prune down to the basics of what I’m looking for.

I’ve been attempting to merge the Linear Plasticity model from @bleyerj with Changing DBCs from @marchirschvogel , but it’s proving very difficult.

Any pointers or links to good examples would be greatly appreciated.

Kind regards,

Magnus

Consider reading fenicsmechanics Plasticity on BitBucket

See: https://github.com/michalhabera/dolfiny/tree/master/demo/plasticity

Hi, I tried running the demo but I got the error -

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
/tmp/ipykernel_1157/2608910224.py in <module>
----> 1 import dolfiny

ModuleNotFoundError: No module named 'dolfiny'

when trying to import dolfiny.
I tried installing it with pip3 install dolfiny but met with this error-

ERROR: Could not find a version that satisfies the requirement dolfiny (from versions: none)
ERROR: No matching distribution found for dolfiny

Thanks.
EDIT: I am also interested in knowing the mathematics behind using all the relations therefore I request to kindly provide the reference also.

You need to install dolfiny, see the installation section of: GitHub - michalhabera/dolfiny: Dolfin-y, high level wrappers for dolfin-x, the FEniCS library

I did try to install using pip3 install dolfiny command as mentioned in Installation section but got the error -

ERROR: Could not find a version that satisfies the requirement dolfiny (from versions: none)
ERROR: No matching distribution found for dolfiny

You Need to clone the repo, go to the root of the repo and call pip3 install . or python -m pip install . as stated in the text.

1 Like

Thanks, now I am able to import dolfiny but when I’m trying to write mesh and meshtags to XDMF file using the code -

# Write mesh and meshtags to file
with dolfiny.io.XDMFFile(comm, f"{name}.xdmf", "w") as ofile:
    ofile.write_mesh_meshtags(mesh, mts)

This error appears -

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_1354/205208207.py in <module>
      1 # Write mesh and meshtags to file
      2 with dolfiny.io.XDMFFile(comm, f"{name}.xdmf", "w") as ofile:
----> 3     ofile.write_mesh_meshtags(mesh, mts)

~/.local/lib/python3.10/site-packages/dolfiny/io.py in write_mesh_meshtags(self, mesh, mts)
     35         for mt in mts.values():
     36             mesh.topology.create_connectivity(mt.dim, mesh.topology.dim)
---> 37             self.write_meshtags(mt, mesh.geometry)
     38 
     39     def read_mesh_meshtags(self, mesh_name='mesh'):

TypeError: write_meshtags(): incompatible function arguments. The following argument types are supported:
    1. (self: dolfinx.cpp.io.XDMFFile, meshtags: dolfinx.cpp.mesh.MeshTags_int32, geometry_xpath: str = '/Xdmf/Domain/Grid/Geometry', xpath: str = '/Xdmf/Domain') -> None

Invoked with: <dolfiny.io.XDMFFile object at 0x7fe898403ec0>, <dolfinx.cpp.mesh.MeshTags_int32 object at 0x7fe843958fb0>, <dolfinx.cpp.mesh.Geometry object at 0x7fe843adf170>

Do I have to write it separately, mesh and meshtags ?

You need to install the release of DOLFINy that is compatible with DOLFINx.
If you have v0.6.0 of DOLFINx, you need to install a compatible version of DOLFINy. I guess this commit: Merge branch 'azilian/multiarch-build-push' into 'master' · michalhabera/dolfiny@b52cb50 · GitHub
@michalhabera can probably comment on this.

I am using DOLFINx version: 0.5.2, I think upgrading it to 0.6.0 might solve the issue. Can you please tell me how do I upgrade it ? Assuming that v0.6.0 is compatible with the already installed DOLFINy.
Thanks.

I dont know how the DOLFINy developers mark compatibility. The error message you get indicates that you need to be on the main branch of DOLFINx.

To use that I recommend docker, ie use:

Otherwise you would have to to back to a commit of DOLFINy around september/october 2022, Which is at the time of the 0.5.2 release. My best guess is:

What are the steps to do this ?
PS: I don’t use docker, so I have to install it first. That’s why I want to try 2nd method first.

Go to the repository that you cloned on your computer.
Write git checkout 43610f4d6cc265adf926d82b898d20c894e69559. Then reinstall the software with python3 -m pip install . —upgrade

I got the error on writing git checkout 43610f4d6cc265adf926d82b898d20c894e69559 -

fatal: not a git repository (or any parent up to mount point /mnt)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

EDIT: I thought it is due to mounting D drive but trying it only on Ubuntu gives the error -

How did you download dolfiny?
As it is a git repository, the most natural way of downloading it would be
git clone https://github.com/michalhabera/dolfiny
which would give you the possibility to use the git features of the repo.

I downloaded the zip and extracted it, I’ll try git clone https://github.com/michalhabera/dolfiny.

Thanks again @dokken for solving the issue. Code is working smoothly now, just one last question, can I get mathematical reference which are used to build this demo ? I have messaged @michalhabera to provide the same if it is possible.

Is there any fenics plasticity tutorial exists that deals with displacement control loading?
I am trying to change loading in Elasto-plastic analysis of a 2D von Mises material — Numerical tours of continuum mechanics using FEniCS master documentation. But not able to achieve it.

Thanks @dokken and @violetus, I think I’ve got parts of the demo working now, but the solver does not seem to converge. I’m using dolfinx 0.6.0.0 and dolfiny 0.1, I changed a couple of lines of solid_plasticity_monolithic.py:

dλ = ufl.Max(f, 0)  # ppos = MacAuley bracket  

to

dλ = ufl.max_value(f, 0)  # ppos = MacAuley bracket

and

I = ufl.Identity(u.geometric_dimension())  # noqa: E741

to

I = ufl.Identity(len(u))  # noqa: E741

As neither of the old functions seem to exist. This then runs, assembles the mesh and begins solving, but as soon as the loading bc is greater than zero, the snes solver doesn’t converge.

+++ Processing load factor μ = 0.0000 

### SNES iteration 0 
# sub  0 |x|=0.000e+00 |dx|=0.000e+00 |r|=0.000e+00 (u) 
# sub  1 |x|=0.000e+00 |dx|=0.000e+00 |r|=0.000e+00 (P) 
# sub  2 |x|=0.000e+00 |dx|=0.000e+00 |r|=0.000e+00 (h) 
# sub  3 |x|=0.000e+00 |dx|=0.000e+00 |r|=0.000e+00 (B) 
# all    |x|=0.000e+00 |dx|=0.000e+00 |r|=0.000e+00 

+++ Processing load factor μ = 0.0400 

### SNES iteration 0 
# sub  0 |x|=0.000e+00 |dx|=0.000e+00 |r|=1.263e-03 (u) 
# sub  1 |x|=0.000e+00 |dx|=0.000e+00 |r|=0.000e+00 (P) 
# sub  2 |x|=0.000e+00 |dx|=0.000e+00 |r|=0.000e+00 (h) 
# sub  3 |x|=0.000e+00 |dx|=0.000e+00 |r|=0.000e+00 (B) 
# all    |x|=0.000e+00 |dx|=0.000e+00 |r|=1.263e-03 
Traceback (most recent call last):
  File "/root/dolfiny/demo/plasticity/solid_plasticity_monolithic1.py", line 216, in <module>
    assert problem.snes.getConvergedReason() > 0, "Nonlinear solver did not converge!"
AssertionError: Nonlinear solver did not converge!

Did either of you encounter this problem?

With DOLFINx 0.5.2 and DOLFINy 0.1 the two changes you mentioned are working fine for me.