1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2017 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)
22 from medcoupling import *
25 class FileCreator(object):
26 def __init__(self,tester,fname):
36 if os.path.exists(self._fname):
37 os.remove(self._fname)
41 def __exit__(self, type, value, traceback):
43 if not os.path.exists(self._fname):
44 self._tester.assertTrue(False)
47 os.remove(self._fname)
50 class medcouplingTest(unittest.TestCase):
52 @unittest.skipUnless(HasMEDFileExt(),"Requires link to MED file")
56 arr=DataArrayDouble(10) ; arr.iota()
60 with FileCreator(self,fname) as fc:
61 m.write(fc.fileName())
62 m=m.buildUnstructured()
63 with FileCreator(self,fname) as fc:
64 m.write(fc.fileName())
65 f=MEDCouplingFieldDouble(ON_NODES) ; f.setMesh(m) ; f.setArray(m.getCoords()) ; f.setName("field")
66 with FileCreator(self,fname) as fc:
67 f.write(fc.fileName())
68 f=MEDCouplingFieldFloat(ON_NODES) ; f.setMesh(m)
69 d=DataArrayFloat(m.getNumberOfNodes()) ; d.iota()
70 f.setArray(d) ; f.setName("field1")
71 with FileCreator(self,fname) as fc:
72 f.write(fc.fileName())
75 @unittest.skipUnless(HasRenumberExt(),"Requires Boost or Metis to activate Renumberer")
77 arr=DataArrayDouble(10) ; arr.iota()
78 m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
79 m=m.buildUnstructured() ; m.setName("mesh")
81 renf=RenumberingFactory("Boost")
82 neigh,neighi=m.computeNeighborsOfCells()
83 n2o,o2n=renf.renumber(neigh,neighi)
87 @unittest.skipUnless(HasPartitionerExt(),"Requires Partitioner activation")
89 for alg in MEDPartitioner.AvailableAlgorithms():
90 st="Graph.%s"%alg.upper()
92 self.partitionerTesterHelper(eval(st))
96 @unittest.skipUnless(HasParallelInterpolatorExt(),"Requires // interpolator activated")
98 interface=CommInterface()
101 def partitionerTesterHelper(self,algoSelected):
102 arr=DataArrayDouble(10) ; arr.iota()
103 m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
104 m=m.buildUnstructured() ; m.setName("mesh")
105 a,b=m.computeNeighborsOfCells()
106 sk=MEDCouplingSkyLineArray(b,a)
107 g=MEDPartitioner.Graph(sk,algoSelected)
109 procIdOnCells=g.getPartition().getValuesArray()
110 m0=m[procIdOnCells.findIdsEqual(0)] ; m0.setName("m0")
115 if __name__ == "__main__":
116 if HasParallelInterpolatorExt():
118 from mpi4py import MPI # if not imported test3 may failed due to MPI call of partitioner algorithms.