hext_kq.c

Go to the documentation of this file.
00001 /*
00002     This file is part of magpar.
00003 
00004     Copyright (C) 2009 Josephat Kalezhi
00005     Copyright (C) 2002-2010 Werner Scholz
00006 
00007     www:   http://www.magpar.net/
00008     email: magpar(at)magpar.net
00009 
00010     magpar is free software; you can redistribute it and/or modify
00011     it under the terms of the GNU General Public License as published by
00012     the Free Software Foundation; either version 2 of the License, or
00013     (at your option) any later version.
00014 
00015     magpar is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU General Public License for more details.
00019 
00020     You should have received a copy of the GNU General Public License
00021     along with magpar; if not, write to the Free Software
00022     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 */
00024 
00025 /*
00026 Karlqvist type ring head model
00027 
00028 Reference:
00029 
00030 C. Denis Mee, Eric D. Daniel,
00031 "Magnetic Recording Technology"
00032 2nd ed. 1990
00033 Sec. 2.1.2, p. 2.3
00034 http://books.google.co.uk/books?id=extQfrcDveYC&pg=SA2-PA1&dq=recording+and+reproduce+theory+middleton&cd=1#v=onepage&q=recording%20and%20reproduce%20theory%20middleton&f=true
00035 
00036 Hx = (Hg/pi)*(atan((g/2 + x)/y) + atan((g/2 - x)/y) )
00037 Hy = -(Hg/2*pi)*log(((g/2 + x)2 + y2)/((g/2 -x)2 + y2))
00038 
00039 Hx/Hy represent the horizontal/vertical component of the field.
00040 Hg is the head gap field
00041 g is the gapsize
00042 x is the horizontal offset
00043 y is the vertical offset
00044 */
00045 
00046 static char const Id[] = "$Id: hext_kq.c 3024 2010-03-28 17:17:35Z scholz $\n\n";
00047 static char const Td[] = "$Today: " __FILE__ "  " __DATE__ "  "  __TIME__  " $\n\n";
00048 
00049 #include "griddata.h"
00050 
00051 static int       doinit=1;
00052 static int       fieldon=0;
00053 static Vec       VHthis;
00054 static PetscReal hextamp; /* Field strength in Tesla */
00055 
00056 int Hext_kq_Init(GridData *gdata)
00057 {
00058   MagparFunctionLogBegin;
00059 
00060   PetscTruth flg;
00061   ierr = PetscOptionsGetInt(PETSC_NULL,"-hext_kq",(PetscInt*)&fieldon,&flg);CHKERRQ(ierr);
00062   if (flg!=PETSC_TRUE) {
00063     fieldon=0;
00064     PetscPrintf(PETSC_COMM_WORLD,
00065     "Option -hext_kq not found, using default value: %i (field off)\n",
00066     fieldon
00067     );
00068   }
00069 
00070   if (!fieldon) {
00071     PetscPrintf(PETSC_COMM_WORLD,"Hext_kq off\n");
00072     MagparFunctionLogReturn(0);
00073   }
00074   PetscPrintf(PETSC_COMM_WORLD,"Hext_kq on\n");
00075 
00076   PetscReal hgapini;
00077   ierr = PetscOptionsGetReal(PETSC_NULL,"-hext_kq_gapini",&hgapini,&flg);CHKERRQ(ierr);
00078   if (flg!=PETSC_TRUE) {
00079     hgapini=50.0;
00080     PetscPrintf(PETSC_COMM_WORLD,
00081     "Option -hext_kq_gapini not found. Using default value %g\n",
00082     hgapini
00083     );
00084   }
00085   PetscPrintf(PETSC_COMM_WORLD,"hext_kq_gapini %g\n",hgapini);
00086 
00087   PetscReal gapsize;
00088   ierr = PetscOptionsGetReal(PETSC_NULL,"-hext_kq_gapsize",&gapsize,&flg);CHKERRQ(ierr);
00089   if (flg!=PETSC_TRUE) {
00090     gapsize=25.0;
00091     PetscPrintf(PETSC_COMM_WORLD,
00092     "Option -hext_kq_gapsize not found. Using default value %g\n",
00093     gapsize
00094     );
00095   }
00096   PetscPrintf(PETSC_COMM_WORLD,"kq_gap_size %g\n",gapsize);
00097 
00098   PetscReal x_offset;
00099   ierr = PetscOptionsGetReal(PETSC_NULL,"-hext_kq_x_offset",&x_offset,&flg);CHKERRQ(ierr);
00100   if (flg!=PETSC_TRUE) {
00101     x_offset=0.0;
00102     PetscPrintf(PETSC_COMM_WORLD,
00103     "Option -hext_kq_x_offset not found. Using default value %g\n",
00104     x_offset
00105     );
00106   }
00107   PetscPrintf(PETSC_COMM_WORLD,"kq_value of x_offset %g\n",x_offset);
00108 
00109   PetscReal z_offset;
00110   ierr = PetscOptionsGetReal(PETSC_NULL,"-hext_kq_z_offset",&z_offset,&flg);CHKERRQ(ierr);
00111   if (flg!=PETSC_TRUE) {
00112     z_offset=0.0;
00113     PetscPrintf(PETSC_COMM_WORLD,
00114     "Option -hext_kq_z_offset not found. Using default value %g\n",
00115     z_offset
00116     );
00117   }
00118   PetscPrintf(PETSC_COMM_WORLD,"kq_z_offset %g\n",z_offset);
00119 
00120   ierr = VecDuplicate(gdata->M,&VHthis);CHKERRQ(ierr);
00121 
00122   /* this sets the external field according to Karlqvist */
00123 
00124   /* make the vector of the external field accessible */
00125   PetscReal *ta_Hext;
00126   ierr = VecGetArray(VHthis,&ta_Hext);CHKERRQ(ierr);
00127 
00128   hgapini *=1000.0; /* in A/m */
00129   hgapini /= gdata->hscale/MU0; /* scaled */
00130   hextamp=hgapini;
00131 
00132   for (int j=0; j<gdata->ln_vert; j++) {
00133     PetscReal x,y,z;
00134     x = gdata->vertxyz[ND*gdata->vertl2g[j]+0];
00135     y = gdata->vertxyz[ND*gdata->vertl2g[j]+1];
00136     z = gdata->vertxyz[ND*gdata->vertl2g[j]+2];
00137 
00138     /* Using a ring head */
00139 
00140     PetscReal x_coord, z_coord;
00141     /* horizontal separation between head centre and point in question */
00142     x_coord = x_offset*1e-9 + x*gdata->lenscale;
00143     /* vertical separation between head centre and point in question */
00144     z_coord = z_offset*1e-9 + z*gdata->lenscale;
00145 
00146     PetscReal hx,hy,hz;
00147     hx = (hgapini/PETSC_PI)*
00148          (atan(((gapsize*1e-9)/2.0 + x_coord)/z_coord) +
00149           atan(((gapsize*1e-9)/2.0 - x_coord)/z_coord));
00150     hy = 0;
00151     hz = -(hgapini/(2*PETSC_PI))*
00152          log((((gapsize*1e-9)/2.0 + x_coord)*((gapsize*1e-9)/2.0 + x_coord) + z_coord*z_coord)/
00153              (((gapsize*1e-9)/2.0 - x_coord)*((gapsize*1e-9)/2.0 - x_coord) + z_coord*z_coord)
00154             );
00155 
00156     PetscPrintf(PETSC_COMM_WORLD,"Coordinates: (%g,%g,%g)\n",x,y,z);
00157     PetscPrintf(PETSC_COMM_WORLD,"Field:       (%g,%g,%g)\n",hx,hy,hz);
00158 
00159     ta_Hext[ND*j+0]= hx;
00160     ta_Hext[ND*j+1]= hy;
00161     ta_Hext[ND*j+2]= hz;
00162   }
00163   ierr = VecRestoreArray(VHthis,&ta_Hext);CHKERRQ(ierr);
00164 
00165   ierr = VecScale(gdata->VHext,hextamp);CHKERRQ(ierr);
00166 
00167   MagparFunctionLogReturn(0);
00168 }
00169 
00170 
00171 int Hext_kq(GridData *gdata,Vec VHextsum,PetscReal *hext)
00172 {
00173   MagparFunctionInfoBegin;
00174 
00175   if (doinit) {
00176     ierr = Hext_kq_Init(gdata);CHKERRQ(ierr);
00177     doinit=0;
00178   }
00179   if (!fieldon) {
00180     MagparFunctionInfoReturn(0);
00181   }
00182 
00183   ierr = VecAXPY(VHextsum,1.0,VHthis);CHKERRQ(ierr);
00184 
00185   *hext=hextamp;
00186 
00187   MagparFunctionProfReturn(0);
00188 }
00189 

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