Cahn-Hilliard equation in 3D

Hello, I am running the following script and want to run the same equation in 3D mesh. Could you give an idea how can I change the 2D mesh script to 3D mesh script?


For the mesh, I think you can just use UnitCubeMesh

1 Like

@Kei_Yamamoto Thanks a lot for your message. I used UnitCubeMesh and got this error. Do you know what this message means? I cannot get what the “shapes” means.

Can't add expressions with different shapes.
Traceback (most recent call last):
  File "", line 258, in <module>
    f    = 100*c**2*(1-c)**2
  File "/usr/lib/python3/dist-packages/ufl/", line 232, in _rsub
    return Sum(o, -self)
  File "/usr/lib/python3/dist-packages/ufl/", line 41, in __new__
    error("Can't add expressions with different shapes.")
  File "/usr/lib/python3/dist-packages/ufl/", line 158, in error
    raise self._exception_type(self._format_raw(*message))
ufl.log.UFLException: Can't add expressions with different shapes.

I can’t tell what is causing error without looking your code but, my understanding of shgapes is the same as dimensions. So, you are probably trying add something that doesn’t have the same dimension (For example, trying to add scalar and vector).

1 Like