[petsc-users] Questions about Gmsh and petsc (absolute beginner level)

juan.petscmaillist at yahoo.com juan.petscmaillist at yahoo.com
Wed Jan 18 17:33:17 CST 2017


Dear All,
I am absolutely new to the mesh generation, the finite element method and petsc. But I wish to master this platform.  

I am trying to use gmsh to generate mesh file of a sphere and use the interface, DMPlexCreateGmshFromFile, to create mesh in petsc. The mesh file (sphere.msh, see to the end of the email), created by gmsh, contains 58 nodes and 220 elements of two types, a) type 2, triangle of 3 vertices and b) type 4, tetrahedral with 4 vertices. 

I have absolute no idea of my setup and could not find examples of this problem to compare with. So could anyone tell me whether the following code is correct or not? This code runs properly on petsc 3.7.5 with -@$(MPIEXEC) -n $(N_CPU) ./a.out -snes_monitor_short, where N_CPU can be any number.
Q1: Corresponding to the given mesh file, are these variables correct?
#define MAX_ELEM      220  /* Maximum number of elements */
#define MAX_VERT      58  /* Maximum number of vertices */
#define MAX_VERT_ELEM   4  /* Vertices per element       */
Q2: The data structure AppCtx is copied from src/snes/examples/tutorials/ex10d/ex10.c. Is this structure suitable for this problem? 

Q3: Before and after calling DMPlexCreateGmshFromFile, did I miss any important steps?
Q4: Also could anyone let me know what the proper way to check the mesh setup by petsc is.
I just started playing around with is package. I found it is really amazing powerful, but also quite hard to get the accurate understanding. I appreciate if someone can give me some further suggestions.

Thank you very much in advance.
Juan



//------------------------------------------------
#include <petscsnes.h>
#include <petscao.h>
#include <petscsys.h>
#include <petscvec.h>
#include <petscdm.h> 
DM             dm;                   /* problem definition */

PetscMPIInt    ranks, sizes, ierr;

PetscViewer    viewer;

PetscBool      interpolate;

#define MAX_ELEM      220  /* Maximum number of elements */
#define MAX_VERT      58  /* Maximum number of vertices */
#define MAX_VERT_ELEM   4  /* Vertices per element       */

typedef struct {
  PetscInt   Nvglobal,Nvlocal;              /* global and local number of vertices */
  PetscInt   Neglobal,Nelocal;              /* global and local number of vertices */
  PetscInt   AdjM[MAX_VERT][50];            /* adjacency list of a vertex */
  PetscInt   itot[MAX_VERT];                /* total number of neighbors for a vertex */
  PetscInt   icv[MAX_ELEM][MAX_VERT_ELEM];  /* vertices belonging to an element */
  PetscInt   v2p[MAX_VERT];                 /* processor number for a vertex */
  PetscInt   *locInd,*gloInd;               /* local and global orderings for a node */
  Vec        localX,localF;                 /* local solution (u) and f(u) vectors */
  PetscReal  non_lin_param;                 /* nonlinear parameter for the PDE */
  PetscReal  lin_param;                     /* linear parameter for the PDE */
  VecScatter scatter;                       /* scatter context for the local and
                                               distributed vectors */
} AppCtx;


#undef __FUNCT__
#define __FUNCT__ "main"
int main(int argc,char **argv)
{

  static char help[] = "Define Vector";
  static char filename[] = "./data/sphere.msh";

  PetscInitialize(&argc,&argv,(char*)0,help);

  ierr  = MPI_Comm_rank(PETSC_COMM_WORLD,&ranks);CHKERRQ(ierr);
  ierr  = MPI_Comm_size(PETSC_COMM_WORLD,&sizes);CHKERRQ(ierr);

  ierr=DMPlexCreateGmshFromFile(PETSC_COMM_WORLD, filename, interpolate, &dm);  
  PetscFinalize();

  return 0;
};

-------------- Mesh file ----------

