Problem defining ufl form

Asked by Pietro Maximoff

Hello,

I don't know why the following ufl file fails when calculating F. The error:

Expecting 'forms' to be a list of Form instances.
Traceback (most recent call last):
  File "/home/pietro/FEniCS/bin/ffc", line 195, in <module>
    sys.exit(main(sys.argv[1:]))
  File "/home/pietro/FEniCS/bin/ffc", line 159, in main
    ufd = load_ufl_file(filename)
  File "/home/pietro/FEniCS/lib/python2.7/site-packages/ufl/algorithms/formfiles.py", line 164, in load_ufl_file
    "Expecting 'forms' to be a list of Form instances.")
  File "/home/pietro/FEniCS/lib/python2.7/site-packages/ufl/assertions.py", line 37, in ufl_assert
    if not condition: error(*message)
  File "/home/pietro/FEniCS/lib/python2.7/site-packages/ufl/log.py", line 148, in error
    raise self._exception_type(self._format_raw(*message))
ufl.log.UFLException: Expecting 'forms' to be a list of Form instances.

incompressible_elasticity.ufl:
####################
# Function spaces
porder = 2
V = VectorElement("CG", tetrahedron, porder) # space for displacements
P = FiniteElement("CG", tetrahedron, porder-1) # space for pressure
element = V*P

# Trial and test functions
v, q = TestFunctions(element) # Testfunction in the mixed space
dup = TrialFunction(element) # Trial function in the mixed space to define the incremental solution

# Functions
up = Coefficient(element) # Function in the mixed space to store the solution
u, p = split(up) # Function in each subspace to write the functional

# Kinematics
I = Identity(element.cell().d) # Identity tensor
F = variable(I + grad(u)) # Deformation gradient <============== FAILS HERE !!!!!!!!!!!!!!!!!!!!!!!!

---
P.

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Martin Sandve Alnæs
Solved:
Last query:
Last reply:

This question was reopened

Revision history for this message
Martin Sandve Alnæs (martinal) said :
#1

Are you sure you provided the entire UFL file and the correct error message? The stack trace does not correspond with what you point to as the line where it fails.

Martin

Den 17. jan. 2012 kl. 18:05 skrev Pietro Maximoff <email address hidden>:

> New question #185013 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/185013
>
> Hello,
>
> I don't know why the following ufl file fails when calculating F. The error:
>
> Expecting 'forms' to be a list of Form instances.
> Traceback (most recent call last):
> File "/home/pietro/FEniCS/bin/ffc", line 195, in <module>
> sys.exit(main(sys.argv[1:]))
> File "/home/pietro/FEniCS/bin/ffc", line 159, in main
> ufd = load_ufl_file(filename)
> File "/home/pietro/FEniCS/lib/python2.7/site-packages/ufl/algorithms/formfiles.py", line 164, in load_ufl_file
> "Expecting 'forms' to be a list of Form instances.")
> File "/home/pietro/FEniCS/lib/python2.7/site-packages/ufl/assertions.py", line 37, in ufl_assert
> if not condition: error(*message)
> File "/home/pietro/FEniCS/lib/python2.7/site-packages/ufl/log.py", line 148, in error
> raise self._exception_type(self._format_raw(*message))
> ufl.log.UFLException: Expecting 'forms' to be a list of Form instances.
>
>
>
> incompressible_elasticity.ufl:
> ####################
> # Function spaces
> porder = 2
> V = VectorElement("CG", tetrahedron, porder) # space for displacements
> P = FiniteElement("CG", tetrahedron, porder-1) # space for pressure
> element = V*P
>
> # Trial and test functions
> v, q = TestFunctions(element) # Testfunction in the mixed space
> dup = TrialFunction(element) # Trial function in the mixed space to define the incremental solution
>
> # Functions
> up = Coefficient(element) # Function in the mixed space to store the solution
> u, p = split(up) # Function in each subspace to write the functional
>
> # Kinematics
> I = Identity(element.cell().d) # Identity tensor
> F = variable(I + grad(u)) # Deformation gradient <============== FAILS HERE !!!!!!!!!!!!!!!!!!!!!!!!
>
> ---
> P.
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.

