[petsc-users] Matrices - Arrays

Matthew Knepley knepley at gmail.com
Tue May 14 16:15:15 CDT 2013


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.

   Matt


> Thanks, keep up the great job guys!!
>
> Regards,
> Anthony Vergottis
>



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


More information about the petsc-users mailing list