serinit.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: serinit.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 #include "io/magpario.h"
00029 
00030 #ifdef ADDONS
00031 #include "addons/addons.h"
00032 #endif
00033 
00034 int SerInit(GridData *gdata)
00035 {
00036   MagparFunctionLogBegin;
00037 
00038   int rank,size;
00039   ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr);
00040   ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr);
00041 
00042   /* print useful information about magpar itself, library versions, etc. */
00043   ierr = InitInfo();CHKERRQ(ierr);
00044 
00045   PetscPrintf(PETSC_COMM_WORLD,
00046     "--------------------------------------------------------------------------\n"
00047     "Starting single processor part\n"
00048   );
00049 
00050   /* read FE mesh */
00051   ierr = ReadMesh(gdata);CHKERRQ(ierr);
00052 
00053   /* read material properties */
00054   ierr = ReadKrn(gdata);CHKERRQ(ierr);
00055 
00056   /* modify material properties */
00057   ierr = ModifyPropSer(gdata);CHKERRQ(ierr);
00058 #ifdef ADDONS
00059   ierr = ModifyPropSerGrains(gdata);CHKERRQ(ierr);
00060 #endif
00061 
00062   /* initialize magnetization etc. */
00063 
00064 #ifdef ADDONS
00065   /* FIXME: MagInit calls VertProp, which checks vertcouple
00066    * need to initialize before call to MagInit to avoid segv
00067    * better initialize all global variables (gdata struct) elsewhere! */
00068   gdata->vertcoupl=PETSC_NULL;
00069 #endif
00070 
00071   /* we need to initialize the magnetization before we modify the mesh
00072      (i.e. filter elements and possibly remove elements and nodes)
00073      in case we read the magnetization from an inp file
00074   */
00075   ierr = MagInit(gdata);CHKERRQ(ierr);
00076 
00077 #ifdef ADDONS
00078   ierr = Hext_in1_Init(gdata);CHKERRQ(ierr);
00079   ierr = Hext_in2_Init(gdata);CHKERRQ(ierr);
00080   ierr = FilterElements(&gdata->n_ele,&gdata->elevert,&gdata->eleprop,gdata->propdat);CHKERRQ(ierr);
00081   ierr = MeshMirror(&gdata->n_vert,&gdata->n_ele,&gdata->vertxyz,&gdata->elevert,&gdata->eleprop);CHKERRQ(ierr);
00082   ierr = FilterNodes(&gdata->n_vert,&gdata->n_ele,&gdata->vertxyz,gdata->elevert,&gdata->M,&gdata->VH1,&gdata->VH2);CHKERRQ(ierr);
00083   if (!rank) {
00084     gdata->ln_vert=gdata->n_vert;
00085     gdata->ln_ele =gdata->n_ele;
00086   }
00087 #else
00088   Vec dum=PETSC_NULL;
00089   ierr = FilterElements(&gdata->n_ele,&gdata->elevert,&gdata->eleprop,gdata->propdat);CHKERRQ(ierr);
00090   ierr = FilterNodes(&gdata->n_vert,&gdata->n_ele,&gdata->vertxyz,gdata->elevert,&gdata->M,&dum,&dum);CHKERRQ(ierr);
00091   if (!rank) {
00092     gdata->ln_vert=gdata->n_vert;
00093     gdata->ln_ele =gdata->n_ele;
00094   }
00095 #endif
00096 
00097   /* mesh refinement */
00098   ierr = RegularRefinement(gdata);CHKERRQ(ierr);
00099 
00100 #ifdef ADDONS
00101   /* need to do after refinement due to coupling matrix */
00102   ierr = DecoupleGrains(gdata);CHKERRQ(ierr);
00103   /* TODO: cannot move behind Reorder (and avoid renumbering coupling array) because
00104      Reorder generates the gdata->vertl2g, elel2g arrays
00105      should be done separately, so that Reorder really only renumbers vertices and elements
00106   */
00107 #endif
00108 
00109   /* Reorder/renumber nodes and elements */
00110   ierr = Reorder(gdata);CHKERRQ(ierr);
00111 
00112 #ifdef ADDONS
00113   /* save coupling information after reordering */
00114   if (gdata->vertcoupl!=PETSC_NULL) {
00115     char str[256];
00116     ierr = PetscSNPrintf(str,255,"%s.%04i.%s",gdata->simname,gdata->inp,"vertcoupl");CHKERRQ(ierr);
00117     WriteVertcoupl(str,gdata->n_vert,gdata->vertcoupl);
00118   }
00119 #endif
00120 
00121   /* find faces, neighbours, surface */
00122   ierr = FacNB(gdata);CHKERRQ(ierr);
00123 
00124   /* assign property ids to vertices */
00125   ierr = VertProp(gdata);CHKERRQ(ierr);
00126 
00127 #ifdef ADDONS
00128   ierr = DataPartitionSurfSer(gdata);CHKERRQ(ierr);
00129   ierr = DataPartitionSurfSerMoveData(gdata);CHKERRQ(ierr);
00130 #endif
00131 
00132   /* distort surface and/or interior mesh (introduce roughness) */
00133   ierr = DistortMesh(gdata);CHKERRQ(ierr);
00134 
00135   /* distribute data to processors */
00136   ierr = DataMoveData(gdata);CHKERRQ(ierr);
00137 
00138   MagparFunctionLogReturn(0);
00139 }
00140 

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