Error: Invalid value rank for coefficient 1

Asked by Phil Marinier

I hope this isn't a stupid question, but I have get this error message and I have no idea what it means.

Solving linear variational problem
  Matrix of size 1251 x 1251 has 8551 nonzero entries.
terminate called after throwing an instance of 'std::runtime_error'
  what(): *** Error: Invalid value rank for coefficient 1, got 1 but expecting 0. Did you forget to specify the value rank correctly in an Expression sub class?
[wolf:00486] *** Process received signal ***
[wolf:00486] Signal: Aborted (6)
[wolf:00486] Signal code: (-6)
[wolf:00486] [ 0] [0xe99410]
[wolf:00486] [ 1] [0xe99422]
[wolf:00486] [ 2] /lib/tls/i686/cmov/libc.so.6(gsignal+0x51) [0x78b84d1]
[wolf:00486] [ 3] /lib/tls/i686/cmov/libc.so.6(abort+0x182) [0x78bb932]
[wolf:00486] [ 4] /usr/lib/libstdc++.so.6(_ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x14f) [0x1d034df]
[wolf:00486] [ 5] /usr/lib/libstdc++.so.6 [0x1d01415]
[wolf:00486] [ 6] /usr/lib/libstdc++.so.6 [0x1d01452]
[wolf:00486] [ 7] /usr/lib/libstdc++.so.6 [0x1d01591]
[wolf:00486] [ 8] /home/claude/FEniCS/build/lib/libdolfin.so.0(_ZNK6dolfin6Logger5errorESs+0x98) [0x477fb8]
[wolf:00486] [ 9] /home/claude/FEniCS/build/lib/libdolfin.so.0(_ZN6dolfin5errorESsz+0x9f) [0x47f92f]
[wolf:00486] [10] /home/claude/FEniCS/build/lib/libdolfin.so.0(_ZN6dolfin14AssemblerTools5checkERKNS_4FormE+0x18f) [0x39fd9f]
[wolf:00486] [11] /home/claude/FEniCS/build/lib/libdolfin.so.0(_ZN6dolfin9Assembler8assembleERNS_13GenericTensorERKNS_4FormEPKNS_12MeshFunctionIjEES9_S9_bb+0x3c) [0x3b774c]
[wolf:00486] [12] /home/claude/FEniCS/build/lib/libdolfin.so.0(_ZN6dolfin8assembleERNS_13GenericTensorERKNS_4FormEPKNS_12MeshFunctionIjEES8_S8_bb+0x49) [0x3a4c29]
[wolf:00486] [13] /home/claude/FEniCS/build/lib/libdolfin.so.0(_ZN6dolfin18VariationalProblem12solve_linearERNS_8FunctionE+0x829) [0x399ff9]
[wolf:00486] [14] /home/claude/FEniCS/build/lib/libdolfin.so.0(_ZN6dolfin18VariationalProblem5solveERNS_8FunctionE+0x2a) [0x39a95a]
[wolf:00486] [15] ./forward(_ZN7ASolver5solveEPN6dolfin8FunctionES2_PdS3_S3_ddP4Edge+0xb9f) [0x80965cf]
[wolf:00486] [16] ./forward(_ZN9Fiterator5solveEPdS0_S0_+0x12d2) [0x80819c2]
[wolf:00486] [17] ./forward(main+0x82d) [0x807002d]
[wolf:00486] [18] /lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe6) [0x78a4b56]
[wolf:00486] [19] ./forward [0x806e931]
[wolf:00486] *** End of error message ***
Aborted

I'm not using any sub classes of Expression. I am using dolfin::Function but as far as I know, I don't have to specify the value rank when using Function. What does this error message mean? I am using MeshFunction but I double checked the new programmers reference and I'm declaring it the right way, and it doesn't seem to need a value rank. What should I be looking for when I debug?

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Anders Logg
Solved:
Last query:
Last reply:

This question was reopened

Revision history for this message
Murtazo Nazarov (murtazo) said :
#1

