← Back to team overview

dolfin team mailing list archive

[Bug 740293] [NEW] SWIG does not pass correct type to PETScKrylovSolver

 

Public bug reported:

The following code fails with
TypeError: in method 'new_Function', argument 1 of type 'dolfin::Function const &'


from dolfin import *

def boundary(x,on_boundary):
    return on_boundary

mesh = UnitSquare(32, 32)
V = FunctionSpace(mesh, 'CG', 1)

bc = DirichletBC(V, Constant(0.0), boundary)
u = TrialFunction(V)
v = TestFunction(V)
a = inner(grad(u), grad(v))*dx

class NewtonMatrix(PETScKrylovMatrix) :
    def __init__(self) :
        PETScKrylovMatrix.__init__(self, V.dim(), V.dim())

    def mult(self, *args) :  
        du = Function(V,args[0])
        f = du*v*dx
        problem = VariationalProblem(a, f, bc)
        dy = problem.solve()
        args[1][:] = down_cast(dy.vector())

y_petsc = PETScVector(V.dim()); y_petsc[:] = 1.0
x_petsc = PETScVector(V.dim())

NewtonSolver = PETScKrylovSolver('cg', 'none')
NewtonSolver.solve(NewtonMatrix(), x_petsc, y_petsc)

** Affects: dolfin
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of DOLFIN
Team, which is subscribed to DOLFIN.
https://bugs.launchpad.net/bugs/740293

Title:
  SWIG does not pass correct type to PETScKrylovSolver

Status in DOLFIN:
  New

Bug description:
  The following code fails with
  TypeError: in method 'new_Function', argument 1 of type 'dolfin::Function const &'

  
  from dolfin import *

  def boundary(x,on_boundary):
      return on_boundary

  mesh = UnitSquare(32, 32)
  V = FunctionSpace(mesh, 'CG', 1)

  bc = DirichletBC(V, Constant(0.0), boundary)
  u = TrialFunction(V)
  v = TestFunction(V)
  a = inner(grad(u), grad(v))*dx

  class NewtonMatrix(PETScKrylovMatrix) :
      def __init__(self) :
          PETScKrylovMatrix.__init__(self, V.dim(), V.dim())

      def mult(self, *args) :  
          du = Function(V,args[0])
          f = du*v*dx
          problem = VariationalProblem(a, f, bc)
          dy = problem.solve()
          args[1][:] = down_cast(dy.vector())

  y_petsc = PETScVector(V.dim()); y_petsc[:] = 1.0
  x_petsc = PETScVector(V.dim())

  NewtonSolver = PETScKrylovSolver('cg', 'none')
  NewtonSolver.solve(NewtonMatrix(), x_petsc, y_petsc)



Follow ups

References