-
Notifications
You must be signed in to change notification settings - Fork 177
/
vsectionis.c
2048 lines (1714 loc) · 70.5 KB
/
vsectionis.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
This file contains routines for basic section object implementation.
*/
#include <petsc-private/isimpl.h> /*I "petscvec.h" I*/
#include <petscsf.h>
#include <petscviewer.h>
PetscClassId PETSC_SECTION_CLASSID;
#undef __FUNCT__
#define __FUNCT__ "PetscSectionCreate"
/*@
PetscSectionCreate - Allocates PetscSection space and sets the map contents to the default.
Collective on MPI_Comm
Input Parameters:
+ comm - the MPI communicator
- s - pointer to the section
Level: developer
Notes: Typical calling sequence
PetscSectionCreate(MPI_Comm,PetscSection *);
PetscSectionSetChart(PetscSection,low,high);
PetscSectionSetDof(PetscSection,point,numdof);
PetscSectionSetUp(PetscSection);
PetscSectionGetOffset(PetscSection,point,PetscInt *);
PetscSectionDestroy(PetscSection);
The PetscSection object and methods are intended to be used in the PETSc Vec and Mat implementions; it is
recommended they not be used in user codes unless you really gain something in their use.
.seealso: PetscSection, PetscSectionDestroy()
@*/
PetscErrorCode PetscSectionCreate(MPI_Comm comm, PetscSection *s)
{
PetscErrorCode ierr;
PetscFunctionBegin;
PetscValidPointer(s,2);
ierr = ISInitializePackage();CHKERRQ(ierr);
ierr = PetscHeaderCreate(*s,_p_PetscSection,int,PETSC_SECTION_CLASSID,"PetscSection","Section","IS",comm,PetscSectionDestroy,PetscSectionView);CHKERRQ(ierr);
(*s)->atlasLayout.comm = comm;
(*s)->atlasLayout.pStart = -1;
(*s)->atlasLayout.pEnd = -1;
(*s)->atlasLayout.numDof = 1;
(*s)->maxDof = 0;
(*s)->atlasDof = NULL;
(*s)->atlasOff = NULL;
(*s)->bc = NULL;
(*s)->bcIndices = NULL;
(*s)->setup = PETSC_FALSE;
(*s)->numFields = 0;
(*s)->fieldNames = NULL;
(*s)->field = NULL;
(*s)->clObj = NULL;
(*s)->clSection = NULL;
(*s)->clPoints = NULL;
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "PetscSectionClone"
/*@
PetscSectionClone - Creates a shallow (if possible) copy of the PetscSection
Collective on MPI_Comm
Input Parameter:
. section - the PetscSection
Output Parameter:
. newSection - the copy
Level: developer
.seealso: PetscSection, PetscSectionCreate(), PetscSectionDestroy()
@*/
PetscErrorCode PetscSectionClone(PetscSection section, PetscSection *newSection)
{
PetscInt numFields, f, pStart, pEnd, p;
PetscErrorCode ierr;
PetscFunctionBegin;
ierr = PetscSectionCreate(section->atlasLayout.comm, newSection);CHKERRQ(ierr);
ierr = PetscSectionGetNumFields(section, &numFields);CHKERRQ(ierr);
if (numFields) {ierr = PetscSectionSetNumFields(*newSection, numFields);CHKERRQ(ierr);}
for (f = 0; f < numFields; ++f) {
const char *name = NULL;
PetscInt numComp = 0;
ierr = PetscSectionGetFieldName(section, f, &name);CHKERRQ(ierr);
ierr = PetscSectionSetFieldName(*newSection, f, name);CHKERRQ(ierr);
ierr = PetscSectionGetFieldComponents(section, f, &numComp);CHKERRQ(ierr);
ierr = PetscSectionSetFieldComponents(*newSection, f, numComp);CHKERRQ(ierr);
}
ierr = PetscSectionGetChart(section, &pStart, &pEnd);CHKERRQ(ierr);
ierr = PetscSectionSetChart(*newSection, pStart, pEnd);CHKERRQ(ierr);
for (p = pStart; p < pEnd; ++p) {
PetscInt dof, cdof, fcdof = 0;
ierr = PetscSectionGetDof(section, p, &dof);CHKERRQ(ierr);
ierr = PetscSectionSetDof(*newSection, p, dof);CHKERRQ(ierr);
ierr = PetscSectionGetConstraintDof(section, p, &cdof);CHKERRQ(ierr);
if (cdof) {ierr = PetscSectionSetConstraintDof(*newSection, p, cdof);CHKERRQ(ierr);}
for (f = 0; f < numFields; ++f) {
ierr = PetscSectionGetFieldDof(section, p, f, &dof);CHKERRQ(ierr);
ierr = PetscSectionSetFieldDof(*newSection, p, f, dof);CHKERRQ(ierr);
if (cdof) {
ierr = PetscSectionGetFieldConstraintDof(section, p, f, &fcdof);CHKERRQ(ierr);
if (fcdof) {ierr = PetscSectionSetFieldConstraintDof(*newSection, p, f, fcdof);CHKERRQ(ierr);}
}
}
}
ierr = PetscSectionSetUp(*newSection);CHKERRQ(ierr);
for (p = pStart; p < pEnd; ++p) {
PetscInt off, cdof, fcdof = 0;
const PetscInt *cInd;
/* Must set offsets in case they do not agree with the prefix sums */
ierr = PetscSectionGetOffset(section, p, &off);CHKERRQ(ierr);
ierr = PetscSectionSetOffset(*newSection, p, off);CHKERRQ(ierr);
ierr = PetscSectionGetConstraintDof(section, p, &cdof);CHKERRQ(ierr);
if (cdof) {
ierr = PetscSectionGetConstraintIndices(section, p, &cInd);CHKERRQ(ierr);
ierr = PetscSectionSetConstraintIndices(*newSection, p, cInd);CHKERRQ(ierr);
for (f = 0; f < numFields; ++f) {
ierr = PetscSectionGetFieldConstraintDof(section, p, f, &fcdof);CHKERRQ(ierr);
if (fcdof) {
ierr = PetscSectionGetFieldConstraintIndices(section, p, f, &cInd);CHKERRQ(ierr);
ierr = PetscSectionSetFieldConstraintIndices(*newSection, p, f, cInd);CHKERRQ(ierr);
}
}
}
}
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "PetscSectionGetNumFields"
/*@
PetscSectionGetNumFields - Returns the number of fields, or 0 if no fields were defined.
Not collective
Input Parameter:
. s - the PetscSection
Output Parameter:
. numFields - the number of fields defined, or 0 if none were defined
Level: intermediate
.seealso: PetscSectionSetNumFields()
@*/
PetscErrorCode PetscSectionGetNumFields(PetscSection s, PetscInt *numFields)
{
PetscFunctionBegin;
PetscValidPointer(numFields,2);
*numFields = s->numFields;
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "PetscSectionSetNumFields"
/*@
PetscSectionSetNumFields - Sets the number of fields.
Not collective
Input Parameters:
+ s - the PetscSection
- numFields - the number of fields
Level: intermediate
.seealso: PetscSectionGetNumFields()
@*/
PetscErrorCode PetscSectionSetNumFields(PetscSection s, PetscInt numFields)
{
PetscInt f;
PetscErrorCode ierr;
PetscFunctionBegin;
if (numFields <= 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "The number of fields %d must be positive", numFields);
ierr = PetscSectionReset(s);CHKERRQ(ierr);
s->numFields = numFields;
ierr = PetscMalloc1(s->numFields, &s->numFieldComponents);CHKERRQ(ierr);
ierr = PetscMalloc1(s->numFields, &s->fieldNames);CHKERRQ(ierr);
ierr = PetscMalloc1(s->numFields, &s->field);CHKERRQ(ierr);
for (f = 0; f < s->numFields; ++f) {
char name[64];
s->numFieldComponents[f] = 1;
ierr = PetscSectionCreate(s->atlasLayout.comm, &s->field[f]);CHKERRQ(ierr);
ierr = PetscSNPrintf(name, 64, "Field_%D", f);CHKERRQ(ierr);
ierr = PetscStrallocpy(name, (char **) &s->fieldNames[f]);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "PetscSectionGetFieldName"
/*@C
PetscSectionGetFieldName - Returns the name of a field in the PetscSection
Not Collective
Input Parameters:
+ s - the PetscSection
- field - the field number
Output Parameter:
. fieldName - the field name
Level: developer
.seealso: PetscSectionSetFieldName()
@*/
PetscErrorCode PetscSectionGetFieldName(PetscSection s, PetscInt field, const char *fieldName[])
{
PetscFunctionBegin;
PetscValidPointer(fieldName,2);
if ((field < 0) || (field >= s->numFields)) SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Section field %d should be in [%d, %d)", field, 0, s->numFields);
*fieldName = s->fieldNames[field];
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "PetscSectionSetFieldName"
/*@C
PetscSectionSetFieldName - Sets the name of a field in the PetscSection
Not Collective
Input Parameters:
+ s - the PetscSection
. field - the field number
- fieldName - the field name
Level: developer
.seealso: PetscSectionGetFieldName()
@*/
PetscErrorCode PetscSectionSetFieldName(PetscSection s, PetscInt field, const char fieldName[])
{
PetscErrorCode ierr;
PetscFunctionBegin;
PetscValidCharPointer(fieldName,3);
if ((field < 0) || (field >= s->numFields)) SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Section field %d should be in [%d, %d)", field, 0, s->numFields);
ierr = PetscFree(s->fieldNames[field]);CHKERRQ(ierr);
ierr = PetscStrallocpy(fieldName, (char**) &s->fieldNames[field]);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "PetscSectionGetFieldComponents"
/*@
PetscSectionGetFieldComponents - Returns the number of field components for the given field.
Not collective
Input Parameters:
+ s - the PetscSection
- field - the field number
Output Parameter:
. numComp - the number of field components
Level: intermediate
.seealso: PetscSectionSetNumFieldComponents(), PetscSectionGetNumFields()
@*/
PetscErrorCode PetscSectionGetFieldComponents(PetscSection s, PetscInt field, PetscInt *numComp)
{
PetscFunctionBegin;
PetscValidPointer(numComp,2);
if ((field < 0) || (field >= s->numFields)) SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Section field %d should be in [%d, %d)", field, 0, s->numFields);
*numComp = s->numFieldComponents[field];
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "PetscSectionSetFieldComponents"
/*@
PetscSectionSetFieldComponents - Sets the number of field components for the given field.
Not collective
Input Parameters:
+ s - the PetscSection
. field - the field number
- numComp - the number of field components
Level: intermediate
.seealso: PetscSectionGetNumFieldComponents(), PetscSectionGetNumFields()
@*/
PetscErrorCode PetscSectionSetFieldComponents(PetscSection s, PetscInt field, PetscInt numComp)
{
PetscFunctionBegin;
if ((field < 0) || (field >= s->numFields)) SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Section field %d should be in [%d, %d)", field, 0, s->numFields);
s->numFieldComponents[field] = numComp;
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "PetscSectionCheckConstraints"
PetscErrorCode PetscSectionCheckConstraints(PetscSection s)
{
PetscErrorCode ierr;
PetscFunctionBegin;
if (!s->bc) {
ierr = PetscSectionCreate(PETSC_COMM_SELF, &s->bc);CHKERRQ(ierr);
ierr = PetscSectionSetChart(s->bc, s->atlasLayout.pStart, s->atlasLayout.pEnd);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "PetscSectionGetChart"
/*@
PetscSectionGetChart - Returns the range [pStart, pEnd) in which points in the lie.
Not collective
Input Parameter:
. s - the PetscSection
Output Parameters:
+ pStart - the first point
- pEnd - one past the last point
Level: intermediate
.seealso: PetscSectionSetChart(), PetscSectionCreate()
@*/
PetscErrorCode PetscSectionGetChart(PetscSection s, PetscInt *pStart, PetscInt *pEnd)
{
PetscFunctionBegin;
if (pStart) *pStart = s->atlasLayout.pStart;
if (pEnd) *pEnd = s->atlasLayout.pEnd;
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "PetscSectionSetChart"
/*@
PetscSectionSetChart - Sets the range [pStart, pEnd) in which points in the lie.
Not collective
Input Parameters:
+ s - the PetscSection
. pStart - the first point
- pEnd - one past the last point
Level: intermediate
.seealso: PetscSectionSetChart(), PetscSectionCreate()
@*/
PetscErrorCode PetscSectionSetChart(PetscSection s, PetscInt pStart, PetscInt pEnd)
{
PetscInt f;
PetscErrorCode ierr;
PetscFunctionBegin;
/* Cannot Reset() because it destroys field information */
s->setup = PETSC_FALSE;
ierr = PetscSectionDestroy(&s->bc);CHKERRQ(ierr);
ierr = PetscFree(s->bcIndices);CHKERRQ(ierr);
ierr = PetscFree2(s->atlasDof, s->atlasOff);CHKERRQ(ierr);
s->atlasLayout.pStart = pStart;
s->atlasLayout.pEnd = pEnd;
ierr = PetscMalloc2((pEnd - pStart), &s->atlasDof, (pEnd - pStart), &s->atlasOff);CHKERRQ(ierr);
ierr = PetscMemzero(s->atlasDof, (pEnd - pStart)*sizeof(PetscInt));CHKERRQ(ierr);
for (f = 0; f < s->numFields; ++f) {
ierr = PetscSectionSetChart(s->field[f], pStart, pEnd);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "PetscSectionGetDof"
/*@
PetscSectionGetDof - Return the number of degrees of freedom associated with a given point.
Not collective
Input Parameters:
+ s - the PetscSection
- point - the point
Output Parameter:
. numDof - the number of dof
Level: intermediate
.seealso: PetscSectionSetDof(), PetscSectionCreate()
@*/
PetscErrorCode PetscSectionGetDof(PetscSection s, PetscInt point, PetscInt *numDof)
{
PetscFunctionBegin;
#if defined(PETSC_USE_DEBUG)
if ((point < s->atlasLayout.pStart) || (point >= s->atlasLayout.pEnd)) SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Section point %d should be in [%d, %d)", point, s->atlasLayout.pStart, s->atlasLayout.pEnd);
#endif
*numDof = s->atlasDof[point - s->atlasLayout.pStart];
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "PetscSectionSetDof"
/*@
PetscSectionSetDof - Sets the number of degrees of freedom associated with a given point.
Not collective
Input Parameters:
+ s - the PetscSection
. point - the point
- numDof - the number of dof
Level: intermediate
.seealso: PetscSectionGetDof(), PetscSectionAddDof(), PetscSectionCreate()
@*/
PetscErrorCode PetscSectionSetDof(PetscSection s, PetscInt point, PetscInt numDof)
{
PetscFunctionBegin;
if ((point < s->atlasLayout.pStart) || (point >= s->atlasLayout.pEnd)) SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Section point %d should be in [%d, %d)", point, s->atlasLayout.pStart, s->atlasLayout.pEnd);
s->atlasDof[point - s->atlasLayout.pStart] = numDof;
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "PetscSectionAddDof"
/*@
PetscSectionAddDof - Adds to the number of degrees of freedom associated with a given point.
Not collective
Input Parameters:
+ s - the PetscSection
. point - the point
- numDof - the number of additional dof
Level: intermediate
.seealso: PetscSectionGetDof(), PetscSectionSetDof(), PetscSectionCreate()
@*/
PetscErrorCode PetscSectionAddDof(PetscSection s, PetscInt point, PetscInt numDof)
{
PetscFunctionBegin;
if ((point < s->atlasLayout.pStart) || (point >= s->atlasLayout.pEnd)) SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Section point %d should be in [%d, %d)", point, s->atlasLayout.pStart, s->atlasLayout.pEnd);
s->atlasDof[point - s->atlasLayout.pStart] += numDof;
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "PetscSectionGetFieldDof"
/*@
PetscSectionGetFieldDof - Return the number of degrees of freedom associated with a field on a given point.
Not collective
Input Parameters:
+ s - the PetscSection
. point - the point
- field - the field
Output Parameter:
. numDof - the number of dof
Level: intermediate
.seealso: PetscSectionSetFieldDof(), PetscSectionCreate()
@*/
PetscErrorCode PetscSectionGetFieldDof(PetscSection s, PetscInt point, PetscInt field, PetscInt *numDof)
{
PetscErrorCode ierr;
PetscFunctionBegin;
if ((field < 0) || (field >= s->numFields)) SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Section field %d should be in [%d, %d)", field, 0, s->numFields);
ierr = PetscSectionGetDof(s->field[field], point, numDof);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "PetscSectionSetFieldDof"
/*@
PetscSectionSetFieldDof - Sets the number of degrees of freedom associated with a field on a given point.
Not collective
Input Parameters:
+ s - the PetscSection
. point - the point
. field - the field
- numDof - the number of dof
Level: intermediate
.seealso: PetscSectionGetFieldDof(), PetscSectionCreate()
@*/
PetscErrorCode PetscSectionSetFieldDof(PetscSection s, PetscInt point, PetscInt field, PetscInt numDof)
{
PetscErrorCode ierr;
PetscFunctionBegin;
if ((field < 0) || (field >= s->numFields)) SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Section field %d should be in [%d, %d)", field, 0, s->numFields);
ierr = PetscSectionSetDof(s->field[field], point, numDof);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "PetscSectionAddFieldDof"
/*@
PetscSectionAddFieldDof - Adds a number of degrees of freedom associated with a field on a given point.
Not collective
Input Parameters:
+ s - the PetscSection
. point - the point
. field - the field
- numDof - the number of dof
Level: intermediate
.seealso: PetscSectionSetFieldDof(), PetscSectionGetFieldDof(), PetscSectionCreate()
@*/
PetscErrorCode PetscSectionAddFieldDof(PetscSection s, PetscInt point, PetscInt field, PetscInt numDof)
{
PetscErrorCode ierr;
PetscFunctionBegin;
if ((field < 0) || (field >= s->numFields)) SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Section field %d should be in [%d, %d)", field, 0, s->numFields);
ierr = PetscSectionAddDof(s->field[field], point, numDof);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "PetscSectionGetConstraintDof"
/*@
PetscSectionGetConstraintDof - Return the number of constrained degrees of freedom associated with a given point.
Not collective
Input Parameters:
+ s - the PetscSection
- point - the point
Output Parameter:
. numDof - the number of dof which are fixed by constraints
Level: intermediate
.seealso: PetscSectionGetDof(), PetscSectionSetConstraintDof(), PetscSectionCreate()
@*/
PetscErrorCode PetscSectionGetConstraintDof(PetscSection s, PetscInt point, PetscInt *numDof)
{
PetscErrorCode ierr;
PetscFunctionBegin;
if (s->bc) {
ierr = PetscSectionGetDof(s->bc, point, numDof);CHKERRQ(ierr);
} else *numDof = 0;
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "PetscSectionSetConstraintDof"
/*@
PetscSectionSetConstraintDof - Set the number of constrained degrees of freedom associated with a given point.
Not collective
Input Parameters:
+ s - the PetscSection
. point - the point
- numDof - the number of dof which are fixed by constraints
Level: intermediate
.seealso: PetscSectionSetDof(), PetscSectionGetConstraintDof(), PetscSectionCreate()
@*/
PetscErrorCode PetscSectionSetConstraintDof(PetscSection s, PetscInt point, PetscInt numDof)
{
PetscErrorCode ierr;
PetscFunctionBegin;
if (numDof) {
ierr = PetscSectionCheckConstraints(s);CHKERRQ(ierr);
ierr = PetscSectionSetDof(s->bc, point, numDof);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "PetscSectionAddConstraintDof"
/*@
PetscSectionAddConstraintDof - Increment the number of constrained degrees of freedom associated with a given point.
Not collective
Input Parameters:
+ s - the PetscSection
. point - the point
- numDof - the number of additional dof which are fixed by constraints
Level: intermediate
.seealso: PetscSectionAddDof(), PetscSectionGetConstraintDof(), PetscSectionCreate()
@*/
PetscErrorCode PetscSectionAddConstraintDof(PetscSection s, PetscInt point, PetscInt numDof)
{
PetscErrorCode ierr;
PetscFunctionBegin;
if (numDof) {
ierr = PetscSectionCheckConstraints(s);CHKERRQ(ierr);
ierr = PetscSectionAddDof(s->bc, point, numDof);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "PetscSectionGetFieldConstraintDof"
/*@
PetscSectionGetFieldConstraintDof - Return the number of constrained degrees of freedom associated with a given field on a point.
Not collective
Input Parameters:
+ s - the PetscSection
. point - the point
- field - the field
Output Parameter:
. numDof - the number of dof which are fixed by constraints
Level: intermediate
.seealso: PetscSectionGetDof(), PetscSectionSetFieldConstraintDof(), PetscSectionCreate()
@*/
PetscErrorCode PetscSectionGetFieldConstraintDof(PetscSection s, PetscInt point, PetscInt field, PetscInt *numDof)
{
PetscErrorCode ierr;
PetscFunctionBegin;
if ((field < 0) || (field >= s->numFields)) SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Section field %d should be in [%d, %d)", field, 0, s->numFields);
ierr = PetscSectionGetConstraintDof(s->field[field], point, numDof);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "PetscSectionSetFieldConstraintDof"
/*@
PetscSectionSetFieldConstraintDof - Set the number of constrained degrees of freedom associated with a given field on a point.
Not collective
Input Parameters:
+ s - the PetscSection
. point - the point
. field - the field
- numDof - the number of dof which are fixed by constraints
Level: intermediate
.seealso: PetscSectionSetDof(), PetscSectionGetFieldConstraintDof(), PetscSectionCreate()
@*/
PetscErrorCode PetscSectionSetFieldConstraintDof(PetscSection s, PetscInt point, PetscInt field, PetscInt numDof)
{
PetscErrorCode ierr;
PetscFunctionBegin;
if ((field < 0) || (field >= s->numFields)) SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Section field %d should be in [%d, %d)", field, 0, s->numFields);
ierr = PetscSectionSetConstraintDof(s->field[field], point, numDof);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "PetscSectionAddFieldConstraintDof"
/*@
PetscSectionAddFieldConstraintDof - Increment the number of constrained degrees of freedom associated with a given field on a point.
Not collective
Input Parameters:
+ s - the PetscSection
. point - the point
. field - the field
- numDof - the number of additional dof which are fixed by constraints
Level: intermediate
.seealso: PetscSectionAddDof(), PetscSectionGetFieldConstraintDof(), PetscSectionCreate()
@*/
PetscErrorCode PetscSectionAddFieldConstraintDof(PetscSection s, PetscInt point, PetscInt field, PetscInt numDof)
{
PetscErrorCode ierr;
PetscFunctionBegin;
if ((field < 0) || (field >= s->numFields)) SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Section field %d should be in [%d, %d)", field, 0, s->numFields);
ierr = PetscSectionAddConstraintDof(s->field[field], point, numDof);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "PetscSectionSetUpBC"
PetscErrorCode PetscSectionSetUpBC(PetscSection s)
{
PetscErrorCode ierr;
PetscFunctionBegin;
if (s->bc) {
const PetscInt last = (s->bc->atlasLayout.pEnd-s->bc->atlasLayout.pStart) - 1;
ierr = PetscSectionSetUp(s->bc);CHKERRQ(ierr);
ierr = PetscMalloc1((s->bc->atlasOff[last] + s->bc->atlasDof[last]), &s->bcIndices);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "PetscSectionSetUp"
/*@
PetscSectionSetUp - Calculate offsets based upon the number of degrees of freedom for each point.
Not collective
Input Parameter:
. s - the PetscSection
Level: intermediate
.seealso: PetscSectionCreate()
@*/
PetscErrorCode PetscSectionSetUp(PetscSection s)
{
PetscInt offset = 0, p, f;
PetscErrorCode ierr;
PetscFunctionBegin;
if (s->setup) PetscFunctionReturn(0);
s->setup = PETSC_TRUE;
for (p = 0; p < s->atlasLayout.pEnd - s->atlasLayout.pStart; ++p) {
s->atlasOff[p] = offset;
offset += s->atlasDof[p];
s->maxDof = PetscMax(s->maxDof, s->atlasDof[p]);
}
ierr = PetscSectionSetUpBC(s);CHKERRQ(ierr);
/* Assume that all fields have the same chart */
for (p = 0; p < s->atlasLayout.pEnd - s->atlasLayout.pStart; ++p) {
PetscInt off = s->atlasOff[p];
for (f = 0; f < s->numFields; ++f) {
PetscSection sf = s->field[f];
sf->atlasOff[p] = off;
off += sf->atlasDof[p];
}
}
for (f = 0; f < s->numFields; ++f) {
ierr = PetscSectionSetUpBC(s->field[f]);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "PetscSectionGetMaxDof"
/*@
PetscSectionGetMaxDof - Return the maximum number of degrees of freedom on any point in the chart
Not collective
Input Parameters:
. s - the PetscSection
Output Parameter:
. maxDof - the maximum dof
Level: intermediate
.seealso: PetscSectionGetDof(), PetscSectionSetDof(), PetscSectionCreate()
@*/
PetscErrorCode PetscSectionGetMaxDof(PetscSection s, PetscInt *maxDof)
{
PetscFunctionBegin;
*maxDof = s->maxDof;
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "PetscSectionGetStorageSize"
/*@
PetscSectionGetStorageSize - Return the size of an array or local Vec capable of holding all the degrees of freedom.
Not collective
Input Parameters:
+ s - the PetscSection
- point - the point
Output Parameter:
. size - the size of an array which can hold all the dofs
Level: intermediate
.seealso: PetscSectionGetOffset(), PetscSectionCreate()
@*/
PetscErrorCode PetscSectionGetStorageSize(PetscSection s, PetscInt *size)
{
PetscInt p, n = 0;
PetscFunctionBegin;
for (p = 0; p < s->atlasLayout.pEnd - s->atlasLayout.pStart; ++p) n += s->atlasDof[p] > 0 ? s->atlasDof[p] : 0;
*size = n;
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "PetscSectionGetConstrainedStorageSize"
PetscErrorCode PetscSectionGetConstrainedStorageSize(PetscSection s, PetscInt *size)
{
PetscInt p, n = 0;
PetscFunctionBegin;
for (p = 0; p < s->atlasLayout.pEnd - s->atlasLayout.pStart; ++p) {
const PetscInt cdof = s->bc ? s->bc->atlasDof[p] : 0;
n += s->atlasDof[p] > 0 ? s->atlasDof[p] - cdof : 0;
}
*size = n;
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "PetscSectionCreateGlobalSection"
/*@
PetscSectionCreateGlobalSection - Create a section describing the global field layout using
the local section and an SF describing the section point overlap.
Input Parameters:
+ s - The PetscSection for the local field layout
. sf - The SF describing parallel layout of the section points (leaves are unowned local points)
- includeConstraints - By default this is PETSC_FALSE, meaning that the global field vector will not possess constrained dofs
Output Parameter:
. gsection - The PetscSection for the global field layout
Note: This gives negative sizes and offsets to points not owned by this process
Level: developer
.seealso: PetscSectionCreate()
@*/
PetscErrorCode PetscSectionCreateGlobalSection(PetscSection s, PetscSF sf, PetscBool includeConstraints, PetscSection *gsection)
{
PetscInt *neg = NULL, *recv = NULL;
PetscInt pStart, pEnd, p, dof, cdof, off, globalOff = 0, nroots, nlocal;
PetscErrorCode ierr;
PetscFunctionBegin;
ierr = PetscSectionCreate(s->atlasLayout.comm, gsection);CHKERRQ(ierr);
ierr = PetscSectionGetChart(s, &pStart, &pEnd);CHKERRQ(ierr);
ierr = PetscSectionSetChart(*gsection, pStart, pEnd);CHKERRQ(ierr);
ierr = PetscSFGetGraph(sf, &nroots, NULL, NULL, NULL);CHKERRQ(ierr);
nlocal = nroots; /* The local/leaf space matches global/root space */
/* Must allocate for all points visible to SF, which may be more than this section */
if (nroots >= 0) { /* nroots < 0 means that the graph has not been set, only happens in serial */
ierr = PetscMalloc2(nroots,&neg,nlocal,&recv);CHKERRQ(ierr);
ierr = PetscMemzero(neg,nroots*sizeof(PetscInt));CHKERRQ(ierr);
}
/* Mark all local points with negative dof */
for (p = pStart; p < pEnd; ++p) {
ierr = PetscSectionGetDof(s, p, &dof);CHKERRQ(ierr);
ierr = PetscSectionSetDof(*gsection, p, dof);CHKERRQ(ierr);
ierr = PetscSectionGetConstraintDof(s, p, &cdof);CHKERRQ(ierr);
if (!includeConstraints && cdof > 0) {ierr = PetscSectionSetConstraintDof(*gsection, p, cdof);CHKERRQ(ierr);}
if (neg) neg[p] = -(dof+1);
}
ierr = PetscSectionSetUpBC(*gsection);CHKERRQ(ierr);
if (nroots >= 0) {
ierr = PetscMemzero(recv,nlocal*sizeof(PetscInt));CHKERRQ(ierr);
ierr = PetscSFBcastBegin(sf, MPIU_INT, neg, recv);CHKERRQ(ierr);
ierr = PetscSFBcastEnd(sf, MPIU_INT, neg, recv);CHKERRQ(ierr);
for (p = pStart; p < pEnd; ++p) {
if (recv[p] < 0) (*gsection)->atlasDof[p-pStart] = recv[p];
}
}
/* Calculate new sizes, get proccess offset, and calculate point offsets */
for (p = 0, off = 0; p < pEnd-pStart; ++p) {
cdof = (!includeConstraints && s->bc) ? s->bc->atlasDof[p] : 0;
(*gsection)->atlasOff[p] = off;
off += (*gsection)->atlasDof[p] > 0 ? (*gsection)->atlasDof[p]-cdof : 0;
}
ierr = MPI_Scan(&off, &globalOff, 1, MPIU_INT, MPI_SUM, s->atlasLayout.comm);CHKERRQ(ierr);
globalOff -= off;
for (p = pStart, off = 0; p < pEnd; ++p) {
(*gsection)->atlasOff[p-pStart] += globalOff;
if (neg) neg[p] = -((*gsection)->atlasOff[p-pStart]+1);
}
/* Put in negative offsets for ghost points */
if (nroots >= 0) {
ierr = PetscMemzero(recv,nlocal*sizeof(PetscInt));CHKERRQ(ierr);
ierr = PetscSFBcastBegin(sf, MPIU_INT, neg, recv);CHKERRQ(ierr);
ierr = PetscSFBcastEnd(sf, MPIU_INT, neg, recv);CHKERRQ(ierr);
for (p = pStart; p < pEnd; ++p) {
if (recv[p] < 0) (*gsection)->atlasOff[p-pStart] = recv[p];
}
}
ierr = PetscFree2(neg,recv);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "PetscSectionCreateGlobalSectionCensored"
/*@
PetscSectionCreateGlobalSectionCensored - Create a section describing the global field layout using
the local section and an SF describing the section point overlap.
Input Parameters:
+ s - The PetscSection for the local field layout
. sf - The SF describing parallel layout of the section points
. includeConstraints - By default this is PETSC_FALSE, meaning that the global field vector will not possess constrained dofs
. numExcludes - The number of exclusion ranges
- excludes - An array [start_0, end_0, start_1, end_1, ...] where there are numExcludes pairs
Output Parameter:
. gsection - The PetscSection for the global field layout
Note: This gives negative sizes and offsets to points not owned by this process
Level: developer
.seealso: PetscSectionCreate()
@*/
PetscErrorCode PetscSectionCreateGlobalSectionCensored(PetscSection s, PetscSF sf, PetscBool includeConstraints, PetscInt numExcludes, const PetscInt excludes[], PetscSection *gsection)
{
PetscInt *neg = NULL, *tmpOff = NULL;
PetscInt pStart, pEnd, p, e, dof, cdof, off, globalOff = 0, nroots;
PetscErrorCode ierr;
PetscFunctionBegin;
ierr = PetscSectionCreate(s->atlasLayout.comm, gsection);CHKERRQ(ierr);
ierr = PetscSectionGetChart(s, &pStart, &pEnd);CHKERRQ(ierr);
ierr = PetscSectionSetChart(*gsection, pStart, pEnd);CHKERRQ(ierr);
ierr = PetscSFGetGraph(sf, &nroots, NULL, NULL, NULL);CHKERRQ(ierr);
if (nroots >= 0) {
if (nroots < pEnd-pStart) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "PetscSF nroots %d < %d section size", nroots, pEnd-pStart);
ierr = PetscCalloc1(nroots, &neg);CHKERRQ(ierr);
if (nroots > pEnd-pStart) {
ierr = PetscCalloc1(nroots, &tmpOff);CHKERRQ(ierr);
} else {
tmpOff = &(*gsection)->atlasDof[-pStart];
}
}
/* Mark ghost points with negative dof */
for (p = pStart; p < pEnd; ++p) {
for (e = 0; e < numExcludes; ++e) {
if ((p >= excludes[e*2+0]) && (p < excludes[e*2+1])) {
ierr = PetscSectionSetDof(*gsection, p, 0);CHKERRQ(ierr);
break;
}
}
if (e < numExcludes) continue;
ierr = PetscSectionGetDof(s, p, &dof);CHKERRQ(ierr);
ierr = PetscSectionSetDof(*gsection, p, dof);CHKERRQ(ierr);
ierr = PetscSectionGetConstraintDof(s, p, &cdof);CHKERRQ(ierr);
if (!includeConstraints && cdof > 0) {ierr = PetscSectionSetConstraintDof(*gsection, p, cdof);CHKERRQ(ierr);}
if (neg) neg[p] = -(dof+1);
}
ierr = PetscSectionSetUpBC(*gsection);CHKERRQ(ierr);
if (nroots >= 0) {
ierr = PetscSFBcastBegin(sf, MPIU_INT, neg, tmpOff);CHKERRQ(ierr);
ierr = PetscSFBcastEnd(sf, MPIU_INT, neg, tmpOff);CHKERRQ(ierr);
if (nroots > pEnd - pStart) {
for (p = pStart; p < pEnd; ++p) {if (tmpOff[p] < 0) (*gsection)->atlasDof[p-pStart] = tmpOff[p];}
}
}
/* Calculate new sizes, get proccess offset, and calculate point offsets */
for (p = 0, off = 0; p < pEnd-pStart; ++p) {
cdof = (!includeConstraints && s->bc) ? s->bc->atlasDof[p] : 0;
(*gsection)->atlasOff[p] = off;
off += (*gsection)->atlasDof[p] > 0 ? (*gsection)->atlasDof[p]-cdof : 0;
}
ierr = MPI_Scan(&off, &globalOff, 1, MPIU_INT, MPI_SUM, s->atlasLayout.comm);CHKERRQ(ierr);
globalOff -= off;
for (p = 0, off = 0; p < pEnd-pStart; ++p) {
(*gsection)->atlasOff[p] += globalOff;