[Trilinos-Users] an array of matrices
Chris Baker
cgbaker at gmail.com
Thu Jul 10 16:02:55 MDT 2008
Nikhil,
There are a number of approaches that you can take. Here is one:
// create a vector of smart pointers to CrsMatrix objects
std::vector< Teuchos::RCP< Epetra_CrsMatrix > > A;
for (int i = 0; i < Num; i++) {
// dynamically create the Epetra CrsMatrix A[i]
Teuchos::RCP< Epetra_CrsMatrix > mat = Teuchos::rcp( new
Epetra_CrsMatrix(...) );
// add it to the vector
A.push_back(mat);
}
// now you can loop over your list of matrices
for (int i = 0; i < Num; i++) {
Problem.SetOperator(&*A[i]);
...
Solver->Solve();
}
A benefit to this approach is that you don't have to worry about
deallocating the memory. When the std::vector A goes out of scope and is
deleted, the RCPs (RefCountPtrs) will be deleted along with the matrices
that they point to.
Chris
On Thu, Jul 10, 2008 at 15:39, Nikhil Kriplani <nmkripla at ncsu.edu> wrote:
> Hello,
>
> I am wondering how to create an array of Epetra_CrsMatrices.
> Essentially, I need to have several such matrices (say Num) in my
> program. Each matrix will be LU factored and solved, so I need to do
> something like
>
> for (int i = 0; i < Num; i++)
> {
> Problem.SetOperator(&A[i]);
> ...
> Solver->Solve();
> }
>
> Is there a way to perform this creation?
>
> Thanks,
> --Nikhil
>
> P.S. the standard way for creating multidimensional containers for
> native C++ types (int, double) does not work.
>
> _______________________________________________
> Trilinos-Users mailing list
> Trilinos-Users at software.sandia.gov
> http://software.sandia.gov/mailman/listinfo/trilinos-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://software.sandia.gov/mailman/private/trilinos-users/attachments/20080710/f336241f/attachment.html
More information about the Trilinos-Users
mailing list