xref: /petsc/src/dm/impls/plex/plexpoint.c (revision 3387962581f688b27e93fa2fa63070eb31b1b9d5)
1 #include <petsc-private/dmpleximpl.h>   /*I      "petscdmplex.h"   I*/
2 #include <petsc-private/isimpl.h>     /* for inline access to atlasOff */
3 
4 #undef __FUNCT__
5 #define __FUNCT__ "DMPlexGetLocalOffset_Private"
6 PETSC_STATIC_INLINE PetscErrorCode DMPlexGetLocalOffset_Private(DM dm,PetscInt point,PetscInt *offset)
7 {
8   PetscFunctionBegin;
9 #if defined(PETSC_USE_DEBUG)
10   {
11     PetscErrorCode ierr;
12     ierr = PetscSectionGetOffset(dm->defaultSection,point,offset);CHKERRQ(ierr);
13   }
14 #else
15   {
16     PetscSection s = dm->defaultSection;
17     *offset = s->atlasOff[point - s->pStart];
18   }
19 #endif
20   PetscFunctionReturn(0);
21 }
22 
23 #undef __FUNCT__
24 #define __FUNCT__ "DMPlexGetLocalFieldOffset_Private"
25 PETSC_STATIC_INLINE PetscErrorCode DMPlexGetLocalFieldOffset_Private(DM dm,PetscInt point,PetscInt field,PetscInt *offset)
26 {
27   PetscFunctionBegin;
28 #if defined(PETSC_USE_DEBUG)
29   {
30     PetscErrorCode ierr;
31     ierr = PetscSectionGetFieldOffset(dm->defaultSection,point,field,offset);CHKERRQ(ierr);
32   }
33 #else
34   {
35     PetscSection s = dm->defaultSection->field[field];
36     *offset = s->atlasOff[point - s->pStart];
37   }
38 #endif
39   PetscFunctionReturn(0);
40 }
41 
42 #undef __FUNCT__
43 #define __FUNCT__ "DMPlexGetGlobalOffset_Private"
44 PETSC_STATIC_INLINE PetscErrorCode DMPlexGetGlobalOffset_Private(DM dm,PetscInt point,PetscInt *offset)
45 {
46   PetscFunctionBegin;
47 #if defined(PETSC_USE_DEBUG)
48   {
49     PetscErrorCode ierr;
50     PetscInt       dof,cdof;
51     ierr = PetscSectionGetOffset(dm->defaultGlobalSection,point,offset);CHKERRQ(ierr);
52     ierr = PetscSectionGetDof(dm->defaultGlobalSection,point,&dof);CHKERRQ(ierr);
53     ierr = PetscSectionGetConstraintDof(dm->defaultGlobalSection,point,&cdof);CHKERRQ(ierr);
54     if (dof-cdof <= 0) *offset = -1; /* Indicates no data */
55   }
56 #else
57   {
58     PetscSection s = dm->defaultGlobalSection;
59     PetscInt     dof,cdof;
60     *offset = s->atlasOff[point - s->pStart];
61     dof     = s->atlasDof[point - s->pStart];
62     cdof    = s->bc ? s->bc->atlasDof[point - s->bc->pStart] : 0;
63     if (dof-cdof <= 0) *offset = -1;
64   }
65 #endif
66   PetscFunctionReturn(0);
67 }
68 
69 #undef __FUNCT__
70 #define __FUNCT__ "DMPlexGetGlobalFieldOffset_Private"
71 PETSC_STATIC_INLINE PetscErrorCode DMPlexGetGlobalFieldOffset_Private(DM dm,PetscInt point,PetscInt field,PetscInt *offset)
72 {
73   PetscFunctionBegin;
74 #if defined(PETSC_USE_DEBUG)
75   {
76     PetscErrorCode ierr;
77     PetscInt       loff,lfoff,dof,cdof;
78     ierr = PetscSectionGetOffset(dm->defaultGlobalSection,point,offset);CHKERRQ(ierr);
79     ierr = PetscSectionGetOffset(dm->defaultSection,point,&loff);CHKERRQ(ierr);
80     ierr = PetscSectionGetFieldOffset(dm->defaultSection,point,field,&lfoff);CHKERRQ(ierr);
81     ierr = PetscSectionGetFieldDof(dm->defaultSection,point,field,&dof);CHKERRQ(ierr);
82     ierr = PetscSectionGetFieldConstraintDof(dm->defaultSection,point,field,&cdof);CHKERRQ(ierr);
83     *offset += lfoff - loff;
84     if (dof-cdof <= 0) *offset = -1; /* Indicates no data */
85   }
86 #else
87   {
88     1/0;
89     PetscSection s = dm->defaultGlobalSection->field[field];
90     PetscInt     dof,cdof;
91     *offset = s->atlasOff[point - s->pStart];
92     dof     = s->atlasDof[point - s->pStart];
93     cdof    = s->bc ? s->bc->atlasDof[point - s->bc->pStart] : 0;
94     if (dof-cdof <= 0) *offset = -1;
95   }
96 #endif
97   PetscFunctionReturn(0);
98 }
99 
100 #undef __FUNCT__
101 #define __FUNCT__ "DMPlexGetPointLocal"
102 /*@
103    DMPlexGetPointLocal - get location of point data in local Vec
104 
105    Not Collective
106 
107    Input Arguments:
108 +  dm - DM defining the topological space
109 -  point - topological point
110 
111    Output Arguments:
112 +  start - start of point data
113 -  end - end of point data
114 
115    Level: intermediate
116 
117 .seealso: DMGetDefaultSection(), PetscSectionGetOffset(), PetscSectionGetDof(), DMPlexPointLocalRead(), DMPlexPointLocalRead(), DMPlexPointLocalRef()
118 @*/
119 PetscErrorCode DMPlexGetPointLocal(DM dm,PetscInt point,PetscInt *start,PetscInt *end)
120 {
121   PetscErrorCode ierr;
122   PetscInt       offset,dof;
123 
124   PetscFunctionBegin;
125   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
126   ierr = PetscSectionGetOffset(dm->defaultSection,point,&offset);CHKERRQ(ierr);
127   ierr = PetscSectionGetDof(dm->defaultSection,point,&dof);CHKERRQ(ierr);
128   if (start) *start = offset;
129   if (end) *end = offset + dof;
130   PetscFunctionReturn(0);
131 }
132 
133 #undef __FUNCT__
134 #define __FUNCT__ "DMPlexPointLocalRead"
135 /*@
136    DMPlexPointLocalRead - return read access to a point in local array
137 
138    Not Collective
139 
140    Input Arguments:
141 +  dm - DM defining topological space
142 .  point - topological point
143 -  array - array to index into
144 
145    Output Arguments:
146 .  ptr - address of read reference to point data, type generic so user can place in structure
147 
148    Level: intermediate
149 
150    Note:
151    A common usage when data sizes are known statically:
152 
153 $  const struct { PetscScalar foo,bar,baz; } *ptr;
154 $  DMPlexPointLocalRead(dm,point,array,&ptr);
155 $  x = 2*ptr->foo + 3*ptr->bar + 5*ptr->baz;
156 
157 .seealso: DMGetDefaultSection(), PetscSectionGetOffset(), PetscSectionGetDof(), DMPlexGetPointLocal(), DMPlexPointGlobalRead()
158 @*/
159 PetscErrorCode DMPlexPointLocalRead(DM dm,PetscInt point,const PetscScalar *array,const void *ptr)
160 {
161   PetscErrorCode ierr;
162   PetscInt       start;
163 
164   PetscFunctionBegin;
165   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
166   PetscValidScalarPointer(array,3);
167   PetscValidPointer(ptr,4);
168   ierr                      = DMPlexGetLocalOffset_Private(dm,point,&start);CHKERRQ(ierr);
169   *(const PetscScalar**)ptr = array + start;
170   PetscFunctionReturn(0);
171 }
172 
173 #undef __FUNCT__
174 #define __FUNCT__ "DMPlexPointLocalRef"
175 /*@
176    DMPlexPointLocalRef - return read/write access to a point in local array
177 
178    Not Collective
179 
180    Input Arguments:
181 +  dm - DM defining topological space
182 .  point - topological point
183 -  array - array to index into
184 
185    Output Arguments:
186 .  ptr - address of reference to point data, type generic so user can place in structure
187 
188    Level: intermediate
189 
190    Note:
191    A common usage when data sizes are known statically:
192 
193 $  struct { PetscScalar foo,bar,baz; } *ptr;
194 $  DMPlexPointLocalRef(dm,point,array,&ptr);
195 $  ptr->foo = 2; ptr->bar = 3; ptr->baz = 5;
196 
197 .seealso: DMGetDefaultSection(), PetscSectionGetOffset(), PetscSectionGetDof(), DMPlexGetPointLocal(), DMPlexPointGlobalRef()
198 @*/
199 PetscErrorCode DMPlexPointLocalRef(DM dm,PetscInt point,PetscScalar *array,void *ptr)
200 {
201   PetscErrorCode ierr;
202   PetscInt       start;
203 
204   PetscFunctionBegin;
205   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
206   PetscValidScalarPointer(array,3);
207   PetscValidPointer(ptr,4);
208   ierr                = DMPlexGetLocalOffset_Private(dm,point,&start);CHKERRQ(ierr);
209   *(PetscScalar**)ptr = array + start;
210   PetscFunctionReturn(0);
211 }
212 
213 #undef __FUNCT__
214 #define __FUNCT__ "DMPlexPointLocalFieldRead"
215 /*@
216    DMPlexPointLocalFieldRead - return read access to a field on a point in local array
217 
218    Not Collective
219 
220    Input Arguments:
221 +  dm - DM defining topological space
222 .  point - topological point
223 .  field - field number
224 -  array - array to index into
225 
226    Output Arguments:
227 .  ptr - address of read reference to point data, type generic so user can place in structure
228 
229    Level: intermediate
230 
231 .seealso: DMGetDefaultSection(), PetscSectionGetOffset(), PetscSectionGetDof(), DMPlexGetPointLocal(), DMPlexPointGlobalRef()
232 @*/
233 PetscErrorCode DMPlexPointLocalFieldRead(DM dm,PetscInt point,PetscInt field,const PetscScalar *array,const void *ptr)
234 {
235   PetscErrorCode ierr;
236   PetscInt       start;
237 
238   PetscFunctionBegin;
239   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
240   PetscValidScalarPointer(array,3);
241   PetscValidPointer(ptr,4);
242   ierr                      = DMPlexGetLocalFieldOffset_Private(dm,point,field,&start);CHKERRQ(ierr);
243   *(const PetscScalar**)ptr = array + start;
244   PetscFunctionReturn(0);
245 }
246 
247 #undef __FUNCT__
248 #define __FUNCT__ "DMPlexPointLocalFieldRef"
249 /*@
250    DMPlexPointLocalFieldRef - return read/write access to a field on a point in local array
251 
252    Not Collective
253 
254    Input Arguments:
255 +  dm - DM defining topological space
256 .  point - topological point
257 .  field - field number
258 -  array - array to index into
259 
260    Output Arguments:
261 .  ptr - address of reference to point data, type generic so user can place in structure
262 
263    Level: intermediate
264 
265 .seealso: DMGetDefaultSection(), PetscSectionGetOffset(), PetscSectionGetDof(), DMPlexGetPointLocal(), DMPlexPointGlobalRef()
266 @*/
267 PetscErrorCode DMPlexPointLocalFieldRef(DM dm,PetscInt point,PetscInt field,PetscScalar *array,void *ptr)
268 {
269   PetscErrorCode ierr;
270   PetscInt       start;
271 
272   PetscFunctionBegin;
273   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
274   PetscValidScalarPointer(array,3);
275   PetscValidPointer(ptr,4);
276   ierr                = DMPlexGetLocalFieldOffset_Private(dm,point,field,&start);CHKERRQ(ierr);
277   *(PetscScalar**)ptr = array + start;
278   PetscFunctionReturn(0);
279 }
280 
281 #undef __FUNCT__
282 #define __FUNCT__ "DMPlexGetPointGlobal"
283 /*@
284    DMPlexGetPointGlobal - get location of point data in global Vec
285 
286    Not Collective
287 
288    Input Arguments:
289 +  dm - DM defining the topological space
290 -  point - topological point
291 
292    Output Arguments:
293 +  start - start of point data; returns -(global_start+1) if point is not owned
294 -  end - end of point data; returns -(global_end+1) if point is not owned
295 
296    Level: intermediate
297 
298 .seealso: DMGetDefaultSection(), PetscSectionGetOffset(), PetscSectionGetDof(), DMPlexPointGlobalRead(), DMPlexGetPointLocal(), DMPlexPointGlobalRead(), DMPlexPointGlobalRef()
299 @*/
300 PetscErrorCode DMPlexGetPointGlobal(DM dm,PetscInt point,PetscInt *start,PetscInt *end)
301 {
302   PetscErrorCode ierr;
303   PetscInt       offset,dof;
304 
305   PetscFunctionBegin;
306   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
307   ierr = PetscSectionGetOffset(dm->defaultGlobalSection,point,&offset);CHKERRQ(ierr);
308   ierr = PetscSectionGetDof(dm->defaultGlobalSection,point,&dof);CHKERRQ(ierr);
309   if (start) *start = offset;
310   if (end) *end = offset + dof;
311   PetscFunctionReturn(0);
312 }
313 
314 #undef __FUNCT__
315 #define __FUNCT__ "DMPlexPointGlobalRead"
316 /*@
317    DMPlexPointGlobalRead - return read access to a point in global array
318 
319    Not Collective
320 
321    Input Arguments:
322 +  dm - DM defining topological space
323 .  point - topological point
324 -  array - array to index into
325 
326    Output Arguments:
327 .  ptr - address of read reference to point data, type generic so user can place in structure; returns NULL if global point is not owned
328 
329    Level: intermediate
330 
331    Note:
332    A common usage when data sizes are known statically:
333 
334 $  const struct { PetscScalar foo,bar,baz; } *ptr;
335 $  DMPlexPointGlobalRead(dm,point,array,&ptr);
336 $  x = 2*ptr->foo + 3*ptr->bar + 5*ptr->baz;
337 
338 .seealso: DMGetDefaultSection(), PetscSectionGetOffset(), PetscSectionGetDof(), DMPlexGetPointGlobal(), DMPlexPointLocalRead(), DMPlexPointGlobalRef()
339 @*/
340 PetscErrorCode DMPlexPointGlobalRead(DM dm,PetscInt point,const PetscScalar *array,const void *ptr)
341 {
342   PetscErrorCode ierr;
343   PetscInt       start;
344 
345   PetscFunctionBegin;
346   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
347   PetscValidScalarPointer(array,3);
348   PetscValidPointer(ptr,4);
349   ierr                      = DMPlexGetGlobalOffset_Private(dm,point,&start);CHKERRQ(ierr);
350   *(const PetscScalar**)ptr = (start >= 0) ? array + start - dm->map->rstart : NULL;
351   PetscFunctionReturn(0);
352 }
353 
354 #undef __FUNCT__
355 #define __FUNCT__ "DMPlexPointGlobalRef"
356 /*@
357    DMPlexPointGlobalRef - return read/write access to a point in global array
358 
359    Not Collective
360 
361    Input Arguments:
362 +  dm - DM defining topological space
363 .  point - topological point
364 -  array - array to index into
365 
366    Output Arguments:
367 .  ptr - address of reference to point data, type generic so user can place in structure; returns NULL if global point is not owned
368 
369    Level: intermediate
370 
371    Note:
372    A common usage when data sizes are known statically:
373 
374 $  struct { PetscScalar foo,bar,baz; } *ptr;
375 $  DMPlexPointGlobalRef(dm,point,array,&ptr);
376 $  ptr->foo = 2; ptr->bar = 3; ptr->baz = 5;
377 
378 .seealso: DMGetDefaultSection(), PetscSectionGetOffset(), PetscSectionGetDof(), DMPlexGetPointGlobal(), DMPlexPointLocalRef(), DMPlexPointGlobalRead()
379 @*/
380 PetscErrorCode DMPlexPointGlobalRef(DM dm,PetscInt point,PetscScalar *array,void *ptr)
381 {
382   PetscErrorCode ierr;
383   PetscInt       start;
384 
385   PetscFunctionBegin;
386   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
387   PetscValidScalarPointer(array,3);
388   PetscValidPointer(ptr,4);
389   ierr                = DMPlexGetGlobalOffset_Private(dm,point,&start);CHKERRQ(ierr);
390   *(PetscScalar**)ptr = (start >= 0) ? array + start - dm->map->rstart : NULL;
391   PetscFunctionReturn(0);
392 }
393 
394 #undef __FUNCT__
395 #define __FUNCT__ "DMPlexPointGlobalFieldRead"
396 /*@
397    DMPlexPointGlobalFieldRead - return read access to a field on a point in global array
398 
399    Not Collective
400 
401    Input Arguments:
402 +  dm - DM defining topological space
403 .  point - topological point
404 .  field - field number
405 -  array - array to index into
406 
407    Output Arguments:
408 .  ptr - address of read reference to point data, type generic so user can place in structure; returns NULL if global point is not owned
409 
410    Level: intermediate
411 
412 .seealso: DMGetDefaultSection(), PetscSectionGetOffset(), PetscSectionGetDof(), DMPlexGetPointGlobal(), DMPlexPointLocalRead(), DMPlexPointGlobalRef()
413 @*/
414 PetscErrorCode DMPlexPointGlobalFieldRead(DM dm,PetscInt point,PetscInt field,const PetscScalar *array,const void *ptr)
415 {
416   PetscErrorCode ierr;
417   PetscInt       start;
418 
419   PetscFunctionBegin;
420   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
421   PetscValidScalarPointer(array,3);
422   PetscValidPointer(ptr,4);
423   ierr                      = DMPlexGetGlobalFieldOffset_Private(dm,point,field,&start);CHKERRQ(ierr);
424   *(const PetscScalar**)ptr = (start >= 0) ? array + start - dm->map->rstart : NULL;
425   PetscFunctionReturn(0);
426 }
427 
428 #undef __FUNCT__
429 #define __FUNCT__ "DMPlexPointGlobalFieldRef"
430 /*@
431    DMPlexPointGlobalFieldRef - return read/write access to a field on a point in global array
432 
433    Not Collective
434 
435    Input Arguments:
436 +  dm - DM defining topological space
437 .  point - topological point
438 .  field - field number
439 -  array - array to index into
440 
441    Output Arguments:
442 .  ptr - address of reference to point data, type generic so user can place in structure; returns NULL if global point is not owned
443 
444    Level: intermediate
445 
446 .seealso: DMGetDefaultSection(), PetscSectionGetOffset(), PetscSectionGetDof(), DMPlexGetPointGlobal(), DMPlexPointLocalRef(), DMPlexPointGlobalRead()
447 @*/
448 PetscErrorCode DMPlexPointGlobalFieldRef(DM dm,PetscInt point,PetscInt field,PetscScalar *array,void *ptr)
449 {
450   PetscErrorCode ierr;
451   PetscInt       start;
452 
453   PetscFunctionBegin;
454   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
455   PetscValidScalarPointer(array,3);
456   PetscValidPointer(ptr,4);
457   ierr                = DMPlexGetGlobalFieldOffset_Private(dm,point,field,&start);CHKERRQ(ierr);
458   *(PetscScalar**)ptr = (start >= 0) ? array + start - dm->map->rstart : NULL;
459   PetscFunctionReturn(0);
460 }
461