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.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 "magpario.h"
00028 #include "util/util.h"
00029 #include "field/field.h"
00030
00031 #ifdef ADDONS
00032 #include "addons/addons.h"
00033 #endif
00034
00035 #ifdef SPINTORQ
00036 #include "spintorq/spintorq.h"
00037 #endif
00038
00039 #ifdef SUNDIALS_VERSION
00040 #include "llg/llg.h"
00041 #endif
00042
00043 static int doinit=1;
00044 static FILE *logfile;
00046 static Vec V1Mtot[ND];
00048 int Vec3VolAvg(Vec v,PetscReal* res)
00049 {
00050 MagparFunctionInfoBegin;
00051
00052
00053 for (int i=0;i<ND;i++) {
00054 ierr = VecDot(v,V1Mtot[i],&res[i]);CHKERRQ(ierr);
00055 }
00056
00057 MagparFunctionInfoReturn(0);
00058 }
00059
00060
00061 int WriteLogInit(GridData *gdata)
00062 {
00063 MagparFunctionLogBegin;
00064
00065 int rank,size;
00066 ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr);
00067 ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr);
00068
00069 PetscReal *vvol;
00070 ierr = VecGetArray(gdata->vertvol,&vvol);CHKERRQ(ierr);
00071
00072
00073 PetscReal Vtot;
00074 Vtot=0.0;
00075 for (int j=0;j<gdata->ln_vert;j++) {
00076 if (gdata->propdat[NP*gdata->vertprop[j]+4]>0.0) {
00077 Vtot += vvol[j];
00078 }
00079 }
00080 PetscReal temp;
00081 ierr = PetscGlobalSum(&Vtot,&temp,PETSC_COMM_WORLD);CHKERRQ(ierr);
00082 Vtot=temp;
00083
00084 PetscInfo2(0,"Using total volume %g (%g)\n",Vtot,gdata->totvol);
00085
00086
00087
00088 for (int i=0;i<ND;i++) {
00089 ierr = VecDuplicate(gdata->M,&V1Mtot[i]);CHKERRQ(ierr);
00090
00091 PetscReal *v1m;
00092 ierr = VecGetArray(V1Mtot[i],&v1m);CHKERRQ(ierr);
00093 for (int j=0;j<gdata->ln_vert;j++) {
00094 if (gdata->propdat[NP*gdata->vertprop[j]+4]>0.0) {
00095 v1m[ND*j+i]=vvol[j];
00096 }
00097 }
00098 ierr = VecRestoreArray(V1Mtot[i],&v1m);CHKERRQ(ierr);
00099
00100 ierr = VecScale(V1Mtot[i],1.0/Vtot);CHKERRQ(ierr);
00101 }
00102
00103 ierr = VecRestoreArray(gdata->vertvol,&vvol);CHKERRQ(ierr);
00104
00105 if (rank) {
00106 MagparFunctionLogReturn(0);
00107 }
00108
00109 char fmesh[256];
00110 ierr = PetscSNPrintf(fmesh,255,"%s%s",gdata->simname,".log");CHKERRQ(ierr);
00111 ierr = PetscFOpen(PETSC_COMM_WORLD,fmesh,"a",&logfile);CHKERRQ(ierr);
00112 if (!logfile) {
00113 SETERRQ1(PETSC_ERR_FILE_OPEN,"Cannot open %s\n",fmesh);
00114 }
00115 PetscPrintf(PETSC_COMM_WORLD,"Opening file %s\n",fmesh);
00116
00117 PetscGetDate(fmesh,255);
00118 ierr = PetscFPrintf(PETSC_COMM_WORLD,logfile,"#.date: %s\n",fmesh);
00119
00120
00121 ierr = PetscFPrintf(PETSC_COMM_WORLD,logfile,
00122 "#.%3s %4s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s\n",
00123 ".1:",
00124 " 2:",
00125 " 3:",
00126 " 4:",
00127 " 5:",
00128 " 6:",
00129 " 7:",
00130 " 8:",
00131 " 9:",
00132 "10:",
00133 "11:",
00134 "12:",
00135 "13:",
00136 "14:",
00137 "15:",
00138 "16:",
00139 "17:",
00140 "18:",
00141 "20:"
00142 );CHKERRQ(ierr);
00143
00144 ierr = PetscFPrintf(PETSC_COMM_WORLD,logfile,
00145 "#.%3s %4s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s\n",
00146 ".eq",
00147 "inp",
00148 "time",
00149 "Hext",
00150 "Etot",
00151 "J//Hext",
00152 "Mx",
00153 "My",
00154 "Mz",
00155 "|M|",
00156 "Edem",
00157 #ifdef EXCH
00158 "Eanionly",
00159 #else
00160 "Eexchani",
00161 #endif
00162 "Eext",
00163 #ifdef EXCH
00164 "Eexchonly",
00165 #else
00166 "-",
00167 #endif
00168 "devNorm",
00169 "mx|dM/dt|",
00170 "timestep",
00171 "tCPU",
00172 "CPUtstep"
00173 );CHKERRQ(ierr);
00174
00175 ierr = PetscFPrintf(PETSC_COMM_WORLD,logfile,
00176 "#.%3s %4s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s\n",
00177 "..-",
00178 "-",
00179 "(ns)",
00180 "(kA/m)",
00181 "(J/m^3)",
00182 "[J/Javg]",
00183 "(1)",
00184 "(1)",
00185 "(1)",
00186 "(1)",
00187 "(J/m^3)",
00188 "(J/m^3)",
00189 "(J/m^3)",
00190 #ifdef EXCH
00191 "(J/m^3)",
00192 #else
00193 "-",
00194 #endif
00195 "(1)",
00196 "(1)",
00197 "(ns)",
00198 "(s)",
00199 "(s)"
00200 );CHKERRQ(ierr);
00201
00202 MagparFunctionLogReturn(0);
00203 }
00204
00205
00206 int WriteLogData(GridData *gdata)
00207 {
00208 static PetscLogDouble tCPUstart=-1;
00209 static PetscLogDouble tCPUlast;
00210 static PetscReal timelast;
00211
00212 MagparFunctionInfoBegin;
00213
00214 int rank,size;
00215 ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr);
00216 ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr);
00217
00218 if (doinit) {
00219 tCPUstart=t_t1;
00220 tCPUlast=t_t1;
00221 timelast=gdata->time;
00222 ierr = WriteLogInit(gdata);CHKERRQ(ierr);
00223 doinit=0;
00224 }
00225
00226 PetscReal devNorm;
00227 devNorm=RenormVec(gdata->M,1.0,PETSC_MAX,ND);
00228
00229
00230 PetscReal Mtot[ND];
00231 ierr = Vec3VolAvg(gdata->M,Mtot);CHKERRQ(ierr);
00232
00233
00234 PetscReal valMpHext;
00235 ierr = MpHext(gdata->M,&valMpHext);CHKERRQ(ierr);
00236
00237 PetscReal hext;
00238 hext = Hexternal_hext();
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248 if (gdata->Edem<0) {
00249 PetscPrintf(MPI_COMM_WORLD,
00250 "Warning: Edem<0 at t=%g ns: Edem=%g J/m^3\n",
00251 gdata->time*gdata->tscale*1e9,
00252 gdata->Edem*gdata->escale
00253 );
00254 }
00255
00256
00257 ierr = PetscFPrintf(PETSC_COMM_WORLD,logfile,
00258 " %3d %4d %14e %14e %14e %14e %14e %14e %14e %14e %14e %14e %14e %14e %14e %14e %14e %14e %14e\n",
00259 gdata->equil,
00260 gdata->inp >= 0 ? gdata->inp : 0,
00261 gdata->time*gdata->tscale*1e9,
00262 hext*gdata->hscale/(MU0*1000.0),
00263 gdata->Etot*gdata->escale,
00264 valMpHext,
00265 Mtot[0],
00266 Mtot[1],
00267 Mtot[2],
00268 sqrt(Mtot[0]*Mtot[0]+Mtot[1]*Mtot[1]+Mtot[2]*Mtot[2]),
00269 gdata->Edem*gdata->escale,
00270 #ifdef EXCH
00271 (gdata->Eexchani-gdata->Eexchonly)*gdata->escale,
00272 #else
00273 gdata->Eexchani*gdata->escale,
00274 #endif
00275 gdata->Eext*gdata->escale,
00276 #ifdef EXCH
00277 gdata->Eexchonly*gdata->escale,
00278 #else
00279 -1.0,
00280 #endif
00281 devNorm,
00282 gdata->vequil,
00283 (gdata->time-timelast)*gdata->tscale*1e9,
00284 t_t1-tCPUstart,
00285 t_t1-tCPUlast
00286 );
00287
00288 tCPUlast=t_t1;
00289 timelast=gdata->time;
00290
00291 MagparFunctionInfoReturn(0);
00292 }
00293
00294
00295 int WriteLog(GridData *gdata)
00296 {
00297 MagparFunctionInfoBegin;
00298
00299 ierr = WriteLogData(gdata);CHKERRQ(ierr);
00300 ierr = WriteLogPid(gdata);CHKERRQ(ierr);
00301
00302 #ifdef SUNDIALS_VERSION
00303
00304 ierr = WriteLogPVode(gdata);CHKERRQ(ierr);
00305 #endif
00306
00307 #ifdef ADDONS
00308
00309 ierr = WriteLogExt(gdata);CHKERRQ(ierr);
00310 #endif
00311
00312 #ifdef SPINTORQ
00313
00314 ierr = WriteLogGMR(gdata);CHKERRQ(ierr);
00315 #endif
00316
00317 MagparFunctionInfoReturn(0);
00318 }
00319