vertprop.c

Go to the documentation of this file.
00001 /*
00002     This file is part of magpar.
00003 
00004     Copyright (C) 2002-2010 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: vertprop.c 2962 2010-02-04 19:50:44Z scholz $\n\n";
00025 static char const Td[] = "$Today: " __FILE__ "  " __DATE__ "  "  __TIME__  " $\n\n";
00026 
00027 #include "init.h"
00028 
00029 int VertProp(GridData *gdata)
00030 {
00031   MagparFunctionLogBegin;
00032 
00033   int rank,size;
00034   ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr);
00035   ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr);
00036 
00037   if (rank) {
00038     MagparFunctionLogReturn(0);
00039   }
00040 
00041   /* initialize vertprop array */
00042   ierr = PetscMalloc(gdata->n_vert*sizeof(int),&gdata->vertprop);CHKERRQ(ierr);
00043   for (int i=0; i<gdata->n_vert; i++) {
00044     gdata->vertprop[i]=-1;
00045   }
00046 
00047   /* assign property ids to vertices: larger Ms wins */
00048   for (int i=0; i<gdata->n_ele; i++) {
00049     for (int j=0; j<NV; j++) {
00050       if (gdata->vertprop[gdata->elevert[NV*i+j]]==-1 ||
00051           gdata->propdat[NP*gdata->eleprop[i]+4]>
00052           gdata->propdat[NP*gdata->vertprop[gdata->elevert[NV*i+j]]+4]) {
00053         gdata->vertprop[gdata->elevert[NV*i+j]]=gdata->eleprop[i];
00054       }
00055     }
00056   }
00057 
00058   int *npidvert;
00059   ierr = PetscMalloc(gdata->n_prop*sizeof(int),&npidvert);CHKERRQ(ierr);
00060   for (int i=0; i<gdata->n_prop; i++) {
00061     npidvert[i]=0;
00062   }
00063 
00064   /* verify that all vertices have valid pids */
00065   for (int i=0; i<gdata->n_vert; i++) {
00066     if (gdata->vertprop[i]<0) {
00067       PetscPrintf(PETSC_COMM_WORLD,"Warning: node %i unused\n",i);
00068       gdata->vertprop[i]=0;
00069     }
00070     npidvert[gdata->vertprop[i]]++;
00071     assert(gdata->vertprop[i]<gdata->n_prop);
00072   }
00073 
00074   PetscInfo(0,"   pid |   n_vert\n");
00075   PetscInfo(0,"-----------------\n");
00076   for (int i=0; i<gdata->n_prop; i++) {
00077     PetscInfo2(0,"%6i | %8i\n",i,npidvert[i]);
00078   }
00079 
00080 #ifdef ADDONS
00081   PetscInfo(0,"  vert |   pid    | v_coupl \n");
00082   PetscInfo(0,"----------------------------\n");
00083   for (int i=0; i<gdata->n_vert; i++) {
00084     if (gdata->vertcoupl!=PETSC_NULL) {
00085       PetscInfo3(0,"%6i | %8i | %8i\n",i,gdata->vertprop[i],gdata->vertcoupl[i]);
00086     }
00087     else {
00088       PetscInfo2(0,"%6i | %8i\n",i,gdata->vertprop[i]);
00089     }
00090   }
00091 #endif
00092 
00093   ierr = PetscFree(npidvert);CHKERRQ(ierr);
00094 
00095   MagparFunctionLogReturn(0);
00096 }

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