[petsc-dev] Which approach to modifying vectors from DMComplex is better?
Chris Eldred
chris.eldred at gmail.com
Wed Sep 26 09:18:42 CDT 2012
I have a vector (created from a PetscSection) that holds a set of
values distributed over various points in my mesh. It represents
multiple fields with different dofs. I was wondering which approach
for modifying (or just getting) the values for a given field from the
vector was preferred? The vector is created using
DMCreateLocal/GlobalVector.
Approach 1 (get the underlying array, find the points using
PetscSection, do whatever, restore the array)
call VecGetArrayF90( varvector , varptr , ierr)
CHKERRQ(ierr)
call DMComplexGetDepthStratum(model_mesh, vardepth , pStart, pEnd, ierr)
CHKERRQ(ierr)
do p=pStart,pEnd-1
call PetscSectionGetFieldOffset( varsection, p, varnum , poffset, ierr)
CHKERRQ(ierr)
call PetscSectionGetFieldDof( varsection, p, varnum , ndof, ierr)
CHKERRQ(ierr)
do something with the values (modify them, read them, etc.)
enddo
call VecRestoreArrayF90( varvector , varptr , ierr)
CHKERRQ(ierr)
Approach 2 (find the points using PetscSection, get the values using
VecGetValues, do whatever, set the values using VecSetValues (if
needed), call VecAssemblyBegin/End )
call DMComplexGetDepthStratum(model_mesh, vardepth , pStart, pEnd, ierr)
CHKERRQ(ierr)
do p=pStart,pEnd-1
call PetscSectionGetFieldOffset( varsection, p, varnum , poffset, ierr)
CHKERRQ(ierr)
call PetscSectionGetFieldDof( varsection, p, varnum , ndof, ierr)
CHKERRQ(ierr)
add points to a list (points are a contiguos list so its easy)- ie for
each dof add poffset+dof to the list
enddo
call VecGetValues( varvector, npts, ptslist, vals, ierr)
CHKERRQ(ierr)
do something with the values (modify them, read them, etc.)
call VecSetValues( varvector, npts, ptslist, vals, INSERT_MODE, ierr)
!if need to
CHKERRQ(ierr)
call VecAssemblyBegin/End (if i set values)
CHKERRQ(ierr)
Instead of VecAssemblyBegin/End, should I be using the DMGlobaltoLocal
/ DMLocaltoGlobal routines?
On a related note, should I be calling VecAssemblyBegin/End (or
DMGlobaltoLocal, etc.) when I modify the values in the array using
Approach 1?
Is there another, third approach I should be using?
-Chris
--
Chris Eldred
DOE Computational Science Graduate Fellow
Graduate Student, Atmospheric Science, Colorado State University
B.S. Applied Computational Physics, Carnegie Mellon University, 2009
chris.eldred at gmail.com
More information about the petsc-dev
mailing list