hexternal.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: hexternal.c 3001 2010-03-15 15:22:36Z scholz $\n\n";
00025 static char const Td[] = "$Today: " __FILE__ "  " __DATE__ "  "  __TIME__  " $\n\n";
00026 
00027 #include "field.h"
00028 #include "util/util.h"
00029 
00030 #ifdef ADDONS
00031 #include "addons/addons.h"
00032 #endif
00033 
00034 #ifdef SPINTORQ
00035 #include "spintorq/spintorq.h"
00036 #endif
00037 
00038 static int doinit=1;
00039 static Vec VHextsum=PETSC_NULL;
00040 static PetscReal hextsum=0;
00041 
00042 int Hexternal_Init(GridData *gdata)
00043 {
00044   MagparFunctionLogBegin;
00045 
00046   PetscPrintf(PETSC_COMM_WORLD,"Hexternal on\n");
00047 
00048   ierr = VecDuplicate(gdata->M,&VHextsum);CHKERRQ(ierr);
00049   ierr = VecDuplicate(gdata->M,&gdata->VHext);CHKERRQ(ierr);
00050 
00051   MagparFunctionLogReturn(0);
00052 }
00053 
00054 
00055 int Hexternal(GridData *gdata,Vec VHtotsum)
00056 {
00057   MagparFunctionInfoBegin;
00058 
00059   /* initialize if necessary */
00060   if (doinit) {
00061     ierr = Hexternal_Init(gdata);CHKERRQ(ierr);
00062     doinit=0;
00063   }
00064 
00065   hextsum=0;
00066   ierr = VecZeroEntries(VHextsum);CHKERRQ(ierr);
00067 
00068   PetscReal hext;
00069   hext=0;ierr = Hext_ho(gdata,VHextsum,&hext);CHKERRQ(ierr); hextsum += hext;
00070   hext=0;ierr = Hext_kq(gdata,VHextsum,&hext);CHKERRQ(ierr); hextsum += hext;
00071   hext=0;ierr = Hext_cu(gdata,VHextsum,&hext);CHKERRQ(ierr); hextsum += hext;
00072   hext=0;ierr = Hext_py(gdata,VHextsum,&hext);CHKERRQ(ierr); hextsum += hext;
00073 #ifdef ADDONS
00074   hext=0;ierr = Hext_ac(gdata,VHextsum,&hext);CHKERRQ(ierr); hextsum += hext;
00075   hext=0;ierr = Hext_co(gdata,VHextsum,&hext);CHKERRQ(ierr); hextsum += hext;
00076   hext=0;ierr = Hext_do(gdata,VHextsum,&hext);CHKERRQ(ierr); hextsum += hext;
00077   hext=0;ierr = Hext_ht1(gdata,VHextsum,&hext);CHKERRQ(ierr);hextsum += hext;
00078   hext=0;ierr = Hext_ht2(gdata,VHextsum,&hext);CHKERRQ(ierr);hextsum += hext;
00079   hext=0;ierr = Hext_mp(gdata,VHextsum,&hext);CHKERRQ(ierr); hextsum += hext;
00080   hext=0;ierr = Hext_pd(gdata,VHextsum,&hext);CHKERRQ(ierr); hextsum += hext;
00081   hext=0;ierr = Hext_rg(gdata,VHextsum,&hext);CHKERRQ(ierr); hextsum += hext;
00082   hext=0;ierr = Hext_tf(gdata,VHextsum,&hext);CHKERRQ(ierr); hextsum += hext;
00083 #endif
00084 #ifdef SPINTORQ
00085   hext=0;ierr = Hcurrent(gdata,VHextsum,&hext);CHKERRQ(ierr);hextsum += hext;
00086   hext=0;ierr = Hcurrent_stack(gdata,VHextsum,&hext);CHKERRQ(ierr);hextsum += hext;
00087 #endif
00088 
00089   /* copy total field into VHext */
00090   ierr = VecCopy(VHextsum,gdata->VHext);CHKERRQ(ierr);
00091 
00092   ierr = VecAXPY(VHtotsum,1,VHextsum);CHKERRQ(ierr);
00093 
00094   MagparFunctionProfReturn(0);
00095 }
00096 
00097 
00098 int Hexternal_Energy(GridData *gdata,Vec VMom,PetscReal *energy)
00099 {
00100   PetscReal e;
00101 
00102   MagparFunctionInfoBegin;
00103 
00104   ierr = VecDot(VMom,VHextsum,&e);CHKERRQ(ierr);
00105   e *= -1.0;
00106 
00107   *energy=e;
00108 
00109   MagparFunctionProfReturn(0);
00110 }
00111 
00112 
00113 PetscReal Hexternal_hext()
00114 {
00115   MagparFunctionInfoBegin;
00116   MagparFunctionInfoReturn(hextsum);
00117 }
00118 

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