Debian Codegraph @

tests/usecases/c/UsesCase_MEDmesh_6.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 * How to create an unstructured mesh
20 *
21 * Use case 6 : a 2D unstructured mesh with the following features
22 * computin steps, profiles and nodes coordinates evolution.
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 unstructured 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 const med_float initial_coordinates[30] = { 2.,1., 7.,1., 12.,1., 17.,1., 22.,1.,
39 2.,6., 7.,6., 12.,6., 17.,6., 22.,6.,
40 2.,11., 7.,11., 12.,11., 17.,11., 22.,11.};
41 const med_int nnodes = 15;
42 const med_int triaconnectivity[24] = { 1,7,6, 2,7,1, 3,7,2, 8,7,3,
43 13,7,8, 12,7,13, 11,7,12, 6,7,11 };
44 const med_int ntria3 = 8;
45 const med_int quadconnectivity[16] = {3,4,9,8, 4,5,10,9,
46 15,14,9,10, 13,8,9,14};
47 const med_int nquad4 = 4;
48 /* new coordinates (step 1) for nodes 13, 14 and 15 */
49 const med_float new_coordinates_step1 [6] = { 12.,15., 17.,15., 22.,15.};
50 const char profile1name[MED_NAME_SIZE+1] = "UPPER_QUAD4_PROFILE";
51 const med_int profile1[3] = {13, 14, 15};
52 const med_int profile1size = 3;
53 /* new coordinates (step 2) for nodes 8, 9 and 10 */
54 const med_float new_coordinates_step2 [6] = { 12.,10., 17.,10., 22.,10.};
55 const char profile2name[MED_NAME_SIZE+1] = "MIDDLE_QUAD4_PROFILE";
56 const med_int profile2[3] = {8, 9, 10};
57 const med_int profile2size = 3;
58 int ret=-1;
59
60
61 /* open MED file */
62 fid = MEDfileOpen("UsesCase_MEDmesh_6.med",MED_ACC_CREAT);
63 if (fid < 0) {
64 MESSAGE("ERROR : file creation ...");
65 goto ERROR;
66 }
67
68 /* write a comment in the file */
69 if (MEDfileCommentWr(fid,"A 2D unstructured mesh : 15 nodes, 12 cells") < 0) {
70 MESSAGE("ERROR : write file description ...");
71 goto ERROR;
72 }
73
74 /* create the profiles in the file */
75 if (MEDprofileWr(fid, profile1name, profile1size, profile1 ) < 0) {
76 MESSAGE("ERROR : create profile ...");
77 goto ERROR;
78 }
79
80 if (MEDprofileWr(fid, profile2name, profile2size, profile2 ) < 0) {
81 MESSAGE("ERROR : create profile ...");
82 goto ERROR;
83 }
84
85 /* mesh creation : a 2D unstructured mesh */
86 if (MEDmeshCr(fid, meshname, spacedim, meshdim, MED_UNSTRUCTURED_MESH,
87 "A 2D unstructured mesh","",MED_SORT_DTIT,MED_CARTESIAN, axisname, unitname) < 0) {
88 MESSAGE("ERROR : mesh creation ...");
89 goto ERROR;
90 }
91
92 /* initial nodes coordinates in a cartesian axis in full interlace mode
93 (X1,Y1, X2,Y2, X3,Y3, ...)
94 */
95 if (MEDmeshNodeCoordinateWithProfileWr(fid, meshname, MED_NO_DT, MED_NO_IT, 0.0,
96 MED_COMPACT_STMODE, MED_NO_PROFILE,
97 MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,
98 nnodes, initial_coordinates) < 0) {
99 MESSAGE("ERROR : nodes coordinates ...");
100 goto ERROR;
101 }
102
103 /* cells connectiviy is defined in nodal mode */
104 if (MEDmeshElementConnectivityWithProfileWr(fid, meshname, MED_NO_DT, MED_NO_IT, 0.0,
105 MED_CELL, MED_TRIA3, MED_NODAL,
106 MED_COMPACT_STMODE, MED_NO_PROFILE,
107 MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,
108 ntria3, triaconnectivity) < 0) {
109 MESSAGE("ERROR : triangular cells connectivity ...");
110 goto ERROR;
111 }
112
113 if (MEDmeshElementConnectivityWithProfileWr(fid, meshname, MED_NO_DT, MED_NO_IT, 0.0,
114 MED_CELL, MED_QUAD4, MED_NODAL,
115 MED_COMPACT_STMODE, MED_NO_PROFILE,
116 MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,
117 nquad4, quadconnectivity) < 0) {
118 MESSAGE("ERROR : quadrangular cells connectivity ...");
119 goto ERROR;
120 }
121
122 /*
123 * Mesh deformation (nodes coordinates) in 2 steps
124 * The nodes modified are identified by a profile
125 */
126 /* STEP 1 : dt1 = 5.5, it = 1*/
127 if (MEDmeshNodeCoordinateWithProfileWr(fid, meshname, 1, 1, 5.5,
128 MED_COMPACT_STMODE, profile1name,
129 MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,
130 nnodes, new_coordinates_step1 ) < 0) {
131 MESSAGE("ERROR : nodes coordinates ...");
132 goto ERROR;
133 }
134 /* STEP 2 : dt2 = 8.9, it = 1*/
135 if (MEDmeshNodeCoordinateWithProfileWr(fid, meshname, 2, 1, 8.9,
136 MED_COMPACT_STMODE, profile2name,
137 MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,
138 nnodes, new_coordinates_step2 ) < 0) {
139 MESSAGE("ERROR : nodes coordinates ...");
140 goto ERROR;
141 }
142
143 /* create family 0 : by default, all mesh entities family number is 0 */
144 if (MEDfamilyCr(fid, meshname,MED_NO_NAME, 0, 0, MED_NO_GROUP) < 0) {
145 MESSAGE("ERROR : familly 0 creation ...");
146 goto ERROR;
147 }
148
149 ret=0;
150 ERROR:
151
152 /* close MED file */
153 if (MEDfileClose(fid) < 0) {
154 MESSAGE("ERROR : close file ...");
155 ret=-1;
156 }
157
158 return ret;
159 }