]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
*** empty log message ***
authorageay <ageay>
Mon, 6 Dec 2010 17:09:28 +0000 (17:09 +0000)
committerageay <ageay>
Mon, 6 Dec 2010 17:09:28 +0000 (17:09 +0000)
src/MEDLoader/MEDFileMeshLL.cxx
src/MEDLoader/Swig/MEDLoaderTest3.py [new file with mode: 0644]
src/MEDLoader/Swig/MEDLoaderTypemaps.i
src/MEDLoader/Swig/libMEDLoader_Swig.i

index fa879cd55d0a281d63b938a5dabeeb35bd601b19..7a02f848ed885c0089487986d91fab6cbe881214 100644 (file)
@@ -22,6 +22,8 @@
 
 #include "MEDCouplingUMesh.hxx"
 
+#include "InterpKernelAutoPtr.hxx"
+
 #include <set>
 
 extern med_geometrie_element typmai[MED_NBR_GEOMETRIE_MAILLE+2];
@@ -169,7 +171,18 @@ void MEDFileUMeshL2::writeCoords(med_idt fid, const char *mname, const DataArray
 {
   if(!coords)
     return ;
-  MEDcoordEcr(fid,maa,spaceDim,arr->getPointer(),MED_FULL_INTERLACE,mesh[0]->getNumberOfNodes(),MED_CART,comp,unit);
+  int spaceDim=coords->getNumberOfComponents();
+  INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM);
+  INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM);
+  for(int i=0;i<spaceDim;i++)
+    {
+      std::string info=coords->getInfoOnComponent(i);
+      std::string c,u;
+      MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
+      MEDLoaderBase::safeStrCpy(c.c_str(),MED_TAILLE_PNOM-1,comp+i*MED_TAILLE_PNOM,0);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
+      MEDLoaderBase::safeStrCpy(u.c_str(),MED_TAILLE_PNOM-1,unit+i*MED_TAILLE_PNOM,0);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
+    }
+  MEDcoordEcr(fid,(char *)mname,spaceDim,coords->getPointer(),MED_FULL_INTERLACE,coords->getNumberOfTuples(),MED_CART,comp,unit);
 }
 
 bool MEDFileUMeshL2::isFamDefinedOnLev(int levId) const
diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py
new file mode 100644 (file)
index 0000000..aac9945
--- /dev/null
@@ -0,0 +1,76 @@
+#  -*- coding: iso-8859-1 -*-
+#  Copyright (C) 2007-2010  CEA/DEN, EDF R&D
+#
+#  This library is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU Lesser General Public
+#  License as published by the Free Software Foundation; either
+#  version 2.1 of the License.
+#
+#  This library is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  Lesser General Public License for more details.
+#
+#  You should have received a copy of the GNU Lesser General Public
+#  License along with this library; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+#  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+from libMEDLoader_Swig import *
+import unittest
+from math import pi,e,sqrt
+from MEDLoaderDataForTest import MEDLoaderDataForTest
+
+class MEDLoaderTest(unittest.TestCase):
+    def testMEDMesh1(self):
+        fileName="Pyfile18.med"
+        mname="ExampleOfMultiDimW"
+        medmesh=MEDFileUMesh.New(fileName,mname)
+        self.assertEqual((0,-1),medmesh.getNonEmptyLevels())
+        m1_0=medmesh.getRank0Mesh()
+        m1_1=MEDLoader.ReadUMeshFromFile(fileName,mname,0)
+        self.assertTrue(m1_0.isEqual(m1_1,1e-12));
+        m2_0=medmesh.getRankM1Mesh()
+        m2_1=MEDLoader.ReadUMeshFromFile(fileName,mname,-1)
+        self.assertTrue(m2_0.isEqual(m2_1,1e-12));
+        pass
+    def testMEDMesh2(self):
+        fileName="Pyfile10.med"
+        mname="3DToto"
+        medmesh=MEDFileUMesh.New(fileName,mname)
+        self.assertEqual((0,),medmesh.getNonEmptyLevels())
+        m1_0=medmesh.getRank0Mesh()
+        m1_1=MEDLoader.ReadUMeshFromFile(fileName,mname,0)
+        self.assertTrue(m1_0.isEqual(m1_1,1e-12));
+        g1_0=medmesh.getGroup(0,"mesh2")
+        g1_1=MEDLoader.ReadUMeshFromGroups(fileName,mname,0,["mesh2"]);
+        self.assertTrue(g1_0.isEqual(g1_1,1e-12));
+        g1_0=medmesh.getGroup(0,"mesh3")
+        g1_1=MEDLoader.ReadUMeshFromGroups(fileName,mname,0,["mesh3"]);
+        self.assertTrue(g1_0.isEqual(g1_1,1e-12));
+        g1_0=medmesh.getGroups(0,["mesh3","mesh2"])
+        g1_1=MEDLoader.ReadUMeshFromGroups(fileName,mname,0,["mesh3","mesh2"]);
+        g1_1.setName(g1_0.getName())
+        self.assertTrue(g1_0.isEqual(g1_1,1e-12));
+        g1_0=medmesh.getFamily(0,"Family_2")
+        g1_1=MEDLoader.ReadUMeshFromFamilies(fileName,mname,0,["Family_2"]);
+        self.assertTrue(g1_0.isEqual(g1_1,1e-12));
+        g1_0=medmesh.getFamilies(0,["Family_2","Family_4"])
+        g1_1=MEDLoader.ReadUMeshFromFamilies(fileName,mname,0,["Family_2","Family_4"]);
+        g1_1.setName(g1_0.getName())
+        self.assertTrue(g1_0.isEqual(g1_1,1e-12));
+        ## st=g1_0.advancedRepr()
+        ## f=file("out1","w")
+        ## f.write(st)
+        ## f.close()
+        ## st=g1_1.advancedRepr()
+        ## f=file("out2","w")
+        ## f.write(st)
+        ## f.close()
+        self.assertTrue(g1_0.isEqual(g1_1,1e-12));
+        pass
+    pass
+
+unittest.main()
index 94811c36da981c2cc8ed75da202d4bad8fd301f8..e362503354ccb39f19e2304b1395a4ecae9d2744 100644 (file)
 
 #include <vector>
 
