checkiterationemini.c

Go to the documentation of this file.
00001 /*
00002     This file is part of magpar.
00003 
00004     Copyright (C) 2002-2009 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: checkiterationemini.c 2681 2009-07-31 04:30:53Z scholz $\n\n";
00025 static char const Td[] = "$Today: " __FILE__ "  " __DATE__ "  "  __TIME__  " $\n\n";
00026 
00027 #include "emini.h"
00028 #include "io/magpario.h"
00029 #include "field/field.h"
00030 
00031 static int       doinit=1;
00032 
00033 static int       condinp_equil;
00034 static PetscReal condinp_j;
00035 static PetscReal condinp_equil_j;
00036 
00037 int CheckIterationEmini_Init()
00038 {
00039   MagparFunctionLogBegin;
00040 
00041   PetscTruth flg;
00042   ierr = PetscOptionsGetInt(PETSC_NULL,"-condinp_equil",(PetscInt*)&condinp_equil,&flg);CHKERRQ(ierr);
00043   if (flg!=PETSC_TRUE) {
00044     condinp_equil=1;
00045     PetscPrintf(PETSC_COMM_WORLD,
00046       "Option -condinp_equil not found, using default value: %i\n",
00047       condinp_equil
00048     );
00049   }
00050   ierr = PetscOptionsGetReal(PETSC_NULL,"-condinp_j",&condinp_j,&flg);CHKERRQ(ierr);
00051   if (flg!=PETSC_TRUE) {
00052     condinp_j=0.1;
00053     PetscPrintf(PETSC_COMM_WORLD,
00054       "Option -condinp_j not found, using default value: %g\n",
00055       condinp_j
00056     );
00057   }
00058   ierr = PetscOptionsGetReal(PETSC_NULL,"-condinp_equil_j",&condinp_equil_j,&flg);CHKERRQ(ierr);
00059   if (flg!=PETSC_TRUE) {
00060     condinp_equil_j=0.0;
00061     PetscPrintf(PETSC_COMM_WORLD,
00062       "Option -condinp_equil_j not found, using default value: %g\n",
00063       condinp_equil_j
00064     );
00065   }
00066 
00067   MagparFunctionLogReturn(0);
00068 }
00069 
00070 
00071 int CheckIterationEmini(GridData *gdata)
00072 {
00073   static PetscReal condinp_last_j=PETSC_MIN;
00074   static PetscReal condinp_last_equil_j=PETSC_MIN;
00075 
00076   MagparFunctionInfoBegin;
00077 
00078   /* initialize if necessary */
00079   if (doinit) {
00080     ierr = CheckIterationEmini_Init();CHKERRQ(ierr);
00081     doinit=0;
00082   }
00083 
00084   /* check if we should save complete set of output data */
00085   PetscReal valMpHext;
00086   ierr = MpHext(gdata->M,&valMpHext);CHKERRQ(ierr);
00087 
00088   /* check if a set of output data should be written */
00089   if (PetscAbsReal(valMpHext-condinp_last_j) > condinp_j) {
00090     gdata->inp=PetscAbsInt(gdata->inp);
00091     condinp_last_j=valMpHext;
00092   }
00093   else if (condinp_equil==1 && gdata->equil>0) {
00094     /* check for condinp_equil_j (defaults to 0.0) */
00095     if (PetscAbsReal(valMpHext-condinp_last_equil_j) > condinp_equil_j) {
00096       gdata->inp=PetscAbsInt(gdata->inp);
00097       condinp_last_j=valMpHext;
00098       condinp_last_equil_j=valMpHext;
00099     }
00100   }
00101   else {
00102     /* write checkpoint file even if we are not in equilibrium */
00103     int  oldinp;
00104     oldinp=gdata->inp;
00105     gdata->inp=9999;
00106 
00107     PetscPrintf(PETSC_COMM_WORLD,
00108       "Writing checkpoint file (9999) at: %g ns\n",
00109       gdata->time*gdata->tscale*1e9
00110     );
00111     ierr = WriteSet(gdata);CHKERRQ(ierr);
00112 
00113     gdata->inp=oldinp;
00114   }
00115 
00116   /* write output data */
00117   ierr = WriteLog(gdata);CHKERRQ(ierr);
00118   ierr = WriteSet(gdata);CHKERRQ(ierr);
00119 
00120   /* if system is in equilibrium */
00121   if (gdata->equil>0) {
00122 
00123     /* update external field */
00124     ierr = Hext_ho_hstep(gdata);CHKERRQ(ierr);
00125 
00126     /* increase (pseudo-)time by 1 ns */
00127     gdata->time += 1e-9/gdata->tscale;
00128   }
00129 
00130   /* exit if field did not get updated and we are
00131      therefore still in equilibrium
00132   */
00133   if (gdata->equil>0) {
00134     gdata->mode=99;
00135   }
00136 
00137   MagparFunctionProfReturn(0);
00138 }
00139 

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