From: Anthony GEAY Date: Tue, 22 Sep 2020 19:47:30 +0000 (+0200) Subject: fix of med convertors for int64 X-Git-Tag: V9_6_0a1~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fagy%2Ftu20059_int64;p=tools%2Fmedcoupling.git fix of med convertors for int64 --- diff --git a/src/MEDCoupling_Swig/vtk2medcoupling.py b/src/MEDCoupling_Swig/vtk2medcoupling.py index 1e3bb97f0..211c3805f 100644 --- a/src/MEDCoupling_Swig/vtk2medcoupling.py +++ b/src/MEDCoupling_Swig/vtk2medcoupling.py @@ -1,10 +1,33 @@ +#! /usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright (C) 2020 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, or (at your option) any later version. +# +# 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 +# +# Author : Anthony GEAY (EDF R&D) + import vtk from vtk.util import numpy_support import medcoupling as mc import numpy as np def mesh_convertor(fileName): - reader = vtk.vtkDataSetReader() + #vtk.vtkDataSetReader() + reader = vtk.vtkXMLUnstructuredGridReader() reader.SetFileName(fileName) reader.Update() ug = reader.GetOutput() @@ -19,7 +42,7 @@ def mesh_convertor_mem(ug): ctvtk = numpy_support.vtk_to_numpy(ug.GetCellTypesArray()) conn = numpy_support.vtk_to_numpy(ug.GetCells().GetData()) # - ct=mc.DataArrayInt(np.array(ctvtk,dtype=np.int32))[:] + ct=mc.DataArrayInt(np.array(ctvtk,dtype="int{}".format(mc.MEDCouplingSizeOfIDs())))[:] c=mc.DataArrayInt(conn)[:] ci=mc.DataArrayInt(cla)[:] # for pv580 @@ -33,8 +56,15 @@ def mesh_convertor_mem(ug): c[ci]=ct ci = mc.DataArrayInt.Aggregate([ci,mc.DataArrayInt([len(c)])]) # - - m=mc.MEDCouplingUMesh("mesh",2) + gtv = ct.getDifferentValues().getValues() + dimArray = mc.DataArrayInt(len(gtv)) ; dimArray[:] = -1 + for i,gt in enumerate(gtv): + dimArray[i] = mc.MEDCouplingUMesh.GetDimensionOfGeometricType(gt) + dim = dimArray.getMaxValueInArray() + if not dimArray.isUniform(dim): + raise RuntimeError("The input vtkUnstructuredGrid instance is not a single level mesh ! need to split it !") + # + m=mc.MEDCouplingUMesh("mesh",dim) m.setCoords(mc.DataArrayDouble(np.array(pts,dtype=np.float64))) m.setConnectivity(c,ci,True) m.checkConsistencyLight() diff --git a/src/MEDLoader/Swig/CaseReader.py b/src/MEDLoader/Swig/CaseReader.py index e2d419306..733bbd134 100644 --- a/src/MEDLoader/Swig/CaseReader.py +++ b/src/MEDLoader/Swig/CaseReader.py @@ -21,7 +21,7 @@ # http://www-vis.lbl.gov/NERSC/Software/ensight/doc/OnlineHelp/UM-C11.pdf import numpy as np -from MEDLoader import * +from medcoupling import * from CaseIO import CaseIO import sys,re,os @@ -56,11 +56,7 @@ class CaseReader(CaseIO): cI=DataArrayInt(len(cells)+1) ; cI.iota() ; cI*=nbNodesPerCell+1 # cells2=cells.reshape(len(cells),nbNodesPerCell) - if cells2.dtype=='int32': - c2=DataArrayInt(cells2) - else: - c2=DataArrayInt(np.array(cells2,dtype="int32")) - pass + c2=DataArrayInt(np.array(cells2,dtype="int{}".format(MEDCouplingSizeOfIDs())) ) c=DataArrayInt(len(cells),nbNodesPerCell+1) ; c[:,0]=ct ; c[:,1:]=c2-1 ; c.rearrange(1) m.setConnectivity(c,cI,True) m.checkConsistency() diff --git a/src/MEDLoader/Swig/case2med b/src/MEDLoader/Swig/case2med index 84b681947..0b6d226af 100755 --- a/src/MEDLoader/Swig/case2med +++ b/src/MEDLoader/Swig/case2med @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: iso-8859-1 -*- # Copyright (C) 2007-2020 CEA/DEN, EDF R&D #