Error: Unable to access vector of degrees of freedom.


119
views
1
10 weeks ago by
Hi,

I'm wondering why the following
mesh = UnitSquareMesh(5, 5)
el = triangle
P1 = FiniteElement('Lagrange', el, 1) # pressure space
Elem = MixedElement([P1, P1, P1])
F = FunctionSpace(mesh, Elem)
p = Function(F)
p1, p2, p3 = p.split()
s1 = p1.copy(deepcopy=True)​

fails with the following error
s1 = p1.copy(deepcopy=True)
  File "/usr/lib/python3/dist-packages/dolfin/cpp/function.py", line 859, in copy
    return Function(self.function_space(), self.vector().copy())
RuntimeError: 

*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
***     fenics-support@googlegroups.com
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error:   Unable to access vector of degrees of freedom.
*** Reason:  Cannot access a non-const vector from a subfunction.
*** Where:   This error was encountered inside Function.cpp.
*** Process: 0
*** 
*** DOLFIN version: 2017.2.0
*** Git changeset:  4c59bbdb45b95db2f07f4e3fd8985c098615527f
*** -------------------------------------------------------------------------​


Thanks!

Community: FEniCS Project

2 Answers


4
10 weeks ago by
It seems you have to first create a deep copy to be able to actually access the DoFs. The function.copy() constructor seems to rely on this functionality.
The following code should however give the result you are after:
from fenics import *

mesh = UnitSquareMesh(5, 5)
el = triangle
P1 = FiniteElement('Lagrange', el, 1) # pressure space
Elem = MixedElement([P1, P1, P1])
F = FunctionSpace(mesh, Elem)
p = Function(F)

s1 = p.sub(0, True)​
Thanks, that worked!
written 10 weeks ago by alexdiem  
-1
10 weeks ago by
Nima  
I think you should split 'p' by split(p) not p.split()
This won't work.
split(p) is actually ufl.split(p) and not the way to construct a copy of a discrete function object.
written 10 weeks ago by klunkean  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »