[petsc-users] Matrices - Arrays

Patrick Sanan psanan at cms.caltech.edu
Tue May 14 16:41:05 CDT 2013


On May 14, 2013, at 2:15 PM, Matthew Knepley wrote:

> On Tue, May 14, 2013 at 4:06 PM, Anthony Vergottis <a.vergottis at gmail.com> wrote:
> To whom it may concern,
> 
> I am very new to Petsc and I would very much appreciate some assistance.
> 
> What would be the best way to create an array of matrix objects? The number of matrix objects required would be determined during run time.
> 
> For example, I am looking into the FEM and I would like to create a matrix for each element (I know how to set up the matrix objects). Therefore, if I am using a mesh with 100 element I would like to determine during runtime that I will need to create 100 "Mat    A[100]" etc, something along those lines. Hope I explained it well.
> 
> Sorry if this is a trivial question but your help would go a long way.
> 
> I don't think you want to do this. Generally, element matrices can be raw arrays. If you really want
> an array of Mat objects, declare it
> 
>   Mat *mats;
> 
> Allocate it
> 
>   ierr = PetscMalloc(numMats * sizeof(Mat), &mats);CHKERRQ(ierr);
> 
> and call MatCreate(), etc. for each entry.
Another alternative is to use a lightweight vector/matrix library for small local matrices. Since you're using C++, an easy-to-use option might be Eigen. 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20130514/774fb09d/attachment.html>


More information about the petsc-users mailing list