Phil Marinier wrote:
> New question #95908 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/95908
>
> I hope this isn't a stupid question, but I have get this error message and I have no idea what it means.
>
>
> Solving linear variational problem
> Matrix of size 1251 x 1251 has 8551 nonzero entries.
> terminate called after throwing an instance of 'std::runtime_error'
> what(): *** Error: Invalid value rank for coefficient 1, got 1 but expecting 0. Did you forget to specify the value rank correctly in an Expression sub class?
> [wolf:00486] *** Process received signal ***
> [wolf:00486] Signal: Aborted (6)
> [wolf:00486] Signal code: (-6)
> [wolf:00486] [ 0] [0xe99410]
> [wolf:00486] [ 1] [0xe99422]
> [wolf:00486] [ 2] /lib/tls/i686/cmov/libc.so.6(gsignal+0x51) [0x78b84d1]
> [wolf:00486] [ 3] /lib/tls/i686/cmov/libc.so.6(abort+0x182) [0x78bb932]
> [wolf:00486] [ 4] /usr/lib/libstdc++.so.6(_ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x14f) [0x1d034df]
> [wolf:00486] [ 5] /usr/lib/libstdc++.so.6 [0x1d01415]
> [wolf:00486] [ 6] /usr/lib/libstdc++.so.6 [0x1d01452]
> [wolf:00486] [ 7] /usr/lib/libstdc++.so.6 [0x1d01591]
> [wolf:00486] [ 8] /home/claude/FEniCS/build/lib/libdolfin.so.0(_ZNK6dolfin6Logger5errorESs+0x98) [0x477fb8]
> [wolf:00486] [ 9] /home/claude/FEniCS/build/lib/libdolfin.so.0(_ZN6dolfin5errorESsz+0x9f) [0x47f92f]
> [wolf:00486] [10] /home/claude/FEniCS/build/lib/libdolfin.so.0(_ZN6dolfin14AssemblerTools5checkERKNS_4FormE+0x18f) [0x39fd9f]
> [wolf:00486] [11] /home/claude/FEniCS/build/lib/libdolfin.so.0(_ZN6dolfin9Assembler8assembleERNS_13GenericTensorERKNS_4FormEPKNS_12MeshFunctionIjEES9_S9_bb+0x3c) [0x3b774c]
> [wolf:00486] [12] /home/claude/FEniCS/build/lib/libdolfin.so.0(_ZN6dolfin8assembleERNS_13GenericTensorERKNS_4FormEPKNS_12MeshFunctionIjEES8_S8_bb+0x49) [0x3a4c29]
> [wolf:00486] [13] /home/claude/FEniCS/build/lib/libdolfin.so.0(_ZN6dolfin18VariationalProblem12solve_linearERNS_8FunctionE+0x829) [0x399ff9]
> [wolf:00486] [14] /home/claude/FEniCS/build/lib/libdolfin.so.0(_ZN6dolfin18VariationalProblem5solveERNS_8FunctionE+0x2a) [0x39a95a]
> [wolf:00486] [15] ./forward(_ZN7ASolver5solveEPN6dolfin8FunctionES2_PdS3_S3_ddP4Edge+0xb9f) [0x80965cf]
> [wolf:00486] [16] ./forward(_ZN9Fiterator5solveEPdS0_S0_+0x12d2) [0x80819c2]
> [wolf:00486] [17] ./forward(main+0x82d) [0x807002d]
> [wolf:00486] [18] /lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe6) [0x78a4b56]
> [wolf:00486] [19] ./forward [0x806e931]
> [wolf:00486] *** End of error message ***
> Aborted
>
>
> I'm not using any sub classes of Expression. I am using dolfin::Function but as far as I know, I don't have to specify the value rank when using Function. What does this error message mean? I am using MeshFunction but I double checked the new programmers reference and I'm declaring it the right way, and it doesn't seem to need a value rank. What should I be looking for when I debug?
>
>

I think this might happens like the following: your function space
which you define the function from is different in your cpp code and in
a ufl form file. For example

W = new YourForm::FunctionSpace(mesh) //it might not much to the
function space in YourForm.ufl
Function w(*W); //

You can print out the size of the vector w.vector() to check.

murtazo

Revision history for this message
Anders Logg (logg) said :
#2

