C++ matrix/vector initialization in constructor

Matthew Knepley knepley at gmail.com
Wed Oct 21 04:25:16 CDT 2009

The types Mat and Vec are actually pointers. The assignments are just
pointer copies.


On Tue, Oct 20, 2009 at 7:27 PM, Umut Tabak <u.tabak at tudelft.nl> wrote:

> Dear all,
> I tried to write a very primitive wrapper class for a linear equation
> solver, Ax=B. I am puzzled at a point and turned to the list. In  my
> constructors, I use
> solveKxF::solveKxF(Mat &K, Vec &F, Vec &x)
> { // assign
>  A = K; B = F;
>  VecDuplicate(x, &y);
>  // set up the solver
>  setUpSolver();
> }
> K and F are allocated before creating the object, however I do no
> allocation for A and B and PETSc automatically does the trick for me, right?
> (At least, it seems that way.) I just have the data members Mat A and Vec B
> which seems to work as above where the allocation is somewhere going behind
> the scenes in this assignment/initialization(which one is right term I am
> not sure).
> Best regards,
> Umut

What most experimenters take for granted before they begin their experiments
is infinitely more interesting than any results to which their experiments
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20091021/4d37e16c/attachment.htm>

More information about the petsc-users mailing list