Back to index

salome-paravis  6.5.0
Defines | Functions
TestMedPolyhedron.cxx File Reference
#include <med.h>
#include <med_utils.h>
#include <string.h>

Go to the source code of this file.

Defines

#define MESGERR   1

Functions

int main (int argc, char **argv)

Define Documentation

#define MESGERR   1

Definition at line 28 of file TestMedPolyhedron.cxx.


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 33 of file TestMedPolyhedron.cxx.

                                 {
  med_idt fid;
  const char meshname[MED_NAME_SIZE+1] = "3D unstructured mesh";
  const med_int spacedim = 3;
  const med_int meshdim = 3;
  /*                                         12345678901234561234567890123456 */
  const char axisname[3*MED_SNAME_SIZE+1] = "x               y               z               ";
  const char unitname[3*MED_SNAME_SIZE+1] = "cm              cm              cm              ";
  const med_int nnodes = 12;
  const med_float coordinates[3 * 12] =
          { 1.618,  1.,     0.,
           -1.618,  1.,     0.,
            1.618, -1.,     0.,
           -1.618, -1.,     0.,
            1.,     0.,     1.618,
            1.,     0.,    -1.618,
           -1.,     0.,     1.618,
           -1.,     0.,    -1.618,
            0.,  1.618,     1.,
            0., -1.618,     1.,
            0.,  0,    0.,
//            0.,  1.618,    -1.,
            0., -1.618,    -1.  };
  const med_int faceIndexSize = 2;
  const med_int faceindex[2] = {1,22};
  const med_int nodeIndexSize = 21;
  /* connectivity : 1 icosahedron */
  const med_int nodeindex[21] = { 1, 4, 7,10,13,16,19,22,25,28,
                                 31,34,37,40,43,46,49,52,55,58,61 };
  const med_int connectivity[60] = { 1,  9,  5,
                                     1,  6, 11,
                                     3,  5, 10,
                                     3, 12,  6,
                                     2,  7,  9,
                                     2, 11,  8,
                                     4, 10,  7,
                                     4,  8, 12,
                                     1, 11,  9,
                                     2,  9, 11,
                                     3, 10, 12,
                                     4, 10, 12,
                                     5,  3,  1,
                                     6,  1,  3,
                                     7,  2,  4,
                                     8,  4,  2,
                                     9,  7,  5,
                                    10,  5,  7,
                                    11,  6,  8,
                                    12,  8,  6  };

  /* open MED file */
  fid = MEDfileOpen("UsesCase_MEDmesh_15.med",
        MED_ACC_CREAT);
  if (fid < 0) {
    MESSAGE("ERROR : file creation ...");
    return -1;
  }

  /* write a comment in the file */
  if (MEDfileCommentWr(fid,
           "A 3D unstructured mesh : 1 icosahedron") < 0) {
    MESSAGE("ERROR : write file description ...");
    return -1;
  }

  /* mesh creation : a 3D unstructured mesh */
  if (MEDmeshCr(fid,
    meshname,
    spacedim,
    meshdim,
    MED_UNSTRUCTURED_MESH,
    "A 3D mesh with 1 icosahedron",
    "",
    MED_SORT_DTIT,
    MED_CARTESIAN,
    axisname,
    unitname) < 0) {
    MESSAGE("ERROR : mesh creation ...");
    return -1;
  }

  /* nodes coordinates in a cartesian axis in full interlace mode
     (X1,Y1, X2,Y2, X3,Y3, ...) with no iteration and computation step
  */
  if (MEDmeshNodeCoordinateWr(fid,
            meshname,
            MED_NO_DT,
            MED_NO_IT,
            MED_UNDEF_DT,
            MED_FULL_INTERLACE,
            nnodes,
            coordinates) < 0) {
    MESSAGE("ERROR : nodes coordinates ...");
    return -1;
  }

  /* cells connectiviy is defined in nodal mode */
  /* 1 icosahedron */
  if (MEDmeshPolyhedronWr(fid,
              meshname,
              MED_NO_DT,
              MED_NO_IT,
              MED_UNDEF_DT,
              MED_CELL,
              MED_NODAL,
              faceIndexSize,
              faceindex,
              nodeIndexSize,
              nodeindex,
              connectivity) < 0) {
    MESSAGE("ERROR : polyhedron connectivity ...");
    return -1;
  }

  /* create family 0 : by default, all mesh entities family number is 0 */
  if (MEDfamilyCr(fid,
      meshname,
      "",
      0,
      0,
      "") < 0) {
    MESSAGE("ERROR : quadrangular cells connectivity ...");
    return -1;
  }

  /* close MED file */
  if (MEDfileClose(fid)  < 0) {
    MESSAGE("ERROR : close file ...");
    return -1;
  }

  return 0;
}