On Sat, Jan 02, 2010 at 10:31:50AM -0000, Phil Marinier wrote:
> New question #95908 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/95908
>
> I hope this isn't a stupid question, but I have get this error message and I have no idea what it means.
>
>
> Solving linear variational problem
> Matrix of size 1251 x 1251 has 8551 nonzero entries.
> terminate called after throwing an instance of 'std::runtime_error'
> what(): *** Error: Invalid value rank for coefficient 1, got 1 but expecting 0. Did you forget to specify the value rank correctly in an Expression sub class?
> [wolf:00486] *** Process received signal ***
> [wolf:00486] Signal: Aborted (6)
> [wolf:00486] Signal code: (-6)
> [wolf:00486] [ 0] [0xe99410]
> [wolf:00486] [ 1] [0xe99422]
> [wolf:00486] [ 2] /lib/tls/i686/cmov/libc.so.6(gsignal+0x51) [0x78b84d1]
> [wolf:00486] [ 3] /lib/tls/i686/cmov/libc.so.6(abort+0x182) [0x78bb932]
> [wolf:00486] [ 4] /usr/lib/libstdc++.so.6(_ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x14f) [0x1d034df]
> [wolf:00486] [ 5] /usr/lib/libstdc++.so.6 [0x1d01415]
> [wolf:00486] [ 6] /usr/lib/libstdc++.so.6 [0x1d01452]
> [wolf:00486] [ 7] /usr/lib/libstdc++.so.6 [0x1d01591]
> [wolf:00486] [ 8] /home/claude/FEniCS/build/lib/libdolfin.so.0(_ZNK6dolfin6Logger5errorESs+0x98) [0x477fb8]
> [wolf:00486] [ 9] /home/claude/FEniCS/build/lib/libdolfin.so.0(_ZN6dolfin5errorESsz+0x9f) [0x47f92f]
> [wolf:00486] [10] /home/claude/FEniCS/build/lib/libdolfin.so.0(_ZN6dolfin14AssemblerTools5checkERKNS_4FormE+0x18f) [0x39fd9f]
> [wolf:00486] [11] /home/claude/FEniCS/build/lib/libdolfin.so.0(_ZN6dolfin9Assembler8assembleERNS_13GenericTensorERKNS_4FormEPKNS_12MeshFunctionIjEES9_S9_bb+0x3c) [0x3b774c]
> [wolf:00486] [12] /home/claude/FEniCS/build/lib/libdolfin.so.0(_ZN6dolfin8assembleERNS_13GenericTensorERKNS_4FormEPKNS_12MeshFunctionIjEES8_S8_bb+0x49) [0x3a4c29]
> [wolf:00486] [13] /home/claude/FEniCS/build/lib/libdolfin.so.0(_ZN6dolfin18VariationalProblem12solve_linearERNS_8FunctionE+0x829) [0x399ff9]
> [wolf:00486] [14] /home/claude/FEniCS/build/lib/libdolfin.so.0(_ZN6dolfin18VariationalProblem5solveERNS_8FunctionE+0x2a) [0x39a95a]
> [wolf:00486] [15] ./forward(_ZN7ASolver5solveEPN6dolfin8FunctionES2_PdS3_S3_ddP4Edge+0xb9f) [0x80965cf]
> [wolf:00486] [16] ./forward(_ZN9Fiterator5solveEPdS0_S0_+0x12d2) [0x80819c2]
> [wolf:00486] [17] ./forward(main+0x82d) [0x807002d]
> [wolf:00486] [18] /lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe6) [0x78a4b56]
> [wolf:00486] [19] ./forward [0x806e931]
> [wolf:00486] *** End of error message ***
> Aborted
>
>
> I'm not using any sub classes of Expression. I am using dolfin::Function but as far as I know, I don't have to specify the value rank when using Function. What does this error message mean? I am using MeshFunction but I double checked the new programmers reference and I'm declaring it the right way, and it doesn't seem to need a value rank. What should I be looking for when I debug?

This indicates that you are using a vector-valued Expression or
Function (rank 1) for a coefficient that should be scalar (rank 0).

--
Anders

Revision history for this message
Phil Marinier (lonewolf-13p) said :
#3

Thank you guys, I found my error and understand a little more whats going on. My problem is the work around I was trying to do because I have problems defining subFunctions. My work around involved using a Function that already had subFunctions, but that function was defined on a different FunctionSpace and so cause a whole new set of errors. I will go back the the subFunction thread I started and post there so I don't confuse people with my subject line.

Thank you again for all your help

Phil

Revision history for this message
Phil Marinier (lonewolf-13p) said :
#4

So I just finished thinking through some of the consequences of not being able to use vector valued Functions. I am trying to assign gradients to a Neumann boundary condition. Basic I'm doing a domain decomposition approach and I need to be able to calculate the gradients after each iteration, average them out and reapply them as Neumann BCs for the next iteration. I am also doing stuff on another boundary but its all Dirichlet conditions. I defined my FunctionSpace and neumann conditions like so:

element = FiniteElement("Lagrange", triangle, 1)

v = TestFunction(element)
u = TrialFunction(element)
f = Function(element)
g = Function(element)

