]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/PyWrapping/TestPyWrapGathered_medcoupling.py
Salome HOME
Testing PyWrapping
[tools/medcoupling.git] / src / PyWrapping / TestPyWrapGathered_medcoupling.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2017  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 from medcoupling import *
23 import unittest
24
25 class FileCreator(object):
26     def __init__(self,tester,fname):
27         self._tester=tester
28         self._fname=fname
29         pass
30         
31     def fileName(self):
32         return self._fname
33     
34     def __enter__(self):
35         import os
36         if os.path.exists(self._fname):
37             os.remove(self._fname)
38             pass
39         return self
40     
41     def __exit__(self, type, value, traceback):
42         import os
43         if not os.path.exists(self._fname):
44             self._tester.assertTrue(False)
45             pass
46         else:
47             os.remove(self._fname)
48         pass
49         
50 class medcouplingTest(unittest.TestCase):
51     
52     @unittest.skipUnless(HasMEDFileExt(),"Requires link to MED file")
53     def test1(self):
54         import sys
55         fname="mctest1.med"
56         arr=DataArrayDouble(10) ; arr.iota()
57         m=MEDCouplingCMesh()
58         m.setCoords(arr,arr)
59         m.setName("mesh")
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())
73         pass
74
75     @unittest.skipUnless(HasRenumberExt(),"Requires Boost or Metis to activate Renumberer")
76     def test2(self):
77         arr=DataArrayDouble(10) ; arr.iota()
78         m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
79         m=m.buildUnstructured() ; m.setName("mesh")
80         #
81         renf=RenumberingFactory("Boost")
82         neigh,neighi=m.computeNeighborsOfCells()
83         n2o,o2n=renf.renumber(neigh,neighi)
84         mRenum=m[n2o]
85         pass
86
87     @unittest.skipUnless(HasPartitionerExt(),"Requires Partitioner activation")
88     def test3(self):
89         arr=DataArrayDouble(10) ; arr.iota()
90         m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
91         m=m.buildUnstructured() ; m.setName("mesh")
92         m.write("all.med")
93         a,b=m.computeNeighborsOfCells()
94         sk=MEDCouplingSkyLineArray(b,a)
95         g=MEDPartitioner.Graph(sk)
96         g.partGraph(4)
97         procIdOnCells=g.getPartition().getValuesArray()
98         m0=m[procIdOnCells.findIdsEqual(0)] ; m0.setName("m0")
99         m0.write("part0.med")
100         pass
101     
102     @unittest.skipUnless(HasParallelInterpolatorExt(),"Requires // interpolator activated")
103     def test4(self):
104         interface=CommInterface()
105         pass
106     
107     pass
108
109 if __name__ == "__main__":
110     unittest.main()