C++ matrix/vector initialization in constructor

Umut Tabak u.tabak at tudelft.nl
Tue Oct 20 19:27:16 CDT 2009

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

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,

More information about the petsc-users mailing list