Error: Unable to extract subsystem of finite element.

Asked by Charles Cook

I'm trying to assign a value to a Function. It would appear that I need to setup some 'subsystems'. How may I do that without calling solve?

Interval mesh (cells, xLeft, xRight);
FunctionSpace V (mesh);
Function u (V);

for(int i=0;i<=cells;i++)
    un[i] = 1.0; //some value

I receive the following error:

*** -------------------------------------------------------------------------
*** Error: Unable to extract subsystem of finite element.
*** Reason: There are no subsystems.
*** Where: This error was encountered inside FiniteElement.cpp.
*** -------------------------------------------------------------------------

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Johan Hake
Solved:
Last query:
Last reply:
Revision history for this message
Johan Hake (johan-hake) said :
#1

To access degrees of freedoms you need to access the vector of a Function.

  u.vector()[i] = ...;

with

  u[i]

you try accessing a sub function.

Johan

On Monday January 30 2012 22:35:37 Charles Cook wrote:
> New question #186334 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/186334
>
> I'm trying to assign a value to a Function. It would appear that I need to
> setup some 'subsystems'. How may I do that without calling solve?
>
> Interval mesh (cells, xLeft, xRight);
> FunctionSpace V (mesh);
> Function u (V);
>
> for(int i=0;i<=cells;i++)
> un[i] = 1.0; //some value
>
>
> I receive the following error:
>
> ***
> -------------------------------------------------------------------------
> *** Error: Unable to extract subsystem of finite element.
> *** Reason: There are no subsystems.
> *** Where: This error was encountered inside FiniteElement.cpp.
> ***
> -------------------------------------------------------------------------

Revision history for this message
Charles Cook (charles-4w) said :
#2

Johan,

Unless I'm mistaken the operator[] is not defined for the vector?

The compile time error message I receive:

error: no match for ‘operator[]’ in ‘dolfin::Function::vector()()[i]’

Revision history for this message
Best Johan Hake (johan-hake) said :
#3

On Tuesday January 31 2012 13:23:34 Charles Cook wrote:
> Question #186334 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/186334
>
> Status: Answered => Open
>
> Charles Cook is still having a problem:
> Johan,
>
> Unless I'm mistaken the operator[] is not defined for the vector?
>
> The compile time error message I receive:
>
> error: no match for ‘operator[]’ in ‘dolfin::Function::vector()()[i]’

Ahh, I was stuck in the Python interface in my mind. Then you can use:

  GenericVector.setitem(i, value);

remember to call:

  GenericVector.apply("insert");

before using the vector to anything. Also remember that in paralell you are on
your own, as one can only assign indices which are local to each processor.

For basic reference questions I suggest you take a look at our different
manuals and generated references:

  http://fenicsproject.org/documentation/index.htm

They are often more correct than the developers ;)

Johan

Revision history for this message
Charles Cook (charles-4w) said :
#4

Thanks Johan Hake, that solved my question.

Revision history for this message
Charles Cook (charles-4w) said :
#5

Thank you!

Fortunately I am working on one thread. But, I did notice the documentation provides methods to find the local block: http://fenicsproject.org/documentation/dolfin/1.0.0/cpp/programmers-reference/la/Vector.html#Vector

The setitem method was hiding behind a boost::shared_ptr so I didnt see it by intellisense. In my case the syntax was:

(*domain->u.vector()).setitem(i, 1.0);