Problem with Restriction class

Asked by Edwin Mai on 2013-02-26

Hello,

i found a Problem in the Restriction class.

here my python-code (analog to c++ demo):
n = 5
#Mesh
mesh = UnitSquareMesh(n, n)
#SubDomain
class Boundary(SubDomain):
    def inside(self, x, on_boundary):
        return on_boundary

res = Restriction(mesh, Boundary)

it delivers the error:
  res = Restriction(mesh, Boundary)
  File "/usr/lib/python2.7/dist-packages/dolfin/cpp/mesh.py", line 4981, in __init__
    _mesh.Restriction_swiginit(self,_mesh.new_Restriction(*args))
TypeError: in method 'new_Restriction', argument 1 of type 'dolfin::MeshFunction< std::size_t > const &'

the first argument is the mesh as an instance of the Mesh class and the second of type SubDomain, so why does
it display its of type MeshFunction an raise a error?

Thanks
Edwin

Question information

Language:
English Edit question
Status:
Solved
For:
FEniCS Project Edit question
Assignee:
No assignee Edit question
Solved by:
Johan Hake
Solved:
2013-02-27
Last query:
2013-02-27
Last reply:
2013-02-27
Johan Hake (johan-hake) said : #1

Try:

res = Restriction(mesh, Boundary())

Johan

On 02/27/2013 12:11 AM, Edwin Mai wrote:
> New question #222920 on FEniCS Project:
> https://answers.launchpad.net/fenics/+question/222920
>
> Hello,
>
> i found a Problem in the Restriction class.
>
> here my python-code (analog to c++ demo):
> n = 5
> #Mesh
> mesh = UnitSquareMesh(n, n)
> #SubDomain
> class Boundary(SubDomain):
> def inside(self, x, on_boundary):
> return on_boundary
>
> res = Restriction(mesh, Boundary)
>
> it delivers the error:
> res = Restriction(mesh, Boundary)
> File "/usr/lib/python2.7/dist-packages/dolfin/cpp/mesh.py", line 4981, in __init__
> _mesh.Restriction_swiginit(self,_mesh.new_Restriction(*args))
> TypeError: in method 'new_Restriction', argument 1 of type 'dolfin::MeshFunction< std::size_t > const &'
>
> the first argument is the mesh as an instance of the Mesh class and the second of type SubDomain, so why does
> it display its of type MeshFunction an raise a error?
>
> Thanks
> Edwin
>

Edwin Mai (edwinmai) said : #2

Thanks, it works. How do i create a restriced function space now?
Just using:

V = FunctionSpace(res, "CG", 1)

is throwing an error, because res is not of type mesh.

I try to rewrite my code using the ident_zero() function to restrict a function to the boundary because
it now throws an Argument out of range PETSC error.

Thanks

Johan Hake (johan-hake) said : #3

There is not a python version of the restriction demo. There is probably
a reason for that. Python support for Restrictions are probably not
complete.

> I try to rewrite my code using the ident_zero() function to restrict
> a function to the boundary because it now throws an Argument out of
> range PETSC error.

We cannot help if you do not pass the code.

Johan

On 02/27/2013 12:01 PM, Edwin Mai wrote:
> Question #222920 on FEniCS Project changed:
> https://answers.launchpad.net/fenics/+question/222920
>
> Status: Answered => Open
>
> Edwin Mai is still having a problem: Thanks, it works. How do i
> create a restriced function space now? Just using:
>
> V = FunctionSpace(res, "CG", 1)
>
> is throwing an error, because res is not of type mesh.
>
>
> Thanks
>

Edwin Mai (edwinmai) said : #4

Ok, here is a basic example that computes the unitnormalfield on the boundary as a Function:

from dolfin import*

n = 20
mesh = UnitSquareMesh(n, n)

V = VectorFunctionSpace(mesh, "CG", 1)
X = FunctionSpace(mesh, "CG", 1)

one = interpolate(Constant(1.0), X)
n = FacetNormal(mesh)

nf = TrialFunction(V)
phi = TestFunction(V)
a = inner(nf,phi)*ds
L = inner(n,phi)*ds
A = assemble(a)
A.ident_zeros()
B = assemble(L)
nf = Function(V)
solve(A, nf.vector(), B)

plot(nf, interactive=True)

it plot the function but throws the error
[0]PETSC ERROR: Argument out of range!
[0]PETSC ERROR: New nonzero at (802,802) caused a malloc!
[0]PETSC ERROR: --------------------------------------------------------------------
...
[0]PETSC ERROR: ------------------------------------------------------------------------
[0]PETSC ERROR: MatSetValues_SeqAIJ() line 331 in src/mat/impls/aij/seq/aij.c
[0]PETSC ERROR: MatSetValues() line 1115 in src/mat/interface/

Thanks a lot Johan

Best Johan Hake (johan-hake) said : #5

This is a known problem:

  https://bugs.launchpad.net/bugs/1033611

If I have understood this correct it will generate the correct result
but with a flooded console of annoying messages.

Johan

On 02/27/2013 12:21 PM, Edwin Mai wrote:
> Question #222920 on FEniCS Project changed:
> https://answers.launchpad.net/fenics/+question/222920
>
> Status: Answered => Open
>
> Edwin Mai is still having a problem:
> Ok, here is a basic example that computes the unitnormalfield on the
> boundary as a Function:
>
> from dolfin import*
>
> n = 20
> mesh = UnitSquareMesh(n, n)
>
> V = VectorFunctionSpace(mesh, "CG", 1)
> X = FunctionSpace(mesh, "CG", 1)
>
> one = interpolate(Constant(1.0), X)
> n = FacetNormal(mesh)
>
> nf = TrialFunction(V)
> phi = TestFunction(V)
> a = inner(nf,phi)*ds
> L = inner(n,phi)*ds
> A = assemble(a)
> A.ident_zeros()
> B = assemble(L)
> nf = Function(V)
> solve(A, nf.vector(), B)
>
> plot(nf, interactive=True)
>
> it plot the function but throws the error
> [0]PETSC ERROR: Argument out of range!
> [0]PETSC ERROR: New nonzero at (802,802) caused a malloc!
> [0]PETSC ERROR: --------------------------------------------------------------------
> ...
> [0]PETSC ERROR: ------------------------------------------------------------------------
> [0]PETSC ERROR: MatSetValues_SeqAIJ() line 331 in src/mat/impls/aij/seq/aij.c
> [0]PETSC ERROR: MatSetValues() line 1115 in src/mat/interface/
>
> Thanks a lot Johan
>

Edwin Mai (edwinmai) said : #6

Thanks Johan Hake, that solved my question.