# UsesCase_MEDfield_17.c

Aller à la documentation de ce fichier.

    00001 /*  This file is part of MED.
    00002  *
    00003  *  COPYRIGHT (C) 1999 - 2011  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 17 : write a field in a MED file with
    00020  *                     values defined on integration points
    00021  *                     on struct elements
    00022  */
    00023
    00024 #include <med.h>
    00025 #define MESGERR 1
    00026 #include <med_utils.h>
    00027
    00028 #include <string.h>
    00029
    00030
    00031 int main (int argc, char **argv) {
    00032   med_idt fid=0,mfid=0,sfid=0;
    00033   const med_int spacedim = 3;
    00034   const char meshname[MED_NAME_SIZE+1] = "COMPUT_MESH";
    00035   const char fieldname[MED_NAME_SIZE+1] = "TEMPERATURE";
    00036   const med_int ncomponent = 1;
    00037   /*                                      1234567890123456123456*/
    00038   const char componentname[MED_SNAME_SIZE+1] = "TEMP            ";
    00039   const char componentunit[MED_SNAME_SIZE+1] = "CELSIUS         ";
    00040   med_geometry_type geotype=MED_NONE;
    00041   const med_int nbeam = 1;
    00042   char structelementname[MED_NAME_SIZE+1];
    00043   const med_float tempvalue[3*1*4] = { 1.1, 2.2, 3.3, 4.4,
    00044                                        5.5, 6.6, 7.7, 8.8,
    00045                                        9.9, 10.1,11.11, 12.12};
    00046   const char localization[MED_NAME_SIZE+1] = "BEAM_INTEGRATION_POINTS";
    00047   const char localization2[MED_NAME_SIZE+1] = "BEAM_INTEGRATION_TRANSF";
    00048   const med_float elementcoordinate[3*3] = { 0.0,0.0,0.0,
    00049                                              0.0,0.0,0.0,
    00050                                              0.0,0.0,0.0,};
    00051   const med_float ipointcoordinate[3*3] = { 0.0,0.0,2.5,
    00052                                             0.0,0.0,3.5,
    00053                                             0.0,0.0,4.5};
    00054   const med_float weight[4] = {1.0/4, 1.0/4, 1.0/4, 1.0/4};
    00055   const char beamsectionname[MED_NAME_SIZE+1]="BEAM_SECTION_MESH";
    00056   const med_int nipoint = 3;
    00057   char interpname[MED_NAME_SIZE+1] = "geometrical transformation";
    00058   const med_int nbofvariable=2;
    00059   const med_int maxdegree=1;
    00060   const med_int nmaxcoefficient=3;
    00061   const med_int         nbofcoefficient1_1 = 3;
    00062   const med_int   const power1_1[]         = {0,0,1,0,0,1};
    00063   const med_float const coefficient1_1[]   = {1,-1,-1};
    00064   const med_int         nbofcoefficient1_2 = 1;
    00065   const med_int   const power1_2[]         = {1,0};
    00066   const med_float const coefficient1_2[]   = {1};
    00067   const med_int         nbofcoefficient1_3 = 1;
    00068   const med_int   const power1_3[]         = {0,1};
    00069   const med_float const coefficient1_3[]   = {1};
    00070   int ret=-1;
    00071
    00072
    00073   /* Open file to write the field */
    00074   fid = MEDfileOpen("UsesCase_MEDfield_17.med",MED_ACC_CREAT);
    00075   if (fid < 0) {
    00076     MESSAGE("ERROR : file creation ...");
    00077     goto ERROR;
    00078   }
    00079
    00080   if (( mfid=MEDfileObjectsMount(fid,  "UsesCase_MEDstructElement_1.med",MED_MESH_SUPPORT)) < 0 ) {
    00081     MESSAGE("ERROR : file mounting ...");
    00082     goto ERROR;
    00083   }
    00084
    00085   if (( sfid=MEDfileObjectsMount(fid,  "UsesCase_MEDstructElement_1.med",MED_ELSTRUCT)) < 0 ) {
    00086     MESSAGE("ERROR : file mounting ...");
    00087     goto ERROR;
    00088   }
    00089
    00090   /* Create mesh link */
    00091   if (MEDlinkWr(fid,meshname,"./UsesCase_MEDstructElement_1.med") < 0) {
    00092     MESSAGE("ERROR : create mesh link ...");
    00093     goto ERROR;
    00094   }
    00095
    00096   /*
    00097    * Read struct element geometric type
    00098    */
    00099   strcpy(structelementname,MED_BEAM_NAME);
    00100   geotype = MEDstructElementGeotype(fid,structelementname);
    00101
    00102
    00103   /* create a geometrical transformation fonction */
    00104   if (MEDinterpCr(fid, interpname, geotype, MED_FALSE, nbofvariable, maxdegree, nmaxcoefficient) < 0) {
    00105     MESSAGE("ERROR : interpolation family creation ...");
    00106     goto ERROR;
    00107   }
    00108   /* Basis functions creation */
    00109   if (MEDinterpBaseFunctionWr(fid,interpname,1,nbofcoefficient1_1,power1_1,coefficient1_1) < 0) {
    00110     MESSAGE("ERROR : first base function creation ...");
    00111     goto ERROR;
    00112   }
    00113
    00114   if (MEDinterpBaseFunctionWr(fid,interpname,2,nbofcoefficient1_2,power1_2,coefficient1_2) < 0) {
    00115     MESSAGE("ERROR : second base function creation ...");
    00116     goto ERROR;
    00117   }
    00118
    00119   if (MEDinterpBaseFunctionWr(fid,interpname,3,nbofcoefficient1_3,power1_3,coefficient1_3) < 0) {
    00120     MESSAGE("ERROR : third base function creation ...");
    00121     goto ERROR;
    00122   }
    00123
    00124
    00125   /* create the families of integration points
    00126      for the struct element */
    00127   if (MEDlocalizationWr(fid, localization, geotype, spacedim,
    00128                         elementcoordinate, MED_FULL_INTERLACE,
    00129                         nipoint, ipointcoordinate, weight,
    00130                         MED_NO_INTERPOLATION, beamsectionname) < 0) {
    00131     MESSAGE("ERROR : create famlily of integration points ...");
    00132     goto ERROR;
    00133   }
    00134
    00135   if (MEDlocalizationWr(fid, localization2, geotype, spacedim,
    00136                         elementcoordinate, MED_FULL_INTERLACE,
    00137                         nipoint, ipointcoordinate, weight,
    00138                         interpname, beamsectionname) < 0) {
    00139     MESSAGE("ERROR : create famlily of integration points ...");
    00140     goto ERROR;
    00141   }
    00142
    00143   /*
    00144    * Temperature  field creation for beam struct element :
    00145    * - 1 component, 3 integration points, 4 cells in the support mesh for each
    00146    *   the section of each integration point
    00147    * - mesh is the 3D computation mesh of UsesCase_MEDstructElement_1 use case.
    00148    */
    00149   if (MEDfieldCr(fid, fieldname, MED_FLOAT64,
    00150                  ncomponent, componentname, componentunit,
    00151                  "ms", meshname) < 0) {
    00152     MESSAGE("ERROR : create field");
    00153     goto ERROR;
    00154   }
    00155
    00156   if (MEDfieldValueWithProfileWr(fid, fieldname, MED_NO_DT, MED_NO_IT, MED_UNDEF_DT,
    00157                                  MED_STRUCT_ELEMENT, geotype,
    00158                                  MED_COMPACT_PFLMODE, MED_NO_PROFILE, localization,
    00159                                  MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,
    00160                                  nbeam, (unsigned char*) tempvalue) < 0) {
    00161     MESSAGE("ERROR : write field values on MED_BEAM ");
    00162     goto ERROR;
    00163   }
    00164
    00165   if (MEDfieldValueWithProfileWr(fid, fieldname, MED_NO_DT, 1, MED_UNDEF_DT,
    00166                                  MED_STRUCT_ELEMENT, geotype,
    00167                                  MED_COMPACT_PFLMODE, MED_NO_PROFILE, localization2,
    00168                                  MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,
    00169                                  nbeam, (unsigned char*) tempvalue) < 0) {
    00170     MESSAGE("ERROR : write field values on MED_BEAM ");
    00171     goto ERROR;
    00172   }
    00173
    00174   /* unmount file objects */
    00175
    00176  if ( MEDfileObjectsUnmount(fid, sfid, MED_ELSTRUCT) < 0 ) {
    00177     MESSAGE("ERROR : file unmounting ...");
    00178     goto ERROR;
    00179   }
    00180
    00181   if ( MEDfileObjectsUnmount(fid, mfid, MED_MESH_SUPPORT) < 0 ) {
    00182     MESSAGE("ERROR : file unmounting ...");
    00183     goto ERROR;
    00184   }
    00185
    00186   ret=0;
    00187  ERROR:
    00188
    00189   /* close file */
    00190   if (MEDfileClose(fid) < 0) {
    00191     MESSAGE("ERROR : close file ...");
    00192     ret=-1;
    00193   }
    00194
    00195   return ret;
    00196 }
    00197