00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
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
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
00102 ierr = PetscFPrintf(PETSC_COMM_WORLD,logfile,
00103 "#.%14s %7s %4s %4s %4s %4s %4s %4s %4s %4s\n",
00104 "..........(ns)",
00105 "-",
00106 "-",
00107 "-",
00108 "-",
00109 "-",
00110 "-",
00111 "-",
00112 "-",
00113 "-"
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
00142 if (nstep==0 || nstep<last_nstep) {
00143
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
00166 ierr = PetscFPrintf(PETSC_COMM_WORLD,logfile,
00167 " %14e %7d %4d %4ld %4ld %4ld %4ld %4ld %4ld %4ld\n",
00168 gdata->time*gdata->tscale*1e9,
00169 nstep,
00170 qu,
00171 nfe- last_nfe,
00172 nni- last_nni,
00173 ncfn-last_ncfn,
00174 nli- last_nli,
00175 npe- last_npe,
00176 nps- last_nps,
00177 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