Revision history for this message
Pietro Maximoff (segment-x) said :
#2

Hi Martin

I took out the usual preamble at the top that comes with the demo ufl files, i..e, license information, etc. The ufl file ends at F=?? because I was adding to it line by line and compiling to determine where it fails.

Here's the error information again, the ufl file is still the same:

This is FFC, the FEniCS Form Compiler, version 1.0.0.
For further information, visit http://www.fenics.org/ffc/.

Expecting 'forms' to be a list of Form instances.
Traceback (most recent call last):
  File "/home/pietro/FEniCS/bin/ffc", line 195, in <module>
    sys.exit(main(sys.argv[1:]))
  File "/home/pietro/FEniCS/bin/ffc", line 159, in main
    ufd = load_ufl_file(filename)
  File "/home/pietro/FEniCS/lib/python2.7/site-packages/ufl/algorithms/formfiles.py", line 164, in load_ufl_file
    "Expecting 'forms' to be a list of Form instances.")
  File "/home/pietro/FEniCS/lib/python2.7/site-packages/ufl/assertions.py", line 37, in ufl_assert
    if not condition: error(*message)
  File "/home/pietro/FEniCS/lib/python2.7/site-packages/ufl/log.py", line 148, in error
    raise self._exception_type(self._format_raw(*message))
ufl.log.UFLException: Expecting 'forms' to be a list of Form instances.

Thanks.

P.

Revision history for this message
Martin Sandve Alnæs (martinal) said :
#3

Ok. I think you triggered a bug not related to your actual problem. You do not define any forms in your UFL file, and F is somehow added to the forms list. But F is not a Form. Rename F to e.g. F2 and you should get some other error. FFC does not compile the UFL file line by line, it is executed as a python script and FFC interprets the Form objects. To try line by line, you can make it a .py file and add from ufl import * at the top to run it with python.

Martin

Den 17. jan. 2012 kl. 21:15 skrev Pietro Maximoff <email address hidden>:

> Question #185013 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/185013
>
> Status: Answered => Open
>
> Pietro Maximoff is still having a problem:
> Hi Martin
>
> I took out the usual preamble at the top that comes with the demo ufl
> files, i..e, license information, etc. The ufl file ends at F=?? because
> I was adding to it line by line and compiling to determine where it
> fails.
>
>
> Here's the error information again, the ufl file is still the same
> This is FFC, the FEniCS Form Compiler, version 1.0.0.
> For further information, visit http://www.fenics.org/ffc/.
>
> Expecting 'forms' to be a list of Form instances.
> Traceback (most recent call last):
> File "/home/pietro/FEniCS/bin/ffc", line 195, in <module>
> sys.exit(main(sys.argv[1:]))
> File "/home/pietro/FEniCS/bin/ffc", line 159, in main
> ufd = load_ufl_file(filename)
> File "/home/pietro/FEniCS/lib/python2.7/site-packages/ufl/algorithms/formfiles.py", line 164, in load_ufl_file
> "Expecting 'forms' to be a list of Form instances.")
> File "/home/pietro/FEniCS/lib/python2.7/site-packages/ufl/assertions.py", line 37, in ufl_assert
> if not condition: error(*message)
> File "/home/pietro/FEniCS/lib/python2.7/site-packages/ufl/log.py", line 148, in error
> raise self._exception_type(self._format_raw(*message))
> ufl.log.UFLException: Expecting 'forms' to be a list of Form instances.
>
> Thanks.
>
> P.
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.

Revision history for this message
Pietro Maximoff (segment-x) said :
#4

Thanks Martin Sandve Alnæs, that solved my question.

Revision history for this message
Kristian B. Ølgaard (k.b.oelgaard) said :
#5

