xref: /petsc/src/dm/impls/plex/plexpoint.c (revision a1cb98fac0cdf0eb4d3e8a0c8b58f3fe8f800bc6)
1af0996ceSBarry Smith #include <petsc/private/dmpleximpl.h> /*I      "petscdmplex.h"   I*/
233879625SMatthew G. Knepley 
3552f7358SJed Brown /*@
4*a1cb98faSBarry Smith    DMPlexGetPointLocal - get location of point data in local `Vec`
5552f7358SJed Brown 
6552f7358SJed Brown    Not Collective
7552f7358SJed Brown 
84165533cSJose E. Roman    Input Parameters:
9*a1cb98faSBarry Smith +  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 
16552f7358SJed Brown    Level: intermediate
17552f7358SJed Brown 
18*a1cb98faSBarry Smith    Note:
19*a1cb98faSBarry Smith    This is a half open interval [start, end)
20*a1cb98faSBarry Smith 
21*a1cb98faSBarry Smith .seealso: [](chapter_unstructured), `DM`, `DMPLEX`, `DMPlexGetPointLocalField()`, `DMGetLocalSection()`, `PetscSectionGetOffset()`, `PetscSectionGetDof()`, `DMPlexPointLocalRead()`, `DMPlexPointLocalRead()`, `DMPlexPointLocalRef()`
22552f7358SJed Brown @*/
23d71ae5a4SJacob Faibussowitsch PetscErrorCode DMPlexGetPointLocal(DM dm, PetscInt point, PetscInt *start, PetscInt *end)
24d71ae5a4SJacob Faibussowitsch {
25a89cf0ddSMatthew G. Knepley   PetscInt s, e;
26552f7358SJed Brown 
27552f7358SJed Brown   PetscFunctionBegin;
28552f7358SJed Brown   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
29dadcf809SJacob Faibussowitsch   if (start) PetscValidIntPointer(start, 3);
30dadcf809SJacob Faibussowitsch   if (end) PetscValidIntPointer(end, 4);
319566063dSJacob Faibussowitsch   PetscCall(DMGetLocalOffset_Private(dm, point, &s, &e));
32a89cf0ddSMatthew G. Knepley   if (start) *start = s;
33a89cf0ddSMatthew G. Knepley   if (end) *end = e;
34552f7358SJed Brown   PetscFunctionReturn(0);
35552f7358SJed Brown }
36552f7358SJed Brown 
37552f7358SJed Brown /*@
38552f7358SJed Brown    DMPlexPointLocalRead - return read access to a point in local array
39552f7358SJed Brown 
40552f7358SJed Brown    Not Collective
41552f7358SJed Brown 
424165533cSJose E. Roman    Input Parameters:
43*a1cb98faSBarry Smith +  dm - `DM` defining topological space
44552f7358SJed Brown .  point - topological point
45552f7358SJed Brown -  array - array to index into
46552f7358SJed Brown 
474165533cSJose E. Roman    Output Parameter:
48552f7358SJed Brown .  ptr - address of read reference to point data, type generic so user can place in structure
49552f7358SJed Brown 
50552f7358SJed Brown    Level: intermediate
51552f7358SJed Brown 
52552f7358SJed Brown    Note:
53552f7358SJed Brown    A common usage when data sizes are known statically:
54*a1cb98faSBarry Smith .vb
55*a1cb98faSBarry Smith   const struct { PetscScalar foo,bar,baz; } *ptr;
56*a1cb98faSBarry Smith   DMPlexPointLocalRead(dm,point,array,&ptr);
57*a1cb98faSBarry Smith   x = 2*ptr->foo + 3*ptr->bar + 5*ptr->baz;
58*a1cb98faSBarry Smith .ve
59552f7358SJed Brown 
60*a1cb98faSBarry Smith .seealso: [](chapter_unstructured), `DM`, `DMPLEX`, `DMGetLocalSection()`, `PetscSectionGetOffset()`, `PetscSectionGetDof()`, `DMPlexGetPointLocal()`, `DMPlexPointGlobalRead()`
61552f7358SJed Brown @*/
62d71ae5a4SJacob Faibussowitsch PetscErrorCode DMPlexPointLocalRead(DM dm, PetscInt point, const PetscScalar *array, void *ptr)
63d71ae5a4SJacob Faibussowitsch {
64a89cf0ddSMatthew G. Knepley   PetscInt start, end;
65552f7358SJed Brown 
66552f7358SJed Brown   PetscFunctionBegin;
67552f7358SJed Brown   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
68552f7358SJed Brown   PetscValidScalarPointer(array, 3);
69552f7358SJed Brown   PetscValidPointer(ptr, 4);
709566063dSJacob Faibussowitsch   PetscCall(DMGetLocalOffset_Private(dm, point, &start, &end));
71a89cf0ddSMatthew G. Knepley   *(const PetscScalar **)ptr = (start < end) ? array + start : NULL;
72552f7358SJed Brown   PetscFunctionReturn(0);
73552f7358SJed Brown }
74552f7358SJed Brown 
75552f7358SJed Brown /*@
76552f7358SJed Brown    DMPlexPointLocalRef - return read/write access to a point in local array
77552f7358SJed Brown 
78552f7358SJed Brown    Not Collective
79552f7358SJed Brown 
804165533cSJose E. Roman    Input Parameters:
81*a1cb98faSBarry Smith +  dm - `DM` defining topological space
82552f7358SJed Brown .  point - topological point
83552f7358SJed Brown -  array - array to index into
84552f7358SJed Brown 
854165533cSJose E. Roman    Output Parameter:
86552f7358SJed Brown .  ptr - address of reference to point data, type generic so user can place in structure
87552f7358SJed Brown 
88552f7358SJed Brown    Level: intermediate
89552f7358SJed Brown 
90552f7358SJed Brown    Note:
91552f7358SJed Brown    A common usage when data sizes are known statically:
92*a1cb98faSBarry Smith .vb
93*a1cb98faSBarry Smith   struct { PetscScalar foo,bar,baz; } *ptr;
94*a1cb98faSBarry Smith   DMPlexPointLocalRef(dm,point,array,&ptr);
95*a1cb98faSBarry Smith   ptr->foo = 2; ptr->bar = 3; ptr->baz = 5;
96*a1cb98faSBarry Smith .ve
97552f7358SJed Brown 
98*a1cb98faSBarry Smith .seealso: [](chapter_unstructured), `DM`, `DMPLEX`, `DMGetLocalSection()`, `PetscSectionGetOffset()`, `PetscSectionGetDof()`, `DMPlexGetPointLocal()`, `DMPlexPointGlobalRef()`
99552f7358SJed Brown @*/
100d71ae5a4SJacob Faibussowitsch PetscErrorCode DMPlexPointLocalRef(DM dm, PetscInt point, PetscScalar *array, void *ptr)
101d71ae5a4SJacob Faibussowitsch {
102a89cf0ddSMatthew G. Knepley   PetscInt start, end;
103552f7358SJed Brown 
104552f7358SJed Brown   PetscFunctionBegin;
105552f7358SJed Brown   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
106552f7358SJed Brown   PetscValidScalarPointer(array, 3);
107552f7358SJed Brown   PetscValidPointer(ptr, 4);
1089566063dSJacob Faibussowitsch   PetscCall(DMGetLocalOffset_Private(dm, point, &start, &end));
109a89cf0ddSMatthew G. Knepley   *(PetscScalar **)ptr = (start < end) ? array + start : NULL;
110a89cf0ddSMatthew G. Knepley   PetscFunctionReturn(0);
111a89cf0ddSMatthew G. Knepley }
112a89cf0ddSMatthew G. Knepley 
113a89cf0ddSMatthew G. Knepley /*@
114a89cf0ddSMatthew G. Knepley   DMPlexGetPointLocalField - get location of point field data in local Vec
115a89cf0ddSMatthew G. Knepley 
116a89cf0ddSMatthew G. Knepley   Not Collective
117a89cf0ddSMatthew G. Knepley 
1184165533cSJose E. Roman   Input Parameters:
119*a1cb98faSBarry Smith + dm - `DM` defining the topological space
120a89cf0ddSMatthew G. Knepley . point - topological point
121a89cf0ddSMatthew G. Knepley - field - the field number
122a89cf0ddSMatthew G. Knepley 
1234165533cSJose E. Roman   Output Parameters:
124a89cf0ddSMatthew G. Knepley + start - start of point data
125a89cf0ddSMatthew G. Knepley - end - end of point data
126a89cf0ddSMatthew G. Knepley 
127a89cf0ddSMatthew G. Knepley   Level: intermediate
128a89cf0ddSMatthew G. Knepley 
129*a1cb98faSBarry Smith   Note:
130*a1cb98faSBarry Smith   This is a half open interval [start, end)
131*a1cb98faSBarry Smith 
132*a1cb98faSBarry Smith .seealso: [](chapter_unstructured), `DM`, `DMPLEX`, `DMPlexGetPointLocal()`, `DMGetLocalSection()`, `PetscSectionGetOffset()`, `PetscSectionGetDof()`, `DMPlexPointLocalRead()`, `DMPlexPointLocalRead()`, `DMPlexPointLocalRef()`
133a89cf0ddSMatthew G. Knepley @*/
134d71ae5a4SJacob Faibussowitsch PetscErrorCode DMPlexGetPointLocalField(DM dm, PetscInt point, PetscInt field, PetscInt *start, PetscInt *end)
135d71ae5a4SJacob Faibussowitsch {
136a89cf0ddSMatthew G. Knepley   PetscInt s, e;
137a89cf0ddSMatthew G. Knepley 
138a89cf0ddSMatthew G. Knepley   PetscFunctionBegin;
139a89cf0ddSMatthew G. Knepley   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
140dadcf809SJacob Faibussowitsch   if (start) PetscValidIntPointer(start, 4);
141dadcf809SJacob Faibussowitsch   if (end) PetscValidIntPointer(end, 5);
1429566063dSJacob Faibussowitsch   PetscCall(DMGetLocalFieldOffset_Private(dm, point, field, &s, &e));
143a89cf0ddSMatthew G. Knepley   if (start) *start = s;
144a89cf0ddSMatthew G. Knepley   if (end) *end = e;
145552f7358SJed Brown   PetscFunctionReturn(0);
146552f7358SJed Brown }
147552f7358SJed Brown 
1481ce3176fSMatthew G. Knepley /*@
1491ce3176fSMatthew G. Knepley    DMPlexPointLocalFieldRead - return read access to a field on a point in local array
1501ce3176fSMatthew G. Knepley 
1511ce3176fSMatthew G. Knepley    Not Collective
1521ce3176fSMatthew G. Knepley 
1534165533cSJose E. Roman    Input Parameters:
154*a1cb98faSBarry Smith +  dm - `DM` defining topological space
1551ce3176fSMatthew G. Knepley .  point - topological point
1561ce3176fSMatthew G. Knepley .  field - field number
1571ce3176fSMatthew G. Knepley -  array - array to index into
1581ce3176fSMatthew G. Knepley 
1594165533cSJose E. Roman    Output Parameter:
1601ce3176fSMatthew G. Knepley .  ptr - address of read reference to point data, type generic so user can place in structure
1611ce3176fSMatthew G. Knepley 
1621ce3176fSMatthew G. Knepley    Level: intermediate
1631ce3176fSMatthew G. Knepley 
164*a1cb98faSBarry Smith .seealso: [](chapter_unstructured), `DM`, `DMPLEX`, `DMGetLocalSection()`, `PetscSectionGetOffset()`, `PetscSectionGetDof()`, `DMPlexGetPointLocal()`, `DMPlexPointGlobalRef()`
1651ce3176fSMatthew G. Knepley @*/
166d71ae5a4SJacob Faibussowitsch PetscErrorCode DMPlexPointLocalFieldRead(DM dm, PetscInt point, PetscInt field, const PetscScalar *array, void *ptr)
167d71ae5a4SJacob Faibussowitsch {
168a89cf0ddSMatthew G. Knepley   PetscInt start, end;
1691ce3176fSMatthew G. Knepley 
1701ce3176fSMatthew G. Knepley   PetscFunctionBegin;
1711ce3176fSMatthew G. Knepley   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
172064a246eSJacob Faibussowitsch   PetscValidScalarPointer(array, 4);
173064a246eSJacob Faibussowitsch   PetscValidPointer(ptr, 5);
1749566063dSJacob Faibussowitsch   PetscCall(DMGetLocalFieldOffset_Private(dm, point, field, &start, &end));
1751ce3176fSMatthew G. Knepley   *(const PetscScalar **)ptr = array + start;
1761ce3176fSMatthew G. Knepley   PetscFunctionReturn(0);
1771ce3176fSMatthew G. Knepley }
1781ce3176fSMatthew G. Knepley 
1794824f456SMatthew G. Knepley /*@
1804824f456SMatthew G. Knepley    DMPlexPointLocalFieldRef - return read/write access to a field on a point in local array
1814824f456SMatthew G. Knepley 
1824824f456SMatthew G. Knepley    Not Collective
1834824f456SMatthew G. Knepley 
1844165533cSJose E. Roman    Input Parameters:
185*a1cb98faSBarry Smith +  dm - `DM` defining topological space
1864824f456SMatthew G. Knepley .  point - topological point
1874824f456SMatthew G. Knepley .  field - field number
1884824f456SMatthew G. Knepley -  array - array to index into
1894824f456SMatthew G. Knepley 
1904165533cSJose E. Roman    Output Parameter:
1914824f456SMatthew G. Knepley .  ptr - address of reference to point data, type generic so user can place in structure
1924824f456SMatthew G. Knepley 
1934824f456SMatthew G. Knepley    Level: intermediate
1944824f456SMatthew G. Knepley 
195*a1cb98faSBarry Smith .seealso: [](chapter_unstructured), `DM`, `DMPLEX`, `DMGetLocalSection()`, `PetscSectionGetOffset()`, `PetscSectionGetDof()`, `DMPlexGetPointLocal()`, `DMPlexPointGlobalRef()`
1964824f456SMatthew G. Knepley @*/
197d71ae5a4SJacob Faibussowitsch PetscErrorCode DMPlexPointLocalFieldRef(DM dm, PetscInt point, PetscInt field, PetscScalar *array, void *ptr)
198d71ae5a4SJacob Faibussowitsch {
199a89cf0ddSMatthew G. Knepley   PetscInt start, end;
2004824f456SMatthew G. Knepley 
2014824f456SMatthew G. Knepley   PetscFunctionBegin;
2024824f456SMatthew G. Knepley   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
203064a246eSJacob Faibussowitsch   PetscValidScalarPointer(array, 4);
204064a246eSJacob Faibussowitsch   PetscValidPointer(ptr, 5);
2059566063dSJacob Faibussowitsch   PetscCall(DMGetLocalFieldOffset_Private(dm, point, field, &start, &end));
2064824f456SMatthew G. Knepley   *(PetscScalar **)ptr = array + start;
2074824f456SMatthew G. Knepley   PetscFunctionReturn(0);
2084824f456SMatthew G. Knepley }
2094824f456SMatthew G. Knepley 
210552f7358SJed Brown /*@
211552f7358SJed Brown   DMPlexGetPointGlobal - get location of point data in global Vec
212552f7358SJed Brown 
213552f7358SJed Brown   Not Collective
214552f7358SJed Brown 
2154165533cSJose E. Roman   Input Parameters:
216*a1cb98faSBarry Smith + dm - `DM` defining the topological space
217552f7358SJed Brown - point - topological point
218552f7358SJed Brown 
2194165533cSJose E. Roman   Output Parameters:
220a89cf0ddSMatthew G. Knepley + start - start of point data; returns -(globalStart+1) if point is not owned
221a89cf0ddSMatthew G. Knepley - end - end of point data; returns -(globalEnd+1) if point is not owned
222a89cf0ddSMatthew G. Knepley 
223552f7358SJed Brown   Level: intermediate
224552f7358SJed Brown 
225*a1cb98faSBarry Smith   Note:
226*a1cb98faSBarry Smith   This is a half open interval [start, end)
227*a1cb98faSBarry Smith 
228*a1cb98faSBarry Smith .seealso: [](chapter_unstructured), `DM`, `DMPLEX`, `DMPlexGetPointGlobalField()`, `DMGetLocalSection()`, `PetscSectionGetOffset()`, `PetscSectionGetDof()`, `DMPlexPointGlobalRead()`, `DMPlexGetPointLocal()`, `DMPlexPointGlobalRead()`, `DMPlexPointGlobalRef()`
229552f7358SJed Brown @*/
230d71ae5a4SJacob Faibussowitsch PetscErrorCode DMPlexGetPointGlobal(DM dm, PetscInt point, PetscInt *start, PetscInt *end)
231d71ae5a4SJacob Faibussowitsch {
232a89cf0ddSMatthew G. Knepley   PetscInt s, e;
233552f7358SJed Brown 
234552f7358SJed Brown   PetscFunctionBegin;
235552f7358SJed Brown   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
236dadcf809SJacob Faibussowitsch   if (start) PetscValidIntPointer(start, 3);
237dadcf809SJacob Faibussowitsch   if (end) PetscValidIntPointer(end, 4);
2389566063dSJacob Faibussowitsch   PetscCall(DMGetGlobalOffset_Private(dm, point, &s, &e));
239a89cf0ddSMatthew G. Knepley   if (start) *start = s;
240a89cf0ddSMatthew G. Knepley   if (end) *end = e;
241552f7358SJed Brown   PetscFunctionReturn(0);
242552f7358SJed Brown }
243552f7358SJed Brown 
244552f7358SJed Brown /*@
245552f7358SJed Brown    DMPlexPointGlobalRead - return read access to a point in global array
246552f7358SJed Brown 
247552f7358SJed Brown    Not Collective
248552f7358SJed Brown 
2494165533cSJose E. Roman    Input Parameters:
250*a1cb98faSBarry Smith +  dm - `DM` defining topological space
251552f7358SJed Brown .  point - topological point
252552f7358SJed Brown -  array - array to index into
253552f7358SJed Brown 
2544165533cSJose E. Roman    Output Parameter:
2550298fd71SBarry 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
256552f7358SJed Brown 
257552f7358SJed Brown    Level: intermediate
258552f7358SJed Brown 
259552f7358SJed Brown    Note:
260552f7358SJed Brown    A common usage when data sizes are known statically:
261*a1cb98faSBarry Smith .vb
262*a1cb98faSBarry Smith   const struct { PetscScalar foo,bar,baz; } *ptr;
263*a1cb98faSBarry Smith   DMPlexPointGlobalRead(dm,point,array,&ptr);
264*a1cb98faSBarry Smith   x = 2*ptr->foo + 3*ptr->bar + 5*ptr->baz;
265*a1cb98faSBarry Smith .ve
266552f7358SJed Brown 
267*a1cb98faSBarry Smith .seealso: [](chapter_unstructured), `DM`, `DMPLEX`, `DMGetLocalSection()`, `PetscSectionGetOffset()`, `PetscSectionGetDof()`, `DMPlexGetPointGlobal()`, `DMPlexPointLocalRead()`, `DMPlexPointGlobalRef()`
268552f7358SJed Brown @*/
269d71ae5a4SJacob Faibussowitsch PetscErrorCode DMPlexPointGlobalRead(DM dm, PetscInt point, const PetscScalar *array, const void *ptr)
270d71ae5a4SJacob Faibussowitsch {
27179532bb4SMatthew G. Knepley   PetscInt start, end;
272552f7358SJed Brown 
273552f7358SJed Brown   PetscFunctionBegin;
274552f7358SJed Brown   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
275552f7358SJed Brown   PetscValidScalarPointer(array, 3);
276552f7358SJed Brown   PetscValidPointer(ptr, 4);
2779566063dSJacob Faibussowitsch   PetscCall(DMGetGlobalOffset_Private(dm, point, &start, &end));
27879532bb4SMatthew G. Knepley   *(const PetscScalar **)ptr = (start < end) ? array + start - dm->map->rstart : NULL;
279552f7358SJed Brown   PetscFunctionReturn(0);
280552f7358SJed Brown }
281552f7358SJed Brown 
282552f7358SJed Brown /*@
283552f7358SJed Brown    DMPlexPointGlobalRef - return read/write access to a point in global array
284552f7358SJed Brown 
285552f7358SJed Brown    Not Collective
286552f7358SJed Brown 
2874165533cSJose E. Roman    Input Parameters:
288*a1cb98faSBarry Smith +  dm - `DM` defining topological space
289552f7358SJed Brown .  point - topological point
290552f7358SJed Brown -  array - array to index into
291552f7358SJed Brown 
2924165533cSJose E. Roman    Output Parameter:
2930298fd71SBarry Smith .  ptr - address of reference to point data, type generic so user can place in structure; returns NULL if global point is not owned
294552f7358SJed Brown 
295552f7358SJed Brown    Level: intermediate
296552f7358SJed Brown 
297552f7358SJed Brown    Note:
298552f7358SJed Brown    A common usage when data sizes are known statically:
299*a1cb98faSBarry Smith .vb
300*a1cb98faSBarry Smith   struct { PetscScalar foo,bar,baz; } *ptr;
301*a1cb98faSBarry Smith   DMPlexPointGlobalRef(dm,point,array,&ptr);
302*a1cb98faSBarry Smith   ptr->foo = 2; ptr->bar = 3; ptr->baz = 5;
303*a1cb98faSBarry Smith .ve
304552f7358SJed Brown 
305*a1cb98faSBarry Smith .seealso: [](chapter_unstructured), `DM`, `DMPLEX`, `DMGetLocalSection()`, `PetscSectionGetOffset()`, `PetscSectionGetDof()`, `DMPlexGetPointGlobal()`, `DMPlexPointLocalRef()`, `DMPlexPointGlobalRead()`
306552f7358SJed Brown @*/
307d71ae5a4SJacob Faibussowitsch PetscErrorCode DMPlexPointGlobalRef(DM dm, PetscInt point, PetscScalar *array, void *ptr)
308d71ae5a4SJacob Faibussowitsch {
30979532bb4SMatthew G. Knepley   PetscInt start, end;
310552f7358SJed Brown 
311552f7358SJed Brown   PetscFunctionBegin;
312552f7358SJed Brown   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
313552f7358SJed Brown   PetscValidScalarPointer(array, 3);
314552f7358SJed Brown   PetscValidPointer(ptr, 4);
3159566063dSJacob Faibussowitsch   PetscCall(DMGetGlobalOffset_Private(dm, point, &start, &end));
31679532bb4SMatthew G. Knepley   *(PetscScalar **)ptr = (start < end) ? array + start - dm->map->rstart : NULL;
317552f7358SJed Brown   PetscFunctionReturn(0);
318552f7358SJed Brown }
31933879625SMatthew G. Knepley 
320a89cf0ddSMatthew G. Knepley /*@
321*a1cb98faSBarry Smith   DMPlexGetPointGlobalField - get location of point field data in global `Vec`
322a89cf0ddSMatthew G. Knepley 
323a89cf0ddSMatthew G. Knepley   Not Collective
324a89cf0ddSMatthew G. Knepley 
3254165533cSJose E. Roman   Input Parameters:
326*a1cb98faSBarry Smith + dm - `DM` defining the topological space
327a89cf0ddSMatthew G. Knepley . point - topological point
328a89cf0ddSMatthew G. Knepley - field - the field number
329a89cf0ddSMatthew G. Knepley 
3304165533cSJose E. Roman   Output Parameters:
331a89cf0ddSMatthew G. Knepley + start - start of point data; returns -(globalStart+1) if point is not owned
332a89cf0ddSMatthew G. Knepley - end - end of point data; returns -(globalEnd+1) if point is not owned
333a89cf0ddSMatthew G. Knepley 
334a89cf0ddSMatthew G. Knepley   Level: intermediate
335a89cf0ddSMatthew G. Knepley 
336*a1cb98faSBarry Smith   Note:
337*a1cb98faSBarry Smith   This is a half open interval [start, end)
338*a1cb98faSBarry Smith 
339*a1cb98faSBarry Smith .seealso: [](chapter_unstructured), `DM`, `DMPLEX`, `DMPlexGetPointGlobal()`, `DMGetLocalSection()`, `PetscSectionGetOffset()`, `PetscSectionGetDof()`, `DMPlexPointGlobalRead()`, `DMPlexGetPointLocal()`, `DMPlexPointGlobalRead()`, `DMPlexPointGlobalRef()`
340a89cf0ddSMatthew G. Knepley @*/
341d71ae5a4SJacob Faibussowitsch PetscErrorCode DMPlexGetPointGlobalField(DM dm, PetscInt point, PetscInt field, PetscInt *start, PetscInt *end)
342d71ae5a4SJacob Faibussowitsch {
343a89cf0ddSMatthew G. Knepley   PetscInt s, e;
344a89cf0ddSMatthew G. Knepley 
345a89cf0ddSMatthew G. Knepley   PetscFunctionBegin;
346a89cf0ddSMatthew G. Knepley   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
347dadcf809SJacob Faibussowitsch   if (start) PetscValidIntPointer(start, 4);
348dadcf809SJacob Faibussowitsch   if (end) PetscValidIntPointer(end, 5);
3499566063dSJacob Faibussowitsch   PetscCall(DMGetGlobalFieldOffset_Private(dm, point, field, &s, &e));
350a89cf0ddSMatthew G. Knepley   if (start) *start = s;
351a89cf0ddSMatthew G. Knepley   if (end) *end = e;
352a89cf0ddSMatthew G. Knepley   PetscFunctionReturn(0);
353a89cf0ddSMatthew G. Knepley }
354a89cf0ddSMatthew G. Knepley 
35533879625SMatthew G. Knepley /*@
35633879625SMatthew G. Knepley    DMPlexPointGlobalFieldRead - return read access to a field on a point in global array
35733879625SMatthew G. Knepley 
35833879625SMatthew G. Knepley    Not Collective
35933879625SMatthew G. Knepley 
3604165533cSJose E. Roman    Input Parameters:
361*a1cb98faSBarry Smith +  dm - `DM` defining topological space
36233879625SMatthew G. Knepley .  point - topological point
36333879625SMatthew G. Knepley .  field - field number
36433879625SMatthew G. Knepley -  array - array to index into
36533879625SMatthew G. Knepley 
3664165533cSJose E. Roman    Output Parameter:
36733879625SMatthew 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
36833879625SMatthew G. Knepley 
36933879625SMatthew G. Knepley    Level: intermediate
37033879625SMatthew G. Knepley 
371*a1cb98faSBarry Smith .seealso: [](chapter_unstructured), `DM`, `DMPLEX`, `DMGetLocalSection()`, `PetscSectionGetOffset()`, `PetscSectionGetDof()`, `DMPlexGetPointGlobal()`, `DMPlexPointLocalRead()`, `DMPlexPointGlobalRef()`
37233879625SMatthew G. Knepley @*/
373d71ae5a4SJacob Faibussowitsch PetscErrorCode DMPlexPointGlobalFieldRead(DM dm, PetscInt point, PetscInt field, const PetscScalar *array, void *ptr)
374d71ae5a4SJacob Faibussowitsch {
37579532bb4SMatthew G. Knepley   PetscInt start, end;
37633879625SMatthew G. Knepley 
37733879625SMatthew G. Knepley   PetscFunctionBegin;
37833879625SMatthew G. Knepley   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
379064a246eSJacob Faibussowitsch   PetscValidScalarPointer(array, 4);
380064a246eSJacob Faibussowitsch   PetscValidPointer(ptr, 5);
3819566063dSJacob Faibussowitsch   PetscCall(DMGetGlobalFieldOffset_Private(dm, point, field, &start, &end));
38279532bb4SMatthew G. Knepley   *(const PetscScalar **)ptr = (start < end) ? array + start - dm->map->rstart : NULL;
38333879625SMatthew G. Knepley   PetscFunctionReturn(0);
38433879625SMatthew G. Knepley }
38533879625SMatthew G. Knepley 
38633879625SMatthew G. Knepley /*@
38733879625SMatthew G. Knepley    DMPlexPointGlobalFieldRef - return read/write access to a field on a point in global array
38833879625SMatthew G. Knepley 
38933879625SMatthew G. Knepley    Not Collective
39033879625SMatthew G. Knepley 
3914165533cSJose E. Roman    Input Parameters:
392*a1cb98faSBarry Smith +  dm - `DM` defining topological space
39333879625SMatthew G. Knepley .  point - topological point
39433879625SMatthew G. Knepley .  field - field number
39533879625SMatthew G. Knepley -  array - array to index into
39633879625SMatthew G. Knepley 
3974165533cSJose E. Roman    Output Parameter:
39833879625SMatthew 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
39933879625SMatthew G. Knepley 
40033879625SMatthew G. Knepley    Level: intermediate
40133879625SMatthew G. Knepley 
402*a1cb98faSBarry Smith .seealso: [](chapter_unstructured), `DM`, `DMPLEX`, `DMGetLocalSection()`, `PetscSectionGetOffset()`, `PetscSectionGetDof()`, `DMPlexGetPointGlobal()`, `DMPlexPointLocalRef()`, `DMPlexPointGlobalRead()`
40333879625SMatthew G. Knepley @*/
404d71ae5a4SJacob Faibussowitsch PetscErrorCode DMPlexPointGlobalFieldRef(DM dm, PetscInt point, PetscInt field, PetscScalar *array, void *ptr)
405d71ae5a4SJacob Faibussowitsch {
40679532bb4SMatthew G. Knepley   PetscInt start, end;
40733879625SMatthew G. Knepley 
40833879625SMatthew G. Knepley   PetscFunctionBegin;
40933879625SMatthew G. Knepley   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
410064a246eSJacob Faibussowitsch   PetscValidScalarPointer(array, 4);
411064a246eSJacob Faibussowitsch   PetscValidPointer(ptr, 5);
4129566063dSJacob Faibussowitsch   PetscCall(DMGetGlobalFieldOffset_Private(dm, point, field, &start, &end));
41379532bb4SMatthew G. Knepley   *(PetscScalar **)ptr = (start < end) ? array + start - dm->map->rstart : NULL;
41433879625SMatthew G. Knepley   PetscFunctionReturn(0);
41533879625SMatthew G. Knepley }
416