Back to index

salome-med  6.5.0
Classes | Namespaces | Functions
MEDMEMTest.hxx File Reference
#include "MEDMEMCppTestExport.hxx"
#include "MEDMEMTest_Utils.hxx"
#include <cppunit/extensions/HelperMacros.h>
#include "MEDMEM_Field.hxx"
#include <set>
#include <string>
#include <iostream>

Go to the source code of this file.

Classes

protocol  MEDMEMCPPTEST_EXPORT
protocol  MEDMEMCPPTEST_EXPORT

Namespaces

namespace  MEDMEM
 A template class to generate an array of any particular type (int, long, float, double) for our purpose in the MED++ library.

Functions

MEDMEMCPPTEST_EXPORT MEDMEM::MESH * MEDMEMTest_createTestMesh ()
 Check methods (not in spec), defined in MEDMEM_medimport_src.hxx:
template<class T >
void MEDMEMTest_DumpArray (std::ostream &stream, const T *array, const int length, const std::string text)
 Tool to print array to stream.

Function Documentation

Check methods (not in spec), defined in MEDMEM_medimport_src.hxx:

Create a mesh with certain filling .n4 | | n16,n12,n8.---------.n7,n11,n15 | | | | | | n5.----|----.----|----.n3 | | | | | | n17,n13,n9.---------.n10,n14,n18 | | .n6

.n19 (0,0,5) | | | | n16.--|-.----.n15 / |/ / . . . / /| / n17.----.----.n18 | | n12.--|-.----.n11 / |/ / . . . / /| / n13.----.----.n14 | | n8.--|-.----.n7 / |/ / . . . / /| / n9.----.----.n10 | .n4 (0,2,1) | / | . |/ n5.----.----.----.----.n3 (2,0,1) (-2,0,1) /n2 (0,0,1) . | / | .n6 | | | .n1 (0,0,0)

Definition at line 431 of file MEDMEMTest.cxx.

