+#! /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()
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
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()
# 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
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()