Salome HOME
On the road of the ParaMEDReader. MEDLoader can load partially a MEDFileUMesh from...
[tools/medcoupling.git] / src / ParaMEDLoader / ParaMEDFileMesh.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (EDF R&D)
20
21 #include "ParaMEDFileMesh.hxx"
22 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
23 #include "MEDFileMesh.hxx"
24 #include "MEDFileMeshLL.hxx"
25 #include "MEDLoader.hxx"
26
27 using namespace ParaMEDMEM;
28
29 MEDFileMesh *ParaMEDFileMesh::New(const MPI_Comm com, const MPI_Info nfo, const std::string& fileName, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
30 {
31   MEDFileUtilities::CheckFileForRead(fileName);
32   ParaMEDMEM::MEDCouplingMeshType meshType;
33   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY));
34   int dummy0,dummy1;
35   std::string dummy2;
36   MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dummy2);
37   switch(meshType)
38   {
39     case UNSTRUCTURED:
40       {
41         return ParaMEDFileUMesh::New(com,nfo,fileName,mName,dt,it,mrs);
42       }
43     default:
44       throw INTERP_KERNEL::Exception("ParaMEDFileMesh::New : only unstructured mesh supported for the moment !");
45   }
46 }
47
48 MEDFileUMesh *ParaMEDFileUMesh::New(const MPI_Comm com, const MPI_Info nfo, const std::string& fileName, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
49 {
50   MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> ret(MEDFileUMesh::New());
51   MEDFileUtilities::AutoFid fid(MEDparFileOpen(fileName.c_str(),MED_ACC_RDONLY,com,nfo));
52   //
53   int meshDim, spaceDim, numberOfNodes;
54   std::vector< std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > > typesDistrib(MEDLoader::GetUMeshGlobalInfo(fileName,mName,meshDim,spaceDim,numberOfNodes));
55   return ret.retn();
56 }
57
58 MEDFileMeshes *ParaMEDFileMeshes::New(const MPI_Comm com, const MPI_Info nfo, const std::string& fileName)
59 {
60   std::vector<std::string> ms(MEDLoader::GetMeshNames(fileName));
61   MEDCouplingAutoRefCountObjectPtr<MEDFileMeshes> ret(MEDFileMeshes::New());
62   for(std::vector<std::string>::const_iterator it=ms.begin();it!=ms.end();it++)
63     {
64       MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mesh(ParaMEDFileMesh::New(com,nfo,fileName,(*it)));
65       ret->pushMesh(mesh);
66     }
67   return ret.retn();
68 }