# -*- coding: utf-8 -*-
-# Copyright (C) 2007-2015 CEA/DEN, EDF R&D
+# Copyright (C) 2007-2016 CEA/DEN, EDF R&D
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
from datetime import datetime
from MEDCouplingDataForTest import MEDCouplingDataForTest
import rlcompleter,readline # this line has to be here, to ensure a usability of MEDCoupling/MEDLoader. B4 removing it please notify to anthony.geay@cea.fr
+from sys import platform
+
+def checkFreeMemory(size):
+ """
+ Get node total memory and memory usage
+ """
+ ret = True
+ dic = {}
+ if platform not in ["win32"]:
+ with open('/proc/meminfo', 'r') as mem:
+ tmp = 0
+ for i in mem:
+ sline = i.split()
+ if str(sline[0]) == 'MemTotal:':
+ dic['total'] = int(sline[1])
+ elif str(sline[0]) in ('MemFree:', 'Buffers:', 'Cached:'):
+ tmp += int(sline[1])
+ dic['free'] = tmp
+ dic['used'] = int(dic['total']) - int(dic['free'])
+ ret = dic['free'] > size
+ #TODO: extend this method for Windows OS
+ return ret
+
class MEDCouplingBasicsTest4(unittest.TestCase):
def testSwigDADOp4(self):
expected2=DataArrayInt.New([271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,302,303,304,305,306,307,308,309,310,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330]);
self.assertTrue(expected2.isEqual(daC));
#
- vals=m.getMeasureField(ON_CELLS).getArray()
+ vals=m.getMeasureField(False).getArray()
ref=271*[184.69493088478035]+3*[-61.564976961404426,-92.34746544254946,-92.34746544259811,-92.34746544253488,-92.3474654425349,-92.34746544180479,-92.34746544253493,-92.3474654419026,-92.34746544190256,-92.34746544253491]+2*[61.564976961404426,-92.34746544254946,-92.34746544259811,-92.34746544253488,-92.3474654425349,-92.34746544180479,-92.34746544253493,-92.3474654419026,-92.34746544190256,-92.34746544253491]+[-61.564976961404426,-92.34746544254946,-92.34746544259811,-92.34746544253488,-92.3474654425349,-92.34746544180479,-92.34746544253493,-92.3474654419026,-92.34746544190256,-92.34746544253491]
vals-=DataArrayDouble.New(ref)
vals.abs()
self.assertEqual(0,da.index(7))
self.assertEqual(10,da.index(47))
self.assertTrue(14 not in da)
- self.assertEqual(5,da.search([9,9]))
- self.assertEqual(-1,da.search([5,8]))
+ self.assertEqual(5,da.findIdSequence([9,9]))
+ self.assertEqual(-1,da.findIdSequence([5,8]))
da.rearrange(2)
self.assertTrue([47,16] not in da)
self.assertTrue([5,6] not in da)
m.setCoords(coords);
m.checkConsistencyLight();
#
- vol=m.getMeasureField(ON_CELLS);
+ vol=m.getMeasureField(False);
self.assertEqual(1,vol.getArray().getNumberOfTuples());
self.assertAlmostEqual(0.5,vol.getArray().getIJ(0,0),12)
#
self.assertTrue(DataArrayInt([0,7]).isEqual(m.getNodalConnectivityIndex()))
self.assertTrue(DataArrayInt([16,0,2,1,3,5,4]).isEqual(m.getNodalConnectivity()))
#
- vol=m.getMeasureField(ON_CELLS);
+ vol=m.getMeasureField(False);
self.assertEqual(1,vol.getArray().getNumberOfTuples());
self.assertAlmostEqual(0.5,vol.getArray().getIJ(0,0),12)
pass
areaExpected=[-65.18804756198824,-65.18804756198824,-65.18804756198824,-65.18804756198824,-66.75884388878285,-66.75884388878285,-66.7588438887833,-66.75884388878308,-68.32964021557768,-68.32964021557768,-68.32964021557814,-68.32964021557791,-69.9004365423732,-69.9004365423732,-69.90043654237297,-69.90043654237297,-1.194568659706448,-1.0869994447159463,-142.2316939607081,-144.51326206513068,-144.5132620651309,-1.1945686597064424,-143.3186934054243,-5.002264310862817,-10.0261332846393,-3.9727823117092953,-7.290862524642649,-124.504404940456,-3.9727823117093237,-146.82366506060032,-150.79644737231024,-5.002264310862776,-145.79418306144626,-5.00208651738126,-10.054764051268958,-4.001067863263231,-8.027932154428669,-129.99378209314813,-4.001067863263216,-153.07856481622616,-157.0796326794898,-5.0020865173811915,-152.07754616210832,-5.001928880064381,-10.050590216368969,-4.00098721602491,-8.025810856794209,-136.28350081741684,-4.000987216024939,-159.36183077064402,-163.36281798667005,-5.0019288800643285,-158.36088910660442,-1.2991516319851801,-3.702636830195414,-3.7815130030068254,-6.265364371195623,-0.02516260900254963,-0.6553944641345026,-3.975752765070567,-7.368528340442765,-142.57249927881398,-0.02516260900254963,-3.9757527650706095,-165.64508791977525,-169.64600329384803,-1.299151631985167,-3.7026368301953885,-164.6442148316677,-10.00321285677458,-20.08414323176165,-8.001644468035863,-16.042954878437143,-304.0096070742277,-8.00164446803587,-350.1399180412005,-358.1415625092368,-10.003212856774468,-348.13834965246224,-3.794150313030109,-8.65049239704272,-0.02260276689354157,-0.5885167811200915,-370.2185414798688,-0.022602766893559393,-383.2517009710623,-383.2743037379555,-3.7941503130300576,-379.48015342492505,-408.40704496667513,-408.4070449666742,-408.4070449666742,-408.4070449666742,-433.53978619538975,-433.5397861953902,-433.5397861953911,-433.53978619539066,-458.67252742410983,-458.6725274241094,-458.67252742410983,-458.6725274241089,-608.6835766330232,-608.6835766330232,-608.6835766330232,-608.6835766330241]
expected1=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,16,16,17,18,19,19,20,20,20,20,20,21,21,22,23,23,24,24,24,24,24,25,25,26,27,27,28,28,28,28,28,29,29,30,31,31,32,32,32,32,32,32,32,32,32,33,33,33,34,35,35,35,36,36,36,36,36,37,37,38,39,39,40,40,40,40,40,41,41,42,43,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59]
expected2=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,2,-1,-1,-1,0,-1,0,2,4,5,-1,4,-1,-1,0,-1,0,2,4,5,-1,4,-1,-1,0,-1,0,2,4,5,-1,4,-1,-1,0,-1,0,1,2,3,4,5,6,7,-1,4,6,-1,-1,0,1,-1,1,3,6,7,-1,6,-1,-1,1,-1,1,3,6,7,-1,6,-1,-1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]
- f3=m3.getMeasureField(ON_CELLS).getArray().getValues();
+ f3=m3.getMeasureField(False).getArray().getValues();
for i in xrange(105):
self.assertAlmostEqual(areaExpected[i],f3[i],10)
pass
m1=m.deepCopy()
d1=m1.simplexize(PLANAR_FACE_5)
m1.checkConsistency()
- vol1=m1.getMeasureField(ON_CELLS).getArray()
+ vol1=m1.getMeasureField(False).getArray()
self.assertTrue(vol1.isEqual(DataArrayDouble([1./6, 1./6, 1./6,1./6, 1./6, 1./3,1./6, 1./6, 1./6, 1./6, 1./3, 1./6]),1e-12))
self.assertEqual(m1.getNodalConnectivity().getValues(),[14,0,1,2,3,14,4,9,5,6,14,4,8,9,11,14,4,7,11,6,14,9,11,10,6,14,4,9,6,11,14,12,17,13,14,14,12,16,17,19,14,12,15,19,14,14,17,19,18,14,14,12,17,14,19,14,20,21,22,23])
self.assertEqual(m1.getNodalConnectivityIndex().getValues(),[0,5,10,15,20,25,30,35,40,45,50,55,60])
m2=m.deepCopy()
d2=m2.simplexize(PLANAR_FACE_6)
m2.checkConsistency()
- vol2=m2.getMeasureField(ON_CELLS).getArray()
+ vol2=m2.getMeasureField(False).getArray()
self.assertTrue(vol2.isEqual(DataArrayDouble([1./6, 1./6, 1./6,1./6, 1./6, 1./6,1./6,1./6, 1./6, 1./6, 1./6, 1./6,1./6,1./6]),1e-12))
self.assertEqual(m2.getNodalConnectivity().getValues(),[14,0,1,2,3,14,4,9,5,10,14,4,5,6,10,14,4,8,9,10,14,4,11,8,10,14,4,6,7,10,14,4,7,11,10,14,12,17,13,18,14,12,13,14,18,14,12,16,17,18,14,12,19,16,18,14,12,14,15,18,14,12,15,19,18,14,20,21,22,23])
self.assertEqual(m2.getNodalConnectivityIndex().getValues(),[0,5,10,15,20,25,30,35,40,45,50,55,60,65,70])
self.assertTrue(e.isEqual(DataArrayInt([0,1,2,5,6,7,10,11,12,15,16,17,20,21,22,25,26,27,30,31,32,35,36,37,40,41,42,45,46,47,50,51,52,55,56,57,61,62])))
self.assertEqual(("d",6),dd3.getMaxValue())
self.assertEqual(("A",0),dd3.getMinValue())
- self.assertEqual(26,dd3.search("LGYYM"))
- self.assertEqual(-1,dd3.search("LGYYN"))
+ self.assertEqual(26,dd3.findIdSequence("LGYYM"))
+ self.assertEqual(-1,dd3.findIdSequence("LGYYN"))
dd3.rearrange(5)
self.assertEqual(7,dd3.findIdFirstEqualTuple("OPGYY"))
self.assertTrue("OPGYY" in dd3)
self.assertTrue(a.isEqual(DataArrayInt([0,2,4])))
self.assertTrue(b.isEqual(DataArrayInt([0,1,2,7,8,15,16,17])))
pass
-
+
+ @unittest.skipUnless(checkFreeMemory((223456789*16)/(1024)), "Not enough memory")
def testSwig2BigMem(self):
if MEDCouplingSizeOfVoidStar()==64:
d=DataArrayAsciiChar(223456789,16)