Error (markActionFulfilled) changing sigma definition tutorial 'elastic-tube-3d'

Hi there, I had a question on how to make changes in the definitions which are given in this tutorial.
Right now I try to modify the definition of sigma in this tutorial, but it ends up with an error. I saw this error has been posted previously, but would it be possible to change definitions in a proper way without such an error? If not, could someone explain for which reason?
I modified the definition from

E = 300000
nu = 0.3
mu = Constant(E / (2.0 * (1.0 + nu)))
lambda_ = Constant(E * nu / ((1.0 + nu) * (1.0 - 2.0 * nu)))

# Define Stress tensor
def sigma(u):
    return lambda_ * nabla_div(u) * Identity(dim) + 2 * mu * epsilon(u)

to

E = 300000
nu = 0.3
mu = Constant(E / (2.0 * (1.0 + nu)))
lambda_ = Constant(E * nu / ((1.0 + nu) * (1.0 - 2.0 * nu)))

# Define Stress tensor for Neo-Hookean material
def sigma(u):
    I = Identity(dim)
    F = I + grad(u)
    J = np.linalg.det(F)

    C = F.T*F
    C_inv = np.linalg.inv(C)
    I1 = np.trace(C)
    return mu/J * (F - (1./3) * I1 * C_inv) + lambda_/J * ln(J) * I

Despite, the following error is received. I guess it might have something to do with the way the determinant of the matrix is determined.

---[precice]  iteration: 1 of 30, time-window: 1 of 100, time: 0, time-window-size: 0.0001, max-timestep-length: 0.0001, ongoing: yes, time-window-complete: no, write-iteration-checkpoint 
---[precice]  initializeData is skipped since no data has to be initialized.
Traceback (most recent call last):
  File "/home/username/preCICE/tutorials/elastic-tube-3d/solid-fenics/solid.py", line 169, in <module>
    res = m(avg(a_n, a_np1, alpha_m), v) + k(avg(u_n, du, alpha_f), v)
  File "/home/username/preCICE/tutorials/elastic-tube-3d/solid-fenics/solid.py", line 112, in k
    return inner(sigma(u), sym(grad(v))) * dx
  File "/home/username/preCICE/tutorials/elastic-tube-3d/solid-fenics/solid.py", line 93, in sigma
    J = np.linalg.det(F)
  File "<__array_function__ internals>", line 180, in det
  File "/home/username/.local/lib/python3.10/site-packages/numpy/linalg/linalg.py", line 2150, in det
    _assert_stacked_2d(a)
  File "/home/username/.local/lib/python3.10/site-packages/numpy/linalg/linalg.py", line 197, in _assert_stacked_2d
    raise LinAlgError('%d-dimensional array given. Array must be '
numpy.linalg.LinAlgError: 0-dimensional array given. Array must be at least two-dimensional
---[precice]  Implicitly finalizing in destructor
---[precice] ERROR:  The required actions write-iteration-checkpoint are not fulfilled. Did you forget to call "markActionFulfilled"?

Already thanks for any help & suggestions.

Hi @G6-gottaL

For such modifications, it is usually hard to tell directly what is going wrong. The error basically says that the matrix F that you create needs to be two dimensional, but is somehow 0 dimensional. The FEniCS matrix object will have a function which will let you see the contents of the matrix. I suggest finding this function and using it to check the contents of F and if those are problematic, then check the contents of the objects which are used in creating F. Such a step by step process should reveal the problem.

The problem seems indeed to arise once a multiplication should be done with F. No errors occur if the original definition of sigma is changed from

return lambda_ * nabla_div(u) * Identity(dim) + 2 * mu * epsilon(u)

to

return lambda_ * nabla_grad(u) * Identity(dim) + 2 * mu * epsilon(u)

However an error is introduced once it is multiplied once more with this gradient

return lambda_ * nabla_grad(u) * Identity(dim) * nabla_grad(u) + 2 * mu * epsilon(u)

In essence this also seems to happen with introduction of C, where the term grad(u) is squared as well. Is there a logical reason for this error to pop up?

Traceback (most recent call last):
  File "/home/username/preCICE/tutorials/elastic-tube-3d/solid-fenics/solid.py", line 251, in <module>
    A, b = assemble_system(a_form, L_form, bc)
...
File "/usr/lib/python3/dist-packages/ufl_legacy/algorithms/check_arities.py", line 20, in <genexpr>
    for arg, conj in atuple)
ValueError: too many values to unpack (expected 2)
---[precice]  Implicitly finalizing in destructor
---[precice]  Synchronize participants and close communication channels

Hi @G6-gottaL,

I think this question is better suited for the FEniCS Discourse: https://fenicsproject.discourse.group/ as it is quite FEniCS specific.

I agree on the fact that this problem is related to FEniCS. The only thing is that this multiplication is possible in the python interface. Hence I suspect that the problem is related to the link between OpenFOAM and FEniCS with preCICE.

Do you mean the Python interface of FEniCS? This means it is still a FEniCS problem and most likely not related to the coupling.