-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.cpp
123 lines (91 loc) · 3.45 KB
/
example.cpp
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
static const char help[] = "Simple Tests";
#include <petsc.h>
#include <petsc/private/dmpleximpl.h>
#include <egadsTypes.h>
#include <egads.h>
#include "petscdmplex.h"
#include <petscviewerhdf5.h>
#include <iostream>
int main(int argc, char **argv) {
PetscCall(PetscInitialize(&argc, &argv, NULL, help));
PetscViewer petscViewer = nullptr;
PetscViewerHDF5Open(PETSC_COMM_SELF, "/Users/mcgurn/scratch/testinput/_meshMappingTest/domain.hdf5", FILE_MODE_READ, &petscViewer);
DM dmLoad;
DMCreate(PETSC_COMM_SELF, &dmLoad);
DMSetType(dmLoad, DMPLEX);
DMLoad(dmLoad, petscViewer);
DMView(dmLoad, PETSC_VIEWER_STDOUT_WORLD);
// determine the number of cells in the
PetscInt dmCells;
// extract the connected cells and store them
PetscInt cStart, cEnd;
DMPlexGetHeightStratum(dmLoad, 0, &cStart, &cEnd);
PetscInt numberCells = cEnd-cStart;
DM dm;
DMClone(dmLoad, &dm);
// create an empty vec
Vec glob;
VecCreate(PETSC_COMM_WORLD, &glob);
PetscViewerHDF5PushTimestepping(petscViewer);
PetscCall(PetscObjectSetName((PetscObject)glob, "/cell_fields/solution_fieldB"));
PetscCall(VecLoad(glob, petscViewer));
// sanity checks
PetscInt blockSize;
VecGetBlockSize(glob, &blockSize);
printf("Block Size: %d\n", blockSize);
PetscInt vecSize;
VecGetSize(glob, &vecSize);
printf("Vec Size: %d\n", vecSize);
printf("Vec cells: %d\n", (vecSize/blockSize));
printf("Number Cells: %d\n", numberCells);
// Setup the DM for this field
PetscInt dim;
DMGetDimension(dm, &dim);
PetscBool simplex;
DMPlexIsSimplex(dm, &simplex);
PetscFE fe;
PetscFECreateLagrange(PETSC_COMM_SELF, dim, blockSize, simplex, 0, PETSC_DETERMINE, &fe);
DMSetField(dm, 0, NULL, (PetscObject)fe);
PetscFEDestroy(&fe);
DMCreateDS(dm);
DMInterpolationInfo interpolant;
DMInterpolationCreate(PETSC_COMM_SELF, &interpolant);
DMInterpolationSetDim(interpolant, 2);
DMInterpolationSetDof(interpolant, blockSize);
// Copy over the np of particles
PetscReal pt[2] = {0.0189287, 0.00845254};
DMInterpolationAddPoints(interpolant, 1, pt);
/* Particles that lie outside the domain should be dropped,
whereas particles that move to another partition should trigger a migration */
DMInterpolationSetUp(interpolant, dm, PETSC_FALSE, PETSC_TRUE);
// Create a vec to hold the information
Vec eulerianFieldAtParticles;
VecCreateSeq(PETSC_COMM_SELF, 1 * blockSize, &eulerianFieldAtParticles);
// interpolate
PetscCall(DMInterpolationEvaluate(interpolant, dm, glob, eulerianFieldAtParticles));
// Now cleanup
DMInterpolationDestroy(&interpolant);
VecView(eulerianFieldAtParticles, PETSC_VIEWER_STDOUT_WORLD);
// VecView(glob, PETSC_VIEWER_STDOUT_WORLD);
// // try to create global mesh
// Vec glob;
// DMCreateGlobalVector(dm, &glob);
// VecView(glob, PETSC_VIEWER_STDOUT_WORLD);
// PetscInt size;
// VecGetSize(glob, &size);
// printf("Size: %d", size);
// VecCreate(PETSC_COMM_WORLD, &glob);
//// PetscViewerHDF5PushGroup(petscViewer, "cell_fields");
// PetscBool has;
// PetscCall(PetscViewerHDF5HasGroup(petscViewer, "cell_fields", &has));
//
// PetscCall(PetscObjectSetName((PetscObject)glob, "solution_euler"));
// PetscViewerHDF5PopGroup(petscViewer);
//
// PetscCall(VecLoad(glob, petscViewer));
//
//
// PetscViewerDestroy(&petscViewer);
PetscFinalize();
return 0;
}