a = inner(grad(v), grad(u))*dx
L = v*f*dx + v*g*ds(3)

where g is going to be my Neumann condition. In my code, I am currently trying to assign a Function with 2 subfunctions (X and Y) to g

L.g = FunctionWith2SubFunctions

This should work, assuming the function with 2 subfunctions is defined on the same FunctionSpace as L. But if I don't use vecotr values elements, will dolfin know that the 2 SubFunctions are the X and Y values? If my understanding of how things work is right, then dolfin will get confused and either run wrong, or blow up.

Can I define 2 Neumann conditions, X and Y on the same boundary? If so should I mark them differently? by this I mean should I do this:

L = v*f*dx + v*g*ds(2) + v*h*ds(3)

but mark the same boundary as both 2 and 3? Can this even be done in dolfin?

Thank you for your help.

Phil

Revision history for this message
Anders Logg (logg) said :
#5

On Tue, Jan 05, 2010 at 08:13:37AM -0000, Phil Marinier wrote:
> Question #95908 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/95908
>
> Status: Solved => Open
>
> Phil Marinier is still having a problem:
> So I just finished thinking through some of the consequences of not
> being able to use vector valued Functions. I am trying to assign
> gradients to a Neumann boundary condition. Basic I'm doing a domain
> decomposition approach and I need to be able to calculate the gradients
> after each iteration, average them out and reapply them as Neumann BCs
> for the next iteration. I am also doing stuff on another boundary but
> its all Dirichlet conditions. I defined my FunctionSpace and neumann
> conditions like so:
>
> element = FiniteElement("Lagrange", triangle, 1)
>
> v = TestFunction(element)
> u = TrialFunction(element)
> f = Function(element)
> g = Function(element)
>
> a = inner(grad(v), grad(u))*dx
> L = v*f*dx + v*g*ds(3)
>
> where g is going to be my Neumann condition. In my code, I am currently
> trying to assign a Function with 2 subfunctions (X and Y) to g
>
> L.g = FunctionWith2SubFunctions
>
> This should work, assuming the function with 2 subfunctions is defined
> on the same FunctionSpace as L. But if I don't use vecotr values
> elements, will dolfin know that the 2 SubFunctions are the X and Y
> values? If my understanding of how things work is right, then dolfin
> will get confused and either run wrong, or blow up.
>
> Can I define 2 Neumann conditions, X and Y on the same boundary? If so
> should I mark them differently? by this I mean should I do this:
>
> L = v*f*dx + v*g*ds(2) + v*h*ds(3)
>
> but mark the same boundary as both 2 and 3? Can this even be done in
> dolfin?
>
> Thank you for your help.
>
> Phil

In your above examples, g is scalar-valued since you have defined it
by

  g = Function(element)

and element is a scalar element.

Then you can't assign L.g = something vector-valued.

--
Anders

Revision history for this message
Phil Marinier (lonewolf-13p) said :
#6

I tried this:

element = FiniteElement("Lagrange", triangle, 1)
VE = VectorElement("Lagrange", triangle, 1)

v = TestFunction(element)
u = TrialFunction(element)
f = Function(element)
g = Function(VE)

a = inner(grad(v), grad(u))*dx
L = v*f*dx + v*g*ds(3)

This was the error message:

phil@wolf:~/Desktop/Domain Decomposition$ ffc -l dolfin -O Laplace.ufl
This is FFC, the FEniCS Form Compiler, version 0.7.1.
For further information, visit http://www.fenics.org/ffc/.

Trying to integrate expression of rank 1 with free indices ().
An exception occured during evaluation of form file.
To help you find the location of the error, a temporary script
'Laplace_debug.py'
has been created and will now be executed with debug output enabled:
Trying to integrate expression of rank 1 with free indices ().
Traceback (most recent call last):
  File "/home/claude/FEniCS/build/bin/ffc", line 153, in <module>
    sys.exit(main(sys.argv[1:]))
  File "/home/claude/FEniCS/build/bin/ffc", line 130, in main
    ufd = load_ufl_file(filename)
  File "/home/claude/FEniCS/build/lib/python2.6/site-packages/ufl/algorithms/formfiles.py", line 91, in load_ufl_file
    m = __import__(basename)
  File "/home/phil/Desktop/Domain Decomposition/Laplace_debug.py", line 13, in <module>
    L = v*f*dx + v*g*ds(3)
  File "/home/claude/FEniCS/build/lib/python2.6/site-packages/ufl/integral.py", line 94, in __rmul__
    % (integrand.rank(), integrand.free_indices()))
  File "/home/claude/FEniCS/build/lib/python2.6/site-packages/ufl/assertions.py", line 20, in ufl_assert
    if not condition: error(*message)
  File "/home/claude/FEniCS/build/lib/python2.6/site-packages/ufl/log.py", line 106, in error
    raise UFLException(self._format_raw(*message))