+static PyObject* convertMEDFileMesh(ParaMEDMEM::MEDFileMesh* mesh, int owner)
+{
+  PyObject *ret=0;
+  if(dynamic_cast<ParaMEDMEM::MEDFileUMesh *>(mesh))
+    ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDFileUMesh,owner);
+  if(dynamic_cast<ParaMEDMEM::MEDFileCMesh *>(mesh))
+    ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDFileCMesh,owner);
+  if(!ret)
+    {
+      PyErr_SetString(PyExc_TypeError,"Not recognized type of MEDFileMesh on downcast !");
+      PyErr_Print();
+    }
+  return ret;
+}
+
 static std::vector<std::pair<int,int> > convertTimePairIdsFromPy(PyObject *pyLi)
 {
   std::vector<std::pair<int,int> > ret;
index 5feded4d5f6275a77b1376b6d20f77c0f8fa32fa..fb670d2e354add470ff83fc9273585d30988d3c0 100644 (file)
 
 %{
 #include "MEDLoader.hxx"
+#include "MEDFileMesh.hxx"
 #include "MEDLoaderTypemaps.i"
+
+using namespace ParaMEDMEM;
 %}
 
 #if SWIG_VERSION >= 0x010329
 %template()  std::vector<std::string>;
 #endif
 
+%typemap(out) ParaMEDMEM::MEDFileMesh*
+{
+  $result=convertMEDFileMesh($1,$owner);
+}
+
 %newobject MEDLoader::ReadUMeshFromFamilies;
 %newobject MEDLoader::ReadUMeshFromGroups;
 %newobject MEDLoader::ReadUMeshFromFile;
 %newobject MEDLoader::ReadFieldNode;
 %newobject MEDLoader::ReadFieldGauss;
 %newobject MEDLoader::ReadFieldGaussNE;
+%newobject ParaMEDMEM::MEDFileUMesh::New;
+%newobject ParaMEDMEM::MEDFileUMesh::getCoords;
+%newobject ParaMEDMEM::MEDFileUMesh::getGroup;
+%newobject ParaMEDMEM::MEDFileUMesh::getGroups;
+%newobject ParaMEDMEM::MEDFileUMesh::getFamily;
+%newobject ParaMEDMEM::MEDFileUMesh::getFamilies;
+%newobject ParaMEDMEM::MEDFileUMesh::getMeshAtRank;
+%newobject ParaMEDMEM::MEDFileUMesh::getRank0Mesh;
+%newobject ParaMEDMEM::MEDFileUMesh::getRankM1Mesh;
+%newobject ParaMEDMEM::MEDFileUMesh::getRankM2Mesh;
+%newobject ParaMEDMEM::MEDFileUMesh::getRankM3Mesh;
 
 class MEDLoader
 {
@@ -168,3 +187,6 @@ public:
   static void WriteFieldDep(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch) throw(INTERP_KERNEL::Exception);
   static void WriteFieldUsingAlreadyWrittenMesh(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f) throw(INTERP_KERNEL::Exception);
 };
+
+%include "MEDFileMesh.hxx"
+