xref: /petsc/src/dm/impls/plex/plexpoint.c (revision dadcf80911fb48939c55327431ae8d7e47dbe367)
1af0996ceSBarry Smith #include <petsc/private/dmpleximpl.h>   /*I      "petscdmplex.h"   I*/
233879625SMatthew G. Knepley 
3552f7358SJed Brown /*@
4552f7358SJed Brown    DMPlexGetPointLocal - get location of point data in local Vec
5552f7358SJed Brown 
6552f7358SJed Brown    Not Collective
7552f7358SJed Brown 
84165533cSJose E. Roman    Input Parameters:
9552f7358SJed Brown +  dm - DM defining the topological space
10552f7358SJed Brown -  point - topological point
11552f7358SJed Brown 
124165533cSJose E. Roman    Output Parameters:
13552f7358SJed Brown +  start - start of point data
14552f7358SJed Brown -  end - end of point data
15552f7358SJed Brown 
16a89cf0ddSMatthew G. Knepley    Note: This is a half open interval [start, end)
17a89cf0ddSMatthew G. Knepley 
18552f7358SJed Brown    Level: intermediate
19552f7358SJed Brown 
2092fd8e1eSJed Brown .seealso: DMPlexGetPointLocalField(), DMGetLocalSection(), PetscSectionGetOffset(), PetscSectionGetDof(), DMPlexPointLocalRead(), DMPlexPointLocalRead(), DMPlexPointLocalRef()
21552f7358SJed Brown @*/
22552f7358SJed Brown PetscErrorCode DMPlexGetPointLocal(DM dm, PetscInt point, PetscInt *start, PetscInt *end)
23552f7358SJed Brown {
24a89cf0ddSMatthew G. Knepley   PetscInt       s, e;
25552f7358SJed Brown 
26552f7358SJed Brown   PetscFunctionBegin;
27552f7358SJed Brown   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
28*dadcf809SJacob Faibussowitsch   if (start) PetscValidIntPointer(start, 3);
29*dadcf809SJacob Faibussowitsch   if (end)   PetscValidIntPointer(end,   4);
305f80ce2aSJacob Faibussowitsch   CHKERRQ(DMGetLocalOffset_Private(dm, point, &s, &e));
31a89cf0ddSMatthew G. Knepley   if (start) *start = s;
32a89cf0ddSMatthew G. Knepley   if (end)   *end   = e;
33552f7358SJed Brown   PetscFunctionReturn(0);
34552f7358SJed Brown }
35552f7358SJed Brown 
36552f7358SJed Brown /*@
37552f7358SJed Brown    DMPlexPointLocalRead - return read access to a point in local array
38552f7358SJed Brown 
39552f7358SJed Brown    Not Collective
40552f7358SJed Brown 
414165533cSJose E. Roman    Input Parameters:
42552f7358SJed Brown +  dm - DM defining topological space
43552f7358SJed Brown .  point - topological point
44552f7358SJed Brown -  array - array to index into
45552f7358SJed Brown 
464165533cSJose E. Roman    Output Parameter:
47552f7358SJed Brown .  ptr - address of read reference to point data, type generic so user can place in structure
48552f7358SJed Brown 
49552f7358SJed Brown    Level: intermediate
50552f7358SJed Brown 
51552f7358SJed Brown    Note:
52552f7358SJed Brown    A common usage when data sizes are known statically:
53552f7358SJed Brown 
54552f7358SJed Brown $  const struct { PetscScalar foo,bar,baz; } *ptr;
55552f7358SJed Brown $  DMPlexPointLocalRead(dm,point,array,&ptr);
56552f7358SJed Brown $  x = 2*ptr->foo + 3*ptr->bar + 5*ptr->baz;
57552f7358SJed Brown 
5892fd8e1eSJed Brown .seealso: DMGetLocalSection(), PetscSectionGetOffset(), PetscSectionGetDof(), DMPlexGetPointLocal(), DMPlexPointGlobalRead()
59552f7358SJed Brown @*/
60081a2d76SSatish Balay PetscErrorCode DMPlexPointLocalRead(DM dm,PetscInt point,const PetscScalar *array,void *ptr)
61552f7358SJed Brown {
62a89cf0ddSMatthew G. Knepley   PetscInt       start, end;
63552f7358SJed Brown 
64552f7358SJed Brown   PetscFunctionBegin;
65552f7358SJed Brown   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
66552f7358SJed Brown   PetscValidScalarPointer(array,3);
67552f7358SJed Brown   PetscValidPointer(ptr,4);
685f80ce2aSJacob Faibussowitsch   CHKERRQ(DMGetLocalOffset_Private(dm,point,&start,&end));
69a89cf0ddSMatthew G. Knepley   *(const PetscScalar**)ptr = (start < end) ? array + start : NULL;
70552f7358SJed Brown   PetscFunctionReturn(0);
71552f7358SJed Brown }
72552f7358SJed Brown 
73552f7358SJed Brown /*@
74552f7358SJed Brown    DMPlexPointLocalRef - return read/write access to a point in local array
75552f7358SJed Brown 
76552f7358SJed Brown    Not Collective
77552f7358SJed Brown 
784165533cSJose E. Roman    Input Parameters:
79552f7358SJed Brown +  dm - DM defining topological space
80552f7358SJed Brown .  point - topological point
81552f7358SJed Brown -  array - array to index into
82552f7358SJed Brown 
834165533cSJose E. Roman    Output Parameter:
84552f7358SJed Brown .  ptr - address of reference to point data, type generic so user can place in structure
85552f7358SJed Brown 
86552f7358SJed Brown    Level: intermediate
87552f7358SJed Brown 
88552f7358SJed Brown    Note:
89552f7358SJed Brown    A common usage when data sizes are known statically:
90552f7358SJed Brown 
91552f7358SJed Brown $  struct { PetscScalar foo,bar,baz; } *ptr;
92552f7358SJed Brown $  DMPlexPointLocalRef(dm,point,array,&ptr);
93552f7358SJed Brown $  ptr->foo = 2; ptr->bar = 3; ptr->baz = 5;
94552f7358SJed Brown 
9592fd8e1eSJed Brown .seealso: DMGetLocalSection(), PetscSectionGetOffset(), PetscSectionGetDof(), DMPlexGetPointLocal(), DMPlexPointGlobalRef()
96552f7358SJed Brown @*/
97552f7358SJed Brown PetscErrorCode DMPlexPointLocalRef(DM dm,PetscInt point,PetscScalar *array,void *ptr)
98552f7358SJed Brown {
99a89cf0ddSMatthew G. Knepley   PetscInt       start, end;
100552f7358SJed Brown 
101552f7358SJed Brown   PetscFunctionBegin;
102552f7358SJed Brown   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
103552f7358SJed Brown   PetscValidScalarPointer(array,3);
104552f7358SJed Brown   PetscValidPointer(ptr,4);
1055f80ce2aSJacob Faibussowitsch   CHKERRQ(DMGetLocalOffset_Private(dm,point,&start,&end));
106a89cf0ddSMatthew G. Knepley   *(PetscScalar**)ptr = (start < end) ? array + start : NULL;
107a89cf0ddSMatthew G. Knepley   PetscFunctionReturn(0);
108a89cf0ddSMatthew G. Knepley }
109a89cf0ddSMatthew G. Knepley 
110a89cf0ddSMatthew G. Knepley /*@
111a89cf0ddSMatthew G. Knepley   DMPlexGetPointLocalField - get location of point field data in local Vec
112a89cf0ddSMatthew G. Knepley 
113a89cf0ddSMatthew G. Knepley   Not Collective
114a89cf0ddSMatthew G. Knepley 
1154165533cSJose E. Roman   Input Parameters:
116a89cf0ddSMatthew G. Knepley + dm - DM defining the topological space
117a89cf0ddSMatthew G. Knepley . point - topological point
118a89cf0ddSMatthew G. Knepley - field - the field number
119a89cf0ddSMatthew G. Knepley 
1204165533cSJose E. Roman   Output Parameters:
121a89cf0ddSMatthew G. Knepley + start - start of point data
122a89cf0ddSMatthew G. Knepley - end - end of point data
123a89cf0ddSMatthew G. Knepley 
124a89cf0ddSMatthew G. Knepley   Note: This is a half open interval [start, end)
125a89cf0ddSMatthew G. Knepley 
126a89cf0ddSMatthew G. Knepley   Level: intermediate
127a89cf0ddSMatthew G. Knepley 
12892fd8e1eSJed Brown .seealso: DMPlexGetPointLocal(), DMGetLocalSection(), PetscSectionGetOffset(), PetscSectionGetDof(), DMPlexPointLocalRead(), DMPlexPointLocalRead(), DMPlexPointLocalRef()
129a89cf0ddSMatthew G. Knepley @*/
130a89cf0ddSMatthew G. Knepley PetscErrorCode DMPlexGetPointLocalField(DM dm, PetscInt point, PetscInt field, PetscInt *start, PetscInt *end)
131a89cf0ddSMatthew G. Knepley {
132a89cf0ddSMatthew G. Knepley   PetscInt       s, e;
133a89cf0ddSMatthew G. Knepley 
134a89cf0ddSMatthew G. Knepley   PetscFunctionBegin;
135a89cf0ddSMatthew G. Knepley   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
136*dadcf809SJacob Faibussowitsch   if (start) PetscValidIntPointer(start, 4);
137*dadcf809SJacob Faibussowitsch   if (end)   PetscValidIntPointer(end,   5);
1385f80ce2aSJacob Faibussowitsch   CHKERRQ(DMGetLocalFieldOffset_Private(dm, point, field, &s, &e));
139a89cf0ddSMatthew G. Knepley   if (start) *start = s;
140a89cf0ddSMatthew G. Knepley   if (end)   *end   = e;
141552f7358SJed Brown   PetscFunctionReturn(0);
142552f7358SJed Brown }
143552f7358SJed Brown 
1441ce3176fSMatthew G. Knepley /*@
1451ce3176fSMatthew G. Knepley    DMPlexPointLocalFieldRead - return read access to a field on a point in local array
1461ce3176fSMatthew G. Knepley 
1471ce3176fSMatthew G. Knepley    Not Collective
1481ce3176fSMatthew G. Knepley 
1494165533cSJose E. Roman    Input Parameters:
1501ce3176fSMatthew G. Knepley +  dm - DM defining topological space
1511ce3176fSMatthew G. Knepley .  point - topological point
1521ce3176fSMatthew G. Knepley .  field - field number
1531ce3176fSMatthew G. Knepley -  array - array to index into
1541ce3176fSMatthew G. Knepley 
1554165533cSJose E. Roman    Output Parameter:
1561ce3176fSMatthew G. Knepley .  ptr - address of read reference to point data, type generic so user can place in structure
1571ce3176fSMatthew G. Knepley 
1581ce3176fSMatthew G. Knepley    Level: intermediate
1591ce3176fSMatthew G. Knepley 
16092fd8e1eSJed Brown .seealso: DMGetLocalSection(), PetscSectionGetOffset(), PetscSectionGetDof(), DMPlexGetPointLocal(), DMPlexPointGlobalRef()
1611ce3176fSMatthew G. Knepley @*/
162081a2d76SSatish Balay PetscErrorCode DMPlexPointLocalFieldRead(DM dm, PetscInt point,PetscInt field,const PetscScalar *array,void *ptr)
1631ce3176fSMatthew G. Knepley {
164a89cf0ddSMatthew G. Knepley   PetscInt       start, end;
1651ce3176fSMatthew G. Knepley 
1661ce3176fSMatthew G. Knepley   PetscFunctionBegin;
1671ce3176fSMatthew G. Knepley   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
168064a246eSJacob Faibussowitsch   PetscValidScalarPointer(array,4);
169064a246eSJacob Faibussowitsch   PetscValidPointer(ptr,5);
1705f80ce2aSJacob Faibussowitsch   CHKERRQ(DMGetLocalFieldOffset_Private(dm, point, field, &start, &end));
1711ce3176fSMatthew G. Knepley   *(const PetscScalar**)ptr = array + start;
1721ce3176fSMatthew G. Knepley   PetscFunctionReturn(0);
1731ce3176fSMatthew G. Knepley }
1741ce3176fSMatthew G. Knepley 
1754824f456SMatthew G. Knepley /*@
1764824f456SMatthew G. Knepley    DMPlexPointLocalFieldRef - return read/write access to a field on a point in local array
1774824f456SMatthew G. Knepley 
1784824f456SMatthew G. Knepley    Not Collective
1794824f456SMatthew G. Knepley 
1804165533cSJose E. Roman    Input Parameters:
1814824f456SMatthew G. Knepley +  dm - DM defining topological space
1824824f456SMatthew G. Knepley .  point - topological point
1834824f456SMatthew G. Knepley .  field - field number
1844824f456SMatthew G. Knepley -  array - array to index into
1854824f456SMatthew G. Knepley 
1864165533cSJose E. Roman    Output Parameter:
1874824f456SMatthew G. Knepley .  ptr - address of reference to point data, type generic so user can place in structure
1884824f456SMatthew G. Knepley 
1894824f456SMatthew G. Knepley    Level: intermediate
1904824f456SMatthew G. Knepley 
19192fd8e1eSJed Brown .seealso: DMGetLocalSection(), PetscSectionGetOffset(), PetscSectionGetDof(), DMPlexGetPointLocal(), DMPlexPointGlobalRef()
1924824f456SMatthew G. Knepley @*/
1934824f456SMatthew G. Knepley PetscErrorCode DMPlexPointLocalFieldRef(DM dm,PetscInt point,PetscInt field,PetscScalar *array,void *ptr)
1944824f456SMatthew G. Knepley {
195a89cf0ddSMatthew G. Knepley   PetscInt       start, end;
1964824f456SMatthew G. Knepley 
1974824f456SMatthew G. Knepley   PetscFunctionBegin;
1984824f456SMatthew G. Knepley   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
199064a246eSJacob Faibussowitsch   PetscValidScalarPointer(array,4);
200064a246eSJacob Faibussowitsch   PetscValidPointer(ptr,5);
2015f80ce2aSJacob Faibussowitsch   CHKERRQ(DMGetLocalFieldOffset_Private(dm, point, field, &start, &end));
2024824f456SMatthew G. Knepley   *(PetscScalar**)ptr = array + start;
2034824f456SMatthew G. Knepley   PetscFunctionReturn(0);
2044824f456SMatthew G. Knepley }
2054824f456SMatthew G. Knepley 
206552f7358SJed Brown /*@
207552f7358SJed Brown   DMPlexGetPointGlobal - get location of point data in global Vec
208552f7358SJed Brown 
209552f7358SJed Brown   Not Collective
210552f7358SJed Brown 
2114165533cSJose E. Roman   Input Parameters:
212552f7358SJed Brown + dm - DM defining the topological space
213552f7358SJed Brown - point - topological point
214552f7358SJed Brown 
2154165533cSJose E. Roman   Output Parameters:
216a89cf0ddSMatthew G. Knepley + start - start of point data; returns -(globalStart+1) if point is not owned
217a89cf0ddSMatthew G. Knepley - end - end of point data; returns -(globalEnd+1) if point is not owned
218a89cf0ddSMatthew G. Knepley 
219a89cf0ddSMatthew G. Knepley   Note: This is a half open interval [start, end)
220552f7358SJed Brown 
221552f7358SJed Brown   Level: intermediate
222552f7358SJed Brown 
22392fd8e1eSJed Brown .seealso: DMPlexGetPointGlobalField(), DMGetLocalSection(), PetscSectionGetOffset(), PetscSectionGetDof(), DMPlexPointGlobalRead(), DMPlexGetPointLocal(), DMPlexPointGlobalRead(), DMPlexPointGlobalRef()
224552f7358SJed Brown @*/
225552f7358SJed Brown PetscErrorCode DMPlexGetPointGlobal(DM dm, PetscInt point, PetscInt *start, PetscInt *end)
226552f7358SJed Brown {
227a89cf0ddSMatthew G. Knepley   PetscInt       s, e;
228552f7358SJed Brown 
229552f7358SJed Brown   PetscFunctionBegin;
230552f7358SJed Brown   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
231*dadcf809SJacob Faibussowitsch   if (start) PetscValidIntPointer(start, 3);
232*dadcf809SJacob Faibussowitsch   if (end)   PetscValidIntPointer(end,   4);
2335f80ce2aSJacob Faibussowitsch   CHKERRQ(DMGetGlobalOffset_Private(dm, point, &s, &e));
234a89cf0ddSMatthew G. Knepley   if (start) *start = s;
235a89cf0ddSMatthew G. Knepley   if (end)   *end   = e;
236552f7358SJed Brown   PetscFunctionReturn(0);
237552f7358SJed Brown }
238552f7358SJed Brown 
239552f7358SJed Brown /*@
240552f7358SJed Brown    DMPlexPointGlobalRead - return read access to a point in global array
241552f7358SJed Brown 
242552f7358SJed Brown    Not Collective
243552f7358SJed Brown 
2444165533cSJose E. Roman    Input Parameters:
245552f7358SJed Brown +  dm - DM defining topological space
246552f7358SJed Brown .  point - topological point
247552f7358SJed Brown -  array - array to index into
248552f7358SJed Brown 
2494165533cSJose E. Roman    Output Parameter:
2500298fd71SBarry Smith .  ptr - address of read reference to point data, type generic so user can place in structure; returns NULL if global point is not owned
251552f7358SJed Brown 
252552f7358SJed Brown    Level: intermediate
253552f7358SJed Brown 
254552f7358SJed Brown    Note:
255552f7358SJed Brown    A common usage when data sizes are known statically:
256552f7358SJed Brown 
257552f7358SJed Brown $  const struct { PetscScalar foo,bar,baz; } *ptr;
258552f7358SJed Brown $  DMPlexPointGlobalRead(dm,point,array,&ptr);
259552f7358SJed Brown $  x = 2*ptr->foo + 3*ptr->bar + 5*ptr->baz;
260552f7358SJed Brown 
26192fd8e1eSJed Brown .seealso: DMGetLocalSection(), PetscSectionGetOffset(), PetscSectionGetDof(), DMPlexGetPointGlobal(), DMPlexPointLocalRead(), DMPlexPointGlobalRef()
262552f7358SJed Brown @*/
263552f7358SJed Brown PetscErrorCode DMPlexPointGlobalRead(DM dm,PetscInt point,const PetscScalar *array,const void *ptr)
264552f7358SJed Brown {
26579532bb4SMatthew G. Knepley   PetscInt       start, end;
266552f7358SJed Brown 
267552f7358SJed Brown   PetscFunctionBegin;
268552f7358SJed Brown   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
269552f7358SJed Brown   PetscValidScalarPointer(array, 3);
270552f7358SJed Brown   PetscValidPointer(ptr, 4);
2715f80ce2aSJacob Faibussowitsch   CHKERRQ(DMGetGlobalOffset_Private(dm, point, &start, &end));
27279532bb4SMatthew G. Knepley   *(const PetscScalar**) ptr = (start < end) ? array + start - dm->map->rstart : NULL;
273552f7358SJed Brown   PetscFunctionReturn(0);
274552f7358SJed Brown }
275552f7358SJed Brown 
276552f7358SJed Brown /*@
277552f7358SJed Brown    DMPlexPointGlobalRef - return read/write access to a point in global array
278552f7358SJed Brown 
279552f7358SJed Brown    Not Collective
280552f7358SJed Brown 
2814165533cSJose E. Roman    Input Parameters:
282552f7358SJed Brown +  dm - DM defining topological space
283552f7358SJed Brown .  point - topological point
284552f7358SJed Brown -  array - array to index into
285552f7358SJed Brown 
2864165533cSJose E. Roman    Output Parameter:
2870298fd71SBarry Smith .  ptr - address of reference to point data, type generic so user can place in structure; returns NULL if global point is not owned
288552f7358SJed Brown 
289552f7358SJed Brown    Level: intermediate
290552f7358SJed Brown 
291552f7358SJed Brown    Note:
292552f7358SJed Brown    A common usage when data sizes are known statically:
293552f7358SJed Brown 
294552f7358SJed Brown $  struct { PetscScalar foo,bar,baz; } *ptr;
295552f7358SJed Brown $  DMPlexPointGlobalRef(dm,point,array,&ptr);
296552f7358SJed Brown $  ptr->foo = 2; ptr->bar = 3; ptr->baz = 5;
297552f7358SJed Brown 
29892fd8e1eSJed Brown .seealso: DMGetLocalSection(), PetscSectionGetOffset(), PetscSectionGetDof(), DMPlexGetPointGlobal(), DMPlexPointLocalRef(), DMPlexPointGlobalRead()
299552f7358SJed Brown @*/
300552f7358SJed Brown PetscErrorCode DMPlexPointGlobalRef(DM dm,PetscInt point,PetscScalar *array,void *ptr)
301552f7358SJed Brown {
30279532bb4SMatthew G. Knepley   PetscInt       start, end;
303552f7358SJed Brown 
304552f7358SJed Brown   PetscFunctionBegin;
305552f7358SJed Brown   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
306552f7358SJed Brown   PetscValidScalarPointer(array, 3);
307552f7358SJed Brown   PetscValidPointer(ptr, 4);
3085f80ce2aSJacob Faibussowitsch   CHKERRQ(DMGetGlobalOffset_Private(dm, point, &start, &end));
30979532bb4SMatthew G. Knepley   *(PetscScalar**) ptr = (start < end) ? array + start - dm->map->rstart : NULL;
310552f7358SJed Brown   PetscFunctionReturn(0);
311552f7358SJed Brown }
31233879625SMatthew G. Knepley 
313a89cf0ddSMatthew G. Knepley /*@
314a89cf0ddSMatthew G. Knepley   DMPlexGetPointGlobalField - get location of point field data in global Vec
315a89cf0ddSMatthew G. Knepley 
316a89cf0ddSMatthew G. Knepley   Not Collective
317a89cf0ddSMatthew G. Knepley 
3184165533cSJose E. Roman   Input Parameters:
319a89cf0ddSMatthew G. Knepley + dm - DM defining the topological space
320a89cf0ddSMatthew G. Knepley . point - topological point
321a89cf0ddSMatthew G. Knepley - field - the field number
322a89cf0ddSMatthew G. Knepley 
3234165533cSJose E. Roman   Output Parameters:
324a89cf0ddSMatthew G. Knepley + start - start of point data; returns -(globalStart+1) if point is not owned
325a89cf0ddSMatthew G. Knepley - end - end of point data; returns -(globalEnd+1) if point is not owned
326a89cf0ddSMatthew G. Knepley 
327a89cf0ddSMatthew G. Knepley   Note: This is a half open interval [start, end)
328a89cf0ddSMatthew G. Knepley 
329a89cf0ddSMatthew G. Knepley   Level: intermediate
330a89cf0ddSMatthew G. Knepley 
33192fd8e1eSJed Brown .seealso: DMPlexGetPointGlobal(), DMGetLocalSection(), PetscSectionGetOffset(), PetscSectionGetDof(), DMPlexPointGlobalRead(), DMPlexGetPointLocal(), DMPlexPointGlobalRead(), DMPlexPointGlobalRef()
332a89cf0ddSMatthew G. Knepley @*/
333a89cf0ddSMatthew G. Knepley PetscErrorCode DMPlexGetPointGlobalField(DM dm, PetscInt point, PetscInt field, PetscInt *start, PetscInt *end)
334a89cf0ddSMatthew G. Knepley {
335a89cf0ddSMatthew G. Knepley   PetscInt       s, e;
336a89cf0ddSMatthew G. Knepley 
337a89cf0ddSMatthew G. Knepley   PetscFunctionBegin;
338a89cf0ddSMatthew G. Knepley   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
339*dadcf809SJacob Faibussowitsch   if (start) PetscValidIntPointer(start, 4);
340*dadcf809SJacob Faibussowitsch   if (end)   PetscValidIntPointer(end,   5);
3415f80ce2aSJacob Faibussowitsch   CHKERRQ(DMGetGlobalFieldOffset_Private(dm, point, field, &s, &e));
342a89cf0ddSMatthew G. Knepley   if (start) *start = s;
343a89cf0ddSMatthew G. Knepley   if (end)   *end   = e;
344a89cf0ddSMatthew G. Knepley   PetscFunctionReturn(0);
345a89cf0ddSMatthew G. Knepley }
346a89cf0ddSMatthew G. Knepley 
34733879625SMatthew G. Knepley /*@
34833879625SMatthew G. Knepley    DMPlexPointGlobalFieldRead - return read access to a field on a point in global array
34933879625SMatthew G. Knepley 
35033879625SMatthew G. Knepley    Not Collective
35133879625SMatthew G. Knepley 
3524165533cSJose E. Roman    Input Parameters:
35333879625SMatthew G. Knepley +  dm - DM defining topological space
35433879625SMatthew G. Knepley .  point - topological point
35533879625SMatthew G. Knepley .  field - field number
35633879625SMatthew G. Knepley -  array - array to index into
35733879625SMatthew G. Knepley 
3584165533cSJose E. Roman    Output Parameter:
35933879625SMatthew G. Knepley .  ptr - address of read reference to point data, type generic so user can place in structure; returns NULL if global point is not owned
36033879625SMatthew G. Knepley 
36133879625SMatthew G. Knepley    Level: intermediate
36233879625SMatthew G. Knepley 
36392fd8e1eSJed Brown .seealso: DMGetLocalSection(), PetscSectionGetOffset(), PetscSectionGetDof(), DMPlexGetPointGlobal(), DMPlexPointLocalRead(), DMPlexPointGlobalRef()
36433879625SMatthew G. Knepley @*/
365081a2d76SSatish Balay PetscErrorCode DMPlexPointGlobalFieldRead(DM dm,PetscInt point,PetscInt field,const PetscScalar *array,void *ptr)
36633879625SMatthew G. Knepley {
36779532bb4SMatthew G. Knepley   PetscInt       start, end;
36833879625SMatthew G. Knepley 
36933879625SMatthew G. Knepley   PetscFunctionBegin;
37033879625SMatthew G. Knepley   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
371064a246eSJacob Faibussowitsch   PetscValidScalarPointer(array, 4);
372064a246eSJacob Faibussowitsch   PetscValidPointer(ptr, 5);
3735f80ce2aSJacob Faibussowitsch   CHKERRQ(DMGetGlobalFieldOffset_Private(dm, point, field, &start, &end));
37479532bb4SMatthew G. Knepley   *(const PetscScalar**) ptr = (start < end) ? array + start - dm->map->rstart : NULL;
37533879625SMatthew G. Knepley   PetscFunctionReturn(0);
37633879625SMatthew G. Knepley }
37733879625SMatthew G. Knepley 
37833879625SMatthew G. Knepley /*@
37933879625SMatthew G. Knepley    DMPlexPointGlobalFieldRef - return read/write access to a field on a point in global array
38033879625SMatthew G. Knepley 
38133879625SMatthew G. Knepley    Not Collective
38233879625SMatthew G. Knepley 
3834165533cSJose E. Roman    Input Parameters:
38433879625SMatthew G. Knepley +  dm - DM defining topological space
38533879625SMatthew G. Knepley .  point - topological point
38633879625SMatthew G. Knepley .  field - field number
38733879625SMatthew G. Knepley -  array - array to index into
38833879625SMatthew G. Knepley 
3894165533cSJose E. Roman    Output Parameter:
39033879625SMatthew G. Knepley .  ptr - address of reference to point data, type generic so user can place in structure; returns NULL if global point is not owned
39133879625SMatthew G. Knepley 
39233879625SMatthew G. Knepley    Level: intermediate
39333879625SMatthew G. Knepley 
39492fd8e1eSJed Brown .seealso: DMGetLocalSection(), PetscSectionGetOffset(), PetscSectionGetDof(), DMPlexGetPointGlobal(), DMPlexPointLocalRef(), DMPlexPointGlobalRead()
39533879625SMatthew G. Knepley @*/
39633879625SMatthew G. Knepley PetscErrorCode DMPlexPointGlobalFieldRef(DM dm,PetscInt point,PetscInt field,PetscScalar *array,void *ptr)
39733879625SMatthew G. Knepley {
39879532bb4SMatthew G. Knepley   PetscInt       start, end;
39933879625SMatthew G. Knepley 
40033879625SMatthew G. Knepley   PetscFunctionBegin;
40133879625SMatthew G. Knepley   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
402064a246eSJacob Faibussowitsch   PetscValidScalarPointer(array, 4);
403064a246eSJacob Faibussowitsch   PetscValidPointer(ptr, 5);
4045f80ce2aSJacob Faibussowitsch   CHKERRQ(DMGetGlobalFieldOffset_Private(dm, point, field, &start, &end));
40579532bb4SMatthew G. Knepley   *(PetscScalar**) ptr = (start < end) ? array + start - dm->map->rstart : NULL;
40633879625SMatthew G. Knepley   PetscFunctionReturn(0);
40733879625SMatthew G. Knepley }
408