ufl.log.UFLException: Trying to integrate expression of rank 1 with free indices ().

I assumed because of the "rank 1" in the error message that the problem was that I was using a vector valued element for g and that wasn't allowed. I know that I can't use VectorElements for my test and trial functions because it messes up the dot product.

I guess my real question is how would I go about re writing the form file to get a neumann boundary condition on one boundary that has both X and Y components?

Revision history for this message
Best Anders Logg (logg) said :
#7

On Wed, Jan 06, 2010 at 07:46:28AM -0000, Phil Marinier wrote:
> Question #95908 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/95908
>
> Status: Answered => Open
>
> Phil Marinier is still having a problem:
> I tried this:
>
> element = FiniteElement("Lagrange", triangle, 1)
> VE = VectorElement("Lagrange", triangle, 1)
>
> v = TestFunction(element)
> u = TrialFunction(element)
> f = Function(element)
> g = Function(VE)
>
> a = inner(grad(v), grad(u))*dx
> L = v*f*dx + v*g*ds(3)
>
>
> This was the error message:
>
>
> phil@wolf:~/Desktop/Domain Decomposition$ ffc -l dolfin -O Laplace.ufl
> This is FFC, the FEniCS Form Compiler, version 0.7.1.
> For further information, visit http://www.fenics.org/ffc/.
>
> Trying to integrate expression of rank 1 with free indices ().
> An exception occured during evaluation of form file.
> To help you find the location of the error, a temporary script
> 'Laplace_debug.py'
> has been created and will now be executed with debug output enabled:
> Trying to integrate expression of rank 1 with free indices ().
> Traceback (most recent call last):
> File "/home/claude/FEniCS/build/bin/ffc", line 153, in <module>
> sys.exit(main(sys.argv[1:]))
> File "/home/claude/FEniCS/build/bin/ffc", line 130, in main
> ufd = load_ufl_file(filename)
> File "/home/claude/FEniCS/build/lib/python2.6/site-packages/ufl/algorithms/formfiles.py", line 91, in load_ufl_file
> m = __import__(basename)
> File "/home/phil/Desktop/Domain Decomposition/Laplace_debug.py", line 13, in <module>
> L = v*f*dx + v*g*ds(3)
> File "/home/claude/FEniCS/build/lib/python2.6/site-packages/ufl/integral.py", line 94, in __rmul__
> % (integrand.rank(), integrand.free_indices()))
> File "/home/claude/FEniCS/build/lib/python2.6/site-packages/ufl/assertions.py", line 20, in ufl_assert
> if not condition: error(*message)
> File "/home/claude/FEniCS/build/lib/python2.6/site-packages/ufl/log.py", line 106, in error
> raise UFLException(self._format_raw(*message))
> ufl.log.UFLException: Trying to integrate expression of rank 1 with free indices ().
>
>
> I assumed because of the "rank 1" in the error message that the problem was that I was using a vector valued element for g and that wasn't allowed. I know that I can't use VectorElements for my test and trial functions because it messes up the dot product.
>
> I guess my real question is how would I go about re writing the form
> file to get a neumann boundary condition on one boundary that has both X
> and Y components?

This is not surprising at all. Your function g is now vector-valued so
then it doesn't make sense to write

  v*g*ds

since that will be a vector-valued integral.

g must be a scalar in the above example, and it should be equal to the
normal derivative of u on the boundary.

What you can do is instead of writing v*g*ds let g denote the
vector-valued gradient of u on the boundary. Then you must also
include the facet normal:

  n = triangle.n
  L = v*f*dx + v*dot(g, n)*ds

with g the vector-valued gradient of u on the neighboring domain.

That might be what you are looking for.

You could also do

  n = triangle.n
  L = v*f*dx + v*dot(grad(g), n)*ds

and let g be the scalar-valued u on the neighboring domain.

--
Anders

Revision history for this message
Phil Marinier (lonewolf-13p) said :
#8

That was exactly what I was looking for, thank you very much

Revision history for this message
Phil Marinier (lonewolf-13p) said :
#9

Thanks Anders Logg, that solved my question.