$MeshFormat
2.2 0 8
$EndMeshFormat
$Nodes
58
1 0 1 0
2 -1 0 0
3 0 0 1
4 -0.4999999999988097 0.8660254037851258 0
5 -0.8660254037838017 0.5000000000011033 0
6 0 0.4999999999988097 0.8660254037851258
7 0 0.8660254037838017 0.5000000000011033
8 -0.4999999999988097 0 0.8660254037851258
9 -0.8660254037838017 0 0.5000000000011033
10 -0.6339745962178445 0.4428909829273233 0.633974596172505
11 -0.4822994153869866 0.7506004041478795 0.4516484331982243
12 -0.3493897428766589 0.3546301510880328 0.8672740417606545
13 -0.8378218522221577 0.4012601404060589 0.3701956829304511
14 0 -1 0
15 -0.8660254037851258 -0.4999999999988097 0
16 -0.5000000000011033 -0.8660254037838017 0
17 0 -0.8660254037851258 0.4999999999988097
18 0 -0.5000000000011033 0.8660254037838017
19 -0.4428909828654145 -0.6339745962336311 0.6339745961999673
20 -0.7198886675198282 -0.4906852283660827 0.4909056050197959
21 -0.3594838238878847 -0.383951782616808 0.8505012692455668
22 -0.358692803375615 -0.8508569143149735 0.3839036131230655
23 1 0 0
24 0.8660254037851258 0.4999999999988097 0
25 0.5000000000011033 0.8660254037838017 0
26 0.8660254037851258 0 0.4999999999988097
27 0.5000000000011033 0 0.8660254037838017
28 0.5108386809150948 0.5108386789440059 0.6914388520872029
29 0.8481866372316714 0.374552685492926 0.3745526854952001
30 0.4487154446450166 0.8265947249299238 0.3396992941633065
31 0 0 -1
32 0 0.8660254037851258 -0.4999999999988097
33 0 0.5000000000011033 -0.8660254037838017
34 -0.8660254037851258 0 -0.4999999999988097
35 -0.5000000000011033 0 -0.8660254037838017
36 -0.6339745962178445 0.633974596172505 -0.4428909829273234
37 -0.5097746217363811 0.4676776035922022 -0.7220855171873929
38 -0.3545204312296736 0.868050272320611 -0.3475686817951805
39 -0.8398086783581998 0.3742446117737876 -0.3932713494682021
40 0.4999999999988097 0 -0.8660254037851258
41 0.8660254037838017 0 -0.5000000000011033
42 0.5314152505108283 0.5314152505101392 -0.6596936130127075
43 0.3745526855885761 0.8481866371475475 -0.3745526855900513
44 0.8166239656466456 0.4593780018327371 -0.3494240263114541
45 0 -0.4999999999988097 -0.8660254037851258
46 0 -0.8660254037838017 -0.5000000000011033
47 -0.693625367376466 -0.4647476149317986 -0.5503576147806688
48 -0.3745526897803909 -0.3745526897775885 -0.8481866334472902
49 -0.4411747191846568 -0.7694084839919415 -0.4619258078020342
50 0.4999999999988097 -0.8660254037851258 0
51 0.8660254037838017 -0.5000000000011033 0
52 0.4835428142572408 -0.7296387419233323 0.4835428140968744
53 0.8051246928456837 -0.4546444607248049 0.38088402867854
54 0.4212799396792105 -0.4355246816538718 0.7955133336998031
55 0.4835428133498502 -0.7296387419932698 -0.483542814898733
56 0.3808840285417322 -0.4546444603984627 -0.8051246930946855
57 0.7955133341574981 -0.4355246806022939 -0.4212799399020684
58 -1.110223024625157e-15 1.110223024625157e-15 -6.106226635438361e-16
$EndNodes
$Elements
220
1 2 2 1 14 1 4 11
2 2 2 1 14 1 11 7
3 2 2 1 14 2 13 5
4 2 2 1 14 2 9 13
5 2 2 1 14 3 6 12
6 2 2 1 14 3 12 8
7 2 2 1 14 4 5 11
8 2 2 1 14 5 13 11
9 2 2 1 14 6 7 11
10 2 2 1 14 6 11 12
11 2 2 1 14 8 10 9
12 2 2 1 14 8 12 10
13 2 2 1 14 9 10 13
14 2 2 1 14 10 12 11
15 2 2 1 14 10 11 13
16 2 2 1 16 15 20 2
17 2 2 1 16 20 9 2
18 2 2 1 16 22 16 14
19 2 2 1 16 17 22 14
20 2 2 1 16 21 18 3
21 2 2 1 16 8 21 3
22 2 2 1 16 16 20 15
23 2 2 1 16 22 20 16
24 2 2 1 16 18 19 17
25 2 2 1 16 19 22 17
26 2 2 1 16 21 19 18
27 2 2 1 16 9 20 8
28 2 2 1 16 20 21 8
29 2 2 1 16 21 20 19
30 2 2 1 16 20 22 19
31 2 2 1 18 24 29 23
32 2 2 1 18 29 26 23
33 2 2 1 18 30 25 1
34 2 2 1 18 7 30 1
35 2 2 1 18 3 27 6
36 2 2 1 18 24 25 30
37 2 2 1 18 24 30 29
38 2 2 1 18 28 7 6
39 2 2 1 18 27 28 6
40 2 2 1 18 28 30 7
41 2 2 1 18 28 27 26
42 2 2 1 18 29 28 26
43 2 2 1 18 29 30 28
44 2 2 1 20 1 38 4
45 2 2 1 20 1 32 38
46 2 2 1 20 2 5 39
47 2 2 1 20 2 39 34
48 2 2 1 20 31 37 33
49 2 2 1 20 31 35 37
50 2 2 1 20 4 36 5
51 2 2 1 20 4 38 36
52 2 2 1 20 5 36 39
53 2 2 1 20 32 33 37
54 2 2 1 20 32 37 38
55 2 2 1 20 34 37 35
56 2 2 1 20 34 39 37
57 2 2 1 20 36 38 37
58 2 2 1 20 36 37 39
59 2 2 1 22 23 44 24
60 2 2 1 22 23 41 44
61 2 2 1 22 1 25 43
62 2 2 1 22 1 43 32
63 2 2 1 22 31 33 40
64 2 2 1 22 24 44 25
65 2 2 1 22 44 43 25
66 2 2 1 22 32 42 33
67 2 2 1 22 32 43 42
68 2 2 1 22 33 42 40
69 2 2 1 22 40 42 41
70 2 2 1 22 41 42 44
71 2 2 1 22 42 43 44
72 2 2 1 24 2 34 15
73 2 2 1 24 16 49 14
74 2 2 1 24 49 46 14
75 2 2 1 24 45 48 31
76 2 2 1 24 48 35 31
77 2 2 1 24 16 15 49
78 2 2 1 24 34 47 15
79 2 2 1 24 49 15 47
80 2 2 1 24 45 46 49
81 2 2 1 24 45 49 48
82 2 2 1 24 35 47 34
83 2 2 1 24 48 47 35
84 2 2 1 24 48 49 47
85 2 2 1 26 23 53 51
86 2 2 1 26 23 26 53
87 2 2 1 26 17 14 50
88 2 2 1 26 3 18 54
89 2 2 1 26 3 54 27
90 2 2 1 26 53 50 51
91 2 2 1 26 50 52 17
92 2 2 1 26 52 50 53
93 2 2 1 26 54 18 17
94 2 2 1 26 52 54 17
95 2 2 1 26 26 27 54
96 2 2 1 26 53 26 54
97 2 2 1 26 52 53 54
98 2 2 1 28 51 57 23
99 2 2 1 28 57 41 23
100 2 2 1 28 14 46 50
101 2 2 1 28 56 45 31
102 2 2 1 28 40 56 31
103 2 2 1 28 51 50 57
104 2 2 1 28 46 55 50
105 2 2 1 28 57 50 55
106 2 2 1 28 56 46 45
107 2 2 1 28 55 46 56
108 2 2 1 28 41 57 40
109 2 2 1 28 40 57 56
110 2 2 1 28 56 57 55
111 4 2 2 30 21 18 19 58
112 4 2 2 30 13 10 9 58
113 4 2 2 30 36 38 4 58
114 4 2 2 30 36 4 5 58
115 4 2 2 30 10 8 9 58
116 4 2 2 30 21 3 18 58
117 4 2 2 30 19 18 17 58
118 4 2 2 30 47 48 35 58
119 4 2 2 30 36 5 39 58
120 4 2 2 30 23 51 53 58
121 4 2 2 30 10 12 8 58
122 4 2 2 30 22 19 17 58
123 4 2 2 30 38 1 4 58
124 4 2 2 30 12 10 11 58
125 4 2 2 30 43 44 25 58
126 4 2 2 30 23 57 51 58
127 4 2 2 30 18 3 54 58
128 4 2 2 30 11 10 13 58
129 4 2 2 30 52 53 50 58
130 4 2 2 30 56 46 55 58
131 4 2 2 30 13 9 2 58
132 4 2 2 30 36 37 38 58
133 4 2 2 30 20 19 22 58
134 4 2 2 30 29 30 24 58
135 4 2 2 30 19 20 21 58
136 4 2 2 30 52 54 53 58
137 4 2 2 30 57 56 55 58
138 4 2 2 30 5 4 11 58
139 4 2 2 30 53 51 50 58
140 4 2 2 30 49 48 47 58
141 4 2 2 30 8 3 21 58
142 4 2 2 30 43 42 44 58
143 4 2 2 30 24 25 44 58
144 4 2 2 30 57 55 50 58
145 4 2 2 30 52 17 54 58
146 4 2 2 30 52 50 17 58
147 4 2 2 30 46 50 55 58
148 4 2 2 30 30 25 24 58
149 4 2 2 30 48 49 45 58
150 4 2 2 30 36 39 37 58
151 4 2 2 30 28 30 29 58
152 4 2 2 30 11 4 1 58
153 4 2 2 30 57 50 51 58
154 4 2 2 30 18 54 17 58
155 4 2 2 30 29 24 23 58
156 4 2 2 30 34 47 35 58
157 4 2 2 30 24 44 23 58
158 4 2 2 30 22 14 16 58
159 4 2 2 30 20 9 8 58
160 4 2 2 30 32 42 43 58
161 4 2 2 30 44 41 23 58
162 4 2 2 30 44 42 41 58
163 4 2 2 30 5 11 13 58
164 4 2 2 30 12 3 8 58
165 4 2 2 30 48 31 35 58
166 4 2 2 30 28 7 30 58
167 4 2 2 30 28 29 26 58
168 4 2 2 30 16 20 22 58
169 4 2 2 30 20 8 21 58
170 4 2 2 30 43 25 1 58
171 4 2 2 30 2 9 20 58
172 4 2 2 30 29 23 26 58
173 4 2 2 30 22 17 14 58
174 4 2 2 30 47 15 49 58
175 4 2 2 30 53 26 23 58
176 4 2 2 30 47 34 15 58
177 4 2 2 30 12 6 3 58
178 4 2 2 30 41 57 23 58
179 4 2 2 30 37 32 38 58
180 4 2 2 30 30 1 25 58
181 4 2 2 30 39 5 2 58
182 4 2 2 30 12 11 6 58
183 4 2 2 30 42 40 41 58
184 4 2 2 30 13 2 5 58
185 4 2 2 30 48 45 31 58
186 4 2 2 30 53 54 26 58
187 4 2 2 30 6 7 28 58
188 4 2 2 30 38 32 1 58
189 4 2 2 30 30 7 1 58
190 4 2 2 30 16 14 49 58
191 4 2 2 30 56 45 46 58
192 4 2 2 30 57 40 56 58
193 4 2 2 30 43 1 32 58
194 4 2 2 30 33 40 42 58
195 4 2 2 30 27 3 6 58
196 4 2 2 30 41 40 57 58
197 4 2 2 30 33 42 32 58
198 4 2 2 30 37 39 34 58
199 4 2 2 30 49 15 16 58
200 4 2 2 30 28 27 6 58
201 4 2 2 30 31 37 35 58
202 4 2 2 30 1 7 11 58
203 4 2 2 30 28 26 27 58
204 4 2 2 30 54 3 27 58
205 4 2 2 30 49 46 45 58
206 4 2 2 30 11 7 6 58
207 4 2 2 30 34 35 37 58
208 4 2 2 30 31 45 56 58
209 4 2 2 30 39 2 34 58
210 4 2 2 30 49 14 46 58
211 4 2 2 30 50 14 17 58
212 4 2 2 30 46 14 50 58
213 4 2 2 30 54 27 26 58
214 4 2 2 30 40 31 56 58
215 4 2 2 30 16 15 20 58
216 4 2 2 30 33 32 37 58
217 4 2 2 30 33 31 40 58
218 4 2 2 30 34 2 15 58
219 4 2 2 30 33 37 31 58
220 4 2 2 30 2 20 15 58
$EndElements

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20170118/0d29fa7f/attachment-0003.html>


More information about the petsc-users mailing list