On 17 January 2012 23:05, Martin Sandve Alnæs
<email address hidden> wrote:
> Question #185013 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/185013
>
>    Status: Open => Answered
>
> Martin Sandve Alnæs proposed the following answer:
> Ok. I think you triggered a bug not related to your actual problem. You
> do not define any forms in your UFL file, and F is somehow added to the
> forms list. But F is not a Form. Rename F to e.g. F2 and you should get
> some other error. FFC does not compile the UFL file line by line, it is
> executed as a python script and FFC interprets the Form objects. To try
> line by line, you can make it a .py file and add from ufl import * at
> the top to run it with python.

FFC, or actually ufl.algorithms.load_ufl_file, looks for the following
variables when trying to figure out what forms should be handled:

forms, M, L, a, J and F (I actually forgot about J and F until I
looked in the code)

so I guess it is not a big surprise that the above code fails, perhaps
the ufl function should assert that each variable defines a valid form
to produce a better error message?

> Martin
>
>
> Den 17. jan. 2012 kl. 21:15 skrev Pietro Maximoff <email address hidden>:
>
>> Question #185013 on DOLFIN changed:
>> https://answers.launchpad.net/dolfin/+question/185013
>>
>>    Status: Answered => Open
>>
>> Pietro Maximoff is still having a problem:
>> Hi Martin
>>
>> I took out the usual preamble at the top that comes with the demo ufl
>> files, i..e, license information, etc. The ufl file ends at F=?? because
>> I was adding to it line by line and compiling to determine where it
>> fails.
>>
>>
>> Here's the error information again, the ufl file is still the same
>> This is FFC, the FEniCS Form Compiler, version 1.0.0.
>> For further information, visit http://www.fenics.org/ffc/.
>>
>> Expecting 'forms' to be a list of Form instances.
>> Traceback (most recent call last):
>>  File "/home/pietro/FEniCS/bin/ffc", line 195, in <module>
>>    sys.exit(main(sys.argv[1:]))
>>  File "/home/pietro/FEniCS/bin/ffc", line 159, in main
>>    ufd = load_ufl_file(filename)
>>  File "/home/pietro/FEniCS/lib/python2.7/site-packages/ufl/algorithms/formfiles.py", line 164, in load_ufl_file
>>    "Expecting 'forms' to be a list of Form instances.")
>>  File "/home/pietro/FEniCS/lib/python2.7/site-packages/ufl/assertions.py", line 37, in ufl_assert
>>    if not condition: error(*message)
>>  File "/home/pietro/FEniCS/lib/python2.7/site-packages/ufl/log.py", line 148, in error
>>    raise self._exception_type(self._format_raw(*message))
>> ufl.log.UFLException: Expecting 'forms' to be a list of Form instances.
>>
>> Thanks.
>>
>> P.
>>
>> --
>> You received this question notification because you are a member of
>> DOLFIN Team, which is an answer contact for DOLFIN.
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.

Revision history for this message
Pietro Maximoff (segment-x) said :
#6

Thanks Kristian, I'll keep this in mind in the future.

P.

Revision history for this message
Martin Sandve Alnæs (martinal) said :
#7

You can also export forms explicitly by making a list 'forms', e.g.

...
R = f*dx
forms = [R]

OR use the forms a, L, M (intended convention: bilinear, linear, functional),
OR use the forms F, J (intended convention: linear form for residual
equation, bilinear form for Jacobi of F)

Martin

On 18 January 2012 10:31, Pietro Maximoff
<email address hidden> wrote:
> Question #185013 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/185013
>
> Pietro Maximoff posted a new comment:
> Thanks Kristian, I'll keep this in mind in the future.
>
> P.
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.

Revision history for this message
Pietro Maximoff (segment-x) said :
#8

Hi

The ufl file below gives a "tuple index out of range" error in Stage 2 but I can't spot where the problem comes from.

Compiler stage 2: Computing intermediate representation
-------------------------------------------------------
  Computing representation of 4 elements
  Computing representation of 4 dofmaps
  Computing representation of integrals
  Computing quadrature representation
  Transforming cell integral

*** FFC: tuple index out of range

I've checked the shapes of all the tensors and they're all ok.

