-
Notifications
You must be signed in to change notification settings - Fork 0
/
funcs1.cc~
1257 lines (1003 loc) · 33.9 KB
/
funcs1.cc~
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 is the interface between julia and PUMI
// all functions defined in this file are usable using only standard C data
// types
//
// Every Julia process that calls this function will see its own "copy" of this
// library, having its own fully unique state
// this library is only tested to work on 3d meshes
// for now, this library is intended *only* to iterate over mesh entities in order
// functions (except those that loop over the type named in their declaration)
// do not increment the iterators
#include <iostream>
#include <apf.h>
#include <gmi_mesh.h>
#include <gmi_null.h>
#include <apfMDS.h>
#include <apfMesh2.h>
#include <PCU.h>
#include <apfNumbering.h>
#include <apfShape.h>
#include <ma.h>
#include <stdlib.h> // malloc, free, etc.
#include <math.h>
#include <string.h>
#include "funcs1.h"
#include "adaptFuncsJ.h"
#include "apfSBPShape.h"
#include "apfSBPShape3.h"
//#include "a2.h"
//=============================================================================
//declare global variables (persistent state of library)
apf::Mesh2* m;
apf::FieldShape* mshape;
apf::MeshEntity* entity_global; // token mesh entity used for EntityShape
apf::Numbering* elNums; // element numbering
apf::Numbering* faceNums; // face numbering
apf::Numbering* edgeNums; // edge numbering
apf::Numbering* vertNums; // vertex numbers
bool meshloaded = false; // record whether or not a mesh has been loaded
apf::MeshEntity* e_tmp;
// arrays to hold variables for each entity type
// array[0] = vertex, array[1] = edge, array[2] = face, array[3] = element
apf::MeshIterator* its[4]; // mesh iterators
int numEntity[4]; // number of each type of entity
int numDown[4][4]; // number of downward adjacencies entity i has of type j
// define vertices to have zero
// this assumes only one type of element per mesh
apf::Numbering* numberings[4]; // numberings of each type of entity
// numberings are 1 index (not zero)
apf::MeshTag* globalVertNums; // tag each vertex with global vertex number
const char *names[] = { "vertex", "edge", "face", "element"}; // array of strings, used for printing output inside loops
IsotropicFunctionJ isofunc; // declare isotropic function at global scope
AnisotropicFunctionJ anisofunc; // declare anisotropic function at global scope
// init for 2d mesh
// order = order of shape functions to use
// load_mesh = load mesh from files or not (for reinitilizing after mesh adaptation, do not load from file)
// shape_type: type of shape functions, 0 = lagrange, 1 = SBP
int initABC(char* dmg_name, char* smb_name, int number_entities[4], apf::Mesh2* m_ptr_array[1], apf::FieldShape* mshape_ptr_array[1], int order, int load_mesh, int shape_type )
{
std::cout << "Entered init\n" << std::endl;
// various startup options
// initilize communications if needed
if (!PCU_Comm_Initialized())
{
MPI_Init(0,NULL); // initilize MPI
PCU_Comm_Init(); // initilize PUMI's communication
}
if (load_mesh) // if the user said to load a new mesh
{
if ( meshloaded) // if a mesh has been loaded before
{
std::cout << "Performing cleanup before loading new mesh" << std::endl;
cleanup(m);
}
if (strcmp(dmg_name, ".null") == 0)
{
gmi_register_null();
std::cout << "loading null geometric model" << std::endl;
gmi_model* g = gmi_load(".null");
std::cout << "finished loading geometric model" << std::endl;
m = apf::loadMdsMesh(g, smb_name);
// apf::changeMeshShape(m, apf::getLagrange(2), true);
// apf::changeMeshShape(m, apf::getLagrange(1), false); // for linear meshes
// apf::changeMeshShape(m, apf::getSerendipity(), true);
// apf::changeMeshShape(m, m->getShape(), false);
m->verify();
} else {
gmi_register_mesh();
std::cout << "loading geometric model from file" << std::endl;
m = apf::loadMdsMesh(dmg_name, smb_name);
}
meshloaded = true; // record the fact that a mesh is now loaded
apf::reorderMdsMesh(m);
// apply shape functions to newly loaded mesh
apf::FieldShape* fshape; // variable to hold field shape
if ( shape_type == 0)
{
fshape = apf::getLagrange(order);
} else if ( shape_type == 1) // use SBP shape functions
{
fshape = apf::getSBP3Shape(order);
} else // default to lagrange shape functions
{
std::cout << "Warning: unrecognized shape_type, defaulting to Lagrange" << std::endl;
fshape = apf::getLagrange(order);
}
if ( order == 1)
{
apf::changeMeshShape(m, fshape, false);
} else
{
apf::changeMeshShape(m, fshape, true);
}
std::cout << "finished loading mesh, changing shape" << std::endl;
} else { // if not loading a mesh
destroyNumberings(3); // destroy the numberings before creating new ones
std::cout << "finished destroying numberings of existing mesh" << std::endl;
}
// this should have a new filename everytime
apf::writeVtkFiles("output_check", m);
m_ptr_array[0] = m;
mshape_ptr_array[0] = m->getShape();
its[0] = m->begin(0);
entity_global = m->iterate(its[0]); // get token mesh entity
std::cout << "initilized library global variables" << std::endl;
// initilize number of each type of entity
for (int i = 0; i < 4; ++i)
{
numEntity[i] = apf::countOwned(m, i);
number_entities[i] = numEntity[i];
}
std::cout << "counted number of mesh each type of mesh entities" << std::endl;
// initilize numberings
numberings[0] = numberOwnedDimension(m, "vertNums", 0);
numberings[1] = numberOwnedDimension(m, "edgeNums", 1);
numberings[2] = numberOwnedDimension(m, "faceNums", 2);
numberings[3] = numberOwnedDimension(m, "elNums", 3);
// initilize iterators
its[0] = m->begin(0);
its[1] = m->begin(1);
its[2] = m->begin(2);
its[3] = m->begin(3);
for (int i = 0; i < 4; ++i)
{
int type = m->getType(m->deref(its[i]));
std::cout << "type of its[" << i << "] = " << type;
std::cout << "index its[" << i << "] = " << type << std::endl;
}
std::cout << std::endl;
std::cout << "numV = " << numEntity[0] << " , numEdge = " << numEntity[1];
std::cout << " , numFace = " << numEntity[2] << std::endl;
std::cout << std::endl;
resetFaceIt();
apf::writeVtkFiles("output_init", m);
return 0;
}
// init for 2d mesh
// order = order of shape functions to use
// load_mesh = load mesh from files or not (for reinitilizing after mesh adaptation, do not load from file)
int initABC2(char* dmg_name, char* smb_name, int number_entities[3], apf::Mesh2* m_ptr_array[1], apf::FieldShape* mshape_ptr_array[1], int order, int load_mesh, int shape_type )
{
std::cout << "Entered init2\n" << std::endl;
// various startup options
// initilize communications if needed
if (!PCU_Comm_Initialized())
{
MPI_Init(0,NULL); // initilize MPI
PCU_Comm_Init(); // initilize PUMI's communication
}
if (load_mesh) // if the user said to load a new mesh
{
if ( meshloaded) // if a mesh has been loaded before
{
std::cout << "Performing cleanup before loading new mesh" << std::endl;
cleanup(m);
}
if (strcmp(dmg_name, ".null") == 0)
{
gmi_register_null();
std::cout << "loading null geometric model" << std::endl;
gmi_model* g = gmi_load(".null");
std::cout << "finished loading geometric model" << std::endl;
m = apf::loadMdsMesh(g, smb_name);
// apf::changeMeshShape(m, apf::getLagrange(2), true);
// apf::changeMeshShape(m, apf::getLagrange(1), false); // for linear meshes
// apf::changeMeshShape(m, apf::getSerendipity(), true);
// apf::changeMeshShape(m, m->getShape(), false);
m->verify();
} else {
gmi_register_mesh();
std::cout << "loading geometric model from file" << std::endl;
m = apf::loadMdsMesh(dmg_name, smb_name);
}
meshloaded = true; // record the fact that a mesh is now loaded
apf::reorderMdsMesh(m);
apf::FieldShape* fshape; // variable to hold field shape
bool change_shape = false;
if ( shape_type == 0) // use lagrange
{
fshape = apf::getLagrange(order);
change_shape = true;
} else if ( shape_type == 1) // use SBP shape functions
{
fshape = apf::getSBPShape(order);
change_shape = true;
} else // default to lagrange shape functions
{
std::cout << "Warning: unrecognized shape_type, not changing mesh shape" << std::endl;
fshape = apf::getLagrange(1); // unused, but avoids compiler warning
}
// check if the coordinates have been moved into tags
// this is a result of the mesh shape having been changed previously
apf::MeshTag* coords_tag = m->findTag("coordinates_ver");
if (coords_tag != 0 && change_shape) // if the tag exists
{
apf::changeMeshShape(m, apf::getLagrange(1), false);
}
if (change_shape)
{
if ( order == 1 )
{
apf::changeMeshShape(m, fshape, true);
} else
{
apf::changeMeshShape(m, fshape, true);
}
std::cout << "finished loading mesh, changing shape" << std::endl;
} else
{
std::cout << "finished loading mesh" << std::endl;
}
} else { // if not loading a mesh
destroyNumberings(2); // destroy the numberings before creating new ones
std::cout << "finished destroying numberings of existing mesh" << std::endl;
}
// this should have a new filename everytime
apf::writeVtkFiles("output_check", m);
m_ptr_array[0] = m;
mshape_ptr_array[0] = m->getShape();
its[0] = m->begin(0);
entity_global = m->iterate(its[0]); // get token mesh entity
std::cout << "initilized library global variables" << std::endl;
// initilize number of each type of entity
for (int i = 0; i < 3; ++i)
{
numEntity[i] = apf::countOwned(m, i);
number_entities[i] = numEntity[i];
}
std::cout << "counted number of mesh each type of mesh entities" << std::endl;
/*
// initilize numberings
numberings[0] = numberOwnedDimension(m, "vertNums", 0);
numberings[1] = numberOwnedDimension(m, "edgeNums", 1);
numberings[2] = numberOwnedDimension(m, "faceNums", 2);
// numberings[3] = numberOwnedDimension(m, "elNums", 3);
*/
// create numberings
numberings[0] = apf::createNumbering(m, "vertNums", apf::getConstant(0), 1);
numberings[1] = apf::createNumbering(m, "edgeNums", apf::getConstant(1), 1);
numberings[2] = apf::createNumbering(m, "faceNums", apf::getConstant(2), 1);
std::cout << " finished creating tag field" << std::endl;
// initilize iterators
its[0] = m->begin(0);
its[1] = m->begin(1);
its[2] = m->begin(2);
// its[3] = m->begin(3);
for (int i = 0; i < 3; ++i) // loop over dimensions
{
int curr_num = 0;
apf::MeshEntity* e_local;
while ( (e_local = m->iterate(its[i])) )
{
std::cout << "curr_num = " << curr_num << std::endl;
apf::number(numberings[0], e_local, 0, 0, curr_num);
++curr_num;
}
its[i] = m->begin(i); // reset iterator
}
std::cout << "Finished numbering mesh entities" << std::endl;
for (int i = 0; i < 3; ++i)
{
int type = m->getType(m->deref(its[i]));
std::cout << "type of its[" << i << "] = " << type;
std::cout << "index its[" << i << "] = " << type << std::endl;
}
std::cout << std::endl;
std::cout << "numV = " << numEntity[0] << " , numEdge = " << numEntity[1];
std::cout << " , numFace = " << numEntity[2] << std::endl;
std::cout << std::endl;
resetFaceIt();
apf::writeVtkFiles("output_init", m);
return 0;
}
// perform cleanup activities, making it safe to load a new mesh
void cleanup(apf::Mesh* m_local)
{
m_local->destroyNative();
apf::destroyMesh(m_local);
meshloaded = false;
// PCU_Comm_Free();
// MPI_Finalize();
}
// destroy numberings after mesh adaptation
// dim specifies dimension of existing mesh (2 or 3d)
void destroyNumberings(int dim)
{
apf::destroyNumbering(numberings[0]);
apf::destroyNumbering(numberings[1]);
apf::destroyNumbering(numberings[2]);
if (dim > 2)
{
apf::destroyNumbering(numberings[2]);
}
}
apf::Mesh2* getMeshPtr()
{
return m;
}
apf::FieldShape* getMeshShapePtr()
{
return m->getShape();
}
// get constant field shape of given dimension
apf::FieldShape* getConstantShapePtr(int dimension)
{
return apf::getConstant(dimension);
}
apf::Numbering* getVertNumbering()
{
return numberings[0];
}
apf::Numbering* getEdgeNumbering()
{
return numberings[1];
}
apf::Numbering* getFaceNumbering()
{
return numberings[2];
}
apf::Numbering* getElNumbering()
{
return numberings[3];
}
void resetVertIt()
{
its[0] = m->begin(0);
}
void resetEdgeIt()
{
its[1] = m->begin(1);
}
void resetFaceIt()
{
its[2] = m->begin(2);
}
void resetElIt()
{
its[3] = m->begin(3);
}
void incrementVertIt()
{
m->iterate(its[0]);
}
// increment vertex iterator n times
void incrementVertItn(int n)
{
for (int i=0; i < n; ++i)
m->iterate(its[0]);
}
void incrementEdgeIt()
{
m->iterate(its[1]);
}
// increment edge iterator n times
void incrementEdgeItn(int n)
{
for (int i=0; i < n; ++i)
m->iterate(its[1]);
}
void incrementFaceIt()
{
m->iterate(its[2]);
}
// increment face iterator n times
void incrementFaceItn(int n)
{
for (int i=0; i < n; ++i)
m->iterate(its[2]);
}
void incrementElIt()
{
m->iterate(its[3]);
}
// increment element iterator n times
void incrementElItn(int n)
{
for (int i=0; i < n; ++i)
m->iterate(its[3]);
}
int count(apf::Mesh2* m_local, int dimension)
{
return m_local->count(dimension);
}
void writeVtkFiles(char* name, apf::Mesh2* m_local)
{
apf::writeVtkFiles(name, m_local);
}
// tag current vertex with val, part of MeshTag globalNodeNumbers
//
// these functions no longer work
void setGlobalVertNumber(int val)
{
apf::MeshEntity* e = m->deref(its[0]); // get current vertex
// tag the vertex with a value
// setIntTag expects an array, so pass it a pointer to a single integer
m->setIntTag(e, globalVertNums, &val); // tag the vertex with the a value
}
// get the global vertex number of the current vertex
int getGlobalVertNumber()
{
apf::MeshEntity* e = m->deref(its[0]);
int val;
m->getIntTag(e, globalVertNums, &val);
return val;
}
int getVertNumber()
{
apf::MeshEntity*e = m->deref(its[0]);
int num = apf::getNumber(numberings[0], e, 0, 0);
return num;
}
int getEdgeNumber()
{
apf::MeshEntity*e = m->deref(its[1]);
int num = apf::getNumber(numberings[1], e, 0, 0);
return num;
}
int getFaceNumber()
{
apf::MeshEntity*e = m->deref(its[2]);
int num = apf::getNumber(numberings[2], e, 0, 0);
return num;
}
int getElNumber()
{
apf::MeshEntity*e = m->deref(its[3]);
int num = apf::getNumber(numberings[3], e, 0, 0);
return num;
}
// return MeshEntity pointer to current vertex
apf::MeshEntity* getVert()
{
apf::MeshEntity* e = m->deref(its[0]);
return e;
}
// return MeshEntity pointer to current edge
apf::MeshEntity* getEdge()
{
apf::MeshEntity* e = m->deref(its[1]);
return e;
}
// return MeshEntity pointer to current face
apf::MeshEntity* getFace()
{
apf::MeshEntity* e = m->deref(its[2]);
return e;
}
// return MeshEntity pointer to current element
apf::MeshEntity* getEl()
{
apf::MeshEntity* e = m->deref(its[3]);
return e;
}
// get number of the vertex MeshEntity* e
int getVertNumber2(apf::MeshEntity* e)
{
int i = apf::getNumber(numberings[0], e, 0 , 0);
return i;
}
// get number of the edge MeshEntity* e
int getEdgeNumber2(apf::MeshEntity* e)
{
int i = apf::getNumber(numberings[1], e, 0 , 0);
return i;
}
// get number of the face MeshEntity* e
int getFaceNumber2(apf::MeshEntity* e)
{
int i = apf::getNumber(numberings[2], e, 0 , 0);
return i;
}
// get number of the element MeshEntity* e
int getElNumber2(apf::MeshEntity* e)
{
int i = apf::getNumber(numberings[3], e, 0 , 0);
return i;
}
// get model info of a mesh element
apf::ModelEntity* toModel(apf::Mesh* m_local, apf::MeshEntity* e)
{
return m_local->toModel(e);
}
// get the *dimension* of the model entity
// not its type like the name implies
int getModelType(apf::Mesh* m_local, apf::ModelEntity* e)
{
return m_local->getModelType(e);
}
int getModelTag(apf::Mesh* m_local, apf::ModelEntity* e)
{
return m_local->getModelTag( e);
}
// get dimension of mesh
int getMeshDimension(apf::Mesh2* m_local)
{
int i = m_local->getDimension();
// std::cout << "Mesh Dimesion = " << i << std::endl;
return i;
}
// untested
int getType(apf::Mesh2* m_local, apf::MeshEntity* e)
{
return m_local->getType(e);
}
// get the downward adjacencies of a MeshEntity
// supply a 12 element array of Ptr{Void}
// the function return an integer telling the number of entities put into the
// array
int getDownward(apf::Mesh2* m_local, apf::MeshEntity* e, int dimension, apf::MeshEntity* downwards[12])
{
// std::cout << "in C++ getDownwards, dimension = " << dimension << std::endl;
int numDown = m->getDownward(e, dimension, downwards);
return numDown;
}
apf::DynamicArray<apf::MeshEntity*> adjacencies;
bool adjacent_ready; // stores whether countAdjacent has been called
// before getAdjacent
// gets the mesh entities adjacenct to the given meshentity e, stores them in
// the global variable, and returns the number of entities
// the getAdjacent function only returns the adjcencies fetched by this function
int countAdjacent(apf::Mesh2* m_local, apf::MeshEntity* e, int dimension)
{
m_local->getAdjacent(e, dimension, adjacencies);
int num_adjacent = adjacencies.getSize();
adjacent_ready = true;
// std::cout << " set adjcent_read = true" << std::endl;
return num_adjacent;
}
// returns the adjacencies fetched by countAdjacent, copying them into
// adjacencies_ret[]
void getAdjacent(apf::MeshEntity* adjacencies_ret[])
{
if (!adjacent_ready)
{
std::cout << "Warning, adjacencies might not be ready" << std::endl;
}
int num_adjacent = adjacencies.getSize();
for (int i = 0; i < num_adjacent; ++i)
{
adjacencies_ret[i] = adjacencies[i];
}
adjacent_ready = false;
// std::cout << "set adjacent_ready = false" << std::endl;
}
void getAlignment(apf::Mesh* m_local, apf::MeshEntity* elem, apf::MeshEntity* boundary, int which[1], bool flip[1], int rotate[1])
{
// std::cout << "in getAlignment, which = " << which << " flip = " << flip << " rotate = " << rotate << std::endl;
apf::getAlignment(m_local, elem, boundary, which[0], flip[0], rotate[0]);
// std::cout << "after apf::getAlignment, which = " << which << " flip = " << flip << " rotate = " << rotate << std::endl;
}
// apf::Fieldshape Functions
// check whether the given field as nodes on entities of the specified dimension
bool hasNodesIn(apf::FieldShape* fshape_local, int dimension)
{
return fshape_local->hasNodesIn(dimension);
}
// determine the number of nodes on entities of a given type (apf::Mesh::Type)
int countNodesOn(apf::FieldShape* fshape_local, int type)
{
return fshape_local->countNodesOn(type);
}
// get the EntityShape (object describing shape functions) of a type of entity
apf::EntityShape* getEntityShape(apf::FieldShape* mshape_local, int type)
{
return mshape_local->getEntityShape(type);
}
// MeshElement related functions
extern apf::MeshElement* createMeshElement( apf::Mesh2* m_local, apf::MeshEntity* e)
{
return apf::createMeshElement(m_local, e);
}
// count the number of integration points needed to achieve specified order of
// accuracy. MeshElement can be edges as well as 2D and 3D regions.
// not sure what happens if it is a vertex.
int countIntPoints(apf::MeshElement* e, int order)
{
return apf::countIntPoints(e, order);
}
extern void getIntPoint(apf::MeshElement* e, int order, int point, double coords[3])
{
apf::Vector3 vec;
apf::getIntPoint(e, order, point, vec); // coordinates are now in vec
coords[0] = vec[0];
coords[1] = vec[1];
coords[2] = vec[2];
}
extern double getIntWeight(apf::MeshElement* e, int order, int point)
{
return apf::getIntWeight(e, order, point);
}
// gets the jacobian of a mesh element at a specified location in parametric coordinates
extern void getJacobian(apf::MeshElement* e, double coords[3], double jac[3][3])
{
// copy coordinates to vec
apf::Vector3 vec (coords[0], coords[1], coords[2]);
// create matrix to hold jacobian
apf::Matrix3x3 jac_local;
// poppulate jac_local with the jacobian
apf::getJacobian(e, vec, jac_local);
// copy the jacobian to jac to be returned
jac_local.toArray(jac);
// std::cout << "jac_local = " << jac_local << std::endl;
}
// functions involving EntityShape
int countNodes(apf::EntityShape* eshape_local)
{
return eshape_local->countNodes();
}
// get shape function values
// vals had better be the right size
void getValues(apf::EntityShape* eshape_local, double xi[3], double vals[])
{
apf::Vector3 xi_vec (xi[0], xi[1], xi[2]); // create vector of coordinates
apf::NewArray<double> vals_array; // array to store retrieved values in
int numN_local = eshape_local->countNodes(); // get number of nodes
eshape_local->getValues(m, entity_global, xi_vec, vals_array);
// copy vals_array into vals to be returned
for (int i = 0; i < numN_local; ++i)
{
vals[i] = vals_array[i];
}
}
// get shape function gradient values
// vals had better be the right size
void getLocalGradients(apf::EntityShape* eshape_local, double xi[3], double vals[][3])
{
apf::Vector3 xi_vec (xi[0], xi[1], xi[2]); // create vector of coordinates
apf::NewArray<apf::Vector3> vals_array; // array to store retrieved values in
int numN_local = eshape_local->countNodes(); // get number of nodes
eshape_local->getLocalGradients(m, entity_global, xi_vec, vals_array);
// copy vals_array into vals to be returned
for (int i = 0; i < numN_local; ++i)
{
apf::Vector3 tmp = vals_array[i]; // get the ith vector
for (int j = 0; j < 3; ++j)
{
vals[i][j] = tmp[j]; // copy the vector into a column of vals
}
}
}
// get the array that transforms from local element order to canonical order
// the length of order must be the number of nodes classified on
// apf::MeshEntity* shared
void alignSharedNodes(apf::EntityShape* eshape_local, apf::Mesh* m_local, apf::MeshEntity* elem, apf::MeshEntity* shared, int order[])
{
eshape_local->alignSharedNodes(m_local, elem, shared, order);
}
// check that global variable are persisent
// doesn't work in 2d
void checkVars()
{
std::cout << "Entered checkVars()" << std::endl;
for (int i = 0; i < 4; ++i)
{
int type = m->getType(m->deref(its[i]));
std::cout << "type of its[" << i << "] = " << type;
int index = apf::getMdsIndex(m, m->deref(its[i]));
std::cout << "index its[" << i << "] = " << index << std::endl;
m->iterate(its[i]);
}
std::cout << "iterated all iterators stored in array" << std::endl;
for (int i = 0; i < 4; ++i)
{
int index = apf::getMdsIndex(m, m->deref(its[i]));
std::cout << "index its[" << i << "] = " << index << std::endl;
}
}
// print numberings of all mesh entitites
// doesn't work in 2d
void checkNums()
{
std::cout << "Entered checkNums" << std::endl;
apf::MeshEntity* e;
int i = 0; // counter
int id = 0; // store numbering output
std::cout << "about to start loop" << std::endl;
apf::MeshIterator* it = m->begin(0);
for (int j = 0; j < 4; ++j) // loop over mesh entity types
{
it = m->begin(j);
while ( ( e = m->iterate(it) ) )
// while (( e = m->iterate(its[j]) )) // loop over entities of type j
{
// int dim = m->getType(e);
// std::cout << "type of current entity = " << dim << std::endl;
// std::cout << "About to fetch numbering" << std::endl;
id = apf::getNumber(numberings[j], e, 0, 0);
std::cout << names[j] << " number " << i << " has number " << id << std::endl;
// std::cout << "i = " << i << std::endl;
++i;
}
// reset for next outer loop
std::cout << std::endl;
i = 0;
}
// reset iterators
resetVertIt();
resetEdgeIt();
resetFaceIt();
resetElIt();
}
// get the coordinates of a vertex
// coords is 2d array to populate, sx and sy are dimension of the array
void getVertCoords(double coords[][3], int sx, int sy)
{
// std::cout << "in getVertCoords" << std::endl;
// std::cout << "sx = " << sx << " ,sy = " << sy << std::endl;
apf::MeshEntity* e = m->deref(its[0]);
apf::Vector3 vec;
m->getPoint(e, 0, vec);
// std::cout << "coords = " << vec << std::endl;
coords[0][0] = vec[0];
coords[0][1] = vec[1];
coords[0][2] = vec[2];
}
// get the coordinates of a vertex
// coords is 2d array to populate, sx and sy are dimension of the array
void getVertCoords2(apf::MeshEntity* e, double coords[][3], int sx, int sy)
{
// std::cout << "in getVertCoords" << std::endl;
// std::cout << "sx = " << sx << " ,sy = " << sy << std::endl;
apf::Vector3 vec;
m->getPoint(e, 0, vec);
// std::cout << "coords = " << vec << std::endl;
coords[0][0] = vec[0];
coords[0][1] = vec[1];
coords[0][2] = vec[2];
}
// get the coordinates of the two points that define, iterate edge iterator
// an edge
int getEdgeCoords(double coords[2][3], int sx, int sy)
{
// std::cout <<"in getEdgeCoords" << std::endl;
if (sx < 2 || sy != 3)
{
std::cout << "Warning: coords array too small" << std::endl;
return -1;
}
apf::MeshEntity* e = m->deref(its[1]);
apf::Vector3 vec;
apf::MeshEntity* verts[2];
// std::cout << " about to get downward entities" << std::endl;
m->getDownward(e, 0, verts);
// std::cout << "got vertices of edge" << std::endl;
// get coordinates of each vertex
m->getPoint(verts[0], 0, vec);
coords[0][0] = vec[0];
coords[0][1] = vec[1];
coords[0][2] = vec[2];
// std::cout << "first point coordinates = " << vec << std::endl;
m->getPoint(verts[1], 0, vec);
coords[1][0] = vec[0];
coords[1][1] = vec[1];
coords[1][2] = vec[2];
// std::cout << "second point coordinates = " << vec << std::endl;
return 0;
}
// get the coordinates of the two points that define and edge
int getEdgeCoords2(apf::MeshEntity* e, double coords[2][3], int sx, int sy)
{
// std::cout <<"in getEdgeCoords" << std::endl;
if (sx < 2 || sy != 3)
{
std::cout << "Warning: coords array too small" << std::endl;
return -1;
}
apf::Vector3 vec;
apf::MeshEntity* verts[2];
// std::cout << " about to get downward entities" << std::endl;
m->getDownward(e, 0, verts);
// std::cout << "got vertices of edge" << std::endl;
// get coordinates of each vertex
m->getPoint(verts[0], 0, vec);
coords[0][0] = vec[0];
coords[0][1] = vec[1];
coords[0][2] = vec[2];
// std::cout << "first point coordinates = " << vec << std::endl;
m->getPoint(verts[1], 0, vec);
coords[1][0] = vec[0];
coords[1][1] = vec[1];
coords[1][2] = vec[2];