This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Interpolation on mixef function space failled

+1 vote

Hi Everyone,

Please I have the following problem with interpolation. Everything was working until I defined the initial conditions following the Cahn-Hilliard equation demo found below;

http://fenicsproject.org/documentation/dolfin/1.1.0/python/demo/pde/cahn-hilliard/python/documentation.html

U= (U1,U2) and u=(u1,u2) are vector functions with U1(x,y,0)=U2(x,y,0)=u1(x,y,0)=u2(x,y,0)=y

phi(x,y,0)= 0.01 and p(x,y,0)=0.0 are scalar functions. A sample code is below and I uncounted the error when I defined the initial condition class. My domain in [-1,1]*[-1,1].

I will be glad if someone could explain to me what the problem is . Thank you so much.

from dolfin import *

class PeriodicBoundary(SubDomain):

# left boundary is "target domain"
def inside(self, x, on_boundary):
    return bool(x[0]< DOLFIN_EPS and x[0]> - DOLFIN_EPS and on_boundary)

# Map right boundary to left boundary
def map(self, x, y):
    y[0] = x[0] - 1.0
    y[1] = x[1]

pbc = PeriodicBoundary()

mesh = RectangleMesh(Point(-1,-1),Point(1,1),200,200) #Domain[-1,1]*[-1,1]

V1= VectorFunctionSpace(mesh, 'CG', degree=2, constrained_domain = pbc)
V2=VectorFunctionSpace(mesh, 'CG', degree=2, constrained_domain= pbc)
Q1 = FunctionSpace(mesh, 'CG', degree=1, constrained_domain = pbc )
Q2 = FunctionSpace(mesh, 'CG', degree=1, constrained_domain = pbc)
VQ = MixedFunctionSpace([V1,V2, Q1, Q2])

(U,u, phi,p)= TrialFunctions(VQ)
(m,n,q,r) = TestFunctions(VQ)
H= Function(VQ)

Sub domain for Dirichlet boundary condition

class Top(SubDomain):
def inside(self, x, on_boundary):
return (x[1]>1 - DOLFIN_EPS and on_boundary)

class Bottom(SubDomain):
def inside(self, x, on_boundary):
return (x[1]< -1 + DOLFIN_EPS and on_boundary)

UB= Constant((-1,0))
UT= Constant((1,0))
ub= Constant((-1,0))
ut= Constant((1,0))

top= Top()
bott = Bottom()

bcUB= DirichletBC(VQ.sub(0), UB ,bott)
bcUT= DirichletBC(VQ.sub(0), UB ,top)
bcub= DirichletBC(VQ.sub(1), ub ,bott )
bcut= DirichletBC(VQ.sub(1), ub ,top )

bcs = [bcUB,bcUT, bcub,bcut]

class InitialConditions(Expression):
def eval(self, values, x):
values[0] = x[1]
values[1] = x[1]
values[2] = x[1]
values[3] = x[1]
values[4] = 0.01
values[5] = 0

def value_shape(self):
    return (6,)

u_init = InitialConditions()
ALL_initial = interpolate(u_init, H)

This is the error that followed

Traceback (most recent call last):
File "proj.py", line 125, in
ALL_initial = interpolate(u_init, H)
File "/usr/lib/python2.7/dist-packages/dolfin/fem/interpolation.py", line 60, in interpolate
"Illegal function space for interpolation, not a FunctionSpace (%s)" % str(v))
File "/usr/lib/python2.7/dist-packages/dolfin/cpp/common.py", line 2611, in dolfin_error
return _common.dolfin_error(location, task, reason)
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@fenicsproject.org


*** Remember to include the error message listed below and, if possible,
*** include a minimal running example to reproduce the error.


*** -------------------------------------------------------------------------
*** Error: Unable to compute interpolation.
*** Reason: Illegal function space for interpolation, not a FunctionSpace (f_35).
*** Where: This error was encountered inside interpolation.py.
*** Process: 0


*** DOLFIN version: 1.6.0
*** Git changeset: unknown
*** -------------------------------------------------------------------------

asked Nov 14, 2015 by Vivian FEniCS Novice (550 points)

1 Answer

+3 votes
 
Best answer

Hi, consider

ic = interpolate(u_init, VQ)

The second argument needs to be a FunctionSpace and not Function (like H in your code).

answered Nov 16, 2015 by MiroK FEniCS Expert (80,920 points)
selected Nov 17, 2015 by Vivian

Thank you. That works.

...