Function from array for rhs gives wrong result #3054
-
We (@JosquinHa and I) are trying to solve the following variational problem: a = inner(v, u)*dx - ((
-inner(Dx(Dx(Dx(v, 0), 0), 0), Dx(Dx(Dx(u, 0), 0), 0))
- 3 * inner(Dx(Dx(Dx(v, 1), 0), 0), Dx(Dx(Dx(u, 1), 0), 0))
- 3 * inner(Dx(Dx(Dx(v, 0), 1), 1), Dx(Dx(Dx(u, 0), 1), 1))
- inner(Dx(Dx(Dx(v, 1), 1), 1), Dx(Dx(Dx(u, 1), 1), 1))
)/10)*dx
L = inner(chi, u)*dx where mesh = PeriodicUnitSquareMesh(nx=n, ny=n)
WX = FunctionSpace(mesh, "WXRobH3NC", degree=7)
V = FunctionSpace(mesh, "CG", 1)
m = V.ufl_domain()
W = VectorFunctionSpace(m, V.ufl_element())
v, u = TrialFunction(WX), TestFunction(WX) (Notice this element is not available in master yet, as far as I'm aware. Our docker setup can be found here). If we treat x, y = SpatialCoordinate(mesh)
expr = cos(2*pi*x) + sin(2*pi*y)
chi = interpolate(expr, V) we obtain the expected answer On the other hand, if we consider chi = Function(V)
chi.dat.data[:] = data # where data is a 1d vector with properly ordered values we get a wrong solution (i.e. not close at all, both quantitatively and qualitatively, to the expected result). We solve using defaults: res = Function(WX, name="field")
solve(a == L, res) Does anyone have an idea on what we're doing wrong? I believe the problem may be easy to identify, if not, I can quickly provide more information on how to get |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Could you |
Beta Was this translation helpful? Give feedback.
Hey,
I apologize for the wrong answers I gave before, it seems all I had to do was switching from python notebook to python script. When passing the data from the expression as array things are now working. It seems the notebook I was working on did not update well...
I have corrected the way of ordering the data array and everything works as intended.
Many thanks for all the instructive replies.