modifyprop_par.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: modifyprop_par.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 int ModifyPropPar(GridData *gdata)
00031 {
00032   MagparFunctionLogBegin;
00033 
00034   int rank,size;
00035   ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr);
00036   ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr);
00037 
00038   PetscTruth flg;
00039   int nsliceprop;
00040   ierr = PetscOptionsGetInt(PETSC_NULL,"-nsliceproppar",(PetscInt*)&nsliceprop,&flg);CHKERRQ(ierr);
00041   if (flg!=PETSC_TRUE) {
00042     /* set default values if option is missing */
00043     nsliceprop=0;
00044     PetscPrintf(PETSC_COMM_WORLD,
00045       "Option -nsliceproppar not found, using default value %i!\n",
00046       nsliceprop
00047     );
00048   }
00049 
00050   /* exit if there is nothing to modify */
00051   if (nsliceprop<=0) {
00052     PetscPrintf(PETSC_COMM_WORLD,
00053       "nsliceproppar==%i, nothing modified!\n",
00054       nsliceprop
00055     );
00056     MagparFunctionLogReturn(0);
00057   }
00058 
00059   /* sliced4.out */
00060   PetscReal ep0, ew; /* element "position", width */
00061   ep0= 0.1;
00062   ew=  0.25;
00063 
00064   int ps0, ns; /* prop. id of first slice, no. of slices (properties) */
00065   ps0=15;
00066   ns= 40;
00067 
00068   PetscPrintf(PETSC_COMM_WORLD,
00069     "modifyprop: element position: %g width: %g propid: [%i,%i]\n",
00070     ep0,
00071     ew,
00072     ps0,
00073     ps0+ns-1
00074   );
00075 
00076   if (ps0<gdata->n_prop) {
00077     SETERRQ1(PETSC_ERR_ARG_INCOMP,"ps0 < gdata->n_prop in %s\n",__FUNCT__);
00078   }
00079 
00080   if (ns != nsliceprop) {
00081     SETERRQ1(PETSC_ERR_ARG_INCOMP,"ns != nsliceproppar in %s\n",__FUNCT__);
00082   }
00083 
00084   gdata->n_prop += ns;
00085 
00086   PetscPrintf(PETSC_COMM_WORLD,
00087     "modifyprop: rereading %s.krn for %i additional properties\n",
00088     gdata->simname,
00089     ns
00090   );
00091   ierr = PetscFree(gdata->propdat);CHKERRQ(ierr);
00092   ierr = ReadKrn(gdata);CHKERRQ(ierr);
00093 
00094   if (rank) {
00095     ierr = PetscMalloc(gdata->n_prop*NP*sizeof(PetscReal),&gdata->propdat);CHKERRQ(ierr);
00096   }
00097   ierr = MPI_Bcast(gdata->propdat,gdata->n_prop*NP,MPIU_SCALAR,0,PETSC_COMM_WORLD);CHKERRQ(ierr);
00098 
00099   for (int j=0; j<ns; j++) {
00100     for (int i=0; i<gdata->ln_ele; i++) {
00101       int k;
00102       /* get x-coordinate of first vertex */
00103       PetscReal sgn;
00104       sgn=gdata->vertxyz[ND*gdata->elevert[NV*i+0]+0]-(ep0+ew*j);
00105       for (k=1;k<NV;k++) {
00106         /* multiply with other x-coordinate of other vertices
00107            if (product < 0) then they have opposite signs and
00108            the element must be cut by the slice plane
00109         */
00110         if (sgn*(gdata->vertxyz[ND*gdata->elevert[NV*i+k]+0]-(ep0+ew*j)) < 0.0)
00111           break;
00112       }
00113       if (k<NV) {
00114         gdata->eleprop[i]=ps0+j;
00115       }
00116 
00117 /* does not always work (due to strongly deformed elements)
00118       if (PetscAbsReal(
00119             PetscAbsReal(gdata->vertxyz[ND*gdata->elevert[NV*i+0]+0]+
00120                  gdata->vertxyz[ND*gdata->elevert[NV*i+1]+0]+
00121                  gdata->vertxyz[ND*gdata->elevert[NV*i+2]+0]+
00122                  gdata->vertxyz[ND*gdata->elevert[NV*i+3]+0]
00123                 )/NV-(ep-j*ew)
00124               ) <= et
00125          ) {
00126         gdata->eleprop[i]=ps0+j;
00127       }
00128 */
00129     }
00130   }
00131 
00132   MagparFunctionLogReturn(0);
00133 }
00134 

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