mytssteppvode.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: mytssteppvode.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 "llg.h"
00028 
00029 int myTSStepPVode(GridData *gdata)
00030 {
00031   extern void *cvode_mem;
00032   extern      N_Vector nvu;
00033 
00034   static int  nsteps=-1;
00035 
00036   MagparFunctionInfoBegin;
00037 
00038   /* take 20 time steps at once
00039      problem: tols not increased, because devNorm gets too large
00040      TODO: check again if it buys any speedup
00041   */
00042   if (nsteps<0) {
00043     PetscTruth flg;
00044     ierr = PetscOptionsGetInt(PETSC_NULL,"-ts_nsteps",(PetscInt*)&nsteps,&flg);CHKERRQ(ierr);
00045     if (flg!=PETSC_TRUE) {
00046       nsteps=1;
00047       PetscPrintf(PETSC_COMM_WORLD,
00048         "Option -ts_nsteps not found, using default value: %i\n",
00049         nsteps
00050       );
00051     }
00052     if (nsteps<1) {
00053       SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Option set: -ts_nsteps %i, but has to be >0\n",nsteps);
00054     }
00055   }
00056 
00057   ierr = CV_SUCCESS; /* just to avoid compiler warning about uninitialized var */
00058   for (int i=0;i<nsteps;i++) {
00059     ierr = CVode(cvode_mem,PETSC_MAX,nvu,&gdata->time,CV_ONE_STEP);
00060 
00061     if (ierr != CV_SUCCESS) {
00062       SETERRQ1(PETSC_ERR_LIB,"CVode failed, ierr=%i.\n",ierr);
00063     }
00064   }
00065 
00066   /* integrate for 5 ps
00067      same problem as above
00068   ierr = CVode(
00069     cvode_mem,
00070     gdata->time+5.0e-12/gdata->tscale,
00071     nvu,
00072     &gdata->time,
00073     NORMAL
00074   );
00075   */
00076 
00077 #define DEBUG
00078 
00079 #ifdef DEBUG
00080 
00081   /* FIXME: why is VecPlaceArray not necessary with PETSc version 2.3.0? */
00082   /* check that gdata->M points to the result */
00083   PetscReal *tmp;
00084   ierr = VecGetArray(gdata->M,&tmp);CHKERRQ(ierr);
00085 
00086 #ifdef UNIPROC
00087   assert(tmp==NV_DATA_S(nvu));
00088 #else
00089   assert(tmp==NV_DATA_P(nvu));
00090 #endif
00091 
00092   ierr = VecRestoreArray(gdata->M,&tmp);CHKERRQ(ierr);
00093 
00094 #endif /* DEBUG */
00095 
00096   MagparFunctionProfReturn(0);
00097 }

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