-----Original Message-----
From: Daniel Mckinnell <[email protected]>
To: knepley <[email protected]>
Sent: Thu, 15 Aug 2019 17:05
Subject: Re: [petsc-users] Accessing Global Vector Data with
Thank you, it seemed to work nicely for the fields associated with cells but
I'm having problems with the field on vertices. The code for altering the field
is as follows:
for (int i = vStart; i < vEnd; i++)
{
PetscScalar *values;
PetscInt vsize, voff;
PetscSectionGetDof(globalsection, i, &vsize);
PetscSectionGetOffset(globalsection, i, &voff);
VecGetArray(u, &values);
if (voff >= 0)
{
PetscScalar *p;
DMPlexPointLocalRef(*dm, i, values, &p);
p[0] = i + 1;
}
VecRestoreArray(u, &values);
The Global PetscSection is:
PetscSection Object: 2 MPI processes
type not yet set
Process 0:
( 0) dim 2 offset 0
( 1) dim 2 offset 2
( 2) dim -3 offset -13
( 3) dim -3 offset -15
( 4) dim 1 offset 4
( 5) dim 1 offset 5
( 6) dim 1 offset 6
( 7) dim -2 offset -17
( 8) dim -2 offset -18
( 9) dim -2 offset -19
( 10) dim -2 offset -20
( 11) dim -2 offset -21
( 12) dim -2 offset -22
( 13) dim 1 offset 7
( 14) dim 1 offset 8
( 15) dim 1 offset 9
( 16) dim 1 offset 10
( 17) dim 1 offset 11
( 18) dim -2 offset -23
( 19) dim -2 offset -24
( 20) dim -2 offset -25
( 21) dim -2 offset -26
( 22) dim -2 offset -27
( 23) dim -2 offset -28
( 24) dim -2 offset -29
Process 1:
( 0) dim 2 offset 12
( 1) dim 2 offset 14
( 2) dim -3 offset -1
( 3) dim -3 offset -3
( 4) dim 1 offset 16
( 5) dim 1 offset 17
( 6) dim 1 offset 18
( 7) dim 1 offset 19
( 8) dim 1 offset 20
( 9) dim 1 offset 21
( 10) dim -2 offset -5
( 11) dim -2 offset -6
( 12) dim -2 offset -7
( 13) dim 1 offset 22
( 14) dim 1 offset 23
( 15) dim 1 offset 24
( 16) dim 1 offset 25
( 17) dim 1 offset 26
( 18) dim 1 offset 27
( 19) dim 1 offset 28
( 20) dim -2 offset -8
( 21) dim -2 offset -9
( 22) dim -2 offset -10
( 23) dim -2 offset -11
( 24) dim -2 offset -12
where points 4-6 on proc 0 and points 4-9 on proc 1 are vertices.
The altered vec is:
Vec Object: 2 MPI processes
type: mpi
Process [0]
0.
0.
0.
0.
0.
0.
0.
0.
5.
6.
7.
0.
Process [1]
0.
0.
0.
0.
0.
0.
0.
0.
5.
6.
7.
8.
9.
10.
0.
0.
0.
However the altered values do not correspond with the offsets in the
PetscSection and I'm not sure what is going wrong.Thanks for all of the
help.Daniel
-----Original Message-----
From: Matthew Knepley via petsc-users <[email protected]>
To: Daniel Mckinnell <[email protected]>
CC: PETSc <[email protected]>
Sent: Thu, 15 Aug 2019 16:11
Subject: Re: [petsc-users] Accessing Global Vector Data with
On Thu, Aug 15, 2019 at 10:59 AM Daniel Mckinnell via petsc-users
<[email protected]> wrote:
Hi,Attached is a way I came up with to access data in a global vector, is this
the best way to do this or are there other ways? It would seem intuitive to use
the global PetscSection and VecGetValuesSection but this doesn't seem to work
on global vectors.
Instead I have used VecGetValues and VecSetValues, however I also have a
problem with these when extracting more than one value, I initialise the output
of VecGetValues as PetscScalar *values; and then call VecGetValues(Other
stuff... , values). This seems to work some times and not others and I can't
find any rhyme or reason to it?
I guess I should write something about this. I like to think of it as a sort of
decision tree.
1) Get just local values, meaning those owned by this process
These can be obtained from either a local or global vector.
2) Get ghosted values, meaning those values lying on unowned points that exist
in the default PetscSF
These can only get obtained from a local vector
3) Get arbitrary values
You must use a VecScatter or custom PetscSF to get these
For 1) and 2), I think the best way to get values normally is to use
https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/DMPLEX/DMPlexPointLocalRef.html
https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/DMPLEX/DMPlexPointGlobalRef.html
These also have Read versions, and Field version to split off a particular
field in the Section.
Does this help?
Thanks,
Matt
Finally I was wondering if there is a good reference code base on Github
including DMPlex that would be helpful in viewing applications of the DMPlex
functions?Thanks,Daniel Mckinnell
--
What most experimenters take for granted before they begin their experiments is
infinitely more interesting than any results to which their experiments lead.
-- Norbert Wiener
https://www.cse.buffalo.edu/~knepley/