Salome HOME
Copyright update 2022
[modules/paravis.git] / src / Plugins / MEDReader / plugin / Test / testMEDReader23.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2021-2022  CEA/DEN, EDF R&D
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 # Author : Anthony Geay (EDF R&D)
21
22 __doc__  = """
23 Non regression test of EDF24514. GlobalNodeIds present in MED file whereas it does not appear into output DataSet of MEDReader.
24 """
25
26 from paraview.simple import *
27 import medcoupling as mc
28 from vtk.util import numpy_support
29
30 def MyAssert(clue):
31   if not clue:
32     raise RuntimeError("Assertion failed !")
33
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.)
38
39 def generateCase(fname,globalNodeIds,coordinates):
40   m = mc.MEDCouplingUMesh.Build1DMeshFromCoords(coordinates)
41   m.setName("mesh")
42   mm = mc.MEDFileUMesh()
43   mm[0] = m
44   mm.setGlobalNumFieldAtLevel(1,globalNodeIds)
45   mm.write(fname,2)
46
47 generateCase(fname,ids,coo)
48 myMedReader = MEDReader(registrationName = fname, FileName = fname)
49 myMedReader.AllArrays = ['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']    )
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) )