IncompressibleElasticity.ufl
---
#from ufl import *

# Function spaces
porder = 1
V = VectorElement("CG", tetrahedron, porder) # space for displacements
R = FiniteElement("R", tetrahedron, porder-1) # space for pressure
element = V*R

# Trial and test functions
(u, p) = TrialFunctions(element) # Trial function in the mixed space
(v, q) = TestFunctions(element) # Testfunction in the mixed space

# Functions
B = Coefficient(V) # Body force per unit volume
T = Coefficient(V) # Traction force on the boundary

# Kinematics
I = Identity(element.cell().d) # Identity tensor
F = variable(I + grad(u)) # Deformation gradient
C = variable( transpose(F)*F ) # Right Cauchy-Green tensor
E = variable( 0.5*( C - I ) ) # Green-Lagrange tensor

# Invariants of deformation tensors
Ic = tr(C)
IIc = 0.5*( (tr(C))**2 - tr(C*C) )
IIIc = det(C)
J = det(F)

# Stored strain energy density
c1 = 2.0
c2 = 6.0
W = c1*(Ic-3) + c2*(IIc-3)

S = diff(W, E)
Cinv = transpose(J-1)*diff(J, F)

a = inner( S, grad(v) )*dx - inner( p*Cinv, grad(v) )*dx
L = inner(B, v)*dx + inner(T, v)*ds
#M = q*J*dx

---
P.

Revision history for this message
Best Martin Sandve Alnæs (martinal) said :
#9

Don't know what happens. But R is global constant, try DG for piecewise
constants.

Martin
Den 18. jan. 2012 21.01 skrev "Pietro Maximoff" <
<email address hidden>> følgende:

> Question #185013 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/185013
>
> Status: Solved => Open
>
> Pietro Maximoff is still having a problem:
> Hi
>
> The ufl file below gives a "tuple index out of range" error in Stage 2
> but I can't spot where the problem comes from.
>
> Compiler stage 2: Computing intermediate representation
> -------------------------------------------------------
> Computing representation of 4 elements
> Computing representation of 4 dofmaps
> Computing representation of integrals
> Computing quadrature representation
> Transforming cell integral
>
> *** FFC: tuple index out of range
>
>
> I've checked the shapes of all the tensors and they're all ok.
>
> IncompressibleElasticity.ufl
> ---
> #from ufl import *
>
> # Function spaces
> porder = 1
> V = VectorElement("CG", tetrahedron, porder) # space for
> displacements
> R = FiniteElement("R", tetrahedron, porder-1) # space for
> pressure
> element = V*R
>
> # Trial and test functions
> (u, p) = TrialFunctions(element) #
> Trial function in the mixed space
> (v, q) = TestFunctions(element) #
> Testfunction in the mixed space
>
> # Functions
> B = Coefficient(V)
> # Body force per unit volume
> T = Coefficient(V)
> # Traction force on the boundary
>
> # Kinematics
> I = Identity(element.cell().d) #
> Identity tensor
> F = variable(I + grad(u)) #
> Deformation gradient
> C = variable( transpose(F)*F ) #
> Right Cauchy-Green tensor
> E = variable( 0.5*( C - I ) ) #
> Green-Lagrange tensor
>
> # Invariants of deformation tensors
> Ic = tr(C)
> IIc = 0.5*( (tr(C))**2 - tr(C*C) )
> IIIc = det(C)
> J = det(F)
>
> # Stored strain energy density
> c1 = 2.0
> c2 = 6.0
> W = c1*(Ic-3) + c2*(IIc-3)
>
> S = diff(W, E)
> Cinv = transpose(J-1)*diff(J, F)
>
>
> a = inner( S, grad(v) )*dx - inner( p*Cinv, grad(v) )*dx
> L = inner(B, v)*dx + inner(T, v)*ds
> #M = q*J*dx
>
> ---
> P.
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>

Revision history for this message
Pietro Maximoff (segment-x) said :
#10

Thanks Martin Sandve Alnæs, that solved my question.