00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 #include <med.h>
00026 #define MESGERR 1
00027 #include <med_utils.h>
00028 
00029 #include <string.h>
00030 
00031 int main (int argc, char **argv) {
00032   med_idt fid;
00033   const char meshname[MED_NAME_SIZE+1] = "2D unstructured mesh";
00034   const med_int spacedim = 2;
00035   const med_int meshdim = 2;
00036   const char axisname[2*MED_SNAME_SIZE+1] = "x               y               ";
00037   const char unitname[2*MED_SNAME_SIZE+1] = "cm              cm              ";
00038   const med_float initial_coordinates[30] = { 2.,1.,  7.,1.,  12.,1.,  17.,1.,  22.,1.,
00039                                               2.,6.,  7.,6.,  12.,6.,  17.,6.,  22.,6.,
00040                                               2.,11., 7.,11., 12.,11., 17.,11., 22.,11.};
00041   const med_int nnodes = 15;
00042   const med_int triaconnectivity[24] = { 1,7,6,   2,7,1,  3,7,2,   8,7,3,   
00043                                          13,7,8, 12,7,13, 11,7,12, 6,7,11 };
00044   const med_int ntria3 = 8;
00045   const med_int quadconnectivity[16] = {3,4,9,8,    4,5,10,9, 
00046                                         15,14,9,10, 13,8,9,14};
00047   const med_int nquad4 = 4;
00048   
00049   const med_float new_coordinates_step1 [6] = { 12.,15., 17.,15., 22.,15.};
00050   const char profile1name[MED_NAME_SIZE+1] = "UPPER_QUAD4_PROFILE";
00051   const med_int profile1[3] = {13, 14, 15}; 
00052   const med_int profile1size = 3;
00053   
00054   const med_float new_coordinates_step2 [6] = { 12.,10., 17.,10., 22.,10.};
00055   const char profile2name[MED_NAME_SIZE+1] = "MIDDLE_QUAD4_PROFILE";
00056   const med_int profile2[3] = {8, 9, 10}; 
00057   const med_int profile2size = 3;
00058   int ret=-1;
00059   
00060   
00061   
00062   fid = MEDfileOpen("UsesCase_MEDmesh_6.med",MED_ACC_CREAT);
00063   if (fid < 0) {
00064     MESSAGE("ERROR : file creation ...");
00065     goto ERROR;
00066   }
00067 
00068   
00069   if (MEDfileCommentWr(fid,"A 2D unstructured mesh : 15 nodes, 12 cells") < 0) {
00070     MESSAGE("ERROR : write file description ...");
00071     goto ERROR;
00072   }
00073 
00074   
00075   if (MEDprofileWr(fid, profile1name, profile1size, profile1 ) < 0) {
00076     MESSAGE("ERROR : create profile ...");
00077     goto ERROR; 
00078   }
00079 
00080   if (MEDprofileWr(fid, profile2name, profile2size, profile2 ) < 0) {
00081     MESSAGE("ERROR : create profile ...");
00082     goto ERROR; 
00083   }
00084   
00085   
00086   if (MEDmeshCr(fid, meshname, spacedim, meshdim, MED_UNSTRUCTURED_MESH, 
00087                 "A 2D structured mesh","",MED_SORT_DTIT,MED_CARTESIAN, axisname, unitname) < 0) {
00088     MESSAGE("ERROR : mesh creation ...");
00089     goto ERROR;
00090   }
00091 
00092   
00093 
00094 
00095   if (MEDmeshNodeCoordinateWithProfileWr(fid, meshname, MED_NO_DT, MED_NO_IT, 0.0,
00096                                          MED_COMPACT_PFLMODE, MED_NO_PROFILE,
00097                                          MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,
00098                                          nnodes, initial_coordinates) < 0) {
00099     MESSAGE("ERROR : nodes coordinates ...");
00100     goto ERROR;
00101   }
00102 
00103   
00104   if (MEDmeshElementConnectivityWithProfileWr(fid, meshname, MED_NO_DT, MED_NO_IT, 0.0,
00105                                               MED_CELL, MED_TRIA3, MED_NODAL, 
00106                                               MED_COMPACT_PFLMODE, MED_NO_PROFILE,
00107                                               MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, 
00108                                               ntria3, triaconnectivity) < 0) {
00109     MESSAGE("ERROR : triangular cells connectivity ...");
00110     goto ERROR;
00111   }
00112 
00113   if (MEDmeshElementConnectivityWithProfileWr(fid, meshname, MED_NO_DT, MED_NO_IT, 0.0,
00114                                               MED_CELL, MED_QUAD4, MED_NODAL, 
00115                                               MED_COMPACT_PFLMODE, MED_NO_PROFILE,
00116                                               MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,  
00117                                               nquad4, quadconnectivity) < 0) {
00118     MESSAGE("ERROR : quadrangular cells connectivity ..."); 
00119     goto ERROR;
00120   }
00121 
00122   
00123 
00124 
00125  
00126   
00127   if (MEDmeshNodeCoordinateWithProfileWr(fid, meshname, 1, 1, 5.5,
00128                                          MED_COMPACT_PFLMODE, profile1name,
00129                                          MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,
00130                                          nnodes, new_coordinates_step1 ) < 0) {
00131     MESSAGE("ERROR : nodes coordinates ...");
00132     goto ERROR;
00133   }
00134   
00135   if (MEDmeshNodeCoordinateWithProfileWr(fid, meshname, 2, 1, 8.9,
00136                                          MED_COMPACT_PFLMODE, profile2name,
00137                                          MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,
00138                                          nnodes, new_coordinates_step2 ) < 0) {
00139     MESSAGE("ERROR : nodes coordinates ...");
00140     goto ERROR;
00141   }
00142 
00143   
00144   if (MEDfamilyCr(fid, meshname,MED_NO_NAME, 0, 0, MED_NO_GROUP) < 0) {
00145     MESSAGE("ERROR : quadrangular cells connectivity ...");
00146     goto ERROR;
00147   }
00148   
00149   ret=0;
00150  ERROR:
00151   
00152   
00153   if (MEDfileClose(fid)  < 0) {
00154     MESSAGE("ERROR : close file ...");
00155     ret=-1;
00156   }
00157 
00158   return ret;
00159 }