rhsfunction.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: rhsfunction.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 static Vec dMdt=PETSC_NULL;
00030 
00031 int RHSfunction(realtype t,N_Vector u,N_Vector udot,void *f_data)
00032 {
00033   GridData     *gdata = (GridData*)f_data;
00034 
00035   MagparFunctionInfoBegin;
00036   t_t2=0; /* just to avoid warning about unused variable */
00037 
00038   /* SUNDIALS<230: must not use CHKERRQ here because we have to return void */
00039   if (dMdt==PETSC_NULL) {
00040     /* FIXME: use VecCreateMPIWithArray instead!? */
00041     ierr = VecDuplicate(gdata->M,&dMdt);
00042   }
00043 
00044 #ifdef UNIPROC
00045   ierr = VecPlaceArray(gdata->M,NV_DATA_S(u));
00046   ierr = VecPlaceArray(dMdt,NV_DATA_S(udot));
00047 #else
00048   ierr = VecPlaceArray(gdata->M,NV_DATA_P(u));
00049   ierr = VecPlaceArray(dMdt,NV_DATA_P(udot));
00050 #endif
00051 
00052   /* set time to get time dependent parts (e.g. Hext) right */
00053   gdata->time=t;
00054 
00055   calc_dMdt(PETSC_NULL,0.0,gdata->M,dMdt,gdata);
00056 
00057   /* We could use this differential dMdt to set vequil.
00058      However, there is more noise in dMdt than if we take the finite difference over one full time step
00059      using the EquilCheck functions.
00060   #include "util/util.h"
00061   gdata->vequil=RenormVec(dMdt,0.0,PETSC_MAX,ND);
00062   */
00063 
00064   ierr = VecResetArray(gdata->M);
00065   ierr = VecResetArray(dMdt);
00066 
00067 #if SUNDIALS_VERSION >= 230
00068   MagparFunctionProfReturn(0);
00069 #else
00070   PetscFunctionReturnVoid();
00071 #endif
00072 }
00073 

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