astrojuanlu / fenics-recipes

This repository contains conda recipes for the FEniCS libraries
The Unlicense
13 stars 15 forks source link

Wrong paths on DOLFIN errors #28

Open mthewissen opened 9 years ago

mthewissen commented 9 years ago
*** -------------------------------------------------------------------------
*** Error:   Unable to successfully call PETSc function 'KSPSolve'.
*** Reason:  PETSc error code is: 73.
*** Where:   This error was encountered inside /home/juanlu/miniconda/conda-bld/work/dolfin-1.4.0/dolfin/la/PETScKrylovSolver.cpp.
*** Process: unknown
***
*** DOLFIN version: 1.4.0
*** Git changeset: 
*** -------------------------------------------------------------------------

This error was produced by the code below. I encountered other Unable to successfully call PETSc function-errors, too.

from dolfin import *
mesh = UnitSquareMesh(2, 2)
V = FunctionSpace(mesh, 'CG', 1)
u = TrialFunction(V)
v = TestFunction(V)
a = inner(grad(u), grad(v))* dx
f = Expression('x[0]*x[1]')
b = f * v * dx
p = a + u * v * dx

A = assemble(a)
B = assemble(b)
P = assemble(p)

class CompositeOperator(object):
    def __init__(self, A, B, C):
        self.A_mat = as_backend_type(A).mat()
        self.B_vec = as_backend_type(B).vec()
        self.C_vec = as_backend_type(C).vec()

    def mult(self, mat, x, y):
        self.A_mat.mult(x, y)
        a = self.C_vec.dot(x)
        y.axpy(a, self.B_vec)

    def as_petscmatrix(self):
        from petsc4py import PETSc
        mat = PETSc.Mat().createPython(self.A_mat.getSizes(), comm = mpi_comm_world())
        mat.setPythonContext(self)
        return PETScMatrix(mat)

# Apply boundary conditions
bc = DirichletBC(V, 1., "x[1]<DOLFIN_EPS")
bc.apply(A)
bc.apply(P)
C = B.copy()
bc.homogenize()
bc.apply(B)

A_B = CompositeOperator(A, B, C).as_petscmatrix()

solver = PETScKrylovSolver('gmres', 'hypre_amg')
solver.set_operators(A_B, P)

solution = Function(V)
solver.solve(solution.vector(), C)
astrojuanlu commented 9 years ago

There's definitely something happening if my paths appear in your computer. I'll have a look.

astrojuanlu commented 9 years ago

By the way @mthewissen, while I figure out how to fix the paths issue, would you also ask about the error in the fenics-support mailing list or http://fenicsproject.org/qa? Maybe if there's something wrong with the code itself we'll get some hint.

astrojuanlu commented 9 years ago

For reference, error 73 is "object in argument is in wrong state, e.g. unassembled mat".

http://www.mcs.anl.gov/petsc/petsc-master/include/petscerror.h.html

mthewissen commented 9 years ago

I encountered the problem in this qa question. http://fenicsproject.org/qa/7954/apply-dirichlet-boundary-conditions-using-matrix-free-method

I also asked a new one: http://fenicsproject.org/qa/8060/petsckrylovsolver-wont-solve-in-version-1-4-0

Thanks for looking into it

astrojuanlu commented 9 years ago

So it works on 1.6 and not on 1.4, right? Please ping me if someone else proves it right on FEniCS Q&A so I can focus on fixing the paths issue :) Thanks!

mthewissen commented 9 years ago

Correct. However, for 1.6 I use the FEniCS version from the ubuntu repositories (no conda) so I am not sure if that is much help.

On 8 September 2015 at 18:42, Juan Luis Cano Rodríguez < notifications@github.com> wrote:

So it works on 1.6 and not on 1.4, right? Please ping me if someone else proves it right on FEniCS Q&A so I can focus on fixing the paths issue :) Thanks!

— Reply to this email directly or view it on GitHub https://github.com/Juanlu001/fenics-recipes/issues/28#issuecomment-138626971 .

mthewissen commented 8 years ago

If you check the second Q&A question, you will notice that a solution was posted to get rid of the error. Another Unable to successfully call PETSc function-error was also solved (mistake from me), so that leaves you with the question why your path appears.

astrojuanlu commented 8 years ago

Thanks for the update! I will change the title accordingly then.