{
  // MESH DATA
  int SpaceDimension = 3;

  // coordinates
  int NumberOfNodes = 19;

  string Names[3] = { "X","Y","Z" };
  string Units[3] = { "cm","cm","cm" };

  double Coordinates[57] = {
     0.0,  0.0, 0.0, // n1
     0.0,  0.0, 1.0, // n2
     2.0,  0.0, 1.0, // n3
     0.0,  2.0, 1.0, // n4
    -2.0,  0.0, 1.0, // n5
     0.0, -2.0, 1.0, // n6
     1.0,  1.0, 2.0, // n7
    -1.0,  1.0, 2.0, // n8
    -1.0, -1.0, 2.0, // n9
     1.0, -1.0, 2.0, // n10
     1.0,  1.0, 3.0, // n11
    -1.0,  1.0, 3.0, // n12
    -1.0, -1.0, 3.0, // n13
     1.0, -1.0, 3.0, // n14
     1.0,  1.0, 4.0, // n15
    -1.0,  1.0, 4.0, // n16
    -1.0, -1.0, 4.0, // n17
     1.0, -1.0, 4.0, // n18
     0.0,  0.0, 5.0  // n19
  };

  // cells connectivities
  const int NumberOfCellTypes = 3;
  MED_EN::medGeometryElement CellTypes[NumberOfCellTypes] =
    {MED_EN::MED_TETRA4, MED_EN::MED_PYRA5, MED_EN::MED_HEXA8};
  const int NumberOfCells[NumberOfCellTypes] = {12, 2, 2};

  int ConnectivityTetra[12 * 4] = {
    1,2,3,6,
    1,2,4,3,
    1,2,5,4,
    1,2,6,5,
    2,7,4,3,
    2,8,5,4,
    2,9,6,5,
    2,10,3,6,
    2,7,3,10,
    2,8,4,7,
    2,9,5,8,
    2,10,6,9
  };

  int ConnectivityPyra[2 * 5] = {
    7,8,9,10,2,
    15,18,17,16,19
  };

  int ConnectivityHexa[2 * 8] = {
    11,12,13,14,7,8,9,10,
    15,16,17,18,11,12,13,14
  };

  // faces connectivities
  const int NumberOfFaceTypes = 2;
  MED_EN::medGeometryElement FaceTypes[NumberOfFaceTypes] = {MED_EN::MED_TRIA3, MED_EN::MED_QUAD4};
  const int NumberOfFaces[NumberOfFaceTypes] = {4, 4};

  int ConnectivityTria[4 * 3] = {
    1,4,3,
    1,5,4,
    1,6,5,
    1,3,6
  };

  int ConnectivityQua[4 * 4] = {
    7,8,9,10,
    11,12,13,14,
    11,7,8,12,
    12,8,9,13
  };


  // CREATE THE MESH
  MEDMEM::MESHING* myMeshing = new MEDMEM::MESHING;

  myMeshing->setName("meshing");

  myMeshing->setCoordinates(SpaceDimension, NumberOfNodes, Coordinates,
                           "CARTESIAN", MED_EN::MED_FULL_INTERLACE);
  myMeshing->setCoordinatesNames(Names);
  myMeshing->setCoordinatesUnits(Units);

  // define connectivities
  myMeshing->setNumberOfTypes(NumberOfCellTypes, MED_EN::MED_CELL);
  myMeshing->setTypes(CellTypes, MED_EN::MED_CELL);
  myMeshing->setNumberOfElements(NumberOfCells, MED_EN::MED_CELL);

  myMeshing->setConnectivity(MED_EN::MED_CELL, MED_EN::MED_TETRA4, ConnectivityTetra );
  myMeshing->setConnectivity(MED_EN::MED_CELL, MED_EN::MED_PYRA5 , ConnectivityPyra  );
  myMeshing->setConnectivity(MED_EN::MED_CELL, MED_EN::MED_HEXA8 , ConnectivityHexa  );

  myMeshing->setNumberOfTypes(NumberOfFaceTypes, MED_EN::MED_FACE);
  myMeshing->setTypes(FaceTypes, MED_EN::MED_FACE);
  myMeshing->setNumberOfElements(NumberOfFaces, MED_EN::MED_FACE);

  myMeshing->setConnectivity(MED_EN::MED_FACE, MED_EN::MED_TRIA3,ConnectivityTria);
  myMeshing->setConnectivity(MED_EN::MED_FACE, MED_EN::MED_QUAD4,ConnectivityQua);

  // edges connectivities
  // not yet implemented : if set, results are unpredictable.

  // groups of nodes
  {
    MEDMEM::GROUP *myGroup=new MEDMEM::GROUP;
    myGroup->setName("SomeNodes");
    myGroup->setMesh(myMeshing);
    myGroup->setEntity(MED_EN::MED_NODE);
    myGroup->setNumberOfGeometricType(1);
    MED_EN::medGeometryElement myTypes[1] = {MED_EN::MED_NONE};
    myGroup->setGeometricType(myTypes);
    const int myNumberOfElements[1] = {4};
    myGroup->setNumberOfElements(myNumberOfElements);
    const int index[1+1] = {1,5};
    const int value[4] = {1,4,5,7};
    myGroup->setNumber(index,value);
    myMeshing->addGroup(*myGroup);
    myGroup->removeReference();
  }
  {
    MEDMEM::GROUP *myGroup=new MEDMEM::GROUP;
    myGroup->setName("OtherNodes");
    myGroup->setMesh(myMeshing);
    myGroup->setEntity(MED_EN::MED_NODE);
    myGroup->setNumberOfGeometricType(1);
    MED_EN::medGeometryElement myTypes[1] = {MED_EN::MED_NONE};
    myGroup->setGeometricType(myTypes);
    const int myNumberOfElements[1] = {3};
    myGroup->setNumberOfElements(myNumberOfElements);
    const int index[1+1] = {1,4};
    const int value[3] = {2,3,6};
    myGroup->setNumber(index,value);
    myMeshing->addGroup(*myGroup);
    myGroup->removeReference();
  }

  // groups of cells
  {
    MEDMEM::GROUP *myGroup=new MEDMEM::GROUP;
    myGroup->setName("SomeCells");
    myGroup->setMesh(myMeshing);
    myGroup->setEntity(MED_EN::MED_CELL);
    myGroup->setNumberOfGeometricType(3);
    MED_EN::medGeometryElement myTypes[3] = {MED_EN::MED_TETRA4,MED_EN::MED_PYRA5,MED_EN::MED_HEXA8};
    myGroup->setGeometricType(myTypes);
    const int myNumberOfElements[3] = {4,1,2};
    myGroup->setNumberOfElements(myNumberOfElements);
    const int index[3+1] = {1,5,6,8};
    const int value[4+1+2] = {2,7,8,12,  13,  15,16};
    myGroup->setNumber(index,value);
    myMeshing->addGroup(*myGroup);
    myGroup->removeReference();
  }
  {
    MEDMEM::GROUP *myGroup=new MEDMEM::GROUP;
    myGroup->setName("OtherCells");
    myGroup->setMesh(myMeshing);
    myGroup->setEntity(MED_EN::MED_CELL);
    myGroup->setNumberOfGeometricType(2);
    MED_EN::medGeometryElement myTypes[] = {MED_EN::MED_TETRA4,MED_EN::MED_PYRA5};
    myGroup->setGeometricType(myTypes);
    const int myNumberOfElements[] = {4,1};
    myGroup->setNumberOfElements(myNumberOfElements);
    const int index[2+1] = {1,5,6};
    const int value[4+1] = {3,4,5,9,  14};
    myGroup->setNumber(index,value);
    myMeshing->addGroup(*myGroup);
    myGroup->removeReference();
  }

  // groups of faces
  {
    MEDMEM::GROUP *myGroup=new MEDMEM::GROUP;
    myGroup->setName("SomeFaces");
    myGroup->setMesh(myMeshing);
    myGroup->setEntity(MED_EN::MED_FACE);
    myGroup->setNumberOfGeometricType(2);
    MED_EN::medGeometryElement myTypes[2] = {MED_EN::MED_TRIA3,MED_EN::MED_QUAD4};
    myGroup->setGeometricType(myTypes);
    const int myNumberOfElements[2] = {2,3};
    myGroup->setNumberOfElements(myNumberOfElements);
    const int index[2+1] = {1,3,6};
    const int value[2+3] = {2,4,  5,6,8};
    myGroup->setNumber(index,value);
    myMeshing->addGroup(*myGroup);
    myGroup->removeReference();
  }
  {
    MEDMEM::GROUP *myGroup=new MEDMEM::GROUP;
    myGroup->setName("OtherFaces");
    myGroup->setMesh(myMeshing);
    myGroup->setEntity(MED_EN::MED_FACE);
    myGroup->setNumberOfGeometricType(1);
    MED_EN::medGeometryElement myTypes[1] = {MED_EN::MED_TRIA3};
    myGroup->setGeometricType(myTypes);
    const int myNumberOfElements[1] = {2};
    myGroup->setNumberOfElements(myNumberOfElements);
    const int index[1+1] = {1,3};
    const int value[2] = {1,3};
    myGroup->setNumber(index,value);
    myMeshing->addGroup(*myGroup);
    myGroup->removeReference();
  }

  return myMeshing;
}

Here is the caller graph for this function:

template<class T >
void MEDMEMTest_DumpArray ( std::ostream &  stream,
const T *  array,
const int  length,
const std::string  text 
)

Tool to print array to stream.

Definition at line 218 of file MEDMEMTest.hxx.

{
  stream << text << ": {";
  if (length > 0) {
    stream << array[0];
    for (int i = 1; i < length; i++) {
      stream << ", " << array[i];
    }
  }
  stream << "}" << std::endl;
}