I need to translate the mesh nodes in a 2D geometry by a vector \textbf{u} of size (2,1). Since mesh coordinates are geometry-type objects and not a function object, I tried to project the mesh_node coordinates to a vector function space and then tried adding \textbf{u}. Consider the below MWE:
from __future__ import print_function
from fenics import *
import matplotlib.pyplot as plt
from dolfin import *
import meshio
from dolfin import Mesh, XDMFFile, File, MeshValueCollection, cpp
# Optimization options for the form compiler
parameters["form_compiler"]["cpp_optimize"] = True
ffc_options = {"optimize": True, \
"eliminate_zeros": True, \
"precompute_basis_const": True, \
"precompute_ip_const": True}
import numpy as np
import meshio
from mshr import Circle, generate_mesh
from dolfin import Mesh, File, MeshFunction, Point, BoundaryMesh, SubDomain, plot, File
import matplotlib.pyplot as plt
from dolfin import *
from mshr import *
import numpy as np
class boundary(SubDomain):
def inside(self, x, on_boundary):
return on_boundary
class disk(SubDomain):
def inside(self, x, on_boundary):
return True
C = Circle(Point(0, 0), 5)
mesh = generate_mesh(C, 50)
V = VectorFunctionSpace(mesh, "Lagrange", 1)
mesh_nodes = mesh.coordinates()
print(mesh_nodes)
u = Function(V)
coords = project(mesh_nodes, V)
phi = coords + u
But this raises the error:
coords = project(mesh_nodes, V)
File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/fem/projection.py", line 129, in project
L = ufl.inner(w, v) * dx
File "/usr/lib/python3/dist-packages/ufl/operators.py", line 155, in inner
b = as_ufl(b)
File "/usr/lib/python3/dist-packages/ufl/constantvalue.py", line 437, in as_ufl
raise UFLValueError("Invalid type conversion: %s can not be converted"
ufl.log.UFLValueError: Invalid type conversion: [[-4.99899902 0.10004404]
[-4.99899902 -0.10004404]
[-4.99099357 -0.29997192]
...
[ 1.81895092 4.25595418]
[ 1.60783276 -2.54317265]
[ 1.12755794 -2.61691696]] can not be converted to any UFL type.
What does the error mean and what can be done to overcome that?