matcreateseqadj.c

Go to the documentation of this file.
00001 /*
00002     This file is part of magpar.
00003 
00004     Copyright (C) 2006-2009 Werner Scholz
00005 
00006     www:   http://www.magpar.net/
00007     email: magpar(at)magpar.net
00008 
00009     magpar is free software; you can redistribute it and/or modify
00010     it under the terms of the GNU General Public License as published by
00011     the Free Software Foundation; either version 2 of the License, or
00012     (at your option) any later version.
00013 
00014     magpar is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017     GNU General Public License for more details.
00018 
00019     You should have received a copy of the GNU General Public License
00020     along with magpar; if not, write to the Free Software
00021     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 */
00023 
00024 static char const Id[] = "$Id: matcreateseqadj.c 2681 2009-07-31 04:30:53Z scholz $\n\n";
00025 static char const Td[] = "$Today: " __FILE__ "  " __DATE__ "  "  __TIME__  " $\n\n";
00026 
00027 #define PREALLOC_DG 20
00028 #include "util.h"
00029 
00030 int matcreateseqadj(int nvert,int nele,int *elevert,Mat *matout)
00031 {
00032   MagparFunctionInfoBegin;
00033 
00034   int *ia,*ja;
00035   ierr = Mesh2Nodal(nele,nvert,elevert,&ia,&ja);CHKERRQ(ierr);
00036 
00037   /* calculate number of nonzeroes for each line */
00038   for (int i=0;i<nvert;i++) {
00039     ia[i]=ia[i+1]-ia[i]+1;
00040   }
00041 
00042   /* create matrix mat */
00043   Mat mat;
00044   ierr = MatCreateSeqAIJ(
00045     PETSC_COMM_SELF,
00046     nvert,nvert,
00047     0,ia,
00048 /*
00049     PREALLOC_DG,PETSC_NULL,
00050 */
00051     &mat
00052   );CHKERRQ(ierr);
00053   ierr = MatSetFromOptions(mat);CHKERRQ(ierr);
00054 
00055   ierr = PetscFree(ia);CHKERRQ(ierr);
00056   ierr = PetscFree(ja);CHKERRQ(ierr);
00057 
00058   for (int i=0; i<nele; i++) {
00059     for (int l=0;l<NV;l++) {
00060       for (int j=0;j<NV;j++) {
00061         /* set stiffness matrix element */
00062         ierr = MatSetValue(
00063           mat,
00064           elevert[i*NV+j],
00065           elevert[i*NV+l],
00066           1.0,
00067           ADD_VALUES
00068         );CHKERRQ(ierr);
00069       } /* end for j loop */
00070     }
00071   }
00072 
00073   PetscInfo(0,"mat matrix assembly complete\n");
00074   ierr = MatAssemblyBegin(mat,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
00075   ierr = MatAssemblyEnd(mat,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
00076 
00077   *matout=mat;
00078 
00079   MagparFunctionInfoReturn(0);
00080 }
00081 

magpar - Parallel Finite Element Micromagnetics Package
Copyright (C) 2002-2009 Werner Scholz