1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2021-2022 CEA/DEN, EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 # Author : Anthony Geay (EDF R&D)
23 Non regression test of EDF24514. GlobalNodeIds present in MED file whereas it does not appear into output DataSet of MEDReader.
26 from paraview.simple import *
27 import medcoupling as mc
28 from vtk.util import numpy_support
32 raise RuntimeError("Assertion failed !")
34 fname = 'testMEDReader23.med'
35 ids = mc.DataArrayInt(40) ; ids.iota(100) # array used to define GlobalNodeIds. Used to be checked
36 coo = mc.DataArrayDouble(40) ; coo.iota()
37 coo = coo.changeNbOfComponents(3,0.)
39 def generateCase(fname,globalNodeIds,coordinates):
40 m = mc.MEDCouplingUMesh.Build1DMeshFromCoords(coordinates)
42 mm = mc.MEDFileUMesh()
44 mm.setGlobalNumFieldAtLevel(1,globalNodeIds)
47 generateCase(fname,ids,coo)
48 myMedReader = MEDReader(registrationName = fname, FileNames = [fname])
49 myMedReader.FieldsStatus = ['TS0/mesh/ComSup0/mesh@@][@@P0']
50 myMedReader.UpdatePipeline()
51 # first important testing here
52 MyAssert( [myMedReader.PointData.GetArray(i).GetName() for i in range(myMedReader.PointData.GetNumberOfArrays())] == ['GlobalNodeIds','vtkGhostType'] )
53 ReadUnstructuredGrid = servermanager.Fetch(myMedReader).GetBlock(0)
54 numpy_support.vtk_to_numpy( ReadUnstructuredGrid.GetPointData().GetArray('GlobalNodeIds') )
55 # check match of coordinates written in testMEDReader23.med file and its representation
56 MyAssert( mc.DataArrayInt(numpy_support.vtk_to_numpy( ReadUnstructuredGrid.GetPointData().GetArray('GlobalNodeIds') ) ).isEqual(ids) )
57 MyAssert( mc.DataArrayDouble(numpy_support.vtk_to_numpy(ReadUnstructuredGrid.GetPoints().GetData())).isEqual(coo,1e-12) )