Back to index

salome-med  6.5.0
MEDMeshMaker.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "MEDMeshMaker.hxx"
00021 
00022 #include "MEDMEM_Mesh.hxx"
00023 #include "MEDMEM_Meshing.hxx"
00024 
00025 MEDMEM::MESH* MEDMeshMaker(int dim, int nbedge, MED_EN::medGeometryElement type)
00026 {
00027   MEDMEM::MESHING* mesh=new MEDMEM::MESHING();
00028   int nbnodes;
00029   int nbelems;
00030   switch (dim)
00031     {
00032     case 2: 
00033       nbnodes=(nbedge+1)*(nbedge+1);
00034       if(type==MED_EN::MED_QUAD4)
00035         nbelems=(nbedge*nbedge);
00036       else
00037         throw MEDMEM::MEDEXCEPTION("MEDMeshMaker: type not impletmented");
00038       break;
00039     case 3:
00040       nbnodes=(nbedge+1)*(nbedge+1)*(nbedge+1);
00041       if (type==MED_EN::MED_HEXA8)
00042         nbelems= nbedge*nbedge*nbedge;
00043       else
00044         throw MEDMEM::MEDEXCEPTION("MEDMeshMaker: type not impletmented");
00045       break;
00046     }
00047   double* coords = new double[dim*nbnodes];
00048   int nz;
00049   if (dim==2) nz =1; else nz=nbedge+1;
00050   {
00051     for (int ix=0; ix < nbedge+1; ix++)
00052       for (int iy=0; iy<nbedge+1; iy++)
00053         for (int iz=0; iz<nz;iz++)
00054           {
00055             int inode=(ix*(nbedge+1)*nz+iy*nz+iz);
00056             coords[inode*dim]=double(ix)/double(nbedge);
00057             coords[inode*dim+1]=double(iy)/double(nbedge);
00058             if (dim==3)
00059               coords[inode*dim+2]=double(iz)/double(nbedge);
00060           }
00061   }
00062   mesh->setCoordinates(dim, nbnodes,coords,"CARTESIAN",MED_EN::MED_FULL_INTERLACE);
00063   delete [] coords;
00064   mesh->setNumberOfTypes(1,MED_EN::MED_CELL);
00065   mesh->setTypes(&type,MED_EN::MED_CELL);
00066   mesh->setNumberOfElements(&nbelems,MED_EN::MED_CELL);
00067   
00068   int* conn = new int [nbelems*(type%100)];
00069   if (dim==2)
00070     {
00071       for (int ix=0; ix<nbedge; ix++)
00072         for (int iy=0; iy<nbedge; iy++)
00073           {
00074             int ielem=(ix*nbedge+iy);
00075             conn [ielem*4]=ix*(nbedge+1)+iy+1;
00076             conn [ielem*4+1]=ix*(nbedge+1)+iy+1+1;
00077             conn [ielem*4+2]=(ix+1)*(nbedge+1)+iy+1+1;
00078             conn [ielem*4+3]=(ix+1)*(nbedge+1)+iy+1;                               
00079           }
00080     }
00081   if (dim==3)
00082     {
00083       for (int ix=0; ix<nbedge; ix++)
00084         for (int iy=0; iy<nbedge; iy++)
00085           for (int iz=0; iz<nbedge; iz++)
00086             {
00087               int ielem=(ix*nbedge*nbedge+iy*nbedge+iz);
00088               conn [ielem*8]=ix*(nbedge+1)*(nbedge+1)+iy*(nbedge+1)+iz+1;
00089               conn [ielem*8+1]=(ix+1)*(nbedge+1)*(nbedge+1)+iy*(nbedge+1)+iz+1;
00090               conn [ielem*8+2]=(ix+1)*(nbedge+1)*(nbedge+1)+(iy+1)*(nbedge+1)+iz+1;
00091               conn [ielem*8+3]=ix*(nbedge+1)*(nbedge+1)+(iy+1)*(nbedge+1)+iz+1;
00092               conn [ielem*8+4]=ix*(nbedge+1)*(nbedge+1)+iy*(nbedge+1)+iz+1+1;
00093               conn [ielem*8+5]=(ix+1)*(nbedge+1)*(nbedge+1)+iy*(nbedge+1)+iz+1+1;
00094               conn [ielem*8+6]=(ix+1)*(nbedge+1)*(nbedge+1)+(iy+1)*(nbedge+1)+iz+1+1;
00095               conn [ielem*8+7]=ix*(nbedge+1)*(nbedge+1)+(iy+1)*(nbedge+1)+iz+1+1;
00096             }
00097     }
00098   mesh->setConnectivity(MED_EN::MED_CELL,type,conn);
00099   delete [] conn;
00100   return mesh;
00101 }