Cannot infer geometric dimension for this expression

Asked by Yaakoub El Khamra

Greetings
I am running into an interesting problem when I try to add a non-isotropic permeability tensor term to my code. Simplified, what I want to do is something as follows:

coefficient = divergence( K_perm_tensor * gradient ( Pressure ) )

Can someone please help me identify the issue and fix it? I have created a dummy code that mimics the problem here:

from dolfin import *

# Create mesh and define function space
degree = 2
mesh = UnitSquare(32, 32)
V = FunctionSpace(mesh, 'Lagrange', degree)

# Define Dirichlet boundary (x=0,y=0,x=1 or y=1)
def boundary(x):
    return x[0] < DOLFIN_EPS or x[0] > 1.0 - DOLFIN_EPS or \
           x[1] < DOLFIN_EPS or x[1] > 1.0 - DOLFIN_EPS

# Define boundary condition
Pw0 = Constant(1.0)
bc = DirichletBC(V, Pw0, boundary)

# Define the permeability tensor
kxx = 2.0
kyy = 1.0
K = Expression((('k11', '0'), \
                ('0', 'k22')), \
                k11=kxx,k22=kyy)

# Define variational problem for Picard iteration
Pw = TrialFunction(V)
v = TestFunction(V)

Pw_k = interpolate(Expression("-10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)"), V)
Sw = interpolate(Constant(10.0), V) # previous (known) Pw

a = inner(Pw_k*grad(Pw), grad(v))*dx
#f = Expression("10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)")
f = div( K* grad(Pw_k) )
L = f*v*dx

# Picard iterations
Pw = Function(V) # new unknown function
solve(a == L, Pw, bc)

And the following is the error generated when I try to solve the problem:

--------------------------------------------------------------------------
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling DOLFIN just-in-time (JIT) compiler, this may take some time.
 Calling DOLFIN just-in-time (JIT) compiler, this may take some time.
Cannot infer geometric dimension for this expression.
Traceback (most recent call last):
  File "TensorProduct.py", line 39, in <module>
    solve(a == L, Pw, bc)
  File "/home/yye00/Work/FEniCS/lib64/python2.7/site-packages/dolfin/fem/solving.py", line 250, in solve
    _solve_varproblem(*args, **kwargs)
  File "/home/yye00/Work/FEniCS/lib64/python2.7/site-packages/dolfin/fem/solving.py", line 274, in _solve_varproblem
.......

  File "/home/yye00/Work/FEniCS/lib/python2.7/site-packages/ufl/log.py", line 148, in error
    raise self._exception_type(self._format_raw(*message))
ufl.log.UFLException: Cannot infer geometric dimension for this expression.

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
Best Johan Hake (johan-hake) said :
#1

Use:

   K = Expression((('k11', '0'), \
                 ('0', 'k22')), \
                 k11=kxx,k22=kyy, cell=triangle)
   Pw_k = Expression("-10*exp(-(pow(x[0] - 0.5, 2)"\
                     " + pow(x[1] - 0.5, 2)) / 0.02)",\
                     cell=triangle)

and you should be good. Taking spatial derivatives of expressions with
no geometric association is not possible. This can however, be handled
using the cell argument.

Johan

On 07/13/2012 01:41 AM, Yaakoub El Khamra wrote:
> New question #203001 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/203001
>
> Greetings
> I am running into an interesting problem when I try to add a non-isotropic permeability tensor term to my code. Simplified, what I want to do is something as follows:
>
> coefficient = divergence( K_perm_tensor * gradient ( Pressure ) )
>
> Can someone please help me identify the issue and fix it? I have created a dummy code that mimics the problem here:
>
> from dolfin import *
>
> # Create mesh and define function space
> degree = 2
> mesh = UnitSquare(32, 32)
> V = FunctionSpace(mesh, 'Lagrange', degree)
>
> # Define Dirichlet boundary (x=0,y=0,x=1 or y=1)
> def boundary(x):
> return x[0] < DOLFIN_EPS or x[0] > 1.0 - DOLFIN_EPS or \
> x[1] < DOLFIN_EPS or x[1] > 1.0 - DOLFIN_EPS
>
> # Define boundary condition
> Pw0 = Constant(1.0)
> bc = DirichletBC(V, Pw0, boundary)
>
> # Define the permeability tensor
> kxx = 2.0
> kyy = 1.0
> K = Expression((('k11', '0'), \
> ('0', 'k22')), \
> k11=kxx,k22=kyy)
>
> # Define variational problem for Picard iteration
> Pw = TrialFunction(V)
> v = TestFunction(V)
>
> Pw_k = interpolate(Expression("-10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)"), V)
> Sw = interpolate(Constant(10.0), V) # previous (known) Pw
>
> a = inner(Pw_k*grad(Pw), grad(v))*dx
> #f = Expression("10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)")
> f = div( K* grad(Pw_k) )
> L = f*v*dx
>
> # Picard iterations
> Pw = Function(V) # new unknown function
> solve(a == L, Pw, bc)
>
>
>
> And the following is the error generated when I try to solve the problem:
>
>
> --------------------------------------------------------------------------
> Calling FFC just-in-time (JIT) compiler, this may take some time.
> Calling DOLFIN just-in-time (JIT) compiler, this may take some time.
> Calling DOLFIN just-in-time (JIT) compiler, this may take some time.
> Cannot infer geometric dimension for this expression.
> Traceback (most recent call last):
> File "TensorProduct.py", line 39, in <module>
> solve(a == L, Pw, bc)
> File "/home/yye00/Work/FEniCS/lib64/python2.7/site-packages/dolfin/fem/solving.py", line 250, in solve
> _solve_varproblem(*args, **kwargs)
> File "/home/yye00/Work/FEniCS/lib64/python2.7/site-packages/dolfin/fem/solving.py", line 274, in _solve_varproblem
> .......
>
> File "/home/yye00/Work/FEniCS/lib/python2.7/site-packages/ufl/log.py", line 148, in error
> raise self._exception_type(self._format_raw(*message))
> ufl.log.UFLException: Cannot infer geometric dimension for this expression.
>

Revision history for this message
Yaakoub El Khamra (yelkhamra) said :
#2

Absolutely brilliant! Thank you very much, it works!

Regard
Yaakoub

Revision history for this message
Yaakoub El Khamra (yelkhamra) said :
#3

Thanks Johan Hake, that solved my question.