writelog_pvode.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: writelog_pvode.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 "llg.h"
00028 
00029 #include "cvode/cvode.h"
00030 
00031 #if SUNDIALS_VERSION >= 230
00032 #include "cvode/cvode_spgmr.h"
00033 #else
00034 #error "SUNDIALS versions lower/older than 2.3.0 are not supported"
00035 #endif
00036 
00037 static int  doinit=1;
00038 static int  fieldon=0;
00039 static FILE *logfile=NULL; 
00041 int WriteLogPVodeInit(GridData *gdata)
00042 {
00043   MagparFunctionLogBegin;
00044 
00045   int rank,size;
00046   ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr);
00047   ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr);
00048 
00049   if (rank) {
00050     MagparFunctionLogReturn(0);
00051   }
00052 
00053   if (gdata->mode!=0 && gdata->mode!=2 && gdata->mode!=3) {
00054     MagparFunctionLogReturn(0);
00055   }
00056   fieldon=1;
00057 
00058   char fmesh[256];
00059   ierr = PetscSNPrintf(fmesh,255,"%s%s",gdata->simname,".log_pvode");CHKERRQ(ierr);
00060   ierr = PetscFOpen(PETSC_COMM_WORLD,fmesh,"a",&logfile);CHKERRQ(ierr);
00061   if (!logfile) {
00062     SETERRQ1(PETSC_ERR_FILE_OPEN,"Cannot open %s\n",fmesh);
00063   }
00064   PetscPrintf(PETSC_COMM_WORLD,"Opening file %s\n",fmesh);
00065 
00066   PetscGetDate(fmesh,255);
00067   ierr = PetscFPrintf(PETSC_COMM_WORLD,
00068     logfile,
00069     "#.date: %s\n",
00070     fmesh
00071   );
00072 
00073   /*      1   2   3   4   5   6   7   8   9  10 */
00074   ierr = PetscFPrintf(PETSC_COMM_WORLD,logfile,
00075     "#.%14s %7s %4s %4s %4s %4s %4s %4s %4s %4s\n",
00076     "............1:",
00077     " 2:",
00078     " 3:",
00079     " 4:",
00080     " 5:",
00081     " 6:",
00082     " 7:",
00083     " 8:",
00084     " 9:",
00085     "10:"
00086   );CHKERRQ(ierr);
00087   /*      1   2   3   4   5   6   7   8   9  10 */
00088   ierr = PetscFPrintf(PETSC_COMM_WORLD,logfile,
00089     "#.%14s %7s %4s %4s %4s %4s %4s %4s %4s %4s\n",
00090     "..........time",
00091     "nstep",
00092     "qu",
00093     "nfe",
00094     "nni",
00095     "ncfn",
00096     "nli",
00097     "npe",
00098     "nps",
00099     "ncfl"
00100   );CHKERRQ(ierr);
00101   /*      1   2   3   4   5   6   7   8   9  10 */
00102   ierr = PetscFPrintf(PETSC_COMM_WORLD,logfile,
00103     "#.%14s %7s %4s %4s %4s %4s %4s %4s %4s %4s\n",
00104     /* "time",      */ "..........(ns)",
00105     /* "nstep",     */ "-",
00106     /* "qu",        */ "-",
00107     /* "nfe",       */ "-",
00108     /* "nni",       */ "-",
00109     /* "ncfn",      */ "-",
00110     /* "nli",       */ "-",
00111     /* "npe",       */ "-",
00112     /* "nps",       */ "-",
00113     /* "ncfl",      */ "-"
00114   );CHKERRQ(ierr);
00115 
00116   MagparFunctionLogReturn(0);
00117 }
00118 
00119 
00120 int WriteLogPVode(GridData *gdata)
00121 {
00122   extern void *cvode_mem;
00123 
00124   MagparFunctionInfoBegin;
00125 
00126   if (doinit) {
00127     ierr = WriteLogPVodeInit(gdata);CHKERRQ(ierr);
00128     doinit=0;
00129   }
00130   if (!fieldon || cvode_mem==PETSC_NULL) {
00131     MagparFunctionInfoReturn(0);
00132   }
00133 
00134   int flag;
00135   static long int last_nfe,last_nni,last_ncfn,last_nli,last_npe,last_nps,last_ncfl,last_nstep;
00136   long int nstep,nfe,nni,ncfn,nli,npe,nps,ncfl;
00137   int qu;
00138 
00139   flag=CVodeGetNumSteps(cvode_mem,&nstep);
00140 
00141   /* if PVODE hase been (re)started */
00142   if (nstep==0 || nstep<last_nstep) {
00143     /* reset counters */
00144     last_nfe=last_nni=last_ncfn=last_nli=last_npe=last_nps=last_ncfl=0;
00145   }
00146   if (nstep==0) {
00147     nfe=nni=ncfn=nli=npe=nps=ncfl=0;
00148     qu=0;
00149   }
00150   else {
00151     flag=CVodeGetLastOrder(cvode_mem,&qu);
00152     flag=CVodeGetNumRhsEvals(cvode_mem,&nfe);
00153     flag=CVodeGetNumNonlinSolvIters(cvode_mem,&nni);
00154     flag=CVodeGetNumNonlinSolvConvFails(cvode_mem,&ncfn);
00155 #if SUNDIALS_VERSION >= 230
00156     flag=CVSpilsGetNumLinIters(  cvode_mem,&nli);
00157     flag=CVSpilsGetNumPrecEvals( cvode_mem,&npe);
00158     flag=CVSpilsGetNumPrecSolves(cvode_mem,&nps);
00159     flag=CVSpilsGetNumConvFails( cvode_mem,&ncfl);
00160 #else
00161 #error "SUNDIALS versions lower/older than 2.3.0 are not supported"
00162 #endif
00163   }
00164 
00165   /*     1   2    3    4    5    6    7    8    9   10 */
00166   ierr = PetscFPrintf(PETSC_COMM_WORLD,logfile,
00167     "  %14e %7d %4d %4ld %4ld %4ld %4ld %4ld %4ld %4ld\n",
00168     /* " 1:time",      */ gdata->time*gdata->tscale*1e9,
00169     /* " 2:nstep",     */ nstep,
00170     /* " 3:qu",        */ qu,
00171     /* " 4:nfe",       */ nfe- last_nfe,
00172     /* " 5:nni",       */ nni- last_nni,
00173     /* " 6:ncfn",      */ ncfn-last_ncfn,
00174     /* " 7:nli",       */ nli- last_nli,
00175     /* " 8:npe",       */ npe- last_npe,
00176     /* " 9:nps",       */ nps- last_nps,
00177     /* "10:ncfl",      */ ncfl-last_ncfl
00178   );
00179 
00180   last_nfe=  nfe;
00181   last_nni=  nni;
00182   last_ncfn= ncfn;
00183   last_nli=  nli;
00184   last_npe=  npe;
00185   last_nps=  nps;
00186   last_ncfl= ncfl;
00187   last_nstep= nstep;
00188 
00189   MagparFunctionInfoReturn(0);
00190 }
00191 

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