Debian Codegraph @

tests/usecases/c/UsesCase_MEDmesh_4.c

raw symbols SCIP
1 /* This file is part of MED.
2 *
3 * COPYRIGHT (C) 1999 - 2020 EDF R&D, CEA/DEN
4 * MED is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * MED is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with MED. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18
19 /*
20 * How to create a structured mesh
21 *
22 * Use case 4 : write a 2D structured mesh (5x3 cartesian grid)
23 */
24
25 #include <med.h>
26 #define MESGERR 1
27 #include <med_utils.h>
28
29 #include <string.h>
30
31 int main (int argc, char **argv) {
32 med_idt fid;
33 const char meshname[MED_NAME_SIZE+1] = "2D structured mesh";
34 const med_int spacedim = 2;
35 const med_int meshdim = 2;
36 const char axisname[2*MED_SNAME_SIZE+1] = "x y ";
37 const char unitname[2*MED_SNAME_SIZE+1] = "cm cm ";
38 med_int axis, size ;
39 const med_float cooXaxis[5] = {1.,2.,3.,4.,5.};
40 const med_float cooYaxis[3] = {1.,2.,3.};
41 const med_int nquad4 = 8;
42 /* 12345678901234561234567890123456123456789012345612345678901234561234567890123456123456789012345612345678901234561234567890123456 */
43 const char cellsnames[8*MED_SNAME_SIZE+1] = "CELL_1 CELL_2 CELL_3 CELL_4 CELL_5 CELL_6 CELL_7 CELL_8 ";
44 const char familyname [MED_NAME_SIZE+1] = "CART_GRID_QUAD_FAMILY";
45 const char groupname [MED_LNAME_SIZE+1] = "CART_GRID_GROUP";
46 const med_int familynumbers[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
47 int ret=-1;
48
49 /* MED file creation */
50 fid = MEDfileOpen("UsesCase_MEDmesh_4.med",MED_ACC_CREAT);
51 if (fid < 0) {
52 MESSAGE("ERROR : file creation ...");
53 goto ERROR;
54 }
55
56 /* create the structured mesh in the MED file */
57 if (MEDmeshCr(fid, meshname, spacedim, meshdim, MED_STRUCTURED_MESH,
58 "A 2D structured mesh","",MED_SORT_DTIT,
59 MED_CARTESIAN, axisname, unitname) < 0) {
60 MESSAGE("ERROR : mesh creation ...");
61 goto ERROR;
62 }
63
64 /* specify the grid type : MED_CARTESIAN_GRID */
65 if (MEDmeshGridTypeWr(fid,meshname, MED_CARTESIAN_GRID) < 0) {
66 MESSAGE("ERROR : write grid type ...");
67 goto ERROR;
68 }
69
70 /* write axis "X" and "Y" coordinates */
71 axis = 1;
72 size = 5;
73 if (MEDmeshGridIndexCoordinateWr(fid, meshname, MED_NO_DT, MED_NO_IT,0.0,
74 axis, size, cooXaxis) < 0) {
75 MESSAGE("ERROR : write of axis X coordinates ...");
76 goto ERROR;
77 }
78 axis++;
79 size = 3;
80 if (MEDmeshGridIndexCoordinateWr(fid, meshname, MED_NO_DT, MED_NO_IT,0.0,
81 axis, size, cooYaxis) < 0) {
82 MESSAGE("ERROR : write of axis Y coordinates ...");
83 goto ERROR;
84 }
85
86 /* optionnal : names for nodes or elements */
87 /* In this case, a name is given to the cells of the mesh */
88 if (MEDmeshEntityNameWr(fid, meshname, MED_NO_DT, MED_NO_IT,
89 MED_CELL, MED_QUAD4, nquad4, cellsnames) < 0) {
90 MESSAGE("ERROR : cells names ...");
91 goto ERROR;
92 }
93
94 /* We have to create family 0 : by default, all mesh entities family number is 0 */
95 if (MEDfamilyCr(fid, meshname, MED_NO_NAME, 0, 0, MED_NO_GROUP) < 0) {
96 MESSAGE("ERROR : family 0 creation ...");
97 goto ERROR;
98 }
99
100 /* We decide to create a family for boundary quad4 :
101 by convention a nodes family number is > 0 and an element family number is < 0 */
102 if (MEDfamilyCr(fid, meshname,familyname, 1, -1, groupname) < 0) {
103 MESSAGE("ERROR : family creation ...");
104 goto ERROR;
105 }
106
107 /* Then we write family number for quad4 */
108 if (MEDmeshEntityFamilyNumberWr(fid, meshname, MED_NO_DT, MED_NO_IT,
109 MED_CELL, MED_QUAD4, nquad4, familynumbers) < 0) {
110 MESSAGE("ERROR : nodes family numbers ...");
111 goto ERROR;
112 }
113
114 ret = 0;
115 ERROR:
116
117 /* close MED file */
118 if (MEDfileClose(fid) < 0) {
119 MESSAGE("ERROR : close file ...");
120 ret = -1;
121 }
122
123 return ret;
124 }
125