# -*- coding: iso-8859-1 -*-
-# Copyright (C) 2017 CEA/DEN, EDF R&D
+# Copyright (C) 2017-2024 CEA, EDF
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# Author : Anthony Geay (EDF R&D)
from medcoupling import *
+
import unittest
+def WriteInTmpDir(func):
+ def decoratedFunc(*args,**kwargs):
+ import tempfile,os, sys
+ ret = None
+ with tempfile.TemporaryDirectory() as tmpdirname:
+ os.chdir(tmpdirname)
+ ret = func(*args,**kwargs)
+ os.chdir(os.path.dirname(tmpdirname))
+ pass
+ return ret
+ return decoratedFunc
+
class FileCreator(object):
def __init__(self,tester,fname):
self._tester=tester
pass
class medcouplingTest(unittest.TestCase):
+
+ def test0(self):
+ """ Unconditional test : medcoupling "kernel" classes """
+ f=MEDCouplingFieldDouble(ON_CELLS)
+ g=DataArrayDouble(10,2)
+ h=MEDCouplingUMesh("mesh",3)
+ hh=MEDCouplingRemapper()
+ ee=InterpKernelException("ee")
+ pass
@unittest.skipUnless(HasMEDFileExt(),"Requires link to MED file")
+ @WriteInTmpDir
def test1(self):
import sys
fname="mctest1.med"
@unittest.skipUnless(HasPartitionerExt(),"Requires Partitioner activation")
def test3(self):
+ for alg in MEDPartitioner.AvailableAlgorithms():
+ st="Graph.%s"%alg.upper()
+ print(st)
+ self.partitionerTesterHelper(eval(st))
+ pass
+ pass
+
+ @unittest.skipUnless(HasParallelInterpolatorExt(),"Requires // interpolator activated")
+ def test4(self):
+ interface=CommInterface()
+ pass
+
+ @unittest.skipUnless(HasMEDFileExt(),"Requires link to MED file")
+ def test5(self):
+ f=MEDCouplingFieldDouble(ON_NODES)
+ f.setTime(1.25,3,6)
+ a,b,c=f.getTime()
+ self.assertEqual(b,3) ; self.assertEqual(c,6) ; self.assertAlmostEqual(a,1.25,14);
+ f1ts=MEDFileField1TS()
+ f1ts.setTime(10,13,10.75)
+ f.copyTimeInfoFrom(f1ts)
+ a,b,c=f.getTime()
+ self.assertEqual(b,10) ; self.assertEqual(c,13) ; self.assertAlmostEqual(a,10.75,14);
+ f2=MEDCouplingFieldInt(ON_NODES)
+ f2.copyTimeInfoFrom(f1ts)
+ a,b,c=f2.getTime()
+ self.assertEqual(b,10) ; self.assertEqual(c,13) ; self.assertAlmostEqual(a,10.75,14);
+ f3=MEDCouplingFieldFloat(ON_NODES)
+ f3.copyTimeInfoFrom(f1ts)
+ a,b,c=f3.getTime()
+ self.assertEqual(b,10) ; self.assertEqual(c,13) ; self.assertAlmostEqual(a,10.75,14);
+ pass
+
+
+ def partitionerTesterHelper(self,algoSelected):
arr=DataArrayDouble(10) ; arr.iota()
m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
m=m.buildUnstructured() ; m.setName("mesh")
- m.write("all.med")
a,b=m.computeNeighborsOfCells()
sk=MEDCouplingSkyLineArray(b,a)
- g=MEDPartitioner.Graph(sk)
+ g=MEDPartitioner.Graph(sk,algoSelected)
g.partGraph(4)
procIdOnCells=g.getPartition().getValuesArray()
m0=m[procIdOnCells.findIdsEqual(0)] ; m0.setName("m0")
- m0.write("part0.med")
- pass
-
- @unittest.skipUnless(HasParallelInterpolatorExt(),"Requires // interpolator activated")
- def test4(self):
- interface=CommInterface()
pass
pass
if __name__ == "__main__":
+ if HasParallelInterpolatorExt():
+ try:
+ from mpi4py import MPI # if not imported test3 may failed due to MPI call of partitioner algorithms.
+ except:
+ pass
+ pass
unittest.main()
+ pass
+