Hi all,
I’m trying to understand the differences in terms of syntax and workflow between dolfin
and dolfinx
, since I’d like to use the latter for working with complex numbers.
Now I was trying to implement the dolfinx
equivalent of Expression
, e.g.:
E = Expression(("0.0", "0.0", "cos(x[0])"), degree=2)
By looking at dolfinx
demos (e.g. helmholtz demo) and at other posts in the group, I’ve developed this .py
file.
#minimum example
from dolfinx import FunctionSpace, Function, UnitCubeMesh
from ufl import FiniteElement
from mpi4py import MPI
from numpy import stack, zeros, cos, sin
mesh = UnitCubeMesh(MPI.COMM_WORLD, 8, 8, 8)
curl_el = FiniteElement("N1curl", mesh.ufl_cell(), 2)
V = FunctionSpace(mesh, curl_el)
def incident_field(x):
E = stack((zeros(x.shape[1]), zeros(x.shape[1]),
cos(x[0])+1j*sin(x[0])))
return E
E = Function(V)
E.interpolate(incident_field)
When I run the script, I get the following error:
Traceback (most recent call last):
File "/usr/local/dolfinx-complex/lib/python3.8/dist-packages/dolfinx/fem/function.py", line 262, in _interpolate
self._cpp_object.interpolate(u._cpp_object)
AttributeError: 'function' object has no attribute '_cpp_object'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "mwe.py", line 19, in <module>
E.interpolate(incident_field)
File "/usr/local/dolfinx-complex/lib/python3.8/dist-packages/dolfinx/fem/function.py", line 270, in interpolate
_interpolate(u)
File "/usr/lib/python3.8/functools.py", line 875, in wrapper
return dispatch(args[0].__class__)(*args, **kw)
File "/usr/local/dolfinx-complex/lib/python3.8/dist-packages/dolfinx/fem/function.py", line 264, in _interpolate
self._cpp_object.interpolate(u)
RuntimeError: Point dim does not match element dim.
Substituting the command curl_el = FiniteElement("N1curl", mesh.ufl_cell(), 2)
with curl_el = FiniteElement("N1curl", mesh.ufl_cell(), 1)
does not give me any error, but anyway I’m not understanding why I should do that. Maybe I’m getting confused with the variables involved, but, In general, I think that my main issue is related to the fact that I do not get how to handle the interpolate
function when dealing with vectors in dolfinx
, since I’ve not found an example as clear as the scalar one.
Could you give me some hints on how to solve the error? Thank you so much.
I’m running the latest version of dolfinx-complex
on Docker.