modifyprop_par.c
Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
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     
00043     nsliceprop=0;
00044     PetscPrintf(PETSC_COMM_WORLD,
00045       "Option -nsliceproppar not found, using default value %i!\n",
00046       nsliceprop
00047     );
00048   }
00049 
00050   
00051   if (nsliceprop<=0) {
00052     PetscPrintf(PETSC_COMM_WORLD,
00053       "nsliceproppar==%i, nothing modified!\n",
00054       nsliceprop
00055     );
00056     MagparFunctionLogReturn(0);
00057   }
00058 
00059   
00060   PetscReal ep0, ew; 
00061   ep0= 0.1;
00062   ew=  0.25;
00063 
00064   int ps0, ns; 
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       
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         
00107 
00108 
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 
00118 
00119 
00120 
00121 
00122 
00123 
00124 
00125 
00126 
00127 
00128 
00129     }
00130   }
00131 
00132   MagparFunctionLogReturn(0);
00133 }
00134