From: ageay Date: Mon, 6 Dec 2010 17:09:28 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: MEDPartitioner_first_compilable_version~52 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ed04cb4403b2b64955593390d50759256c8bbd7d;p=tools%2Fmedcoupling.git *** empty log message *** --- diff --git a/src/MEDLoader/MEDFileMeshLL.cxx b/src/MEDLoader/MEDFileMeshLL.cxx index fa879cd55..7a02f848e 100644 --- a/src/MEDLoader/MEDFileMeshLL.cxx +++ b/src/MEDLoader/MEDFileMeshLL.cxx @@ -22,6 +22,8 @@ #include "MEDCouplingUMesh.hxx" +#include "InterpKernelAutoPtr.hxx" + #include 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 comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM); + INTERP_KERNEL::AutoPtr unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM); + for(int i=0;igetInfoOnComponent(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 index 000000000..aac99454b --- /dev/null +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -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() diff --git a/src/MEDLoader/Swig/MEDLoaderTypemaps.i b/src/MEDLoader/Swig/MEDLoaderTypemaps.i index 94811c36d..e36250335 100644 --- a/src/MEDLoader/Swig/MEDLoaderTypemaps.i +++ b/src/MEDLoader/Swig/MEDLoaderTypemaps.i @@ -19,6 +19,21 @@ #include +static PyObject* convertMEDFileMesh(ParaMEDMEM::MEDFileMesh* mesh, int owner) +{ + PyObject *ret=0; + if(dynamic_cast(mesh)) + ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDFileUMesh,owner); + if(dynamic_cast(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 > convertTimePairIdsFromPy(PyObject *pyLi) { std::vector > ret; diff --git a/src/MEDLoader/Swig/libMEDLoader_Swig.i b/src/MEDLoader/Swig/libMEDLoader_Swig.i index 5feded4d5..fb670d2e3 100644 --- a/src/MEDLoader/Swig/libMEDLoader_Swig.i +++ b/src/MEDLoader/Swig/libMEDLoader_Swig.i @@ -26,13 +26,21 @@ %{ #include "MEDLoader.hxx" +#include "MEDFileMesh.hxx" #include "MEDLoaderTypemaps.i" + +using namespace ParaMEDMEM; %} #if SWIG_VERSION >= 0x010329 %template() std::vector; #endif +%typemap(out) ParaMEDMEM::MEDFileMesh* +{ + $result=convertMEDFileMesh($1,$owner); +} + %newobject MEDLoader::ReadUMeshFromFamilies; %newobject MEDLoader::ReadUMeshFromGroups; %newobject MEDLoader::ReadUMeshFromFile; @@ -41,6 +49,17 @@ %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" +