hext_cu.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: hext_cu.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 "field.h"
00028 
00029 static int       doinit=1;
00030 static int       fieldon=0;
00031 static Vec       VHthis;
00032 static PetscReal hextamp=0.5; /* Field strength in Tesla */
00033 
00034 int Hext_cu_Init(GridData *gdata)
00035 {
00036   PetscTruth     flg;
00037 
00038   MagparFunctionLogBegin;
00039 
00040   ierr = PetscOptionsGetInt(PETSC_NULL,"-hext_cu",(PetscInt*)&fieldon,&flg);CHKERRQ(ierr);
00041   if (flg!=PETSC_TRUE) {
00042     fieldon=0;
00043     PetscPrintf(PETSC_COMM_WORLD,
00044       "Option -hext_cu not found, using default value: %i (field off)\n",
00045       fieldon
00046     );
00047   }
00048   if (!fieldon) {
00049     PetscPrintf(PETSC_COMM_WORLD,"Hext_cu off\n");
00050     MagparFunctionLogReturn(0);
00051   }
00052   PetscPrintf(PETSC_COMM_WORLD,"Hext_cu on\n");
00053 
00054   ierr = VecDuplicate(gdata->M,&VHthis);CHKERRQ(ierr);
00055 
00056   /* this example sets the external field in a certain area to a
00057      non-zero value and everywhere else to zero
00058   */
00059 
00060   /* make the vector of the external field accessible */
00061   PetscReal *ta_Hext;
00062   ierr = VecGetArray(VHthis,&ta_Hext);CHKERRQ(ierr);
00063 
00064   /* loop over all (local) nodes */
00065   for (int j=0; j<gdata->ln_vert; j++) {
00066     /* select nodes within a rectangular area */
00067     if (
00068       gdata->vertxyz[ND*gdata->vertl2g[j]+0]>=65.0 &&
00069       gdata->vertxyz[ND*gdata->vertl2g[j]+0]<=250.0 &&
00070       gdata->vertxyz[ND*gdata->vertl2g[j]+1]>=192.0 &&
00071       gdata->vertxyz[ND*gdata->vertl2g[j]+1]<=310.0
00072     ) {
00073       /* set the direction of the field (unit vector!) */
00074 
00075       PetscReal hextxyz[ND]={1.0,0.0,0.0};
00076       for (int i=0; i<ND; i++) {
00077         ta_Hext[ND*j+i]=hextxyz[i];
00078       }
00079     }
00080     else {
00081       /* set the field to zero outside the rectangular area */
00082       for (int i=0; i<ND; i++) {
00083         ta_Hext[ND*j+i]=0.0;
00084       }
00085     }
00086   }
00087   ierr = VecRestoreArray(VHthis,&ta_Hext);CHKERRQ(ierr);
00088   
00089   /* scale the vector to set the field strength */
00090   ierr = VecScale(gdata->VHext,hextamp);CHKERRQ(ierr);
00091 
00092   MagparFunctionLogReturn(0);
00093 }
00094 
00095 
00096 int Hext_cu(GridData *gdata,Vec VHextsum,PetscReal *hext)
00097 {
00098   MagparFunctionInfoBegin;
00099 
00100   /* to be implemented by the user */
00101 
00102   if (doinit) {
00103     ierr = Hext_cu_Init(gdata);CHKERRQ(ierr);
00104     doinit=0;
00105   }
00106   if (!fieldon) {
00107     MagparFunctionInfoReturn(0);
00108   }
00109 
00110   ierr = VecAXPY(VHextsum,1.0,VHthis);CHKERRQ(ierr);
00111 
00112   *hext=hextamp;
00113 
00114   MagparFunctionProfReturn(0);
00115 }
00116 

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