bbox2.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: bbox2.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 "util.h"
00028 
00029 int bbox2(GridData *gdata,PetscReal *vertxyz2,int n_prop,int *propid,PetscReal *bbox,int *pix)
00030 {
00031   MagparFunctionLogBegin;
00032 
00033   ierr = calcbbox(gdata->ln_ele,gdata->elevert,gdata->eleprop,vertxyz2,n_prop,propid,bbox);
00034 
00035   /* find longest edge (neglecting z-direction!) */
00036   PetscReal maxedge=0;
00037   for (int i=0;i<ND-1;i++) {
00038     maxedge=PetscMax(maxedge,bbox[ND+i]-bbox[i]);
00039   }
00040 
00041   int res;
00042   res=pix[0];
00043 
00044   /* add approx. 1 pixel around the sample (i.e. 2 pixel to each edge length) */
00045   for (int i=0;i<ND;i++) {
00046     bbox[i]    -= 1.0*maxedge/(res-2);
00047     bbox[ND+i] += 1.0*maxedge/(res-2);
00048   }
00049 
00050   /* shift slightly */
00051   for (int i=0;i<ND;i++) {
00052     bbox[i]    += 0.1*maxedge/(res-2);
00053     bbox[ND+i] += 0.1*maxedge/(res-2);
00054   }
00055   /* adjust maxedge length */
00056   maxedge = maxedge*res/(res-2);
00057 
00058   PetscPrintf(PETSC_COMM_WORLD,
00059     "enlarged bbox: (%g,%g,%g) (%g,%g,%g) (%g,%g,%g)\nmaxedge: %g\n",
00060     bbox[0],bbox[1],bbox[2],bbox[ND+0],bbox[ND+1],bbox[ND+2],
00061     bbox[ND+0]-bbox[0],bbox[ND+1]-bbox[1],bbox[ND+2]-bbox[2],
00062     maxedge
00063   );
00064 
00065   /* calculate number of pixels */
00066   if (pix!=PETSC_NULL) {
00067     for (int i=0;i<ND;i++) {
00068       pix[i]=(int) ceil(res*(bbox[ND+i]-bbox[i])/maxedge);
00069     }
00070 
00071     PetscPrintf(PETSC_COMM_WORLD,
00072       "pixels: %i x %i x %i\n",
00073       pix[0],pix[1],pix[2]
00074     );
00075     PetscPrintf(PETSC_COMM_WORLD,
00076       "pixellength: %g x %g x %g = %g * (%g x %g x %g)\n",
00077       (bbox[ND+0]-bbox[0])/pix[0],
00078       (bbox[ND+1]-bbox[1])/pix[1],
00079       (bbox[ND+2]-bbox[2])/pix[2],
00080       (bbox[ND+0]-bbox[0])/pix[0],
00081       1.0,
00082       (bbox[ND+1]-bbox[1])/pix[1]/((bbox[ND+0]-bbox[0])/pix[0]),
00083       (bbox[ND+2]-bbox[2])/pix[2]/((bbox[ND+0]-bbox[0])/pix[0])
00084     );
00085   }
00086 
00087   MagparFunctionLogReturn(0);
00088 }
00089 

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