vecsetvec.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: vecsetvec.c 2681 2009-07-31 04:30:53Z scholz $\n\n";
00025 static char const Td[] = "$Today$\n\n";
00026 
00027 #include "util.h"
00028 
00029 int VecSetVec(Vec vec, PetscReal *vec3, int dim)
00030 {
00031   MagparFunctionInfoBegin;
00032 
00033   int vsize;
00034   ierr = VecGetLocalSize(vec,&vsize);CHKERRQ(ierr);
00035   if (vsize%dim!=0) {
00036     SETERRQ3(PETSC_ERR_ARG_CORRUPT,
00037       "vsize=%i, dim=%i, %i!=0!\n",
00038       vsize,dim,vsize%dim
00039     );
00040   }
00041 
00042   PetscReal *ta_vec;
00043   ierr = VecGetArray(vec,&ta_vec);CHKERRQ(ierr);
00044   for (int j=0; j<vsize/dim; j++) {
00045     for (int i=0; i<dim; i++) {
00046       ta_vec[dim*j+i]=vec3[i];
00047     }
00048   }
00049   ierr = VecRestoreArray(vec,&ta_vec);CHKERRQ(ierr);
00050 
00051   MagparFunctionInfoReturn(0);
00052 }
00053 

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