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

How to use set_operator in c++

0 votes

I have this code in python:

L_mat = dolfin.assemble(L)
A_mat = dolfin.assemble(a)

bc.apply(A_mat,L_mat)

solver = dolfin.LUSolver(lu_solver)
solver.set_operator(A_mat)

solver.solve(u_vector, L_mat)

where L is a linear form and a is a bilinear form, lu_solver is just a string specifying the LU solver to use and u_vector is just the vector associated to the solution function.

Now, I am trying to convert this code into c++ code but I am running into problems. My first try was:

dolfin::Matrix A_mat;
dolfin::Vector L_mat;

dolfin::assemble(L_mat,L);
dolfin::assemble(A_mat,a);

bc.apply(A_mat,L_mat);

dolfin::LinearSolver solver(lu_solver);
solver.set_operator(A_mat);

solver.solver(*(u.vector()),b);

This gives an error:

error: no viable conversion from 'dolfin::Matrix' to 'std::shared_ptr<const GenericLinearOperator>'

What I understand is that u.vector() is a std::shared_ptr but A_mat is not, but set_operator requires a std::shared_ptr of time GenericLinearOperator. Am I initialising the matrix correctly? Should I create a shared pointer? How?

Thank you for your help.

asked Apr 1, 2015 by apalha FEniCS Novice (440 points)

1 Answer

+1 vote
 
Best answer

The set_operator function expects a shared pointer.

I suggest either rewriting your C++ code using shared pointers, or using the simple solve interface: solve(A, *u.vector(), b).

answered Apr 2, 2015 by logg FEniCS Expert (11,790 points)
selected Apr 13, 2015 by apalha

Thank you for your answer.

...