UsesCase_MEDfield_10.c

Aller à la documentation de ce fichier.
00001 /*  This file is part of MED.
00002  *
00003  *  COPYRIGHT (C) 1999 - 2015  EDF R&D, CEA/DEN
00004  *  MED is free software: you can redistribute it and/or modify
00005  *  it under the terms of the GNU Lesser General Public License as published by
00006  *  the Free Software Foundation, either version 3 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  MED is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU Lesser General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Lesser General Public License
00015  *  along with MED.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 /* 
00019  * Field use case 10 : write a field in a MED file with computing steps,
00020  *                     profiles, integration points and interpolation families
00021  */
00022 
00023 #include <med.h>
00024 #define MESGERR 1
00025 #include <med_utils.h>
00026 
00027 #include <string.h>
00028 
00029 
00030 int main (int argc, char **argv) {
00031   med_idt fid;
00032   const char meshname[MED_NAME_SIZE+1] = "2D unstructured mesh";
00033   const char fieldname[MED_NAME_SIZE+1] = "TEMPERATURE_FIELD";
00034   const med_int ncomponent = 1;
00035   const char componentname[MED_SNAME_SIZE+1] = "TEMPERATURE";
00036   const char componentunit[MED_SNAME_SIZE+1] = "C";
00037   const med_float tria3values_step1_profile1[9] = {1000.,1010.,1020.,    
00038                                                    4000.,4010.,4020.,    
00039                                                    8000.,8010.,8020. };
00040   const med_float tria3values_step2_profile1[24] = {1500.,1510.,1520.,    
00041                                                     0.,   0.,   0.,
00042                                                     0.,   0.,   0.,
00043                                                     4500.,4510,4520.,
00044                                                     0.,   0.,   0.,
00045                                                     0.,   0.,   0.,
00046                                                     0.,   0.,   0.,
00047                                                     8500., 8510, 8520 };
00048   const med_float tria3values_step2_profile2[32] = {   0.,   0.,   0.,  0.,
00049                                                        2500.,2510.,2520,2530., 
00050                                                        3500.,3510.,3520.,3530.,    
00051                                                        0.,   0.,   0.,  0.,
00052                                                        5500.,5510.,5520.,5530., 
00053                                                        6500.,6510.,6520.,6530., 
00054                                                        7500.,7510.,7520.,7530.,   
00055                                                        0.,   0.,   0.,   0. };
00056   const med_int ntria3 = 8;
00057   const med_int nquad4 = 4;
00058   const med_float quad4values_step1[4] = {10000., 20000., 30000., 40000.};
00059   const med_float quad4values_step2[4] = {15000., 25000., 35000., 45000.};
00060   const char profile1name[MED_NAME_SIZE+1] = "MED_TRIA3_PROFILE1";
00061   const med_int profile1[3] = {1, 4, 8}; 
00062   const med_int profile1size = 3;
00063   const char profile2name[MED_NAME_SIZE+1] = "MED_TRIA3_PROFILE2";
00064   const med_int profile2[5] = {2, 3, 5, 6, 7}; 
00065   const med_int profile2size = 5;
00066   const char localization1name[MED_NAME_SIZE+1] = "TRIA3_INTEGRATION_POINTS_3";
00067   const med_float weight1[3] = {1.0/6, 1.0/6, 1.0/6};
00068   const med_float elementcoordinate[6] = {0.0, 0.0,  1.0, 0.0,  0.0,1.0};
00069   const med_float ipoint1coordinate[6] = {1.0/6, 1.0/6,  2.0/3, 1.0/6,  1.0/6, 2.0/6};
00070   const char localization2name[MED_NAME_SIZE+1] = "TRIA3_INTEGRATION_POINTS_4";
00071   const med_float weight2[6] = {25.0/(24*4), 25.0/(24*4), 25.0/(24*4), -27.0/(24*4)};
00072   const med_float ipoint2coordinate[8] = {1.0/5, 1.0/5,  3.0/5, 1.0/5,  1.0/5, 3.0/5,  1.0/3, 1.0/3};
00073   med_int nipoint, spacedim;
00074   const char interpname[MED_NAME_SIZE+1] = "MED_TRIA3 interpolation family";
00075   int ret=-1;
00076 
00077   /* file creation */
00078   fid = MEDfileOpen("UsesCase_MEDfield_10.med",MED_ACC_CREAT);
00079   if (fid < 0) {
00080     MESSAGE("ERROR : file creation ...");
00081     goto ERROR;
00082   }
00083 
00084   /* create mesh link */
00085   if (MEDlinkWr(fid,meshname,"./UsesCase_MEDmesh_1.med") < 0) {
00086     MESSAGE("ERROR : create mesh link ...");
00087     goto ERROR;
00088   }
00089   
00090   /* create the profiles in the file */
00091   if (MEDprofileWr(fid, profile1name, profile1size, profile1 ) < 0) {
00092     MESSAGE("ERROR : create profile ...");
00093     goto ERROR; 
00094   }
00095 
00096   if (MEDprofileWr(fid, profile2name, profile2size, profile2 ) < 0) {
00097     MESSAGE("ERROR : create profile ...");
00098     goto ERROR; 
00099   }
00100 
00101   /* create the localization elements for integration points */
00102   spacedim = 2;
00103   nipoint = 3;
00104   if (MEDlocalizationWr(fid, localization1name, MED_TRIA3, spacedim, 
00105                         elementcoordinate, MED_FULL_INTERLACE, 
00106                         nipoint, ipoint1coordinate, weight1,
00107                         MED_NO_INTERPOLATION, MED_NO_MESH_SUPPORT) < 0) {
00108     MESSAGE("ERROR : create famlily of integration points ...");
00109     goto ERROR; 
00110   }
00111 
00112   spacedim = 2;
00113   nipoint = 4;
00114   if (MEDlocalizationWr(fid, localization2name, MED_TRIA3, spacedim, 
00115                         elementcoordinate, MED_FULL_INTERLACE, 
00116                         nipoint, ipoint2coordinate, weight2, 
00117                         MED_NO_INTERPOLATION, MED_NO_MESH_SUPPORT) < 0) {
00118     MESSAGE("ERROR : create famlily of integration points ...");
00119     goto ERROR; 
00120   }
00121 
00122   /* 
00123    * Temperature field  creation : 
00124    * - 1 component 
00125    * - component unit : celsius degree
00126    * - mesh is the 2D unstructured mesh of UsecaseMEDmesh_1.c use case.
00127    * - computation step unit in 'ms'
00128    */ 
00129   if (MEDfieldCr(fid, fieldname, MED_FLOAT64, 
00130                  ncomponent, componentname, componentunit,
00131                  "ms", meshname) < 0) {
00132     MESSAGE("ERROR : create field");
00133     goto ERROR;
00134   }
00135 
00136   /* write interpolation family name for MED_TRIA3 cell type */
00137   /* The interpolation family "interpname" is created in the UsesCase_MEDinterp_1 
00138      use case */
00139   if (MEDfieldInterpWr(fid,fieldname,interpname) <0) {
00140     MESSAGE("ERROR : write field interpolation family name ...");
00141     goto ERROR;
00142   }  
00143   
00144   /* two computation steps */
00145   /* write values at cell centers : 8 MED_TRIA3 and 4 MED_QUAD4 */
00146 
00147   /* STEP 1 : dt1 = 5.5, it = 1*/
00148   /* MED_TRIA3 : with a profile of 3 values in compact memory storage mode 
00149      and a family of 3 integration points */
00150   if (MEDfieldValueWithProfileWr(fid, fieldname, 1, 1, 5.5, MED_CELL,MED_TRIA3, 
00151                                  MED_COMPACT_PFLMODE, profile1name, localization1name,    
00152                                  MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, 
00153                                  ntria3, (unsigned char*) tria3values_step1_profile1) < 0) {
00154     MESSAGE("ERROR : write field values on MED_TRIA3");
00155     goto ERROR;
00156   }
00157    /* MED_QUAD4  : with no profile */ 
00158   if (MEDfieldValueWithProfileWr(fid, fieldname, 1, 1, 5.5, MED_CELL, MED_QUAD4, 
00159                                  MED_COMPACT_PFLMODE, MED_NO_PROFILE, MED_NO_LOCALIZATION,
00160                                  MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, 
00161                                  nquad4, (unsigned char*) quad4values_step1) < 0) {
00162     MESSAGE("ERROR : write field values on MED_QUAD4 ");
00163     goto ERROR;
00164   }
00165 
00166   /* STEP 2 : dt2 = 8.9, it = 1*/
00167   /* MED_TRIA3 : with a profile of 3 values then a profile of 5 values in global memory storage mode 
00168    * For each profile, a family of 3 and then 4 integration points */
00169   if (MEDfieldValueWithProfileWr(fid, fieldname, 2 , 1 , 8.9 , MED_CELL, MED_TRIA3, 
00170                                  MED_GLOBAL_PFLMODE, profile1name, localization1name,    
00171                                  MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,  
00172                                  ntria3, (unsigned char*) tria3values_step2_profile1) < 0) {
00173     MESSAGE("ERROR : write field values on MED_TRIA3 ...");
00174     goto ERROR;
00175   }
00176   if (MEDfieldValueWithProfileWr(fid, fieldname, 2 , 1 , 8.9 , MED_CELL, MED_TRIA3, 
00177                                  MED_GLOBAL_PFLMODE, profile2name, localization2name,    
00178                                  MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,  
00179                                  ntria3, (unsigned char*) tria3values_step2_profile2) < 0) {
00180     MESSAGE("ERROR : write field values on MED_TRIA3 ...");
00181     goto ERROR;
00182   }
00183 
00184   /* MED_QUAD4 : with no profile */
00185   if (MEDfieldValueWithProfileWr(fid, fieldname, 2, 1, 8.9, MED_CELL, MED_QUAD4, 
00186                                  MED_COMPACT_PFLMODE, MED_NO_PROFILE, MED_NO_LOCALIZATION,
00187                                  MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,  
00188                                  nquad4, (unsigned char*) quad4values_step2) < 0) {
00189     MESSAGE("ERROR : write field values on MED_QUAD4 ... ");
00190     goto ERROR;
00191   }
00192 
00193   ret=0;
00194  ERROR:
00195   
00196   /* close file */
00197   if (MEDfileClose(fid) < 0) {
00198     MESSAGE("ERROR : close file ...");             
00199     ret=-1; 
00200   } 
00201   
00202   return ret;
00203 }
00204 

Généré le Thu Oct 8 14:26:17 2015 pour MED fichier par  doxygen 1.6.1